Hello all. I’m trying to set up n8n with Docker Compose using Traefik as a reverse proxy and PostgreSQL as the database hosted on another container. However, I’m encountering issues with starting n8n and database connection.
N8N setup information:
- n8n version: Latest (as specified in the Docker image
docker.n8n.io/n8nio/n8n
) - Database: PostgreSQL
- n8n EXECUTIONS_PROCESS setting: Not specified (using default)
- Running n8n via: Docker Compose
- Operating system: Ubuntu VPS Server
Error Message:
2025-01-31T17:36:34.723Z | error | Last session crashed {"file":"crash-journal.js","function":"init"}
2025-01-31T17:36:44.734Z | info | Initializing n8n process {"file":"start.js","function":"init"}
2025-01-31T17:36:45.051Z | debug | Lazy-loading nodes and credentials from n8n-nodes-base {"nodes":468,"credentials":371,"file":"DirectoryLoader.js","function":"loadAll"}
2025-01-31T17:36:45.201Z | debug | Lazy-loading nodes and credentials from @n8n/n8n-nodes-langchain {"nodes":79,"credentials":15,"file":"DirectoryLoader.js","function":"loadAll"}
2025-01-31T17:36:45.487Z | error | There was an error initializing DB {"file":"error-reporter.js","function":"defaultReport"}
2025-01-31T17:36:45.488Z | error | SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string {"file":"error-reporter.js","function":"defaultReport"}
My n8n docker-compose file:
version: "3.7"
services:
traefik:
image: "traefik"
restart: always
command:
- "--api=true"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.web.http.redirections.entryPoint.to=websecure"
- "--entrypoints.web.http.redirections.entrypoint.scheme=https"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true"
- "--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}"
- "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json"
ports:
- "80:80"
- "443:443"
volumes:
- traefik_data:/letsencrypt
- /var/run/docker.sock:/var/run/docker.sock:ro
n8n:
image: docker.n8n.io/n8nio/n8n:latest
container_name: con-n8n
env_file:
- .env
restart: always
ports:
- "5678:5678"
labels:
- traefik.enable=true
- traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`)
- traefik.http.routers.n8n.tls=true
- traefik.http.routers.n8n.entrypoints=websecure
- traefik.http.routers.n8n.tls.certresolver=mytlschallenge
- traefik.http.middlewares.n8n.headers.SSLRedirect=true
- traefik.http.middlewares.n8n.headers.STSSeconds=315360000
- traefik.http.middlewares.n8n.headers.browserXSSFilter=true
- traefik.http.middlewares.n8n.headers.contentTypeNosniff=true
- traefik.http.middlewares.n8n.headers.forceSTSHeader=true
- traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME}
- traefik.http.middlewares.n8n.headers.STSIncludeSubdomains=true
- traefik.http.middlewares.n8n.headers.STSPreload=true
- traefik.http.routers.n8n.middlewares=n8n@docker
environment:
- DB_TYPE=${DB_TYPE}
- DB_POSTGRESDB_HOST=${POSTGRES_HOSTNAME}
- DB_POSTGRESDB_PORT=${POSTGRES_PORT}
- DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
- DB_POSTGRESDBB_SCHEMA=${POSTGRES_SCHEMA}
- DB_POSTGRES_USER='n8n'
- DB_POSTGRES_PASSWORD='n8npassword'
- N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
- N8N_PORT=5678
- N8N_PROTOCOL=https
- NODE_ENV=production
- WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
- GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
networks:
- n8n-network
volumes:
- n8n_data:/home/node/.n8n
networks:
n8n-network:
external: true
volumes:
traefik_data:
external: true
n8n_data:
external: true
I’m not getting any errors on my postgres container but here is my postgres docker settings:
version: '3'
services:
postgres:
image: postgres:latest
container_name: con-postgres
restart: always
environment:
- DB_TYPE=postgresdb
- POSTGRESDB_HOST=postgres-container
- POSTGRES_PORT=5432
- POSTGRES_DATABASE=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_NON_ROOT_USER=${POSTGRES_NON_ROOT_USER}
- POSTGRES_NON_ROOT_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}
volumes:
- ./data:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', 'pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
interval: 5s
timeout: 5s
retries: 10
networks:
- n8n-network
networks:
n8n-network:
external: true
I’ve already tried using ‘password’, hardcoded the password and setting the passwords and privileges on my n8n user. But nothing seems to work. Please help. Before this, when I was using the SQLite as database, everything is working fine.