Deploy PostgreSQL
Run PostgreSQL 16 on Railway with Docker, volume-ready defaults.
railwayapp-postgresql
Just deployed
PostgreSQL for railway.app
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.
ποΈ 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
| Variable | Required | Description |
|---|---|---|
POSTGRES_PASSWORD | Yes | Password for the postgres user |
Optional
| Variable | Description |
|---|---|
POSTGRES_USER | Defaults to postgres |
POSTGRES_DB | Defaults to postgres |
POSTGRES_INIT_DUMP_URL | HTTPS 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_BASE64 | Same 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
Template Content
railwayapp-postgresql
vergissberlin/railwayapp-postgresql