Skip to content

feat: exclude backups from long running queries#3790

Open
ekozilforce wants to merge 4 commits into
mainfrom
feat/exclude-backups-from-long-running-queries
Open

feat: exclude backups from long running queries#3790
ekozilforce wants to merge 4 commits into
mainfrom
feat/exclude-backups-from-long-running-queries

Conversation

@ekozilforce

@ekozilforce ekozilforce commented Jun 25, 2026

Copy link
Copy Markdown

Summary

This pr adds a where clause to pg:long-running-queries to filter out backups that are expected, low impact, and not actionable for customers. This command is meant to provide clarity for debugging, so the existence of this query leads to customer confusion. Thepg:ps command will continue to show all active queries.

Type of Change

Breaking Changes (major semver update)

  • Add a ! after your change type to denote a change that breaks current behavior

Feature Additions (minor semver update)

  • feat: Introduces a new feature to the codebase

Patch Updates (patch semver update)

  • fix: Bug fix
  • deps: Dependency upgrade
  • revert: Revert a previous commit
  • chore: Change that does not affect production code
  • refactor: Refactoring existing code without changing behavior
  • test: Add/update/remove tests

Testing

Notes:

Standard db Testing

ps shows all running queries. Below we see follower replication, backup, and user queries:

% ./bin/dev.js pg:ps postgresql-trapezoidal-38184 --app ekozil-dev
  pid   |        state        |      source      |    username    |   running_for   |       transaction_start       | waiting |                                                                               query                                                                                
--------+---------------------+------------------+----------------+-----------------+-------------------------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------
 557810 | active              | psql interactive | ub7m0qjpm7g4mi | 00:08:16.344795 | 2026-06-26 14:03:10.928145+00 | t       | SELECT pg_sleep(36000);
 557739 | idle in transaction |                  | postgres       | 00:15:10.941238 | 2026-06-26 13:56:16.331702+00 | t       | SELECT file_name,   lpad(file_offset::text, 8, '0') AS file_offset FROM pg_walfile_name_offset(  pg_backup_start('freeze_start_2026-06-26T13:56:16.331605+00:00'))
 557712 | active              | follower         | postgres       |                 |                               | t       | START_REPLICATION 0/61000000 TIMELINE 1
(3 rows)

long-running-queries pre-implementation, we see the backup and follower queries:

% ./bin/dev.js pg:long-running-queries postgresql-trapezoidal-38184  --app ekozil-dev
  pid   |    duration     |                                                                               query                                                                                
--------+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------
 557712 | 00:17:05.834817 | START_REPLICATION 0/61000000 TIMELINE 1
 557739 | 00:16:03.32151  | SELECT file_name,   lpad(file_offset::text, 8, '0') AS file_offset FROM pg_walfile_name_offset(  pg_backup_start('freeze_start_2026-06-26T13:56:16.331605+00:00'))
 557810 | 00:09:08.725209 | SELECT pg_sleep(36000);
(3 rows)

Post-implementation we only see the user query, filtering out the backup and follower queries:

% ./bin/dev.js pg:long-running-queries postgresql-trapezoidal-38184  --app ekozil-dev
  pid   |    duration     |         query          
--------+-----------------+------------------------
 557810 | 00:08:47.514534 | SELECT pg_sleep(36000);
(1 row)


Post-implementation smoke tests for essential and advanced show the command runs without error:

% ./bin/dev.js pg:long-running-queries postgresql-pointy-19471 --app ekozil-dev   
(node:54131) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
 pid | duration | query 
-----+----------+-------
(0 rows)


./bin/dev.js pg:long-running-queries postgresql-octagonal-04440 --app ekozil-dev          
(node:50829) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
 pid | duration | query 
-----+----------+-------
(0 rows)

Screenshots (if applicable)

Related Issues

GUS work item: W-22101694

@ekozilforce ekozilforce changed the title feat/exclude-backups-from-long-running-queries feat: exclude-backups-from-long-running-queries Jun 25, 2026
@ekozilforce ekozilforce changed the title feat: exclude-backups-from-long-running-queries feat: exclude backups from long running queries Jun 25, 2026
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

@subakva subakva left a comment

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.

Looks good to me. I hope this reduces some confusion about expected background processes.

@ekozilforce ekozilforce marked this pull request as ready for review June 26, 2026 14:49
@ekozilforce ekozilforce requested a review from a team as a code owner June 26, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants