Scrivio Interview library
InternalsFoundations7 min read · updated 12 November 2026

Every PostgreSQL row version has hidden columns xmin and xmax. Explain what they hold and how a SELECT decides whether it can see a row version.

xmin holds the id of the transaction that created a row version, and xmax holds the id of the transaction that deleted or updated it (or locked it), or 0 if none. A SELECT uses its snapshot, a record of which transactions had committed when it started, to decide visibility: a version is visible if its xmin committed before the snapshot and its xmax is empty, aborted, or not committed from the snapshot's point of view. Commit status comes from pg_xact and is cached on the row in hint bits.

Why this question is asked

MVCC is the reason PostgreSQL readers never wait for writers, and xmin and xmax are the two numbers that make it work. Once we understand them, many puzzling behaviours make sense: why a table grows after updates, why a long transaction causes bloat, and why a plain SELECT can write to disk. Interviewers ask this internals question to check that we know how visibility is really decided. In this answer, we will look at the hidden columns on a real row, see what a snapshot contains, walk through the visibility rule with examples, and see where commit status comes from.

1Looking at the Hidden Columns

Every row version in a PostgreSQL table, called a tuple, carries a header with system columns we do not see with SELECT *. We can ask for them by name. xmin is the transaction id (xid) that inserted this version. xmax is the xid that deleted it, replaced it with an UPDATE, or locked it with SELECT FOR UPDATE; it is 0 when nothing has. ctid is the physical location of the version: page number and position in the page.

SQL
SELECT xmin, xmax, ctid, * FROM orders WHERE id = 1;
-- xmin | xmax | ctid | id | status
-- 7001 | 0 | (0,1) | 1 | NEW
BEGIN;
UPDATE orders SET status = 'PAID' WHERE id = 1;
SELECT txid_current(); -- 7050 (pg_current_xact_id() in newer versions)
COMMIT;
SELECT xmin, xmax, ctid, * FROM orders WHERE id = 1;
-- 7050 | 0 | (0,2) | 1 | PAID

Notice that after the UPDATE we see a different tuple at a new ctid. The old version at (0,1) still exists with xmin 7001 and xmax 7050, but our new snapshot no longer sees it. An UPDATE in PostgreSQL is really an insert of a new version plus setting xmax on the old one.

2What a Snapshot Records

Visibility is decided against a snapshot, taken at the start of each statement in READ COMMITTED, or at the first statement of the transaction in REPEATABLE READ and SERIALIZABLE. A snapshot is small. It holds xmin, the lowest transaction id that was still running when the snapshot was taken; xmax, one past the highest transaction id that had been assigned; and the list of transaction ids between them that were still in progress.

With those three things, a snapshot can classify any xid. Anything below the snapshot's xmin had finished, committed or aborted, before the snapshot. Anything at or above its xmax had not started yet, so it is invisible. Anything in between is visible only if it is not in the in-progress list. We can see one with pg_current_snapshot().

SQL
SELECT pg_current_snapshot(); -- 7048:7053:7048,7051
-- xmin 7048, xmax 7053, transactions 7048 and 7051 were still running

3The Visibility Rule, Step by Step

For each tuple, a SELECT asks two questions. First, is the creating transaction, xmin, visible to me? It must have committed, and from my snapshot's point of view it must have finished before I started. If xmin aborted, or was still running when my snapshot was taken, the tuple does not exist for me. (Our own transaction's changes are a special case: we always see our own writes.)

Second, has the tuple been removed for me? If xmax is 0, nobody deleted it, so it is visible. If xmax belongs to a transaction that aborted, the delete never happened. If xmax is only a lock, from SELECT FOR UPDATE, the row is still there. If xmax committed before my snapshot, the tuple is gone for me. And if xmax is in progress or committed after my snapshot was taken, I still see the tuple, because for me that delete has not happened yet.

Step throughIs this tuple visible to my snapshot?
  1. Did xmin commit before my snapshot?
    YesCheck xmaxNoNot visible
  2. Is xmax 0, aborted, or only a lock?
    YesVisibleNoCheck when xmax committed
  3. Did xmax commit before my snapshot?
    YesNot visible: deleted for meNoVisible: the delete is in my future

3 steps in order. Play them, or step through them one at a time.

Our own transaction's inserts and deletes are handled as a special case.

That last case is what lets a long report keep seeing yesterday's rows while other transactions update them, and it is also why those old versions cannot be vacuumed while the report runs.

4A Worked Example With Two Sessions

