Connecting to a DB Instance from a Linux ECS over a Private Network
You can connect to your DB instance using a Linux ECS installed with a PostgreSQL client over a private network.
Step 1: Buy an ECS
- Log in to the management console and check whether there is an ECS available.
Figure 1 ECS
- Buy an ECS and select Linux (for example, CentOS) as its OS.
To download a PostgreSQL client to the ECS, bind an EIP to the ECS. The ECS must be in the same region, VPC, and security group as the TaurusDB for PostgreSQL instance for mutual communications.
For details about how to purchase a Linux ECS, see Purchasing an ECS in Custom Config Mode in Elastic Cloud Server User Guide.
- On the ECS Information page, check the region and VPC of the ECS.
Figure 2 ECS information
- On the Basic Information page of the TaurusDB for PostgreSQL instance, check the region and VPC of the instance.
Figure 3 Checking the region and VPC
- Check whether the ECS and the TaurusDB for PostgreSQL instance are in the same region and VPC.
- If they are in the same region and VPC, go to Step 2: Test Connectivity and Install the PostgreSQL Client.
- If they are not in the same region, purchase another ECS or DB instance. The ECS and DB instance in different regions cannot communicate with each other. To reduce network latency, deploy your DB instance in the region nearest to your workloads.
- If the ECS and DB instance are in different VPCs, change the VPC of the ECS to that of the DB instance. For details, see Changing a VPC.
Step 2: Test Connectivity and Install the PostgreSQL Client
- Log in to the ECS. For details, see Logging In to a Linux ECS Using VNC in Elastic Cloud Server User Guide.
- On the Instances page of the TaurusDB console, click the instance name to go to the Basic Information page.
- In the Network Information area, obtain the private IP address and database port of the DB instance.
Figure 4 Obtaining the private IP address and database port
- On the ECS, check whether the private IP address and database port of the DB instance can be connected.
curl -kv 192.168.0.7:5432
- If yes, network connectivity is normal.
- If no, check the security group rules.
- If in the security group of the ECS, there is no outbound rule with Destination set to 0.0.0.0/0 and Protocol & Port set to All, add an outbound rule for the private IP address and port of the DB instance.
- If in the security group of the DB instance, there is no inbound rule allowing the access from the private IP address and port of the ECS, add an inbound rule for the private IP address and port of the ECS. For details, see Configuring Security Group Rules.
- Install the PostgreSQL client.
Installation from source code: This installation method has no restrictions on TaurusDB for PostgreSQL instance versions and ECS OS types.
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 5 Checking the ECS image
- To use SSL, download OpenSSL to 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 then 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 the source code and then install the client.
cd postgresql-16.4 ./configure --without-icu --without-readline --without-zlib --with-openssl make -j 8 && make install
If --prefix is not specified, the default path is /usr/local/pgsql. The client can be installed in the simplest way.
Figure 6 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 7 Testing psql
- To use SSL, download OpenSSL to the ECS in advance.
Step 3: Connect to the DB Instance Using a CLI (Non-SSL Connection)
- Run the following command on the ECS to connect to the DB instance:
psql --no-readline -h <host> -p <port> "dbname=<database> user=<user>"
Example:
psql --no-readline -h 192.168.0.7 -p 5432 "dbname=postgres user=root"
- Enter the password of the database account as prompted.
Password:
If no error message is displayed, the connection is successful.
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