/* once idle conneciton sayisini database bazinda sayalim */
SELECT COUNT(datname) AS "SAYI",datname FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND state in ( 'idle') GROUP BY datname
/* database isimlerini çeker */
select ''''||datname||''',' from pg_database where datname not in ('postgres','template1','template0',)
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'databasename' AND pid <> pg_backend_pid() AND state in ( 'idle');
/* YA DA */
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname IN ('BlueCollar' ,'BlueCollar' ,'BlueCollarNotificationCenter' ,'BlueCollarPushNotification' ,'BlueCollarPushNotificationLog' ,'ConsentApiDB' ,'Core' ,'CoreLog' ,'Job' ,'Scheduler') AND pid <> pg_backend_pid() AND state in ( 'idle');