select * from depesz;·
PostgreSQL 20 Adds Backend-Level Lock Statistics
Waiting for PostgreSQL 20 – Add backend-level lock statistics
Key Takeaway
Michael Paquier committed a patch on June 30, 2026 adding per-backend lock statistics to PostgreSQL 20, covering lock wait counts, wait times, and fastpath_exceeded counts.
Why It Matters
Per-backend lock statistics break down aggregate waits by process and can be joined with pg_stat_activity to diagnose contention in running sessions.
Technical Breakdown · Distilled from the original source
Querying lock statistics by process
pg_stat_get_backend_lock(pid)takes a backend PID and returns one row per lock type. It exposes the same metrics aspg_stat_lock: wait counts, cumulative wait times, andfastpath_exceededcounts.- The function can be called from another connection. Like
pg_stat_get_backend_io(), it can be joined withpg_stat_activityto examine lock statistics alongside activity information for each running backend.
Breaking down waits across three sessions
- The article demonstrates the feature on a development build using three
psqlsessions. The first holds anACCESS EXCLUSIVElock on tabletinside a transaction. The other two runSELECT * FROM tat different times and remain blocked until the transaction holding the lock ends. - The
relationrow inpg_stat_lockrecords two waits and await_timeof13525.1. Queries by PID show one wait per reader, withwait_timevalues of8849.524and4675.576. Both per-backend rows showNULLforstats_reset.
Flushing and persistence
- The patch builds on the backend statistics infrastructure introduced by commit
9aea73fc61d4and adds a flag topgstat_flush_backend()to control flushing of lock statistics. It bumps the catalog version but leavesPGSTAT_FILE_FORMAT_IDunchanged because backend statistics are never written to disk.
Source: select * from depesz;· depesz.com
PG Radar summarizes verified changes and impact. Read the original post for full technical details and code samples.