Closed
Description
Hi!
I use sqlalchemy 1.4 with asyncpg driver with pgbouncer.
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.asyncio import AsyncSession
engine = create_async_engine(
f'postgresql+asyncpg://{username}:{password}@{host}:{port}/{dbname}',
echo=False,
)
session_maker = sessionmaker(
engine,
class_=AsyncSession,
)
I have an error:
asyncpg.exceptions.DuplicatePreparedStatementError: prepared statement "__asyncpg_stmt_a__" already exists
HINT:
NOTE: pgbouncer with pool_mode set to "transaction" or
"statement" does not support prepared statements properly.
You have two options:
* if you are using pgbouncer for connection pooling to a
single server, switch to the connection pool functionality
provided by asyncpg, it is a much better option for this
purpose;
* if you have no option of avoiding the use of pgbouncer,
then you can set statement_cache_size to 0 when creating
the asyncpg connection object.
How i can pass this setting (statement_cache_size=0) to asyncpg connection object?