Case study

n8n with PostgreSQL in Docker Compose

How n8n runs with its own PostgreSQL database in Docker Compose on a home server behind a tunnel. Includes the configs, a from-scratch install, a backup checked by restoring it, and fixes for two problems found in a working setup.

Net Admin Pro case cover: n8n with PostgreSQL in Docker Compose
Format
PDF EN + RU
Files
Configs and commands
Stack
n8n 2.25.6 · PostgreSQL 16
Server
Debian 13, Docker 29.5.3, Compose v5.1.4

What’s inside

  • A stack diagram and the key decisions: a pinned image version, the n8n port on localhost only, waiting for the database to be ready, an explicit credentials encryption key, secrets in .env.
  • Installing the stack from scratch: the full docker-compose.yml, an .env template, startup and checks.
  • Backing up the database before changes and checking that the dump restores, in a temporary container.
  • Two problems found in the working configuration: the image on the latest tag and an n8n port open to the whole local network. How they were fixed and what the before-and-after checks showed.
  • What the n8n log lines that look like errors actually mean.
  • A repeat checklist.

The text marks what was verified on a working server and what was not.

What’s in the archive

  • PDF in English and Russian;
  • docker-compose.yml;
  • env.example;
  • commands.txt – all commands from the text, by section.

Who it is for

  • Those who run n8n on their own server in Docker or plan to.
  • You need in advance: a server with Docker and Docker Compose, a user in the docker group, python3; for internet access, a working tunnel and a domain.

Not included

  • Installing Debian and Docker.
  • Setting up the Cloudflare tunnel and a firewall.
  • Daily backup of the whole server.
  • Ready-made n8n workflows.
  • Updating the n8n version is described but was not carried out on the server and is marked as not verified in the text.

What the case study covers

  1. Diagram and decisions

    A stack diagram and six key decisions: a pinned image version, the port on localhost only, waiting for the database, an explicit encryption key, the restart policy and secrets in .env.

  2. Install from scratch

    The stack directory, the full docker-compose.yml, .env with permissions 600, startup and a check that n8n responds from inside its container.

  3. Backup

    A database dump with pg_dump, set -o pipefail, an archive check with gzip -t and permissions 600.

  4. Restore check

    Restoring the dump into a temporary PostgreSQL container and comparing the table count with the working database.

  5. Pinning the version and port

    Moving from the latest tag to 2.25.6 and publishing the n8n port on 127.0.0.1 only, on a running stack.

  6. Before and after checks

    Six commands used to record the stack state before and after the change, and a table of the results.

  7. Checklist

    Items for installation, access checks and preparing for any change to the stack.