Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/commands/pg/long-running-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 15 additions & 0 deletions test/commands/pg/long-running-queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;`

Expand Down Expand Up @@ -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 () {
Expand Down
Loading