Force client disconnect using PostgreSQL

前端 未结 6 1094
轮回少年
轮回少年 2020-12-25 11:33

Is there a way to force clients to disconnect from PostgreSQL? I\'m looking for the equivlent of DB2\'s force application all.

I\'d like to do this on my development

6条回答
  •  天涯浪人
    2020-12-25 11:38

    I post my answer because I couldn't use any of them in my script, server 9.3:

    psql -U postgres -c "SELECT pid, (SELECT pg_terminate_backend(pid)) as killed from pg_stat_activity WHERE datname = 'my_database_to_alter';"
    

    In the next line, you can do anything yo want with 'my_database_to_alter'. As you can see, yo perform the query from the "postgres" database, which exists almost in every postgresql installation.

    Doing by superuser and outside the problem-database itself worked perfect for me.

提交回复
热议问题