The Railway PostgreSQL database service allows you to provision and connect to a PostgreSQL database with zero configuration.


You can add a PostgreSQL database via the CMD + K menu or by clicking the + New button on the Project Canvas.

GIF of the Adding Database


There are two ways to connect to a PostgreSQL database -

When you deploy your PostgreSQL database, you will have access to two environment variables that enable one of the two connection types (private or public).

As you create more services in your project, you can use Reference Variables to easily connect to the PostgreSQL database.

Private Networking

To access your PostgreSQL database from another service within the same project, you can use the connection string stored in the DATABASE_PRIVATE_URL environment variable.

This connection string uses Private Networking to route communication to your service over the private network.

TCP Proxy Connection

To access your PostgreSQL database over the public internet, you can use the connection string stored in the DATABASE_URL environment variable available in the service.

This connection string uses the TCP Proxy connection to route communication to your service over the public internet.

You can also connect using psql shell:


The following variables are included in the PostgreSQL service and can be referenced in other services:


Note, Many libraries will automatically look for the DATABASE_URL variable and use it to connect to PostgreSQL but you can use these variables in whatever way works for you.


The Postgres database service uses Railway's SSL-enabled Postgres image, which uses the official postgres image in Docker Hub as its base.

Changing System Variables

Tailor your PostgreSQL service to your needs by adding any variables relevant to the postgres image.

Timescale and PostGIS

The Postgres service deployed from the Command Palette no longer contains PostGIS or Timescale extensions. However, there are several options in the template marketplace that deploy a PostGIS or Timescale-enabled Postgres image.

To deploy a service from a template in an existing project, simply click + New from your project canvas, select Template and search for the template you require.

Edit this file on GitHub