After you create an ApsaraDB RDS for PostgreSQL instance and configure an account and IP address whitelist, connect to the instance using one of the following methods.
Prerequisites
Before you begin, ensure that you have:
An RDS instance. For more information, see Create an ApsaraDB RDS for PostgreSQL instance.
A database and an account created on the instance. For more information, see Create a database and an account.
An IP address whitelist configured for the instance. For more information, see Configure an IP address whitelist.
To connect from an Elastic Compute Service (ECS) instance over the internal network: the ECS instance and RDS instance must be in the same region, the same virtual private cloud (VPC), and under the same Alibaba Cloud account. Add the private IP address of the ECS instance to the whitelist.
To connect from an on-premises device: add the public IP address of the device to the whitelist.
Choose a connection method
| Method | Best for |
|---|---|
| Data Management (DMS) | Quick browser-based access without installing a client |
| pgAdmin | Visual database management with a desktop GUI |
| PostgreSQL CLI (psql) | Scripting, automation, and command-line workflows |
| Application code (JDBC) | Integrating the database into a Java application |
| Power BI Desktop | Business intelligence reporting and data visualization |
All methods require the instance endpoint and port. Find these on the Database Connection page of your RDS instance. For more information, see View and change the endpoints and port numbers of an ApsaraDB RDS for PostgreSQL instance.
Internal endpoint: use when connecting from an ECS instance in the same region and VPC.
Public endpoint: use when connecting from an on-premises device or a different region.
Use DMS to connect to the RDS instance
Data Management (DMS) is a browser-based tool that covers data management, schema management, server management, user authorization, security audit, trend analysis, data tracking, BI reporting, and performance optimization. No client installation is required.
Log on to the ApsaraDB RDS console. In the top navigation bar, select the region where the instance resides. Find the instance and click its ID.
On the Basic Information page, click Log On to Database.

In the Log on to Database Instance dialog box, configure the Access mode and Control Mode parameters. Access mode options:
Security Hosting - Automatic (Recommended): DMS enables security hosting and creates a database account automatically.
Account + password login: use a database account that has permissions on the target database.
Login with KMS Secret: DMS enables security hosting, but you must manually select the RDS credentials from Key Management Service (KMS).
Parameter Description Access mode The method used to connect to the RDS instance from DMS. Security Hosting - Automatic (Recommended) and Login with KMS Secret both enable security hosting, which activates logon-free mode for the instance. Account + password login requires a database account with the necessary permissions. Control Mode The instance-level control mode: Flexible Management, Stable Change, or Security Collaboration. Choose based on your business requirements. Refresh the page. In the left-side navigation pane, click Instances Connected to view the connected RDS instances and their databases. Keep the following in mind:
To switch databases in DMS, double-click the target database. The
USEcommand is not supported.If the instance appears but the database is missing, either the account lacks permissions to that database, or the metadata needs a refresh. To refresh, hover over the instance name and click the
icon.To quickly synchronize database and table schemas, use the empty database initialization feature.
If you enabled security hosting, the instances appear under Logon-free Instances instead.

To add an RDS instance directly from the DMS console, see Register an Alibaba Cloud database instance. After resetting your account password, log on to DMS again.
Use pgAdmin to connect to the RDS instance
pgAdmin is a desktop GUI client for PostgreSQL. pgAdmin 4 is bundled with the PostgreSQL installer from the PostgreSQL official website. To install pgAdmin without PostgreSQL, download it separately from pgadmin.org.
The following steps use pgAdmin 4 V6.2.0 as an example.
Start pgAdmin 4.
On first launch of newer pgAdmin versions, set a master password to protect saved credentials.
Right-click Servers and choose Register > Server.

On the General tab, enter a name for the server.

Click the Connection tab and configure the connection parameters.
Parameter Description Host name/address The instance endpoint. Use the internal endpoint for VPC connections, or the public endpoint for Internet connections. Port The port corresponding to the endpoint type (internal or public). Username The database account username. Password The database account password. For more information, see Create a database and an account. 
Click Save. A successful connection shows the server tree in the left panel.

