Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Relational Database Service/ Getting Started/ Getting Started with RDS for PostgreSQL/ Buying a DB Instance and Connecting to It Using the PostgreSQL Client

Buying a DB Instance and Connecting to It Using the PostgreSQL Client

Updated on 2025-01-10 GMT+08:00

You can connect to your DB instance using a Linux ECS installed with the PostgreSQL client over a private network.

You can use the PostgreSQL client to connect to your DB instance over a Secure Sockets Layer (SSL) connection. SSL encrypts connections to your DB instance, making in-transit data more secure.

SSL is enabled by default when you create an RDS for PostgreSQL DB instance and cannot be disabled after the instance is created.

Enabling SSL reduces the read-only and read/write performance of your instance by about 20%.

Operation Process

Process

Description

Preparations

Sign up for a HUAWEI ID, enable Huawei Cloud services, make sure you have a valid payment method configured, create IAM users, and grant them specific RDS permissions.

Step 1: Buy an RDS for PostgreSQL DB Instance

Select required basic settings and additional options and buy an RDS for PostgreSQL DB instance.

Step 2: Buy an ECS

If you want to use the PostgreSQL client to connect to a DB instance, you need to prepare a server, install the PostgreSQL client on the server, and run the connection command.

Purchase a Linux ECS that is in the same region and VPC as your DB instance.

Step 2: Test Connectivity and Install the PostgreSQL Client

Test the network connectivity between the ECS and the floating IP address and port of the DB instance, and install the PostgreSQL client on the ECS.

Step 4: Connect to the DB Instance Using Commands (SSL Connection)

Use a command-line interface (CLI) to connect to the DB instance using the floating IP address and port.

Preparations

  1. Sign up for a HUAWEI ID and enable Huawei Cloud services.
  2. Before purchasing DB instances, ensure that your account balance is sufficient. Top up your account if required.
  3. For fine-grained permissions management on Huawei Cloud resources, use Identity and Access Management (IAM) to create a user or user group and grant it specific operation permissions. For details, see Creating a User and Granting Permissions.

Step 1: Buy an RDS for PostgreSQL DB Instance

  1. Go to the Buy DB Instance page.
  2. On the Quick Config page, set basic parameters.
    NOTE:

    The following parameter settings are only for reference.

    Parameter

    Example Value

    Description

    Billing Mode

    Pay-per-use

    The billing mode of an instance.

    • Yearly/Monthly: A prepaid billing mode in which you pay for resources before using it. Bills are settled based on the subscription period. The longer the subscription, the bigger the discount. This mode is a good option for long-term, stable services.
    • Pay-per-use: A postpaid billing mode. You pay as you go and just pay for what you use. The DB instance usage is calculated by the second but billed every hour. This mode allows you to adjust resource usage easily. You neither need to prepare for resources in advance, nor end up with excessive or insufficient preset resources.

    Region

    CN-Hong Kong

    The region where your resources are located.

    NOTE:

    Products in different regions cannot communicate with each other through a private network. After a DB instance is created, the region cannot be changed. Therefore, exercise caution when selecting a region.

    DB Engine Version

    16

    The database version.

    DB Instance Type

    Primary/Standby

    The architecture type of an instance.

    Primary/Standby: An HA architecture. In a primary/standby pair, each instance has the same instance class. When a primary instance is being created, a standby instance is provisioned along with it to provide data redundancy. The standby instance is invisible to you after being created.

    Instance Class

    General-purpose | 4U | 8G

    The vCPU and memory of an instance.

    Storage

    Cloud SSD | 100GB

    The storage space of an instance.

    It contains the system overhead required for inodes, reserved blocks, and database operation.

    Disk Encryption

    Disable

    Enabling disk encryption improves data security, but slightly affects the read and write performance of the database.

    If a shared KMS key is used, the corresponding CTS events are createdatakey and decrydatakey. Only the key owner can receive the events.

  3. Complete advanced configurations.
    Figure 1 Additional Options

    Parameter

    Example Value

    Description

    VPC

    default_vpc

    The virtual network in which your instance is located. A VPC can isolate networks for different workloads.

    If no VPC is available, click Create VPC. After a VPC is created, click . For details, see Creating a VPC and Subnet.

    Subnet

    default_subnet

    A subnet provides dedicated network resources that are logically isolated from other networks for network security.

    Security Group

    default

    It can enhance security by controlling access to RDS for PostgreSQL from other services.

    Enterprise Project

    default

    If your account has been associated with an enterprise project, select the target project from the Enterprise Project drop-down list.

    For more information about enterprise projects, see Enterprise Management User Guide.

    Quantity

    1

    The number of instances to be created in a batch.

  4. Click Buy.
  5. Check the purchased DB instance.
    Figure 2 Instance successfully purchased

Step 2: Buy an ECS

  1. Go to the Elastic Cloud Server console.
  2. Check whether there is a Linux ECS that meets the requirements.
    NOTICE:

    RDS for PostgreSQL supports the following client installation methods:

    • Download the PostgreSQL client installation package. This method is recommended for PostgreSQL 15 and earlier versions. It has requirements on ECS images. For details, see the official PostgreSQL documentation.
    • Download the source code. This method has no requirements on PostgreSQL versions and ECS images.
    • If yes, go to 3.
    • If no, purchase an ECS and select Linux (for example, CentOS 7) as its OS.

      To download the PostgreSQL client to the ECS, bind an EIP to the ECS. The ECS must be in the same region, VPC, and security group as the RDS for PostgreSQL DB instance for mutual communications.

      For details about how to purchase a Linux ECS, see Purchasing a Custom ECS in Elastic Cloud Server User Guide.

  3. Check whether the ECS and RDS for PostgreSQL instance are in the same region and VPC.
    Figure 3 ECS information

    Figure 4 Overview
    • If they are not in the same region, purchase another ECS. The ECS and DB instance in different regions cannot communicate with each other. To reduce network latency, deploy your DB instance in the region nearest to your workloads.
    • If the ECS and DB instance are in different VPCs, change the VPC of the ECS to that of the DB instance. For details, see Changing a VPC.

