autovacuum
should be running in any modern Postgres database unless you know exactly what you are doing. But autovacuum is not going to shrink tables except for rare corner cases. It schedules periodic VACUUM
and ANALYZE
jobs, but never VACUUM FULL
, which acquires an exclusive lock on processed tables and indexes. VACUUM
helps to avoid table and index bloat, though, by cleaning up dead tuples (along with various other good deeds) and thereby making space available to future write operations on the same object - not returning space to the OS, yet.
You write:
tried to execute 'VACUUM FULL;' but that consumed my whole disk space.
You mean temporarily? Because that's what VACUUM FULL
does. But when it's done, tables and associated indexes are reduced to their minimum size - which is not generally desirable, unless you urgently need the disk space or rows are never updated.
So VACUUM FULL
is the right tool for you, unless you are out of disk space already - which should best not occur to begin with. So you need to create some wiggle room to let it work its magic.
There is also the community tool pg_repack
, which can do the same as VACUUM FULL
without exclusive locks. But it also needs some free disk space to work. Related answer with more details:
To delete all rows of a table and immediately release disk space, use TRUNCATE
. It effectively writes a new file on disk and deletes the old. That's also why it typically can't be used with concurrent load on a DB.
TRUNCATE table_name;