Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active July 6, 2016 01:23
Show Gist options
  • Save nepsilon/a7b034616ffb24521c8fb9442c64d41f to your computer and use it in GitHub Desktop.
Save nepsilon/a7b034616ffb24521c8fb9442c64d41f to your computer and use it in GitHub Desktop.
Periodically run a query with PostgreSQL — First published in fullweb.io issue #53

Periodically run a query with PostgreSQL

If you ever used watch -n 3 ... to run your SQL query every 3 seconds, rejoice because Postgres provides a way to do this without leaving the psql prompt.

First run the command you’d like to repeat:

test-db=# SELECT now();

Then just type \watch X to repeat your query every X seconds:

test-db=# \watch 3

Watch every 3s Mon Jun 20 13:44:53 2016

              now
───────────────────────────────
   2016-06-20 13:44:53.739159+08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment