简体   繁体   English

如何通过应用程序关闭所有postgres连接

[英]how to close all postgres connections through app

I want to add restore functionality to my jsf app. 我想将还原功能添加到我的jsf应用程序中。

I need to restore the sql file, but my connections to PostgreSQL prevent me from doing that. 我需要还原sql文件,但是我与PostgreSQL的连接阻止了我这样做。

How can I close all connection to database in order to restore the sql file? 如何关闭与数据库的所有连接以还原sql文件?

I am using a connection pool and I destroy all connections but PostgreSQL tell me there is a open session 我正在使用连接池,并且销毁了所有连接,但是PostgreSQL告诉我有一个开放会话

/**
 * destroy postgresql connection pool
 */
public static void releasePostgresPool() {
    postgresConnectionPool.destroy();
}

You may close all postgresql connections from database side using this query: 您可以使用以下查询从数据库端关闭所有postgresql连接:

select pg_terminate_backend(pid) from pg_stat_activity where pid <> pg_backend_pid();

not sure if it will be correct way for application (it should be able to reconnect after this). 不知道这是否是正确的应用方式(此后应该可以重新连接)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM