From b8f83bdbb4b0ba7adca6563758c292616af7b0b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C5=82eczek?= Date: Wed, 29 Apr 2026 06:09:58 +0200 Subject: [PATCH 1/2] fix: Restore showing LISTEN pgrst in pg_stat_activity --- CHANGELOG.md | 1 + src/PostgREST/Listener.hs | 2 +- test/io/test_io.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd331b62c2..489a0cadc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file. From versio - Fix login with uppercase and mixed case role names by @taimoorzaeem in #4678 - Remove automatic transaction retries on `40001 (serialization_failure)` errors to prevent replication lag by @laurenceisla in #3673 - Fix unexpected results when embedding and filtering the same table more than once by @laurenceisla in #4075 +- Make sure `LISTEN ` query is present in pg_stat_activity row corresponding to session established by notification listening thread by @mkleczek in #4857 #4859 ### Changed diff --git a/src/PostgREST/Listener.hs b/src/PostgREST/Listener.hs index 80c65c2189..f4628122a3 100644 --- a/src/PostgREST/Listener.hs +++ b/src/PostgREST/Listener.hs @@ -68,9 +68,9 @@ retryingListen appState = do -- use connection \case Right db -> do - SQL.listen db $ SQL.toPgIdentifier dbChannel (pqHost, pqPort) <- SQL.withLibPQConnection db $ bisequence . (LibPQ.host &&& LibPQ.port) pgFullName <- SQL.run queryPgVersion db >>= either throwIO (pure . pgvFullName) + SQL.listen db $ SQL.toPgIdentifier dbChannel AppState.putIsListenerOn appState True diff --git a/test/io/test_io.py b/test/io/test_io.py index 03cc458932..c59721ebc8 100644 --- a/test/io/test_io.py +++ b/test/io/test_io.py @@ -3,6 +3,7 @@ import os import re import signal +import subprocess import time import pytest @@ -690,6 +691,39 @@ def test_admin_ready_w_channel(defaultenv): assert response.status_code == 200 +def test_listener_query_is_visible_in_pg_stat_activity(defaultenv): + "The listener connection should show the LISTEN pgrst statement in pg_stat_activity" + + env = { + **defaultenv, + "PGRST_DB_CHANNEL_ENABLED": "true", + "PGAPPNAME": "listener-query-test", + } + + with run(env=env): + query = """ +select query +from pg_stat_activity +where application_name = 'listener-query-test' + and query = 'LISTEN "pgrst"' +limit 1; +""" + output = subprocess.check_output( + [ + "psql", + "--set", + "ON_ERROR_STOP=1", + "--tuples-only", + "--no-align", + "-c", + query, + ], + text=True, + ).strip() + + assert output == 'LISTEN "pgrst"' + + def test_admin_ready_wo_channel(defaultenv): "Should get a success response from the admin server ready endpoint when the LISTEN channel is disabled" From 81335bd40b4207510cf55e09ca3d483307c0d1ce Mon Sep 17 00:00:00 2001 From: Steve Chavez Date: Thu, 30 Apr 2026 16:45:42 -0500 Subject: [PATCH 2/2] chore: Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 489a0cadc0..d8d651d393 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ All notable changes to this project will be documented in this file. From versio - Fix login with uppercase and mixed case role names by @taimoorzaeem in #4678 - Remove automatic transaction retries on `40001 (serialization_failure)` errors to prevent replication lag by @laurenceisla in #3673 - Fix unexpected results when embedding and filtering the same table more than once by @laurenceisla in #4075 -- Make sure `LISTEN ` query is present in pg_stat_activity row corresponding to session established by notification listening thread by @mkleczek in #4857 #4859 +- Restore Listener query shape so it can be found in pg_stat_activity by @mkleczek in #4857 #4859 ### Changed