postgres=# select * from sessions where video_id = 'vTV8XhWf3mo';

Postgres Hacking 101: \watch with limited loops

· 56:56 · SQL & client

Add a maximum iteration count to psql \watch.

session summary

The main exercise added a maximum iteration count to psql's backslash-watch command, allowing monitoring or sampling queries to stop automatically. Parsing a second optional argument exposed subtleties in psql's meta-command scanner, whitespace handling, defaults, and preserving unlimited behavior; the live prototype was close but still malfunctioned and needed offline cleanup before its later upstream completion. The final segment reviewed a proposed pg_stat_session view, questioning its per-backend memory and runtime overhead, missing functional tests, and practical value to DBAs.

timecodes

  1. Use case for a bounded psql watch
  2. ULID work shifts toward UUIDv7
  3. Starting the psql meta-command patch
  4. Tracing watch argument parsing
  5. Adding the optional iteration argument
  6. Learning how multi-argument meta-commands parse
  7. Iteration defaults and preserving infinity
  8. Reviewing pg_stat_session counters and overhead