psql
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
Before you begin, make sure you have:
-
An endpoint for your instance. Use the internal endpoint if your client runs on an Elastic Compute Service (ECS) instance in the same region and network type as your AnalyticDB for PostgreSQL instance. Otherwise, apply for a public endpoint. To apply for one, see Manage public endpoints. To find the internal endpoint, go to the Basic Information page of your instance and look in the Database Connection Information section.
-
Your client IP address added to the instance whitelist. See Configure an IP address whitelist. If a login attempt fails with an IP access error, your client IP address is not yet in the whitelist — add it before proceeding.
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?