How to connect postgresql privately in railway
yoshimendokusee
FREEOP

4 months ago

how to connect the database privately to avoid fees

Solved

17 Replies

4 months ago

You can use the private network to connect to databases, the DATABASE_URL contains the private url. Unfortunately if you need to connect to your database from outside of your Railway environment then there isn't a way to avoid those fees


yoshimendokusee
FREEOP

4 months ago

what do you mean by the second sentence? sorry, can you give a scenario


4 months ago

Let's say you have a project:

  • ServiceA

  • PostgreSQL

ServiceA stores things in PostgreSQL, you can connect to PostgreSQL from ServiceA via the private url (DATABASE_URL) in order to avoid any egress fees. If you need to connect to PostgreSQL from outside of that project - say you're trying to connect to the database from your PC at home, then you can't use the private network because it only works within your Railway environment. So if you're trying to connect to your database from home then there isn't a way to avoid the fees

The reason I mentioned the part is because I wans't sure in what context you were connecting to postgresql, and so I wanted to cover more ground by giving both scenarios: connecting to the database from a service in the same project and connecting to the database from anything outside of that project. It's possible to avoid fees in the former but not in the latter


yoshimendokusee
FREEOP

4 months ago

what if im trying to connect my ServiceA to my pgadmin4 from my laptop


yoshimendokusee
FREEOP

4 months ago

can i use the private?


4 months ago

any information that leaves your Railway project will result in egress fees, so if you connect anything between Railway to anything outside of Railway and information flows between those 2 points then you'll gain egress fees

You can connect between the two privately though through a tailscail subnet router (guide here: ) but that doesn't prevent egress fees it just improves security


yoshimendokusee
FREEOP

4 months ago

thank you so much!


4 months ago

no problem 🙂


yoshimendokusee
FREEOP

4 months ago

btw, do i need to use the public for this scenario?


4 months ago

yea, the private network only works within Railway services because of Railway's internal DNS, so any network outside of Railway wouldn't be able to understand railway private urls and would fail


yoshimendokusee
FREEOP

4 months ago

thank you so much, but i think using the public proxy is kinda risky. so i might use this process


4 months ago

that's fair, and yea if security is huge concern then the tailscale subnet router is a good additional layer of protection


yoshimendokusee
FREEOP

4 months ago

hi sorry for many question, the postgres database is not needed anymore right? also, can i change the "railway" database name to "educaid" will it still function properly

1435190590764486700


4 months ago

hi sorry for many question, the postgres database is not needed anymore right
I don't know, that depends on you, if you don't need it anymore then I suppose it's not needed

can i change the "railway" database name to "educaid" will it still function properly
I believe so yea, just make sure you update the service variables too so that the Railway UI still works for your database


yoshimendokusee
FREEOP

4 months ago

i just need to change this?

1435195060999291000


4 months ago

i thiink so


4 months ago

!s


Status changed to Solved dev 4 months ago


Loading...