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.

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:试用版、入门版和专业版套餐,以及旧版企业版套餐

¥SQLite: Trial, Starter, and Pro plans, as well as legacy Enterprise plans

  • PostgreSQL:仅限企业扩展计划

¥PostgreSQL: Enterprise Scaling plans only

已共享设置#

¥Shared settings

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

¥The following environment variables get used by all databases:

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

¥DB_TABLE_PREFIX (default: -) - Prefix for table names

PostgresDB#

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

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

  • DB_TYPE=postgresdb

  • DB_POSTGRESDB_DATABASE(默认值:'n8n')

¥DB_POSTGRESDB_DATABASE (default: 'n8n')

  • DB_POSTGRESDB_HOST(默认值:'localhost')

¥DB_POSTGRESDB_HOST (default: 'localhost')

  • DB_POSTGRESDB_PORT(默认值:5432)

¥DB_POSTGRESDB_PORT (default: 5432)

  • DB_POSTGRESDB_USER(默认值:'postgres')

¥DB_POSTGRESDB_USER (default: 'postgres')

  • DB_POSTGRESDB_PASSWORD(默认值:空)

¥DB_POSTGRESDB_PASSWORD (default: empty)

  • DB_POSTGRESDB_SCHEMA(默认值:'public')

¥DB_POSTGRESDB_SCHEMA (default: 'public')

  • DB_POSTGRESDB_SSL_CA(默认值:undefined):用于验证连接的服务器 CA 证书的路径(不支持机会加密)。

¥DB_POSTGRESDB_SSL_CA (default: undefined): Path to the server's CA certificate used to validate the connection (opportunistic encryption isn't supported)

  • DB_POSTGRESDB_SSL_CERT(默认值:undefined):客户端 TLS 证书的路径。

¥DB_POSTGRESDB_SSL_CERT (default: undefined): Path to the client's TLS certificate

  • DB_POSTGRESDB_SSL_KEY(默认值:undefined):与该证书对应的客户端私钥的路径。

¥DB_POSTGRESDB_SSL_KEY (default: undefined): Path to the client's private key corresponding to the certificate

  • DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED(默认值:true):如果验证失败的 TLS 连接应被拒绝

¥DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED (default: true): If TLS connections that fail validation should be rejected

 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 连接

¥Not declaring (default): Connect with SSL=off

  • 仅声明 CA 和未授权标志:连接到 SSL=on 并验证服务器签名

¥Declaring only the CA and unauthorized flag: Connect with SSL=on and verify the server's signature

  • 声明 _{CERT,KEY} 和上述内容:使用客户端 TLS 身份验证的证书和密钥

¥Declaring _{CERT,KEY} and the above: Use the certificate and key for client TLS authentication

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