Watch a Query with psql
Postgres' REPL psql includes a \watch
meta command that repeatedly executes a query every n
seconds. Here's the official description:
\watch [ seconds ] Repeatedly execute the current query buffer (like \g) until interrupted or the query fails. Wait the specified number of seconds (default 2) between executions.
\watch
executes the current query buffer. If you aren't sure what that query is, print it with \p
:
dev=# \p
select title from posts;
Run \watch
to 'tail' that query result as it changes:
dev=# \watch
Sun Jul 29 17:06:13 2018 (every 2s)
title
----------------------
Psql Watch
(1 row)
It prints a timestamp each time it watches.
Tweet