The postgres database is a system database. Do not perform operations on it. Use a different database on the instance.
Use the PostgreSQL CLI to connect to the RDS instance
The PostgreSQL CLI (psql, also called Command Line Tools) is installed with PostgreSQL from the PostgreSQL official website.
Run the following command to connect:
psql -h <endpoint> -U <username> -p <port> [-d <database-name>]| Parameter | Description |
|---|---|
<endpoint> | The instance endpoint. Use the internal endpoint for VPC connections, or the public endpoint for Internet connections. |
<username> | The database account username. |
<port> | The port corresponding to the endpoint type. |
<database-name> | (Optional) The database to connect to. Defaults to the postgres system database if omitted — do not use the postgres database for operations. |

Connect from an application
The following example uses Java Database Connectivity (JDBC) in a Maven project. The approach is similar for other programming languages.
Step 1: Add the PostgreSQL JDBC dependency to pom.xml:
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.2-504.jdbc3</version>
</dependency>Step 2: Connect to the instance using JDBC:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DatabaseConnection {
public static void main(String[] args) {
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
// Endpoint of the RDS instance
String hostname = "pgm-bp1i3kkq7321o9****.pg.rds.aliyuncs.com";
// Port number of the RDS instance
int port = 5432;
// Database name
String dbname = "postgres";
// Username
String username = "username";
// Password
String password = "password";
String dbUrl = "jdbc:postgresql://" + hostname + ":" + port + "/" + dbname + "?binaryTransfer=true";
try {
Connection dbConnection = DriverManager.getConnection(dbUrl, username, password);
Statement statement = dbConnection.createStatement();
String selectSql = "SELECT * FROM information_schema.sql_features LIMIT 10";
ResultSet resultSet = statement.executeQuery(selectSql);
while (resultSet.next()) {
System.out.println(resultSet.getString("feature_name"));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}Use a third-party reporting tool to connect to the RDS instance
ApsaraDB RDS for PostgreSQL allows you to use third-party reporting tools to obtain, cleanse, and visualize data, and create models based on the data. This facilitates data analysis. This section provides an example on how to use Power BI Desktop that is provided by Microsoft to connect to an RDS instance. In this example, Power BI Desktop 2.112.1161.0 64-bit is used.
Download and install Power BI Desktop. For more information about the download method, see Obtain Power BI Desktop.
Start Power BI Desktop.
In the top navigation bar, click the Home tab and choose .
In the Get Data dialog box, choose and click Connect.

In the PostgreSQL database dialog box, configure the Server and Database parameters and click OK.
Parameter
Description
Server
The endpoint and port of the RDS instance.
The value is in the format of
Endpoint:Port number.If you want to connect to the RDS instance over an internal network, enter the internal endpoint and internal port of the RDS instance.
If you want to connect to the RDS instance over the Internet, enter the public endpoint and public port of the RDS instance.
You can view the preceding information on the Database Connection page of the RDS instance.
For more information, see View and change the endpoints and port numbers of an ApsaraDB RDS for PostgreSQL instance.
Database
The name of the database that you want to connect on the RDS instance. The database named postgres is the default system database. Do not perform operations on the postgres database. We recommend that you use another existing database of the RDS instance.
For more information about how to create and view a database on an RDS instance, see Create a database.
Configure the User name and Password parameters and click Connect.
You must set these parameters to the username and password of the RDS instance. NoteFor more information about how to create an account on an RDS instance, see Create an account and a database.
In the Encryption Support dialog box, click OK.
In the Navigator window, view information about the tables in the database. You can select the required table and click Load or Transform Data based on your business requirements.
FAQ
How do I connect from an ECS instance in a different region or under a different Alibaba Cloud account?
Two options are available:
VPC peering connections: establish a private network connection between two VPCs. Same-region peering is free of charge. For more information, see VPC peering connections.
Cloud Enterprise Network (CEN): connect VPCs across regions or accounts. For more information, see Connect VPCs in the same region, Connect VPCs in different regions, and Connect VPCs in different accounts.
How do I access RDS data from Function Compute?
Install third-party dependencies on Function Compute to query ApsaraDB RDS. For more information, see Install third-party dependencies.