Skip to content

Instantly share code, notes, and snippets.

@khaliqgant
Last active May 2, 2024 07:47
Show Gist options
  • Save khaliqgant/e147c4ae5fc4d9c133038de8eb4db8c0 to your computer and use it in GitHub Desktop.
Save khaliqgant/e147c4ae5fc4d9c133038de8eb4db8c0 to your computer and use it in GitHub Desktop.
[Postgres Kill Process] Kill A Process In Postgres #database #postgres
SELECT * FROM pg_stat_activity WHERE state = 'active';
SELECT pg_cancel_backend(<PID>);
SELECT pg_terminate_backend(<PID>);
-- kill all active except active one
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE pid <> pg_backend_pid()
AND state = 'active';
-- https://www.sqlprostudio.com/blog/8-killing-cancelling-a-long-running-postgres-query#:~:text=If%20you%20want%20to%20terminate,be%20used%20in%20special%20situations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment