完全な接続文字列を表示せずに `watch` PostgreSQLクエリ

完全な接続文字列を表示せずに `watch` PostgreSQLクエリ

チームメンバーとオンラインでいくつかの洞察を共有したいと思います。PostgreSQLデータベース(Dockered Debian Bullseyeでホスト)を使用するwatch(他のツールがわかっている場合は優先)pgAdmin4ただし、リアルタイム修正を表示する方法が見つかりません。教えてください。)

現在私はこれをしています:

$  PGPASSWORD=***************
$ reset
$ watch -n 1.0 "psql \
-d postgresql://postgres:${PGPASSWORD}@localhost:5432/dbname \
  -c 'select id,name,customer,order,product from public.table where id in (1,2,3,4) order by (id)';"

これにより、パスワードはbash履歴に保存されず(最初の行の前のスペースに注意してください)、呼び出し後に画面に表示されなくなりますreset(ホストはUbuntu 18.04にあります)。

ただし、watchコマンドが開始されると、実際には画面の上部に接続されたクエリ文字列全体がプレーンテキストに「変換」され、データベースパスワード(または他の変数)が表示されます。

Every 1.0s: psql -d postgresql://postgres:mysecretpassword@localhost:5439/dbname -c (...)
...

隠す機会がありますか?

ベストアンサー1

はい、-t説明されているようにこのオプションを使用してくださいturn off header

これにより、呼び出されたコマンドの出力のみが印刷されます。

追加情報:

$ watch --help

Usage:
 watch [options] command

Options:
  -b, --beep             beep if command has a non-zero exit
  -c, --color            interpret ANSI color and style sequences
  -d, --differences[=<permanent>]
                         highlight changes between updates
  -e, --errexit          exit if command has a non-zero exit
  -g, --chgexit          exit when output from command changes
  -n, --interval <secs>  seconds to wait between updates
  -p, --precise          attempt run command in precise intervals
  -t, --no-title         turn off header
  -x, --exec             pass command to exec instead of "sh -c"

 -h, --help     display this help and exit
 -v, --version  output version information and exit

For more details see watch(1).

おすすめ記事