psql is a common CLI tool that provides a variety of commands. You can download and install psql and use psql to connect to an AnalyticDB for PostgreSQL instance.
Prerequisites
-
You have obtained the endpoint of your AnalyticDB for PostgreSQL instance.
-
If your client is on an ECS instance in the same region and network type as your AnalyticDB for PostgreSQL instance, you can connect to it using its internal endpoint. You can find the internal endpoint in the Database Connection Information section on the instance details page of the AnalyticDB for PostgreSQL console.
-
If your client is deployed on an ECS instance that is in a different region or has a different network type than the AnalyticDB for PostgreSQL instance, or on a system outside of Alibaba Cloud, you need to apply for a public endpoint and use it to connect. For instructions on how to apply for a public endpoint, see Manage public endpoints.
-
-
You have obtained your client's IP address and added it to the IP address whitelist of your AnalyticDB for PostgreSQL instance. For more information, see Configure an IP address whitelist.
Download and install psql
For Red Hat Enterprise Linux (RHEL) 6 or 7 and CentOS 6 or 7, you can download the installation package of psql from the following links.
Engine version
Operating system version
Download link
AnalyticDB for PostgreSQL V7.0
RHEL 7 or CentOS 7
AnalyticDB for PostgreSQL V6.0
RHEL 7 or CentOS 7
RHEL 6 or CentOS 6
After you download the installation package, you must decompress the package and install the tool. Perform the following steps:
Run the following command to decompress the installation package in the directory of the package:
tar -xzvf <Name of the installation package>Sample command:
tar -xzvf adbpg_client_package.el7.x86_64.tar.gzRun the following command to switch to the bin directory:
cd adbpg_client_package/binThe bin directory includes client tools such as psql and pg_dump. Run the corresponding commands based on the reference documentation of each tool.
For information about how to connect to an instance by using psql, see the "Connect to an instance" section of this topic.
pg_dump is a logical backup tool for PostgreSQL. For information about how to use pg_dump, see pg_dump.
Connect to an instance
Use one of the following methods to connect to an instance:
Connection string
psql "host=yourgpdbaddress.gpdb.rds.aliyuncs.com port=5432 dbname=postgres user=gpdbaccount password=gpdbpassword"Specified parameters
psql -h yourgpdbaddress.gpdb.rds.aliyuncs.com -p 5432 -d postgres -U gpdbaccountParameters:
-h: the endpoint that is used to connect to the instance.
-p: the port number that is used to connect to the instance.
-d: the name of the database. The default value is postgres.
-U: the database account that is used to connect to the instance.
NoteYou can run the
psql --helpcommand to view more options. You can also run the\?command to view more commands that are supported in psql.
Enter the password to go to the psql CLI.
In addition, you can use the Docker toolbox in AnalyticDB for PostgreSQL, as shown in the following sample code. For information about how to install Docker, visit the Docker official website.
Run the tool image corresponding to AnalyticDB for PostgreSQL V6.0.
docker run -idt --name=adbpgcli aliadbpg/adbpgcli:v6.3.0
docker exec -it adbpgcli /bin/bash -lReferences
For information about how to use psql in Greenplum, see Greenplum psql.
You can also use psql in PostgreSQL. Take note of the differences of psql commands between Greenplum and PostgreSQL. For more information, see PostgreSQL psql.
For information about how to resolve issues if the
could not connect to server xxxerror occurs, see What do I do if I cannot connect to an instance?