Let us apply the rule. The row (id 1, NEW) has xmin 7001, which committed long ago. Session A, at REPEATABLE READ, takes a snapshot. Then session B updates the row in transaction 7050 and commits.

SQL
-- Session A -- Session B
BEGIN ISOLATION LEVEL REPEATABLE READ;
SELECT status FROM orders WHERE id = 1; -- NEW
UPDATE orders SET status = 'PAID' WHERE id = 1;
COMMIT; -- xid 7050
SELECT status FROM orders WHERE id = 1; -- NEW (still)
COMMIT;
SELECT status FROM orders WHERE id = 1; -- PAID

For session A's second SELECT, the old tuple has xmin 7001 (committed before the snapshot: exists) and xmax 7050 (not finished when A's snapshot was taken: the delete is in A's future), so it is visible. The new tuple has xmin 7050, also not visible to A's snapshot, so it is skipped. After A commits, its next statement takes a fresh snapshot in which 7050 has committed, and the rule flips.

5Where Commit Status Comes From: pg_xact and Hint Bits

xmin and xmax are only ids; they do not say whether the transaction committed. That information lives in pg_xact (called pg_clog before PostgreSQL 10), which stores two bits per transaction: in progress, committed, aborted, or sub-committed. Looking it up for every tuple on every read would be expensive.

So the first time a backend checks a tuple and finds that its xmin or xmax has definitely committed or aborted, it sets hint bits in the tuple header to remember the answer. Later readers see the hint bits and skip the lookup. Setting them changes the page, which is the reason a plain SELECT can make pages dirty and cause writes.

6Follow-up questions

Why can a plain SELECT cause disk writes?

Because of hint bits. The first reader to see a tuple after its transaction finished looks up the status in pg_xact and records it in the tuple header, which marks the page dirty. The page is later written to disk by the background writer or a checkpoint, and with data checksums or wal_log_hints on, it may also produce a WAL record. So the first full scan after a large bulk load often writes almost as much as it reads. Running VACUUM after the load sets the hint bits once.

What does ctid tell you after an UPDATE?

The ctid is the physical address of a tuple version, as page number and item number. After an UPDATE, the visible version has a new ctid because a new tuple was written. If the new version fits on the same page and no indexed column changed, it is a HOT update: indexes keep pointing to the old item, which redirects to the new one. ctid is useful for debugging, but it changes after updates and VACUUM FULL, so it must never be used as a stable row id.

What does xmax mean when a row was only locked?

SELECT FOR UPDATE or FOR SHARE sets xmax to the locking transaction and sets flags in the header saying it is a lock, not a delete. Readers ignore lock-only xmax values when deciding visibility. With several lockers, xmax holds a MultiXact id, which points to a list of transactions.

7Conclusion

In this answer, we saw that each tuple carries xmin, the transaction that created it, and xmax, the transaction that deleted, updated or locked it, or 0. A snapshot records its xmin, its xmax and the transactions in progress when it was taken, and a SELECT sees a tuple if its xmin committed before the snapshot and its xmax is empty, aborted, a lock, or not committed from the snapshot's point of view. Commit status comes from pg_xact and is cached in hint bits, which is why reads can write. We can inspect all of this with SELECT xmin, xmax, ctid, * FROM orders.

What to say in the interviewAbout 90 seconds aloud

Open with

Every tuple in PostgreSQL has hidden system columns. xmin is the transaction id that created that row version, and xmax is the transaction id that deleted it or replaced it with an update, or locked it, and it is 0 if none has.

Then, if they want more

An UPDATE writes a new tuple with the updater as xmin and sets xmax on the old one. Visibility is decided against a snapshot, which records the lowest transaction still running, one past the highest assigned id, and the list of ids in progress at that moment.

For a tuple to be visible, its xmin must have committed before my snapshot, in other words it is below the snapshot's xmax, not in the in-progress list, and committed.

Then I check xmax: if it is 0, aborted, only a lock, or belongs to a transaction that was still running or had not started when my snapshot was taken, I still see the tuple; if xmax committed before my snapshot, the tuple is gone for me.

The commit status itself comes from pg_xact, formerly pg_clog, and after the first lookup PostgreSQL caches it in hint bits on the tuple, which is why a plain SELECT can dirty pages. I can see all of it with SELECT xmin, xmax, ctid, * FROM orders WHERE id = 1.

About this answer

Last updated
12 November 2026
Versions it names
PostgreSQL 10
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.
Official documentation
PostgreSQL documentation
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 "Every PostgreSQL row version has hidden columns xmin and xmax. Explain what they hold...": https://scrivio-interview-library.netlify.app/databases/postgresql/b9b1b8547b/