Re: PoC - psql - emphases line with table name in verbose output

Jim Jones <jim.jones@uni-muenster.de>

From: Jim Jones <jim.jones@uni-muenster.de>
To: Pavel Stehule <pavel.stehule@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-04-23T15:17:47Z
Lists: pgsql-hackers
Hi Pavel

On 14/04/2026 05:42, Pavel Stehule wrote:
> rebase, new commit message and minor cleaning
Thanks for the patch!

I tested the patch and setting PG_COLOR highlights the INFO messages.

A few observations:

== string matching is locale-fragile ==

Since the code relies on these fixed strings ...

if (level == PG_LOG_INFO && sgr_info_command &&
  (strncmp(buf, "INFO:  vacuuming", strlen("INFO:  vacuuming")) == 0 ||
   strncmp(buf, "INFO:  repacking", strlen("INFO:  repacking")) == 0 ||
   strncmp(buf, "INFO:  analyzing", strlen("INFO:  analyzing")) == 0))

.. the conditions only work if lc_messages is set to English. For
instance, in German you get a different string, which means that
highlighting won't work:

$ psql postgres -c "VACUUM VERBOSE pg_class;" 2>&1 | grep INFO
INFO:  Vacuum von »postgres.pg_catalog.pg_class«
INFO:  beende Vacuum der Tabelle »postgres.pg_catalog.pg_class«:
Index-Scans: 0

$ psql postgres -c "ANALYSE VERBOSE pg_class;" 2>&1 | grep INFO
INFO:  analysiere »pg_catalog.pg_class«
INFO:  »pg_class«: 15 von 15 Seiten gelesen, enthalten 452 lebende
Zeilen und 0 tote Zeilen; 452 Zeilen in Stichprobe, schätzungsweise 452
Zeilen insgesamt
INFO:  finished analyzing table "postgres.pg_catalog.pg_class"

== fixed command list ==

Future verbose operations, if not added to this list, would silently get
no highlighting.

I'm wondering if it is possible to achieve it (locale-agnostic) only for
certain commands without touching the code on the server side. Only by
checking strings it'll be difficult to identify which INFO messages to
highlight.

Thanks!

Best, Jim