diff --git a/patroni/postgresql/connection.py b/patroni/postgresql/connection.py index 933ee89c..434bda59 100644 --- a/patroni/postgresql/connection.py +++ b/patroni/postgresql/connection.py @@ -40,7 +40,8 @@ class Connection(object): @contextmanager def get_connection_cursor(**kwargs): - with psycopg2.connect(**kwargs) as conn: - conn.autocommit = True - with conn.cursor() as cur: - yield cur + conn = psycopg2.connect(**kwargs) + conn.autocommit = True + with conn.cursor() as cur: + yield cur + conn.close()