Skip to content

Commit 3d9e62a

Browse files
authored
fix(postgres): filter background processes in postgres-list-active-queries (#3885)
## Description This PR updates the `postgres-list-active-queries` tool statement to filter out internal PostgreSQL/AlloyDB system background processes by adding `AND backend_type = 'client backend'` to the `pg_stat_activity` query. ## Context * Following the upgrade of our shared AlloyDB test instance from PG 15 to PG 17 ([screenshot](https://screenshot-v2.corp.google.com/3vi4uot403tmg)), AlloyDB's continuous replication streaming worker remained continuously active in `pg_stat_activity`. * Because `postgres-list-active-queries` queries `pg_stat_activity WHERE state = 'active'` without filtering for client connections, this internal background worker was returned alongside user queries, causing `TestAlloyDBPgToolEndpoints/invoke_list_active_queries_when_the_system_is_idle` to fail on the idle check. * When users run `postgres-list-active-queries`, they expect to see queries initiated by client applications/users, not internal database infrastructure workers. * Adding `backend_type = 'client backend'` is the standard PostgreSQL mechanism (supported across PG 10+) to isolate user/client sessions from engine background processes. ## Changes * Added `AND backend_type = 'client backend'` in `internal/tools/postgres/postgreslistactivequeries/postgreslistactivequeries.go`.
1 parent 81e5b01 commit 3d9e62a

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

‎internal/tools/postgres/postgreslistactivequeries/postgreslistactivequeries.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const listActiveQueriesStatement = `
4646
query
4747
FROM pg_stat_activity
4848
WHERE state = 'active'
49+
AND backend_type = 'client backend'
4950
AND ($1::INTERVAL IS NULL OR now() - query_start >= $1::INTERVAL)
5051
AND ($2::text IS NULL OR application_name NOT IN (SELECT trim(app) FROM unnest(string_to_array($2, ',')) AS app))
5152
ORDER BY query_duration DESC

0 commit comments

Comments
 (0)