How to connect postgresql privately in railway
yoshimendokusee
FREEOP

a month ago

how to connect the database privately to avoid fees

Solved

17 Replies

dev
MODERATOR

a month 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

a month ago

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


dev
MODERATOR

a month 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

a month ago

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


yoshimendokusee
FREEOP

a month ago

can i use the private?


dev
MODERATOR

a month 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

a month ago

thank you so much!


dev
MODERATOR

a month ago

no problem 🙂


yoshimendokusee
FREEOP

a month ago

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


dev
MODERATOR

a month 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

a month ago

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


dev
MODERATOR

a month 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

a month 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


dev
MODERATOR

a month 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

a month ago

i just need to change this?

1435195060999291000


dev
MODERATOR

a month ago

i thiink so


dev
MODERATOR

a month ago

!s


Status changed to Solved dev about 1 month ago


Loading...