After creating a TaurusDB for PostgreSQL instance, you can create a proxy instance. With the proxy address, write requests are automatically forwarded to the primary node, and read requests are forwarded to each node based on the routing policy of the proxy instance, offloading the read load from the primary node.
This section describes how to create a proxy instance for read/write splitting.
Step 1: Create a Proxy Instance
Step 2: Check Security Group Rules
Step 3: Use the Proxy Address to Connect to Your TaurusDB for PostgreSQL Instance
Constraints
Before creating a proxy instance, ensure that:
- You have purchased a TaurusDB for PostgreSQL instance.
- You have understood the precautions.
Procedure
Step 1: Create a Proxy Instance
- Log in to the TaurusDB console.
- On the Instances page, click the TaurusDB for PostgreSQL instance name.
- In the navigation pane, choose Database Proxy.
- Click Create Proxy Instance.
- On the displayed page, set required parameters and click Next.
Figure 1 Creating a proxy instance
Table 1 Parameter description | Parameter | Description |
| Proxy Instance Name | The name can consist of 4 to 64 characters and must start with a letter. Only letters (case-sensitive), digits, hyphens (-), and underscores (_) are allowed. |
| Proxy Mode | You can select Read/Write or Read-only as needed. - Read/Write: Write requests are only forwarded to the primary node. Read requests are forwarded to the selected nodes with fewer active connections.
- Read-only: All read requests are forwarded to the selected read replicas with fewer active connections.
|
| Routing Policy | Only Load balancing is supported. Read requests are assigned to nodes with fewer active connections. |
| Reads Allowed on Primary | After Reads Allowed on Primary is enabled, read requests are distributed to the primary node and all read replicas. |
| Proxy Instance Specifications | You can select the proxy instance specifications as needed. General-enhanced: 2 vCPUs | 4 GB, 4 vCPUs | 8 GB, and 8 vCPUs | 16 GB |
| Associate New Nodes | After Associate New Nodes is enabled, new read replicas will be automatically associated with the proxy instance. |
| Database Nodes | You need to select the nodes to be associated with the proxy instance for processing read requests. |
- Confirm the proxy instance configuration.
- If you need to modify your settings, click Previous.
- If you do not need to modify your settings, click Submit.
- View the proxy instance and associated nodes.
After the proxy instance creation is complete, you can view the created proxy instance on the Database Proxy page.
Figure 2 Viewing the created proxy instance
On the Database Proxy page, click the proxy instance name to go to the Basic Information page. In the lower part of the page, check database nodes associated with the proxy instance. You can move the pointer to a node name to view its details.
Figure 3 Viewing information about nodes associated with a proxy instance
Step 2: Check Security Group Rules
Ensure that the inbound and outbound rules allow access of the proxy address. The default port is 5432.
- Log in to the TaurusDB console.
- On the Instances page, click the instance name to go to the Basic Information page.
- In the Network Information area, click the security group name under Security Group.
- On the Inbound Rules tab, check whether access through port 5432 is allowed by default.
Figure 4 Allowing access through port 5432
If there is no such a rule, click Fast-Add Rule. In the displayed dialog box, select PostgreSQL (5432), set the inbound rule parameters, and click OK.
Figure 5 Fast adding port 5432
Table 2 Inbound rule parameters | Parameter | Description |
| Protocols and Ports | Select PostgreSQL (5432). |
| Type | Select IPv4 or IPv6. |
| Source | Used to match the source of an external request. The source can be: |
| Action | A security group rule action. The value can be Allow or Deny. - If Action is set to Allow, the rule allows the source addresses to access specified ports of the cloud servers within the security group.
- If Action is set to Deny, the rule blocks the source addresses from accessing specified ports of the cloud servers within the security group.
Security group rules are matched first by priority and then by action. Deny rules take precedence over allow rules. |
| Priority | Priority of the security group rule. The priority value ranges from 1 to 100. The default value is 1, which has the highest priority. The security group rule with a smaller value has a higher priority. |
| Description | Supplementary information about the security group rule. This parameter is optional. The description can contain a maximum of 255 characters and cannot contain angle brackets (<>). |
Step 3: Use the Proxy Address to Connect to Your TaurusDB for PostgreSQL Instance
- Check for the proxy address and port on the TaurusDB for PostgreSQL console.
Click the TaurusDB for PostgreSQL instance name. In the navigation pane, choose Database Proxy. In the proxy instance list, check for the proxy address and port.
Figure 6 Checking for the proxy address and port
- Log in to an ECS.
For details, see Logging In to a Linux ECS.
- Run the following command and enter the password to connect to the TaurusDB for PostgreSQL instance through the proxy address:
psql -h <hostIP> -p <port> -U <userName> -d <database>
Table 3 Parameter description | Parameter | Description |
| <hostIP> | Proxy address obtained in 1. |
| <port> | Port obtained in 1. |
| <userName> | Username of the TaurusDB for PostgreSQL database administrator account. The default value is root. |
| <database> | Database name. The default value is postgres. |
When you log in as a new user, the error message FATAL: No pool configured for database: "postgres", user: "***" may be displayed. To resolve this, the proxy instance's synchronization needs to be triggered. You can do this in two ways:
- Wait up to the cache_refresh timeout (5 minutes by default) for automatic synchronization.
- Manually reboot the proxy instance to trigger synchronization immediately.