psql is a command-line interface (CLI) tool for connecting to and querying an AnalyticDB for PostgreSQL instance.
Prerequisites
Before you begin, ensure that you have:
The internal or public endpoint of the AnalyticDB for PostgreSQL instance
Internal endpoint: Use when your client runs on an Elastic Compute Service (ECS) instance in the same region and the same network type as the AnalyticDB for PostgreSQL instance. To find the internal endpoint, go to the AnalyticDB for PostgreSQL console, open the instance, and check internal endpoint in the Database Connection Information section of the Basic Information page.
Public endpoint: Use when your client runs on an ECS instance in a different region or network type, or on a system outside Alibaba Cloud. Apply for a public endpoint first. For details, see Manage public endpoints.
The IP address of your client added to an IP address whitelist of the instance. For details, see Configure an IP address whitelist
Download and install psql
The installation packages support Red Hat Enterprise Linux (RHEL) 6 or 7 and CentOS 6 or 7.
Download the installation package for your engine version and operating system:
Engine version Operating system Download link AnalyticDB for PostgreSQL V7.0 RHEL 7 or CentOS 7 adbpg7_client_package.el7.x86_64.tar.gz AnalyticDB for PostgreSQL V6.0 RHEL 7 or CentOS 7 ADBPG_client_package_el7 AnalyticDB for PostgreSQL V6.0 RHEL 6 or CentOS 6 ADBPG_client_package_el6 Decompress the package:
tar -xzvf <installation-package-name>Example:
tar -xzvf adbpg_client_package.el7.x86_64.tar.gzSwitch to the
bindirectory:cd adbpg_client_package/binThe
bindirectory containspsqlandpg_dump.pg_dumpis a logical backup tool for PostgreSQL. For usage details, see pg_dump.
Connect to an instance
Before running the connection command, collect the following values from the Database Connection Information section of the Basic Information page in the AnalyticDB for PostgreSQL console:
Endpoint (internal or public)
Port
Database name (default:
postgres)Database account and password
Connect using either of the following methods:
Connection string:
psql "host=yourgpdbaddress.gpdb.rds.aliyuncs.com port=5432 dbname=postgres user=gpdbaccount password=gpdbpassword"Separate parameters:
psql -h yourgpdbaddress.gpdb.rds.aliyuncs.com -p 5432 -d postgres -U gpdbaccount| Parameter | Description |
|---|---|
-h | Endpoint of the instance |
-p | Port number |
-d | Database name. Default: postgres |
-U | Database account |
Enter the password when prompted to go to the psql CLI.
psql --help to view all available options. Inside the psql session, run \? to view all supported psql commands.Connect using Docker (V6.0 only)
As an alternative for AnalyticDB for PostgreSQL V6.0, use the Docker toolbox. Install Docker first. For instructions, see the Docker official website.
Run the following commands:
docker run -idt --name=adbpgcli aliadbpg/adbpgcli:v6.3.0
docker exec -it adbpgcli /bin/bash -lReferences
Greenplum psql — psql usage in Greenplum
PostgreSQL psql — psql usage in PostgreSQL. Note that some psql commands differ between Greenplum and PostgreSQL.
What do I do if I cannot connect to an instance? — Troubleshooting for the
could not connect to servererror