Connecting to a DB Instance Through psql
You can use the PostgreSQL client psql to connect to a DB instance through a non-SSL connection or an SSL connection. The SSL connection is encrypted and therefore more secure.
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 the PostgreSQL Client?
Non-SSL Connection
- Log in to the ECS or the device that can access RDS.
- Run the following command to connect to the DB instance:
psql --no-readline -U<user>-h<host>-p<port>-d<datastore>-W
Table 1 Parameter description Parameter
Description
<user>
Indicates the username of the RDS database account. The default administrator is root.
<host>
Indicates the IP address of the primary DB instance. To obtain this parameter, go to the Basic Information page of the DB instance. The IP address can be found on the EIPs page.
<port>
Indicates the 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.
<datastore>
Indicates the name of the database (the default database name is postgres).
The parameter -W indicates that a password must be entered for the connection. After running this command, you will be prompted to enter a password.
Example:
Run the following command as user root to connect to a DB instance:
psql --no-readline -U root -h 192.168.0.44 -p 5432 -d postgres -W
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