Monitoring and tuning a vacuum
This recipe covers both the VACUUM
command and autovacuum
, which I refer to collectively as vacuums (non-capitalized). It’s important to be able to monitor both to know how long they take and what resources they use so you can better tune the behavior and timing of future vacuums.
If you’re currently waiting for a long-running vacuum (or autovacuum
) to finish, continue 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 go straight to the How it works… section.
Getting ready
Let’s watch what happens when we run a large VACUUM
. Don’t run VACUUM FULL
because, as we mentioned in the recipe Controlling automatic database maintenance, it runs for a long time while holding an AccessExclusiveLock
on the table. Ouch.
How to do it…
First, locate which process is running this VACUUM
...