The YSQLSH client includes a \watch meta-command that repeatedly executes a query every n seconds. This is a handy feature if you need to monitor the system resources consumed for a particular SQL statement.
Note that the \watch meta-command executes the current statement in the query buffer. You can print the query that’s in the buffer using the \p meta-command.
Example:
yugabyte=# \p
SELECT MAX(c) FROM t;
yugabyte=# \watch 5
Thu 29 Dec 2022 08:19:36 PM UTC (every 5s)
max
-----------
579820286
(1 row)
Thu 29 Dec 2022 08:19:41 PM UTC (every 5s)
max
-----------
579820286
(1 row)
Thu 29 Dec 2022 08:19:46 PM UTC (every 5s)
max
-----------
579820286
(1 row)
^C
If you do not specify the number of seconds to wait in between re-exectuing the buffered query, the \watch meta-command defaults to 2 seconds.