Error P1001 while migrating with Prisma

I get the following error message after running "npx prisma migrate dev*

Error: P1001 Can't reach database server at "ep-black-silence...": "5432"

I copied the links as given in Neon like here:


I copied the links in my file .env

DATABASE_URL=postgres://mrexito.rg:XXX@ep-lively-breeze-417358.eu-central-1.aws.neon.tech/MainDB

SHADOW_DATABASE_URL=postgres://mrexito.rg:XXX@ep-black-silence-594226.eu-central-1.aws.neon.tech/ShadowDB

In Prisma scheme I have:

  provider          = "postgresql"
  url               = env("DATABASE_URL")
  shadowDatabaseUrl = env("SHADOW_DATABASE_URL")

I did log in with Google in Neon.
What should I do?
Thank you for any help

Hey! @patite

The error you got most likely means that the Prisma query engine timed out before the Neon compute was activated. You can adjust your Neon connection string by adding a connect_timeout parameter that defines the maximum number of seconds to wait for a new connection to be opened. The default value is 5 seconds. A higher setting should provide the time required to avoid connection timeout issues. For example:

DATABASE_URL=postgres://daniel:<password>@ep-mute-rain-952417.us-east-2.aws.neon.tech/neondb?connect_timeout=10`

You should add this parameter to both your DATABASE_URL and SHADOW_DATABASE_URL

1 Like

I’ve added the timeout parameter

DATABASE_URL=postgres://mrexito.rg:XXX@ep-lively-breeze-417358.eu-central-1.aws.neon.tech/MainDB?connect_timeout=10

SHADOW_DATABASE_URL=postgres://mrexito.rg:XXX@ep-black-silence-594226.eu-central-1.aws.neon.tech/ShadowDB?connect_timeout=10

I get the following error:
image
Thank you

When you go to the “Databases” page from the sidebar, do you have a database called ShadowDB? Perhaps you either don’t have one or it has a different name

I have it:

I just noticed that your DATABASE_URL and SHADOW_DATABASE_URL don’t match when it comes to the endpoint ID.

It should be

DATABASE_URL=postgres://mrexito.rg:XXX@ep-lively-breeze-417358.eu-central-1.aws.neon.tech/MainDB?connect_timeout=10

SHADOW_DATABASE_URL=postgres://mrexito.rg:XXX@ep-lively-breeze-417358.eu-central-1.aws.neon.tech/ShadowDB?connect_timeout=10

Each branch has its own compute endpoint and databases. If you create a branch and then create a database for the new branch, the parent branch won’t have that database

Thank you.
For the shadow_database should I create a branch in the main_database?
What I did is to create two databases. I guess this is wrong.
Even with the same IDs I get the following error:
image

What I did is to create two databases. I guess this is wrong.

This is the recommended approach.

The error you’re getting is odd. Could you try resetting the password for your user?

Hi Mahmoud - I am in a similar boat but have a beginner question. How do I create a Shadow DB in the first place?

Hey @Uzair_Minhas! this workaround is not needed anymore :slight_smile:

We now support managing roles and databases via SQL, so Prisma Migrate automatically creates and deletes the shadow database when developing locally.

If you run prisma migrate dev everything should work normally. Let me know if you run into any issues.

1 Like

Hi @Mahmoud - I am getting the following error

Error: db error: ERROR: database “prisma_migrate_shadow_db_8aa4eddb-6161-481b-ac7a-20cc3e1dd4d2” is being accessed by other users
DETAIL: There are 2 other sessions using the database.
0: schema_core::state::DevDiagnostic
at schema-engine/core/src/state.rs:266

@Uzair_Minhas Do this error occur every time you run prisma migrate dev?

Hi @Mahmoud - Yes, I even commented out/removed the reference to the shadowURL in schema.prisma

Hi @Mahmoud - I think I fixed it!

1 Like

@Mahmoud - My env variable for directURL was not specified, as I had been referencing an OS schema.prisma file. I see directURL was in my new prisma file on my dashboard.

Interesting. glad to see that the issue is fixed!

Hi @Mahmoud - Unrelated question. But I am following a tutorial from @nutlope where he implemented next-auth: Add auth with next-auth and Neon by Nutlope · Pull Request #27 · Nutlope/roomGPT · GitHub

However, in my app, I use the Edge runtime. Apparently next-auth doesn’t work with Edge functions. Are you aware of this?

Does Neon/Primsa work with the latest experimental version of NextAuth/Auth.js?

Currently, you can’t connect from edge environments to Neon while using Prisma. If you want to keep using Prisma you can either switch to a regular lambda function or set up the Prisma Data Proxy https://cloud.prisma.io/