Cancel or Terminate a PostgreSQL Backend
pg_kill_queryCancel or terminate PostgreSQL backend processes by PID. Use cancel mode to stop a query without disconnecting, or terminate to forcefully kill the connection.
Instructions
Cancel or terminate a PostgreSQL backend process by PID.
Two modes:
cancel (safe): Sends SIGINT — cancels the current query but leaves the connection alive. The client can reconnect and retry.
terminate (forceful): Sends SIGTERM — kills the connection entirely. Use when cancel doesn't work.
Args:
pid: Process ID of the backend to cancel/terminate (from pg_active_queries or pg_list_locks)
mode: 'cancel' to cancel current query, 'terminate' to kill connection (default: cancel)
Returns: Whether the signal was successfully sent.
Note: You cannot cancel/terminate your own backend or superuser backends without superuser privileges.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pid | Yes | Backend PID to cancel or terminate | |
| mode | No | 'cancel' = cancel query, 'terminate' = kill connection | cancel |