Prisma too many connection to my database
Hey everyone,
I use Prisma for ORM and Neon for my database
I noticed something, my connections aren't unique and after some time, i reach to the max to my database
But i throught i'd solved the problem by doing this :
I have this file and i only imported prisma from this file in my project
prisma.ts
Why do I have so many connections?
Thanks in advance for your help
9 Replies
How are you deploying your application?
Im using vercel for deploy my app !
Maybe because vercel it's serverless so there is a problem ?
But i have the same problem in local
yup yup, I assumed Next.js + Vercel.
If you are using serverless or edge functions on Vercel, then you will definitely run into issues. I'd recommend checking out the connection pooling docs from Neon. It's pretty straightforward.
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...
I think that when I put the api on Vercel, it creates server less functions.
But here, for example, just locally, so without vercel, I have a problem because I have too much connection
Where could this be coming from?
Not sure. How are you importing the Prisma Client in other parts of your application?
import { prisma } from "@/src/lib/prisma";
and i put prisma.ts just aboveRight. Just comparing that against our documentation.
I know that Next.js does some stuff to mimic Vercel's deployed environment, especially when it involves edge functions. It could be the same with serverless functions, which could cause a separate Prisma Client to be instantiated for each "instance" of that serverless function.
Using connection pooling would resolve your issue regardless of the location. We also have specific Neon documentation here
Neon | Prisma Documentation
Guide to Neon
Ok thanks, i'll take a look !