From b85d36120cd06d223772e925152f78fb65dc42a5 Mon Sep 17 00:00:00 2001 From: Anthonin Bonnefoy Date: Wed, 23 Sep 2026 10:26:54 +0200 Subject: Add HIDE_NOTIFICATIONS parameter to psql for regression testing Add a new HIDE_NOTIFICATIONS parameter to pset to silence notifications, allowing to execute LISTEN/NOTIFY queries with a payload in the regression tests. --- src/bin/psql/common.c | 17 ++++++++++------- src/bin/psql/settings.h | 1 + src/bin/psql/startup.c | 9 +++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index f220344daaf..388cb975b9c 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -752,13 +752,16 @@ PrintNotifications(void) PQconsumeInput(pset.db); while ((notify = PQnotifies(pset.db)) != NULL) { - /* for backward compatibility, only show payload if nonempty */ - if (notify->extra[0]) - fprintf(pset.queryFout, _("Asynchronous notification \"%s\" with payload \"%s\" received from server process with PID %d.\n"), - notify->relname, notify->extra, notify->be_pid); - else - fprintf(pset.queryFout, _("Asynchronous notification \"%s\" received from server process with PID %d.\n"), - notify->relname, notify->be_pid); + if (!pset.hide_notifications) + { + /* for backward compatibility, only show payload if nonempty */ + if (notify->extra[0]) + fprintf(pset.queryFout, _("Asynchronous notification \"%s\" with payload \"%s\" received from server process with PID %d.\n"), + notify->relname, notify->extra, notify->be_pid); + else + fprintf(pset.queryFout, _("Asynchronous notification \"%s\" received from server process with PID %d.\n"), + notify->relname, notify->be_pid); + } fflush(pset.queryFout); PQfreemem(notify); PQconsumeInput(pset.db); diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h index a3d088d80cd..89403959238 100644 --- a/src/bin/psql/settings.h +++ b/src/bin/psql/settings.h @@ -168,6 +168,7 @@ typedef struct _psqlSettings bool singleline; bool singlestep; bool hide_compression; + bool hide_notifications; bool hide_tableam; int fetch_count; int histsize; diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index bb33c7c14d7..c0c6ceabd30 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -1213,6 +1213,12 @@ hide_compression_hook(const char *newval) &pset.hide_compression); } +static bool +hide_notifications_hook(const char *newval) +{ + return ParseVariableBool(newval, "HIDE_NOTIFICATIONS", &pset.hide_notifications); +} + static bool hide_tableam_hook(const char *newval) { @@ -1287,6 +1293,9 @@ EstablishVariableSpace(void) SetVariableHooks(pset.vars, "HIDE_TOAST_COMPRESSION", bool_substitute_hook, hide_compression_hook); + SetVariableHooks(pset.vars, "HIDE_NOTIFICATIONS", + bool_substitute_hook, + hide_notifications_hook); SetVariableHooks(pset.vars, "HIDE_TABLEAM", bool_substitute_hook, hide_tableam_hook); -- 2.50.1 (Apple Git-155)