get_lock_monitoring
Monitor current locks and identify blocked sessions in PostgreSQL databases to diagnose lock contention and prevent deadlocks.
Instructions
[Tool Purpose]: Monitor current locks and potential deadlocks in PostgreSQL
[Exact Functionality]:
List all current locks held and waited for by sessions
Show blocked and blocking sessions, lock types, and wait status
Help diagnose lock contention and deadlock risk
Filter results by granted status, state, mode, lock type, or username
[Required Use Cases]:
When user requests "lock monitoring", "deadlock check", "blocked sessions", etc.
When diagnosing performance issues due to locking
When checking for blocked or waiting queries
When filtering specific types of locks or users
[Strictly Prohibited Use Cases]:
Requests for killing sessions or force-unlocking
Requests for lock configuration changes
Requests for historical lock data (only current state is shown)
Args: database_name: Database name to analyze (uses default database if omitted) granted: Filter by granted status ("true" or "false") state: Filter by session state ("active", "idle", "idle in transaction", etc.) mode: Filter by lock mode ("AccessShareLock", "ExclusiveLock", etc.) locktype: Filter by lock type ("relation", "transactionid", "virtualxid", etc.) username: Filter by specific username
Returns: Table-format information showing PID, user, database, lock type, relation, mode, granted, waiting, and blocked-by info
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database_name | No | ||
| granted | No | ||
| state | No | ||
| mode | No | ||
| locktype | No | ||
| username | No |