Relational Database ServiceRelational Database Service

Compute
Elastic Cloud Server
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
Domain Name Service
VPC Endpoint
Cloud Connect
Enterprise Switch
Security & Compliance
Anti-DDoS
Web Application Firewall
Host Security Service
Data Encryption Workshop
Database Security Service
Advanced Anti-DDoS
Data Security Center
Container Guard Service
Situation Awareness
Managed Threat Detection
Compass
Cloud Certificate Manager
Anti-DDoS Service
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GaussDB NoSQL
GaussDB(for MySQL)
Distributed Database Middleware
GaussDB(for openGauss)
Developer Services
ServiceStage
Distributed Cache Service
Simple Message Notification
Application Performance Management
Application Operations Management
Blockchain
API Gateway
Cloud Performance Test Service
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
DevCloud
ProjectMan
CodeHub
CloudRelease
CloudPipeline
CloudBuild
CloudDeploy
Cloud Communications
Message & SMS
Cloud Ecosystem
Marketplace
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP License Service
Support Plans
Customer Operation Capabilities
Partner Support Plans
Professional Services
enterprise-collaboration
Meeting
IoT
IoT
Intelligent EdgeFabric
DeveloperTools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Updated at: Apr 02, 2022 GMT+08:00

Using psql CLI to Connect to an Instance Through a Private Network

You can use the PostgreSQL client to connect to an instance through an SSL connection. The SSL connection is encrypted and therefore 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.

Prerequisites

  1. You have logged in to an ECS.
    • For details on how to create and log in to an ECS, see Purchasing an ECS and Logging In to an ECS.
    • To connect to an RDS instance through an ECS, make sure that:
      • The ECS and DB instance must be in the same VPC.
      • The ECS must be allowed by the security group to access the DB instance.
        • If the security group with which the DB instance is associated is the default security group, you do not need to configure security group rules.
        • If the security group with which the DB instance is associated is not the default security group, check whether the security group rules allow the ECS to connect to the DB instance. For details, see Configuring Security Group Rules.

          If the security group rules allow the access from the ECS, the ECS can connect to the DB instance.

          If the security group rules do not allow the access from the ECS, you need to add a security group rule. The ECS must be allowed by the security group to access the DB instance.

  2. You have installed a database client to connect to DB instances.

    For details, see Installing the PostgreSQL Client.

SSL Connection

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click in the upper left corner of the page and choose Database > Relational Database Service. The RDS console is displayed.
  4. On the Instance Management page, click the target DB instance. In the DB Information area on the Basic Information page, click in the SSL field to download the root certificate or certificate bundle.
  5. Upload the root certificate to the ECS or save it to the device to be connected to the DB instance.

    Import the root certificate to the Linux OS on the ECS.For details, see How Can I Import the Root Certificate to the Windows or Linux OS?

  6. Connect to the RDS DB instance. The Linux OS is used as an example.

    psql --no-readline -h <host> -p <port> "dbname=<database> user=<user> sslmode=verify-ca sslrootcert=<ca-file-directory>"

    Table 1 Parameter description

    Parameter

    Description

    <host>

    IP address of the primary DB instance. To obtain this parameter value, go to the Basic Information page of the DB instance and view the floating IP address in the Connection Information area (if the DB instance is to be accessed through an ECS).

    <port>

    Database port in use. The default value is 5432. To obtain this parameter value, go to the Basic Information page of the DB instance. The port number can be found in the Database Port field in the Connection Information area.

    <database>

    Name of the database (the default database name is postgres).

    <user>

    Username of the RDS database account. The default administrator is root.

    <ca-file-directory>

    Directory of the CA certificate for the SSL connection. The 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.

    Enter the password of the database account if the following information is prompted:

    Password:

    For example, to connect to a DB instance through an SSL connection as user root, run the following command:

    psql --no-readline -h 192.168.0.44 -p 5432 "dbname=postgres user=root sslmode=verify-ca sslrootcert=/root/ca.pem"

    Password:

  7. Log in to the database and check whether information similar to the following is displayed:

    SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)

Did you find this page helpful?

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel