[Error] Using Drizzle with Neon DB
Is drizzle compatible with neon pooled connections? Neon pooled connections don't support prepared statements, and it seems like drizzle uses prepared statements internally for all requests, but I'm not sure.
https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/pg-core/query-builders/select.ts#L537
https://neon.tech/docs/connect/connection-pooling
--
We've been getting many issues with our nextjs/vercel serverless production app using
drizzle-orm/neon-http
, @neondatabase/serverless
, and neon pooled connection with autoscaling. Issues like "prepared statement x doesn't exist" and db connections becoming clogged. Wondering if this might be a cause for thatNeon
Connection pooling - Neon Docs
Neon uses PgBouncer to offer support for connection pooling, enabling up to 10,000 concurrent connections. PgBouncer is a lightweight connection pooler for Postgres. This topic describes Neon's defaul...
GitHub
drizzle-orm/drizzle-orm/src/pg-core/query-builders/select.ts at mai...
TypeScript ORM that feels like writing SQL. Contribute to drizzle-team/drizzle-orm development by creating an account on GitHub.
9 Replies
postgresjs auto generates prepared statements by default if you're using that
https://github.com/porsager/postgres#prepared-statements
GitHub
GitHub - porsager/postgres: Postgres.js - The Fastest full featured...
Postgres.js - The Fastest full featured PostgreSQL client for Node.js and Deno - GitHub - porsager/postgres: Postgres.js - The Fastest full featured PostgreSQL client for Node.js and Deno
Not using this in our code, is it used in drizzle?
Sorry didn't see that you were using @Neondatabase/serverless. Drizzle doesn't use prepared statements for all requests internally
Just wondering, what are the names of the prepared statements that don't exist?
“s11383”, “s11367”, etc “s” followed by some numbers. We don’t explicitly use .prepare() for any of our queries
It seems like drizzle prepares statements to execute here using _prepare, but my reading of the code might be wrong
https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/pg-core/query-builders/select.ts#L537
GitHub
drizzle-orm/drizzle-orm/src/pg-core/query-builders/select.ts at mai...
TypeScript ORM that feels like writing SQL. Contribute to drizzle-team/drizzle-orm development by creating an account on GitHub.
@Andrew Sherman sorry for pinging, thought you could possibly give a quick clarification on the code here
@Dan Kochetov
yes, Drizzle internally prepares every query before execution
Ah, it seems that Neon uses pgBouncer in transaction mode, which does not support prepared statements (see: https://neon.tech/docs/connect/connection-pooling)
Is there a way to make drizzle work with Neon? I saw that there are a few neon drivers made by drizzle so it seems that drizzle does support neon.
people have been using Neon with Drizzle successfully, so there should be a way
I don't really know what do you need to change though