Can't reach database server at `aws-0-us-east-1.pooler.supabase.com`:`5432`
Asked Answered
I

7

5

Happy Monday! I've recently run into a weird issue and can't seem to figure out what would be causing it.

I have a NextJS project using Prisma and Supabase. When I run the app on my Windows desktop or Vercel, it runs perfectly with no error. However, when I run it on my MacBook, it presents me with this error:

Error: 
Invalid `prisma.user.findUnique()` invocation:


Can't reach database server at `aws-0-us-east-1.pooler.supabase.com`:`5432`

Please make sure your database server is running at `aws-0-us-east-1.pooler.supabase.com`:`5432`.
Source
src/app/layout.tsx (37:17) @ async getData
  35 | noStore();
  36 | if (userId) {
> 37 |   const data = await prisma.user.findUnique({
     |               ^
  38 |     where: {
  39 |       id: userId,
  40 |     },

I've looked around for some answers but can't seem to find anyone with the same problem, any help would be appreciated!

Intercalary answered 13/2, 2024 at 18:4 Comment(3)
Please check the docs: supabase.com/partners/integrations/prismaMarnimarnia
Found any solution yet?Bathysphere
password can also create issue When your database password includes special characters like $ and &, it can cause issues with environment variables as these characters have special meanings in shell scripts , You can URL encode your password to ensure that special characters are properly interpretedFlann
C
7

Get Transaction and Session connection pooler string from your Superbase database setting page.

Transaction connection pooler string:

postgres://[db-user].[project-ref]:[db-password]@aws-0-[aws-region].pooler.supabase.com:6543/[db-name]?pgbouncer=true&connection_limit=1

Session connection pooler string:

postgres://[db-user].[project-ref]:[db-password]@aws-0-[aws-region].pooler.supabase.com:5432/[db-name]

Update .env file:

DATABASE_URL="" #The Transaction connection pooler string
DIRECT_URL=""  #The Session connection pooler string

schema.prisma file should look like:

datasource db {
 provider          = "postgresql"
 url               = env("DATABASE_URL")
 directUrl         = env("DIRECT_URL")
}

From Superbase document

Camilacamile answered 21/2, 2024 at 17:51 Comment(0)
G
1

when you are creating project in supabase select west not east, this will resolve your issue

Grandma answered 20/5, 2024 at 14:53 Comment(1)
Oh man, after trying many things, this solved my issue. I had to recreate a fresh Supabase project and select west. Thanks.Clavius
S
0

A solution that worked for me in the connection string for directUrl = env("DIRECT_DATABASE_URL").

-DIRECT_DATABASE_URL=postgres://postgres:[YOUR-PASSWORD]@db.[project-ref].supabase.co:5432/postgres
+DIRECT_DATABASE_URL=postgres://postgres.[project-ref]:[YOUR-PASSWORD]@aws-0-eu-central-1.pooler.supabase.com:5432/postgres
Subcritical answered 27/2, 2024 at 6:59 Comment(0)
T
0

Add the end of Database Url ?pgbouncer=true

Update the prisma to latest. My version [email protected]

Turnspit answered 2/5, 2024 at 17:39 Comment(0)
K
0

The supabase password might have a "$" in it and apparently, it needed to be encoded in the .env file.
So change the "$" to "%24" which is the encoded value for the symbol.
You can look up symbols that you need to change here [https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding]

Kistner answered 10/7, 2024 at 5:27 Comment(0)
C
0

I had the same issue, what worked for me was to go and change the password in Supabase, use just letters, no special character or numbers, then reset the project in Supabase and update the password on your ENV.

Charmeuse answered 13/7, 2024 at 13:13 Comment(0)
H
0

In my case, I just swapped the order of the password with the username; it might be that you swapped them in the .env file as well

Heteropterous answered 18/9, 2024 at 22:18 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.