Terminate (kill) a session / query
Oracle
ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
-- To cancel only the running statement (18c+):
-- ALTER SYSTEM CANCEL SQL 'sid,serial#';Get the sid and serial# values from v$session. IMMEDIATE starts the rollback right away.
PostgreSQL
-- Cancel only the running query (the session stays):
SELECT pg_cancel_backend(pid);
-- Close the session entirely:
SELECT pg_terminate_backend(pid);Try pg_cancel_backend first; if it does not work, use pg_terminate_backend.
MySQL
-- Kill only the query:
KILL QUERY <id>;
-- Close the connection entirely:
KILL CONNECTION <id>;The <id> value is the Id column in the processlist.
SQL Server
KILL <session_id>;
-- To see rollback progress:
-- KILL <session_id> WITH STATUSONLY;KILL rolls back the open transaction; for large transactions the rollback can take a long time.
MongoDB
db.killOp(<opid>)Take the opid value from the opid field in the db.currentOp() output.
Redis
CLIENT KILL ID <client-id>
# or by address: CLIENT KILL ADDR 10.0.0.5:6379Use CLIENT LIST for the client-id. A single command already running cannot be interrupted (except a Lua script: SCRIPT KILL); you must wait for it to finish. To release a client waiting on a blocking command such as BLPOP/XREAD BLOCK without dropping its connection, use CLIENT UNBLOCK <client-id> [TIMEOUT|ERROR]. CLIENT UNPAUSE only resumes clients paused with CLIENT PAUSE.