Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

What is lock escalation, which databases do it, and why does PostgreSQL not escalate row locks? What symptom would you see in SQL Server when it happens?

Lock escalation is when a database replaces many fine-grained locks, on rows or pages, with one coarse lock on the whole table or partition, to save lock-manager memory. SQL Server and Db2 do it; Oracle, MySQL InnoDB and PostgreSQL do not escalate row locks. PostgreSQL has no reason to, because a row lock is stored in the row's own header rather than in a lock table in memory. In SQL Server, the symptom is that a large update suddenly blocks all other access to the table, which shows up as a table-level X lock in sys.dm_tran_locks.

Why this question is asked

Lock escalation explains a puzzling class of incidents: a job that ran fine for months suddenly blocks the whole table once its data grows past some size. Interviewers ask this concept question because it checks whether we know how different databases store locks, and why advice that is right for SQL Server is irrelevant for PostgreSQL. In this answer, we will recap lock granularity, see why and when escalation happens, compare the main databases, explain why PostgreSQL does not need it, and look at the SQL Server symptom and how to spot it.

1A Quick Recap of Lock Granularity

Locks can cover different amounts of data. A row lock covers one row, a page lock covers one storage page of rows (8 KB in SQL Server), and a table lock covers everything. Fine-grained locks give the best concurrency, because two transactions touching different rows never conflict. But in databases that keep locks in a lock manager, each lock is a small structure in memory, roughly a hundred bytes in SQL Server, and a statement that updates ten million rows would need ten million of them.

So such databases also use intention locks. Before locking a row, a transaction takes an intention lock, such as IX (intent exclusive), on the page and the table. That lets the database check quickly whether someone wants the whole table without inspecting every row lock.

2What Escalation Does and When

Escalation trades concurrency for memory. When one statement has taken many locks on one object, the database tries to convert them into a single lock on the table (or on a partition, where that is enabled). If it succeeds, the row and page locks are released and the transaction holds one table lock instead.

In SQL Server, escalation is attempted when a single statement holds roughly 5,000 locks on one table or index, or when lock memory crosses a threshold of the available memory; if the attempt fails because of conflicting locks, it tries again after more locks are taken. The exact thresholds and their memory rules vary by version and configuration, so check your version's documentation. Escalation can be controlled per table with ALTER TABLE ... SET (LOCK_ESCALATION = TABLE, AUTO or DISABLE).

Step throughSQL Server lock escalation
  1. Statement takes row locksplus IX on page and table
  2. About 5,000 locks on one object, or lock memory pressure?
    Yestry to escalateNokeep taking row locks
  3. Other sessions hold conflicting locks on the table?
    Yesescalation fails, retried laterNotable X lock granted
  4. Row and page locks releasedone table lock now held until commit
  5. Everyone else waitsreaders and writers on that table queue

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

3Which Databases Escalate

SQL Server and Db2 escalate, with Db2 controlling it through the LOCKLIST and MAXLOCKS settings. Oracle does not escalate row locks: it stores row locks in the data block itself, in the block's interested transaction list, so there is no per-row memory to save. MySQL InnoDB does not escalate either; it keeps row locks as bitmaps per index page, so locking many records on the same page costs little extra memory.

PostgreSQL also never escalates row locks. That does not mean locking many rows is free in every database, only that the cost shows up elsewhere.

Lock escalation across databases
DatabaseEscalates row locks?Where row locks live
SQL Serveryes, to table or partitionlock manager memory
Db2yes, controlled by MAXLOCKSlock list memory
Oraclenoin the data block (transaction list)
MySQL InnoDBnobitmaps per locked index page
PostgreSQLnoin the row header (xmax, MultiXact)

4Why PostgreSQL Does Not Escalate

When PostgreSQL locks a row, it writes the locking transaction's id into the row's xmax field and sets flag bits in the row header. If several transactions share the lock, it stores them in a MultiXact entry. A transaction that needs the row and finds it locked waits on the holder's transaction id, not on a per-row entry in shared memory. So the lock manager never fills up with row locks, and there is nothing to escalate.

