部署与运维

Database

By default, n8n uses SQLite. n8n also supports PostgreSQL. n8n deprecated support for MySQL and MariaDB in v1.0.

This page outlines environment variables to configure your chosen database for your self-hosted n8n instance.

Variable Type Default Description
<code>DB\_TYPE</code>
/<code>\_FILE</code> Enum string:
<code>sqlite</code>, <code>postgresdb</code> sqlite The database to use.
DB_TABLE_PREFIX \* - Prefix to use for table names.
DB_PING_INTERVAL_SECONDS Number 2 How often, in seconds, n8n pings the database to check that the connection is still alive.
DB_PING_TIMEOUT_MS Number 5000 How long, in milliseconds, n8n waits for a single ping to respond before counting it as a failure. Falls back to the deprecated N8N_DB_PING_TIMEOUT if that's set.
DB_PING_MAX_FAILURES_BEFORE_RECOVERY Number 3 How many pings in a row must fail before n8n treats the connection as lost and starts recovery.
DB_RECOVERY_BACKOFF_MIN_MS Number 1000 How long, in milliseconds, n8n waits before its first recovery attempt. Each retry waits longer (exponential backoff).
DB_RECOVERY_BACKOFF_MAX_MS Number 30000 The longest, in milliseconds, n8n waits between recovery attempts. This caps the backoff. Must be greater than or equal to DB_RECOVERY_BACKOFF_MIN_MS.
DB_CONNECTION_ACQUISITION_TIMEOUT_MS Number 30000 How long, in milliseconds, a query waits while recovery is in progress before failing fast with an error. Set to 0 to wait indefinitely. Applies to PostgreSQL only.

PostgreSQL

Variable Type Default Description
<code>DB\_POSTGRESDB\_DATABASE</code>
/<code>\_FILE</code> String n8n The name of the PostgreSQL database.
<code>DB\_POSTGRESDB\_HOST</code>
/<code>\_FILE</code> String localhost The PostgreSQL host.
<code>DB\_POSTGRESDB\_PORT</code>
/<code>\_FILE</code> Number 5432 The PostgreSQL port.
<code>DB\_POSTGRESDB\_USER</code>
/<code>\_FILE</code> String postgres The PostgreSQL user.
<code>DB\_POSTGRESDB\_PASSWORD</code>
/<code>\_FILE</code> String - The PostgreSQL password.
<code>DB\_POSTGRESDB\_POOL\_SIZE</code>
/<code>\_FILE</code> Number 2 Control how many parallel open Postgres connections n8n should have. Increasing it may help with resource utilization, but too many connections may degrade performance.
<code>DB\_POSTGRESDB\_CONNECTION\_TIMEOUT</code>
/<code>\_FILE</code> Number 20000 Postgres connection timeout (ms).
<code>DB\_POSTGRESDB\_IDLE\_CONNECTION\_TIMEOUT</code>
/<code>\_FILE</code> Number 30000 Amount of time before an idle connection is eligible for eviction for being idle.
<code>DB\_POSTGRESDB\_MAX\_CONNECTION\_LIFETIME\_MS</code>
/<code>\_FILE</code> Number 3600000 How long, in milliseconds, n8n keeps a pooled connection before recycling it. Recycling old connections helps avoid stale connections that the database or network dropped without n8n noticing. The default is one hour. Set to 0 to disable recycling.
<code>DB\_POSTGRESDB\_KEEP\_ALIVE</code>
/<code>\_FILE</code> Boolean true Whether to enable TCP keep-alive on connections. Keep-alive lets n8n notice a dead connection without having to run a query first.
<code>DB\_POSTGRESDB\_KEEP\_ALIVE\_INITIAL\_DELAY\_MS</code>
/<code>\_FILE</code> Number 10000 How long, in milliseconds, n8n waits before sending the first TCP keep-alive probe on a connection.
<code>DB\_POSTGRESDB\_SCHEMA</code>
/<code>\_FILE</code> String public The PostgreSQL schema.
<code>DB\_POSTGRESDB\_SSL\_ENABLED</code>
/<code>\_FILE</code> Boolean false Whether to enable SSL. Automatically enabled if DB_POSTGRESDB_SSL_CA, DB_POSTGRESDB_SSL_CERT or DB_POSTGRESDB_SSL_KEY is set to a non-empty value, or if DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED is set to false.
<code>DB\_POSTGRESDB\_SSL\_CA</code>
/<code>\_FILE</code> String - The PostgreSQL SSL certificate authority.
<code>DB\_POSTGRESDB\_SSL\_CERT</code>
/<code>\_FILE</code> String - The PostgreSQL SSL certificate.
<code>DB\_POSTGRESDB\_SSL\_KEY</code>
/<code>\_FILE</code> String - The PostgreSQL SSL key.
<code>DB\_POSTGRESDB\_SSL\_REJECT\_UNAUTHORIZED</code>
/<code>\_FILE</code> Boolean true If n8n should reject unauthorized SSL connections (true) or not (false).

SQLite

Variable Type Default Description
DB_SQLITE_POOL_SIZE Number 0 Controls whether to open the SQLite file in WAL mode or rollback journal mode. Uses rollback journal mode when set to zero. When greater than zero, uses WAL mode with the value determining the number of parallel SQL read connections to configure. WAL mode is much more performant and reliable than the rollback journal mode.
DB_SQLITE_VACUUM_ON_STARTUP Boolean false Runs VACUUM operation on startup to rebuild the database. Reduces file size and optimizes indexes. This is a long running blocking operation and increases start-up time.

How database connection recovery works

n8n keeps checking that it can still reach your database. If the connection drops, for example after a database restart or a network blip, n8n can repair it on its own instead of staying broken until you restart n8n.

Here's the cycle the variables on this page control:

  1. Every DB_PING_INTERVAL_SECONDS, n8n sends a ping. Each ping has DB_PING_TIMEOUT_MS to respond.
  2. Once DB_PING_MAX_FAILURES_BEFORE_RECOVERY pings fail in a row, n8n treats the connection as lost.
  3. n8n then rebuilds the connection, retrying with a growing wait between attempts that starts at DB_RECOVERY_BACKOFF_MIN_MS and never exceeds DB_RECOVERY_BACKOFF_MAX_MS.
  4. On PostgreSQL, while recovery is in progress, any new query waits up to DB_CONNECTION_ACQUISITION_TIMEOUT_MS for the connection to come back, then fails with an error rather than hanging.

官方原文和授权

本页来自 N8N 英文官方网站固定快照,并转换成 xueai 静态页面。内容以 N8N 持续更新的官方页面为准。

来源、授权与修改

本站保留许可证、固定提交号、社区作者和修改说明,不代表 n8n 对本站背书。

查看许可证查看来源和修改说明