RDS PostgreSQL

Connecting to an RDS-PostgreSQL Instance Through a psql Command Line Client

2025-06-17 06:56:36

Connecting to an Instance Through a psql Command Line Client (Intranet Connection)

RDS-PostgreSQL allows you to connect to instances through PostgreSQL clients in an Intranet.

Prerequisites
1. Log in to the ECS.

           Create an instance and log in to the ECS.

           To connect to an RDS-PostgreSQL instance through an ECS, you must ensure that:

          The ECS and the target instance must be in the same VPC.

          The ECS must be allowed by the security group to access the target instance.

           If the security group to which the target instance belongs is the default security group, you do not need to configure the rules. (Only some resource pools support the change of instance security group. For other resource pools, the default security group rules apply).

           If the security group to which the target instance belongs is not the default security group, check whether the security group rules allow access by the ECS. For specific operations, see Configuration Guidelines for VPC Security Groups.

2. Install the PostgreSQL client.

For details, see Basic Usage of Database-Installing PostgreSQL Client.

Command Line Connection

After logging into the cloud server, execute the command as follows:

psql -h <host_name> -p <host_port> -U <user_name> -d <database_name>

Parameter Description:

<host_name>: Host IP: the VIP column information of the instance you want to connect in the List of Instances corresponding to the cluster on the List of Instances page of the Console page.

<host_port>: The database port is the database port on the Instance Details page.

<user_name>: User name: the RDS-PostgreSQL database account (the default administrator account is root).

<database_name>: Database name: the database inside the RDS-PostgreSQL instance. The default initialized database name is postgres.

Example:

psql -h xx.xx.xx.xx -p xxxx -U root –d postgres

Connecting to an Instance Through a psql Command Line Client (Public Network Connection)

RDS-PostgreSQL allows you to connect to instances through PostgreSQL clients in a public network.

Prerequisites
1. Bind the elastic IP and set security group rules.

           To order and create an EIP, see Applying for an Elastic IP.

           Obtain the IP address of the local device to facilitate the configuration of security groups.

           Configure the security group rules and add the local device IP address and the target instance port to the allowed access range of the security group. For security group settings, see Adding Security Group Rules.

2. Install the PostgreSQL client

For details, see Basic Usage of Database-Installing PostgreSQL Client.

Command Line Connection

Connect to an RDS-PostgreSQL instance through the public network. Taking a Linux system as an example, execute the following command:

psql -h <host_name> -p <host_port> -U <user_name> -d <database_name>

Parameter Description:

<host_name>: Host IP, that is the Elastic IP under Network on the List of Instances > Instance Details page of the Console.

<host_port>: Database port, that is the database port on the Instance Details page.

<user_name>: User name, that is the PostgreSQL database account (the default administrator account is root).

<database_name>: Database name, that is the database inside the PostgreSQL instance. The default initialized database name is postgres.

Example:

psql -h xx.xx.xx.xx -p xxxx -U root –d postgres


aroh1pwiVhvn