kill all postgresql code example
Example 1: postgres kill running query
--Stop the query normally
SELECT pg_cancel_backend(pid);
--Terminate immediately
SELECT pg_terminate_backend(pid);
Example 2: postgres kill all connections
SELECT
pg_terminate_backend(pid)
FROM
pg_stat_activity
WHERE
pid <> pg_backend_pid()
AND datname = 'database_name';