Drizzle-ORM+PSQL: sorry, too many clients already
X tRPC failed on school.getAll: sorry, too many clients already
I guess this is because the connections stay open? or because it opens a connection per request for some reason?
This is my TRPC inner context:
(Default one provided by T3-Drizzle stack)
Why is that happening?7 Replies
Dealing with exactly the same issue right now, did some research and it looks like it has to do with the hot module reload (HMR) that you get in dev environment with Next.js.
I believe you need to create a singleton to avoid opening a new db connection everytime an HMR refresh happens, but I'm not sure as to the best way to do this, or if there's an accepted best practice.
Maybe someone can confirm/correct me here and provide an example solution?
That's what I thought of, should be implemented by T3 by default
Agreed, let me know if you figure out a solution
Have you came up with something?
I face the same issue (t3-drizzle)
Really driving me crazy
you can checkout this link for a potential fix: https://www.answeroverflow.com/m/1146224610002600067
Too many clients already (!?) - Drizzle Team
Hey guys, been using Drizzle for a few weeks now and I think since last week this issue has started (look at screenshot).
I'm using the
postgres
paackge to connect Drizzle to my PostgreSQL database that's deployed to Railway.
Drizzle connection code 👇 :
```typescript
import { env } from "@/env.mjs";
import { drizzle } from "drizzle-orm/postgre...I used it to fix the same issue with some small modifications:
The solution George sent above looks good, you basically just create a singleton to use for dev instances and leave it as is for production instances