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.
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.
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.
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.
Tailor your PostgreSQL service to your needs by adding any variables relevant to the postgres image.
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