File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -17,9 +17,17 @@ class Oldest(Plugin):
1717"""
1818
1919 OldestQuerySql = """
20- select
21- extract(epoch from max(now() - xact_start))
22- from pg_catalog.pg_stat_activity;
20+ SELECT
21+ CASE WHEN extract(epoch from max(now() - xact_start)) IS NOT null
22+ AND extract(epoch from max(now() - xact_start))>0
23+ THEN extract(epoch from max(now() - xact_start))
24+ ELSE 0
25+ END
26+ FROM pg_catalog.pg_stat_activity
27+ WHERE
28+ pid NOT IN(select pid from pg_stat_replication) AND
29+ pid <> pg_backend_pid() AND
30+ query NOT ilike '%%VACUUM%%';
2331"""
2432
2533 OldestQuerySql_bootstrap = """
Original file line number Diff line number Diff line change 6767
6868CREATE or REPLACE FUNCTION public.mamonsu_get_oldest_query()
6969RETURNS DOUBLE PRECISION AS $$
70- SELECT
71- extract(epoch from max(now() - xact_start))
72- FROM pg_catalog.pg_stat_activity
70+ SELECT
71+ CASE WHEN extract(epoch from max(now() - xact_start)) IS NOT null
72+ AND extract(epoch from max(now() - xact_start))>0
73+ THEN extract(epoch from max(now() - xact_start))
74+ ELSE 0
75+ END
76+ FROM pg_catalog.pg_stat_activity
77+ WHERE
78+ pid NOT IN(select pid from pg_stat_replication) AND
79+ pid <> pg_backend_pid() AND
80+ query NOT ilike '%%VACUUM%%'
7381$$ LANGUAGE SQL SECURITY DEFINER;
7482
7583CREATE OR REPLACE FUNCTION public.mamonsu_count_{3}_files()
You can’t perform that action at this time.
0 commit comments