Last active
May 2, 2024 07:47
-
-
Save khaliqgant/e147c4ae5fc4d9c133038de8eb4db8c0 to your computer and use it in GitHub Desktop.
[Postgres Kill Process] Kill A Process In Postgres #database #postgres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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