Vacuum of empty table takes 3 seconds

223 Views Asked by At

Running vacuum on some of our systems takes 3 seconds for an empty table:

create table t (c int);
vacuum t; -- 3 seconds
vacuum t; -- 3 seconds
vacuum t; -- 3 seconds
...

On my local installation it takes only milliseconds. Why is it so slow on some of our systems? What could the reason be? I tried to find what stalls the vacuum via using pg_stat_progress_vacuum but the stalling vacuum does not show up there.

One idea I have is that there are many table partitions on those systems. One example:

select count(*) from pg_class;                      -- 1.903.740
select count(*) from pg_class WHERE relkind  = 'r'; --   362.800

Could that be the reason? How can I find and fix the reason? This stalls autovacuum, as the wraparound-prevention vacuums take too long for all these table-partitions (that are 99.9% just all-frozen data or empty partitions) when they take several seconds for each partition when it should just take milliseconds.

1

There are 1 best solutions below

1
Evgeniy Chekan On

Try running vacuum verbose t, it will give you some details with timings included