Skip to main content
This guide explains how to configure the database for Dify Enterprise. Dify Enterprise supports both Docker Compose and Helm Chart deployment methods and is compatible with PostgreSQL, MySQL, and TiDB database engines.

Architecture Overview

Dify Enterprise uses a single-instance, multi-database architecture. All community and enterprise services connect to the same database server, but each service uses its own independent database:
Note: Community services and enterprise services use different environment variable naming conventions, but they must point to the same database instance.

Docker Compose Configuration

In a Docker Compose deployment, configure the database by modifying the .env file.

1. Environment Variable Reference

Community Services (Dify API / Worker)

Enterprise Services

2. External Database Mode

If using an external database (such as AWS RDS, Alibaba Cloud RDS, or TiDB Cloud), follow these steps:
  1. Modify .env environment variables: Point the variables above to your external database address.
  2. Adjust COMPOSE_PROFILES (Optional): Remove the database type (e.g., postgresql) from COMPOSE_PROFILES to prevent the built-in database container from starting.
  3. Manually create databases: Before starting Dify, you must manually create the required databases in the external instance (see the Database Initialization section below).

Helm Chart Configuration

In a Helm deployment, configure the database via values.yaml.

1. Internal Database Mode (PostgreSQL)

By default, Helm will start a built-in PostgreSQL container.
Connect to an external PostgreSQL, MySQL, or TiDB.

Database Initialization

1. Built-in Database Mode

When using the built-in database for Docker Compose or Helm, the system automatically executes initialization scripts (such as dify-postgresql-init.sql) to create the enterprise and audit databases.

2. External Database Mode (Manual Creation)

When using an external database, you must manually create the following databases before starting Dify:

PostgreSQL

MySQL / TiDB


FAQ

Why are there two sets of database variables?

Community services (Python) and enterprise services (Go) use different configuration standards. When configuring, ensure both sets of variables point to the same database instance.

Which engine should I choose for TiDB?

TiDB is compatible with the MySQL protocol. When configuring, set both DB_TYPE and DB_ENGINE to mysql, and point the port to TiDB’s service port (default 4000).

How do I enable SSL/TLS connections?

  • Docker Compose: Set DB_SSL_MODE="require". For MySQL/TiDB, also set DB_TLS="true".
  • Helm: Configure the corresponding sslMode or tls fields under dialectOptions.