有時候在 pgsql 會遇到這個錯誤訊息,意思大概就是當前連線數量已達上限,
有可能是因為重複啟動 tomcat 等等

FATAL: sorry, too many clients already




總之可以透過這個 query,刪除10分鐘內的 idle 連線,應該就可以繼續使用。

SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = 'xxxxx'
AND pid <> pg_backend_pid()
AND state = 'idle'
AND state_change < current_timestamp - INTERVAL '10' MINUTE;SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = 'xxxxx'
AND pid <> pg_backend_pid()
AND state = 'idle'
AND state_change < current_timestamp - INTERVAL '10' MINUTE;