prisma: Cannot connect to Supabase database

Bug description

I cannot connect to my Supabase database with the URI. However on the other hand I can connect without prisma directly with psql.

This is the command with which I connected to my database:

psql -h db.nauqxqbyeqpccehwqegs.supabase.co -p 5432 -d postgres -U postgres

And this is my URI:

DATABASE_URL="postgresql://postgres:[mypasswordhere]@db.nauqxqbyeqpccehwqegs.supabase.co:5432/postgres"

How to reproduce

Step to reproduce:

I have tried it a lot, and Every time regardless of changing my db password or restarting server. And when I ran npx prisma db pull. Nothing changes.

This is the error:

Prisma schema loaded from prisma/schema.prisma
Environment variables loaded from .env
Datasource "db": PostgreSQL database "postgres", schema "public" at "db.nauqxqbyeqpccehwqegs.supabase.co:5432"

✖ Introspecting based on datasource defined in prisma/schema.prisma

Error: P1001

Can't reach database server at `db.nauqxqbyeqpccehwqegs.supabase.co`:`5432`

Please make sure your database server is running at `db.nauqxqbyeqpccehwqegs.supabase.co`:`5432`.

Expected behavior

No response

Prisma information

My Prisma Schema

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

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

Environment & setup

  • OS: MX LINUX 21
  • Database: Postgresql
  • Node.js version: v16.13.2

Prisma Version

npx prisma -v
Environment variables loaded from .env
prisma                  : 3.14.0
@prisma/client          : 3.14.0
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : introspection-core 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash    : 2b0c12756921c891fec4f68d9444e18c7d5d4a6a
Studio                  : 0.460.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (4 by maintainers)

Most upvoted comments

superbase already addressed this issue

step -1 add to .env file

# Connect to Supabase via connection pooling with Supavisor.
DATABASE_URL="postgresql://postgres.dnnhtbehpfyusttyytfw:[YOUR-PASSWORD]@aws-0-ap-south-1.pooler.supabase.com:6543/postgres?pgbouncer=true"

# Direct connection to the database. Used for migrations.
DIRECT_URL="postgresql://postgres.dnnhtbehpfyusttyytfw:[YOUR-PASSWORD]@aws-0-ap-south-1.pooler.supabase.com:5432/postgres"
        

step-2 add to schema.prisma

generator client {
  provider = "prisma-client-js"
}

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

?connect_timeout=300

Add connection timeout at the end of your database url…

I discovered that the problem is that I have an empty database there.

So when I created a table there on Supabase, I was able to to get it connected to with Prisma. However, whenever I first wrote some schema declarations I Prisma and then I ran ,npx prisma db pull I also got the sma e error. So I think the point is that always I first should update bring updates in Supabase and after that I should just pull those updates with Prisma.

I believe that it’s something that is related to Supabase maybe.

If your password contains special characters like @, $, or others, make sure to URL encode them. For example, replace @ with %40 to avoid connection issues.

@ - %40 : - %3A / - %2F ? - %3F = - %3D & - %26

Even with ?connect_timeout=300 at the end i get the same error! Wired thing is when i run prisma db push it successfully creates the tabels. When i run npm run dev i get this error message