There are still costs. Writing lock marks into millions of rows dirties those pages and generates write-ahead log, so a SELECT ... FOR UPDATE over a million rows is real write I/O. Table-level locks do live in shared memory, sized by max_locks_per_transaction, so a query that touches thousands of partitions can fail with an out of shared memory error. And under SERIALIZABLE isolation, PostgreSQL's predicate locks (SIRead locks) are kept in memory and are promoted from tuple to page to whole relation when there are too many, which is a form of escalation that causes more false serialization failures rather than blocking.

SQL
BEGIN;
SELECT * FROM orders WHERE created_at < '2026-01-01' FOR UPDATE; -- 1,200,000 rows
SELECT count(*) FROM pg_locks WHERE pid = pg_backend_pid(); -- a handful: table and virtualxid locks
-- the 1.2 million row locks are in the rows, not in pg_locks

5The SQL Server Symptom

In SQL Server the incident looks like this: a large UPDATE or DELETE starts, and after a moment every other query on that table, even reads of unrelated rows under locking READ COMMITTED, starts waiting. In sys.dm_tran_locks we see the job's session holding a lock with resource_type OBJECT and request_mode X on the table, instead of thousands of KEY locks, and the waiting sessions requesting locks on the same object. The lock_escalation event in Extended Events records each escalation, with the number of locks that triggered it.

The usual fixes are to keep each statement under the escalation threshold by batching, to enable partition-level escalation on partitioned tables, or to use read committed snapshot so that readers at least stop waiting.

SQL
SELECT request_session_id, resource_type, request_mode, request_status
FROM sys.dm_tran_locks
WHERE resource_database_id = DB_ID() AND resource_associated_entity_id = OBJECT_ID('dbo.Orders');
-- 57 OBJECT X GRANT <- the escalated job
-- 63 OBJECT IS WAIT <- an API read waiting

6Follow-up questions

Is disabling lock escalation in SQL Server a good fix?

Sometimes, for a specific table with a known workload, but it moves the problem to memory: the statement keeps millions of row locks, lock memory grows, and under pressure SQL Server can still escalate or fail with out-of-locks errors. Batching the work so each statement stays well under the threshold is usually the safer fix.

Does page-level locking in SQL Server escalate to the table too?

Yes. Escalation goes from row or page locks directly to the table, or to the partition when LOCK_ESCALATION = AUTO is set on a partitioned table. It never goes from rows to pages.

Why can locking many rows in PostgreSQL still hurt?

Each locked row gets its header modified, which dirties pages, writes WAL and may require MultiXact storage, and other transactions that want those rows wait as usual. It does not block the whole table, but a huge FOR UPDATE is still heavy I/O and holds many rows hostage until commit.

7Conclusion

In this answer, we saw that lock escalation replaces many row or page locks with one table or partition lock to save lock-manager memory. SQL Server escalates at about 5,000 locks per statement and object or under memory pressure, and Db2 escalates too, while Oracle, InnoDB and PostgreSQL do not escalate row locks because they store them in data blocks, page bitmaps or row headers. PostgreSQL still pays in write I/O, shared-memory table locks and predicate lock promotion under SERIALIZABLE, and in SQL Server the symptom is a sudden table-level X lock visible in sys.dm_tran_locks.

What to say in the interviewAbout 80 seconds aloud

Open with

Lock escalation is when the database swaps lots of fine-grained locks, row or page locks, for one lock on the whole table or partition, to save lock-manager memory.

Then, if they want more

SQL Server does it when a single statement holds roughly five thousand locks on one object or lock memory is under pressure, though the exact rules depend on the version, and Db2 does it too based on its lock list settings.

Oracle doesn't escalate row locks because they live in the data block, InnoDB doesn't because it keeps lock bitmaps per page, and PostgreSQL doesn't because a row lock is just the transaction id written in the row header's xmax, with waiters waiting on that transaction id. So there's no per-row memory to save.

Locking millions of rows in PostgreSQL still costs page writes and WAL, and under SERIALIZABLE the predicate locks can get promoted from tuple to page to relation, which shows up as extra serialization failures.

In SQL Server the symptom is that a big update or delete suddenly blocks everything on the table, and in sys.dm_tran_locks you see the job holding an OBJECT-level X lock with other sessions waiting on it. The usual fix is batching below the threshold.

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 "What is lock escalation, which databases do it, and why does PostgreSQL not escalate row...": https://scrivio-interview-library.netlify.app/databases/database-locking/3258346944/