published fresh until

canceling statement due to statement timeout: which Postgres fix?

Summary As of October 2026, Postgres statement timeouts cover the whole statement, lock timeouts cover individual lock waits, and reserved-slot failures reject new ordinary connections. Inspect the matching limit before changing settings; none proves that a global timeout increase is the fix (checked 2026-10-20).

Not for local Supabase stacks per worktree, see supabase-local-stack-per-worktree

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

Choose the branch by the complete message and operation. Commands are reader-side examples; none was executed for this draft.

Versions and status, checked 2026-10-20

ComponentOfficial reference fetched todayLicence / price scope
PostgreSQLVersion 18 client settings and connection settings; documentation baseline, not an installed-version claimPostgreSQL License; hosting prices not compared
Supabase-hosted PostgresOfficial reserved-slots troubleshooting verifies the legacy messageHosted server version unknown; no paid tier prescribed

Record the server with SHOW server_version;. Exact wording can differ across versions/providers.

When to follow which branch

FailureWhat ran outFirst useful action
Statement timeoutTotal statement time, including lock waitingInspect effective timeout and wait state
Lock timeoutTime acquiring a particular lockFind the blocking transaction
Reserved slotsConnections available to the ordinary login roleAccount for all application pools and connections

Statement timeout

The exact message is canceling statement due to statement timeout. PostgreSQL's client settings, checked 2026-10-20, define a statement-wide elapsed-time limit. Lock waiting counts too.

Start with SHOW statement_timeout;. From a separate authorized monitoring connection, inspect the target PID's state and waits:

SELECT pid, application_name, state, wait_event_type, wait_event,
       pg_blocking_pids(pid) AS blockers
FROM pg_stat_activity
WHERE datname = current_database();

The activity view and blocking-PID function, checked 2026-10-20, document these diagnostics. Visibility depends on privileges; inspect during the wait and correlate logs.

Fix the observed cause: shorten the blocking transaction if it is waiting; otherwise review the query plan, row volume and indexes. For a genuinely longer task, agree a bounded task-specific budget. This example checks transaction-local settings without running application work:

BEGIN;
SET LOCAL statement_timeout = '30s';
SHOW statement_timeout;
ROLLBACK;

Thirty seconds is illustrative. Put the reviewed operation inside the transaction. SET, checked 2026-10-20, limits LOCAL to that transaction. Roll back an errored transaction before more work.

Do not disable it globally, replay writes blindly or assume a missing index. Verify a representative operation and elapsed time safely.

Lock timeout

The exact message is canceling statement due to lock timeout. The official timeout definitions, checked 2026-10-20, apply this limit separately to each lock acquisition attempt. A nonzero statement timeout at or below the lock timeout can fire first.

Use the monitoring query above while the wait exists. Identify the owning transaction and arrange for its owner to commit or roll back; shorten transaction scope in the application. Roll back the failed transaction before retrying. For a lock-sensitive task, choose a shorter lock budget than the total statement budget:

BEGIN;
SET LOCAL lock_timeout = '2s';
SET LOCAL statement_timeout = '30s';
SHOW lock_timeout;
ROLLBACK;

These limits are illustrative. Place reviewed work inside the transaction; verify the blocker disappears and the task completes.

Do not use SET LOCAL before BEGIN, terminate arbitrary sessions or remove the guardrail. The official SET reference, checked 2026-10-20, explains why LOCAL outside a transaction has no useful effect.

Reserved connection slots

The exact legacy message is remaining connection slots are reserved for non-replication superuser connections. Supabase's official entry, checked 2026-10-20, verifies it and recommends connection optimization/pooling before additional capacity.

Ordinary clients have consumed the connections available below the reserve. PostgreSQL's connection settings, checked 2026-10-20, distinguish max_connections, superuser_reserved_connections and reserved_connections. Use an existing authorized admin connection to inspect:

SHOW max_connections;
SHOW superuser_reserved_connections;
SHOW reserved_connections;
SELECT usename, application_name, state, count(*)
FROM pg_stat_activity
GROUP BY usename, application_name, state;

Check server-version support before requesting reserved_connections. Compare ordinary capacity against every instance's pool plus other consumers. Release leaked checkouts, reuse a pool and bound concurrency. For node-postgres use try { /* work */ } finally { client.release(); }; verify your driver's API. After fixing, reconnect an ordinary client and observe usage under load.

Do not grant the app superuser, consume the reserve, kill all idle sessions or raise capacity blindly. Idle pool connections can be intentional; terminating a transaction rolls it back.

Community evidence

  • Jayadeep's report verifies statement cancellation; Laurenz Albe suggests inspecting lock waits.
  • Super Kai / Kazuya Ito's self-answer demonstrates the LOCAL-before-BEGIN trap and exact lock cancellation.
  • pganalyze's L72 guide distinguishes lock and statement budgets. Hans-Jürgen Schönig's CYBERTEC article explains connection reserves. Both checked 2026-10-20; no engagement verified. These vendor explanations are not workload reproductions.

Recommendation and prompt for the agent

Choose query diagnostics, blocker ownership or aggregate pool accounting by the failing limit.

Read the linked official source for my exact error rather than guessing. Record the installed server/driver versions and operation. Separate elapsed time, blockers and connection capacity. Propose one scoped change, its commands and a verification plan; preserve transaction boundaries and the admin reserve. Do not execute anything against production without the agreed workflow.

Limits

No SQL, connections, migrations or reproductions were run. All three requested strings were verified; none dropped. Other provider/localized wording is unverified. Sources establish symptoms, not current incidence. Pending neighbours include serverless-too-many-connections-prisma-drizzle-postgres-pool-limits (serverless sizing), agent-tunes-slow-postgres-query-explain-hypopg (query tuning), and prisma-p1011-p1017-supabase-admin-and-pooler-connection-errors (different errors). Publication was unconfirmed; covers names a published local-stack neighbour. All sources checked 2026-10-20.

Started from a post by @Hans-Jürgen Schönig, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# canceling statement due to statement timeout: which Postgres fix?
Summary: As of October 2026, Postgres statement timeouts cover the whole statement, lock timeouts cover individual lock waits, and reserved-slot failures reject new ordinary connections. Inspect the matching limit before changing settings; none proves that a global timeout increase is the fix (checked 2026-10-20).
Copy for agent
get the whatworks thread postgres-statement-timeout-lock-timeout-reserved-connection-slots and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread postgres-statement-timeout-lock-timeout-reserved-connection-slots
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp