Deploy Dify with existing database instances
If you already have database resources such as ApsaraDB RDS for PostgreSQL, Redis, or AnalyticDB for PostgreSQL, you can reuse these existing instances when you deploy a Dify instance. This approach helps reduce costs and simplify the network architecture.
Scenarios
Deploying a Dify instance with existing databases is applicable in the following scenarios:
-
You already have ApsaraDB RDS for PostgreSQL, Redis, or AnalyticDB for PostgreSQL instances and want to reuse existing resources to reduce costs.
-
You need to deploy the Dify instance in a specific VPC to enable communication with existing business systems.
-
You have specific requirements for database instance specifications, versions, or configurations, and need to manage the database resources yourself.
If you do not have existing database resources, we recommend that you use the Deploy Dify in One Click feature. The system automatically creates all required database resources. For more information, see Deploy a Dify instance in one click.
Supported database versions
When you deploy a Dify instance with existing databases, the databases must meet the following version requirements:
|
Database type |
Purpose |
Supported version |
|
ApsaraDB RDS for PostgreSQL |
Metadata storage (application configurations, user information, and more) |
14.0 or later |
|
Tair (Redis® OSS-Compatible) |
Cache acceleration and session management |
6.0 or later |
|
AnalyticDB for PostgreSQL |
Vector storage and semantic retrieval for the knowledge base |
Versions that support vector search |
The vector database is optional. If you do not need the knowledge base feature of Dify, you can skip the configuration of an AnalyticDB for PostgreSQL instance and add it later when needed.
Prerequisites
-
You have an Alibaba Cloud account that has completed identity verification.
-
Your account has been granted the following permission policies: AliyunRDSFullAccess, AliyunKvstoreFullAccess, AliyunVPCFullAccess, AliyunECSFullAccess, AliyunComputeNestUserFullAccess, AliyunROSFullAccess, and AliyunDMSFullAccess.
-
You have created ApsaraDB RDS for PostgreSQL and Redis instances that meet the version requirements, and the instances are in the Running state.
-
The existing database instances and the Dify instance to be deployed are in the same VPC to ensure network connectivity.
-
The IP address or security group of the ECS instance where Dify is deployed has been added to the whitelists of the database instances.
Procedure
-
Log on to the AI-Native Database Service console.
-
On the Dify tab, click Deploy Dify in One Click. You are redirected to the deployment configuration page of Compute Nest.
-
Configure Billing Method.
-
Pay-as-you-go: Billed by actual usage duration. Suitable for development, testing, or short-term use.
-
Subscription: A prepaid billing method suitable for long-term production environments.
-
-
Select a Deployment Region. Make sure that the selected region is the same as the region of your existing database instances.
-
Configure Network Resources. Select the VPC and vSwitch where your existing database instances are located to ensure that the Dify instance and the existing database instances are in the same VPC.
-
Configure Metadata Database. In the database configuration section, select Use Existing Instance, and then select your ApsaraDB RDS for PostgreSQL instance from the drop-down list.
-
Select the target ApsaraDB RDS for PostgreSQL instance.
-
Enter the Privileged Account and Password of the database. The system uses this account to automatically create the databases and table structures required by Dify.
ImportantMake sure that the database account has privileged permissions (the permissions to create databases and users). Otherwise, the Dify instance initialization will fail.
-
-
Configure Redis Cache. Select Use Existing Instance, select your Redis instance from the drop-down list, and enter the Redis connection password.
-
(Optional) Configure Vector Database. To use the knowledge base feature of Dify, select Use Existing Instance, select your AnalyticDB for PostgreSQL instance from the drop-down list, and enter the database account and password. If you do not need this feature, skip this step.
-
Confirm the configuration information and estimated costs, read and select the service agreement, and then click Create Now.
-
Wait for the deployment to complete. The deployment typically takes 10 to 15 minutes. You can view the deployment progress in the Compute Nest console.
Result
After the deployment is complete:
-
The Dify instance is automatically registered in the AI-Native Database Service console. You can view and manage the instance on the Dify tab on the Agent Developer Platform > Custom Development page.
-
The existing database instances that you selected are registered in the console and associated with the Dify instance for unified O&M management.
-
The Dify instance provides a dedicated access URL. You can use this URL to access the Dify console and start creating AI applications.
FAQ
What do I do if Dify cannot connect to the existing database?
Verify the following in order: whether the Dify instance and the database instance are in the same VPC; whether the IP address of the ECS instance where Dify is deployed has been added to the whitelist of the database instance; whether the database account and password are correct; and whether the database instance is in the Running state.
What do I do if the existing database version does not meet the requirements?
We recommend that you upgrade the database instance to a supported version, or create a new database instance that meets the version requirements. For more information about how to upgrade ApsaraDB RDS for PostgreSQL, see Upgrade the major engine version.