If you do not resolve this problem fairly quickly your database will go into emergency shutdown to prevent data corruption and refuse to start back up until txid wraparound vaccuum completes. Check the logs to see how close to this point you are, you'll see messages like:
WARNING: database "mydb" must be vacuumed within 177009986 transactions
HINT: To avoid a database shutdown, execute a database-wide VACUUM in "mydb".
Do not just kill the vacuum and put the problem off. You really, really need to resolve this unless you can afford some unplanned downtime.
The reason it's consuming tons of disk space is probably that you're on an old version that doesn't have auto-managed freespacemap settings, and you've likely exceeded max_fsm_pages
and/or max_fsm_relations
. Check the log, you may well see messages about these.
Unfortunately you can't just raise these params after the fact. This old PostgreSQL install has lost the knowledge about what space in the table is free. Proper cleanup and recovery will require a CLUSTER
of the table, which needs at least as much free space as the table+index sizes and requires an exclusive lock on the table for the duration of the run.
Most of the less intrusive mitigating options like pg_reorg
are no longer open to you now that you're approaching forced txid wraparound prevention. Your best bet is quite probably to give autovacuum the space it needs to complete the job - or to deal with the downtime and CLUSTER
then VACUUM FREEZE
the table to get the process over and done with faster.
Once you've recovered, I would recommend greatly increasing max_fsm_pages
and making sure max_fsm_relations
is big enough. Lots of tuning advice for these old versions is around, search.
Plan an upgrade to 9.2, which auto-manages the freespace map (as does any version 8.4+) and has all sorts of autovac enhancements to help stop you getting into these pickles in the first place.
If this situation is desperate consider getting in touch with professional PostgreSQL support provider. (Proper disclosure: I work for 2ndQuadrant, one of the listed providers).