It's a bit complicated but I'll give you my layman explanation.
Most (all?) database systems these days use Multi-Version Concurrency Control (MVCC). This means if you have one connection UPDATEing a row while another connection is SELECTing that row the database will keep before and after copies of the row so that the SELECTing connection sees the row as it was when the transaction started and the UPDATEing connection sees the updated row. Once both connections/transactions end, the updated row is now the latest version and all future connections will see that.
Now, what happens to the old row? You don't want to delete it and reorganise the physical data on disk during either of the above transactions as that would add a variable performance degradation to each mutation (UPDATE/DELETE/INSERT) which isn't ideal. Postgres deals with this by having the DB administrator perform a manual VACUUM command while traffic on the DB is low. This cleans up the table itself and any indexes, removing dead rows and index entries.
The feature added in Postgres 13 is parallel vacuuming. This means if a table has multiple indexes they can all be vacuumed at the same time, seriously reducing the time it takes to vacuum a table with multiple indexes.
The vacuum is normally performed automatically by a special process which weighs system load versus urgency and is generally pretty good at keeping things running smoothly without manual intervention being required.
My understanding is that vacuuming is a bugbear of PostgreSQL as with a constant high write load it can impact performance substantially. How do other RDBMSes handle MVCC stale row cleanup?
A constant high write load will impact anything's performance substantially and an RDBMS isn't the best solution for every problem. There are other ways to handle MVCC but they aren't better than the way PostgreSQL does it and they are probably worse. PostgreSQL gives you the ability to fine tune how garbage collection runs to suit a wide variety of uses.
20
u/BinaryRockStar Sep 24 '20
It's a bit complicated but I'll give you my layman explanation.
Most (all?) database systems these days use Multi-Version Concurrency Control (MVCC). This means if you have one connection
UPDATEing a row while another connection isSELECTing that row the database will keep before and after copies of the row so that theSELECTing connection sees the row as it was when the transaction started and theUPDATEing connection sees the updated row. Once both connections/transactions end, the updated row is now the latest version and all future connections will see that.Now, what happens to the old row? You don't want to delete it and reorganise the physical data on disk during either of the above transactions as that would add a variable performance degradation to each mutation (
UPDATE/DELETE/INSERT) which isn't ideal. Postgres deals with this by having the DB administrator perform a manualVACUUMcommand while traffic on the DB is low. This cleans up the table itself and any indexes, removing dead rows and index entries.The feature added in Postgres 13 is parallel vacuuming. This means if a table has multiple indexes they can all be vacuumed at the same time, seriously reducing the time it takes to vacuum a table with multiple indexes.