flask app not able to connect to postgres
pangshengwei
HOBBYOP

10 months ago

help somehow im not able to connect my flask app to postgres despite adding the DATABASE_URL variable

https://railway.com/project/c10afa2a-f8ea-4901-97cb-31c43cbc4df9/service/b08f7f7c-d46f-46f8-a9a7-8ddddf9bd403/variables?environmentId=a6c900fc-7c3a-4110-8306-7e20223f9b12

looking at the logs, it shows postgres:5432 - no response

strangely it was working fine past few days, but after i enabled serverless mode the issue happened. and it persists even though i have deleted and created new app and db services

Solved$10 Bounty

Pinned Solution

9 months ago

Did you try disabling serverless after it broke? Serverless doesn't really work with services that rely on databases or are themselves databases since the database connection will stop the app from sleeping.

2 Replies

10 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open brody 10 months ago


9 months ago

Did you try disabling serverless after it broke? Serverless doesn't really work with services that rely on databases or are themselves databases since the database connection will stop the app from sleeping.


smolpaw
HOBBY

9 months ago

the issue is likely due to DNS resolution and the way containerization works.

I am guessing when postgres goes to sleep and you try to access it from your flask app it doesn't even turn on automatically right like you expected it to right ?

Like erisa said, db's don't do well with serverless and i would also strongly advise against it. The serverless mode is handled purely by monitoring network packets so your db could be interacting with disk and railway might shut it off leading to data corruption and loss.
https://docs.railway.com/reference/app-sleeping

Turn off serverless mode for postgres.


Status changed to Solved chandrika 9 months ago


Loading...