Multi-version Concurrency Control

COMP9315 21T1 ♢ MVCC ♢ [0/10]
❖ Multi-version Concurrency Control

Multi-version concurrency control (MVCC) aims to

Achieves this by Main difference between MVCC and standard locking:
COMP9315 21T1 ♢ MVCC ♢ [1/10]
❖ Multi-version Concurrency Control (cont)

WTS = timestamp of tx that wrote this data item

Chained tuple versions:   tupoldest → tupolder → tupnewest

When a reader Ti is accessing the database

COMP9315 21T1 ♢ MVCC ♢ [2/10]
❖ Multi-version Concurrency Control (cont)

When a writer Ti attempts to change a data item


Some MVCC versions also maintain RTS (TS of last reader)
COMP9315 21T1 ♢ MVCC ♢ [3/10]
❖ Multi-version Concurrency Control (cont)

Advantage of MVCC

Disadvantages of MVCC Despite apparent disadvantages, MVCC is very effective.
COMP9315 21T1 ♢ MVCC ♢ [4/10]
❖ Multi-version Concurrency Control (cont)

Removing old versions:

When to make this check? PostgreSQL uses the latter (vacuum).
COMP9315 21T1 ♢ MVCC ♢ [5/10]
❖ Concurrency Control in PostgreSQL

PostgreSQL uses two styles of concurrency control:

From the SQL (PLpgSQL) level:
COMP9315 21T1 ♢ MVCC ♢ [6/10]
❖ Concurrency Control in PostgreSQL (cont)

PostgreSQL provides read committed and serializable isolation levels.

Using the serializable isolation level, a select:

Using the serializable isolation level, an update fails: The transaction containing the update must then rollback and re-start.
COMP9315 21T1 ♢ MVCC ♢ [7/10]
❖ Concurrency Control in PostgreSQL (cont)

Implementing MVCC in PostgreSQL requires:

COMP9315 21T1 ♢ MVCC ♢ [8/10]
❖ Concurrency Control in PostgreSQL (cont)

Rules for a tuple to be visible to Ti :

For details, see: backend/access/heap/heapam_visibility.c
COMP9315 21T1 ♢ MVCC ♢ [9/10]
❖ Concurrency Control in PostgreSQL (cont)

Tx's always see a consistent version of the database.

But may not see the "current" version of the database.

E.g. T1 does select, then concurrent T2 deletes some of T1's selected tuples

This is OK unless tx's communicate outside the database system.

E.g. T1 counts tuples; T2 deletes then counts; then counts are compared

Use locks if application needs every tx to see same current version

COMP9315 21T1 ♢ MVCC ♢ [10/10]


Produced: 15 Apr 2021