Skip to content

Commit af5e9d4

Browse files
committed
Execute UNLISTEN unconditionally in connection reset query
Currently, `UNLISTEN` in connection release is guarded by an expensive PL/pgSQL block, because historically PostgreSQL did not allow `UNLISTEN` on a hot standby node. This has since changed, and `UNLISTEN` is allowed in PostgreSQL 9.4.21+, 9.5.16+, 9.6.12+, 10.7+, 11.2+, and versions 12 and newer. If this change breaks your setup, upgrade your server. The removal of the PL/pgSQL guard reduces the `acquire`/`release` overhead by over 50%. Upstream discussion: https://postgr.es/m/CADT4RqCf2gA_TJtPAjnGzkC3ZiexfBZiLmA-mV66e4UyuVv8bA@mail.gmail.com Fixes: #648
1 parent 0dd636f commit af5e9d4

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

asyncpg/connection.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -1500,17 +1500,8 @@ def _get_reset_query(self):
15001500
_reset_query.append('SELECT pg_advisory_unlock_all();')
15011501
if caps.sql_close_all:
15021502
_reset_query.append('CLOSE ALL;')
1503-
if caps.notifications and caps.plpgsql:
1504-
_reset_query.append('''
1505-
DO $$
1506-
BEGIN
1507-
PERFORM * FROM pg_listening_channels() LIMIT 1;
1508-
IF FOUND THEN
1509-
UNLISTEN *;
1510-
END IF;
1511-
END;
1512-
$$;
1513-
''')
1503+
if caps.notifications:
1504+
_reset_query.append('UNLISTEN *;')
15141505
if caps.sql_reset:
15151506
_reset_query.append('RESET ALL;')
15161507

0 commit comments

Comments
 (0)