chore: adds useful SQL scripts for devops (#14068)

This commit is contained in:
Omar López
2024-03-28 11:36:27 -07:00
committed by GitHub
parent 622160ea17
commit 159bbb53b6
4 changed files with 89 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
-- Check all connection activity
SELECT
*
FROM
pg_stat_activity;
-- Clear idle connections older than 15 minutes
SELECT
pg_terminate_backend(pid)
FROM
pg_stat_activity
WHERE
state = 'idle'
AND
state_change < now() - '15min'::INTERVAL;
-- Check connections by user
SELECT
usename,
count(*)
FROM
pg_stat_activity
GROUP BY
usename;