Skip to content

数据库环境变量(Database environment variables)#

File-based configuration

You can add _FILE to individual variables to provide their configuration in a separate file. Refer to Keeping sensitive data in separate files for more details.

默认情况下,n8n 使用 SQLite。n8n 也支持 PostgreSQL。n8n 在 v1.0 中不再支持 MySQL 和 MariaDB

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

本页面概述了用于配置自托管 n8n 实例所选数据库的环境变量。

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

变量 类型 默认值 描述
DB_TYPE
/_FILE
枚举字符串:
sqlite, postgresdb
sqlite 使用的数据库。
DB_TABLE_PREFIX * - 用于表名的前缀。
DB_PING_INTERVAL_SECONDS 数字 2 检查数据库连接是否仍然存活的间隔时间(秒)。

PostgreSQL#

Variable Type Default Description
DB_POSTGRESDB_DATABASE
/_FILE
String n8n The name of the PostgreSQL database.
DB_POSTGRESDB_HOST
/_FILE
String localhost The PostgreSQL host.
DB_POSTGRESDB_PORT
/_FILE
Number 5432 The PostgreSQL port.
DB_POSTGRESDB_USER
/_FILE
String postgres The PostgreSQL user.
DB_POSTGRESDB_PASSWORD
/_FILE
String - The PostgreSQL password.
DB_POSTGRESDB_POOL_SIZE
/_FILE
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.
DB_POSTGRESDB_CONNECTION_TIMEOUT
/_FILE
Number 20000 Postgres connection timeout (ms).
DB_POSTGRESDB_IDLE_CONNECTION_TIMEOUT
/_FILE
Number 30000 Amount of time before an idle connection is eligible for eviction for being idle.
DB_POSTGRESDB_SCHEMA
/_FILE
String public The PostgreSQL schema.
DB_POSTGRESDB_SSL_ENABLED
/_FILE
Boolean false Whether to enable SSL. Automatically enabled if DB_POSTGRESDB_SSL_CA, DB_POSTGRESDB_SSL_CERT or DB_POSTGRESDB_SSL_KEY is defined.
DB_POSTGRESDB_SSL_CA
/_FILE
String - The PostgreSQL SSL certificate authority.
DB_POSTGRESDB_SSL_CERT
/_FILE
String - The PostgreSQL SSL certificate.
DB_POSTGRESDB_SSL_KEY
/_FILE
String - The PostgreSQL SSL key.
DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED
/_FILE
Boolean true If n8n should reject unauthorized SSL connections (true) or not (false).

SQLite#

变量 类型 默认值 描述
DB_SQLITE_POOL_SIZE 数字 0 控制是否以 WAL 模式回滚日志模式 打开 SQLite 文件。当设置为零时,使用回滚日志模式。当大于零时,使用 WAL 模式,值决定配置的并行 SQL 读取连接数。WAL 模式比回滚日志模式性能更高,更可靠。
DB_SQLITE_VACUUM_ON_STARTUP 布尔值 false 启动时运行 VACUUM 操作以重建数据库。可以减少文件大小并优化索引。此操作运行时间较长,会阻塞,并增加启动时间。