NestJS API Struggling to Connect to PostgreSQL
Every time I deploy my app, I repeatedly get an error that my Nest API can't connect to the Postgres database (I'm connecting them over the private network but have tried the public URL as well). Normally after 5-10 tries it's able to connect, but occasionally it times out and the deployment crashes. My service is also completely unavailable for the 2-3 minutes its trying to connect. I have a nearly identical setup on Heroku and it works fine so I don't think its anything with my Nest setup.
Project ID: 9e146e97-31c4-4151-baef-6ebb85aa849d
10 Replies
Project ID:
9e146e97-31c4-4151-baef-6ebb85aa849d
can you try to add a 3 second sleep to your start script?
No difference 🙁
show me how youe done that?
to eliminate variables, please do the sleep in your start script (in package.json)
sleep 3 && <your current start command>
Okay I figured it out. I was running
npx prisma migrate deploy
before the start command. What is the recommended way to check for new database migrations when deploying?in the start command
the sleep 3 should solve it
when I had
npx prisma migrate deploy && sleep 3 && yarn start
it was still happening
Should sleep come before the migrations?sleep should be at the start