N
Neonβ€’17h ago
other-emerald

Getting "pq: unnamed prepared statement does not exist" error

Hi! I'm getting "pq: unnamed prepared statement does not exist" errors when using pooled connections (-pooler) Tech stack: React + Go + database/sql + sqlc. Setup: - Go app with database/sql and pq driver - Using dynamic queries with parameterized placeholders (?, $1, $2, etc.) - No explicit PREPARE/EXECUTE statements in my SQL - Railway hosting, need to handle ~1k concurrent users - 1 vCPU compute (450 max_connections limit) Pattern: GET requests work fine, but PUT β†’ immediate GET requests fail with the prepared statement error. Questions: 1. Should I use pooled (-pooler) or direct connections for my use case? 2. Any known issues with protocol-level prepared statements in PgBouncer transaction mode? 3. With 1k users, will I hit connection limits without pooling? Code uses standard parameterized queries like: SELECT * FROM attendees WHERE event_id = $1 AND first_name ILIKE $2 Any insights appreciated! πŸ™
3 Replies
other-emerald
other-emeraldOPβ€’16h ago
Perhaps simply adding prefer_simple_protocol=true in the connection string could help?
harsh-harlequin
harsh-harlequinβ€’16h ago
Hey! Looks like this SO thread might be of use to you. As for your questions : 1. Stick with the pgbouncer pooler if you can (using the fixes from the SO post) 2. Yes, there is no persistent backend session between transactions when pgbouncer is in transaction mode which is needed for protocol-level prepared statements 3. Depends a lot on database usage for those concurrent 1k users
Stack Overflow
pq driver: prepared statement does not exist
I'm trying to connect to a postresql database with the pq driver in Go. When I do it on a local copy of the database, with a connection string like DB, err = sql.Open("postgres", "user=user passwo...
other-emerald
other-emeraldOPβ€’7h ago
Thanks. I should've searched first before asking here 🀦🏻 Adding binary_parameters=yes to the connection string worked for me. My problem was pq driver relied on unnamed prepared statements and since PgBouncer transaction pooling reuses backend connections, those unnamed statements weren't guaranteed to exist. https://github.com/grafana/xk6-sql/issues/31

Did you find this page helpful?