Re: WAIT FOR command should do some query jumbling
Re: WAIT FOR command should do some query jumbling
Hi Peter,
On Fri, Aug 28, 2026 at 2:48 PM Peter Eisentraut <peter@eisentraut.org> wrote:
Right now, WAIT FOR commands are recorded literally in
pg_stat_statements. I think the actual LSN value should be replaced by
some placeholder, like
WAIT FOR LSN $1
Otherwise, a client library or framework that runs this command
repeatedly would needlessly spam pg_stat_statements.
The query jumbling facilities should be used to handle this.
+1 to your suggestion. Please find the attached patch to address this issue.
Regards,
Sirisha
Re: WAIT FOR command should do some query jumbling
От:
Sami Imseih <samimseih.pg@gmail.com>
Дата:
I see the traction here, but I cannot really get fully convinced by a
grouping of the timeouts without more input. As a whole, I think that
Sirisha's patch is fine enough on its own.
Perhaps LSN is enough for now as it will be the value that will vary the
most with heavy usage. I don't know how often TIMEOUT values will
vary however, so I'll drop the options normalization idea for now.
--
Sami
Re: WAIT FOR command should do some query jumbling
Hi! On Thu, Sep 3, 2026 at 6:38 AM Michael Paquier wrote: > Sami has also mentioned to me off-list that we may want something > smarter in terms of the management of the DefElems that include > strings, because we have other commands with contents that we may want > to normalize in some contexts, like an ALTER TABLE with a password as > one example. Perhaps it would be better to not rush that part. Agreed, so v3 attached drops the generic part and does WAIT only. Two things today: waits differing only in the timeout get an entry each, and so does the same wait with its options written in another order. 1 | WAIT FOR LSN $1 WITH (mode 'primary_flush', timeout '5ms') 1 | WAIT FOR LSN $1 WITH (mode 'primary_flush', timeout '7ms') 1 | WAIT FOR LSN $1 WITH (timeout '5ms', mode 'primary_flush') With v3 those are one entry: 3 | WAIT FOR LSN $1 WITH (mode 'primary_flush', timeout $2) while the modes stay apart, as Sirisha asked for: 1 | WAIT FOR LSN $1 WITH (mode 'standby_replay', timeout $2, no_throw) 1 | WAIT FOR LSN $1 WITH (mode 'standby_write', timeout $2, no_throw) WaitStmt.options gets a custom jumble function that walks the recognized options in a fixed order instead of the order written, records TIMEOUT as a constant, and jumbles MODE and NO_THROW as given. No generic DefElem option normalization: what a value means differs per option and only the command knows, which is the same problem VariableSetStmt.jumble_args solves per grammar flavor. DefElem gains arg_location, since DefElem.location points at the option name -- recording that one normalizes the wrong token: WAIT FOR LSN $1 WITH (mode 'primary_flush', $2 '5ms') and the argument node is a bare String or Integer, which carries no location at all. Nothing else reads the new field, so no other statement changes. One wart left alone: "WITH (no_throw)" and "WITH (no_throw true)" are still separate entries, as VACUUM (ANALYZE) and VACUUM (ANALYZE true) are today. Resolving it would mean calling defGetBoolean() while jumbling, which can throw. Passwords in pg_stat_statements are untouched by this and can go to their own thread. ------ Regards, Alexander Korotkov Supabase
Re: WAIT FOR command should do some query jumbling
От:
Sami Imseih <samimseih.pg@gmail.com>
Дата:
Hi Alexander, > Two things today: waits differing only in the timeout get an entry > each, I agree this is not ideal, and it's the point I raised earlier. > and so does the same wait with its options written in another > order. I am not sure we should add the additional complexity in the custom jumble to deal with this. I don't anticipate this will be a problem in the real world. Scripts and drivers will use the same order. Also we don't really guarantee that in other commands: ``` VACUUM (ANALYZE, VERBOSE) and VACUUM (VERBOSE, ANALYZE) ``` give different queryIds, and the same is true of COPY and every other command taking an option list. If we want option order to not affect the queryId, I think we should teach jumbling to do this for all commands that take options; the consumers of utility_option_list and copy_generic_opt_list, and probably some other places. So my preference is to deal with the TIMEOUT jumbling only, and keep the ordering aspect out of this for now. Maybe others have a different opinion. -- Sami Imseih Amazon Web Services (AWS)