UNI12345 commited on
Commit
f3c8882
·
1 Parent(s): 84f9383

Configure unique prepared statement naming func for asyncpg to fully resolve PgBouncer conflicts

Browse files
Files changed (1) hide show
  1. app/database.py +5 -2
app/database.py CHANGED
@@ -7,8 +7,10 @@ database_url = settings.DATABASE_URL
7
  if database_url.startswith("postgresql://"):
8
  database_url = database_url.replace("postgresql://", "postgresql+asyncpg://", 1)
9
 
 
 
10
  # Enable connection pooling options since we connect to Supabase
11
- # Connect with prepared_statement_cache_size=0 to prevent PgBouncer prepared statement conflicts
12
  engine = create_async_engine(
13
  database_url,
14
  echo=settings.DEBUG,
@@ -17,7 +19,8 @@ engine = create_async_engine(
17
  pool_pre_ping=True,
18
  connect_args={
19
  "statement_cache_size": 0,
20
- "prepared_statement_cache_size": 0
 
21
  }
22
  )
23
 
 
7
  if database_url.startswith("postgresql://"):
8
  database_url = database_url.replace("postgresql://", "postgresql+asyncpg://", 1)
9
 
10
+ from uuid import uuid4
11
+
12
  # Enable connection pooling options since we connect to Supabase
13
+ # Connect with prepared_statement_cache_size=0 and unique statement names to prevent PgBouncer conflicts
14
  engine = create_async_engine(
15
  database_url,
16
  echo=settings.DEBUG,
 
19
  pool_pre_ping=True,
20
  connect_args={
21
  "statement_cache_size": 0,
22
+ "prepared_statement_cache_size": 0,
23
+ "prepared_statement_name_func": lambda: f"__asyncpg_{uuid4().hex}__"
24
  }
25
  )
26