Skip to content

Commit 500a813

Browse files
author
Roman Nikolaev
committed
Fixed: empty tuple error when select oldest transaction age
1 parent a5e0d18 commit 500a813

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

mamonsu/plugins/pgsql/oldest.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -17,14 +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
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;
20+
SELECT
21+
CASE WHEN extract(epoch from max(now() - xact_start)) IS NOT null
22+
THEN extract(epoch from max(now() - xact_start))
23+
ELSE 0
24+
END
25+
FROM pg_catalog.pg_stat_activity
26+
WHERE
27+
pid NOT IN(select pid from pg_stat_replication) AND
28+
pid <> pg_backend_pid() AND
29+
query NOT ilike '%%VACUUM%%'
30+
HAVING extract(epoch from max(now() - xact_start))>0;
2831
"""
2932

3033
OldestQuerySql_bootstrap = """

mamonsu/tools/bootstrap/sql.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,17 @@
6767
6868
CREATE or REPLACE FUNCTION public.mamonsu_get_oldest_query()
6969
RETURNS 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+
THEN extract(epoch from max(now() - xact_start))
73+
ELSE 0
74+
END
75+
FROM pg_catalog.pg_stat_activity
7376
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
77+
pid NOT IN(select pid from pg_stat_replication) AND
78+
pid <> pg_backend_pid() AND
79+
query NOT ilike '%%VACUUM%%'
80+
HAVING extract(epoch from max(now() - xact_start))>0
7881
$$ LANGUAGE SQL SECURITY DEFINER;
7982
8083
CREATE OR REPLACE FUNCTION public.mamonsu_count_{3}_files()

0 commit comments

Comments
 (0)