Optimizing storage and managing cleanup
Transactions are an integral part of the PostgreSQL system. However, transactions come with a small price tag attached. As we’ve already shown in this chapter, sometimes, concurrent users will be presented with different data. Not everybody will get the same data returned by a query. In addition to this, DELETE
and UPDATE
are not allowed to actually overwrite data, since ROLLBACK
would not work. If you happen to be in the middle of a large DELETE
operation, you cannot be sure whether you will be able to use COMMIT
or not. In addition to this, data is still visible while you perform the DELETE
operation, and sometimes, data is even visible once your modification has long since finished.
Consequently, this means that cleanup has to happen asynchronously. A transaction cannot clean up its own mess, and any COMMIT
/ROLLBACK
operation might be too early to take care of dead rows.
The solution to this problem is VACUUM
. The following code...