All Products
Search
Document Center

ApsaraDB RDS:Configure persistent connection settings

Last Updated:Mar 28, 2026

Routine O&M operations on ApsaraDB RDS for MySQL—such as minor version upgrades, parameter changes, and primary/secondary switchovers—temporarily interrupt backend connections between the database proxy and the database. Without persistent connections, your application sees these as connection errors, which causes service interruptions. You would also need to build reconnection logic into your application code.

Persistent connections prevent this. The database proxy keeps frontend connections (between your application and the proxy) alive while it re-establishes the backend connection to the new primary instance. Your application does not need to implement reconnection logic or handle connection errors during planned maintenance.

Starting January 9, 2024, enabling the database proxy feature on a qualifying RDS instance also enables persistent connections by default.

How it works

The database proxy sits between your application and the RDS instance. Connections on each side are managed independently:

  • Frontend connections: between your application and the database proxy

  • Backend connections: between the database proxy and the RDS instance

When a switchover interrupts a backend connection, the proxy restores it on the new primary instance by replaying the connection state—system variables, user variables, temporary tables, character set encoding, transaction state, and PREPARE statements. Your frontend connection remains unaffected throughout.

Proxy type comparison

The type of database proxy determines which events persistent connections cover.

Proxy typePersistent connections during switchoversPersistent connections during failovers
General-purpose proxySupportedNot supported
Dedicated proxySupportedSupported

Switchover

Switchovers are planned operations triggered by:

  • Primary/secondary switchovers

  • Minor engine version updates

  • Parameter changes that require a restart

  • Configuration changes to the primary RDS instance

The proxy handles a switchover in three phases:

  1. Block: The proxy stops accepting new requests. Sessions with active transactions are forwarded to the current primary instance. Sessions that start new transactions during this window have their requests held until the switchover completes. Sessions with active transactions that are still running after the block window ends are disconnected, and the RDS instance rolls back any uncommitted transactions.

    image.png

  2. Switch: The proxy updates the status of existing connections.

    image.png

    • Non-persistent connections are terminated.

    • Persistent connections are moved from the current RDS instance to the new primary instance.

    • Connection pool connections to the original primary instance are released.

  3. Restore: The proxy re-establishes persistent connections on the new primary instance.

    image.png

Failover

A failover is an unplanned event triggered by a primary instance failure. The system automatically promotes a secondary instance as the new primary.

During a failover, the proxy caches SQL statements that are being executed or are to be forwarded, and forwards failed read requests to an available instance, then restores the connection.

Important

Persistent connections do not cover write requests during a failover. The proxy cannot guarantee that write requests will be processed successfully when the primary instance fails.

Prerequisites

Before you begin, ensure that your RDS instance meets the requirements for the type of persistent connections you need.

For switchovers

  • Runs MySQL 5.6, 5.7, or 8.0

  • Uses RDS High-availability Edition or RDS Cluster Edition

  • Uses cloud disks or Premium Local SSDs

  • Uses general-purpose or dedicated database proxies

  • Has the database proxy feature enabled with proxy version 1.14.5_20231207 or later — see Enable the database proxy feature

For failovers

  • Runs MySQL 5.6, 5.7, or 8.0

  • Uses RDS High-availability Edition or RDS Cluster Edition

  • Uses cloud disks or Premium Local SSDs

  • Uses dedicated database proxies

  • Has the database proxy feature enabled with proxy version 2.9.1 or later — see Enable the database proxy feature

Enable persistent connections

  1. Log on to the ApsaraDB RDS console. In the top navigation bar, select the region where your RDS instance resides, find the instance, and click the instance ID.

  2. In the left-side navigation pane, click Database Proxy.

  3. In the Basic Information section, click Enabled to the right of Persistent Connections.

If Persistent Connections does not appear, your RDS instance does not meet the prerequisites.

Use persistent connections

Before you begin, ensure that you have:

  • The database proxy feature enabled for your RDS instance

  • Persistent connections enabled for your RDS instance

To connect your application using the database proxy endpoint:

  1. Log on to the ApsaraDB RDS console. In the top navigation bar, select the region where your RDS instance resides, find the instance, and click the instance ID.

  2. In the left-side navigation pane, click Database Proxy.

  3. Configure the connection settings for the database proxy endpoint. Set Read/Write Attributes to Read/Write (Read/Write Splitting). For details, see Configure the connection settings for a database proxy endpoint.

  4. Apply for an internal or public endpoint for the database proxy endpoint. For details, see Manage database proxy endpoints.

  5. Connect your application to the RDS instance using the endpoint and port of the database proxy.

When O&M operations trigger a switchover, the proxy keeps your frontend connections alive. Your application does not experience disconnection errors.

Disable persistent connections

  1. Log on to the ApsaraDB RDS console. In the top navigation bar, select the region where your RDS instance resides, find the instance, and click the instance ID.

  2. In the left-side navigation pane, click Database Proxy.

  3. In the Basic Information section, click Disable to the right of Persistent Connections.

Limitations

Persistent connections are not maintained in the following scenarios during a switchover:

  • The MySQL server has not finished returning a result set. For example, a 100 MB result set has only returned 50 MB so far.

  • Uncommitted transactions exist.

  • The CHANGE USER statement was executed on the connection.

  • The LOAD DATA statement was executed on the connection.

  • Temporary tables exist.

  • The connection is used to subscribe to binary logs via a database proxy endpoint.

  • The FOUND_ROWS(), ROW_COUNT(), or LAST_INSERT_ID() function is in use. These functions can still be called, but the results may be inaccurate after a reconnection. MySQL no longer recommends SELECT FOUND_ROWS() — replace it with SELECT COUNT(*) FROM tb1. For more information, see FOUND_ROWS().

Usage notes

  • Thread ID changes: Running SELECT CONNECTION_ID() may return a different thread ID after a reconnection.

  • SHOW PROCESSLIST output: The IP addresses and port numbers shown in SHOW PROCESSLIST or on the SQL Explorer page may differ from the actual client addresses after a reconnection.

  • User-defined variables: User-defined variables set on a connection become invalid after the connection is kept alive through a reconnection.

Test results

The following test validates persistent connection behavior during switchovers.

Test environment

ItemValue
RDS editionMySQL 8.0, RDS High-availability Edition
Instance typemysql.x2.xlarge.2c (dedicated, 8 CPU cores, 16 GB memory)
Test toolSysbench
Tables100 tables, 40,000 rows each
Concurrent threads128

Test command

sysbench --db-driver=mysql --mysql-host=127.X.X.1 --mysql-port=3306 --mysql-user=username --mysql-password='' --tables=100 --table-size=40000 --threads=128 --mysql-db=sbtest --report-interval=5 --time=600 oltp_read_write run

Key parameters:

ParameterDescription
db-driverDatabase engine
mysql-hostDatabase proxy endpoint
tablesNumber of tables
table-sizeRows per table
threadsConcurrent threads
timeTest duration, in seconds

Results

All switchover scenarios achieved 100% connection retention.

Switchover scenarioConnection retention
Minor engine version update100%
Primary/secondary switchover100%
Primary instance configuration change100%
Parameter change requiring restart100%

API reference

OperationDescription
ModifyDBProxyModifies the database proxy feature of an instance
DescribeDBProxyQueries the details of the database proxy of an instance

What's next

Enable the database proxy feature