Skip to content

Commit ba1d84b

Browse files
committed
updated postgres_idle_sessions_current_db_kill.sql
1 parent 2b8f367 commit ba1d84b

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

postgres_idle_sessions_current_db_kill.sql

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,28 @@
2020
-- Tested on PostgreSQL 9.2+, 10.x, 11.x, 12.x, 13.0
2121

2222
SELECT
23-
pg_terminate_backend(pid)
23+
pg_terminate_backend(pid)
2424
FROM
25-
pg_stat_activity
25+
pg_stat_activity
2626
WHERE
27-
-- don't kill yourself
28-
pid <> pg_backend_pid()
29-
-- AND
30-
-- don't kill your admin tools
31-
--application_name !~ '(?:psql)|(?:pgAdmin.+)'
32-
-- AND
33-
--usename not in ('postgres')
34-
AND
35-
datname = current_database()
36-
AND
37-
query in ('')
38-
AND
39-
state in ('idle', 'idle in transaction', 'idle in transaction (aborted)', 'disabled')
40-
AND
41-
--state_change < current_timestamp - INTERVAL '15' MINUTE;
42-
(
43-
(current_timestamp - query_start) > interval '15 minutes'
44-
OR
45-
(query_start IS NULL AND (current_timestamp - backend_start) > interval '15 minutes')
46-
)
27+
-- don't kill yourself
28+
pid <> pg_backend_pid()
29+
-- AND
30+
-- don't kill your admin tools
31+
--application_name !~ '(?:psql)|(?:pgAdmin.+)'
32+
-- AND
33+
--usename not in ('postgres')
34+
AND
35+
datname = current_database()
36+
AND
37+
query in ('')
38+
AND
39+
state in ('idle', 'idle in transaction', 'idle in transaction (aborted)', 'disabled')
40+
AND
41+
--state_change < current_timestamp - INTERVAL '15' MINUTE;
42+
(
43+
(current_timestamp - query_start) > interval '15 minutes'
44+
OR
45+
(query_start IS NULL AND (current_timestamp - backend_start) > interval '15 minutes')
46+
)
4747
;

0 commit comments

Comments
 (0)