PostgreSQL drop table command is not reducing DB size

Beautiful Mind picture Beautiful Mind · Sep 25, 2013 · Viewed 10.7k times · Source

I dropped a couple of tables from my Postgres database. However, before dropping tables the size of the database was 6586kB, and after dropping the table size of the database remains same. I think size should be reduced.

What do I need to do to get the actual size?

I know about the VACUUM command. Do I need to use that? And how?

Answer

Erwin Brandstetter picture Erwin Brandstetter · Sep 25, 2013

VACUUM (or VACUUM FULL) is hardly useful in this case, since it only reclaims space from within tables.

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 the client tool vacuumdb with the --full option:

vacuumdb -f mydb

On Postgres 9.0 or later, this also rewrites indices in prestine condition. Details in the Postgres Wiki: http://wiki.postgresql.org/wiki/VACUUM_FULL

That's how Postgres measures db size: with dedicated object size functions:

SELECT pg_size_pretty(pg_database_size(mydb));