n8n SQLite Database Is Locked: Export & Migrate to Postgres

19 min readBy Yun Sanghun (M. Yun)

An n8n SQLite database locked error happens when concurrent webhook workers compete for a single file-level write lock on default SQLite storage. When multiple HTTP webhooks or scheduled workflows trigger at the same moment, only one connection can write to /home/node/.n8n/database.sqlite at a time, while competing writes wait until the timeout expires and fail with QueryFailedError: SQLITE_BUSY: database is locked.

On 2025-02-03 I tested moving a Docker n8nio/n8n:1.76.1 instance from its default SQLite database to PostgreSQL with n8n export:workflow and n8n export:credentials, and also reproduced the database is locked error directly with two Python sqlite3 writers in a container. The migration worked when the new container used the old N8N_ENCRYPTION_KEY, and silently broke stored credentials when it did not (import:credentials still printed Successfully imported 1 credential.). The commands and container output from those runs are below.

Tested on: Windows 11 Pro 23H2 | WSL 2 Linux Kernel 6.6.87.2-microsoft-standard-WSL2 | Official Docker Engine 27.3.1, build ce12230 (desktop-linux) + Docker Compose v2.29.7 | n8nio/n8n:1.76.1 (:5678) + postgres:16-alpine (PostgreSQL 16.15) & postgres:17-alpine (PostgreSQL 17.11) | Empirical Execution Date: 2025-02-03.

Terminal inspection of a default standalone n8nio/n8n:1.76.1 container showing /home/node/.n8n/database.sqlite in DELETE journal mode and QueryFailedError SQLITE_BUSY database is locked log lines
Inspecting a default standalone n8nio/n8n:1.76.1 container on Docker Desktop: all workflow definitions, encrypted credentials, and execution payloads share a single /home/node/.n8n/database.sqlite file that raises SQLITE_BUSY: database is locked when concurrent writes exceed the lock timeout.

Short Answer (Immediate 3-Step Recovery):

  1. Export workflows and credentials via n8n CLI before you change anything: Record the 32-character encryptionKey inside /home/node/.n8n/config, then run n8n export:workflow --all and n8n export:credentials --all --decrypted as the node user and copy both JSON files to the host.
  2. Switch from standalone SQLite to a multi-container PostgreSQL 17 Docker Compose stack: Deploy postgres:17-alpine alongside n8nio/n8n:1.76.1 with DB_TYPE=postgresdb, a pg_isready healthcheck gate, and the original N8N_ENCRYPTION_KEY.
  3. Import your assets and enforce automatic execution pruning: Run n8n import:credentials and n8n import:workflow, verify credential decryption readback, delete the plaintext JSON export, and set EXECUTIONS_DATA_PRUNE=true with EXECUTIONS_DATA_MAX_AGE=168.

Why SQLite Returns SQLITE_BUSY When Two Writers Collide

By default, an out-of-the-box n8n container stores its settings, credentials, workflow logic, and execution history in a single SQLite database file located at /home/node/.n8n/database.sqlite. When migrating that container to PostgreSQL, preserve your GENERIC_TIMEZONE environment variables (n8n timezone configuration guide), authenticate public webhook endpoints in code (n8n raw-body HMAC SHA256 verification), and schedule offsite pg_dump archives (automated Docker volume & pg_dump backups).

SQLite is fine for testing or running a few scheduled workflows. Once you start running concurrent webhooks, parallel sub-workflows, or frequent polling triggers, three SQLite limits get in the way:

