From 8cd374ba8a2bcf88dfcfda785b54a58c581fd0cd Mon Sep 17 00:00:00 2001 From: Igor Khlepitko Date: Tue, 2 Feb 2021 22:11:21 +0100 Subject: [PATCH] Avoid unnecessary overhead during connection reset UNLISTEN is now available in Hot Standby mode in all supported PostgreSQL versions, therefore there's no reason anymore to wrap it in DO block. This should significantly speed up connection reset. --- asyncpg/connection.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/asyncpg/connection.py b/asyncpg/connection.py index e62928f7..2b21247e 100644 --- a/asyncpg/connection.py +++ b/asyncpg/connection.py @@ -1501,16 +1501,7 @@ def _get_reset_query(self): if caps.sql_close_all: _reset_query.append('CLOSE ALL;') if caps.notifications and caps.plpgsql: - _reset_query.append(''' - DO $$ - BEGIN - PERFORM * FROM pg_listening_channels() LIMIT 1; - IF FOUND THEN - UNLISTEN *; - END IF; - END; - $$; - ''') + _reset_query.append('UNLISTEN *;') if caps.sql_reset: _reset_query.append('RESET ALL;')