Skip to content

Commit 0d5b273

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 adc2553 commit 0d5b273

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
@@ -1686,6 +1686,11 @@ if (!triggered)
16861686
Plugins and extensions - <command>LOAD</>
16871687
</para>
16881688
</listitem>
1689+
<listitem>
1690+
<para>
1691+
<command>UNLISTEN</command>
1692+
</para>
1693+
</listitem>
16891694
</itemizedlist>
16901695
</para>
16911696

@@ -1775,16 +1780,16 @@ if (!triggered)
17751780
</listitem>
17761781
<listitem>
17771782
<para>
1778-
<command>LISTEN</>, <command>UNLISTEN</>, <command>NOTIFY</>
1783+
<command>LISTEN</>, <command>NOTIFY</>
17791784
</para>
17801785
</listitem>
17811786
</itemizedlist>
17821787
</para>
17831788

17841789
<para>
17851790
In normal operation, <quote>read-only</> transactions are allowed to
1786-
use <command>LISTEN</>, <command>UNLISTEN</>, and
1787-
<command>NOTIFY</>, so Hot Standby sessions operate under slightly tighter
1791+
use <command>LISTEN</command> and <command>NOTIFY</command>,
1792+
so Hot Standby sessions operate under slightly tighter
17881793
restrictions than ordinary read-only sessions. It is possible that some
17891794
of these restrictions might be loosened in a future release.
17901795
</para>

src/backend/tcop/utility.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ standard_ProcessUtility(Node *parsetree,
621621
{
622622
UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
623623

624-
PreventCommandDuringRecovery("UNLISTEN");
624+
/* we allow UNLISTEN during recovery, as it's a noop */
625625
CheckRestrictedOperation("UNLISTEN");
626626
if (stmt->conditionname)
627627
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