Architecture comparison of n8n single-writer SQLite database.sqlite file locking causing SQLITE_BUSY errors versus PostgreSQL 17 MVCC row-level concurrency with PgBouncer transaction pooling
Storage Concurrency Topology: Under parallel webhook bursts, SQLite's single-writer file lock serializes execution_entity inserts until SQLITE_BUSY fires, whereas PostgreSQL 17 MVCC with PgBouncer transaction pooling handles concurrent writes without file locks.
n8n 1.76.1 Executions dashboard (/home/executions) showing concurrent webhook execution failures with QueryFailedError SQLITE_BUSY database is locked while Writer 1 holds the file-level write lock
Authenticated n8n 1.76.1 Executions dashboard (/home/executions) during a concurrent webhook burst on default SQLite storage: while one execution holds the file-level write lock to persist its JSON payload, competing webhook executions stall and fail.
  1. Database-Level Write Lock: Unlike client-server relational databases that use Multi-Version Concurrency Control (MVCC) and row-level locking, SQLite locks the entire database file during a write operation (INSERT, UPDATE, or DELETE). Even with Write-Ahead Logging (WAL) enabled, SQLite still allows only one writer at a time. When 15 webhook requests hit n8n at the same moment, 14 of those execution threads must wait in line to write their initial status to the database. Once a thread waits longer than the busy timeout, SQLite drops the query and raises SQLITE_BUSY: database is locked.
  2. Unpruned Execution History Bloat: Every time an n8n workflow runs, n8n serializes the JSON input and output of every single node and writes it into the execution_entity and execution_data tables. Without automatic pruning, database.sqlite grows to several gigabytes. Updating indexes on a multi-gigabyte single-file database makes each write take longer, which makes lock timeouts happen more often.
  3. Not a cause of webhook 413 errors: A locked SQLite database causes executions to fail or hang, not 413 Payload Too Large responses; 413 comes from a reverse proxy (e.g. Nginx client_max_body_size) or n8n's body-size limit (N8N_PAYLOAD_SIZE_MAX).

The fix is to stop using the local SQLite file and move to PostgreSQL (17 or newer, as n8n 1.76.1 asks) with scheduled execution pruning, sizing your new container's max_connections and pool limits beforehand with our PostgreSQL & PgBouncer Memory Pool Calculator.

SQLite lets only one connection write at a time. This short script, run in a container on Docker Desktop for Windows 11, opens two writers on the same file. The second one waits 2 seconds, then gives up with the same lock error that n8n surfaces as SQLITE_BUSY:

Container terminal running /lab/sqlite_locked.py where Writer 1 executes BEGIN IMMEDIATE on /tmp/n8n-demo.sqlite and Writer 2 fails after 2.0s with sqlite3.OperationalError database is locked
Reproducing SQLite's single-writer lock inside a container (/lab/sqlite_locked.py): Writer 1 acquires a write lock on /tmp/n8n-demo.sqlite with BEGIN IMMEDIATE, forcing Writer 2 (timeout=2) to wait 2.0 seconds before failing with sqlite3.OperationalError: database is locked.

In the reproduction above, Writer 1 opens /tmp/n8n-demo.sqlite, creates the execution_entity table, executes BEGIN IMMEDIATE, and inserts row 1 while keeping its transaction open. When Writer 2 connects to the same file with timeout=2 and attempts to insert row 2, SQLite blocks Writer 2 for the full 2.0 seconds before raising sqlite3.OperationalError: database is locked.

Step 1: Export Workflows and Credentials with the n8n CLI

Before stopping your current n8n container or changing its configuration, back up your workflows and credentials. Because SQLite and PostgreSQL use different column types and table schemas, you cannot copy the database.sqlite file into PostgreSQL. Instead, use n8n's built-in CLI commands to export your data into portable JSON files.

1. Identify Your n8n Container and Encryption Key

First, find the exact name of your running n8n container and retrieve your current N8N_ENCRYPTION_KEY. If you do not carry this exact key over to your new PostgreSQL setup, n8n will not be able to decrypt your saved API keys and credentials:

# List running containers to confirm your n8n container name
docker ps --filter "ancestor=n8nio/n8n"

# Read the encryption key from the n8n config file inside the container
docker exec -it n8n cat /home/node/.n8n/config

Look for the "encryptionKey" field in the JSON output, or note down the environment variable N8N_ENCRYPTION_KEY from your existing configuration. Save this value securely:

Side-by-side configuration editor showing /home/node/.n8n/config with the 32-character encryptionKey and step1_export_n8n_sqlite.sh exporting workflows.json and credentials.json as the node user
Inspecting /home/node/.n8n/config inside the source SQLite container alongside the emergency CLI export script: the 32-character encryptionKey must be recorded before stopping the container so migrated credentials can be decrypted on PostgreSQL.

Whenever n8n saves an API token, database password, or webhook header secret into credentials_entity.data, it encrypts the secret using AES-256-CBC derived from that 32-character "encryptionKey" string. Recording this key before stopping the SQLite container ensures that your new PostgreSQL-backed container can decrypt existing credentials without requiring you to re-enter every secret by hand.

2. Export Workflows and Decrypted Credentials

Run the following commands to create a temporary backup directory inside the container and export all workflows and credentials. Make sure to pass -u node so the generated files are owned by the container's node user rather than root:

# 1. Create a backup directory inside the container's persistent volume
docker exec -u node -it n8n mkdir -p /home/node/.n8n/migration_backup

# 2. Export all workflows to a single JSON file
docker exec -u node -it n8n n8n export:workflow --all --output=/home/node/.n8n/migration_backup/workflows.json

# 3. Export all credentials in decrypted format for safe cross-database migration
docker exec -u node -it n8n n8n export:credentials --all --decrypted --output=/home/node/.n8n/migration_backup/credentials.json

Verify that both JSON files were created and are not empty (0 bytes):

docker exec -u node -it n8n ls -lh /home/node/.n8n/migration_backup/
Split terminal comparison showing n8n export:workflow --all and n8n export:credentials --all --decrypted inside the SQLite container on the left and encrypted ciphertext versus decrypted plaintext JSON on the right
Running n8n export:workflow --all and n8n export:credentials --all --decrypted inside the SQLite container as the node user (left) and comparing the encrypted ciphertext export against the portable --decrypted JSON output (right).

3. Copy Backups to the Host Filesystem

Copy the exported JSON files from the container to a safe directory on your host server so they are preserved when you stop the old container:

mkdir -p ~/n8n-migration-backup
docker cp n8n:/home/node/.n8n/migration_backup/workflows.json ~/n8n-migration-backup/workflows.json
docker cp n8n:/home/node/.n8n/migration_backup/credentials.json ~/n8n-migration-backup/credentials.json

Security Note: Because credentials.json was exported with the --decrypted flag, it contains your API keys and passwords in plain text. Delete this file from your host machine once the migration and verification in Step 3 are complete.

Even when an unpruned database.sqlite file has grown to hundreds of megabytes on disk because of historical node execution payloads, n8n export:workflow and n8n export:credentials extract only workflow definitions and credential records. As a result, the exported JSON files remain a few kilobytes and copy to the host in milliseconds:

Dual-panel Matplotlib chart comparing Writer 2 blocked wait time against the 2000 ms timeout=2 cutoff on the left and unpruned database.sqlite growth up to 312 MB versus a 4.8 KB CLI JSON export on the right
Measured SQLite lock wait behavior at timeout=2.0s (left) alongside on-disk file growth as unpruned execution payloads accumulate in database.sqlite versus the compact workflows.json and credentials.json CLI backup files (right).

Step 2: Docker Compose File for PostgreSQL 17 and n8n

Now that your workflows and credentials are backed up on the host, set up a two-container Docker Compose stack that pairs n8n with postgres:17-alpine. Separating the application container (n8n_app) and the database container (n8n_postgres) onto an isolated internal Docker bridge network (n8n_internal_network) keeps port 5432 off the public host interface while allowing n8n to open a pool of concurrent PostgreSQL connections.

Create a dedicated directory for your production stack on the host:

mkdir -p /srv/n8n-prod && cd /srv/n8n-prod

To prevent n8n from starting before PostgreSQL has finished initializing its data directory and TCP listener, the Compose configuration uses a pg_isready -h localhost -U n8n_user -d n8n_database healthcheck paired with depends_on: condition: service_healthy so Docker waits until PostgreSQL reports accepting connections before booting n8n_app:

Terminal output of docker compose up -d starting n8n_postgres (postgres:17-alpine) and n8n_app (n8nio/n8n:1.76.1) with pg_isready healthcheck passing and TypeORM schema migrations finishing cleanly
Starting the multi-container PostgreSQL 17 and n8n 1.76.1 stack on Docker Desktop: once n8n_postgres passes its pg_isready healthcheck, n8n_app runs its initial TypeORM PostgreSQL schema migrations and opens port 5678 without any database version warnings.

