Skip to content

支持的数据库(Supported databases)#

默认情况下,n8n 使用 SQLite 来保存凭证、历史执行记录和工作流。n8n 也支持 PostgresDB(仅支持 正在维护的版本)。

🌐 By default, n8n uses SQLite to save credentials, past executions, and workflows. n8n also supports PostgresDB (only actively maintained versions).

n8n 安装的数据库类型(Database type by n8n installation)#

使用的数据库类型取决于你的 n8n 安装:

🌐 The database type used varies depending on your n8n installation:

自托管 n8n(Self-hosted n8n)#

默认情况下,自托管安装使用 SQLite。你可以通过设置相应的环境变量来选择配置 PostgreSQL(请参阅 PostgresDB 配置)。

🌐 By default, self-hosted installations use SQLite. You can optionally configure PostgreSQL by setting the appropriate environment variables (see PostgresDB configuration).

n8n 云(n8n Cloud)#

n8n Cloud 安装会根据你的套餐级别使用不同的数据库:

🌐 n8n Cloud installations use different databases depending on your plan tier:

  • SQLite:试用版、入门版和专业版计划,以及旧版企业计划
  • PostgreSQL:仅限企业扩展计划

已共享设置(Shared settings)#

所有数据库都会使用以下环境变量:

🌐 The following environment variables get used by all databases:

  • DB_TABLE_PREFIX(默认:-)- 表名称前缀

Postgres数据库(PostgresDB)#

要使用 PostgresDB 作为数据库,你可以提供以下环境变量:

🌐 To use PostgresDB as the database, you can provide the following environment variables:

  • DB_TYPE=postgresdb
  • DB_POSTGRESDB_DATABASE(默认值:'n8n')
  • DB_POSTGRESDB_HOST(默认值:'localhost')
  • DB_POSTGRESDB_PORT(默认值:5432)
  • DB_POSTGRESDB_USER(默认值:'postgres')
  • DB_POSTGRESDB_PASSWORD(默认:空)
  • DB_POSTGRESDB_SCHEMA(默认值:'public')
  • DB_POSTGRESDB_SSL_CA(默认值:未定义):用于验证连接的服务器 CA 证书的路径(不支持机会加密)
  • DB_POSTGRESDB_SSL_CERT(默认值:未定义):客户端 TLS 证书的路径
  • DB_POSTGRESDB_SSL_KEY(默认值:未定义):客户端证书对应的私钥路径
  • DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED(默认:true):如果 TLS 连接验证失败,是否应被拒绝
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
export DB_TYPE=postgresdb
export DB_POSTGRESDB_DATABASE=n8n
export DB_POSTGRESDB_HOST=postgresdb
export DB_POSTGRESDB_PORT=5432
export DB_POSTGRESDB_USER=n8n
export DB_POSTGRESDB_PASSWORD=n8n
export DB_POSTGRESDB_SCHEMA=n8n

# optional:
export DB_POSTGRESDB_SSL_CA=$(pwd)/ca.crt
export DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED=false

n8n start

必填权限(Required permissions)#

n8n 需要创建和修改其使用的表的模式。

🌐 n8n needs to create and modify the schemas of the tables it uses.

推荐权限:

🌐 Recommended permissions:

1
2
3
CREATE DATABASE n8n-db;
CREATE USER n8n-user WITH PASSWORD 'random-password';
GRANT ALL PRIVILEGES ON DATABASE n8n-db TO n8n-user;

传输层安全协议(TLS)#

你可以选择以下配置:

🌐 You can choose between these configurations:

  • 未声明(默认):使用 SSL=off 连接
  • 仅声明 CA 和未授权标志:使用 SSL=on 连接并验证服务器的签名
  • 声明 _{CERT,KEY} 及以上内容:使用证书和密钥进行客户端 TLS 身份验证

SQLite#

这是未定义任何内容时使用的默认数据库。

🌐 This is the default database that gets used if nothing is defined.

数据库文件位于: ~/.n8n/database.sqlite

🌐 The database file is located at: ~/.n8n/database.sqlite