add: Log actual host and port of listener connection

Diagnosing problems with listener channel notifications not being handled properly by PostgREST connected to read replicas is difficult. Issues might be related to lost connections and listener not being connected to the right host after failover or database server restarts.
This patch adds logging of actual host:port used by libpq connection opened by the listener. It should make it easier to find out if PostgREST is connected to the right host.
This commit is contained in:
Michał Kłeczek
2026-04-06 11:11:16 -05:00
committed by Steve Chavez
parent 5eac8bd203
commit 34a767a5cc
5 changed files with 32 additions and 8 deletions
+17
View File
@@ -1658,6 +1658,23 @@ def test_log_listener_connection_errors(defaultenv):
)
def test_log_listener_connection_start(defaultenv):
"The logs should show the listener connection start message in a single line"
env = {
**defaultenv,
"PGRST_DB_CHANNEL_ENABLED": "true",
}
with run(env=env, no_startup_stdout=False, wait_for_readiness=True) as postgrest:
output = postgrest.read_stdout(nlines=5)
assert any(
f'Listener connected to "{defaultenv["PGHOST"]}:5432" and listening for database notifications on the "pgrst" channel'
in line
for line in output
)
def test_db_pre_config_with_pg_reserved_words(defaultenv):
"The db-pre-config should not fail unexpectedly when function name is a postgres reserved word"
+1 -1
View File
@@ -206,5 +206,5 @@ waitForObs (ObsChan orig copy) t msg f =
obsDiagMessage :: Observation -> Text
obsDiagMessage = \case
(HasqlPoolObs o) -> show o
o@(DBListenStart channel) -> constrName o <> show channel
o@(DBListenStart host port channel) -> constrName o <> show (host, port, channel)
o -> constrName o