I initially thought n_dead_tup
and dead_tuple_count
in PostgreSQL give the same counts. But they seem to be not. I do not quite understand what exactly is difference.
Following are my observations:
- Created a table with 10k rows.
- Updated all the 10k rows. Now I have 10k dead tuples.
SELECT dead_tuple_count FROM public.pgstattuple('public.vacuum_test');
dead_tuple_count
------------------
10002
select * from pg_stat_get_dead_tuples('18466');
pg_stat_get_dead_tuples
-------------------------
10002
- I did vacuum full on the table. As expected dead_tuple_count is 0.
SELECT dead_tuple_count FROM public.pgstattuple('public.vacuum_test');
dead_tuple_count
------------------
0
But n_dead_tup
from pg_stat_all_tables
i.e pg_stat_get_dead_tuples('18466')
is still 10002:
select * from pg_stat_get_dead_tuples('18466');
pg_stat_get_dead_tuples
-------------------------
10002
I repeated this process several times and observed that number of updated tuples is getting added to the stat n_dead_tup
after every update.
So what exactly is VACUUM
doing here?
And what is the difference between n_dead_tup
and dead_tuple_count
?