MagicStack / asyncpg

A fast PostgreSQL Database Client Library for Python/asyncio.
Apache License 2.0
6.99k stars 404 forks source link

Add support for `after_connect` statements when `server_settings` are not supported #1013

Closed mbrancato closed 1 year ago

mbrancato commented 1 year ago

In a very large environment, pooling along is not enough, and we use pgbouncer to help control connections to the DB. The problem is that pgbouncer does not support some of the parameters. This includes settings like statement_timeout and lock_timeout.

Other pooling libraries support a set of queries that run after connect and at other points in the connection lifecycle.

It would be nice if asyncpg could allow queries / exec to call SET in the connection before it enters the pool to enforce these settings.

elprans commented 1 year ago

It's already implemented, as the init kwarg to connect and create_pool:

pool = await asyncpg.create_pool(..., init=your_callback)

Is that what you're looking for?

mbrancato commented 1 year ago

Yes, I think that works. I didn't realize that form the docs.