Ok, so i got in to this problem running query in my app based on:
- Remix app framework
- Postgres as a db
- Prisma as ORM
I have simple loader function, which basically loads post types from my db.
So, after i hit browser reload button for a couple of times i get this error
Error querying the database: db error: FATAL: sorry, too many clients already
The only one way is get rid of error is restart the app.
CodePudding user response:
The solution is quite simple, we should init our prisma client before the render starts.
To do this, follow the remix guideline.
This way it will reuse object after server update.
Second thing you need to do is to increase your connection limit, by passing number to connect url in this way:
postgresql://postgres:@localhost:5432/db?connection_limit=13
The number is:
(Quantity of cores on your computer * 2) 1
To get more info about optimizing prisma connection pull, follow.
CodePudding user response:
In development Remix purges the require cache before each request. This is to support LiveReload
You need to store the Prisma client on the global object to survive the purge.
You’ll see an example of this on the Jokes tutorial.
https://github.com/remix-run/examples/blob/main/jokes/app/utils/db.server.ts