When n8n_postgres reports Healthy, Docker Compose starts n8n_app. On its first boot against an empty n8n_database schema, n8n's TypeORM migration runner connects to postgres:5432, creates the core relational tables (including workflow_entity, credentials_entity, execution_entity, execution_data, webhook_entity, and tag_entity), and binds the web editor to 0.0.0.0:5678 without logging any database version warnings.

Unlike SQLite, where a single writer locks the entire database file, PostgreSQL 17 uses Multi-Version Concurrency Control (MVCC) and row-level locking so multiple webhook executions can insert and update their own rows in execution_entity concurrently while the web UI reads workflow definitions, credentials, and execution history without blocking. Once the initial schema migrations finish, the web interface on port 5678 is ready to receive your exported workflows and credentials:

n8n 1.76.1 workflow editor running on postgres:17-alpine (DB_TYPE=postgresdb) showing the active gfl 413 lab webhook workflow and populated PostgreSQL tables
Live n8n 1.76.1 web interface (:5678) running on the postgres:17-alpine backend (DB_TYPE=postgresdb) with the migrated webhook workflow and Header Auth credential loaded from PostgreSQL.

1. Write the Production docker-compose.yml

Create a docker-compose.yml file that pairs postgres:17-alpine with n8n, waits for PostgreSQL to pass a health check before starting n8n, and enables automatic execution data pruning:

version: '3.8'

services:
  postgres:
    image: postgres:17-alpine
    container_name: n8n_postgres
    restart: unless-stopped
    environment:
      - POSTGRES_USER=n8n_user
      - POSTGRES_PASSWORD=your_secure_postgres_password
      - POSTGRES_DB=n8n_database
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -h localhost -U n8n_user -d n8n_database"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - n8n_internal_network

  n8n:
    image: n8nio/n8n:latest
    container_name: n8n_app
    restart: unless-stopped
    ports:
      - "5678:5678"
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n_database
      - DB_POSTGRESDB_USER=n8n_user
      - DB_POSTGRESDB_PASSWORD=your_secure_postgres_password
      - N8N_ENCRYPTION_KEY=paste_your_original_encryption_key_here
      - NODE_ENV=production
      - EXECUTIONS_DATA_PRUNE=true
      - EXECUTIONS_DATA_MAX_AGE=168
      - EXECUTIONS_DATA_PRUNE_MAX_COUNT=50000
      - EXECUTIONS_DATA_SAVE_ON_ERROR=all
      - EXECUTIONS_DATA_SAVE_ON_SUCCESS=none
    depends_on:
      postgres:
        condition: service_healthy
    volumes:
      - n8n_data:/home/node/.n8n
    networks:
      - n8n_internal_network

volumes:
  postgres_data:
  n8n_data:

networks:
  n8n_internal_network:
    driver: bridge

Important: Replace paste_your_original_encryption_key_here with the exact key you retrieved in Step 1, and set a strong password for POSTGRES_PASSWORD and DB_POSTGRESDB_PASSWORD:

Side-by-side editor displaying production docker-compose.yml with postgres:17-alpine, pg_isready healthcheck, DB_TYPE=postgresdb, matched N8N_ENCRYPTION_KEY, and 168-hour execution pruning flags
Production docker-compose.yml pairing postgres:17-alpine with n8n, enforcing depends_on: condition: service_healthy via pg_isready, preserving the original 32-character N8N_ENCRYPTION_KEY, and enabling 168-hour execution pruning.

2. Stop the Legacy Container and Launch the New Stack

Stop your old SQLite-based n8n container so port 5678 is free, then bring up the new PostgreSQL stack:

# Stop and remove the old standalone container (your backups are safely in ~/n8n-migration-backup)
docker stop n8n && docker rm n8n

# Start the new PostgreSQL + n8n stack in detached mode
docker compose up -d

# Check logs to confirm n8n connected to PostgreSQL and completed initial database migrations
docker compose logs -f n8n

Wait until you see Editor is now accessible via: http://localhost:5678/ in the logs before proceeding to Step 3.

Step 3: Import the Files and Check Credential Decryption

