n8n with PostgreSQL
Workflow automation with PostgreSQL and persistent encrypted credentials.
Choose your deployment and the way you want to use Selfhost. The instructions below follow that choice.
Set up n8n with PostgreSQL
Workflow automation with PostgreSQL and persistent encrypted credentials.
Customize deployment inputs (2)
- Local HTTP port
port - portDefault:
5678 - Initial hostname (change public URL later in app settings)
hostname - hostnameDefault:
"localhost"
Save this as inputs.json and adjust the values before initialization.
{
"port": 5678,
"hostname": "localhost"
}selfhost app --directory ./n8n-postgres init n8n-postgres --stack --inputs inputs.json Initialization writes portable files and does not start the app. Review compose.yaml, the private .env and any files in files/, then start it:
selfhost app --directory ./n8n-postgres startNo Selfhost dashboard or background service is needed. You can also start these files directly:
cd n8n-postgres
docker compose -f compose.yaml up -d- Review the generated Compose and environment before starting. Only the app HTTP port is published, on loopback.
- Keep credentials, database and data volumes together in an independent backup. Exported Compose files do not include volume data.
- Use App setup to create the first owner. Set a public editor URL, webhook URL and secure cookies before configuring HTTPS access.
- Save ENCRYPTION_KEY with the database; losing it prevents decryption of existing credentials.
- SSO features depend on your n8n license. The community recipe does not claim licensed authentication features.
n8n integrations
Compose service: n8n. These operations use the profile saved when this deployment is created.
Initialize and connect
Supported setup modes: bootstrap.
- Creates the first owner only. Configure public URLs and HTTPS cookies before exposing this instance.
Setup fields
- Owner email
email - string · requiredLength: 1 to 255 characters
- First name
first-name - string · requiredLength: 1 to 255 characters
- Last name
last-name - string · requiredLength: 1 to 255 characters
- Owner password
password - secret · requiredLength: 12 to 255 characters
Save onboarding.json, replace example values and supply env: secrets privately through your shell. Empty apps adds no links; add explicit links when this profile supports them.
{
"mode": "bootstrap",
"inputs": {
"email": "YOUR_VALUE",
"first-name": "YOUR_VALUE",
"last-name": "YOUR_VALUE",
"password": "env:SELFHOST_PASSWORD"
},
"apps": []
}selfhost app --directory ./n8n-postgres setup n8n
selfhost app --directory ./n8n-postgres setup-plan n8n onboarding.json
selfhost app --directory ./n8n-postgres setup-apply n8n onboarding.json --revision REVIEWED_REVISIONNative settings
Changes use the app’s Compose environment. Unrelated settings are preserved.
Supported fields (30)
- Public editor URL
editor-url - string
- Public webhook URL
webhook-url - string
- Hostname
hostname - string
- Public protocol
protocol - stringChoices: http, https
- HTTPS-only session cookie
secure-cookie - stringChoices: true, false
- Trusted proxy hops
proxy-hops - string · advanced
- Workflow timezone
timezone - string
- Database type
database-type - string · advancedChoices: sqlite, postgresdb
- PostgreSQL host
database-host - string · advanced
- PostgreSQL port
database-port - string · advanced
- PostgreSQL database
database-name - string · advanced
- PostgreSQL username
database-user - string · advanced
- PostgreSQL password
database-password - secret · advanced
- Prune execution history
execution-prune - stringChoices: true, false
- Execution retention in hours
execution-age - string
- Maximum stored executions
execution-limit - string
- Workflow timeout in seconds
execution-timeout - string · advanced
- Prometheus metrics
metrics - stringChoices: true, false
- Log level
log-level - stringChoices: error, warn, info, debug
- SMTP host
smtp-host - string
- SMTP port
smtp-port - string
- SMTP username
smtp-user - string
- SMTP password
smtp-password - secret
- SMTP sender
smtp-sender - string
- SMTP TLS
smtp-ssl - stringChoices: true, false
- Disable public API
api-disabled - stringChoices: true, false
- Allow community packages
community-packages - string · advancedChoices: true, false
- Database TLS
database-tls - string · advancedChoices: true, false
- Verify database certificate
database-verify-certificate - string · advancedChoices: true, false
- Database CA certificate
database-ca - secret · advanced
Save a JSON map of the field IDs you want to change as changes.json. Replace FIELD_ID with an ID from the supported fields above, and use its declared value type. Review the plan and replace REVIEWED_REVISION with the revision it returns.
{
"FIELD_ID": "YOUR_VALUE"
}selfhost app --directory ./n8n-postgres config n8n
selfhost app --directory ./n8n-postgres plan n8n changes.json
selfhost app --directory ./n8n-postgres apply n8n changes.json --revision REVIEWED_REVISION Saved changes need service recreation to become active. Existing interpolated environment values stay under your control in .env or Compose.
Database placement
This recipe supports postgres. Workspace projects can choose a dedicated database, a shared source with a separate database and account, or an existing external database before their first start.
Standalone directories use the generated Compose and environment files directly. Configure the database there before first start. Selfhost’s source provisioning commands belong to workspace projects and are optional.
Database setup, CLI commands and backupsApp actions
List workflows
List workflows stored in this instance.
selfhost app --directory ./n8n-postgres action n8n list-workflowsExport workflows · schedulable
Export all workflows into the persistent data volume. Exports may contain credentials embedded in workflow parameters.
selfhost app --directory ./n8n-postgres action n8n export-workflowsA workspace can schedule this workflow while Selfhost runs. A standalone user can invoke it through an external scheduler. Scheduling guide.
Export encrypted credentials
Export credentials encrypted with the instance encryption key. Back up that key separately.
selfhost app --directory ./n8n-postgres action n8n export-credentialsShow version
Show the running n8n version.
selfhost app --directory ./n8n-postgres action n8n versionVersions and updates
This deployment uses the following images. Existing projects retain their saved recipe and images. A new catalogue version does not silently update them.
- database:
postgres:17-alpine - n8n:
docker.n8n.io/n8nio/n8n:2.40.7
Review compatibility and back up app data before an update. Choose an image version and review the change.
Keep control of your setup
Selfhost remains optional. Your app runs using ordinary Compose files, its own settings and persistent data. Keep the Compose project name and volumes to preserve storage. Configuration exports and setting backups do not include application data.