All Products
Search
Document Center

ApsaraDB RDS:How do I obtain the public IP address of a local server that is connected to an ApsaraDB RDS for PostgreSQL instance?

Last Updated:Feb 02, 2024

To connect to an ApsaraDB RDS for PostgreSQL instance from a local server, you must add the public IP address of the local server to an IP address whitelist of the RDS instance. If the public IP address that you add to the IP address whitelist of the RDS instance is incorrect, the connection fails.

Problem description

After you add the public IP address of the local server to the IP address whitelist of the RDS instance, you cannot connect to the RDS instance from the local server. However, you can connect to the RDS instance from other devices. After you add the public CIDR block of the network in which your local server resides or the entry 0.0.0.0/0 to the IP address whitelist of the RDS instance, you can connect to the RDS instance from the local server.

Causes

The public IP address that you add to the IP address whitelist of the RDS instance is incorrect.

Solution

The solution that is provided in this topic is not applicable to scenarios in which you connect to the RDS instance from an Alibaba Cloud Elastic Compute Service (ECS) instance. If you want to connect to the RDS instance from an ECS instance, you can obtain the public and private IP addresses of the ECS instance in the ECS console.

  1. Add the entry 0.0.0.0/0 to the IP address whitelist of the RDS instance. For more information, see Configure an IP address whitelist.

  2. Use the pgAdmin4 client to connect to the RDS instance. For more information, see Connect to an ApsaraDB RDS for PostgreSQL instance.

  3. Click Database and then click postgres. In the top navigation bar, choose Tools > Query Tool.

  4. Execute the following SQL statement to query the public IP address of the local server. You can obtain the public IP address by locating the query column for which SELECT is displayed and obtaining the value in the client_addr column.

    select datname, pid, usename,client_addr, client_hostname, client_port,query  from pg_stat_activity;

    The following figure shows a sample output.

    image.png

  5. Delete the entry 0.0.0.0/0 that is added to the IP address whitelist of the RDS instance in Step 1. Then, add the obtained public IP address of the local server to the IP address whitelist.

Additional information

If the public IP address of the local server changes and the connection that is established between the local server and the RDS instance is used in the production environment, we recommend that you connect to the RDS instance over an internal network or add an appropriate public CIDR block to the IP address whitelist of the RDS instance. This ensures that the RDS instance is not disconnected due to IP address changes.

Applicable scope

  • ApsaraDB RDS for PostgreSQL