Senior
What happens to remote rows in PostgreSQL?
sobes.tech AI
Answer from AI
In PostgreSQL, deleted rows are not physically removed immediately after a DELETE or UPDATE operation. Instead, they become 'dead tuples' and remain in the table until the VACUUM operation is performed.
This is related to the MVCC (Multi-Version Concurrency Control) mechanism, which allows transactions to see a consistent view of the data without locking.
What happens:
- When deleting or updating, a new version of the row is created, and the old one is marked as deleted but remains physically in the table.
- These 'dead' rows occupy space and can slow down operations.
- The VACUUM command cleans up these rows, freeing space for reuse.
Thus, deleted rows in PostgreSQL are not immediately physically removed but are marked for deletion and will be cleaned up later during maintenance.