Many PostgreSQL users run their favorite database engine on Linux or some other UNIX system. While Windows is definitely an important factor in the database world, many people like the flexibility of a UNIX-style command line. One feature used by many UNIX people is “watch”. watch
runs commands repeatedly, displays their output and errors and allows you to watch the program output change over time. It is therefore a perfect tool to track down errors.
Table of Contents
In the PostgreSQL world I have seen people run watch
from the command line.
watch
command:
1 |
watch -n 5 'psql -c 'SELECT now()' test' |
Every five seconds the output of the SQL function will be displayed.
While this is easy, there is a better way: You can achieve the same thing without having to leave psql at all.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
[hs@zenbook ~]$ psql test psql (9.5.3) Type 'help' for help. test=# SELECT now(); now ------------------------------ 2016-06-02 19:20:42.93694+02 (1 row) test=# watch 5 Watch every 5s Thu Jun 2 19:20:48 2016 now ------------------------------- 2016-06-02 19:20:48.430408+02 (1 row) Watch every 5s Thu Jun 2 19:20:53 2016 now ------------------------------- 2016-06-02 19:20:53.435332+02 (1 row) |
The first thing to do is to run the command you want to execute repeatedly. Then just do “watch seconds”. In my example, the query will be executed every 5 seconds until watch is terminated (ctrl + c).
psql offers a nice and simple way to see what a database is doing right now.
In case you need any assistance, please feel free to contact us.
In order to receive regular updates on important changes in PostgreSQL, subscribe to our newsletter, or follow us on Facebook or LinkedIn.
You need to load content from reCAPTCHA to submit the form. Please note that doing so will share data with third-party providers.
More InformationYou are currently viewing a placeholder content from Facebook. To access the actual content, click the button below. Please note that doing so will share data with third-party providers.
More InformationYou are currently viewing a placeholder content from X. To access the actual content, click the button below. Please note that doing so will share data with third-party providers.
More Information
Can watch be used as a heartbeat system