Skip to content

Commit 549d2a2

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 6d63337 commit 549d2a2

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
@@ -1591,6 +1591,11 @@ if (!triggered)
15911591
Plugins and extensions - <command>LOAD</>
15921592
</para>
15931593
</listitem>
1594+
<listitem>
1595+
<para>
1596+
<command>UNLISTEN</command>
1597+
</para>
1598+
</listitem>
15941599
</itemizedlist>
15951600
</para>
15961601

@@ -1680,16 +1685,16 @@ if (!triggered)
16801685
</listitem>
16811686
<listitem>
16821687
<para>
1683-
<command>LISTEN</>, <command>UNLISTEN</>, <command>NOTIFY</>
1688+
<command>LISTEN</>, <command>NOTIFY</>
16841689
</para>
16851690
</listitem>
16861691
</itemizedlist>
16871692
</para>
16881693

16891694
<para>
16901695
In normal operation, <quote>read-only</> transactions are allowed to
1691-
use <command>LISTEN</>, <command>UNLISTEN</>, and
1692-
<command>NOTIFY</>, so Hot Standby sessions operate under slightly tighter
1696+
use <command>LISTEN</command> and <command>NOTIFY</command>,
1697+
so Hot Standby sessions operate under slightly tighter
16931698
restrictions than ordinary read-only sessions. It is possible that some
16941699
of these restrictions might be loosened in a future release.
16951700
</para>

src/backend/tcop/utility.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ standard_ProcessUtility(Node *parsetree,
608608
{
609609
UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
610610

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