This topic describes how to connect to a Hologres instance and use the standard PostgreSQL statements for data analytics from the PostgreSQL client.
Prerequisites
- The PostgreSQL client is installed. If you have not installed the client, go to the PostgreSQL official website, download the installation package of version 11 or later based on your operating system, and then install the client as prompted.
- The environment variables of your operating system are set. To set the environment
variables, perform the following steps:
- Procedure for the Windows operating system
- Open the Advanced tab and then click Environment Variables in the lower-right corner. dialog box. Click the
- Set the Path variable to the bin subdirectory of the installation directory.
- Click OK.
- For more information about how to set the environment variables in the macOS operating system, see Setting Up Your Environment.
Note You do not need to set environment variables in the Linux operating system. - Procedure for the Windows operating system
Procedure
- Execute the following SQL statement if you are using the Linux operating system:
psql -h <Endpoint> -p <Port> -U <AccessKey ID> -d <Database>
Enter the AccessKey secret of your Alibaba Cloud account as prompted.
- Execute the following SQL statement if you are using the macOS operating system:
PGUSER=<AccessKey ID> PGPASSWORD=<AccessKey Secret> psql -p <Port> -h <Endpoint> -d <Database>
- Execute the following SQL statements if you are using the Windows operating system:
Server [localhost]: Endpoint Database [postgres]: Database Port [5432]: Port Username [postgres]: <AccessKey ID> Password of the <AccessKey ID> user: <AccessKey Secret>
Parameter | Description |
---|---|
AccessKey ID | The AccessKey ID of your Alibaba Cloud account.
You can obtain the AccessKey ID in the User Management console. |
AccessKey Secret | The AccessKey secret of your Alibaba Cloud account.
You can obtain the AccessKey secret in the User Management console. |
Port | The public port number of the Hologres instance.
Example: |
Endpoint | The public endpoint of the Hologres instance.
Example: |
Database | The name of the database that you want to access from the PostgreSQL client.
After you purchase a Hologres instance, a database named postgres is created by default. You can connect to the postgres database, but limited resources are allocated to this database. We recommend that you go to the Hologres console and create a database for business purposes. For more information, see Create a database. Example: |