psycopg 3 connection pool versus sqlalchemy connection pool #7478
Replies: 2 comments 8 replies
-
im not familiar with psycopg3's pool, but if pooling performance is super important to you, and your application runs with more than one Python process (very likely if performance matters), you'd be better off using pgbouncer. that is, the main "pool" issue is that Python processes that all have their own pool don't share the connections as efficiently as if you have high performance middleware handling it.
looking at https://www.psycopg.org/psycopg3/docs/advanced/pool.html it looks like psycopg3's pool is thankfully not implicit, you use a pool object explicitly, so out of the box, psycopg3's pool would not be used, so no.
sure, you would set up for NullPool in your create_engine and then write a creator function that uses the pool. Here is an example that is doing this identical thing for cx_Oracle's connection pool, you can use this as is, just replace the cx_Oracle functions for the psycopg3 ones: https://docs.sqlalchemy.org/en/14/dialects/oracle.html#using-cx-oracle-sessionpool that example is there because folks wanted to use that pool, I think cx_Oracle's pool might be tapping into some more enterprise-level Oracle server stuff (like middleware) that would make it worth it.
SQLAlchemy is designed around the assumptions used by this pool so for most predictable results, mostly in the area of what happens when connections are killed by the server and similar areas, you'd use the built-in pool. Looking at psycopg3's docs, looks like some pretty useful things are lacking:
ouch. that's a basic one. pgbouncer has this, SQLAlchemy has this for every DB (pool_pre_ping), im pretty sure Hibernate's pools have this, if psycopg3 wants to provide a connection pool it should be adding this.
SQLAlchemy's pool does not do this either but we have a pool_recycle option that helps a lot with this, though the pre-ping option prior is mostly all you need.
|
Beta Was this translation helpful? Give feedback.
-
|
I'm experiencing a similar issue. sqlalchemy_engine = create_async_engine(
url=settings.db_url,
async_creator=pool.getconn,
poolclass=NullPool,
)However, this code doesn’t work as expected. According to the API doc, I need to call Additionally, regarding the statement:
This appears to be outdated. psycopg now includes a |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
With more advanced features coming in the psycopg 3 connection pool, I'm wondering:
Interested to hear comments from @dvarrazzo as well. Thanks
Beta Was this translation helpful? Give feedback.
All reactions