NeonDbError: prepared statement "s4908" already exists
Getting the following error: NeonDbError: prepared statement "s4908" already exists
And now also: NeonDbError: prepared statement "s5046" does not exist
Not sure what could cause this, as I am not using prepared statements.
If it matters, I'm using Drizzle, and this is how I instantiate the db
7 Replies
national-goldOP•2y ago
I have pgbouncer=true on my connection string
eastern-cyan•2y ago
I have the same issue using Prisma Accelerate within Cloudflare Workers, for the past ~5 days
I am using the "-pooler" suffix connection string with:
pgbouncer=true&sslmode=require&connect_timeout=15&pool_timeout=15
My connection string has the following parameters:
eastern-cyan•2y ago
I found this comment on the neondatabase GitHub repository
https://github.com/neondatabase/neon/issues/4596#issuecomment-1873785419
Hey. we released a relevant pgbouncer version but were forced to roll it back because of Prisma support. The fix was placed into pgbouncer (pgbouncer/pgbouncer#972), and we already have this version on production, but with disabled prepared statements – the idea to roll it out gradually in January'24.
GitHub
Epic: Support Prepared Statements in PgBouncer · Issue #4596 · neon...
Motivation There were a bunch of requests from users about it. DoD As a user, I can create a prepared statement using the pooled connection. As a user, I can execute the prepared statement with dif...
stormy-gold•2y ago
I'm having the same issue with Drizzle + Neon. I'm also using the
pooler
url and have the pgbouncer=true
flag set. When I refresh the page, the request goes through.
This issue is making the app unusable. Is there a suggested workaround?
Like the code above, I'm also making a few DB calls inside a await Promise.all([...])
.
Interestingly, refactoring promise.all to N separate awaits appears to remediate the issue, but this has an impact on performance. I'm still very interested in a work-around that still allows me to make multiple async calls at once.
The issue also seems to happen when I'm reloading the Astro dev sever. Perhaps that's related too.fascinating-indigo•2y ago
@san4d can you share a small reproduction? If I understand correctly you're issuing queries (not using prepared statements) through the pooled URL, and are receiving an error?
stormy-gold•2y ago
I was not intentionally using prepared statements, but something about my setup seems to be using them. I followed the adjustments in this issue to resolve my issue:
https://discord.com/channels/1176467419317940276/1176467419938701375/1201569843258855585
My queries were selects with some joins. Here are the three concurrent queries, though I'm not sure which caused the error.
fascinating-indigo•2y ago
Ah, OK. Good to know you have a workaround for now. It sounds like the ongoing issue we've seen with pgbouncer, and some drivers using them during initialisation. We hope to roll out a fix for that rolled out soon.