The database proxy feature for ApsaraDB RDS for PostgreSQL sits between your application and the RDS instance, providing read/write splitting and transaction splitting. Use it to offload requests from the primary instance, handle high connection volumes, and distribute workloads across read-only instances.
Prerequisites
Before you begin, make sure that:
The RDS instance runs PostgreSQL 10 or later
The RDS instance uses cloud disks
The RDS instance runs RDS High-availability Edition
The RDS instance is a primary RDS instance
The RDS instance does not reside in Hangzhou Zone C or Hangzhou Zone D. If it does, migrate the instance to another zone before enabling database proxy.
Billing
| Proxy type | Cost |
|---|---|
| General-purpose | Free of charge |
| Dedicated | Pay-as-you-go. For details, see Billing rules for database proxies. |
Proxy types
ApsaraDB RDS for PostgreSQL offers two proxy types. For a detailed comparison, see What are database proxies?
| Aspect | General-purpose | Dedicated |
|---|---|---|
| Cost | Free | Pay-as-you-go |
| Maximum specification | 16 CPU cores | 32 CPU cores |
| Specification at enablement | System-recommended (adjustable later) | User-configurable |
Sizing guidance
The proxy specification is calculated as:
Specification = Recommended number of proxies x 2 CPU coresThe unit specification of each database proxy is fixed at 2 CPU cores. The recommended number of proxies depends on the proxy type:
| Proxy type | Recommended count formula |
|---|---|
| General-purpose | (CPU cores of primary instance + CPU cores of all read-only instances) / 4, rounded up |
| Dedicated | (CPU cores of primary instance + CPU cores of all read-only instances) / 8, rounded up |
Example: A primary RDS instance (RDS High-availability Edition) with 8 CPU cores and a read-only instance with 4 CPU cores produces a dedicated proxy count of ceil((8 + 4) / 8) = 2. The recommended specification is 2 x 2 = 4 CPU cores.
Enable database proxy
Go to the Instances page. In the top navigation bar, select the region of your RDS instance, then click the instance ID.
In the left-side navigation pane, click Database Proxy.
Select a proxy type (General-purpose or Dedicated) and click Enable Now.
General-purpose -- The system automatically assigns the recommended specification. After enablement, you can adjust it.
Dedicated -- Configure the proxy specification during enablement.
NoteIf prompted that service-linked role (SLR) authorization is incomplete, click Authorize, then click OK in the dialog box. Alibaba Cloud creates a service-linked role named AliyunServiceRoleForRdsProxyOnEcs that allows the database proxy to bind elastic network interfaces (ENIs) and establish network connections.
Click OK.
Verify enablement
After the database proxy is enabled, the Database Proxy page displays the proxy's basic information, node details, and connection endpoints.
Basic Information
| Parameter | Description |
|---|---|
| Primary Instance | The ID of the RDS instance. |
| Proxy Instance Status | The current status of the database proxy instance. |
| Proxy Type | General-purpose or Dedicated. For differences, see What are database proxies? |
| Zone | The zone of the database proxy instance. By default, this matches the zone of the primary RDS instance. |
| Proxy Specifications | The total specification of the database proxy, calculated as Unit specification (2 CPU cores) x Number of proxies. For example, 3 proxies produce a specification of 2 x 3 = 6 CPU cores. |
| Proxy Version | The database proxy version. |
| Proxy Instance ID | The ID of the proxy instance. |
Proxy Node
| Parameter | Description |
|---|---|
| Node ID | The ID of the proxy node. |
| Zone | The zone of the proxy node. |
| CPU Cores on Proxy Node | The specification of a single proxy node. |
Connection Information
| Parameter | Description |
|---|---|
| Proxy Endpoint (Terminal) ID | The ID of the database proxy endpoint. Each RDS instance supports up to seven database proxy endpoints. Each endpoint can have one internal endpoint and one public endpoint. Hover over the endpoint ID to view its Read/Write Attributes and Read Weight Information. For configuration details, see Configure the connection settings for a database proxy endpoint and Use a database proxy endpoint to connect to an ApsaraDB RDS for PostgreSQL instance. |
| Read/Write Attributes | The read/write mode of the proxy endpoint: Read/Write or Read-only. For details, see Configure the read/write attributes and the read weight of the database proxy. |
| Internal Endpoint/Port | The internal endpoint and port for connecting to the RDS instance over the internal network through the database proxy. The internal endpoint is bound to the proxy endpoint ID. Click the |
| Public Endpoint/Port | The public endpoint and port for connecting to the RDS instance over the Internet through the database proxy. An internal endpoint is provided by default; apply for a public endpoint separately. After applying, click the |
Important considerations
After the database proxy feature is enabled, we recommend that you do not migrate the primary RDS instance across zones. If you migrate the primary RDS instance across zones, the primary RDS instance and its proxy instances are in different zones. This increases access latency and slows down responses.
NoteIf a primary/secondary switchover is triggered by a service failure, the primary RDS instance and its database proxy instances may end up in different zones. To reduce latency, perform another primary/secondary switchover to bring them back into the same zone. For details, see Switch workloads over between primary and secondary ApsaraDB RDS for PostgreSQL instances.
A read-only RDS instance must exist for the primary instance before you can configure connection settings for a database proxy endpoint. Without a read-only instance, you can enable the database proxy feature but cannot configure connection settings. To create one, see Create a read-only ApsaraDB RDS for PostgreSQL instance.
Next steps
Configure the connection settings for a database proxy endpoint -- Set up read/write splitting rules, connection limits, and access policies for your proxy endpoints.
Configure the read/write attributes and the read weight of the database proxy -- Control how read traffic is distributed across the primary and read-only instances.
Manage the database proxy endpoints -- Apply for public endpoints, modify endpoint prefixes, or change ports.
API reference
| API | Description |
|---|---|
| ModifyDBProxy | Enable or disable the database proxy feature for an instance. |
| DescribeDBProxy | Query the details of a database proxy. |