Railway

Deploy PostgreSQL

Run PostgreSQL 16 on Railway with Docker, volume-ready defaults.

Deploy PostgreSQL

Just deployed

PostgreSQL for railway.app

Template Header

Deploy PostgreSQL 16 on Railway with the official Docker image. This template provisions a ready-to-run relational database for your application data, analytics, or as a shared backing store for other services in your project. It includes sensible defaults, a built-in health check, and guidance for attaching persistent storage so your data survives redeploys.

Deploy on Railway

πŸ—οΈ Architecture

flowchart LR
    Client(["πŸ“¦ App / Client"]) -->|"PostgreSQL Protocol"| Proxy["Railway TCP Proxy"]
    Proxy -->|"$PORT β†’ 5432"| App["Container\npostgres:16-alpine"]
    App --> Volume[("Volume\n/var/lib/postgresql/data")]

Environment

VariableRequiredDescription
POSTGRES_PASSWORDYesPassword for the postgres user

Optional

VariableDescription
POSTGRES_USERDefaults to postgres
POSTGRES_DBDefaults to postgres
POSTGRES_INIT_DUMP_URLHTTPS URL to a .sql or gzip-compressed .sql.gz dump (e.g. pg_dump --format=plain); downloaded and imported automatically, but only on the first start of an empty volume. Takes precedence over POSTGRES_INIT_DUMP_BASE64 if both are set.
POSTGRES_INIT_DUMP_BASE64Same dump, base64-encoded and pasted directly as the variable value. Ignored if POSTGRES_INIT_DUMP_URL is also set. Best for small dumps only.

> [!NOTE] > POSTGRES_INIT_DUMP_URL/POSTGRES_INIT_DUMP_BASE64 are only ever consulted on the very first start against a brand-new, empty volume. Once the database has initialized, both variables are silently ignored on every later restart or redeploy β€” even if you leave them set. The dump runs with full administrative privileges during bootstrap, so only point these at dumps from sources you trust.

Persistence

railway.toml declares requiredMountPath = "/var/lib/postgresql/data". Attach a Railway volume to that path before production traffic β€” Railway will prompt for it based on this setting, but it is not created automatically.

Local

docker build -t railwayapp-postgresql .
docker run --rm -e POSTGRES_PASSWORD=dev -p 5432:5432 railwayapp-postgresql

Airbyte Apache Airflow CloudBeaver CodiMD Django Email Service FastAPI Flask Flowise GitLab CE Grafana Home Assistant InfluxDB MJML MongoDB Mosquitto MQTT MySQL n8n Node.js Node-RED OpenSearch Open WebUI Outerbase Studio PostgreSQL Redis TYPO3 CMS


Template Content

More templates in this category

View Template
Rocky Linux
[Jul'26] Hosted Rocky Linux 9 workspace with SSH and persistent storage. πŸš€

codestorm
40
View Template
Foundry Virtual Tabletop
A Self-Hosted & Modern Roleplaying Platform

Lucas
71
View Template
Letta Code Remote
Run a Letta Code agent 24/7. No inbound ports, just deploy.

Letta
51