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
1 change: 1 addition & 0 deletions cspell-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ urijs
uxxxxxxxxx
vcpu
VERSINFO
walsender
webfactory
withfig
wrapline
Expand Down
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 @@ -18,6 +18,11 @@ 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%'
)
ORDER BY
now() - pg_stat_activity.query_start DESC;
`.trim()
Expand Down
16 changes: 16 additions & 0 deletions test/unit/commands/pg/long-running-queries.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ 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%'
)
ORDER BY
now() - pg_stat_activity.query_start DESC;`

Expand All @@ -58,6 +63,17 @@ 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 () {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This test doesn't really check that the conditions are applied as we expect to exclude the backup processes, only that those substrings are part of the query somewhere. When I gave this a try I got something like https://github.com/heroku/heroku-pg-extras/pull/285/changes#diff-936516becf10c8c9b53b618de31d7bdf2fc7d0555dc96a3176441c6956ed4a2dR100-R105, although it isn't the prettiest.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think the proper way to test this may be to parse into a sql ast, anything else is just janky string matching imo. For now, just matched existing testing patterns

const query = generateLongRunningQueriesQuery()
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 () {
Expand Down
Loading