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.

Short Answer (Immediate 3-Step Recovery):
- Export workflows and credentials via n8n CLI before you change anything: Record the 32-character
encryptionKeyinside/home/node/.n8n/config, then runn8n export:workflow --allandn8n export:credentials --all --decryptedas thenodeuser and copy both JSON files to the host.- Switch from standalone SQLite to a multi-container PostgreSQL 17 Docker Compose stack: Deploy
postgres:17-alpinealongsiden8nio/n8n:1.76.1withDB_TYPE=postgresdb, apg_isreadyhealthcheck gate, and the originalN8N_ENCRYPTION_KEY.- Import your assets and enforce automatic execution pruning: Run
n8n import:credentialsandn8n import:workflow, verify credential decryption readback, delete the plaintext JSON export, and setEXECUTIONS_DATA_PRUNE=truewithEXECUTIONS_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:

execution_entity inserts until SQLITE_BUSY fires, whereas PostgreSQL 17 MVCC with PgBouncer transaction pooling handles concurrent writes without file locks.
- 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, orDELETE). 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 raisesSQLITE_BUSY: database is locked. - 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_entityandexecution_datatables. Without automatic pruning,database.sqlitegrows to several gigabytes. Updating indexes on a multi-gigabyte single-file database makes each write take longer, which makes lock timeouts happen more often. - Not a cause of webhook 413 errors: A locked SQLite database causes executions to fail or hang, not
413 Payload Too Largeresponses; 413 comes from a reverse proxy (e.g. Nginxclient_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:

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:

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/

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:

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:

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:

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:

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

3. Verify Workflow Activation
- Open your n8n web UI (
http://localhost:5678or your custom domain). - Navigate to Credentials and open one of your imported credentials to confirm there are no decryption errors.
- Navigate to Workflows and verify that your active webhook and cron workflows are toggled Active.
- 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):

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:

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:

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 intocredentials_entity. To check that the new instance can actually read the secret, open a credential in the UI or run a testn8n export:credentials --all --decryptedand delete the file right after. - Encrypted export vs
--decryptedexport: The encrypted export is safer on disk, but it only works if you copy the oldencryptionKeyintoN8N_ENCRYPTION_KEYon the new container. A--decryptedexport 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.

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:

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:

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

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

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.

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
- Pre-Migration Key & Backup Check: Confirm the 32-character
encryptionKeyfrom/home/node/.n8n/configis recorded and bothworkflows.jsonandcredentials.jsonare copied to the host before stopping the SQLite container. - Decryption Readback Verification: After running
n8n import:credentialson PostgreSQL 17, open an imported credential in the UI or testn8n export:credentials --all --decryptedto confirm decryption succeeds, then delete all plain-text JSON exports. - Pruning & Weekly Vacuum: Confirm
EXECUTIONS_DATA_PRUNE=true(MAX_AGE=168,SAVE_ON_SUCCESS=none) is active indocker-compose.ymland weeklyvacuumdb -U n8n_user -d n8n_database -z -vmaintenance 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.
Run Prefilled Sizing Math & Download the 1-Page Runbook
Calculate PostgreSQL 17 + PgBouncer connection limits for n8n migrations and decode SQLITE_BUSY locking errors.