Skip to main content
Glama

Locks and blocking

pg_locks
Read-onlyIdempotent

Diagnose hung PostgreSQL queries by showing lock waits as a blocking tree with waiting sessions, lock holders, and root blockers.

Instructions

Show lock waits as a blocking tree: which sessions wait, for how long and for which lock or table, who holds it (pid, state, query, how long its transaction has been open), the root blockers with how many sessions each one blocks, the strong (ACCESS EXCLUSIVE) locks currently granted on user tables, and a count of locks by mode.

Use it when queries hang or pg_activity shows blocked_by. The wait time is counted from the start of the waiting statement, so it is an upper bound. With only_blocked=false it also lists the table locks every session holds or wants.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

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

Input Schema

NameRequiredDescriptionDefault
limitNo
connectionNo
only_blockedNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.3/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations only declare the tool is a safe, idempotent read; the description adds real behavioral context beyond that. It warns that wait time is an upper bound because it counts from the start of the waiting statement, and it discloses that `only_blocked=false` expands results to every table lock each session holds or wants, which changes result volume substantially.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The content is front-loaded: what the tool shows comes first, then the usage trigger, then the caveat and the mode switch. The long enumerated output list is dense but each element tells the agent what to expect, so little is wasted; only minor tightening is possible.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema, the description must describe returns, and it does so thoroughly by listing the tree's fields and counts. The only real gaps are the meaning of `limit` and which connection `connection` selects, plus no mention of result-size behavior when many sessions are blocked.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the description must carry all parameter meaning. It fully explains `only_blocked` (blocked-only tree vs. all locks held or wanted), but `limit` and `connection` are never mentioned, leaving two of three parameters undocumented anywhere.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a concrete verb and resource: 'Show lock waits as a blocking tree,' then enumerates the exact contents (waiting sessions, holders, root blockers, ACCESS EXCLUSIVE locks, lock counts by mode). It also separates this tool from `pg_activity`, so an agent can pick between the two without opening a schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives a clear trigger: 'Use it when queries hang or pg_activity shows blocked_by,' which explicitly routes the agent here from a sibling. It also explains the `only_blocked=false` variant as a broader mode. There is no explicit statement of when NOT to use it, so it falls short of a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.