From 2083a2aeccc7ae0756b6139330ade4b622dac37f Mon Sep 17 00:00:00 2001 From: Elliot Kozil Date: Thu, 25 Jun 2026 13:03:49 -0500 Subject: [PATCH 1/4] feat/exclude-backups-from-long-running-queries --- src/commands/pg/long-running-queries.ts | 5 +++++ .../commands/pg/long-running-queries.unit.test.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/commands/pg/long-running-queries.ts b/src/commands/pg/long-running-queries.ts index 7f4e01ed4e..7818982d1d 100644 --- a/src/commands/pg/long-running-queries.ts +++ b/src/commands/pg/long-running-queries.ts @@ -18,6 +18,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/unit/commands/pg/long-running-queries.unit.test.ts b/test/unit/commands/pg/long-running-queries.unit.test.ts index 8247878fc9..74fb76234c 100644 --- a/test/unit/commands/pg/long-running-queries.unit.test.ts +++ b/test/unit/commands/pg/long-running-queries.unit.test.ts @@ -45,6 +45,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;` @@ -58,6 +63,13 @@ ORDER BY expect(query).to.contain("state <> 'idle'") expect(query).to.contain("interval '5 minutes'") }) + + it('excludes the internal physical backup query from results', function () { + const query = generateLongRunningQueriesQuery() + expect(query).to.contain("state = 'idle in transaction'") + expect(query).to.contain("usename = 'postgres'") + expect(query).to.contain("query LIKE '%pg_backup_start%'") + }) }) describe('command behavior', function () { From 12282cc91777e86d4201b9714f8fc9bab32f15b6 Mon Sep 17 00:00:00 2001 From: Elliot Kozil Date: Thu, 25 Jun 2026 14:32:43 -0500 Subject: [PATCH 2/4] remove 'idle in transaction' state check --- src/commands/pg/long-running-queries.ts | 3 +-- test/unit/commands/pg/long-running-queries.unit.test.ts | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/commands/pg/long-running-queries.ts b/src/commands/pg/long-running-queries.ts index 7818982d1d..ed72f1f1ca 100644 --- a/src/commands/pg/long-running-queries.ts +++ b/src/commands/pg/long-running-queries.ts @@ -19,8 +19,7 @@ WHERE AND state <> 'idle' AND now() - pg_stat_activity.query_start > interval '5 minutes' AND NOT ( - state = 'idle in transaction' - AND usename = 'postgres' + usename = 'postgres' AND query LIKE '%pg_backup_start%' ) ORDER BY diff --git a/test/unit/commands/pg/long-running-queries.unit.test.ts b/test/unit/commands/pg/long-running-queries.unit.test.ts index 74fb76234c..60ec024fcd 100644 --- a/test/unit/commands/pg/long-running-queries.unit.test.ts +++ b/test/unit/commands/pg/long-running-queries.unit.test.ts @@ -66,7 +66,6 @@ ORDER BY it('excludes the internal physical backup query from results', function () { const query = generateLongRunningQueriesQuery() - expect(query).to.contain("state = 'idle in transaction'") expect(query).to.contain("usename = 'postgres'") expect(query).to.contain("query LIKE '%pg_backup_start%'") }) From dd0b565319c3d15e9a0ad3de18ac87c98f7581a1 Mon Sep 17 00:00:00 2001 From: Elliot Kozil Date: Thu, 25 Jun 2026 14:36:45 -0500 Subject: [PATCH 3/4] fix test --- test/unit/commands/pg/long-running-queries.unit.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/unit/commands/pg/long-running-queries.unit.test.ts b/test/unit/commands/pg/long-running-queries.unit.test.ts index 60ec024fcd..a25677f80b 100644 --- a/test/unit/commands/pg/long-running-queries.unit.test.ts +++ b/test/unit/commands/pg/long-running-queries.unit.test.ts @@ -46,8 +46,7 @@ WHERE AND state <> 'idle' AND now() - pg_stat_activity.query_start > interval '5 minutes' AND NOT ( - state = 'idle in transaction' - AND usename = 'postgres' + usename = 'postgres' AND query LIKE '%pg_backup_start%' ) ORDER BY From be852e916241428879f8b2b3e6f8d4446b487388 Mon Sep 17 00:00:00 2001 From: Elliot Kozil Date: Fri, 26 Jun 2026 08:32:29 -0500 Subject: [PATCH 4/4] exclude walsender backends from long running queries --- cspell-dictionary.txt | 1 + src/commands/pg/long-running-queries.ts | 1 + test/unit/commands/pg/long-running-queries.unit.test.ts | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/cspell-dictionary.txt b/cspell-dictionary.txt index d36b6d42db..52110cd1a6 100644 --- a/cspell-dictionary.txt +++ b/cspell-dictionary.txt @@ -412,6 +412,7 @@ urijs uxxxxxxxxx vcpu VERSINFO +walsender webfactory withfig wrapline diff --git a/src/commands/pg/long-running-queries.ts b/src/commands/pg/long-running-queries.ts index ed72f1f1ca..477090e07f 100644 --- a/src/commands/pg/long-running-queries.ts +++ b/src/commands/pg/long-running-queries.ts @@ -18,6 +18,7 @@ WHERE pg_stat_activity.query <> ''::text AND state <> 'idle' AND now() - pg_stat_activity.query_start > interval '5 minutes' + AND backend_type <> 'walsender' AND NOT ( usename = 'postgres' AND query LIKE '%pg_backup_start%' diff --git a/test/unit/commands/pg/long-running-queries.unit.test.ts b/test/unit/commands/pg/long-running-queries.unit.test.ts index a25677f80b..92fe16998f 100644 --- a/test/unit/commands/pg/long-running-queries.unit.test.ts +++ b/test/unit/commands/pg/long-running-queries.unit.test.ts @@ -45,6 +45,7 @@ WHERE pg_stat_activity.query <> ''::text AND state <> 'idle' AND now() - pg_stat_activity.query_start > interval '5 minutes' + AND backend_type <> 'walsender' AND NOT ( usename = 'postgres' AND query LIKE '%pg_backup_start%' @@ -68,6 +69,11 @@ ORDER BY expect(query).to.contain("usename = 'postgres'") expect(query).to.contain("query LIKE '%pg_backup_start%'") }) + + it('excludes walsender backends from results', function () { + const query = generateLongRunningQueriesQuery() + expect(query).to.contain("backend_type <> 'walsender'") + }) }) describe('command behavior', function () {