question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma client can't reach database server from time to time

See original GitHub issue

Bug description

Hi,

We are running a very classic NodeJS Express API connected to a PostgreSQL database via the Prisma client, and from time to time we have requests failing with the error P1001 :

Can't reach database server at ...
Please make sure your database server is running at ...

And everything is ok in the previous or following requests few milliseconds apart:

Capture d’écran 2022-03-13 à 16 46 24

I checked on the infrastructure side, and the database seems reachable from the server with no issues of connection pool, overload, high CPU, high memory or whatever else.

Is there something I can check or try to solve that ?

How to reproduce

I didn’t find any way to reproduce it constantly but it seems to happen a little bit more during low traffic periods like night. And it seems that sending queries every 20 seconds reduce a lot the issue. So it’s maybe linked to idle timeout or something similar.

Expected behavior

No more requests failing with this error of course 😅 ! I don’t expect a fix or whatever, but more at advices or things I can take a look to to move forward in solving this problem.

Prisma information

It happens with different queries, we even have very basic health checks failing from time to time due to this error:

export default async function () {
  await client.$queryRaw`SELECT 0`;
}

Environment & setup

  • OS: Ubuntu
  • Database: PostgreSQL
  • Node.js version: 16.13.0

Prisma Version

3.10.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:23 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
Dammmiencommented, Jun 2, 2022

Hi @pantharshit00 ,

Yes I noticed there was several fixes / improvements of the connection in the last Prisma client versions, many thanks 🙏🏻 !

We also did some changes on our side:

  • opened support ticket to our hosting provider
  • add a health check to the connection between our API and the databases
  • upgraded to the latest versions of the Prisma client

Consequently the errors rate drops from 10 per days to 10 during the last month.

So it’s better 👍🏻 even if I can’t say it’s clearly linked to the Prisma client upgrade.

1reaction
suraj5969commented, Nov 3, 2022

I am also facing the same issue, prisma sometime connects to postgres DB correctly and someimes not. I tested it on 2 providers( render, heroku) but I am still getting this problem. It normally occurs while calling findMany function.

the error thrown is: Can’t reach database server at … Please make sure your database server is running at …

Prisma version: 4.5.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

prisma Error: p1001: Can't reach database server at `db ...
I had a similar issue with a Sveltekit application using Prisma and PlanetScale (MySQL) and Docker on Windows (WSL).
Read more >
Troubleshooting database outages and connection issues
Learn about the possible reasons your database might be down or not connected and what you can do to fix it.
Read more >
please make sure your database server is running at ...
prisma :client:fetcher Error: Can't reach database server at `localhost`:`5432` ... I initially spent a long time troubleshooting my connection to postgres.
Read more >
Can't reach database server in FRA - Build debugging - Fly.io
handleRequestError (/myapp/node_modules/@prisma/client/runtime/index.js:49670:13) 2022-07-21T09:07:01Z app[4bebc390] fra [info] at ...
Read more >
Connecting the Server and Database with Prisma Client
The first thing you need to do is import your generated Prisma Client library and wire up the GraphQL server so that you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found