Maintenance
Vacuum performs key maintenance on PostgreSQL data files:
- Recovers free space consumed by older versions of records under MVCC.
- Updates statistics used by the query planner.
- Updates the visibility map, speeding up index-only scans.
- Prevents loss of very old data caused by transaction ID (
multixact
) wraparound.
Operations
vacuum
can run in parallel with other clients/operations.vacuum full
requires anaccess exclusive
lock. This should be avoidable ifvacuum
is performed routinely.
Autovacuum status
select relname as tablename
, n_live_tup as livetuples
, n_dead_tup as deadtuples
, last_autovacuum as autovacuum
, last_autoanalyze as autoanalyze
from pg_stat_user_tables;
Autovacuum configuration
select category
, name
, setting
, unit
, source
, min_val
, max_val
from pg_settings
where category = 'Autovacuum';