Skip to content

allow setting statement name in set_type_codec #1131

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

Conversation

CobaltCause
Copy link

This is necessary when using PgBouncer because otherwise the default simplistically-generated statement names can fight with other programs using asyncpg due to PgBouncer sharing the same underlying PostgreSQL connection and thus the prepared statement names.

Supposedly asyncpg can be made to use an unnamed statement here by turning the cache off, but I can't for the life of me figure out how to do that when using asyncpg through SQLAlchemy; I observe that setting prepared_statement_cache_size to 0 as described here doesn't cause use_cache to be False. Anyway, that's not really asyncpg's problem.

I think this functionality should probably be provided either way since it'd be kinda weird to only allow configuring the names of some prepared statements.

This is necessary when using PgBouncer because otherwise the default
simplistically-generated statement names can fight with other programs
using asyncpg due to PgBouncer sharing the same underlying PostgreSQL
connection and thus the prepared statement names.

[Supposedly asyncpg can be made to use an unnamed statement here by
turning the cache off][0], but I can't for the life of me figure
out how to do that when using asyncpg through SQLAlchemy; I observe that
setting `prepared_statement_cache_size` to `0` as described [here][1]
doesn't cause `use_cache` to be `False`. Anyway, that's not really
asyncpg's problem.

I think this functionality should probably be provided either way
since it'd be kinda weird to only allow configuring the names of *some*
prepared statements.

[0]: https://github.com/MagicStack/asyncpg/blob/1aab2094d82104d5eee2cffcfd0c7e7347d4c5b8/asyncpg/connection.py#L415-L424
[1]: https://docs.sqlalchemy.org/en/20/dialects/postgresql.html#prepared-statement-cache
@CobaltCause CobaltCause force-pushed the set-type-codec-name branch from f63c7a9 to c266796 Compare March 11, 2024 23:39
@CobaltCause
Copy link
Author

Closing this since it's been a while and I've since solved my problem by using psycopg3 instead, which supports disabling prepared statements altogether.

@CobaltCause CobaltCause deleted the set-type-codec-name branch April 28, 2024 02:30
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 this pull request may close these issues.

1 participant