Think of VACUUM in PostgreSQL and Undo Retention in Oracle as solving the same problem from opposite directions.
- PostgreSQL MVCC keeps old row versions in the table.
- Oracle keeps old row versions in Undo segments.
The challenge for both is:
"How long should old versions be kept for active transactions?"
PostgreSQL VACUUM
What happens after UPDATE?
Internally:
Table becomes:
The dead row is still present because some transaction might still need it.
VACUUM's Job
VACUUM:
- Finds dead tuples.
- Checks whether any transaction can still see them.
- Removes them from future visibility.
- Marks space reusable.
Why VACUUM Cannot Remove Rows Immediately
Assume:
T1 still sees the old row version.
If VACUUM deletes it:
Therefore VACUUM waits until all interested transactions finish.
Problem: Table Bloat
If VACUUM cannot clean:
Table grows:
This is called table bloat.
Common causes:
Oracle Undo Retention
Oracle stores previous values in Undo segments.
Update:
Results:
Undo Retention Parameter
Oracle has:
Meaning:
Not a guarantee in all configurations.
Why Oracle Needs Undo Retention
Suppose:
Update occurs:
Oracle reconstructs old data using undo.
If undo gets overwritten before query finishes:
More Undo Retention
Benefits:
✅ Long reports succeed
✅ Flashback queries succeed
✅ Long-running transactions remain consistent
Cost:
❌ Larger undo tablespace
Direct Comparison
| Feature | PostgreSQL VACUUM | Oracle Undo Retention |
|---|---|---|
| Stores old versions where? | Table itself | Undo tablespace |
| Cleanup mechanism | VACUUM | Undo overwrite |
| What consumes space? | Dead tuples | Undo blocks |
| Long query impact | Prevents cleanup | Requires undo retention |
| Failure mode | Table/index bloat | ORA-01555 |
| Space reclaimed by | VACUUM | Undo reuse |
| Admin tuning | autovacuum | undo_retention + undo size |
Example: 1 Million Updates
PostgreSQL
Creates:
Need:
otherwise:
Oracle
Creates:
Need:
otherwise:
for long consistent reads.
DBA Perspective
PostgreSQL Monitoring
Check dead tuples:
Check vacuum activity:
Oracle Monitoring
Check undo retention:
Check undo statistics:
Interview Answer
VACUUM in PostgreSQL removes obsolete row versions created by MVCC after they are no longer needed by any transaction. Its goal is to prevent table and index bloat and reclaim space for reuse.
Undo Retention in Oracle controls how long old row images stored in Undo segments are preserved so Oracle can reconstruct historical versions for consistent reads and flashback operations.
In one sentence:
PostgreSQL keeps old versions in the table and later removes them using VACUUM, whereas Oracle keeps old versions in Undo and preserves them for a configured retention period before reusing the space.
No comments:
Post a Comment