Find the public IP address of a local client for an ApsaraDB RDS for PostgreSQL instance
To remotely connect to an ApsaraDB RDS for PostgreSQL instance, you must add the public IP address of the local client to the RDS whitelist. An incorrect IP address will cause the connection to fail.
Problem description
After you add the public IP address of a local device to the RDS whitelist, you cannot access the RDS instance from that device. However, other devices can access the instance. If you set the RDS whitelist to your company's CIDR block or 0.0.0.0/0, the local device is then able to access the RDS instance.
Cause
The public IP address added to the whitelist is incorrect.
Solutions
The solutions in this topic apply only when you access an RDS instance from a device other than an Elastic Compute Service (ECS) instance. If you access an RDS instance from an ECS instance, you can view the correct public and private IP addresses on the instance details page.
Method 1 (Recommended)
You can run the curl ipinfo.io/ip command to find the public IP address of the local client.
Method 2
-
Add the
0.0.0.0/0route entry to the whitelist of your ApsaraDB RDS for PostgreSQL instance. For more information, see Set a whitelist. -
Use the pgAdmin4 client to connect to the ApsaraDB RDS for PostgreSQL instance.
-
Click Database, select postgres, and then click Tools > Query Tool on the top navigation bar.
-
Execute the following SQL statement. In the query results, the value in the client_addr column for the row that contains your SELECT query is the public IP address of your local device.
select datname, pid, usename,client_addr, client_hostname, client_port,query from pg_stat_activity;The output is similar to the following example.
-
Delete the
0.0.0.0/0route entry that you added to the whitelist in Step 1. Then, add the correct public IP address.
More information
If the public IP address of a local device changes and the connection is for a production environment, use an internal network connection. Alternatively, you can configure a suitable public CIDR block in the whitelist to prevent disconnections caused by IP address changes.
Applicable to
-
ApsaraDB RDS for PostgreSQL