All Products
Search
Document Center

PolarDB:Connect to a PolarDB for PostgreSQL cluster

Last Updated:Jul 26, 2024

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 is created for the cluster. For more information, see Create a database account.

  • The IP address of the host that you use to access the PolarDB cluster is added to a whitelist of the cluster. For information about how to add IP addresses to a whitelist of a cluster, see Configure a whitelist for a cluster.

Connect to a PolarDB cluster by using DMS

DMS is a one-stop data management platform designed to streamline all aspects of data handling. By using DMS, you can effectively manage data, oversee and modify database schemas, control data access, and create detailed business intelligence (BI) charts. Additionally, DMS offers tools to display and analyze data trends, track data changes, monitor and optimize data performance, and manage servers. You can use DMS to manage relational databases such as MySQL, SQL Server, and PostgreSQL databases and NoSQL databases such as MongoDB and Redis databases. You can also use DMS to manage Linux servers.

  1. Log on to the PolarDB console.

  2. In the upper-left corner, select the region where the cluster to which you want to connect is deployed.

  3. Find the cluster and click its ID.

  4. In the upper-right corner of the Basic Information page, click Log on to Database.

  5. In the dialog box that appears, enter the account and password of the account created for the PolarDB cluster.

  6. Click Login.

    Note

    The first time you connect to the PolarDB cluster by using DMS, the system prompts you to add the IP address ranges of the DMS service to the whitelist. Click OK to complete the configuration.

  7. After you log on to DMS, refresh the page. In the left-side navigation pane, click Instances Connected.

  8. Find and double-click the name of the database that you want to manage. Then, you can manage the database.

Connect to a PolarDB cluster by using pgAdmin 4

You can also use pgAdmin 4 to connect to a PolarDB cluster.

  1. Start pgAdmin 4.

  2. Right-click Servers and choose Create > Server.

    创建服务器

  3. On the General tab of the Create - Server dialog box, enter the name of the server.

    pgadmin4-常规

  4. Click the Connection tab and specify the information about the cluster that you want to connect to. The following table describes the parameters.

    pgadmin-连接

    Table 1. Parameters

    Parameter

    Description

    Host name/address

    The endpoint of the PolarDB cluster. To view the endpoint and port information of the PolarDB cluster, perform the following steps:

    1. Log on to the PolarDB console.

    2. In the upper-left corner of the console, select the region in which the cluster is deployed.

    3. Find the cluster and click its ID.

    4. In the Endpoints section, view the endpoints of the PolarDB cluster.

    Port

    The port of the PolarDB for PostgreSQL cluster. To obtain the port number, see View endpoints and ports.

    Maintenance database

    The name of the maintenance database. Default value: postgres.

    Username

    The account of the PolarDB cluster. For information about how to create an account, see Create a database account.

    Password

    The password of the account for the PolarDB cluster.

  5. Click Save.

  6. 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.

    连接成功

  7. 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.

    查询窗口

Connect to a PolarDB cluster by using psql

In addition to the preceding methods for connecting to your PolarDB cluster, you can also download and install a PostgreSQL client and use psql to connect to your PolarDB cluster.

Note
  • The method for using psql to connect to your PolarDB cluster from a Windows operating system is the same as the method from a Linux operating system.

  • For more information about how to use psql, see psql.

  1. Enter the following command in the psql command-line interface (CLI) and press the Enter key.

    psql -U <username> -h <host> -p <port> <dbname>

    Parameter

    Description

    username

    The account of the PolarDB cluster. For 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 of the PolarDB cluster, perform the following steps:

    1. Log on to the PolarDB console.

    2. In the upper-left corner of the console, select the region in which the cluster is deployed.

    3. Find the cluster and click its ID.

    4. In the Endpoints section, view the endpoints of the PolarDB cluster.

    port

    The port of the PolarDB cluster. . To obtain the port number, see View endpoints and ports.

    dbname

    The name of the maintenance database. For information about how to create a database, see Create a database.

    Example:

    psql -U testuser -h hostname -p 1521 testdb
  2. Enter the password of the specified username and press the Enter key. Then, the connection is established.

Troubleshooting connection failures

  • The IP address whitelist is invalid.

    • The default whitelist contains only the IP address 127.0.0.1. The IP address 127.0.0.1 indicates that no IP address is allowed to access the PolarDB cluster. In this case, you must add the IP addresses of the hosts from which you access the cluster to the whitelist. For more information, see Set 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

      The value 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 correct 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 the 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.

      • An invalid endpoint is entered. In this case, view the valid endpoints in the PolarDB console. For more information, see View endpoints and ports

      • 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