PostgreSQL

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

Deploy

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

Connect

Connect to PostgreSQL from another service in your project by referencing the environment variables made available in the PostgreSQL service:

  • PGHOST
  • PGPORT
  • PGUSER
  • PGPASSWORD
  • PGDATABASE
  • DATABASE_URL

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.

Connecting externally

It is possible to connect to PostgreSQL externally (from outside of the project in which it is deployed), by using the TCP Proxy which is enabled by default.

Keep in mind that you will be billed for Network Egress when using the TCP Proxy.

Image

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