Connect database locally
anubhav1603
HOBBYOP

2 years ago

is it possible to connect with localdburl which is of postgres

by localdburl i mean the one of railway service

14 Replies

anubhav1603
HOBBYOP

2 years ago

N/A


2 years ago

You want to connect to a psql DB from your local computer?

If so then yes, you just need to use the public url


anubhav1603
HOBBYOP

2 years ago

if same project have two service one db and one py app both can communicate locally ?


anubhav1603
HOBBYOP

2 years ago

this is the structure

1267687558096355300


anubhav1603
HOBBYOP

2 years ago

AFW-bot wants to talk with postgres


2 years ago

The AFW-bot can connect to the postgres instance. You should use the private DB url for that though.

You can add a env variable to AFW-bot (will be something like ${{Postgres.DATABASE_PRIVATE_URL}}). Then just grab that env variable in your python application to connect to the DB.


anubhav1603
HOBBYOP

2 years ago

ok so private db wont cost me right? only the public one costs?


anubhav1603
HOBBYOP

2 years ago

url i mean


2 years ago

Hey there, little correction needed -
For Postgres databases that are recently deployed you can simply reference DATABASE_URL as it is now the private url


2 years ago

They'll both count towards your usage. It's just better to use a private URL within your service.

See: https://railway.app/changelog/2024-07-19-database-private-networking#database-private-network-defaults


anubhav1603
HOBBYOP

2 years ago

oki


2 years ago

Hey, correction again, database to service communication over the private network does not cost anything on egress


2 years ago

But they still have resource usage eh? They're not free


2 years ago

yes of course, but there will be no egress


Loading...