there!
I use PgBouncer
with Sqlalchemy
for getting connections.
For my understanding, I would like to clarify the following points:
I use the sqlalchemy default pool (
QueuePool
) and take connections from my pgbouncer. After the transaction is completed, is the connection returned to the"lazy"
connection storage on my side (sqlalchemy
) or directly to thepgbouncer pool
?If I use
QueuePool
withpool_size=5
parameters and create an engine forpgbouncer
pool, doespgbouncer
allocate these 5 connections at once, or are the connections given on demand?If I remove the connection pooling (using
NullPool
) and also create an engine forpgbouncer
, does this mean that after exiting the transaction context, the connection is closed and a new one will be created already insidepgbouncer
at the next request?Which of these approaches is more correct in the context of using
sqlalchemy + pgbouncer
?
With connections I work like this:
async with async_session() as connect:
yield connect
await connect.commit()