Postgresql "Operation timed out"
I get this message on the backend logs very frequently while developing locally. But sometimes it works. What is the reason?
30 Replies
Project ID:
18b66c44-d5b0-474f-bfea-26659858c9ff
18b66c44-d5b0-474f-bfea-26659858c9ff
when developing locally are you starting your app with either
railway run
or railway shell
?I'm using the usual command for FastAPI
uvicorn app:app --reload
yes but are you using it with either of those two commands i mentioned?
no
how would you get access to your database variables then?
I use the PostgreSQL address directly I guess?
SQLALCHEMY_DATABASE_URL = "postgresql://postgres:[email protected]:7865/railway"
you never wanna hardcode credentials
hmm
where is the best practice for this?
show me a screenshot of your service variables so i can advice further
I saw this now on one of your pages:
DATABASE_URL=${{Postgres.DATABASE_URL}}
where should I write this?^
service variables, not your code
do you mean this page?
the service variables
I don't understand?
yes!
okay now do what that info banner wants you to
https://docs.railway.app/develop/variables#reference-variables
OK I added DATABASE_URL
then show me another screenshot once you have a
DATABASE_URL
reference variableperfect
now instead of using a hardcoded string, use
os.getenv("DATABASE_URL")
in place of the hardcoded string
and do you have the railway cli installed?OK I did it
and run
railway run uvicorn blabla
it worked but will it solve my connection timeout problem?in a perfect world, yes
🙂
OK I'll be asking here again if I get the problem again
so you have ran that command and your code has connected to the database?
yes
okay great, that should be all thats needed
now if your code has any other hard coded secrets or credentials add them to the railway service variables, then access them the same way you access the
DATABASE_URL
variableI don't think there is any other. Thank you I'll do that this way from now on.
awsome, happy to help, come back if you have any other problems!