currentLocks

Return current locks (pg_locks) joined with the holding backend's query and user, plus which pids are blocking each waiting lock; use to diagnose lock contention.

read-onlyany connectionsweeps replication groupsweeps groupcan return data values

Synopsis

currentLocks([pid])

Description

Return current locks (pg_locks) joined with the holding backend's query and user, plus which pids are blocking each waiting lock; use to diagnose lock contention. Given a pid, returns that backend's locks together with every backend blocking it transitively, each tagged with chain_depth: 0 is the pid asked about, and the largest depth is the backend at the root of the pile-up, which is the one to look at first.

This operation can return values that came from your data. It never changes anything and never returns rows, but read what reaches the caller before connecting it to a database whose contents are sensitive.

Parameters

pid optionalinteger
restrict to this backend and its transitive blockers, resolved through pg_blocking_pids. Omit for every lock in the cluster

Also accepts connection, replication_group, group, role, described once under arguments every tool takes.

Output

Lock rows, newest blocking chain first. An absent extension or a missing grant is reported as {error, hint} instead.

FieldType
locksarray | null

Scope

This reading is instance-wide -- every database on the same postmaster returns it identically, so asking each of them in turn repeats one answer. The counters here are each server's own, so members of a replication group legitimately disagree and the answer is their sum, not the primary's copy.

Example mocked data

Request

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "currentLocks",
    "arguments": {}
  }
}

Result

{
  "locks": [
    {
      "pid": 51877,
      "chain_depth": 1,
      "lock_type": "transactionid",
      "relation": null,
      "mode": "ShareLock",
      "granted": false,
      "wait_start": "2026-09-15T10:04:20Z",
      "blocked_by": [
        51702
      ],
      "user": "app_rw",
      "application_name": "checkout-api",
      "query": "UPDATE shop.orders SET status = $1 WHERE id = $2"
    },
    {
      "pid": 51702,
      "chain_depth": 0,
      "lock_type": "transactionid",
      "relation": null,
      "mode": "ExclusiveLock",
      "granted": true,
      "wait_start": null,
      "blocked_by": [],
      "user": "batch",
      "application_name": "nightly-reconcile",
      "query": "COMMIT"
    }
  ]
}

Invented values on a fictional shop database, shaped by and checked against this tool's output schema. Real output is returned as structuredContent to clients that negotiate MCP 2025-06-18 or later.

See also

diskUsage, databaseSize, serverSettings, currentActivity, databaseStats, statementStats, wraparoundStatus, progressStats, ioStats, checkpointStats, tableIOStats, hostCapacity, bufferCacheSummary, bufferCacheContents