All Products
Search
Document Center

AnalyticDB:psql

Last Updated:Feb 19, 2024

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

  • The internal or public endpoint of an AnalyticDB for PostgreSQL instance is obtained.

    • If your client is deployed on an Elastic Compute Service (ECS) instance that resides in the same region and uses the same network type as the AnalyticDB for PostgreSQL instance, you can use the internal endpoint to connect to the AnalyticDB for PostgreSQL instance. Log on to the AnalyticDB for PostgreSQL console. In the Database Connection Information section of the Basic Information page, view the internal endpoint of the instance.

    • If your client is deployed on an ECS instance that resides in a different region or uses a different network type from your AnalyticDB for PostgreSQL instance or a system outside Alibaba Cloud, you must apply for a public endpoint and then use the public endpoint to connect to the AnalyticDB for PostgreSQL instance. For more information about how to apply for a public endpoint, see Manage public endpoints.

  • The IP address of your client is added to an IP address whitelist of the AnalyticDB for PostgreSQL instance. For more information, see Configure an IP address whitelist.

Download and install psql

  1. 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

    adbpg7_client_package.el7.x86_64.tar.gz

    AnalyticDB for PostgreSQL V6.0

    RHEL 7 or CentOS 7

    ADBPG_client_package_el7

    RHEL 6 or CentOS 6

    ADBPG_client_package_el6

  2. After you download the installation package, you must decompress the package and install the tool. Perform the following steps:

    1. 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.gz
    2. Run the following command to switch to the bin directory:

      cd adbpg_client_package/bin
    3. The 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

  1. 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 gpdbaccount

      Parameters:

      • -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.

      Note

      You can run the psql --help command to view more options. You can also run the \? command to view more commands that are supported in psql.

  2. 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 -l

References