${{Postgres.DATABASE_URL}} does not show the public URL, only the private one

stefanuddenberg
PRO

5 months ago

I have a project with one web service and one Postgres database spun up on Railway. I can see on the database's side that the environment variables DATABASEURL (on switchback.proxy.rlwy.net) and DATABASEPRIVATEURL (on postgres.railway.internal). However, when I attempt to reference the DATABASEURL from my web service, it reflects instead the DATABASEPRIVATEURL no matter what. This makes it impossible to use Railway's CLI tooling to connect to my database easily to create tables. Can you help me with this?

0 Replies

stefanuddenberg
PRO

5 months ago

Project ID: a560fb3c-2fe5-47e1-94e7-af96bd10b69a


angelonchain
PRO

5 months ago

Unsure if this is your issue but the variable name is; DATABASE_PUBLIC_URL for the public URL and not DATABASE_URL.


echohack
EMPLOYEE

5 months ago

yeah I think angel is right here. I'd check a couple of things if you haven't already:

  • On the Postgres deployment, check Settings > Networking to ensure the Public network TCP proxy is indeed setup. You should see something like [shuttle.proxy.rlwy.net](shuttle.proxy.rlwy.net):port -> :5432

  • On variables, check that you have the reference variable {} DATABASE_PUBLIC_URL, which should be the connection string to your TCP proxy service


5 months ago

If I remember it correctly, in the past, the two connection string variables provided when the database was created were DATABASE_PRIVATE_URL (private) and DATABASE_URL (public).

This has since been changed to DATABASE_PUBLIC_URL (public) and DATABASE_URL (private).


5 months ago

What you could try is to rename the variable names using the raw editor and replace DATABASE_PRIVATE_URL with DATABASE_URL and DATABASE_URL with DATABASE_PUBLIC_URL.

For reference, this is how the two connection string variables are defined for newly created postgres databases.

DATABASE_PUBLIC_URL="postgresql://${{PGUSER}}:${{POSTGRES_PASSWORD}}@${{RAILWAY_TCP_PROXY_DOMAIN}}:${{RAILWAY_TCP_PROXY_PORT}}/${{PGDATABASE}}"
DATABASE_URL="postgresql://${{PGUSER}}:${{POSTGRES_PASSWORD}}@${{RAILWAY_PRIVATE_DOMAIN}}:5432/${{PGDATABASE}}"