Prerequisites for using existing database instances

Updated at:
Copy as MD

This topic describes how to deploy Dify with existing instances. This optional approach is for users who have the required instance resources and want a flexible deployment. You must purchase and prepare these resources in advance.

Required resources and their roles

Note
  • In this example, the metadata database is ApsaraDB RDS for PostgreSQL, and the vector database is AnalyticDB for PostgreSQL. The following instructions are based on this configuration.

  • All four resources must be in the same region. For example, if your ApsaraDB RDS for PostgreSQL instance is in the China (Beijing) region, all other resources must also be in that region.

  • ApsaraDB RDS for PostgreSQL: Stores Dify's structured data and core business data, such as permission configurations and user information, and provides transaction support.

  • Tair (Redis OSS-compatible): Handles caching, session management, and asynchronous task processing to improve the system's real-time performance and concurrency.

  • Vector engine (for example, AnalyticDB for PostgreSQL): Stores vector data, such as from a knowledge base.

  • OSS: Stores Dify's unstructured data, such as knowledge base files and images.

1. Purchase ApsaraDB RDS for PostgreSQL and add to DMS

1.1 Purchase ApsaraDB RDS for PostgreSQL

  1. Navigate to the RDS purchase page.

  2. Select the region for the instance, and configure its edition, storage type, and instance type.

    In the Engine section, select PostgreSQL and set the Version to 17. The Edition supports Basic Edition, High-availability Edition, and Cluster Edition. The Storage Type supports ESSD PL1 and General-purpose Cloud Disks. You can also configure options such as Enable Babelfish, Cloud Disk Encryption, I/O Burst, and Data Archiving as needed. Example configuration: For Instance Type, select 4 vCPU, 8 GiB Memory, and set Storage to 100 GB. You can also choose options with higher specifications.

    On the General-purpose tab, select the specification with the code pg.n2.4c.1m (maximum connections: 800).

  3. Follow the prompts to complete the purchase.

1.2 Configure instance

1.2.1 Create a database account

  1. Navigate to the RDS instance list.

  2. Click the name of the target instance and navigate to the Account Management page to create a database account. For more information, see Create databases and accounts.

    Click Create Account. In the panel that appears on the right, enter a Database Account (for example, dify_test), select Privileged Account for Account Type, set a password, and then click OK.

1.2.2 Create databases

Click the name of the target instance and navigate to the Database Management page to create two databases named dify and dify_plugin. For more information, see Create databases and accounts.

In the Create Database panel, set Supported Character Set to UTF8, Collate to C, and Ctype to en_US.utf8. For Authorized Account, select dify_test(Super), and then click Create.

1.2.3 Configure whitelists

Click the name of the target instance and navigate to the Whitelists and Security Groups page. Add the IPv4 CIDR block of the vSwitch in the Dify VPC to the instance's whitelist. For more information, see Set whitelists and Create and manage vSwitches.

Click the Whitelist Settings tab, and then click Add Whitelist Group. In the dialog box that appears, enter a Group Name (for example, vpc_whitelist) and the Group Whitelist (the IPv4 CIDR block of the vSwitch), and then click OK.

1.3 Add instance to DMS

  1. Log in to DMS 5.0.

  2. Move the pointer over the 2023-01-28_15-57-17.png icon in the upper-left corner of the DMS console and choose All Features > Data Assets > Instances.

    Note

    If you use the DMS console in normal mode, choose Data Assets > Instances in the top navigation bar.

  3. On the Instance Management page, click Add and configure the instance information.

    Note

    For Access Method, you must select Security-managed - Manual.

    In the Add Instance form, set Database Type to PostgreSQL. Select the target Instance Region. For Entry Mode, select Instance ID and enter the corresponding instance ID. For DATABASE, enter the target database name (for example, Dify). Enter the Database Account and Database Password. Click Test Connection to verify the connection, and then click Submit.

  4. After completing the configuration, click Submit.

2. Purchase Tair (Redis OSS-compatible) and add to DMS

2.1 Purchase Tair (Redis OSS-compatible)

  1. Navigate to the .

  2. Select the instance parameters.

    1. Set Product to Redis Open-Source Edition and Deployment Mode to Cloud-native.

      Set Billing Method to Subscription.

    2. Set Series to Standard Version.

    3. Set Major Version to Redis 6.0 and Architecture Type to Non-Cluster.

      Set Instance Type to High-availability.

    4. Configure other parameters.

  3. For more information, see Step 1: Create an instance.

2.2 Configure instance

2.2.1 Create a database account

  1. Navigate to the instance list.

  2. Click the name of the target instance and navigate to the Account Management page to create a database account named dify_user. Ensure that the password for the dify_user account is the same as the password for the default account. For more information, see Create and manage accounts.

2.2.2 Configure whitelists

Click the name of the target instance and navigate to the whitelist settings page. Add the IP address of the vSwitch in the Dify VPC to the instance's whitelist. For more information, see Set IP whitelists and Create and manage vSwitches.

In the navigation pane on the left, click Whitelist Settings. Click Add Whitelist Group, enter dify_whitelist for Group Name, select Manual Add for Add Method, and enter the corresponding vSwitch IP address in the Group Whitelist field.

