Terminate a backend (pg_terminate_backend)
PostgreSQLSessionsCommand
SELECT pg_terminate_backend(12345);What it does
Forcibly terminates the backend process with the given PID; drops the connection and the running transaction.
When to use it
To close a stuck/hung connection or a session holding a lock.
Caution
The running transaction is rolled back; uncommitted work is lost. Try the gentler pg_cancel_backend first. Verify the PID in pg_stat_activity.
Related
- Cancel a running query (pg_cancel_backend)
- Show active and blocking queries
- Build the blocking tree (find the root blocker)
- Inspect lock waits in detail by object and lock mode (pg_locks)
- Find long-running and 'idle in transaction' transactions
- Terminate long 'idle in transaction' sessions in bulk, in a controlled way