Monitoring and tuning a vacuum
This recipe covers both the VACUUM
command and autovacuum
, which I refer to collectively as vacuums (non-capitalized).
If you're currently waiting for a long-running vacuum (or autovacuum
) to finish, go straight to the How to do it... section.
If you've just had a long-running vacuum complete, then you may want to think about setting a few parameters for next time, so read the How it works… section.
Getting ready
Let's watch what happens when we run a large VACUUM
. Don't run VACUUM FULL
, because it runs for a long time while holding an AccessExclusiveLock
 on the table. Ouch.
First, locate which process is running this VACUUM
 by using the pg_stat_activity
 view to identify the specific pid
 (34399
 is just an example).
How to do it…
Repeatedly execute the following query to see the progress of the...