Deploy n8n | Self-Hosted Automation with Postgres and Real Persistence
Self-host n8n on Railway — workflows, Postgres & data that survives.
Just deployed
/var/lib/postgresql/data
n8nio/n8n:2.32.5
Just deployed
/home/node/.n8n
Deploy and Host n8n on Railway
n8n is a self-hosted workflow automation tool — a visual editor for connecting APIs, databases and schedules, with the workflows and credentials living on infrastructure you control. This template deploys n8n with a PostgreSQL database, wired together over Railway's private network.
About Hosting n8n
n8n keeps state in two places, and this is where self-hosted deployments quietly go wrong. Workflows, executions and credentials go into PostgreSQL. But the encryption key, installed community nodes, binary data from executions and the instance's own settings file live on disk, under the user folder. A container filesystem is wiped on every redeploy, so without a volume on the correct path those disappear — and because the workflows themselves survive in Postgres, the instance looks fine until a credential fails to decrypt or a custom node vanishes.
Common Use Cases
- Scheduled jobs: reports, syncs, backups, digests
- Webhook receivers that fan out into several APIs
- Glue between internal tools without writing a service for each connection
Dependencies for n8n Hosting
n8nio/n8n:2.32.5— pinned to an exact release rather than a floating tag- PostgreSQL 18, provisioned here and reached over the private network
Deployment Dependencies
Implementation Details
The volume is mounted at /home/node/.n8n, which is n8n's actual user folder. This is worth stating plainly because the existing n8n templates on Railway get it wrong in two different ways: one attaches no volume to the n8n service at all, the other mounts it at /data, a path n8n never writes to. Both look correct on the canvas and neither persists anything.
The image runs as a non-root user, and a freshly mounted Railway volume is owned by root, so RAILWAY_RUN_UID=0 is set — Railway's documented remedy for exactly this.
The database connection is assembled from the Postgres service's own variables, so credentials are never duplicated and traffic stays on the private network:
DB_TYPE=postgresdb
DB_POSTGRESDB_HOST=${{Postgres.PGHOST}}
DB_POSTGRESDB_PASSWORD=${{Postgres.POSTGRES_PASSWORD}}
N8N_LISTEN_ADDRESS=:: makes n8n bind dual-stack, and WEBHOOK_URL and N8N_EDITOR_BASE_URL are derived from the generated domain so webhook URLs shown in the editor are the ones that actually resolve. N8N_ENCRYPTION_KEY is generated once per deployment — keep it, it is what decrypts your stored credentials.
Both images are pinned. A floating tag means a future upstream release can change your instance during an unrelated redeploy.
Getting Started
Open the generated domain and create the owner account. Add credentials under Credentials, build a workflow, and activate it. Scheduled and webhook workflows only run while the workflow is active.
Why Deploy n8n on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying n8n on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
n8nio/n8n:2.32.5
n8nio/n8n:2.32.5