All Products
Search
Document Center

ApsaraDB RDS:Verify read/write splitting

Last Updated:Mar 28, 2026

After you enable read/write splitting on an ApsaraDB RDS for MySQL instance (RDS High-availability Edition), run test queries through the database proxy and check the SQL Explorer and Audit logs to confirm that read requests reach the read-only instance and write requests reach the primary instance.

This guide uses an Elastic Compute Service (ECS) instance that connects to the RDS instance over an internal network.

Prerequisites

Before you begin, ensure that you have:

If you use a standard account, grant it Read/Write (DDL + DML) permissions on the target database. This guide uses the example database testdb01, table products, and test account cxx1.

How it works

The database proxy intercepts all queries sent to its endpoint and routes them based on the read weight configuration: write operations go to the primary instance, and read operations go to read-only instances according to the weights you set.

Setting the read-only instance weight to a nonzero value and the primary instance weight to 0 forces all read traffic to the read-only instance. This makes routing behavior observable — any SELECT statement you run will appear only in the read-only instance's SQL Explorer logs, not the primary instance's logs.

Verification steps

Step 1: Set read weights

  1. Log in to the ApsaraDB RDS console and go to the Instances page. Select the region of the primary instance, then click its instance ID.

  2. In the left-side navigation pane, click Database Proxy. In the Connection Information section, find the proxy endpoint to configure.

  3. Click Modify Configuration in the Actions column.

  4. In the dialog box, set the following parameters: Click OK.

    ParameterValue
    Read/Write AttributesRead/Write (Read/Write Splitting)
    Read Weight AllocationCustom
    Read-only instance weight10000
    Primary instance weight0
  5. In the Connection Information section, copy the VPC-type proxy endpoint. You will use this to connect from the ECS instance.

Step 2: Run read operations through the proxy

  1. Log in to the ECS instance. For instructions, see Connect to an instance.

  2. Connect to the RDS instance through the database proxy endpoint:

    PlaceholderDescription
    <proxy-endpoint>The VPC-type proxy endpoint from Step 1. Use a public proxy endpoint if connecting from outside the VPC.
    <port>The proxy port number
    <username>The test account name (for example, cxx1)
    <password>The account password. Enter it directly after -p with no space, or omit it and enter it when prompted to avoid exposing it in plaintext.
    mysql -h<proxy-endpoint> -P<port> -u<username> -p<password>
  3. Switch to the test database:

    USE testdb01;
  4. Run the following SELECT statement six times:

    SELECT * FROM products LIMIT 20;

Step 3: Run write operations through the proxy

In the same session, run the following CREATE TABLE statement three times:

CREATE TABLE Products11 (
  prod_id    CHAR(10)      NOT NULL,
  vend_id    CHAR(10)      NOT NULL,
  prod_name  CHAR(254)     NOT NULL,
  prod_price DECIMAL(8,2)  NOT NULL,
  prod_desc  VARCHAR(1000) NULL
);

Step 4: Check routing results in SQL Explorer and Audit

Check the SQL logs on both instances to confirm that each request was routed to the correct instance.

Check the primary instance — expect no SELECT records:

  1. In the left-side navigation pane of the primary instance details page, choose Autonomy Services > SQL Explorer and Audit.

  2. Select a time range that covers your test, then click Query.

  3. Confirm that no SELECT statement records appear. The CREATE TABLE records should be present.

Check the read-only instance — expect six SELECT records:

  1. In the left-side navigation pane of the primary instance details page, click Basic Information. In the Instance Distribution section, hover over the count next to Read-only Instance and click the read-only instance ID.

  2. In the left-side navigation pane of the read-only instance, choose Autonomy Services > SQL Explorer and Audit.

  3. Select the same time range and click Query. Confirm that six SELECT statement records appear.执行记录

Check the primary instance again — expect three CREATE TABLE records:

In the left-side navigation pane of the primary instance details page, choose Autonomy Services > SQL Explorer and Audit. Select the same time range and click Query. The three CREATE TABLE statement records should appear.执行记录

Verification conclusion

With the read-only instance weight set to 10000 and the primary instance weight set to 0:

  • All write requests (CREATE TABLE) are processed by the primary instance

  • All read requests (SELECT) are processed by the read-only instance

This confirms that read/write splitting is working correctly.