From 1b075c41e604da67dfcd417f281f39d8503ca2fc Mon Sep 17 00:00:00 2001 From: Carla Iriberri Date: Fri, 17 Apr 2026 11:18:13 +0000 Subject: [PATCH] Exclude superuser, ongoing, physical backup queries from resuts --- src/commands/pg/long-running-queries.ts | 5 +++++ test/commands/pg/long-running-queries.test.ts | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/commands/pg/long-running-queries.ts b/src/commands/pg/long-running-queries.ts index 11694e6..e67ebc3 100644 --- a/src/commands/pg/long-running-queries.ts +++ b/src/commands/pg/long-running-queries.ts @@ -15,6 +15,11 @@ WHERE pg_stat_activity.query <> ''::text AND state <> 'idle' AND now() - pg_stat_activity.query_start > interval '5 minutes' + AND NOT ( + state = 'idle in transaction' + AND usename = 'postgres' + AND query LIKE '%pg_backup_start%' + ) ORDER BY now() - pg_stat_activity.query_start DESC; `.trim() diff --git a/test/commands/pg/long-running-queries.test.ts b/test/commands/pg/long-running-queries.test.ts index 1cb00d3..01f9be8 100644 --- a/test/commands/pg/long-running-queries.test.ts +++ b/test/commands/pg/long-running-queries.test.ts @@ -50,6 +50,11 @@ WHERE pg_stat_activity.query <> ''::text AND state <> 'idle' AND now() - pg_stat_activity.query_start > interval '5 minutes' + AND NOT ( + state = 'idle in transaction' + AND usename = 'postgres' + AND query LIKE '%pg_backup_start%' + ) ORDER BY now() - pg_stat_activity.query_start DESC;` @@ -88,6 +93,16 @@ ORDER BY expect(query).to.contain('ORDER BY') expect(query).to.contain('now() - pg_stat_activity.query_start DESC') }) + + it('should exclude wal-e backup queries', function () { + const query = generateLongRunningQueriesQuery() + + // Should exclude wal-e backup queries (idle in transaction + postgres user + pg_backup_start) + // Normalize whitespace to check that all three conditions are together in an AND NOT block + const normalizedQuery = query.replaceAll(/\s+/g, ' ') + const expectedPattern = "AND NOT ( state = 'idle in transaction' AND usename = 'postgres' AND query LIKE '%pg_backup_start%' )" + expect(normalizedQuery).to.contain(expectedPattern) + }) }) describe('Command Behavior', function () {