# Please help! n8n crashes on initialization docker + postgresql

**URL:** <https://community.n8n.io/t/please-help-n8n-crashes-on-initialization-docker-postgresql/22278>\
**Category:** Questions\
**Tags:** development\
**Created:** [January 26, 2023, 9:08am UTC](https://community.n8n.io/t/please-help-n8n-crashes-on-initialization-docker-postgresql/22278 "2023-01-26T09:08:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![genobear](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/genobear/32/21707_2.png) [@genobear](https://community.n8n.io/u/genobear)\
**Post date:** [January 26, 2023, 9:08am UTC](https://community.n8n.io/t/please-help-n8n-crashes-on-initialization-docker-postgresql/22278/1 "2023-01-26T09:08:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [January 26, 2023, 9:20am UTC](https://community.n8n.io/t/please-help-n8n-crashes-on-initialization-docker-postgresql/22278/2 "2023-01-26T09:20:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![genobear](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/genobear/32/21707_2.png) [@genobear](https://community.n8n.io/u/genobear)\
**Post date:** [January 27, 2023, 12:20am UTC](https://community.n8n.io/t/please-help-n8n-crashes-on-initialization-docker-postgresql/22278/3 "2023-01-27T00:20:36Z")

</div>

Hi,

Here are the steps I did:

1. Created docker-compose.yml. Here are the contents.

```auto
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

```auto
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.

```auto
docker-compose up

```

Below are the logs

```auto
[+] 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

```

---

<div class="post-metadata">

**Author:** ![genobear](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/genobear/32/21707_2.png) [@genobear](https://community.n8n.io/u/genobear)\
**Post date:** [January 27, 2023, 6:09am UTC](https://community.n8n.io/t/please-help-n8n-crashes-on-initialization-docker-postgresql/22278/4 "2023-01-27T06:09:22Z")

</div>

@MutedJam Just pinging.

---

<div class="post-metadata">

**Author:** ![Jon](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jon/32/40174_2.png) [@Jon](https://community.n8n.io/u/Jon)\
**Post date:** [January 27, 2023, 11:46am UTC](https://community.n8n.io/t/please-help-n8n-crashes-on-initialization-docker-postgresql/22278/5 "2023-01-27T11:46:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![genobear](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/genobear/32/21707_2.png) [@genobear](https://community.n8n.io/u/genobear)\
**Post date:** [January 30, 2023, 2:13am UTC](https://community.n8n.io/t/please-help-n8n-crashes-on-initialization-docker-postgresql/22278/6 "2023-01-30T02:13:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Jon](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jon/32/40174_2.png) [@Jon](https://community.n8n.io/u/Jon)\
**Post date:** [January 30, 2023, 8:45am UTC](https://community.n8n.io/t/please-help-n8n-crashes-on-initialization-docker-postgresql/22278/7 "2023-01-30T08:45:50Z")

</div>

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

```auto
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.

```auto
ports:
  - 8080:5678

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [April 30, 2023, 8:46am UTC](https://community.n8n.io/t/please-help-n8n-crashes-on-initialization-docker-postgresql/22278/8 "2023-04-30T08:46:36Z")

</div>

Closed on April 30, 2023, 8:46am UTC

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