[PostgreSQL] FATAL: sorry, too many clients already connection to server

Table of Contents

[PostgreSQL] FATAL: sorry, too many clients already connection to server

Unable to connect to PostgreSQL server: connection to server at "DB hostname" (DB IP), port DB port failed: FATAL: sorry, too many clients already connection to server at "DB hostname" (DB IP), port DB Port failed: FATAL: sorry, too many clients already

Some useful script

SELECT sum(numbackends) FROM pg_stat_database;
SELECT COUNT(*) from pg_stat_activity;
SHOW config_file;
select min_val, max_val from pg_settings where name='max_connections';
SELECT * FROM pg_stat_activity;

SELECT * FROM pg_stat_activity
order by datname
Where datname = xacthuc

Kill all other active connections to your database

Using SQL Query, run the query below:

SELECT
    pg_terminate_backend(pg_stat_activity.pid)
FROM
    pg_stat_activity
WHERE
    pg_stat_activity.datname = 'database_name'
    AND pid <> pg_backend_pid();

or this query:

SELECT
    pg_terminate_backend(pid)
FROM
    pg_stat_get_activity(NULL::integer)
WHERE
    datid = (
        SELECT
            oid
        FROM
            pg_database
        WHERE
            datname = 'database_name');

Leave a Reply

Your email address will not be published. Required fields are marked *