Skip to content

Commit e8ec19c

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 5b5cb3b commit e8ec19c

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
@@ -1768,6 +1768,11 @@ if (!triggered)
17681768
Plugins and extensions - <command>LOAD</>
17691769
</para>
17701770
</listitem>
1771+
<listitem>
1772+
<para>
1773+
<command>UNLISTEN</command>
1774+
</para>
1775+
</listitem>
17711776
</itemizedlist>
17721777
</para>
17731778

@@ -1857,16 +1862,16 @@ if (!triggered)
18571862
</listitem>
18581863
<listitem>
18591864
<para>
1860-
<command>LISTEN</>, <command>UNLISTEN</>, <command>NOTIFY</>
1865+
<command>LISTEN</>, <command>NOTIFY</>
18611866
</para>
18621867
</listitem>
18631868
</itemizedlist>
18641869
</para>
18651870

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

src/backend/tcop/utility.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
641641
{
642642
UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
643643

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