Step 2: Test Connectivity and Install the PostgreSQL Client

  1. Log in to the ECS. For details, see Login Using VNC in the Elastic Cloud Server User Guide.
  2. On the Instances page of the RDS console, click the DB instance name.
  3. Choose Connectivity & Security from the navigation pane. In the Connection Information area, obtain the floating IP address and database port of the DB instance.
    Figure 5 Connection information
  4. On the ECS, check whether the floating IP address and database port of the DB instance can be connected.
    curl -kv 192.168.0.7:5432
    • If yes, network connectivity is normal.
    • If no, check the security group rules.
      • If in the security group of the ECS, there is no outbound rule with Destination set to 0.0.0.0/0 and Protocol & Port set to All, add an outbound rule for the floating IP address and port of the DB instance.
        Figure 6 ECS security group
      • If in the security group of the DB instance, there is no inbound rule allowing the access from the private IP address and port of the ECS, add an inbound rule for the private IP address and port of the ECS. For details, see Configuring Security Group Rules.
  5. Install the PostgreSQL client.

    The PostgreSQL community provides client installation methods for different OSs. You can download and install the client using the installation tool of the OS. This installation method is simple but has requirements on the ECS OS. It is only available to the OSs supported by the PostgreSQL community.

    In this example, CentOS 7 is used. Use the default installation tool of the OS to install the client (PostgreSQL 15 or earlier).

    Figure 7 Obtaining the installation tool

    Run the following commands:

    sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    sudo yum install -y postgresql15-server

    Check whether the installation is successful.

    psql -V
    Figure 8 Successful installation
  1. Log in to the ECS. For details, see Login Using VNC in the Elastic Cloud Server User Guide.
  2. On the Instances page of the RDS console, click the DB instance name.
  3. Choose Connectivity & Security from the navigation pane. In the Connection Information area, obtain the floating IP address and database port of the DB instance.
    Figure 9 Connection information
  4. On the ECS, check whether the floating IP address and database port of the DB instance can be connected.
    curl -kv 192.168.0.7:5432
    • If yes, network connectivity is normal.
    • If no, check the security group rules.
      • If in the security group of the ECS, there is no outbound rule with Destination set to 0.0.0.0/0 and Protocol & Port set to All, add an outbound rule for the floating IP address and port of the DB instance.
        Figure 10 ECS security group
      • If in the security group of the DB instance, there is no inbound rule allowing the access from the private IP address and port of the ECS, add an inbound rule for the private IP address and port of the ECS. For details, see Configuring Security Group Rules.
  5. Install the PostgreSQL client.

    Installation from source code: This installation method has no restrictions on the RDS PostgreSQL instance version and ECS OS.

    The following uses an ECS using the Huawei Cloud EulerOS 2.0 image as an example to describe how to install a PostgreSQL 16.4 client.

    Figure 11 Checking the ECS image
    1. To use SSL connection, download OpenSSL on the ECS in advance.
      sudo yum install -y openssl-devel
    2. Obtain the code download link, run wget to download the installation package to the ECS, or download the installation package to the local PC and upload it to the ECS.
      wget https://ftp.postgresql.org/pub/source/v16.4/postgresql-16.4.tar.gz
    3. Decompress the installation package.
      tar xf postgresql-16.4.tar.gz
    4. Compile and install the client.
      cd postgresql-16.4
      ./configure --without-icu --without-readline --without-zlib --with-openssl
      make -j 8 && make install
      NOTE:

      If --prefix is not specified, the default path is /usr/local/pgsql. The client can be installed in the simplest way.

      Figure 12 Compilation and installation
    5. Add the following code to the /etc/profile file to configure environment variables:
      export PATH=/usr/local/pgsql/bin:$PATH
      export LD_LIBRARY_PATH=/usr/local/pgsql/lib:$LD_LIBRARY_PATH
      source /etc/profile
    6. Test whether the psql is available.
      psql -V
      Figure 13 Testing psql
  1. Log in to the ECS. For details, see Login Using VNC in the Elastic Cloud Server User Guide.
  2. On the Instances page of the RDS console, click the DB instance name.
  3. Choose Connectivity & Security from the navigation pane. In the Connection Information area, obtain the floating IP address and database port of the DB instance.
    Figure 5 Connection information
  4. On the ECS, check whether the floating IP address and database port of the DB instance can be connected.
    curl -kv 192.168.0.7:5432
    • If yes, network connectivity is normal.
    • If no, check the security group rules.
      • If in the security group of the ECS, there is no outbound rule with Destination set to 0.0.0.0/0 and Protocol & Port set to All, add an outbound rule for the floating IP address and port of the DB instance.
        Figure 6 ECS security group
      • If in the security group of the DB instance, there is no inbound rule allowing the access from the private IP address and port of the ECS, add an inbound rule for the private IP address and port of the ECS. For details, see Configuring Security Group Rules.
  5. Install the PostgreSQL client.

    The PostgreSQL community provides client installation methods for different OSs. You can download and install the client using the installation tool of the OS. This installation method is simple but has requirements on the ECS OS. It is only available to the OSs supported by the PostgreSQL community.

    In this example, CentOS 7 is used. Use the default installation tool of the OS to install the client (PostgreSQL 15 or earlier).

    Figure 7 Obtaining the installation tool

    Run the following commands:

    sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    sudo yum install -y postgresql15-server

    Check whether the installation is successful.

    psql -V
    Figure 8 Successful installation
  1. Log in to the ECS. For details, see Login Using VNC in the Elastic Cloud Server User Guide.
  2. On the Instances page of the RDS console, click the DB instance name.
  3. Choose Connectivity & Security from the navigation pane. In the Connection Information area, obtain the floating IP address and database port of the DB instance.
    Figure 9 Connection information
  4. On the ECS, check whether the floating IP address and database port of the DB instance can be connected.
    curl -kv 192.168.0.7:5432
    • If yes, network connectivity is normal.
    • If no, check the security group rules.
      • If in the security group of the ECS, there is no outbound rule with Destination set to 0.0.0.0/0 and Protocol & Port set to All, add an outbound rule for the floating IP address and port of the DB instance.
        Figure 10 ECS security group
      • If in the security group of the DB instance, there is no inbound rule allowing the access from the private IP address and port of the ECS, add an inbound rule for the private IP address and port of the ECS. For details, see Configuring Security Group Rules.
  5. Install the PostgreSQL client.

    Installation from source code: This installation method has no restrictions on the RDS PostgreSQL instance version and ECS OS.

    The following uses an ECS using the Huawei Cloud EulerOS 2.0 image as an example to describe how to install a PostgreSQL 16.4 client.

    Figure 11 Checking the ECS image
    1. To use SSL connection, download OpenSSL on the ECS in advance.
      sudo yum install -y openssl-devel
    2. Obtain the code download link, run wget to download the installation package to the ECS, or download the installation package to the local PC and upload it to the ECS.
      wget https://ftp.postgresql.org/pub/source/v16.4/postgresql-16.4.tar.gz
    3. Decompress the installation package.
      tar xf postgresql-16.4.tar.gz
    4. Compile and install the client.
      cd postgresql-16.4
      ./configure --without-icu --without-readline --without-zlib --with-openssl
      make -j 8 && make install
      NOTE:

      If --prefix is not specified, the default path is /usr/local/pgsql. The client can be installed in the simplest way.

      Figure 12 Compilation and installation
    5. Add the following code to the /etc/profile file to configure environment variables:
      export PATH=/usr/local/pgsql/bin:$PATH
      export LD_LIBRARY_PATH=/usr/local/pgsql/lib:$LD_LIBRARY_PATH
      source /etc/profile
    6. Test whether the psql is available.
      psql -V
      Figure 13 Testing psql

