database - Kill a postgresql session/connection - Stack Overflow

PHOTO EMBED

Thu Dec 15 2022 16:40:26 GMT+0000 (Coordinated Universal Time)

Saved by @2019cs238 #sql

SELECT 
    pg_terminate_backend(pid) 
FROM 
    pg_stat_activity 
WHERE 
    -- don't kill my own connection!
    pid <> pg_backend_pid()
    -- don't kill the connections to other databases
    AND datname = 'database_name'
    ;
content_copyCOPY

https://stackoverflow.com/questions/5108876/kill-a-postgresql-session-connection