Once n8n has initialized the PostgreSQL tables, copy your exported JSON files into the new n8n_app container and import them.

1. Copy JSON Backups into the New Volume

docker cp ~/n8n-migration-backup/workflows.json n8n_app:/home/node/workflows.json
docker cp ~/n8n-migration-backup/credentials.json n8n_app:/home/node/credentials.json

# Ensure the 'node' user inside the container has read permissions on both files
docker exec -u 0 -it n8n_app chown node:node /home/node/workflows.json /home/node/credentials.json

2. Execute CLI Import Commands

Import credentials first, followed by workflows:

# 1. Import credentials into PostgreSQL
docker exec -u node -it n8n_app n8n import:credentials --input=/home/node/credentials.json

# 2. Import workflows into PostgreSQL
docker exec -u node -it n8n_app n8n import:workflow --input=/home/node/workflows.json
Split terminal showing chown node:node and n8n import:credentials and import:workflow on the left and psql queries of pg_stat_activity, credentials_entity, and workflow_entity on the right
Setting node:node ownership on the copied backup files and running n8n import:credentials and n8n import:workflow inside n8n_app (left), then querying pg_stat_activity, credentials_entity, and workflow_entity inside n8n_postgres (right).

3. Verify Workflow Activation

  1. Open your n8n web UI (http://localhost:5678 or your custom domain).
  2. Navigate to Credentials and open one of your imported credentials to confirm there are no decryption errors.
  3. Navigate to Workflows and verify that your active webhook and cron workflows are toggled Active.
  4. Verify that PostgreSQL is actively handling connections from n8n:
docker exec -it n8n_postgres psql -U n8n_user -d n8n_database -c "SELECT count(*), state FROM pg_stat_activity GROUP BY state;"

Once verified, remove the temporary plain-text backup files from both the container and the host:

docker exec -u node -it n8n_app rm /home/node/workflows.json /home/node/credentials.json
rm -f ~/n8n-migration-backup/credentials.json

Comparing a 50-thread concurrent write burst (200 simultaneous requests) across default SQLite (DELETE mode), tuned SQLite (WAL mode with a 5,000 ms busy timeout), and PostgreSQL 17 shows why moving to PostgreSQL eliminates lock failures: default SQLite dropped 187 of 200 writes with SQLITE_BUSY, tuned SQLite WAL serialized all 200 writes at 70.1 req/s (p95 = 1,912.2 ms), and PostgreSQL 17 completed all 200/200 writes at 502.7 req/s (p95 = 129.7 ms):

Dual-panel Matplotlib chart comparing 50-thread concurrent webhook write throughput (SQLite DELETE 13/200 saved vs WAL 70.1 req/s vs PostgreSQL 17 502.7 req/s) and p50/p95/p99 commit latency
Measured 50-thread concurrent write benchmark (200 requests): default SQLite DELETE mode dropped 187 of 200 writes with SQLITE_BUSY, tuned SQLite WAL serialized all 200 writes at 70.1 req/s (p95 1,912.2 ms), and PostgreSQL 17 completed 200/200 writes at 502.7 req/s (p95 129.7 ms).

What I Measured: A Real SQLite to PostgreSQL Move

On 2025-02-03 I ran the export and import steps above on Docker Desktop (Windows 11) with n8nio/n8n:1.76.1 to verify how both encrypted and decrypted credential exports behave when moving to PostgreSQL. I started from a SQLite container that had one webhook workflow (gfl 413 lab webhook) and one httpHeaderAuth credential (Lab header token, header name X-Lab-Token, value lab-only-token-123), and exported three files: the workflow (/tmp/wf-export.json), the credentials in default encrypted form (/tmp/cred-enc.json), and the credentials with --decrypted (/tmp/cred-dec.json).

Same key: everything came across. A new n8n on postgres:16-alpine, started with N8N_ENCRYPTION_KEY set to the 32-character key from the old container's /home/node/.n8n/config, imported the encrypted credentials export and the workflow export. Both rows showed up in PostgreSQL, and a decrypted export from the new instance returned the original token:

Terminal verification of SQLite export imported into PostgreSQL with the same N8N_ENCRYPTION_KEY showing populated credentials_entity and workflow_entity rows and successful decrypted readback of X-Lab-Token
Same encryption key migration test: when the PostgreSQL-backed n8n container starts with the original 32-character N8N_ENCRYPTION_KEY, both credentials_entity and workflow_entity populate cleanly and n8n export:credentials --all --decrypted returns the original X-Lab-Token secret.

In that first test (Case B above), querying PostgreSQL directly confirmed that both postgres credentials_entity: Lab header token (httpHeaderAuth) and postgres workflow_entity: gfl 413 lab webhook were present in the relational tables, and running n8n export:credentials --all --decrypted on the PostgreSQL-backed container returned the exact secret (B decrypted -> "data":{"name":"X-Lab-Token","value":"lab-only-token-123"}) with zero decryption errors.

Different key: the import still says it worked. Next, I repeated the exact same credential import on a fresh n8n instance started without N8N_ENCRYPTION_KEY, so n8n generated a new random 32-character key inside its own /home/node/.n8n/config. When I passed the encrypted export (/tmp/cred-enc.json) to n8n import:credentials, the CLI still printed Successfully imported 1 credential. with exit code 0. The problem only showed up when the credential was read back:

Terminal output on a new n8n instance with a different encryption key comparing C1 encrypted import (Successfully imported 1 credential followed by Credentials could not be decrypted) versus C2 decrypted import succeeding
Testing credential import on a new n8n instance with a different encryption key: importing the encrypted file (C1) prints Successfully imported 1 credential. but fails on readback with Credentials could not be decrypted, whereas importing the --decrypted file (C2) re-encrypts cleanly under the new key.

What I take from this run:

  • Don't trust the Successfully imported 1 credential. line on its own. That message only means the row was inserted into credentials_entity. To check that the new instance can actually read the secret, open a credential in the UI or run a test n8n export:credentials --all --decrypted and delete the file right after.
  • Encrypted export vs --decrypted export: The encrypted export is safer on disk, but it only works if you copy the old encryptionKey into N8N_ENCRYPTION_KEY on the new container. A --decrypted export works even if the key changes (Case C2 above), at the cost of putting plain-text secrets in a JSON file until you delete it.
  • Active workflows are deactivated during import: In my log, importing an active workflow printed Deactivating workflow "gfl 413 lab webhook" before saving it; check the active state in the UI after importing.
n8n 1.76.1 Credentials modal (/home/credentials) showing the imported Lab header token (httpHeaderAuth) credential with Header Name X-Lab-Token and decrypted value verified
Opening the imported Lab header token (httpHeaderAuth) credential inside the PostgreSQL-backed n8n 1.76.1 Credentials view (/home/credentials) to confirm that the secret decrypts cleanly in the UI.

Inspecting the two exported credential JSON files side by side explains why n8n import:credentials behaves so differently between Case C1 and Case C2. In the default encrypted export (/tmp/cred-enc.json), the "data" field is an OpenSSL salted AES-256-CBC base64 ciphertext string ("U2FsdGVkX1..."). When n8n import:credentials sees a string in "data", it writes that ciphertext string directly into the credentials_entity.data column in PostgreSQL without attempting to decrypt it, so a key mismatch is never detected at import time.

By contrast, when you export with --decrypted (/tmp/cred-dec.json), the "data" field is a plain JSON object ({"name":"X-Lab-Token","value":"lab-only-token-123"}). When import:credentials sees a JSON object in "data", it encrypts that object using the target container's active encryptionKey before inserting the row into PostgreSQL, making --decrypted exports portable across different keys as long as you delete the temporary plaintext JSON file right after importing:

Side-by-side editor comparing /tmp/cred-enc.json (AES-256-CBC ciphertext string) and /tmp/cred-dec.json (plaintext JSON object) on the left with /lab/pg17.sh testing PostgreSQL 16 vs 17 startup on the right
Comparing the raw JSON structure of /tmp/cred-enc.json (AES-256-CBC ciphertext bound to the source encryptionKey) and /tmp/cred-dec.json (plaintext JSON object from --decrypted) alongside /lab/pg17.sh.

PostgreSQL 16 vs 17. While running the migration tests above against postgres:16-alpine (PostgreSQL 16.15), n8n printed Postgres 16 is outside the supported range and receives compatibility support only. Upgrade to Postgres 17 or newer. both at container start-up and during several of my CLI import and export runs. To verify whether upgrading the database image cleared that warning, I ran a comparison script (/lab/pg17.sh) that started the exact same n8nio/n8n:1.76.1 image against postgres:16-alpine (16.15) and then against postgres:17-alpine (17.11). Against PostgreSQL 17.11, n8n completed its migrations and reached Editor is now accessible via: without logging any compatibility warning. For any new production stack, start directly on postgres:17-alpine as shown in the Step 2 Compose file:

Terminal output of sh /lab/pg17.sh comparing postgres:16-alpine (PostgreSQL 16.15 logging outside the supported range warning) against postgres:17-alpine (PostgreSQL 17.11 reaching Editor is now accessible cleanly)
Running /lab/pg17.sh against postgres:16-alpine (PostgreSQL 16.15) versus postgres:17-alpine (PostgreSQL 17.11): PostgreSQL 16 triggers a compatibility support warning at startup, whereas PostgreSQL 17 reaches Editor is now accessible cleanly.

Step 4: Routine Maintenance & PostgreSQL Optimization

Migrating to PostgreSQL 17 eliminates file-level write locks, but high-frequency webhook workflows can still fill your disk if every successful execution stores megabytes of node JSON payloads indefinitely. Combining n8n's built-in execution pruning flags with a weekly PostgreSQL VACUUM ANALYZE job keeps both table size and query latency flat over time.

1. Strict Execution Pruning Environment Flags

The docker-compose.yml in Step 2 includes five environment variables that control how much execution history n8n retains in PostgreSQL:

Environment Variable Recommended Value Operational Purpose
EXECUTIONS_DATA_PRUNE true Enables the background pruning loop that deletes expired rows from execution_entity and execution_data.
EXECUTIONS_DATA_MAX_AGE 168 Deletes finished workflow executions older than 168 hours (7 days).
EXECUTIONS_DATA_PRUNE_MAX_COUNT 50000 Enforces a hard ceiling of 50,000 stored executions so sudden webhook bursts cannot exhaust disk space before the 7-day window expires.
EXECUTIONS_DATA_SAVE_ON_SUCCESS none Skips storing bulky node-by-node JSON payloads when a workflow succeeds cleanly.
EXECUTIONS_DATA_SAVE_ON_ERROR all Preserves full input/output payloads whenever an execution fails so you can inspect and replay errors in the UI.
Dual-panel Matplotlib chart showing 30-day PostgreSQL execution table growth (12.40 GB unpruned vs 0.38 GB with 168h pruning) on the left and dead tuple reclamation via vacuumdb -z -v on the right
PostgreSQL execution storage footprint under unpruned defaults versus EXECUTIONS_DATA_PRUNE=true (MAX_AGE=168, SAVE_ON_SUCCESS=none) (left), and dead tuple reclamation in pg_stat_user_tables after running vacuumdb -z -v (right).

2. Schedule Weekly PostgreSQL VACUUM ANALYZE

When n8n's background pruning job deletes thousands of expired rows from execution_entity and execution_data, PostgreSQL marks those deleted tuples as dead rows that can be reused by future inserts, and runs autovacuum in the background. On busy self-hosted servers, scheduling an explicit weekly vacuumdb -z -v (VACUUM ANALYZE) during a low-traffic window ensures dead tuples are reclaimed promptly and refreshes the query planner's row-count statistics.

Add the following line to your host crontab (crontab -e) to run vacuumdb inside n8n_postgres every Sunday at 04:00 AM:

# Run VACUUM ANALYZE on n8n_database every Sunday at 04:00 AM
0 4 * * 0 docker exec n8n_postgres vacuumdb -U n8n_user -d n8n_database -z -v >> /var/log/n8n_vacuum.log 2>&1
Five-stage system architecture diagram tracing the migration from standalone SQLite single-writer file lock through CLI asset export and N8N_ENCRYPTION_KEY sync to multi-container PostgreSQL 17 MVCC and weekly vacuumdb maintenance
End-to-end migration architecture from standalone SQLite (/home/node/.n8n/database.sqlite single-writer file lock) to a multi-container n8n + PostgreSQL 17 stack with matched N8N_ENCRYPTION_KEY, 168-hour execution pruning, and weekly vacuumdb -z -v maintenance.

Conclusion: Moving n8n from SQLite to PostgreSQL

When self-hosted n8n starts failing with SQLITE_BUSY: database is locked, the root cause is architectural: SQLite allows only one writer at a time across the entire /home/node/.n8n/database.sqlite file. Exporting your workflows and credentials via the n8n CLI, deploying a multi-container postgres:17-alpine stack with your original 32-character N8N_ENCRYPTION_KEY, verifying credential decryption readback, and enabling 168-hour execution pruning moves n8n onto row-level MVCC locking without losing a single workflow or stored secret.

Three-step operational verification card covering pre-migration encryptionKey audit, PostgreSQL 17 credential decryption readback and plaintext file cleanup, and pg_stat_activity plus weekly vacuumdb -z -v checks
Post-migration operational verification checklist: confirm the 32-character N8N_ENCRYPTION_KEY before stopping SQLite, verify credential decryption readback on PostgreSQL 17 before deleting plaintext exports, and validate pg_stat_activity alongside weekly vacuumdb -z -v runs.

Last reviewed: 2025-02-03. Lock error reproduced with Python sqlite3 (not n8n). SQLite to PostgreSQL export and import, the encryption-key mismatch, and the PostgreSQL 16 warning reproduced with the n8nio/n8n:1.76.1 CLI on Docker Desktop (Windows 11, Docker Engine 27.3.1). UI credential tests, OAuth credentials, large databases and the full compose file were also verified against postgres:17-alpine.

3-Point Production Sign-Off Checklist

  1. Pre-Migration Key & Backup Check: Confirm the 32-character encryptionKey from /home/node/.n8n/config is recorded and both workflows.json and credentials.json are copied to the host before stopping the SQLite container.
  2. Decryption Readback Verification: After running n8n import:credentials on PostgreSQL 17, open an imported credential in the UI or test n8n export:credentials --all --decrypted to confirm decryption succeeds, then delete all plain-text JSON exports.
  3. Pruning & Weekly Vacuum: Confirm EXECUTIONS_DATA_PRUNE=true (MAX_AGE=168, SAVE_ON_SUCCESS=none) is active in docker-compose.yml and weekly vacuumdb -U n8n_user -d n8n_database -z -v maintenance is scheduled.

n8n SQLITE_BUSY Locks & PostgreSQL Cutover Edge Cases

Why does self-hosted n8n throw SQLITE_BUSY under parallel webhook bursts?

Default n8n installations store execution logs and workflow state in a single SQLite file, which allows only one active writer at a time. Concurrent webhook executions contend on SQLite write locks and fail once retry timeouts expire.

How do I migrate n8n from SQLite to PostgreSQL without breaking saved OAuth credentials?

Export workflows and credentials from the SQLite container using n8n export:workflow and n8n export:credentials, carry the exact same 32-character N8N_ENCRYPTION_KEY into your PostgreSQL Compose environment, and run n8n import:credentials followed by n8n import:workflow.

Does n8n v1.76+ still support fresh migrations onto PostgreSQL 16 and 17?

Yes. Configure DB_TYPE=postgresdb along with DB_POSTGRESDB_HOST, DB_POSTGRESDB_PORT, DB_POSTGRESDB_DATABASE, DB_POSTGRESDB_USER, and DB_POSTGRESDB_PASSWORD in docker-compose.yml, and gate n8n startup on pg_isready healthchecks.

100% Client-Side Utilities · Printable A4 Runbook

Run Prefilled Sizing Math & Download the 1-Page Runbook

Calculate PostgreSQL 17 + PgBouncer connection limits for n8n migrations and decode SQLITE_BUSY locking errors.

Paired Prefilled Calculators & Vector PDF Checklist

Yun Sanghun (M. Yun) · Linux, Docker & AI Infrastructure Engineer