[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 that
Neon
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
kratious
kratious14mo ago
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
sakura
sakuraOP14mo ago
Not using this in our code, is it used in drizzle?
kratious
kratious14mo ago
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?
sakura
sakuraOP14mo ago
“s11383”, “s11367”, etc “s” followed by some numbers. We don’t explicitly use .prepare() for any of our queries
sakura
sakuraOP14mo ago
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.
sakura
sakuraOP14mo ago
@Andrew Sherman sorry for pinging, thought you could possibly give a quick clarification on the code here @Dan Kochetov
Dan
Dan14mo ago
yes, Drizzle internally prepares every query before execution
justjumper
justjumper14mo ago
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.
Dan
Dan14mo ago
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
Want results from more Discord servers?
Add your server