Configure the database proxy

Updated at:

Configure the database proxy by using the cluster endpoint of PolarDB.

Prerequisites

The product edition must be PolarDB for MySQLCluster Edition. For more information about product editions, see Enterprise editions.

Usage notes

Only PolarDB for MySQL 8.0 clusters support enabling parallel query and setting the degree of parallelism when you configure the database proxy.

Procedure

  1. Log on to the PolarDB console. In the left-side navigation pane, click Clusters, select the region where the cluster is located, and then click the ID of the target cluster to go to the cluster details page.

  2. On the Basic Information page of the cluster, find the target cluster endpoint in the Database Connections section, and click Configure to the right of its name.

  3. In the dialog box that appears, modify the cluster endpoint settings as needed. The following table describes the configuration items.

    Table 1. Configuration parameters

    Parameter

    Description

    Network Information

    PolarDB provides a private endpoint for each cluster endpoint by default. To modify this endpoint or apply for a public endpoint, see Manage endpoints.

    Cluster Settings

    Read/Write

    The read/write mode of the cluster endpoint. Valid modes are Read-only and Read/Write (Automatic Read/Write Splitting).

    Note

    You can modify the read/write mode after you create a custom endpoint. After you change the read/write mode, the change takes effect only for new connections. Existing connections keep the original mode.

    Endpoint Name

    Enter a name for the cluster endpoint.

    Node Settings

    Available Nodes and Selected Nodes

    The Available Nodes box on the left includes the primary node and all read-only nodes. Select the nodes that you want to add to the cluster endpoint to handle read requests, and click the 1 icon to move them to the Selected Nodes box on the right.

    Note

    Node selection does not affect the read/write mode:

    • When the read/write mode is Read/Write (Automatic Read/Write Splitting), write requests are sent only to the primary node, regardless of whether the primary node is selected in Selected Nodes.

    • When the read/write mode is Read-only, all read requests are forwarded to read-only nodes by load balancing and are not forwarded to the primary node. Even if the primary node is added to Selected Nodes, this does not take effect.

    • When the read/write mode is Read/Write (Automatic Read/Write Splitting), because multi-primary clusters (Limitless) use a database and table routing mechanism, add the primary node of the target database and table to the read/write endpoint, or select all primary nodes. Fully evaluate the routing impact before you select nodes.

    Automatically Associate New Nodes

    Specifies whether to automatically add new nodes to this endpoint.

    Load Balancing Settings

    Load Balancing Policy

    The scheduling policy used to process read requests across multiple nodes during read/write splitting. Valid policies are Connections-based Load Balancing and Active Request-based Load Balancing. For more information about the load balancing policy, see Load balancing policies.

    Primary Node Accepts Read Requests

    • Select No. SQL queries are sent only to read-only nodes, which reduces the load on the primary node and keeps the primary node stable.

    • Select Yes. SQL queries can be sent to the primary node and read-only nodes.

    For more information about whether the primary database accepts read requests, see Primary node accepts read requests.

    Note

    This setting is supported only in Read/Write (Automatic Read/Write Splitting) mode.

    Transaction Splitting

    Enable or disable transaction splitting. For more information about transaction splitting, see Transaction splitting.

    Note

    This setting is supported only in Read/Write (Automatic Read/Write Splitting) mode.

    On-demand connections

    Enable or disable on-demand connections. For more information about on-demand connections, see On-demand connections.

    Note

    This setting is supported only when Load balancing policy is Active Request-based Load Balancing.

    Consistency Settings

    Consistency Level

    • When the read/write mode is Read/Write (Automatic Read/Write Splitting), the available consistency levels are Eventual Consistency (Weak), Session Consistency (Medium), and Global Consistency (Strong). For more information, see Consistency levels.

    • When the read/write mode is Read-only, the default consistency level is Eventual Consistency (Weak) and cannot be changed.

    Important
    • The consistency settings are displayed only when the cluster contains at least one read-only node (RO). If the cluster contains no read-only nodes, this section is not displayed.

    • Changes to the consistency level take effect immediately for all connections.

    • Global consistency (high-performance mode) must take effect on all endpoints in the cluster at the same time. If you select a consistency level other than global consistency (high-performance mode), all other endpoints in the cluster revert to the consistency state that was in effect before global consistency (high-performance mode) was enabled.

    Global Consistency Timeout

    The timeout period for a read-only node to synchronize with the latest data. Valid values: 0 to 60,000. Default value: 20. Unit: ms.

    Note

    This setting is supported only when Consistency Level is Global Consistency (Strong) and Global Consistency Mode is Traditional Mode.

    Global Consistency Timeout Policy

    The default policy that PolarDB applies after a read-only node times out. Valid values:

    • Send Requests to Primary Node (Default)

    • SQL Exception: Wait replication complete timeout, please retry.

    Note

    This setting is supported only when Consistency Level is Global Consistency (Strong) and Global Consistency Mode is Traditional Mode.

    Timeout for global consistency reads (high-performance mode)

    The timeout period for a read-only node to synchronize with the latest data. Valid values: 1 to 1,000,000. Default value: 100. Unit: ms.

    Important
    • Global consistency (high-performance mode) must take effect on all endpoints in the cluster at the same time. If you enable global consistency (high-performance mode) for one endpoint, it is enabled for all other endpoints in the cluster.

    • This setting is supported only when Consistency Level is Global Consistency (Strong) and Global Consistency Mode is High-performance Mode.

    Policy for global consistency read timeouts (high-performance mode)

    The default policy that PolarDB applies after a read-only node times out. Valid values:

    • Send Requests to Primary Node (Default)

    • Return error messages due to timeout.

    • Downgrade the consistency level of a query to inconsistent read when a global consistent read in the query times out. No error message is returned to the client.

    Note

    This setting is supported only when Consistency Level is Global Consistency (Strong) and Global Consistency Mode is High-performance Mode.

    Session Consistency Timeout

    The timeout period for a read-only node to synchronize with the latest data. Valid values: 0 to 60,000. Default value: 0. Unit: ms.

    Important
    • This setting is supported only when Consistency Level is Session Consistency (Medium).

    • Global consistency (high-performance mode) must take effect on all endpoints in the cluster at the same time. If you select a consistency level other than global consistency (high-performance mode), all other endpoints in the cluster revert to the consistency state that was in effect before global consistency (high-performance mode) was enabled.

    Session Consistency Timeout Policy

    The default policy that PolarDB applies after a read-only node times out. Valid values:

    • Send Requests to Primary Node (Default)

    • SQL Exception: Wait replication complete timeout, please retry.

    Note

    This setting is supported only when Consistency Level is Session Consistency (Medium).

    Connection Pool Settings

    Connection Pool

    You can select Off (default), Session-level, or Transaction-level. For more information about the connection pool, see Connection pools.

    Note
    • This setting is supported only when the read/write mode is Read/Write (Automatic Read/Write Splitting).

    • Changes to the connection pool configuration take effect only for newly established connections. Usually, to make the changes take effect, restart the application or re-establish the connection to the database.

    HTAP Optimization

    Parallel Query

    Enable or disable parallel query and set the degree of parallelism.

    Elastic Parallel Query (ePQ) uses the parallel processing capability of multi-core CPUs (idle compute resources in the cluster) to accelerate complex queries. For more information, see Elastic Parallel Query.

    Note

    Starting April 1, 2023, Elastic Parallel Query is enabled by default and the degree of parallelism defaults to 2 for clusters that meet the following conditions:

    • Newly created clusters: the cluster has at least 8 CPU cores.

    • Existing clusters: you create a custom cluster endpoint in the cluster, and the cluster has at least 8 CPU cores.

    Transactional/Analytical Processing Splitting

    Enable or disable automatic traffic redirection between row store nodes and column store nodes. For more information, see Configure automatic request distribution.

    Note

    PolarDB for MySQL 8.0.1 cluster endpoints with a minor engine version of 8.0.1.1.22 or later support this setting only in Read/Write (Automatic Read/Write Splitting) mode. In addition, Node Settings must include at least one read-only column store node in Selected Nodes.

    Column store nodes handle OLTP requests.

    Enable or disable the ability of column store nodes to handle OLTP requests.

    After this feature is enabled, column store nodes handle both OLAP and OLTP requests. The database proxy routes OLTP read requests to column store nodes based on the number of active requests, which may increase the load on column store nodes.

    Note

    This setting is supported only when Transactional/Analytical Processing Splitting is enabled.

    Security Protection

    Overload Protection

    Enable or disable overload protection. For more information, see Overload protection.

  4. Click OK.

FAQ

Why does removing a read-only node from a cluster endpoint cause a connection error after its weight is set to 0?

  • Scenario: You want to remove a read-only node from a cluster endpoint. To avoid affecting the connections on that node, you first set the read/write splitting weight of the read-only node to 0. You expect that subsequent read requests are no longer sent to the read-only node after its weight is set to 0. However, after you remove the node from the cluster endpoint, the application reports connection errors.

  • Cause: A cluster endpoint has two Load Balancing Policy options, which are Active Request-based Load Balancing and Connections-based Load Balancing:

    • Active Request-based Load Balancing: After the weight of a read-only node is reduced to 0, subsequent requests are no longer routed to that node.

    • Connections-based Load Balancing: Load balancing occurs only when a connection is established. If an existing connection is connected to a read-only node, subsequent requests on that connection are always sent to that read-only node.

  • Solution:

    1. Change the Load Balancing Policy of the cluster endpoint to Active Request-based Load Balancing.

    2. Set the read/write splitting weight of the target read-only node to 0.

    3. Remove the read-only node.

API reference

API

Description

DescribeDBClusterEndpoints

Queries cluster endpoints.

ModifyDBClusterEndpoint

Modifies cluster endpoints.

DeleteDBClusterEndpoint

Releases custom cluster endpoints.