Connecting to an Greenplum® cluster from applications
This section provides settings for connecting to Yandex MPP Analytics for PostgreSQL cluster hosts using command line tools, graphical IDEs, pgAdmin 4, or a Docker container. To learn how to connect from your application code, see Code examples.
Creating a Greenplum® cluster does not entail creating a user database. To test the connection, use the postgres service database.
To connect to a publicly accessible cluster, prepare an SSL certificate. In these examples, the root.crt SSL certificate is located in the following directory:
/home/<home_directory>/.postgresql/for Ubuntu.$HOME\AppData\Roaming\postgresqlfor Windows.
You can connect to a cluster using either a master host's regular FQDN or a primary master host's special FQDN. To learn how to get a host's FQDN, see this guide.
Command line tools
To see code examples with the host FQDN filled in, open the cluster page in the management console
Linux (Bash)
Before connecting, install the required dependencies:
sudo apt update && sudo apt install --yes postgresql-client
Connect to a database:
psql "host=c-<cluster_ID>.rw.mdb.yandexcloud.net \
port=6432 \
sslmode=disable \
dbname=postgres \
user=<username> \
target_session_attrs=read-write"
psql "host=c-<cluster_ID>.rw.mdb.yandexcloud.net \
port=6432 \
sslmode=verify-full \
dbname=postgres \
user=<username> \
target_session_attrs=read-write"
After you run this command, enter the user password to complete the connection procedure.
To check the connection, run the following query:
SELECT version();
Windows (PowerShell)
Before connecting, install the current version of PostgreSQL for Windows
Connect to a database:
& "C:\Program Files\PostgreSQL\<version>\bin\psql.exe" "`
host=c-<cluster_ID>.rw.mdb.yandexcloud.net `
port=6432 `
sslmode=disable `
dbname=postgres `
user=<username>"
& "C:\Program Files\PostgreSQL\<version>\bin\psql.exe" "`
host=c-<cluster_ID>.rw.mdb.yandexcloud.net `
port=6432 `
sslmode=verify-full `
dbname=postgres `
user=<username>"
After you run this command, enter the user password to complete the connection procedure.
To check the connection, run the following query:
SELECT version();
Connecting with IAM authentication
You can connect to a Greenplum® database from the Yandex Cloud CLI using IAM authentication. To do this, associate a Yandex account or federated account with the Greenplum® user. You can only use IAM authentication to connect to a public cluster, in which case you do not need an SSL certificate.
Before connecting, install the PostgreSQL client:
sudo apt update && sudo apt install --yes postgresql-client
Set up your Yandex MPP Analytics for PostgreSQL cluster for connection:
-
Go to Yandex MPP Analytics for PostgreSQL.
-
Click the cluster name.
-
Assign a role to the user account connecting to the database:
- Select the Access bindings tab and click Assign roles.
- Enter the user account’s email.
- Click
Add role and select themanaged-greenplum.clusters.connectorrole. - Click Save.
-
Create a Greenplum® user and grant them access to the database:
-
Connect to the Yandex MPP Analytics for PostgreSQL cluster using any method of your choice.
-
Create a Greenplum® user, specifying their account’s email as their username.
CREATE ROLE "<account_email>" LOGIN ENCRYPTED PASSWORD '<password>'; -
If required, configure privileges and attributes of the Greenplum® user you created.
-
-
Add the authentication rule for the user you created:
-
Select the User authentication tab.
-
Click Edit rules.
-
Click
Add rule and specify its settings:- Type: Interconnect type.
- Database: Database name.
- User: User account's email.
- Address (CIDR/FQDN): IP range to connect to the database from.
- Method:
iam.
-
Click Save.
-
To connect to the Greenplum® database, run this command:
yc managed-greenplum connect <cluster_name_or_ID> --db <DB_name>
Connecting from graphical IDEs
Connections were tested in the following environment:
- Ubuntu 20.04, DBeaver:
22.2.4 - MacOS Monterey 12.7:
- JetBrains DataGrip:
2023.3.4 - DBeaver Community:
24.0.0
- JetBrains DataGrip:
You can only use graphical IDEs to connect to a public cluster using SSL certificates.
To avoid connection errors, save the certificate
-
Create a data source:
-
Select File → New → Data Source → Greenplum®.
-
On the General tab:
-
Configure the connection as follows:
-
User, Password: DB user name and password.
-
URL: Connection string. Use the special primary master FQDN:
jdbc:postgresql://c-<cluster_ID>.rw.mdb.yandexcloud.net:6432/<DB_name>
-
-
Click Download to download the connection driver.
-
-
On the SSH/SSL tab:
- Enable Use SSL.
- In the CA file field, specify the path to the SSL certificate for your connection.
-
-
Click Test Connection. If the connection is successful, you will see the connection status and information about the DBMS and driver.
-
Click OK to save the data source.
- Create a new DB connection:
- In the Database menu, select New connection.
- Select Greenplum® from the DB list.
- Click Next.
- Specify the connection settings on the Main tab:
- Host: Special FQDN of the primary master,
c-<cluster_ID>.rw.mdb.yandexcloud.net. - Port:
6432. - Database: DB to connect to.
- Under Authentication, specify the DB user name and password.
- Host: Special FQDN of the primary master,
- On the SSL tab:
- Enable Use SSL.
- In the Root certificate field, specify the path to the saved SSL certificate file.
- Click Test Connection .... If the connection is successful, you will see the connection status and information about the DBMS and driver.
- Click Done to save the database connection settings.
Connecting from pgAdmin 4
The connection has been checked for pgAdmin 4
You can only use pgAdmin 4 to connect to public cluster hosts using an SSL certificate.
Create a new server connection:
-
Select Object → Register → Server....
-
On the General tab, in the Name field, specify the cluster name to be shown in the pgAdmin 4 interface. You can set any name.
-
In the Connection tab, specify the connection settings:
- Host name/address: Special master host FQDN or regular host FQDN.
- Port:
6432. - Maintenance database: Name of the
postgresmaintenance database. - Username: Username for connection.
- Password: User password.
-
In the Parameters tab:
- Set the SSL mode parameter to
verify-full. - Add a new Root certificate parameter and specify the path to the saved SSL certificate file in it.
- Set the SSL mode parameter to
-
Click Save to save the server connection settings.
As a result, the cluster appears in the server list in the navigation menu.
To monitor the cluster status, use Yandex Monitoring rather than the Dashboard tab in pgAdmin 4, since the latter might generate an error:
column "wait_event_type" does not exist LINE 10: wait_event_type || ': ' || wait_event AS wait_event, ^
This error does not occur in other pgAdmin 4 tabs.
Before you connect from a Docker container
To connect to a Greenplum® cluster from a Docker container, add the following lines to the Dockerfile:
RUN apt-get update && \
apt-get install postgresql-client --yes
RUN apt-get update && \
apt-get install wget postgresql-client --yes && \
mkdir --parents ~/.postgresql && \
wget "https://storage.yandexcloud.net/cloud-certs/CA.pem" \
--output-document ~/.postgresql/root.crt && \
chmod 0655 ~/.postgresql/root.crt
Greenplum® and Greenplum Database® are registered trademarks or trademarks of Broadcom Inc. in the United States and/or other countries.