brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: psql \watch repeats a query every few seconds so you can watch a database job

Database
~/tips/tip-database-psql-watch-repeat-query

\watch 2

Reruns the last PostgreSQL query at a fixed interval inside psql.

For anything that changes while I wait, such as a running import, I let psql repeat the query for me.

SELECT state, count(*) FROM pg_stat_activity GROUP BY state;
\watch 2

\watch 2 runs the query in the buffer again every two seconds and prints the new result below the old one, with a timestamp. Stop it with Ctrl-C. Without a number the interval is two seconds anyway.

It repeats whatever was run last, so run the query first and type \watch on the next line. Output scrolls rather than redraws, so keep the query short.

Further reading: PostgreSQL documentation: psql

More Database tips mariadb -e 'CREATE DATABASE IF NOT EXISTS blog' mariadb-dump --no-create-info --insert-ignore shop orders > orders-rows.sql SELECT table_schema, table_name, CHECKSUM TABLE shop.orders; services: All Database tips (53) All topics

Link