So I'm trying to run a Nest.js app that has connection to Neon DB (postgre cloud database) using Prisma ORM in Docker container.
Already set .env variable correctly for the database connection
DIRECT_URL="postgres://user:[email protected]/neondb?pgbouncer=true&connect_timeout=500&pool_timeout=500"
As seen above, I also set connect_timeout
and pool_timeout
for the connection.
However when it comes to doing database operation such as find
, update
, delete
, etc, it mostly gives this error: Can't reach database server at `ep-plain-credit-656514.ap-southeast-1.aws.neon.tech`:5432
.
I said "mostly" because if I spam the request to the database, after a few errors finally database connection established and after that the app can request with others operation smoothly.
I feel like this is related to the database active compute time. When the database's compute_time is on IDLE
state, client/Nest.js need to wait for some seconds to establish connection to it. That's why here actually connect_timeout
and pool_timeout
should have been solve the issue, but in my case I don't know why those timeouts just don't work. Precisely it doesn't work if I run the app in Docker container. While in the local run, timeouts worked just fine.
Is there any setup or things that I missed in order to connect to cloud database in Docker container?
Thanks a lot.
Changing the docker Node image version that I use for the project solved this database timeout problem. At first I use this version node:18.17.0-alpine
. After changing to node:18
, the connection finally established.
I still wonder the reason why this could work. And Idk how Node image version can affect this database connection stuffs.