Connecting to a DB Instance Through psql
You can use a 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
- An EIP has been bound to the target DB instance and security group rules have been configured.
- Bind an EIP to the target DB instance.
For details about how to bind an EIP, see Binding an EIP.
- Obtain the IP address of a local device.
- Configure security group rules.
Add the IP address obtained in 1.b and the instance port to the inbound rule of the security group.
For details about how to configure security group rules, see Configuring Security Group Rules.
- Run the ping command to ping the EIP bound in 1.a.
- Bind an EIP to the target DB instance.
- You have installed a database client to connect to DB instances.
For details, see How Can I Install a PostgreSQL Client?
SSL Connection
- Log in to the management console.
- Click in the upper left corner and select a region and a project.
- Click Service List. Under Database, click Relational Database Service. The RDS console is displayed.
- On the Instance Management page, click the instance name to go to the Basic Information page.
- Click next to SSL to download the root certificate or certificate bundle.
- Upload 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 the Linux OS on the ECS, see How Can I Import the Root Certificate to a Windows or Linux OS?
- Connect to an 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>
EIP of the DB instance to be connected.
<port>
Database port in use. The default value is 5432. To obtain this parameter, 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 displayed:
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:
- The SSL connection is established if information similar to the following is displayed after you log in to the database:
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot