Re: psql \watch 2nd argument: iteration count

From: Andrey Borodin <amborodin86(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Nathan Bossart <nathandbossart(at)gmail(dot)com>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, sfrost(at)snowman(dot)net, peter(dot)eisentraut(at)enterprisedb(dot)com, pgsql-hackers(at)postgresql(dot)org, Nikolay Samokhvalov <samokhvalov(at)gmail(dot)com>
Subject: Re: psql \watch 2nd argument: iteration count
Date: 2023-03-13 03:59:44
Message-ID: CAAhFRxjRohdKyOyapvkzjhoo7UqUQtxLf6J7gXr0JyYWDdraRA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Michael, thanks for reviewing this!

On Sun, Mar 12, 2023 at 6:17 PM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> On Sun, Mar 12, 2023 at 01:05:39PM -0700, Andrey Borodin wrote:
> > In the review above Kyotaro-san suggested that message should contain
> > information on what it expects... So, maybe then
> > pg_log_error("\\watch interval must be non-negative number, but
> > argument is '%s'", opt); ?
> > Or perhaps with articles? pg_log_error("\\watch interval must be a
> > non-negative number, but the argument is '%s'", opt);
>
> - HELP0(" \\watch [SEC] execute query every SEC seconds\n");
> + HELP0(" \\watch [SEC [N]] execute query every SEC seconds N times\n");
>
> Is that really the interface we'd want to work with in the long-term?
> For one, this does not give the option to specify only an interval
> while relying on the default number of seconds. This may be fine, but
> it does not strike me as the best choice. How about doing something
> more extensible, for example:
> \watch [ (option=value [, option=value] .. ) ] [SEC]
>
> I am not sure that this will be the last option we'll ever add to
> \watch, so I'd rather have us choose a design more flexible than
> what's proposed here, in a way similar to \g or \gx.
I've attached an implementation of this proposed interface (no tests
and help message yet, though, sorry).
I tried it a little bit, and it works for me.
fire query 3 times
SELECT 1;\watch c=3 0
or with 200ms interval
SELECT 1;\watch i=.2 c=3
nonsense, but correct
SELECT 1;\watch i=1e-100 c=1

Actually Nik was asking for the feature. Nik, what do you think?

On Sun, Mar 12, 2023 at 6:26 PM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> While on it, I have some comments about 0001.
>
> - sleep = strtod(opt, NULL);
> - if (sleep <= 0)
> - sleep = 1;
> + char *opt_end;
> + sleep = strtod(opt, &opt_end);
> + if (sleep < 0 || *opt_end)
> + {
> + pg_log_error("\\watch interval must be non-negative number, "
> + "but argument is '%s'", opt);
> + free(opt);
> + resetPQExpBuffer(query_buf);
> + psql_scan_reset(scan_state);
> + return PSQL_CMD_ERROR;
> + }
>
> Okay by me to make this behavior a bit better, though it is not
> something I would backpatch as it can influence existing workflows,
> even if they worked in an inappropriate way.
+1

> Anyway, are you sure that this is actually OK? It seems to me that
> this needs to check for three things:
> - If sleep is a negative value.
> - errno should be non-zero.
I think we can treat errno and negative values equally.
> - *opt_end == opt.
>
> So this needs three different error messages to show the exact error
> to the user?
I've tried this approach, but could not come up with sufficiently
different error messages...

> Wouldn't it be better to have a couple of regression
> tests, as well?
Added two tests.

Thanks!

Best regards, Andrey Borodin.

Attachment Content-Type Size
v6-0002-Add-iteration-count-argument-to-psql-watch-comman.patch application/octet-stream 8.4 KB
v6-0001-Fix-incorrect-argument-handling-in-psql-watch.patch application/octet-stream 2.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2023-03-13 05:03:43 Re: Compilation error after redesign of the archive modules
Previous Message Thomas Munro 2023-03-13 03:11:22 Re: Sub-millisecond [autovacuum_]vacuum_cost_delay broken