Using CLI to Connect to a FlexusRDS for PostgreSQL Instance
Scenarios
You can connect to your DB instance using the psql command-line interface (CLI) from a FlexusX instance with the PostgreSQL client installed.
Connecting to a FlexusRDS for PostgreSQL Instance Through a Client (PostgreSQL 15 and Earlier Versions)
- Log in to the FlexusX instance in the same region as your FlexusRDS DB instance.
- 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 1 Obtaining the installation toolRun 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 2 Successful installation - Run the following command on the FlexusX instance to connect to the FlexusRDS for PostgreSQL DB instance:
psql --no-readline -U<user>-h<host>-p<port>-d<datastore>-W
Example:
psql --no-readline -U root -h 192.168.0.44 -p 5432 -d postgres -WTable 1 Parameter description Parameter
Description
<host>
- Private network connection (recommended): Click the DB instance name and obtain the floating IP address on the Overview page.
- Public network connection: Click the DB instance name and obtain the EIP on the Overview page. For details about how to bind an EIP to a DB instance, see Binding an EIP to a FlexusRDS for PostgreSQL Instance or Unbinding an EIP from a FlexusRDS for PostgreSQL Instance.
To connect to your DB instance through an EIP, add the EIP and port 5432 to an inbound rule of security group sg-default-smb. For details, see Adding a Security Group Rule.
NOTE:
If the FlexusX instance and the FlexusRDS for PostgreSQL DB instance are in the same region and VPC, you are advised to connect to the DB instance through a private network for higher security.
If a DB instance cannot be accessed through a private network, connect to it through a public network.
<port>
5432
<user>
root
<datastore>
postgres
- When the following information is displayed, enter the password of user root:
Enter password:
Connecting to a FlexusRDS for PostgreSQL Instance Using Source Code (No Restrictions on the Version)
- Log in to the FlexusX instance in the same region as your FlexusRDS DB instance.
- 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 3 Checking the ECS image- To use SSL connection, download OpenSSL on the ECS in advance.
sudo yum install -y openssl-devel
- 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
- Decompress the installation package.
tar xf postgresql-16.4.tar.gz
- 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 4 Compilation and installation - 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
- Test whether the psql is available.
psql -V
Figure 5 Testing psql
- To use SSL connection, download OpenSSL on the ECS in advance.
- Run the following command on the FlexusX instance to connect to the FlexusRDS for PostgreSQL DB instance:
psql --no-readline -U<user>-h<host>-p<port>-d<datastore>-W
Example:
psql --no-readline -U root -h 192.168.0.44 -p 5432 -d postgres -WTable 2 Parameter description Parameter
Description
<host>
- Private network connection (recommended): Click the DB instance name and obtain the floating IP address on the Overview page.
- Public network connection: Click the DB instance name and obtain the EIP on the Overview page. For details about how to bind an EIP to a DB instance, see Binding an EIP to a FlexusRDS for PostgreSQL Instance or Unbinding an EIP from a FlexusRDS for PostgreSQL Instance.
To connect to your DB instance through an EIP, add the EIP and port 5432 to an inbound rule of security group sg-default-smb. For details, see Adding a Security Group Rule.
NOTE:
If the FlexusX instance and the FlexusRDS for PostgreSQL DB instance are in the same region and VPC, you are advised to connect to the DB instance through a private network for higher security.
If a DB instance cannot be accessed through a private network, connect to it through a public network.
<port>
5432
<user>
root
<datastore>
postgres
- When the following information is displayed, enter the password of user root:
Enter password:
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