Mostafa Jamareh
Mostafa Jamareh

Reputation: 1439

how to close all postgres connections through app

I want to add restore functionality to my jsf app.

I need to restore the sql file, but my connections to PostgreSQL prevent me from doing that.

How can I close all connection to database in order to restore the sql file?

I am using a connection pool and I destroy all connections but PostgreSQL tell me there is a open session

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

Upvotes: 1

Views: 1055

Answers (1)

alexius
alexius

Reputation: 2576

You may close all postgresql connections from database side using this query:

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).

Upvotes: 1

Related Questions