a year ago
I don't know how to connect database url to my project
ⓘ Deployment information is only viewable by project members and Railway employees.
5 Replies
a year ago
Hello,
You would want to be using a reference variable -
https://docs.railway.com/guides/variables#referencing-another-services-variable
6 months ago
Hi I have problem with postgres data base. Mu postgres data is not connecting. I haven't internet problem. But I don't know why it is not connecting
brody
Hello,You would want to be using a reference variable -https://docs.railway.com/guides/variables#referencing-another-services-variable
6 months ago
Hi
6 months ago
your database has two variables, that you can use to connect it to services inside railway and outside of it.
If you used default postgress db, then it'll be something like this:${{Postgres.DATABASE_URL}}
- add this in your service who needs db inside railway, it'll be connected.${{Postgres.DATABASE_PUBLIC_URL}}
- if you want a url that you can connect to from outside of railway, then use this.
- remember, this will add egress cost to your final bill, as this traffic will be going outside of railway which will incur the cost as egress.
6 months ago
Use a Reference Variable to wire your DB to the app
Brody’s right: don’t paste credentials - reference your DB service’s DATABASE_URL.
Steps
1. Put your app and database in the same Railway project.
2. In your app → Variables, add:
DATABASE_URL = ${{<DB_SERVICE_NAME>.DATABASE_URL}}
(e.g., postgres, db, postgresql). This uses Railway’s template syntax for Reference Variables.
3. Deploy the staged change so the new env var is applied to the running service.
Notes
Railway’s Postgres exposes
PGHOST/PGPORT/PGUSER/PGPASSWORD/PGDATABASEand a ready-to-useDATABASE_URL; most ORMs readDATABASE_URLautomatically.Need to connect from outside Railway (local laptop, BI tool)? Enable a TCP Proxy on the DB service and use the generated
domain:port. (Prefer internal networking between Railway services when possible.)
To test locally with the same env vars:
railway run <your start command>
(injects your project’s variables into the local process).