nav-img
Advanced

Connecting to a DB Instance Through a Private Network

You can use the PostgreSQL client psql 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%.

Prerequisites

  1. You have logged in to an ECS.
    • You should ensure that:
      • The ECS and your DB instance are in the same VPC.
      • The ECS is 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 target 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 rules allow the access from the ECS, you can connect to the DB instance through the ECS.

          If the security group rules do not allow the access from the ECS, you need to add a security group rule, allowing the ECS to access the DB instance.

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

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 Service List. Under Database, click Relational Database Service.
  4. Click the DB instance name to go to the Basic Information page. In the DB Information area, click next to the SSL field to download the root certificate and certificate bundle.
  5. Import the root certificate to the ECS or save it to the device to be connected to the DB instance.

    For details about how to import the root certificate to a Linux ECS, see How Do I Import the SSL Certificate of an RDS Instance to a Windows or Linux Server?

  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>

    Floating IP address of the DB instance to be connected. 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. The default value is 5432. To obtain this parameter value, go to the Basic Information page of the DB instance and find the port number next to 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 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.

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

    Password:

    For example, to connect to a DB instance through an SSL connection as 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 the connection result. The SSL connection is established if information similar to the following is displayed:

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