Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

PostgreSQL Error 57000: Operator Intervention Explained

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

PostgreSQL error 57000 (operator_intervention) is a catch-all "admin stopped this" code: the database server or whatever runs it has interrupted the query on purpose, not because of a bug in your SQL. You fix it by finding out who sent the stop signal — usually a DBA running pg_terminate_backend, a failover or restart in progress, a statement/transaction timeout, a container or orchestrator killing the process, or the backend hitting a resource limit enforced from outside the database. The query text itself is almost never the problem, so rewriting it does nothing until you know which of these fired.

The code is defined in PostgreSQL's SQLSTATE table as class 57 (operator intervention), which groups all the errors raised when an outside actor aborts work rather than PostgreSQL failing on its own. Its close relatives are 57014 query_canceled, 57P01 admin_shutdown, 57P02 crash_shutdown and 57P03 cannot_connect_now. Seeing 57000 rather than one of those siblings is a hint: 57000 is the generic member of the family, typically raised through ERRCODE_OPERATOR_INTERVENTION in code that deliberately aborts a backend without a more specific reason.

What You'll Need

  • Access to the PostgreSQL server logs (or permission to ask whoever runs the database) — the log line next to the error is where the real cause lives.
  • A client that shows the full error, including the SQLSTATE and any detail or hint fields (psql, or any driver that exposes the diagnostic fields rather than only the message text).
  • For most checks: a role with at least pg_monitor membership, so you can read pg_stat_activity and current settings; superuser or pg_signal_backend is needed to terminate other sessions.
  • For the server-side timeout checks: permission to read postgresql.conf or the result of SHOW for the relevant parameters, or SHOW ALL output.
  • If the database is managed (cloud-hosted), access to the provider's console for failover, restart and connection-killer events.

Step-by-Step

  1. Capture the complete error, not the summary. In psql, the message alone often hides the reason. Check \set VERBOSITY verbose before rerunning, which prints the SQLSTATE, the message and the location in the server source that raised it, or read the SQLSTATE, DETAIL and HINT fields from your driver's diagnostics object. Write down the timestamp, the database, the user and the application that saw the failure.
  2. Open the server log at that timestamp. Look for the same error line and the lines immediately before it. Typical companions are terminating connection due to administrator command, canceling statement due to statement timeout, canceling statement due to user request, server process was terminated by signal, or a crash-recovery and restart sequence. Each points to a different cause, listed in the next steps.
  3. Rule out a deliberate cancellation by a person or a tool. If the log shows terminating connection due to administrator command, someone ran pg_terminate_backend() — a DBA cleaning up long sessions, a connection pooler culling idle backends, a maintenance script, or a management console's "kill query" button. Ask the people with database access; on a managed service, check the provider's activity or event log for a termination or failover event around that time.
  4. Check statement and transaction timeouts. Run SHOW statement_timeout;, SHOW idle_in_transaction_session_timeout;, SHOW lock_timeout;, SHOW transaction_timeout; and, for logical replication, SHOW wal_sender_timeout;. Note that these can also be set per role or per database (ALTER ROLE ... SET, ALTER DATABASE ... SET) or sent in the connection string by the application, so check all three places. A value of zero means disabled. If the failing query ran for roughly the timeout duration, the cutoff is confirmed — the usual remedy is to make the query cheaper or index it, and only then to raise the limit.
  5. Look for external process killers. If PostgreSQL runs in a container or under an orchestrator, a health probe can restart it, and an out-of-memory killer can end the backend. Search the kernel or system logs for out-of-memory messages and the container runtime's log for restarts. Confirm with SHOW max_connections; and the host's memory headroom: one backend using a very large sort or hash can take the whole process down and look like an external intervention.
  6. Inspect what the backend was doing at the moment it died. In pg_stat_activity, look at state, wait_event_type and wait_event. Frequent waits on locks or on client reads point to application behaviour. A pattern where drop or failover events coincide suggests infrastructure rather than SQL.
  7. Reproduce deliberately, then fix the root cause. Rerun the same operation under supervision with logging at log_min_duration_statement set so you can see how long it takes. Then choose the remedy that matches the cause: add an index or rewrite the query for a timeout, coordinate DBA maintenance windows for admin terminations, adjust the pooler's idle timeout or idle_in_transaction_session_timeout for pooler-driven kills, and raise memory limits or tune work_mem for out-of-memory kills.
  8. Make the application handle it gracefully. Error 57000 is retryable in most cases but not in all: a retry is reasonable after a failover or a cancelled query, and dangerous after a termination that happened mid-transaction only if the transaction was idempotent. Implement bounded retries with backoff for the class 57 failures, and never retry in a tight loop — that turns one interruption into a stampede on a server that is already restarting.
  9. Add monitoring so the next occurrence is explained, not guessed. Collect the server log, alert on unexpected restarts (a pg_postmaster_start_time() change), and on managed services enable the provider's event notifications. Record who can run termination functions and require a reason in change logs.

Common Mistakes

  • Rewriting the SQL first. 57000 is not a syntax, deadlock or constraint error; the same query usually succeeds on retry. Change the query only after a timeout is proven.
  • Ignoring the SQLSTATE class. Treating 57000, 57014 and 57P01 as one thing hides whether the stop was a cancellation, a termination or a shutdown — and those need different responses.
  • Raising statement_timeout to a huge value. This hides the symptom while long queries keep holding locks and consuming resources; fix the query first.
  • Retrying blindly in a loop. Unbounded retries around a database in failover prevent it from recovering and multiply load.
  • Not checking pooled connections. Many "mysterious" terminations come from a pooler or proxy recycling stale backends, not from PostgreSQL.

Tips

  • Set log_min_duration_statement and log_line_prefix to include timestamp, user, database, process ID and application name, so you can join an application error to its exact log line.
  • Give each application a distinct application_name in its connection settings; it makes pg_stat_activity and termination auditing far easier.
  • Use pg_cancel_backend() before pg_terminate_backend(): a cancel lets the statement stop cleanly, while a terminate aborts the whole connection.
  • On managed database services, turn on the provider's event stream; failovers and forced restarts are logged there rather than in the PostgreSQL log.

Troubleshooting

If the log has no matching line: you may be reading the wrong log (rotated, or a replica instead of the primary) or the error came from a client-side driver mapping a different underlying condition. Check the driver's documentation for how it maps SQLSTATE values, and check replicas if the connection could have been routed there.

If it happens on a fixed schedule: look for cron jobs, backup scripts, monitoring probes, autovacuum finishing with a restart, or a scheduled failover. Align the timestamps exactly; scheduled causes are almost always clock-regular.

If it happens only under load: suspect memory pressure, connection limits, or a proxy that drops connections past a threshold. Check the host's memory and process logs, and whether the backend was killed by signal 9.

If it happens only at deploy time: the deployment tool may be restarting the database or waiting on a migration lock with a timeout. Coordinate migrations and application restarts, and keep migrations short and separate from deploys where possible.

If you cannot find the origin at all: escalate with the error timestamp, the application, the query and the log excerpt. Unless you have access to server logs, a person with that access is the only one who can answer the question.

Frequently Asked Questions

Is error 57000 a bug in PostgreSQL?

No. It signals that something outside the running statement deliberately interrupted the backend. The bug, if any, is usually in the timeout configuration, tooling or infrastructure.

Is 57000 safe to retry?

Usually yes for read queries, and only if the write is idempotent for writes, because the termination can land at any point in a transaction. Retry with backoff and a cap.

What is the difference between 57000 and 57014?

57014 query_canceled means the statement was cancelled, typically by a timeout or by pg_cancel_backend, and the connection survives. 57000 is the generic operator-intervention code and often accompanies a full connection termination.

Can I catch 57000 in application code?

Yes. Every PostgreSQL driver exposes the SQLSTATE; branch on the five-character code rather than message text, which changes with server version and locale.

Does a PostgreSQL restart always produce 57000?

Not necessarily. A clean shutdown normally produces 57P01 admin_shutdown; 57P02 crash_shutdown appears after a crash. 57000 tends to come from custom tooling and extensions that abort backends generically.

Will raising the timeout stop it forever?

Only if a timeout was the actual cause and the workload stays below the new limit. Investigate what is being cancelled before changing limits.