Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

watch in PostgreSQL with clear screen (cos)

\watch command is great in Postrges.

It appends an output of a query, being watched over and over.

For example, when I previously run a query SELECT id, nickname FROM users;, and entered \watch, in case of no new data, I get the same output over and over:

my_db=# SELECT id, nickname FROM users;
 id | nickname 
----+----------
  1 | AntonAL
(1 row)

my_db=# \watch
четверг, 31 августа 2017 г. 13:23:26 (every 2s)

 id | nickname 
----+----------
  1 | AntonAL
(1 row)

четверг, 31 августа 2017 г. 13:23:28 (every 2s)

 id | nickname 
----+----------
  1 | AntonAL
(1 row)

It there any option to clear screen output, between watch executions?

I want to get dashboard-like experience, when a set of rows is displayed and refreshed, not appended over and over to the Postgres console output.

like image 461
AntonAL Avatar asked Jan 30 '23 16:01

AntonAL


1 Answers

I had this problem, and with a suggestion from MatheusOl on #postgresql, the following works for me:

\C `clear`
SELECT * FROM pg_tables \watch 10

The \C [value] command sequence lets you set a title, and you can set that (shelling out with backticks) to the ANSI escapes returned by clear.

like image 133
Shabble Avatar answered Feb 05 '23 18:02

Shabble