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.

Can't reach database server when doing a large findMany query

See original GitHub issue

Bug description

When I try the following query, I get the following error:

const users = await p.user.findMany({
  include: { quiz: true },
})
(node:7642) UnhandledPromiseRejectionWarning: Error:
Invalid `prisma.user.findMany()` invocation:

 Can't reach database server at `localhost`:`5432`

Please make sure your database server is running at `localhost`:`5432`.

With some initial testing, I noticed removing the include argument allows the query to run just fine.

// works
const users = await p.user.findMany({}) 

Also, I could leave the include in if I limited the number of rows with take. Roughly 32,000 seemed to be the limit.

// works
const users = await p.user.findMany({
  include: { quiz: true },
  take: 32000,
})

// error
const users = await p.user.findMany({
  include: { quiz: true },
  take: 40000,
})

I think this is a bug. But if it’s a known limitation, it would be good if there was a better error message. I initially spent a long time troubleshooting my connection to postgres.

EDIT: I just tested this with the app running on heroku with a heroku managed database. I get the exact same error, so it’s not an issue with my local db.

How to reproduce

Run:

p.user.findMany({
  include: { quiz: true },
})

Both user and quiz have about 100k rows.

Prisma information

model User {
  id       String    @default(uuid())
  email    String    @id @unique
  customer Boolean   @default(false)
  name     String?
  acDate   DateTime?
  quiz     Quiz?
}

model Quiz {
  id         String    @id @default(uuid())
  firstName  String?
  skill      String
  playstyle  String
  discipline String
  age        String
  gender     String
  racketNum  Int?
  date       DateTime?
  user       User      @relation(fields: [userEmail], references: [email], onDelete: Cascade)
  userEmail  String
}

Environment & setup

  • OS: Windows 10 running WSL2 Ubunutu 20.04
  • Database: A local postgres instance
  • Node.js version: v14.5.0

Prisma Version

prisma                  : 3.0.2
@prisma/client          : 3.0.2
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : introspection-core 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash    : 2452cc6313d52b8b9a96999ac0e974d0aedf88db
Studio                  : 0.423.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nwidynskicommented, Sep 17, 2021

This is directly related to #8878

0reactions
jkomynocommented, Sep 28, 2022

We have closed the original issue in prisma@4.4.0, please see this comment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma fails on Postgres query with findMany - Stack Overflow
prisma.user.findMany( Can't reach database server at `xyz`:`25060` Please make sure your database server is running at `xyz`:`25060 ...
Read more >
please make sure your database server is running at ...
I am using Nest js + Prisma + Postgres in the Backend of my website. ... Can't reach database server at `database`:`5432` running...
Read more >
Aggregation, grouping, and summarizing (Concepts) - Prisma
Prisma Client allows you to aggregate on the number fields (such as Int and Float ) of a model. The following query returns...
Read more >
Connecting the Server and Database with Prisma Client
The first thing you need to do is import your generated Prisma Client ... up the GraphQL server so that you can access...
Read more >
Introduction to Prisma with Docker - Section.io
When someone writes a query requesting the data, the server reads it, ... You can also migrate databases using Prisma without having to ......
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