[pg_stat_statements] Strip special characters from query - #1166
Open
ussrlongbow wants to merge 1 commit into
Open
[pg_stat_statements] Strip special characters from query#1166ussrlongbow wants to merge 1 commit into
ussrlongbow wants to merge 1 commit into
Conversation
ArthurSens
requested changes
Aug 26, 2026
ArthurSens
left a comment
Contributor
There was a problem hiding this comment.
Hey, sorry for the very delayed review here. We'll need to rebase this PR to continue 😬
| Default(fmt.Sprintf("%v", defaultDisabled)). | ||
| Bool() | ||
| statementStripSpecialFlag = kingpin.Flag( | ||
| fmt.Sprint(collectorFlagPrefix, statStatementsSubsystem, ".strip_special"), |
Contributor
There was a problem hiding this comment.
strip_special is quite generic when all we do here is strip white spaces.
I'm also wondering if this should be configurable at all; maybe the fix should be applied automatically based on GOOS?
|
|
||
| const ( | ||
| pgStatStatementQuerySelect = `LEFT(pg_stat_statements.query, %d) as query,` | ||
| pgStatStatementQuerySelectStrip = `LEFT(regexp_replace(pg_stat_statements.query, '\s+', ' ', 'g'), %d) as query,` |
Contributor
There was a problem hiding this comment.
\s+ strips a lot more than just CRLF; it strips multiple spaces, tabs, and new lines. Should we use a more restrictive regex?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Same queries from Windows and Linux clients to PostgreSQL may appear as different texts in
pg_stat_statements.queryhaving same query ID, because of different line breaks, which blocks proper matchingquerytext to metrics withqueryidlabel in Prometheus.Example:
This pull request adds option
--[no-]collector.stat_statements.strip_specialto remove such symbols from query output.Authors:
@ussrlongbow
@freehck