Skip to content

Avoid Repeated Type Introspection Queries in asyncpg with NullPool and PgBouncer (Session Mode) #1242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
garima-trivedi opened this issue Mar 10, 2025 · 0 comments · Fixed by #1243

Comments

@garima-trivedi
Copy link

asyncpg version: 0.30.0
PostgreSQL version: 16.6
Do you use a PostgreSQL SaaS? If so, which? AWS Postgres Aurora
Can you reproduce: yes

Python version: 3.11

Do you use pgbouncer?: yes
Did you install asyncpg with pip?: yes
If you built asyncpg locally, which version of Cython did you use?: N/A
Can the issue be reproduced under both asyncio and
uvloop?: yes

When using PgBouncer in session mode with asyncpg, setting NullPool in SQLAlchemy (asyncpg) is required to avoid per-process connection pools. However, this causes asyncpg to trigger type introspection queries on every connection checkout from PgBouncer Pool. Even when jit=off, type introspection queries take a few milliseconds each time, adding unnecessary overhead.

Since introspection happens only once per connection, a solution is needed to preload type codecs and prevent repeated introspection queries.

Provide a mechanism to preload type codecs once per connection, ensuring that asyncpg does not re-run introspection queries on every checkout from the PgBouncer pool. This would improve performance when using asyncpg with external connection pooling solutions like PgBouncer.

Would love to hear thoughts from the community on potential solutions or workarounds!

elprans added a commit that referenced this issue Mar 15, 2025
Type codec setup functions will no longer attempt to introspect the type
if it's one of the known builtin types.

Fixes: #1206
Fixes: #1138
Fixes: #1242
elprans added a commit that referenced this issue Mar 15, 2025
Type codec setup functions will no longer attempt to introspect the type
if it's one of the known builtin types.

Fixes: #1206
Fixes: #1138
Fixes: #1242
elprans added a commit that referenced this issue Mar 15, 2025
Type codec setup functions will no longer attempt to introspect the type
if it's one of the known builtin types.

Fixes: #1206
Fixes: #1138
Fixes: #1242
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant