summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/asyncpg.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2022-09-13 21:47:50 +0200
committerMike Bayer <mike_mp@zzzcomputing.com>2022-09-15 09:31:44 -0400
commit2e302b2d8feca685c8f1b8e2174f239086d239fa (patch)
tree1115cbe3510cf35a6bc7c96d495b31aa350c03b5 /lib/sqlalchemy/dialects/postgresql/asyncpg.py
parentde173b600b0d3747bcf1941e3027598c66da33ac (diff)
downloadsqlalchemy-2e302b2d8feca685c8f1b8e2174f239086d239fa.tar.gz
Use ``;`` instead of ``select 1`` to ping PostgreSQL
Fixes: #8491 Change-Id: I941d2a3cf92e5609e2045a53cec94522340951db
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/asyncpg.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/asyncpg.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/asyncpg.py b/lib/sqlalchemy/dialects/postgresql/asyncpg.py
index a84bece4f..4cc04d20a 100644
--- a/lib/sqlalchemy/dialects/postgresql/asyncpg.py
+++ b/lib/sqlalchemy/dialects/postgresql/asyncpg.py
@@ -741,6 +741,12 @@ class AsyncAdapt_asyncpg_connection(AdaptedConnection):
else:
self.isolation_level = self._isolation_setting
+ def ping(self):
+ try:
+ _ = self.await_(self._connection.fetchrow(";"))
+ except Exception as error:
+ self._handle_exception(error)
+
def set_isolation_level(self, level):
if self._started:
self.rollback()
@@ -996,6 +1002,17 @@ class PGDialect_asyncpg(PGDialect):
util.coerce_kw_type(opts, "port", int)
return ([], opts)
+ def do_ping(self, dbapi_connection):
+ try:
+ dbapi_connection.ping()
+ except self.dbapi.Error as err:
+ if self.is_disconnect(err, dbapi_connection, None):
+ return False
+ else:
+ raise
+ else:
+ return True
+
@classmethod
def get_pool_class(cls, url):