Thread: \watch 0 or \watch 0.00001 doesn't do what I want
Daniel's post [1] on \watch reminded me of this little issue I bumped into: I wanted to run a query in a tight loop, without any delay. I tried "\watch 0", but it didn't do what I wanted: postgres=# \watch 0 Wed 09 Oct 2024 16:34:19 EEST (every 1s) ?column? ---------- 1 (1 row) Wed 09 Oct 2024 16:34:20 EEST (every 1s) ?column? ---------- 1 (1 row) ^C Then I tried setting the delay really small, but that didn't do what I wanted either: postgres=# \watch 0.00001 Wed 09 Oct 2024 16:36:45 EEST (every 1e-05s) ?column? ---------- 1 (1 row) ^C It runs the query just once and then hangs forever, until I hit CTRL-C to cancel. [1] https://www.postgresql.org/message-id/B2FD26B4-8F64-4552-A603-5CC3DF1C7103%40yesql.se -- Heikki Linnakangas Neon (https://neon.tech)
On 09/10/2024 16:38, Heikki Linnakangas wrote: > Daniel's post [1] on \watch reminded me of this little issue I bumped into: > > I wanted to run a query in a tight loop, without any delay. I tried > "\watch 0", but it didn't do what I wanted: > > postgres=# \watch 0 Correction: This changed in version 16. It works the way I expected on v16, but not in earlier versions. > Then I tried setting the delay really small, but that didn't do what I wanted either: > > postgres=# \watch 0.00001 > Wed 09 Oct 2024 16:36:45 EEST (every 1e-05s) > > ?column? > ---------- > 1 > (1 row) > > ^C > > It runs the query just once and then hangs forever, until I hit CTRL-C to cancel. This issue is present on newer versions still. -- Heikki Linnakangas Neon (https://neon.tech)
---- On Wed, 09 Oct 2024 19:08:56 +0530 Heikki Linnakangas <hlinnaka@iki.fi> wrote ---
Then I tried setting the delay really small, but that didn't do what I
wanted either:
postgres=# \watch 0.00001
Wed 09 Oct 2024 16:36:45 EEST (every 1e-05s)
?column?
----------
1
(1 row)
^C
It runs the query just once and then hangs forever, until I hit CTRL-C
to cancel.
hi heikki,but i am in pg 14.7 and the query is running perfectly without getting stuck.
Regards,
Srinath Reddy Sadipiralla
Member Technical Staff
ZOHO
Heikki Linnakangas <hlinnaka@iki.fi> writes: > This issue is present on newer versions still. Here's the problem: long sleep_ms = (long) (sleep * 1000); If "sleep" is less than 0.0005, sleep_ms rounds to zero, which results in the subsequent setitimer disarming rather than arming the interrupt. There is an uncommented if (sleep == 0) continue; in the loop, which I bet some cowboy added to fix the zero-wait problem you complained of. But it's doing the wrong thing because it checks sleep not sleep_ms. We should change this to test sleep_ms, and we should probably fix the code that says what the wait interval is to print sleep_ms/1000.0 not sleep. And some more comments would be good. regards, tom lane