Skip to content

Commit ebfe20d

Browse files
committed
Allow UNLISTEN in hot-standby mode.
Since LISTEN is (still) disallowed, UNLISTEN must be a no-op in a hot-standby session, and so there's no harm in allowing it. This change allows client code to not worry about whether it's connected to a primary or standby server when performing session-state-reset type activities. (Note that DISCARD ALL, which includes UNLISTEN, was already allowed, making it inconsistent to reject UNLISTEN.) Per discussion, back-patch to all supported versions. Shay Rojansky, reviewed by Mi Tar Discussion: https://postgr.es/m/CADT4RqCf2gA_TJtPAjnGzkC3ZiexfBZiLmA-mV66e4UyuVv8bA@mail.gmail.com
1 parent c9b75c5 commit ebfe20d

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

doc/src/sgml/high-availability.sgml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,11 @@ if (!triggered)
17671767
Plugins and extensions - <command>LOAD</command>
17681768
</para>
17691769
</listitem>
1770+
<listitem>
1771+
<para>
1772+
<command>UNLISTEN</command>
1773+
</para>
1774+
</listitem>
17701775
</itemizedlist>
17711776
</para>
17721777

@@ -1856,16 +1861,16 @@ if (!triggered)
18561861
</listitem>
18571862
<listitem>
18581863
<para>
1859-
<command>LISTEN</command>, <command>UNLISTEN</command>, <command>NOTIFY</command>
1864+
<command>LISTEN</command>, <command>NOTIFY</command>
18601865
</para>
18611866
</listitem>
18621867
</itemizedlist>
18631868
</para>
18641869

18651870
<para>
18661871
In normal operation, <quote>read-only</quote> transactions are allowed to
1867-
use <command>LISTEN</command>, <command>UNLISTEN</command>, and
1868-
<command>NOTIFY</command>, so Hot Standby sessions operate under slightly tighter
1872+
use <command>LISTEN</command> and <command>NOTIFY</command>,
1873+
so Hot Standby sessions operate under slightly tighter
18691874
restrictions than ordinary read-only sessions. It is possible that some
18701875
of these restrictions might be loosened in a future release.
18711876
</para>

src/backend/tcop/utility.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
629629
{
630630
UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
631631

632-
PreventCommandDuringRecovery("UNLISTEN");
632+
/* we allow UNLISTEN during recovery, as it's a noop */
633633
CheckRestrictedOperation("UNLISTEN");
634634
if (stmt->conditionname)
635635
Async_Unlisten(stmt->conditionname);

src/test/regress/expected/hs_standby_allowed.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ LOCK hs1 IN ACCESS SHARE MODE;
208208
LOCK hs1 IN ROW SHARE MODE;
209209
LOCK hs1 IN ROW EXCLUSIVE MODE;
210210
COMMIT;
211+
-- UNLISTEN
212+
UNLISTEN a;
213+
UNLISTEN *;
211214
-- LOAD
212215
-- should work, easier if there is no test for that...
213216
-- ALLOWED COMMANDS

src/test/regress/expected/hs_standby_disallowed.out

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ listen a;
118118
ERROR: cannot execute LISTEN during recovery
119119
notify a;
120120
ERROR: cannot execute NOTIFY during recovery
121-
unlisten a;
122-
ERROR: cannot execute UNLISTEN during recovery
123-
unlisten *;
124-
ERROR: cannot execute UNLISTEN during recovery
125121
-- disallowed commands
126122
ANALYZE hs1;
127123
ERROR: cannot execute ANALYZE during recovery

src/test/regress/sql/hs_standby_allowed.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ LOCK hs1 IN ROW SHARE MODE;
110110
LOCK hs1 IN ROW EXCLUSIVE MODE;
111111
COMMIT;
112112

113+
-- UNLISTEN
114+
UNLISTEN a;
115+
UNLISTEN *;
116+
113117
-- LOAD
114118
-- should work, easier if there is no test for that...
115119

src/test/regress/sql/hs_standby_disallowed.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ COMMIT;
8888
-- Listen
8989
listen a;
9090
notify a;
91-
unlisten a;
92-
unlisten *;
9391

9492
-- disallowed commands
9593

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy