Locks
PolarDB for PostgreSQL uses two categories of locks: lightweight locks (lwlocks) and regular locks. When heavy lock contention occurs, identify the lock category first, then use the appropriate view to locate the blocking process.
Lock categories
| Category | How to identify | Where to investigate |
|---|---|---|
| Lightweight lock (lwlock) | wait_event = lwlock in polar_stat_activity | See Wait events for a full list of lwlock names |
| Regular lock | wait_event in polar_stat_activity | wait_object field (blocking process) or pg_locks view |
Both lock categories surface throughpolar_stat_activity. Check thewait_eventcolumn to determine which category applies and to get the specific lock or lwlock name.
Diagnose lwlock contention
When the wait_event column value is lwlock, refer to the Wait events topic for definitions of each lwlock name and guidance on resolving contention.
Diagnose regular lock contention
When lock contention occurs with a regular lock, use one of the following methods to identify the blocking process.
Find the blocking process in polar_stat_activity
The wait_object field in polar_stat_activity contains the process holding the lock. Look up that process in the same view to see the query it is running.
Find the blocking process in pg_locks
pg_locks provides a lower-level view of all active locks. You can join it with polar_stat_activity to see both the waiting process and the blocking process side by side.
What's next
After identifying the blocking process, check its query and decide whether to wait for it to finish or take action to resolve the contention. For lwlock contention details and resolution strategies, see Wait events.