locks collector exposes metrics about PostgreSQL locks held by database connections.
Status
Default: EnabledMetrics
pg_locks_count
Type: GaugeDescription: Number of locks currently held Labels:
datname- Database namemode- Lock mode (see below)
Lock Modes
The collector tracks all PostgreSQL lock modes:accesssharelock- Acquired bySELECTstatementsrowsharelock- Acquired bySELECT FOR UPDATE/SHARErowexclusivelock- Acquired byUPDATE,DELETE,INSERTshareupdateexclusivelock- Acquired byVACUUM,CREATE INDEX CONCURRENTLYsharelock- Acquired byCREATE INDEXsharerowexclusivelock- Acquired byCREATE TRIGGERexclusivelock- Blocks concurrentSELECT FOR UPDATEaccessexclusivelock- Acquired byDROP TABLE,TRUNCATE,VACUUM FULL,LOCK TABLEsireadlock- Used by serializable transactions
SQL Query
PostgreSQL Versions
Supported: All versionsRequired Permissions
The monitoring user needs:- Access to
pg_locksview - Access to
pg_databasecatalog
Example Output
Use Cases
Detecting Lock Contention
High lock counts can indicate:- Long-running transactions
- Lock contention and blocking queries
- Connection pooling issues
- DDL operations blocking queries