Danger in killing autovacuum: VACUUM queries (to prevent wraparound)

Henley picture Henley · Aug 5, 2013 · Viewed 19.9k times · Source

There is an autovacuum query that is taking a very long time to run, and preventing alter queries to run.

What is the danger is killing this autovacuum process before it's done?

PID      QUERY
16967 | autovacuum: VACUUM public.articles (to prevent wraparound)

Here is how I am killing it:

select pg_terminate_backend(16967) from pg_stat_activity;

Answer

bma picture bma · Aug 5, 2013

You can issue pg_cancel_backend(16967) rather than "pg_terminate_backend()" (not quite as severe is my understanding). Once you kill that autovacuum process, it will start back up again as you have probably noticed, particularly because it was launched for the reason stated (which was to prevent wraparound). If you issue VACUUM public.articles manually, the vacuum will complete faster at the expense of higher disk I/O. That's a generalized answer, but is usually how it turns out.