PostgreSQL – Vacuuming Database Termination

postgresql

I was doing database vacuuming to free up disk space for postgreSQL database. The corresponding table size was large and it was taking long time for vacuuming to get complete. But unfortunately because of slow network connection , the network connection got terminated which resulted vacuuming getting terminated in middle.

I am worried whether any database corruption will occur. Can I once again issue database vacuum command?

vacuum full message_log;

Please clarify.

Best Answer

I am worried whether any database corruption will occur

No database corruption will occur due to an interrupted VACUUM, whether it was whole-database or just one table, and whether it was a an ordinary VACUUM or a VACUUM FULL. VACUUM is completely safe to abort at any time. At worst it'll leave some extra table and index bloat that a later VACUUM run (that completes) will clean up.

In fact, it's also crash-safe so long as the underlying storage subsystem respects fsync(), which is a basic requirement for PostgreSQL reliability. It wouldn't even matter if PostgreSQL crashed, or if the machine was reset suddenly. In that case PostgreSQL would just recover from transaction logs.