Trouble establishing connection to db


I went through the docs and I increased the timeout connection to 20 seconds but I am still running into the same issue, I am trying to setup the following repository GitHub - Nutlope/roomGPT: Upload a photo of your room to generate your dream room with AI.. I have also turned pooler on and turned pgbouncer=true, still am unable to establish a connection to the db. Any help will be much appreciated thank you.

(as a user )
Unfortunately, debugging is not easy.

  • Q1: the “Connect with psql” is working?
    • sometimes firewalls blocking the outgoing connections; so check the firewalls …
  • Q2: the console.neon.tech + “SQL editor” is working?
  • Q3: verify the compute endpoint in the console / Dashboard / Connection Details ;
    • any typo? changes?
2 Likes

Hey @goyalpramod!

So I just cloned the project and added the following credentials to the .env (there wasn’t a DIRECT_DATABASE_URL in the .env.example file.

I then created a shadow database and added the connection string.

Note that the DATABASE_URL uses pooling (so there’s ?pgbouncer=true added as a query parameter and the endpoint ID has a -pooler suffix)

DATABASE_URL=postgres://mahmoud:<password>@ep-withered-mouse-378677-pooler.eu-central-1.aws.neon.tech/neondb?pgbouncer=true&connect_timeout=0
DIRECT_DATABASE_URL = postgres://mahmoud:<password>@ep-withered-mouse-378677.eu-central-1.aws.neon.tech/neondb?connect_timeout=0
SHADOW_DATABASE_URL= postgres://mahmoud:<password>@ep-withered-mouse-378677.eu-central-1.aws.neon.tech/shadowdb?connect_timeout=0

This was the output of running prisma migrate dev

Applying migration `20230310013453_initial`
Applying migration `20230317200723_payments`
Applying migration `20230320191014_purchase_table`
Applying migration `20230324045246_decrease_credits`
Applying migration `20230325035657_location`

The following migration(s) have been applied:

migrations/
  └─ 20230310013453_initial/
    └─ migration.sql
  └─ 20230317200723_payments/
    └─ migration.sql
  └─ 20230320191014_purchase_table/
    └─ migration.sql
  └─ 20230324045246_decrease_credits/
    └─ migration.sql
  └─ 20230325035657_location/
    └─ migration.sql

Your database is now in sync with your schema.

✔ Generated Prisma Client (4.11.0 | library) to ./node_modules/@prisma/client in 373ms

So everything seems to work normally. Can you double-check that you’re using the correct connection string?

You can find it in the connection details wiget

btw you don’t need to run prisma db push

2 Likes

I was using VS code and was running into p1001 error again and again, I did everything you mentioned. I switched to Visual Studio and everything ran smoothly. I do not know how to explain how it worked just cause I switched to an IDE. Thanks a lot for the response tho. It clarified a lot of things. I am really grateful.

I checked from the sql editor as you mentioned, and it was working. I was using visual studio code and running into the error but the I switched to Visual Studio and it all worked. I really don’t know what the exact problem was, but it wasn’t running on vs code but running on visual studio. Thanks a lot for the response.

1 Like

Glad that things work now! Feel free to create a new post if you run into any other issues.

@ImreSamu I appreciate your help. Thank you for taking the time to share ways to debug this issue :smile:

2 Likes

So I was going through the steps and found out my exact problem. I am a college student and our Insti has put up a firewall to block a few sites, that was interfering with the connection. I was able to establish a connection yesterday. Because I connected to my cell’s hotspot instead of the institute network.

1 Like