Skip to content

Commit

Permalink
Avoid unnecessary overhead during connection reset (#648)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kitogo authored Feb 10, 2021
1 parent 0dd636f commit ff5da5f
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions asyncpg/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;')

Expand Down

0 comments on commit ff5da5f

Please sign in to comment.