VACUUM
(or VACUUM FULL
) is hardly useful in this case, since it only reclaims space from within tables. Neither is required after dropping a table. Each table (and index) is stored as separate file in the operating system, which is deleted along with the table. So space is reclaimed almost instantly.
Well, there are entries in catalog tables that would leave dead tuples behind after dropping a table. So the database can occupy slightly more space after a table has been created and dropped again.
To get a db down to minimum size again, run (as privileged user):
VACUUM FULL;
Without a list of tables, all accessible tables are rewritten to pristine condition. (Not advisable for a big database with concurrent load, as it takes exclusive locks!)
Or the client tool vacuumdb
with the --full
option:
vacuumdb -f mydb
This also rewrites system catalogs (also tables) and indices in pristine condition. Details in the Postgres Wiki:
Postgres has dedicated object size functions to measure db size:
SELECT pg_size_pretty(pg_database_size(mydb));