2 months ago
In some cases, modifying an environment variable and redeploying the service results in a failed connection attempt to the managed PostgreSQL database. The issue is only resolved after several redeployments.
Pinned Solution
2 months ago
Changing the DB URL from the hardcodedjdbc:postgresql://postgres.railway.internal:5432/railway
to the environment variable-basedjdbc:postgresql://${{Postgres.PGHOST}}:${{Postgres.PGPORT}}/${{Postgres.PGDATABASE}}
seems to have fixed the connection issue.
I'm not sure why this should make a difference, but the deployment worked now about five times in a row. Previously, every deployment—or at least every other one—was failing.
10 Replies
2 months ago
I ran into the same issue recently. Not sure if it actually fixed it, but try ensuring that you're connecting using IPv6, that seemed to fix it for me. I got two deploys out. Previously I was getting connection errors. This is using Elixir Ecto but potentially could be the same underlying issue for you as well?
2 months ago
Hey there! We've found the following might help you get unblocked faster:
🧵 Cross-service variable references (${{ServiceName.VARIABLE}}) don't resolve in PR environments
🧵 Sometimes internal services (postgres) aren't discoverable in PR environments
🧵 Railway: Internal PostgreSQL Networking Breaks After Every Deploy
If you find the answer from one of these, please let us know by solving the thread!
2 months ago
the db is not managed, when it doesn't connect, do you see any error? Are you using the internal or external url?
2 months ago
what framework/language are you using?
2 months ago
if you're using spring boot + hikari connection pool this is a timing race condition when your backend starts before postgres is ready. add these two lines to your application.properties:
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.initialization-fail-timeout=-1the -1 tells hikari to keep retrying indefinitely during startup instead of failing immediately. this fixed the exact same issue (50% deployment failures) for another user , they went from every 2nd deployment failing to zero failures. also make sure you're using the internal railway connection string with railway.internal not the public proxy url.
if not spring boot tell me which framework/language are you using?
domehane
if you're using spring boot + hikari connection pool this is a timing race condition when your backend starts before postgres is ready. add these two lines to your application.properties:spring.datasource.hikari.connection-timeout=30000 spring.datasource.hikari.initialization-fail-timeout=-1the -1 tells hikari to keep retrying indefinitely during startup instead of failing immediately. this fixed the exact same issue (50% deployment failures) for another user , they went from every 2nd deployment failing to zero failures. also make sure you're using the internal railway connection string with railway.internal not the public proxy url.if not spring boot tell me which framework/language are you using?
2 months ago
I’m using Spring Boot. However, the configuration you mentioned doesn’t resolve the issue, since these settings are already configured on my side.
domehane
what framework/language are you using?
2 months ago
Spring Boot 4.0.1 + Java 25
fra
the db is not managed, when it doesn't connect, do you see any error? Are you using the internal or external url?
2 months ago
There are no errors in the PostgreSQL logs. The database is up, running, and ready to accept connections.
bbhoss
I ran into the same issue recently. Not sure if it actually fixed it, but try ensuring that you're connecting using IPv6, that seemed to fix it for me. I got two deploys out. Previously I was getting connection errors. This is using Elixir Ecto but potentially could be the same underlying issue for you as well?
2 months ago
This is more a workaround for an infrastructure/networking quirk. I’d rather see the Railway team resolve the underlying network and DNS problems.
2 months ago
Changing the DB URL from the hardcodedjdbc:postgresql://postgres.railway.internal:5432/railway
to the environment variable-basedjdbc:postgresql://${{Postgres.PGHOST}}:${{Postgres.PGPORT}}/${{Postgres.PGDATABASE}}
seems to have fixed the connection issue.
I'm not sure why this should make a difference, but the deployment worked now about five times in a row. Previously, every deployment—or at least every other one—was failing.
Status changed to Solved brody • 2 months ago
