Postgres 18 template for Railway deployment and hosting.
Largely taken from the Railway's repository with changes to support Postgres 18.
DO NOT simply change the image version and restart your service. PostgreSQL 18 introduced breaking changes to the data directory structure that will result in data loss if not handled properly.
- PostgreSQL 17 and earlier use
/var/lib/postgresql/dataas the data directory - PostgreSQL 18+ uses
/var/lib/postgresql/18/docker(version-specific path) - PostgreSQL 18 cannot read PostgreSQL 17 database files directly
If you're upgrading from PostgreSQL 17:
- Create a backup of your existing database using
pg_dumpall - Deploy a NEW PostgreSQL 18 service (don't reuse the old volume)
- Use Railway's PostgreSQL Migration template or manually restore your backup
- Update your application to use the new database URL
- Verify everything works before deleting the old service
If you're deploying a fresh PostgreSQL 18 database, you can use this template directly. Just ensure your Railway volume is mounted to /var/lib/postgresql (not /var/lib/postgresql/data).
- Volume Mount Path:
/var/lib/postgresql - PGDATA (auto-set):
/var/lib/postgresql/18/docker
See Railway's PostgreSQL upgrade guide for detailed migration instructions.