The database proxy feature allows you to create multiple proxy terminals. This topic describes how to create proxy terminals for an ApsaraDB RDS for PostgreSQL instance.

Usage notes

Each RDS instance supports up to seven proxy terminals. You can create multiple proxy terminals to apply different read and write policies to different clients.

Prerequisites

Procedure

  1. Visit the RDS instance list, select a region above, and click the target instance ID.
  2. In the left-side navigation pane, click Database Proxy.
  3. In the upper-right corner of the page, click Create Proxy Terminal.
  4. In the dialog box that appears, configure the following parameters and click OK.
    Parameter Description
    Custom Proxy Terminal The name of the proxy terminal. The name can be up to 30 characters in length.
    Read/Write Attribute The read and write attributes of the proxy terminal. For more information about the read and write attributes, see the "Processing logic based on the read and write attributes" section of this topic.
    • Read/Write (Read/Write Splitting): The proxy terminal connects to the primary RDS instance and the read-only RDS instances, and can receive write requests. This is the default attribute. If you select this option, your primary RDS instance can receive write requests, and you can specify a read weight for the primary RDS instance.

      If you select this option, make sure that the proxy terminal is associated with at least one primary RDS instance and one read-only RDS instance. All write requests are routed to the primary RDS instance.

    • Read-only: The proxy terminal connects only to the read-only RDS instances and cannot receive write requests. You cannot specify a read weight for your primary RDS instance.

      If you select this option, make sure that the proxy terminal is associated with at least one read-only RDS instance. The proxy terminal does not route requests to the primary RDS instance.

      If you select Read-only for a proxy terminal, the proxy terminal assigns connections to the associated read-only RDS instances based on the round-robin algorithm. Each database client is assigned only one connection to one read-only RDS instance. The proxy terminal does not assign the connection to the primary RDS instance. The total number of available connections is the sum of connections that are established to all the read-only RDS instances.

    Latency Threshold The maximum latency that is allowed for the read-only RDS instances to replicate data from the primary RDS instance. If the latency at which a read-only RDS instance replicates data from the primary RDS instance exceeds the value of this parameter, ApsaraDB RDS no longer routes read requests to the read-only RDS instance regardless of the read weight of the read-only RDS instance.

    Valid values: 0 to 3600. Unit: seconds. The read-only RDS instances may replicate data from the primary RDS instance at a specific latency. The latency varies based on the status of the SQL statements that are executed. We recommend that you set this parameter to a value that is greater than or equal to 30.

    Note This parameter appears only when you set the Read/Write Attribute parameter to Read/Write (Read/Write Splitting).
    Read Weight Distribution The method that is used to assign read weights. A higher read weight indicates more read requests that must be processed.

    For example, three read-only RDS instances are attached to the primary RDS instance, the read weight of the primary RDS instance is 0, and the read weights of the three read-only RDS instances are 100, 200, and 200. In this case, the primary RDS instance processes only write requests, and the three read-only RDS instances process all read requests based on the 1:2:2 ratio.

    • Automatic: ApsaraDB RDS automatically assigns a read weight to each RDS instance in your database system based on the specifications of the RDS instance. After you create a read-only RDS instance, ApsaraDB RDS automatically assigns a read weight to the read-only RDS instance and adds the read-only RDS instance to the read/write splitting link. For more information, see Default read weights.
    • Custom: You must manually specify a read weight for each RDS instance in your database system based on your business requirements. Valid values: 0 to 10000. By default, the read weight of a read-only RDS is 0. After you create a read-only RDS instance, you must manually specify a read weight for the read-only RDS instance based on your business requirements.
    Note
    • You cannot specify weights for read-only RDS instances that have the data replication latency specified.
    • After you reconfigure this parameter, the new read weights immediately take effect and no transient connections occur. In addition, the existing connections remain open. Only the requests that are sent over new connections are routed based on the new weights.
    • After the RDS instances are released, the read weights automatically become invalid.
    • If your RDS instance fails or the data replication latency exceeds the specified threshold, the read weights automatically become invalid. After your RDS instance runs as normal, the read weights become valid again.

Delete a proxy terminal

  1. Visit the RDS instance list, select a region above, and click the target instance ID.
  2. In the left-side navigation pane, click Database Proxy.
  3. On the page that appears, click the Proxy Terminal tab, find the proxy terminal that you want to delete, and then click Delete Proxy Terminal.

Processing logic based on the read and write attributes

Read and write attributes Method to specify read weights Weight of a primary RDS instance Normal case After the last read-only RDS instance is deleted After all read-only RDS instances are faulty
Read-only Automatic or Custom You cannot specify a read weight for your primary RDS instance.
  • Primary RDS instance: does not process read or write requests.
  • Proxy terminal: processes only read requests.
  • Primary RDS instance: processes read and write requests.
  • Proxy terminal: processes read and write requests.
  • Primary RDS instance: processes read and write requests.
  • Proxy terminal: processes read and write requests.
Read and write Automatic A weight greater than 0

For more information, see Default read weights.

  • Primary RDS instance: processes read and write requests.
  • Proxy terminal: processes read and write requests.
  • Primary RDS instance: processes read and write requests.
  • Proxy terminal: processes read and write requests.
  • Primary RDS instance: processes read and write requests.
  • Proxy terminal: processes read and write requests.
Custom A weight greater than 0
  • Primary RDS instance: processes read and write requests.
  • Proxy terminal: processes read and write requests.
  • Primary RDS instance: processes read and write requests.
  • Proxy terminal: processes read and write requests.
  • Primary RDS instance: processes read and write requests.
  • Proxy terminal: processes read and write requests.
A weight equal to 0
  • Primary RDS instance: processes only write requests.
  • Proxy terminal: processes read and write requests.
  • Primary RDS instance: processes read and write requests.
  • Proxy terminal: processes read and write requests.
  • Primary RDS instance: processes read and write requests.
  • Proxy terminal: processes read and write requests.

Related operations

Operation Description
DescribeDBProxy Queries the details of a database proxy.
ModifyDBProxyEndpoint Creates, modifies, or deletes a database proxy terminal.
DescribeDBProxyEndpoint Queries information about a database proxy terminal.