Could we store workflow in to external database like postgres db

Hi. Currently workflows are getting stored in local SQLite database. But my requirements is to store all workflow into external postgres database which is located on different machine. For example, I have two machine, one is for running workflow and other machine is for storing workflows into postgres database. Is there a way to do it?

Hey @shailesh23!

Welcome to the community :slightly_smiling_face:

You can refer to the documentation here: Databases | Docs

Hi harshil.
Thanks. Can I get more info on that OR any in detailed example.

Hey Shailesh,

Can you please share what information you need exactly? The documentation link I mentioned gives all the required information.

1 Like

This work for me:

The ‘docker-compose.yml’ file

version: '3.1'

services:
  n8n:
    image: n8nio/n8n
    restart: always
    environment:
      - DB_TYPE=postgresdb
      - "DB_POSTGRESDB_HOST=${DB_POSTGRESDB_HOST:-postgres}"
      - "DB_POSTGRESDB_PORT=${DB_POSTGRESDB_PORT:-5432}"
      - "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:
      - "${N8N_PORT}:5678"
    volumes:
      - ${N8N_DATA}:/root/.n8n
    # Wait 5 seconds to start n8n to make sure that PostgreSQL is ready
    # when n8n tries to connect to it
    command: /bin/sh -c "sleep 5; n8n start"
    networks:
      - app-network

#Docker Networks
networks:
  app-network:
    driver: bridge

The ‘.env’ file

#GLOBAL TIMEZONE
GENERIC_TIMEZONE=America/Sao_Paulo

DB_POSTGRESDB_HOST=192.168.2.4
DB_POSTGRESDB_PORT=1010
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=local_orquestrador_n8n

POSTGRES_NON_ROOT_USER=postgres
POSTGRES_NON_ROOT_PASSWORD=postgres

N8N_BASIC_AUTH_USER=changeUser
N8N_BASIC_AUTH_PASSWORD=changePassword

N8N_PORT=5678

N8N_DATA=./n8n_data/
N8N_VERSION_NOTIFICATIONS_ENABLED=false
2 Likes

Hey @tiago!

Welcome to the community :sparkling_heart:

Thank you for sharing your solution :slight_smile:

1 Like

Thank you and youre welcome!

1 Like

Hi, this may be really usefull, having more information on how to create a PostgresSQL database for N8N.

  • encoding,
  • locale,

A basic CREATEDB example would be great.

Kind regards.

Hey @Maximilien,

As a basic example I just use create database n8n for me this uses UTF-8 for encoding and en_US.UTF-8 for the collate.

Hey @tiago ,
I’m struggling for the past 2 days to get an external postgresql database work with my self hosted n8n docker. Could you please share complete docker_compose.yaml and .env? Thanks

@Nirmal_Kumar can you open a new topic for this and share the config you are currently using and the error you are seeing?

Most of the time the issue will be down to the user account being used so it would be worth double checking that your user is able to access the database and can create tables.

1 Like