Step 4: Connect to the DB Instance Using Commands (SSL Connection)

  1. On the Instances page of the RDS console, click the DB instance name.
  2. In the navigation pane, choose Connectivity & Security.
  3. In the Connection Information area, click next to the SSL field to download Certificate Download.zip, and extract the root certificate ca.pem and bundle ca-bundle.pem from the package.
    Figure 14 Downloading a certificate
  4. Upload ca.pem to the ECS.
    NOTE:
    • TLS v1.2 or later is recommended. Versions earlier than TLS v1.2 have security risks.
    • The recommended protocol algorithm is EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EDH+aRSA+AESGCM:EDH+aDSS+AESGCM:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!SRP:!RC4. Using other options have security risks.
    • ca-bundle.pem contains both the new certificate provided as of April 2017 and the old certificate.
    • Both ca.pem and ca-bundle.pem can be used for SSL connections because ca-bundle.pem contains ca.pem.
  5. Run the following command on the ECS to connect to the DB instance:
    psql --no-readline -h <host> -p <port> "dbname=<database> user=<user> sslmode=verify-ca sslrootcert=<ca-file-directory>"

    Example:

    psql --no-readline -h 192.168.0.7 -p 5432 "dbname=postgres user=root sslmode=verify-ca sslrootcert=/root/ca.pem"
    Table 1 Parameter description

    Parameter

    Description

    <host>

    Floating IP address obtained in 3.

    <port>

    Database port obtained in 3. The default value is 5432.

    <database>

    Name of the database to be connected. The default database name is postgres.

    <user>

    Administrator account root.

    <ca-file-directory>

    Directory of the CA certificate used for the SSL connection. This certificate should be stored in the directory where the command is executed.

    sslmode

    SSL connection mode. Set it to verify-ca to use a CA to check whether the service is trusted.

  6. Enter the password of the database account as prompted.
    Password:
    If the following information is displayed, the connection is successful.
    SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)

Follow-up Operations

After logging in to the DB instance, you can create or migrate databases.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback