Answers for "how to close all connection postgress"

SQL
1

view and kill postgresql connections to database

/* view connections */
SELECT * FROM pg_stat_activity;

/*-— Kill connections*/
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 = 'clinical_data';

/* kill a specific connection */     
select pg_terminate_backend(13337)
Posted by: Guest on April-14-2020
0

how to stop all connections to a psql 12 database?

# Works for psql 12
select pg_terminate_backend(pid) from pg_stat_activity where datname='<db_name>';
Posted by: Guest on August-11-2021

Code answers related to "how to close all connection postgress"

Code answers related to "SQL"

Browse Popular Code Answers by Language