Skip to content

LWLock waits

Contention on PostgreSQL’s internal shared-memory data structures.

LWLock means a backend could not immediately acquire a lightweight lock that protects an internal shared-memory structure. It does not identify a SQL row or table lock, and pg_locks usually cannot name its owner.

Operator rulerepeat samples → isolate one hot tranche → correlate with workload

How to read this class

A single sample is ordinary scheduler noise. Treat the event as contention only when the same LWLock name recurs across consecutive samples and affects foreground sessions whose latency has increased.

  • Normal: brief appearances during WAL generation, snapshot acquisition, buffer lookup, vacuum, or checkpoint work.
  • Watch: the same event occupies at least 10% of active foreground backends in three consecutive 1-second snapshots.
  • Urgent: at least 25% of active foreground backends pile onto one event, waits persist beyond 5 seconds, or throughput collapses at the same time.

The percentages are operational triage thresholds, not PostgreSQL guarantees. Compare with the cluster’s own baseline and exclude background processes whose main loop is expected to wait.

Ten events worth recognizing

Event Protected resource Typical story
BufferContent Contents of one shared buffer Many sessions touch the same hot page
BufferMapping Buffer-table mapping partitions Working-set churn or broad concurrent scans
LockManager Heavyweight lock manager state Large lock fan-out, DDL, or lock storms
ProcArray Shared process/transaction array Snapshot and transaction-ID pressure
WALBufMapping WAL buffer page mapping WAL buffers turn over under write pressure
WALInsert WAL insertion state Many writers serialize while inserting WAL
WALWrite WAL buffer write coordination WAL flush/write path cannot keep up
XactSLRU Transaction-status SLRU pg_xact cache churn or old visibility checks
MultiXactMemberSLRU Multixact-member SLRU Heavy row-locking and multixact churn
SyncRep Synchronous replication wait queues Commit acknowledgements and sender state contend

Common misreads

  1. “LWLock means a leaked lock.” No. It is a short internal critical section; sustained recurrence is the signal.
  2. “The query shown owns the lock.” pg_stat_activity.query belongs to the waiter. The holder can be another backend inside a different source path.
  3. “More CPU fixes it.” Extra concurrency can intensify a shared-memory hotspot. First identify the protected resource and workload shape.
  4. pg_locks will reveal the blocker.” It covers heavyweight and predicate locks, not general LWLock ownership.

Start with BufferContent for a page-level hotspot and WALInsert for a write-heavy cluster.

Waiting to manage an extension’s space allocation in shared memory

Waiting to update the postgresql.auto.conf file

Waiting to read or update the current state of autovacuum workers

Waiting to ensure that a table selected for autovacuum still needs vacuuming

Waiting to read or update vacuum-related information for a B-tree index

Waiting to associate a data block with a buffer in the buffer pool

Waiting to read or update the last value set for a transaction commit timestamp

Waiting to access the commit timestamp SLRU cache

Waiting to read or update the pg_control file or create a new WAL file

Waiting to read or update the dynamic shared memory registry

Waiting to access dynamic shared memory registry’s dynamic shared memory allocator

Waiting to access dynamic shared memory registry’s shared hash table

Waiting to read or update information related to injection points

Waiting to read or update a process’ fast-path lock information

Waiting to read or update information about “heavyweight” locks

Waiting to access logical replication launcher’s dynamic shared memory allocator

Waiting to read or update the state of logical replication workers

Waiting to read or update shared multixact state

Waiting for I/O on a NOTIFY message SLRU buffer

Waiting to read or update NOTIFY messages

Waiting to access the NOTIFY message SLRU cache

Waiting to allocate a new OID

Waiting to choose the next subplan during Parallel Append plan execution

Waiting to synchronize workers during Parallel B-tree scan plan execution

Waiting to synchronize workers during Parallel Hash Join plan execution

Waiting for parallel query dynamic shared memory allocation

Waiting to access a parallel query’s information about type modifiers that identify anonymous record types

Waiting to access the list of predicate locks held by the current serializable transaction during a parallel query

Waiting for stats dynamic shared memory allocator access

Waiting for shared memory stats data access

Waiting for stats shared memory hash table access

Waiting to access predicate lock information used by serializable transactions

Waiting to access the shared per-process data structures (typically, to get a snapshot or report a session’s transaction ID)

Waiting to read or update a pg_internal.init relation cache initialization file

Waiting to read or update a pg_filenode.map file (used to track the filenode assignments of certain system catalogs)

Waiting to retrieve messages from the shared catalog invalidation queue

Waiting to add a message to the shared catalog invalidation queue

Waiting for I/O on a serializable transaction conflict SLRU buffer

Waiting to access the serializable transaction conflict SLRU cache

Waiting to access a shared TID bitmap during a parallel bitmap index scan

Waiting to find or allocate space in shared memory

Waiting to access the sub-transaction SLRU cache

Waiting to read or update information about the state of synchronous replication

Waiting to select the starting location of a synchronized table scan

Waiting to read or update the state of prepared transactions

Waiting to insert WAL data into a memory buffer

Waiting to read or update WAL summarization state

Waiting for WAL buffers to be written to disk

Waiting to update limits on transaction id and multixact consumption

Waiting for I/O on a transaction status SLRU buffer

Waiting to access the transaction status SLRU cache

Waiting to execute pg_xact_status or update the oldest transaction ID available to it

Waiting to allocate a new transaction ID