2024-04-03

Postgres Locks Explorer

Details/sources

All of the data in this page is derived from these tests, so is true by some definition of true. Notable is this test - given an arbitrary SQL statement, it determines via runtime inspection which locks are taken.

Thanks to kataklinger for this fix!

Locking at a high level
a = ACCESS EXCLUSIVE
b = ACCESS SHARE

Many SELECTs are queued up and
running concurrently:

queue(t=1) = | b       |
             | b[slow] |

A migration enters the queue:

queue(t=2) = | a |         |
             |   | b[slow] |

It blocks new SELECTs from happening
until b[slow] is completed:

queue(t=3) = | b | a |         |
             | b |   | b[slow] |
Key
 Statements
 Statements that acquire row level locks
 Table level locks
 Row level locks