Hi, my app doesn't work properly. Can someone expl...
# orm-help
m
Hi, my app doesn't work properly. Can someone explain how it should be configurated the connection_pool and limit for prisma client?
I have tried to modify both parameters to postgresql://user@pass@xxxxxxxx:5432/database?schema=database_*&connection_limit=40&pool_timeout=20*_
And before that, it was throwing an error timeout. And now it's throwing another error..
Error in connector: Error querying the database: db error: FATAL: remaining connection slots are reserved for non-replication superuser connections
How I should configure the prisma client to work properly? Because in the other hand, there is the database configuration..
a
I think this depends on how you architect your app. In mine, I share the client. So I have a client.ts file:
Copy code
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export default prisma;
And then in my various files I import that client:
Copy code
import prisma from "./prisma/client";
And then within my app I’m able to use it e.g.
Copy code
const ratedOpportunities = await prisma.opportunity.findMany({...
m
Hi @Adrian Duyzer! Many thanks for your opinion. But are you connecting or disconnecting before-after each query? Or you are using lazy connection (without invoke these methods)?
If I understand your code well, you share an unique prisma client instance on whole app, minimizing the database connection impact.
a
Hey, sorry, I just saw this. Are you still having issues? To answer your question, yes, I share a client instance in the whole app. I’m not doing any connecting/disconnecting before or after queries. Incidentally this approach is from the Prisma docs.