All glossary terms

Multiversion concurrency control (MVCC)

What is MVCC in PostgreSQL?

MVCC lets reads and writes run at the same time: each statement sees a snapshot of the data, and updates write new row versions instead of overwriting rows in place.

Multiversion concurrency control (MVCC) is how PostgreSQL keeps concurrent transactions consistent without making them wait for each other. Each statement sees a snapshot of the data as it was at a point in time, so reading never blocks writing and writing never blocks reading.

Internally, an UPDATE writes a new version of the row and marks the old version as expired. The hidden system columns xmin and xmax record which transactions created and expired each version. Old versions stay in the table until VACUUM removes them, which is why very long transactions can make tables grow.

Example

The example reads the hidden xmin column before and after an UPDATE. The value changes because the update wrote a new row version stamped with the updating transaction's ID.

CREATE TABLE accounts (id int PRIMARY KEY, balance int);
INSERT INTO accounts VALUES (1, 100);
SELECT xmin, xmax, * FROM accounts;

UPDATE accounts SET balance = 90 WHERE id = 1;
SELECT xmin, xmax, * FROM accounts;

Plain SQL for stock PostgreSQL 16 or 17, no extensions needed. Run it in an empty database you can throw away.

Sources

Official PostgreSQL documentation (in English).

Related terms