Skip to content

Commit 60e4bd6

Browse files
committed
updated postgres_idle_sessions_kill.sql
1 parent 4b0722c commit 60e4bd6

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

postgres_idle_sessions_kill.sql

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@
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-
query in ('')
36-
AND
37-
state in ('idle', 'idle in transaction', 'idle in transaction (aborted)', 'disabled')
38-
AND
39-
--state_change < current_timestamp - INTERVAL '15' MINUTE;
40-
(
41-
(current_timestamp - query_start) > interval '15 minutes'
42-
OR
43-
(query_start IS NULL AND (current_timestamp - backend_start) > interval '15 minutes')
44-
)
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+
query in ('')
36+
AND
37+
state in ('idle', 'idle in transaction', 'idle in transaction (aborted)', 'disabled')
38+
AND
39+
--state_change < current_timestamp - INTERVAL '15' MINUTE;
40+
(
41+
(current_timestamp - query_start) > interval '15 minutes'
42+
OR
43+
(query_start IS NULL AND (current_timestamp - backend_start) > interval '15 minutes')
44+
)
4545
;

0 commit comments

Comments
 (0)