2.3 Add instance to DMS

  1. Log in to DMS 5.0.

  2. Move the pointer over the 2023-01-28_15-57-17.png icon in the upper-left corner of the DMS console and choose All Features > Data Assets > Instances.

    Note

    If you use the DMS console in normal mode, choose Data Assets > Instances in the top navigation bar.

  3. On the Instance Management page, click Add and configure the instance information.

    Note

    For Access Method, you must select Security-managed - Manual.

    In the Add Instance dialog box, set Database Type to Redis. Select the Instance Region. For Entry Mode, select Instance ID and select the target instance. Enter the Database Account and Database Password.

  4. After completing the configuration, click Submit.

3. Purchase a vector engine and add to DMS

Dify on DMS supports several vector engines, including AnalyticDB for PostgreSQL, AnalyticDB for MySQL, PolarDB for PostgreSQL, PG Vector, and Lindorm. The following section provides an example of purchasing an AnalyticDB for PostgreSQL instance and adding it to DMS.

3.1 Purchase AnalyticDB for PostgreSQL

  1. Navigate to the .

  2. Configure the instance resource type, node specifications, and vector engine optimization.

    Note

    Enable vector engine optimization for the instance to ensure all knowledge base features are available. For more information about the vector engine, see Enable or disable vector search engine optimization.

    Other parameters to configure include Engine Version (6.0 Standard or 7.0 Standard), Product Type, Instance Series (High-Performance (Basic) or High-availability), Master Resources, Number of Nodes (2–512), Storage Disk Type (ESSD PL0, PL1, or PL2), Encryption Type, and Node Storage Capacity.

  3. For more information, see Create an instance.

3.2 Configure instance

3.2.1 Create a database account

  1. Navigate to the AnalyticDB for PostgreSQL instance list.

  2. Click the instance name and create an initial account on the Account Management page. For more information, see Create an initial account.

3.2.2 Configure whitelists

Click the instance name and navigate to the Data Security page to add the IP address of the vSwitch in the Dify VPC. For more information, see Set whitelists and Create and manage vSwitches.

On the Whitelist Settings tab, click Add Whitelist Group.

3.3 Add instance to DMS

  1. Log in to DMS 5.0.

  2. Move the pointer over the 2023-01-28_15-57-17.png icon in the upper-left corner of the DMS console and choose All Features > Data Assets > Instances.

    Note

    If you use the DMS console in normal mode, choose Data Assets > Instances in the top navigation bar.

  3. On the Instance Management page, click Add and configure the instance information.

    Note

    For Access Method, you must select Security-managed - Manual.

    In the Add Instance dialog box, set Database Type to AnalyticDB for PostgreSQL. Select the Instance Region. Set the Entry Mode to Instance ID. Enter the Instance ID, DATABASE, Database Account, and Database Password.

  4. After completing the configuration, click Submit.

4. Create an OSS bucket and add to DMS

4.1 Create an OSS bucket

  1. Navigate to the Bucket List page and click Create Bucket.

  2. When you configure the bucket information, enter a bucket name and select the same region as your other instances.

  3. Click Create. For more information, see Console quick start.

4.2 Add the OSS bucket to DMS

  1. Log in to DMS 5.0.

  2. Move the pointer over the 2023-01-28_15-57-17.png icon in the upper-left corner of the DMS console and choose All Features > Data Assets > Instances.

    Note

    If you use the DMS console in normal mode, choose Data Assets > Instances in the top navigation bar.

  3. On the Instance Management page, click Add and configure the instance information.

    Note

    For Access Method, you must select Security-managed - Manual.

    In the dialog box that appears, set Data Source to Alibaba Cloud-OSS and File and Log Storage to OSS. Select the target Instance Region, such as China (Beijing). For Entry Mode, select Connection String. Enter the Connection String and Bucket name. Enter the AccessKey ID and AccessKey Secret.

    For more information about how to obtain an AccessKey pair, see View AccessKey pair information of a RAM user.

  4. After completing the configuration, click Submit.

Enable internet access for Dify on DMS

To allow Dify to access the internet or connect to public services, follow these steps.

Get your Dify instance's VPC ID

  1. Log in to DMS 5.0.

  2. Move the pointer over the 2023-01-28_15-57-17.png icon in the upper-left corner and choose All Features > Data+AI > Dify.

    Note

    If you use the DMS console in normal mode, choose Data+AI > Dify in the top navigation bar.

  3. Click the name of the target workspace.

  4. In the lower-left corner, click the Settings image icon, select Workspace Management, and obtain the VPC ID of the Dify instance.

Create a NAT gateway for Dify's VPC

  1. Log on to the Virtual Private Cloud (VPC) console.

  2. Find and click the VPC ID of the Dify instance.

  3. On the Resource Management tab, in the NAT Gateway area, click Create Now.

  4. On the purchase page, fill in the configuration information such as Associated VPC and Instance Name. After completing the configuration, click Buy Now in the lower-right corner.

    The following table describes some of the parameters on the purchase page.

    Parameter

    Description

    Region

    The NAT gateway must be in the same region as your Dify instance.

    Associated VPC

    Select the VPC of your Dify instance.

    Instance Name

    Enter a name for the NAT gateway instance.

    EIP

    If you have an existing EIP in the same region as Dify, select Select Existing EIPs. Otherwise, you must purchase a new one.

    For Associate vSwitch, select a vSwitch in the VPC. For Billing Method, select Pay-as-you-go. For Billing Cycle, select Hourly.

  5. After the purchase, the resource will be ready in a few minutes.