P
Prisma•2mo ago
Sommer

P1001: Can't reach database server

Whenever I run this command: npx prisma migrate dev --name init, I end up getting this error:
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "db.nbcsqgnnbagzijwbrfsb.supabase.co:5432"

Error: P1001: Can't reach database server at `db.nbcsqgnnbagzijwbrfsb.supabase.co:5432`

Please make sure your database server is running at `db.nbcsqgnnbagzijwbrfsb.supabase.co:5432`.
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "db.nbcsqgnnbagzijwbrfsb.supabase.co:5432"

Error: P1001: Can't reach database server at `db.nbcsqgnnbagzijwbrfsb.supabase.co:5432`

Please make sure your database server is running at `db.nbcsqgnnbagzijwbrfsb.supabase.co:5432`.
I'm pretty sure that i've tried everything. I have tried to ping it with my command prompt, using DataGrip, and asked ChatGPT, yet I just can't get it to work.
3 Replies
Prisma AI Help
Prisma AI Help•2mo ago
You opted for speed from this bot. Let's conjure up an answer right now! Based on the information provided in the knowledge sources, it appears that you're experiencing a common issue when trying to connect Prisma to a Supabase database. Here are a few potential solutions and things to check: 1. Connection string: Make sure your DATABASE_URL in the .env file is correctly formatted. For Supabase, it should look like this:
DATABASE_URL="postgresql://postgres:[password]@db.nbcsqgnnbagzijwbrfsb.supabase.co:5432/postgres"
DATABASE_URL="postgresql://postgres:[password]@db.nbcsqgnnbagzijwbrfsb.supabase.co:5432/postgres"
2. Direct URL: Supabase recommends using both a DATABASE_URL and a DIRECT_URL in your .env file. Add a DIRECT_URL like this:
DIRECT_URL="postgresql://postgres:[password]@db.nbcsqgnnbagzijwbrfsb.supabase.co:5432/postgres"
DIRECT_URL="postgresql://postgres:[password]@db.nbcsqgnnbagzijwbrfsb.supabase.co:5432/postgres"
Then update your schema.prisma file to include the directUrl:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
3. Port: Some users have reported success by changing the port from 5432 to 6543 in the DATABASE_URL. Try this if the above doesn't work. 4. PgBouncer: If you're using PgBouncer with Supabase, add ?pgbouncer=true to your connection string:
DATABASE_URL="postgresql://postgres:[password]@db.nbcsqgnnbagzijwbrfsb.supabase.co:6543/postgres?pgbouncer=true"
DATABASE_URL="postgresql://postgres:[password]@db.nbcsqgnnbagzijwbrfsb.supabase.co:6543/postgres?pgbouncer=true"
5. IP Whitelist: Make sure your IP address is whitelisted in your Supabase project settings. 6. Check Supabase status: Ensure that your Supabase project is active and the database is running. If none of these solutions work, you may want to try connecting to the database using psql command-line tool to verify if it's a Prisma-specific issue or a general connection problem. For more detailed information and troubleshooting steps, you can refer to these GitHub issues: - Unable to reach database server at aws-0-us-east-1.pooler.supabase.com:5432 using Prisma migrate dev - Can't reach database server at postgres:5432 If you're still u nable to connect after trying these solutions, you may need to open a new issue on the Prisma GitHub repository with more details about your specific setup. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Sommer
SommerOP•2mo ago
I've also tried using different ports.
Nurul
Nurul•2mo ago
This is likely because your network doesn't support IPv6. Can you try changing your network? The other option would be to use the pooled connection string from Supabase

Did you find this page helpful?