Skip to content

Commit a5e0d18

Browse files
author
Roman Nikolaev
committed
Exclude vacuum/autovacuum and backend sessions from activity statistics
1 parent 20db76c commit a5e0d18

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

mamonsu/plugins/pgsql/oldest.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ class Oldest(Plugin):
1919
OldestQuerySql = """
2020
select
2121
extract(epoch from max(now() - xact_start))
22-
from pg_catalog.pg_stat_activity where pid not in (select pid from pg_stat_replication);
22+
from pg_catalog.pg_stat_activity
23+
where
24+
pid not in (select pid from pg_stat_replication)
25+
AND pid <> pg_backend_pid()
26+
AND query not ilike '%VACUUM%'
27+
HAVING extract(epoch from max(now() - xact_start))>0;
2328
"""
2429

2530
OldestQuerySql_bootstrap = """

mamonsu/tools/bootstrap/sql.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@
7070
SELECT
7171
extract(epoch from max(now() - xact_start))
7272
FROM pg_catalog.pg_stat_activity
73-
WHERE pid not in (select pid from pg_stat_replication)
73+
WHERE
74+
pid not in (select pid from pg_stat_replication)
75+
AND pid <> pg_backend_pid()
76+
AND query not ilike '%VACUUM%'
77+
HAVING extract(epoch from max(now() - xact_start))>0
7478
$$ LANGUAGE SQL SECURITY DEFINER;
7579
7680
CREATE OR REPLACE FUNCTION public.mamonsu_count_{3}_files()

0 commit comments

Comments
 (0)