Skip to contentSkip to conversation

hashserv: Re-enable connection pooling with psycopg 3 driver

PATCH New Tobias Hagelborn 1 participant 1 message Feb 23, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hashserv: Re-enable connection pooling with psycopg 3 driver

Re-enable connection pooling in case postgresql+psygopg driver is used. Async connection pooling is supported in psycopg 3 [psycopg] driver in SQLAlchemy. Allow the connection pool to grow to arbitrary size.

---

Added unlimited pool size.
Validated with local stress tests and real builds.

 lib/hashserv/sqlalchemy.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/hashserv/sqlalchemy.py +5 -1
index fc3ae3d33..f7b0226a7 100644
@@ -129,7 +129,11 @@ class DatabaseEngine(object):
             return inspect(conn).has_table(name)
 
         self.logger.info("Using database %s", self.url)
-        self.engine = create_async_engine(self.url, poolclass=NullPool)
+        if self.url.drivername == 'postgresql+psycopg':
+            # Psygopg 3 (psygopg) driver can handle async connection pooling
+            self.engine = create_async_engine(self.url, max_overflow=-1)
+        else:
+            self.engine = create_async_engine(self.url, poolclass=NullPool)
 
         async with self.engine.begin() as conn:
             # Create tables
Signature · 1 line
2.30.2