Too many database connections: FATAL

Hi, I am relatively new to using Aiven and PostGreSQL as well. I created a Next JS web app for my university which uses Prisma to connect to Aiven. However, when the other students used it, I got this error in my Vercel log: “Too many database connections opened: FATAL: remaining connection slots are reserved for non-replication superuser connections”

I think it might be related to the 20 connection limit at Aiven free plan but I still want to be sure before I make any purchases. When this error happens I need to redeploy my app otherwise it does not get fixed.

Here is my database connection string parameters: defaultdb?sslmode=require&max-connections=15

And here is my prisma.tsx. I am only instantiating Prisma once in my app.

import { PrismaClient } from ‘@prisma/client’;

let prisma: PrismaClient;

if (process.env.NODE_ENV === “production”) {
prisma = new PrismaClient();
} else {
if (!global.prisma) {
global.prisma = new PrismaClient();
}
prisma = global.prisma;
}

export default prisma;

Thank you for the help. And sorry if this question might appear silly.

Hi,
Indeed the FREE service has 20 max_connection limits without the ability to perform connection pooling
You might want to move to a paid plan with higher limits or one which has connection pooling enabled