DATABASE_URL vs DATABASE_PUBLIC_URL

kanglichengPRO

a month ago

Hi,

I am struggling to understand when to use the public vs the private DB url.

Apparently in the CLI I have to use DATABASE_PUBLIC_URL. I thought railway run is running on railway infra and the internal URL would be valid.

Solved

1 Replies

a month ago

When deciding between using DATABASE_URL and DATABASE_PUBLIC_URL, it depends on where your application is running. For services running within Railway's infrastructure, you should use DATABASE_URL since it utilizes the private network, allowing faster and more secure connections without incurring egress charges.

However, when you are working locally or through the CLI, as in the case with railway run, you'll need to use DATABASE_PUBLIC_URL. This URL is meant for connecting to your database from outside Railway's private network. It allows you to access your database from your local development environment.

For more guidance on setting up and using these URLs, you can refer to the Build a Database Service guide. If you need further clarification on using the Railway CLI, you can check out the CLI API Reference.

  • Angelo


Status changed to Awaiting User Response railway[bot] about 1 month ago


Status changed to Solved kanglicheng about 1 month ago