Please help! n8n crashes on initialization docker + postgresql

Hi,

I am getting error when I try to setup Docker + postgresql. This is the only logs I am seeing. Just keeps repeating over and over again as log.

Please help!

n8n-n8n-1 exited with code 1
n8n-n8n-1 | Initializing n8n process
n8n-n8n-1 | Last session crashed

Hi @genobear, welcome to the community.

I am sorry to hear you’re having trouble. Can you confirm how to reproduce your problem please? For example, which command are you using to run n8n? How does your docker compose config file look like, if applicable?

Hi,

Here are the steps I did:

  1. Created docker-compose.yml. Here are the contents.
version: '3.8'

volumes:
  n8n_db_storage2:
  n8n_storage:

services:
  postgres:
    image: postgres:11
    restart: always
    ports:
      - 5677:5432
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    volumes:
      - n8n_db_storage2:/var/lib/postgresql/data
      - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
      interval: 5s
      timeout: 5s
      retries: 10

  n8n:
    image: n8nio/n8n
    restart: always
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5677
      - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
      - DB_POSTGRESDB_USER=${POSTGRES_NON_ROOT_USER}
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
    ports:
      - 5678:5678
    links:
      - postgres
    volumes:
      - n8n_storage:/home/node/.n8n
    command: /bin/sh -c "n8n start --tunnel"
    depends_on:
      postgres:
        condition: service_healthy

.env

POSTGRES_USER=admin
POSTGRES_PASSWORD=admin
POSTGRES_DB=n8n

POSTGRES_NON_ROOT_USER=bear
POSTGRES_NON_ROOT_PASSWORD=bear

N8N_BASIC_AUTH_USER=bear
N8N_BASIC_AUTH_PASSWORD=bear

N8N_LOG_LEVEL=debug
  1. Then ran this command.
docker-compose up

Below are the logs

[+] Running 3/2
 ⠿ Network n8n_default       Created                                                                                                                 0.2s
 ⠿ Container n8n-postgres-1  Created                                                                                                                 0.1s
 ⠿ Container n8n-n8n-1       Created                                                                                                                 0.1s
Attaching to n8n-n8n-1, n8n-postgres-1
n8n-postgres-1  | 
n8n-postgres-1  | PostgreSQL Database directory appears to contain a database; Skipping initialization
n8n-postgres-1  | 
n8n-postgres-1  | 2023-01-26 09:10:21.151 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
n8n-postgres-1  | 2023-01-26 09:10:21.152 UTC [1] LOG:  listening on IPv6 address "::", port 5432
n8n-postgres-1  | 2023-01-26 09:10:21.156 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
n8n-postgres-1  | 2023-01-26 09:10:21.179 UTC [25] LOG:  database system was interrupted; last known up at 2023-01-26 09:09:13 UTC
n8n-postgres-1  | 2023-01-26 09:10:21.536 UTC [25] LOG:  database system was not properly shut down; automatic recovery in progress
n8n-postgres-1  | 2023-01-26 09:10:21.541 UTC [25] LOG:  redo starts at 0/1652C80
n8n-postgres-1  | 2023-01-26 09:10:21.542 UTC [25] LOG:  invalid record length at 0/1652CB8: wanted 24, got 0
n8n-postgres-1  | 2023-01-26 09:10:21.542 UTC [25] LOG:  redo done at 0/1652C80
n8n-postgres-1  | 2023-01-26 09:10:21.567 UTC [1] LOG:  database system is ready to accept connections
n8n-n8n-1       | Initializing n8n process
n8n-n8n-1       | Last session crashed
n8n-n8n-1 exited with code 1
n8n-n8n-1       | Initializing n8n process
n8n-n8n-1       | Last session crashed
n8n-n8n-1 exited with code 1
n8n-n8n-1       | Initializing n8n process
n8n-n8n-1       | Last session crashed
n8n-n8n-1 exited with code 1

@MutedJam Just pinging.

Hey @genobear,

It looks like it is a network issue, Try changing the port for n8n to use to connect to the database to 5432 it is all happening in the same network so the host port isn’t available on the container itself it is just a redirect.

I have a different docker instance already running on 5678 (another project is using it). I wanted n8n to be in a different port. Is there a way to do it?

Hey @genobear,

The port of n8n can be changed on the docker host but your issue doesn’t appear to be related to that, If you wanted n8n to listen on a different port on your host though you would need to change

ports:
  - 5678:5678

to something like the below which will have the host listening on 8080 for the connections and passing them to 5678 which is an open port in the container.

ports:
  - 8080:5678
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.