This topic describes how to use Data Management Service (DMS) and a client to connect to a PolarDB for PostgreSQL cluster.
Prerequisites
- A privileged account or a standard account for a PolarDB cluster is created. For more information, see Create database accounts.
- The IP address of the host that you want to connect to the PolarDB cluster is added to the whitelist. For more information, see Configure a whitelist for a cluster.
Use DMS to connect to a PolarDB cluster
DMS provides an integrated data management solution. DMS supports data management, schema management, access control, BI charts, trend analysis, data tracking, performance optimization, and server management. DMS allows you to manage relational databases such as MySQL, SQL Server, and PostgreSQL, as well as NoSQL databases such as MongoDB and Redis. DMS also allows you to manage Linux servers.
- Log on to the PolarDB console.
- In the upper-left corner of the console, select the region in which the cluster that you want to manage is deployed.
- Find the cluster and click the cluster ID.
- In the upper-right corner of the Overview page, click Log On to Database.
- In the dialog box that appears, enter the database account and password that you create in the PolarDB cluster.
- Click Login. Note If you are using DMS to connect to the PolarDB cluster for the first time, you are prompted to set the whitelist. Click Configure Whitelist to complete the authorization.
- After you log on to DMS, refresh the page. In the left-side navigation pane, click Logged in instance.
- Find and double-click the name of the database that you want to manage. Then, you can manage the database.
Use a client to connect to a PolarDB cluster
You can also use your pgAdmin 4 client to connect to a PolarDB cluster.
- Launch the pgAdmin 4 client.
- Right-click Servers and choose , as shown in the following figure.
- On the General tab of the Create - Server dialog box, enter the name of the server, as shown in the following figure.
- Click the Connection tab and specify the information about the cluster that you want to connect to. The following table describes the parameters.
Table 1. Parameter description Parameter Description Host name/address The endpoint of the PolarDB cluster. To view the endpoint and port information about the PolarDB cluster, perform the following steps:
- Log on to the PolarDB console.
- In the upper-left corner of the console, select the region where the cluster is deployed.
- On the Clusters page, click the ID of the cluster that you want to manage.
- In the Endpoints section, view the endpoints of the PolarDB cluster.
Port The port for the PolarDB for PostgreSQL cluster. Default value: 1921. Maintenance database The maintenance database. Default value: postgres. Username The account of the PolarDB cluster. For more information about how to create an account, see Create a database account. Password The password of the account for the PolarDB cluster. - Click Save.
- If the connection information is valid, a page that is similar to the following page appears after you click the database name. This indicates that the database is connected.
- Right-click the name of the database that you want to manage and click Query Tool.... On the page that appears, you can add, delete, update, and query data in the database.
Use psql to connect to a PolarDB cluster
In addition to the preceding methods of connecting to your PolarDB cluster, you can also download and install a PostgreSQL client and use psql to connect to your PolarDB cluster.
- The method of using psql to connect to your PolarDB cluster for Windows operating systems is the same as that for Linux operating systems.
- For more information about how to use psql, see psql.
- Enter the following command in the psql command line interface (CLI) and press Enter:
psql -U <username> -h <host> -p <port> <dbname>
Parameter Description username
The account of the PolarDB cluster. For more information about how to create an account, see Create a database account. host
The endpoint of the PolarDB cluster. To view the endpoint and port information about the PolarDB cluster, perform the following steps:
- Log on to the PolarDB console.
- In the upper-left corner of the console, select the region where the cluster is deployed.
- On the Clusters page, click the ID of the cluster that you want to manage.
- In the Endpoints section, view the endpoints of the PolarDB cluster.
port
The port for the PolarDB cluster. Default value: 1921. dbname
The name of the maintenance database that you want to manage. For more information about how to create a database, see Create a database. The following code provides an example:
psql -U testuser -h hostname -p 1521 testdb
- Enter the password of the specified
username
and press Enter. Then, the connection is established.
Troubleshooting
- The IP address whitelist is invalid.
- The default whitelist contains only the IP address 127.0.0.1. 127.0.0.1 indicates that no IP address is allowed to access the PolarDB cluster. Therefore, you must add the IP addresses of the clients that you use to access your cluster to the whitelist. For more information, see Set IP address whitelists for a cluster.
- The entry in the whitelist is set to 0.0.0.0. The valid format is 0.0.0.0/0. Important 0.0.0.0/0 indicates that all IP addresses are allowed to access the PolarDB cluster. Proceed with caution.
- The public IP addresses that you add to the whitelist are invalid. For example, the public IP addresses may be dynamic IP addresses, or the tools or websites used to check the public IP addresses provide invalid IP addresses.
- The internal or public endpoint is incorrectly used.
If you use an internal endpoint to establish a connection over the Internet or use a public endpoint to establish a connection over an internal network, the connection fails.
Use the required endpoint. If you want to connect to the PolarDB cluster over an internal network, use an internal endpoint of the PolarDB cluster. If you want to connect to the PolarDB cluster over the Internet, use a public endpoint of the PolarDB cluster.
- A Domain Name System (DNS) server fails to resolve the endpoint of your cluster.
- The endpoint that you enter to connect to the PolarDB cluster is invalid. In this case, troubleshoot the issue:
- The endpoint of the PolarDB cluster is invalid. In this case, view the valid endpoints in the PolarDB console. For more information, see View or apply for an endpoint.
- The endpoint that you enter is a public endpoint. However, the public endpoint is manually deleted.
- Some applications have limits on the length of endpoints and the endpoint you enter is truncated.
- If the endpoint of the PolarDB cluster is valid, change the IP address of the DNS server to that of the Alibaba Cloud DNS server.
Network type IP address of the Alibaba Cloud DNS server Internal network (classic network) 10.143.22.116 10.143.22.118
Internal network (virtual private cloud) 100.100.2.136 100.100.2.138
Internet 223.5.5.5 223.6.6.6
- The endpoint that you enter to connect to the PolarDB cluster is invalid. In this case, troubleshoot the issue: