Yandex Cloud
Search
Contact UsTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex Managed Service for PostgreSQL
  • Getting started
    • All guides
      • Pre-configuration
      • FQDNs of hosts
      • Connecting from applications
      • Code examples
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes

In this article:

  • Command line tools
  • Linux (Bash)
  • Windows (PowerShell)
  • Connecting with IAM authentication
  • Connecting from graphical IDEs
  • Connecting from Yandex WebSQL
  • Connecting from pgAdmin 4
  • Connecting from Looker Studio
  • Before you connect from a Docker container
  1. Step-by-step guides
  2. Connection
  3. Connecting from applications

Connecting to a PostgreSQL cluster from applications

Written by
Yandex Cloud
Updated at March 19, 2026
  • Command line tools
    • Linux (Bash)
    • Windows (PowerShell)
    • Connecting with IAM authentication
  • Connecting from graphical IDEs
  • Connecting from Yandex WebSQL
  • Connecting from pgAdmin 4
  • Connecting from Looker Studio
  • Before you connect from a Docker container

You can connect to a PostgreSQL cluster using command line tools, graphical IDEs, Yandex WebSQL, pgAdmin 4, Looker Studio, or a Docker container. To learn how to connect from your application code, see Code examples.

You can connect to ClickHouse® cluster hosts using SSL certificates. The examples below assume that the root.crt certificate is located in this directory:

  • /home/<home_directory>/.postgresql/ for Ubuntu.
  • $HOME\AppData\Roaming\postgresql for Windows

Before connecting, configure security groups for the cluster, if required.

Command line toolsCommand line tools

To see code examples with the host FQDN filled in, open the cluster page in the management console and click Connect.

Linux (Bash)Linux (Bash)

Before connecting, install the required dependencies:

sudo apt update && sudo apt install --yes postgresql-client
Connecting without SSL
Connecting with SSL
  1. Connect to a database:

    psql "host=c-<cluster_ID>.rw.mdb.yandexcloud.net \
          port=6432 \
          sslmode=disable \
          dbname=<DB_name> \
          user=<username> \
          target_session_attrs=read-write"
    

    After you run this command, enter the user password to complete connecting to the database.

  2. To check the connection, run the following query:

    SELECT version();
    
  1. Connect to a database:

    psql "host=c-<cluster_ID>.rw.mdb.yandexcloud.net \
          port=6432 \
          sslmode=verify-full \
          dbname=<DB_name> \
          user=<username> \
          target_session_attrs=read-write"
    

    After you run this command, enter the user password to complete connecting to the database.

  2. To check the connection, run the following query:

    SELECT version();
    

Windows (PowerShell)Windows (PowerShell)

Before connecting, install PostgreSQL for Windows using the same version that is installed in the cluster. Install only the Command Line Tools.

Connecting without SSL
Connecting with SSL
  1. Set the environment variables for the connection:

    $Env:PGSSLMODE="disable"; $Env:PGTARGETSESSIONATTRS="read-write"
    
  2. Connect to a database:

    & "C:\Program Files\PostgreSQL\<version>\bin\psql.exe" `
          --host=c-<cluster_ID>.rw.mdb.yandexcloud.net `
          --port=6432 `
          --username=<username> `
          <DB_name>
    

    After you run this command, enter the user password to complete connecting to the database.

  3. To check the connection, run the following query:

    SELECT version();
    
  1. Set the environment variables for the connection:

    $Env:PGSSLMODE="verify-full"; $Env:PGTARGETSESSIONATTRS="read-write"
    
  2. Connect to a database:

    & "C:\Program Files\PostgreSQL\<version>\bin\psql.exe" `
      --host=c-<cluster_ID>.rw.mdb.yandexcloud.net `
      --port=6432 `
      --username<username> `
      <DB_name>
    

    After you run this command, enter the user password to complete connecting to the database.

  3. To check the connection, run the following query:

    SELECT version();
    

Connecting with IAM authenticationConnecting with IAM authentication

You can connect to a PostgreSQL database via the Yandex Cloud CLI using IAM authentication. This method is available to Yandex accounts, federated accounts, and local users. When connecting with IAM authentication, you do not need to obtain an SSL certificate or specify the cluster hosts’ FQDNs.

Before connecting, install the PostgreSQL client:

sudo apt update && sudo apt install --yes postgresql-client

Set up your PostgreSQL cluster for connection:

Management console
  1. Navigate to the Managed Service for PostgreSQL service.
  2. Click the cluster name.
  3. Enable public access for the cluster hosts:
    1. Select the Hosts tab.
    2. Click in the first host's row and select Edit.
    3. Enable Public access.
    4. Repeat the same for the remaining hosts in the cluster.
  4. Assign a role to the user account connecting to the database:
    1. Select the Access bindings tab and click Assign roles.
    2. Enter the user account’s email.
    3. Click Add role and select the managed-postgresql.clusters.connector role.
    4. Click Save.
  5. Create a user named PostgreSQL:
    1. Select the Users tab.
    2. Click Create user.
    3. Select IAM as the authentication method.
    4. Select the account with the managed-postgresql.clusters.connector role.
    5. In the Database field, click .
    6. Select the database from the drop-down list.
    7. Click Save.

To connect to the PostgreSQL database, run this command:

yc managed-postgresql connect <cluster_name_or_ID> --db <DB_name>

Connecting from graphical IDEsConnecting 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

From graphical IDEs, you can only connect to public cluster hosts using an SSL certificate.

To avoid connection errors, save the certificate to a local folder that does not require administrator rights to access.

DataGrip
DBeaver
  1. Create a data source:
    1. Select File → New → Data Source → PostgreSQL.
    2. Specify the connection settings on the General tab:
      • User, Password: Database user name and password.

      • URL: Connection string:

        jdbc:postgresql://<special_FQDN>:6432/<DB_name>
        

        You can also use a list of all cluster host FQDNs in the connection string:

        jdbc:postgresql://<PostgreSQL_host_1>:6432,...,<PostgreSQL_host_N>:6432/<DB_name>
        
      • Click Download to download the connection driver.

    3. On the SSH/SSL tab:
      1. Enable Use SSL.
      2. In the CA file field, specify the path to the SSL certificate for your connection.
  2. Click Test Connection. If the connection is successful, you will see the connection status and information about the DBMS and driver.
  3. Click OK to save the data source.
  1. Create a new DB connection:
    1. In the Database menu, select New connection.
    2. Select PostgreSQL from the DB list.
    3. Click Next.
    4. Specify the connection settings on the Main tab:
      • Host: Master FQDN or regular host FQDN.
      • Port: 6432.
      • Database: Target database name.
      • Under Authentication, specify the DB user name and password.
    5. On the SSL tab:
      1. Enable Use SSL.
      2. In the Root certificate field, specify the path to the saved SSL certificate file.
  2. Click Test Connection .... If the connection is successful, you will see the connection status and information about the DBMS and driver.
  3. Click Done to save the database connection settings.

Connecting from Yandex WebSQLConnecting from Yandex WebSQL

You can use Yandex WebSQL to send SQL queries to Managed Service for PostgreSQL cluster databases.

WebSQL is a Yandex Cloud service that enables you to connect to managed database clusters, work with databases, tables, and schemas, and run queries. It is a web-based tool that requires no additional authorization and simplifies working with SQL commands by prompting the user.

To connect from WebSQL, activate the WebSQL access option in the cluster settings. You can enable it when creating or updating a cluster.

In the Managed Service for PostgreSQL cluster, a Connection Manager connection is automatically created for each database user, which you can use to connect to the database from WebSQL. If required, you can also create a new connection.

To connect to the database from WebSQL:

Management console
  1. In the management console, select the folder with the cluster you need.

  2. Go to Managed Service for PostgreSQL.

  3. Click the cluster name and go to the WebSQL tab.

  4. Select the required connection.

    The connection will open in WebSQL. To go to the query editor, select the required database.

    Check this PostgreSQL reference for supported queries.

    Note

    You cannot use SQL statements to perform operations requiring superuser privileges.

For more information on how to work with WebSQL, see these guides.

Connecting from pgAdmin 4Connecting from pgAdmin 4

Connection testing was performed for pgAdmin 4 version 7.0 on Ubuntu 20.04.

Connections from pgAdmin 4 are only permitted to publicly accessible cluster hosts and require an SSL certificate.

Create a new server connection:

  1. Select Object → Register → Server....

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

  3. In the Connection tab, specify the connection settings:

    • Host name/address: Master FQDN or regular host FQDN.
    • Port: 6432.
    • Maintenance database: Target database name.
    • Username: Username used to establish the connection.
    • Password: User password.
  4. 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.
  5. Click Save to save the server connection settings.

Your cluster will appear in the server list located in the navigation menu.

Connecting from Looker StudioConnecting from Looker Studio

Connections from Looker Studio are only permitted to publicly accessible hosts.

  1. Save the CA.pem server certificate to a local directory.

  2. In the same directory, generate a client certificate with a private key:

    openssl req -newkey rsa:2048 -nodes -keyout private.pem -out cert.pem
    

    During certificate creation, the program will ask you to modify several settings. Press Enter to keep the default values.

    You will see two files in your local directory: cert.pem and private.pem.

  3. On the Looker Studio navigation page, select Create → Data source.

  4. Select PostgreSQL.

  5. Fill out the fields as follows:

    • Host name or IP address: Master FQDN or regular host FQDN.
    • Port: 6432.
    • Database: DB to connect to.
    • Username: Username used to establish the connection.
    • Password: User password.
  6. Check Enable SSL and Enable client authentication.

  7. Specify the certificate files and the client private key in the appropriate fields:

    • Server certificate: Select the CA.pem file.
    • Client certificate: Select the cert.pem file.
    • Client private key: Select the private.pem file.
  8. Click Authenticate.

Before you connect from a Docker containerBefore you connect from a Docker container

To connect to a Managed Service for PostgreSQL cluster from a Docker container, add the following lines to the Dockerfile:

Connecting without SSL
Connecting with SSL
RUN apt-get update && \
    apt-get install postgresql-client --yes

See the Yandex Serverless Containers connection example in this tutorial.

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

Was the article helpful?

Previous
FQDNs of hosts
Next
Code examples
© 2026 Direct Cursus Technology L.L.C.