Skip to content

Conversation

sysadmind
Copy link
Contributor

This semicolon breaks the query

/cc @kmoppel

This semicolon breaks the query

Signed-off-by: Joe Adams <github@joeadams.io>
Copy link
Contributor

@cristiangreco cristiangreco left a comment

Choose a reason for hiding this comment

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

A bit unfortunate this hasn't been caught by any test.

@cristiangreco
Copy link
Contributor

@sysadmind @SuperQ are we good merging this? I could go ahead with #1196 then if you're ok

@sysadmind sysadmind merged commit 92f9d90 into prometheus-community:fix-1185 Sep 25, 2025
11 checks passed
@sysadmind
Copy link
Contributor Author

It's very unfortunate that the tests didn't catch it. I think we need to take a look at how we do testing in this project and see if we can improve.

@tomhughes
Copy link
Contributor

There's another semicolon at the end of that statement that causes errors to be logged every time it runs:

2025-09-28 15:26:58 GMT ERROR:  syntax error at or near ";" at character 300
2025-09-28 15:26:58 GMT STATEMENT:  WITH
				metrics AS (
					SELECT
					state,
					application_name,
					SUM(EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - state_change))::bigint)::float AS process_idle_seconds_sum,
					COUNT(*) AS process_idle_seconds_count
					FROM pg_stat_activity
					WHERE state ~ '^idle'
					AND pid <> pg_backend_pid();
					GROUP BY state, application_name
				),
				buckets AS (
					SELECT
					state,
					application_name,
					le,
					SUM(
						CASE WHEN EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - state_change)) <= le
						THEN 1
						ELSE 0
						END
					)::bigint AS bucket
					FROM
					pg_stat_activity,
					UNNEST(ARRAY[1, 2, 5, 15, 30, 60, 90, 120, 300]) AS le
					WHERE pid <> pg_backend_pid()
					GROUP BY state, application_name, le
					ORDER BY state, application_name, le
				)
				SELECT
				state,
				application_name,
				process_idle_seconds_sum as seconds_sum,
				process_idle_seconds_count as seconds_count,
				ARRAY_AGG(le) AS seconds,
				ARRAY_AGG(bucket) AS seconds_bucket
				FROM metrics JOIN buckets USING (state, application_name)
				GROUP BY 1, 2, 3, 4;

@cristiangreco
Copy link
Contributor

@tomhughes what PG version are you running? I wasn't able to reproduce the error locally with PG 17.

@tomhughes
Copy link
Contributor

That's 15 at the moment - due to be upgraded to 17 next weekend as it happens.

@cristiangreco
Copy link
Contributor

That's 15 at the moment - due to be upgraded to 17 next weekend as it happens.

Ok I can reproduce the issue locally, will open a PR later.

sysadmind added a commit that referenced this pull request Sep 29, 2025
This semicolon breaks the query

Signed-off-by: Joe Adams <github@joeadams.io>
Co-authored-by: Joe Adams <github@joeadams.io>
cristiangreco added a commit that referenced this pull request Sep 29, 2025
* [BUGFIX] Fix swapped `flushedLsn` and `receiveStartTli` for `wal_receiver` collector by @spantaleev in #1198
* [BUGFIX] Fix superfluous semicolon breaking query in `process_idle` by @sysadmind in #1197 and #1201
cristiangreco added a commit that referenced this pull request Sep 29, 2025
* [BUGFIX] Fix swapped `flushedLsn` and `receiveStartTli` for `wal_receiver` collector by @spantaleev in #1198
* [BUGFIX] Fix superfluous semicolon breaking query in `process_idle` by @sysadmind in #1197 and #1201

Signed-off-by: Cristian Greco <cristian@regolo.cc>
sysadmind pushed a commit that referenced this pull request Sep 29, 2025
* [BUGFIX] Fix swapped `flushedLsn` and `receiveStartTli` for `wal_receiver` collector by @spantaleev in #1198
* [BUGFIX] Fix superfluous semicolon breaking query in `process_idle` by @sysadmind in #1197 and #1201

Signed-off-by: Cristian Greco <cristian@regolo.cc>
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.

4 participants