Scrivio Interview library
ScenarioAdvanced7 min read · updated 12 November 2026

You are moving a workload from Oracle to PostgreSQL. Both use MVCC, but differently. What operational differences in versioning should your teams expect?

Oracle updates rows in place and keeps old versions in undo, so its failure mode is a long query hitting ORA-01555. PostgreSQL writes a whole new row version into the table on every update and leaves the old one as a dead tuple, so it needs VACUUM to reclaim space, and long transactions do not fail but block cleanup and cause bloat. Teams must also plan for transaction ID wraparound, tune fillfactor and HOT updates on update-heavy tables, and change monitoring from undo usage to bloat, oldest transaction age and autovacuum activity.

Why this question is asked

On paper Oracle and PostgreSQL look the same: both give readers a snapshot and never make them wait for writers. In operation they behave very differently, because they store old versions in different places. Teams that move without knowing this are surprised by tables that keep growing, by an idle connection that hurts the whole database, and by a wraparound warning they have never heard of. Interviewers ask this to see whether we can prepare a team for those differences before they become incidents. In this answer, we will recap how each engine stores versions, then go through the consequences one by one: vacuum and bloat, long transactions, wraparound, update-heavy tables, and what to monitor.

1A Quick Recap: Where Each Engine Keeps Old Versions

In Oracle, an UPDATE changes the row in its block and writes the old values into the undo tablespace. The table itself stays the same size. Readers who need the old version rebuild it from undo, and once undo is old enough, it is simply overwritten. Cleanup is automatic and free, but a reader that needs very old undo can find it gone and fail with ORA-01555.

In PostgreSQL, an UPDATE does not change the existing row. It marks the old row version, called a tuple, as ended by this transaction (its xmax), and inserts a complete new tuple elsewhere in the table. A DELETE only marks the tuple. The old tuples stay in the table as dead tuples until VACUUM confirms no running transaction can still see them and frees the space for reuse.

SQL
-- PostgreSQL: one update leaves a dead tuple behind
UPDATE accounts SET balance = balance - 100 WHERE id = 42;
SELECT n_live_tup, n_dead_tup FROM pg_stat_user_tables WHERE relname = 'accounts';
-- 1000000 1 the old version of row 42 is still in the table
Where the old version lives
AspectOraclePostgreSQL
UPDATE writesRow changed in place, old values to undoNew tuple in the table, old tuple marked dead
CleanupUndo overwritten after retentionVACUUM frees dead tuples
Long query or transactionMay fail with ORA-01555Never fails, but blocks cleanup: bloat
Special riskUndo sizingTransaction ID wraparound
WatchUndo usage, V$UNDOSTATBloat, oldest xmin, autovacuum runs

2VACUUM and Autovacuum Become Part of Daily Life

Because dead tuples live in the table, someone must remove them. PostgreSQL's autovacuum daemon does this in the background. By default it vacuums a table when dead tuples exceed 50 rows plus 20 percent of the table (autovacuum_vacuum_scale_factor = 0.2). On a 100 million row table, that means 20 million dead tuples before cleanup starts, which is far too late for a busy table. So teams coming from Oracle need a new habit: tune autovacuum per table for large, hot tables.

SQL
ALTER TABLE orders SET (autovacuum_vacuum_scale_factor = 0.01,
autovacuum_vacuum_cost_limit = 2000);
-- vacuum after about 1 percent of rows are dead, and let it work faster

VACUUM frees space inside the table for new tuples, but it normally does not give the space back to the operating system. A table that bloated to three times its size stays that size until it is rewritten, for example with VACUUM FULL, which locks the table, or with an online tool such as pg_repack. Prevention is far cheaper than repair.

3Long Transactions: Bloat Instead of Errors

This is the most important behaviour change. In Oracle, a long-running report risks its own failure. In PostgreSQL, a long-running transaction never fails for this reason, but VACUUM cannot remove any dead tuple that the oldest open snapshot might still need, in any table of the database. So one forgotten transaction stops cleanup everywhere, and busy tables grow for as long as it stays open.

The worst offender is a connection left idle in transaction, for example a Java service that began a transaction, then waited on a slow HTTP call while holding it. Replication slots that a consumer has stopped reading and hot_standby_feedback from replicas with long queries hold cleanup back in the same way. The fix is mostly discipline plus guard rails.

SQL
-- Who is holding back cleanup?
SELECT pid, state, now() - xact_start AS age, left(query, 60) AS query
FROM pg_stat_activity
WHERE xact_start IS NOT NULL
ORDER BY xact_start
LIMIT 5;
-- 4182 idle in transaction 02:14:09 SELECT * FROM orders WHERE ...
ALTER DATABASE app SET idle_in_transaction_session_timeout = '5min';

4Transaction ID Wraparound

PostgreSQL stamps each tuple with 32-bit transaction ids, which means about 4 billion values, compared in a circle so that roughly 2 billion are in the past and 2 billion in the future. Before old tuples fall off that window, VACUUM must freeze them, marking them as visible to everyone. If freezing falls too far behind, PostgreSQL first warns and eventually refuses new transactions to protect the data.

Autovacuum normally handles this through anti-wraparound vacuums, triggered when a table's age passes autovacuum_freeze_max_age, 200 million by default. The danger is the same as for bloat: a long transaction or a stuck replication slot stops freezing too. So we monitor age(datfrozenxid) per database and alert well before it approaches a billion. Oracle teams have no equivalent concept, which is why this belongs in their training.

5Update-Heavy Tables: Fillfactor and HOT Updates

Because every update writes a new tuple, it would normally also add a new entry to every index on the table, which makes updates expensive. PostgreSQL avoids this with HOT, heap-only tuple, updates: if no indexed column changed and the new tuple fits on the same page, the indexes are not touched at all. Two design rules follow. We avoid indexing columns that change often, such as a last_seen timestamp, and we leave free space on each page with a lower fillfactor so the new version fits next to the old one.

SQL
ALTER TABLE sessions SET (fillfactor = 80); -- leave 20 percent of each page free
-- applies to new pages; rewrite the table to apply to existing ones
SELECT n_tup_upd, n_tup_hot_upd FROM pg_stat_user_tables WHERE relname = 'sessions';
-- 500000 460000 92 percent of updates were HOT

6Changing What We Monitor

Oracle dashboards that track undo tablespace usage and ORA-01555 counts have no meaning in PostgreSQL. The new dashboard tracks table and index bloat for the largest tables, dead tuples and last autovacuum time from pg_stat_user_tables, the age of the oldest transaction and of idle-in-transaction sessions, transaction id age per database, and replication slot lag. Each of these needs an alert with an owner, because the failure is slow and silent until it is serious.

7Follow-up questions

Is PostgreSQL's approach worse than Oracle's?

It is a different trade-off. PostgreSQL makes rollback instant and never fails a long query for lack of old versions, but it pays with vacuum work and the risk of bloat. Oracle keeps tables compact but needs undo sizing and can fail long queries. Neither is free; teams just need to manage the cost they actually have.

How do you find bloated tables?

The pgstattuple extension measures dead and free space exactly but reads the whole table. For a regular dashboard, estimate queries based on statistics are cheaper, and comparing a table's size with its expected size from row count and row width gives a good first signal.

Do Java connection pools make this worse?

They can, if a transaction is left open on a pooled connection. With Spring, keeping @Transactional methods short and never making remote calls inside them is the main defence, and idle_in_transaction_session_timeout catches the cases that slip through.

8Conclusion

In this answer, we saw that Oracle updates in place and keeps old versions in undo, while PostgreSQL writes new tuples into the table and leaves dead ones for VACUUM. That changes operations: autovacuum needs tuning on large tables, long or idle transactions cause bloat across the database instead of ORA-01555 errors, transaction id wraparound must be prevented by freezing, update-heavy tables benefit from HOT updates and a lower fillfactor, and monitoring moves from undo usage to bloat, oldest transaction age, autovacuum activity and xid age.

What to say in the interviewAbout 80 seconds aloud

Open with

The key difference is where old versions live. Oracle updates the row in place and puts the old values in undo, so the table stays compact and the risk is that a long query finds its undo overwritten and fails with ORA-01555.

Then, if they want more

PostgreSQL writes a new tuple for every update and leaves the old one in the table as a dead tuple, so VACUUM has to clean up. I would prepare teams for four things.

First, autovacuum needs per-table tuning, because the default 20 percent threshold is far too late for a hundred million row table, and bloat does not shrink by itself. Second, long transactions behave differently: nothing fails, but the oldest open snapshot stops cleanup across the whole database, so an idle-in-transaction connection from a Java service can bloat every hot table.

I would set idle_in_transaction_session_timeout and keep transactions short. Third, transaction id wraparound: ids are 32-bit, so autovacuum must freeze old tuples, and we alert on age of datfrozenxid long before it gets near a billion. Fourth, update-heavy tables need HOT updates, which means not indexing frequently changed columns and lowering fillfactor so new versions fit on the same page.

And monitoring changes from undo usage to bloat, dead tuples, oldest transaction age, autovacuum activity and replication slot lag.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "You are moving a workload from Oracle to PostgreSQL. Both use MVCC, but differently....": https://scrivio-interview-library.netlify.app/databases/oracle-and-sql-server/fff8395093/