Why is my database so big?

Hey @aston_he,

Have you enabled pruning? I suggest you set the environment variable EXECUTIONS_DATA_PRUNE to true. You can also set a max age using the environment variable EXECUTIONS_DATA_MAX_AGE .

You find more information here: Environment Variables | Docs

I run n8n in the docker,I use the default setting.

You should then add these to your configuration. If you’ve setup environment variables in an .env file, you can add these in that same file

How can I set up this?Please give an advice.

@aston_he in your Docker Compose file (if you are using it) you will have the environment options. In there you can add the extra options, As an example in the instances I have running I use…

      - EXECUTIONS_DATA_SAVE_ON_ERROR=all
      - EXECUTIONS_DATA_SAVE_ON_SUCCESS=none
      - EXECUTIONS_DATA_SAVE_ON_PROGRESS=true
      - EXECUTIONS_DATA_SAVE_MANUAL_EXECUTIONS=false
      - EXECUTIONS_DATA_PRUNE=true
      - EXECUTIONS_DATA_MAX_AGE=168

This makes my full docker-compose.yml look like this:

version: "3"
services:
  n8n:
    container_name: n8n
    image: n8nio/n8n
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=http
      - NODE_ENV=production
      - VUE_APP_URL_BASE_API=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - WEBHOOK_TUNNEL_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - EXECUTIONS_PROCESS=main
      - EXECUTIONS_DATA_SAVE_ON_ERROR=all
      - EXECUTIONS_DATA_SAVE_ON_SUCCESS=none
      - EXECUTIONS_DATA_SAVE_ON_PROGRESS=true
      - EXECUTIONS_DATA_SAVE_MANUAL_EXECUTIONS=false
      - EXECUTIONS_DATA_PRUNE=true
      - EXECUTIONS_DATA_MAX_AGE=168
    volumes:
      - ${DATA_FOLDER}/.n8n:/home/node/.n8n

My .env file looks like this:

DATA_FOLDER=/home/username/n8n/data

DOMAIN_NAME=mydomain.tld
SUBDOMAIN=n8n-service

N8N_BASIC_AUTH_USER=ADMIN_USERNAME_HERE
N8N_BASIC_AUTH_PASSWORD=ADMIN_PASSWORD_HERE

# Timezone
GENERIC_TIMEZONE=Europe/London
3 Likes

You are the best.

2 Likes

It is worth having the other bits as you probably won’t need all the logging… or at least I have found that we don’t need it anyway.

And how can I reduce the exist database now?It sees so big.

You need to set the EXECUTIONS_DATA_PRUNE option.

I have done.As you said.

Perfect, I think you might also need DB_SQLITE_VACUUM_ON_STARTUP to clean up what is already there.

DB_SQLITE_VACUUM_ON_STARTUP = true
2 Likes

Good!
The database is reduced now!

2 Likes

Hello, I am facing this error.

environment variable name 'DB_SQLITE_VACUUM_ON_STARTUP ' may not contain whitespace

below is my docker-compose.yml

      - EXECUTIONS_DATA_SAVE_ON_SUCCESS=none
      - EXECUTIONS_DATA_SAVE_ON_ERROR=all
      - EXECUTIONS_DATA_SAVE_ON_PROGRESS=true
      - EXECUTIONS_DATA_SAVE_MANUAL_EXECUTIONS=false
      - EXECUTIONS_DATA_MAX_AGE=168
      - DB_SQLITE_VACUUM_ON_STARTUP = true
    volumes:
      - /home/ubuntu/n8n/n8n_data:/home/node/.n8n

may i know what is wrong?

now i know what is wrong. there should not have any space before and afte “=” sign. in the environment.

1 Like

Hello,
I’ve installed n8n with YunoHost and now my database is more than 30gb. Can I execute these commands now or only during the installation of n8n?
Thank you

Hey @theRAGEhero,

Welcome to the community :birthday:

You can add the environment options to clear down the database logs and vacuum if using SQLite at any time. It may take a while for the service to start back up as it will have a lot to do but give it 5 minutes or so and see how it is looking.

1 Like

Hey @Jon ,

Do you know how to correctly restart the docker container without deleting any flow after we made this changes on docker-compose file? Here how it looks like:

version: "3"

services:
  traefik:
    image: "traefik"
    restart: always
    command:
      - "--api=true"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.web.http.redirections.entryPoint.to=websecure"
      - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true"
      - "--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}"
      - "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ${DATA_FOLDER}/letsencrypt:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro

  n8n:
    image: n8nio/n8n
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    labels:
      - traefik.enable=true
      - traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`)
      - traefik.http.routers.n8n.tls=true
      - traefik.http.routers.n8n.entrypoints=web,websecure
      - traefik.http.routers.n8n.tls.certresolver=mytlschallenge
      - traefik.http.middlewares.n8n.headers.SSLRedirect=true
      - traefik.http.middlewares.n8n.headers.STSSeconds=315360000
      - traefik.http.middlewares.n8n.headers.browserXSSFilter=true
      - traefik.http.middlewares.n8n.headers.contentTypeNosniff=true
      - traefik.http.middlewares.n8n.headers.forceSTSHeader=true
      - traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME}
      - traefik.http.middlewares.n8n.headers.STSIncludeSubdomains=true
      - traefik.http.middlewares.n8n.headers.STSPreload=true
      - traefik.http.routers.n8n.middlewares=n8n@docker
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
      - N8N_HOST=HOST
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://HOST/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - EXECUTIONS_DATA_SAVE_ON_ERROR=all
      - EXECUTIONS_DATA_SAVE_ON_SUCCESS=none
      - EXECUTIONS_DATA_SAVE_ON_PROGRESS=false
      - EXECUTIONS_DATA_SAVE_MANUAL_EXECUTIONS=false
      - EXECUTIONS_DATA_PRUNE=true
      - EXECUTIONS_DATA_MAX_AGE=2
    volumes:
      - ${DATA_FOLDER}/.n8n:/home/node/.n8n
      - /home/raguelerbackup/n8n-local-files:/files
# Folder where data should be saved
DATA_FOLDER=/home/raguelerbackup/n8n/

# The top level domain to serve from
DOMAIN_NAME=DOMAIN

# The subdomain to serve from
SUBDOMAIN=SUBDOMAIN

# DOMAIN_NAME and SUBDOMAIN combined decide where n8n will be reachable from
# above example would result in: https://n8n.example.com

# The user name to use for authentication - IMPORTANT ALWAYS CHANGE!
N8N_BASIC_AUTH_USER=USER

# The password to use for authentication - IMPORTANT ALWAYS CHANGE!
N8N_BASIC_AUTH_PASSWORD=PASS

# Optional timezone to set which gets used by Cron-Node by default
# If not set New York time will be used
GENERIC_TIMEZONE=Europe/Berlin

# The email address to use for the SSL certificate creation
SSL_EMAIL=EMAIL

Hey @onurbolaca,

This is an old post now and I will have to lock it but to answer your question as long as you are using a volume you will be ok, Looking at your example you have one set so there shouldn’t be anything to worry about.