a month ago
how to connect the database privately to avoid fees
17 Replies
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
what do you mean by the second sentence? sorry, can you give a scenario
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
what if im trying to connect my ServiceA to my pgadmin4 from my laptop
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
a month ago
no problem 🙂
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
thank you so much, but i think using the public proxy is kinda risky. so i might use this process
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
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

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 neededcan 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
a month ago
i thiink so
a month ago
!s
Status changed to Solved dev • about 1 month ago
