I have a Postgres 9.2 DB where a certain table has lots of nonremovable dead rows:
# SELECT * FROM public.pgstattuple('mytable');
table_len | tuple_count | tuple_len | tuple_percent | dead_tuple_count | dead_tuple_len | dead_tuple_percent | free_space | free_percent
------------+-------------+-----------+---------------+------------------+----------------+--------------------+------------+--------------
2850512896 | 283439 | 100900882 | 3.54 | 2537195 | 2666909495 | 93.56 | 50480156 | 1.77
(1 row)
Normal vacuuming also shows lots of nonremovable dead rows:
# VACUUM VERBOSE mytable;
[...]
INFO: "mytable": found 0 removable, 2404332 nonremovable row versions in 309938 out of 316307 pages
DETAIL: 2298005 dead row versions cannot be removed yet.
There were 0 unused item pointers.
0 pages are entirely empty.
CPU 1.90s/2.05u sec elapsed 16.79 sec.
[...]
The table only has around 300.000 actual data rows, but 2.3 million dead rows (and this appears to make certain queries very slow).
According to SELECT * FROM pg_stat_activity where xact_start is not null and datname = 'mydb' order by xact_start; there is no old transaction accessing the database. The oldest transactions are some minutes old and haven't modified anything on the table yet.
I've also checked select * from pg_prepared_xacts (to check for prepared transactions) and select * from pg_stat_replication (to check for pending replications), both of which are empty.
There are lots of inserts, updates and deletes performed on that table, so I can understand that lots of dead rows are being created. But why aren't they removed by the VACUUM command?
SELECT pid, datname, usename, state, backend_xmin FROM pg_stat_activity WHERE backend_xmin IS NOT NULL, but no xmin id is matching with this result. – RBB Mar 20 '20 at 08:22