From a62b6de1d0e93071d3fee87ceb58564d98c09e19 Mon Sep 17 00:00:00 2001 From: Michal Kleczek Date: Fri, 1 May 2026 00:21:12 +0200 Subject: [PATCH] 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 870d74f7b..cd817aa31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. From versio ### Fixed - Fix login with uppercase and mixed case role names by @taimoorzaeem in #4678 +- Restore Listener query shape so it can be found in `pg_stat_activity` by @mkleczek in #4857 #4859 ## [14.10] - 2026-04-16 diff --git a/src/PostgREST/Listener.hs b/src/PostgREST/Listener.hs index e801e1d69..9dc5d3edc 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 False) 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 fca923788..31a5b82a6 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 @@ -542,6 +543,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"