By default, self-hosted n8n installations use a local SQLite database to log settings, active users, and execution logs. While SQLite is great for testing and low execution counts, high webhook traffic can lock the database file and crash the instance.

Why upgrade to PostgreSQL?

  • Concurrent Writes: PostgreSQL handles thousands of parallel operations cleanly.
  • Scale: Easy database maintenance and connection pool scaling.
  • Backups: Live backups without stopping the container.

Docker Compose Configuration

To upgrade your stack, configure a multi-container Docker Compose setup:

services:
  db:
    image: postgres:15-alpine
    restart: always
    environment:
      POSTGRES_USER: n8n_admin
      POSTGRES_PASSWORD: strongPasswordHere
      POSTGRES_DB: n8n_data
    volumes:
      - ./postgres_data:/var/lib/postgresql/data

  n8n:
    image: docker.n8n.io/n8nio/n8n:latest
    restart: always
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n_data
      - DB_POSTGRESDB_USER=n8n_admin
      - DB_POSTGRESDB_PASSWORD=strongPasswordHere
    depends_on:
      - db