[Yandex Cloud documentation](../index.md) > [Yandex MPP Analytics for PostgreSQL](index.md) > Getting started

# Getting started with Yandex MPP Analytics for PostgreSQL

To get started:

1. [Create a cluster](#create-cluster).
1. [Get its ID](#get-cluster-id).
1. [Connect to the cluster](#connect).
1. [Create a database](#create-db).
1. [Run a few queries](#query-db).

To connect to the cluster and work with databases, you will need the following tools:

* [DBeaver](https://dbeaver.io/) graphical IDE.
* `psql` console client.

For more tools you can use to work with Yandex MPP Analytics for PostgreSQL, see [Pre-configuring a Yandex MPP Analytics for PostgreSQL cluster connection](operations/connect/index.md).


## Getting started {#before-you-begin}

1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or sign up if not signed up yet.
1. If you do not have a folder yet, create one:

    1. In the [management console](https://console.yandex.cloud), in the top panel, click ![image](../_assets/console-icons/layout-side-content-left.svg) or ![image](../_assets/console-icons/chevron-down.svg) and select the [cloud](../resource-manager/concepts/resources-hierarchy.md#cloud).
    1. To the right of the cloud name, click ![image](../_assets/console-icons/ellipsis.svg).
    1. Select ![image](../_assets/console-icons/plus.svg) **Create folder**.
    
       ![create-folder1](../_assets/resource-manager/create-folder-1.png)
    
    1. Give your [folder](../resource-manager/concepts/resources-hierarchy.md#folder) a name. The naming requirements are as follows:
    
        * Length: between 3 and 63 characters.
        * It can only contain lowercase Latin letters, numbers, and hyphens.
        * It must start with a letter and cannot end with a hyphen.
    
    1. Optionally, specify the description for your folder.
    1. Select **Create a default network**. This will create a [network](../vpc/concepts/network.md#network) with subnets in each availability zone. Within this network, you will also have a [default security group](../vpc/concepts/security-groups.md#default-security-group), within which all network traffic will be allowed.
    1. Click **Create**.
    
       ![create-folder2](../_assets/resource-manager/create-folder-2.png)

1. [Assign](../iam/operations/roles/grant.md) the [vpc.user](../vpc/security/index.md#vpc-user) role and the [managed-greenplum.editor role (or higher)](security/index.md#roles-list) to your Yandex Cloud account. These roles allow you to create a cluster.

    {% note info %}
    
    If you cannot manage roles, contact your cloud or organization administrator.
    
    {% endnote %}


## Create a cluster {#create-cluster}

Create a Yandex MPP Analytics for PostgreSQL cluster with public access. You can [connect](operations/connect/index.md) to such a cluster with a Yandex Compute Cloud VM or over the internet.

To create a cluster:

1. In the management console, select the folder where you want to create your database cluster.
1. Navigate to **Yandex MPP Analytics&nbsp;for&nbsp;PostgreSQL**.
1. Click **Create cluster**.


1. Specify the following cluster properties:

    * **Basic parameters** → **Cluster name**: Cluster name. It must be unique within the folder.

    * **Network settings**:

        * **Network**: Specify the [network](../vpc/concepts/network.md) you want the [cluster hosts](concepts/index.md) to reside in.
        * **Security groups**: Specify [security groups](../vpc/concepts/security-groups.md) for the cluster network traffic.

            [Set up the security groups](operations/connect/index.md#configuring-security-groups) to be able to connect to the cluster over the internet.

        * **Availability zone**: Specify an availability zone for the cluster hosts.

        * **Subnet**: Specify a subnet for the cluster hosts.

        * Enable **Public access**.

    * **User**:

        * **Username**: Admin username. It may contain Latin letters, numbers, hyphens, and underscores, but cannot start with a hyphen. It must be from 1 to 32 characters long.

            {% note info %}
            
            Such names as `admin`, `gpadmin`, [mdb_admin](concepts/cluster-users.md#mdb_admin), `mdb_replication`, `monitor`, `none`, `postgres`, `public`, and `repl` are reserved for Yandex MPP Analytics for PostgreSQL. You cannot create users with these names.
            
            {% endnote %}

        * **Password**: Admin user password. It must be from 8 to 128 characters long.

        The admin is a special user required for managing the cluster. This user cannot be deleted. For more information, see [Users and roles in Yandex MPP Analytics for PostgreSQL](concepts/cluster-users.md).

    * **Master** and **Segment**: [Master and segment host](concepts/index.md) configuration in the Yandex MPP Analytics for PostgreSQL cluster.

        You can edit the settings on these tabs if the default configuration does not suit your needs. For more information, see [Calculating the cluster configuration](concepts/calculate-specs.md).

1. Click **Create cluster**.


1. Wait until the cluster is ready: its status on the Yandex MPP Analytics for PostgreSQL dashboard will change to **Running** and its state, to **Alive**. This may take a while.

For more information on creating a cluster, see [Creating a cluster Yandex MPP Analytics for PostgreSQL](operations/cluster-create.md).

## Get the cluster ID {#get-cluster-id}

Get the cluster ID required to [connect](#connect) to the cluster:

1. In the [management console](https://console.yandex.cloud), navigate to the folder page.
1. Navigate to **Yandex MPP Analytics&nbsp;for&nbsp;PostgreSQL**.
1. Click the name of your cluster and select the ![image](../_assets/console-icons/flag.svg) **Overview** tab.
1. Copy the cluster ID specified under **General information**.

## Connect to the cluster {#connect}

Connect to the cluster you [created](#create-cluster):

{% list tabs group=mgp-quickstart %}

- DBeaver {#gui}

    1. [Install DBeaver](https://dbeaver.com/docs/dbeaver/Installation/) to the host that will be used for the connection.

        {% note info %}

        Access to the cluster was tested in DBeaver Community 24.2.3

        {% endnote %}

    1. Launch DBeaver.
    1. In the **Database** menu, select **New connection**.
    1. Select **Greenplum®** from the database list.
    1. Click **Next**.
    1. Specify the main connection properties on the **Main** tab:

        * Under **Server**:
            * **Connect by**: `Host`.
            * **Host**: [Special FQDN of the primary master](operations/connect/fqdn.md#fqdn-master), `c-<cluster_ID>.rw.mdb.yandexcloud.net`.

                Cluster ID [you got earlier](#get-cluster-id).

            * **Database**: `postgres`.
            * **Port**: `6432`.
            * **Show all databases**: Enabled.

        * Under **Authentication**:
            * **Authentication**: `Database Native`.
            * **User**: Admin username specified when [creating the cluster](#create-cluster).
            * **Password**: Admin user password.

                You can disable the **Save password** option, which is enabled by default.

    1. Click **Test connection**.

        Click **Download** if DBeaver prompts you to download the driver files. You may not have these files if this is your first time using DBeaver to connect to the Yandex MPP Analytics for PostgreSQL.

        Enter the user password if DBeaver prompts you for one and click **OK**.
        
        DBeaver will connect to the `postgres` database in the Yandex MPP Analytics for PostgreSQL cluster.

        If the connection is successful, you will get general information about the Yandex MPP Analytics for PostgreSQL server and the driver used for the connection. Click **OK**.

        {% note warning %}

        When connecting, you will use an encrypted connection (with SSL) but without authenticating the cluster hosts. This is the [default behavior for all clients](https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS) that use the `libpq` library.

        In the production environment, we recommend [connecting to the cluster over SSL with host authentication](operations/connect/clients.md#connection-ide).

        {% endnote %}

    1. Optionally, on the **Main** tab, click **Connection description (name, type, ...)** and add a name and description for the connection.

        By default, the connection name matches the specified database name, i.e., `postgres`. You may want to select a different name to avoid confusion: you can use this connection to work with any databases, not just `postgres`.

    1. Click **Finish**.

        You will see the new connection in the left-hand panel on the **Databases** tab.

    1. Expand the connection you created in the left-hand panel on the **Databases** tab.

        Enter the user password if DBeaver prompts you for one and click **OK**.
        
        DBeaver will connect to the `postgres` database in the Yandex MPP Analytics for PostgreSQL cluster.

    1. Run this test query:

        1. Open the **Databases** folder, expand the `postgres` database context menu, and select **SQL editor** → **Open SQL console**.

            This will open a console you can use to run SQL queries to the `postgres` database.

        1. Enter your query in the console:

            ```sql
            SELECT version();
            ```

        1. Run the query by clicking **Run SQL script** on the far left side of the console.
           
           Alternatively, select **Run SQL script** in the **SQL editor** menu.

- psql {#cli}

    1. [Install](https://www.postgresql.org/download/) the `psql` client to the host you will use to connect to the cluster.

        For example, to install `psql` on a [Linux VM](../compute/operations/vm-create/create-linux-vm.md) in Yandex Cloud with Ubuntu 24.04:

        
        1. Connect to the VM via [OS Login](../compute/operations/vm-connect/os-login.md) or over [SSH](../compute/operations/vm-connect/ssh.md).


        1. Install the required dependencies and the PostgreSQL client:

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

    1. Connect to the `postgres` database in the Yandex MPP Analytics for PostgreSQL cluster. Use the [special primary master FQDN](operations/connect/fqdn.md#fqdn-master):

        ```bash
        psql "host=c-<cluster_ID>.rw.mdb.yandexcloud.net \
          port=6432 \
          dbname=postgres \
          user=<username>"
        ```

        Cluster ID [you got earlier](#get-cluster-id).

        After you run this command, enter the user password to complete the connection procedure.

        {% note warning %}

        When connecting, you will use an encrypted connection (with SSL) but without authenticating the cluster hosts. This is the [default behavior for all clients](https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS) that use the `libpq` library.

        In the production environment, we recommend [connecting to the cluster over SSL with host authentication](operations/connect/clients.md#bash).

        {% endnote %}

    1. Run this test query:

        ```sql
        SELECT version();
        ```

{% endlist %}

If your cluster connection and test query are successful, you will see the DBMS version.

## Create a database {#create-db}

The [previously created](#create-cluster) Yandex MPP Analytics for PostgreSQL cluster has only one database, a service database named `postgres`. This database is not meant to store user data. For example, you cannot create data schemas in it.

After you [connect to the Yandex MPP Analytics for PostgreSQL cluster](#connect), create a database named `sample_db` for storing user data:

{% list tabs group=mgp-quickstart %}

- DBeaver {#gui}

    1. Expand the [previously created connection](#connect) in the left-hand panel on the **Databases** tab.

        Enter the user password if DBeaver prompts you for one and click **OK**.
        
        DBeaver will connect to the `postgres` database in the Yandex MPP Analytics for PostgreSQL cluster.

    1. Create a database:

        1. Open the **Databases** folder, expand the `postgres` database context menu, and select **SQL editor** → **Open SQL console**.

            This will open a console you can use to run SQL queries to the `postgres` database.

        1. Enter your query in the console:

            ```sql
            CREATE DATABASE sample_db;
            ```

        1. Run the query by clicking **Run SQL script** on the far left side of the console.
           
           Alternatively, select **Run SQL script** in the **SQL editor** menu.

    1. Update the list of databases for it to display the new database.

        To do this, open the context menu of the **Databases** folder and select **Refresh**.

        {% note tip %}

        If you do not see `sample_db` in the list, make sure you [enabled](#connect) the **Show all databases** option for the connection.

        {% endnote %}

- psql {#cli}

    1. Run this query:

        ```sql
        CREATE DATABASE sample_db;
        ```

    1. Display the list of databases in the Yandex MPP Analytics for PostgreSQL cluster and make sure it includes `sample_db`:

        ```sql
        \list
        ```

{% endlist %}

## Run a few queries to the database {#query-db}

To make sure the database [was created](#create-db) correctly, run a few queries to it:

{% list tabs group=mgp-quickstart %}

- DBeaver {#gui}

    1. Expand the [previously created connection](#connect) in the left-hand panel on the **Databases** tab.

        Enter the user password if DBeaver prompts you for one and click **OK**.
        
        DBeaver will connect to the `postgres` database in the Yandex MPP Analytics for PostgreSQL cluster.

    1. Open the **Databases** folder, expand the `sample_db` database context menu, and select **SQL editor** → **Open SQL console**.

        This will open a console you can use to run SQL queries to `sample_db`.

    1. Create a table and populate it with data:

        1. Enter your queries in the console:

            ```sql
            CREATE TABLE sample_table (a int)
                DISTRIBUTED BY (a);
            
            INSERT INTO sample_table
                SELECT * FROM GENERATE_SERIES(1, 10000);
            ```

        1. Run the query by clicking **Run SQL script** on the far left side of the console.
           
           Alternatively, select **Run SQL script** in the **SQL editor** menu.

        The table will be created and populated with numbers from 1 to 10,000.

        The `CREATE TABLE` and `INSERT INTO` queries do not return any results. DBeaver will display statistics for the completed queries as follows:

        ```sql
        Queries         2
        Updated Rows    10000
        Execute time    ...
        Fetch time      ...
        Total time      ...
        Start time      ...
        Finish time     ...
        ```

    1. Get the sum of all numbers in the table. To do this, clear the console, then enter and run the following query:

        ```sql
        SELECT sum(a) FROM sample_table;
        ```
        
        Expected result:
        
        ```sql
        sum     |
        --------+
        50005000|
        ```

    1. Get information on how the 10,000 table rows are distributed across Yandex MPP Analytics for PostgreSQL segments. To do this, clear the console, then enter and run the following query:

        ```sql
        SELECT gp_segment_id, count(*)
            FROM sample_table
            GROUP BY gp_segment_id;
        ```
        
        The result will depend on the number of segments in the cluster. Distribution of strings by segments may vary as well.
        
        Here is a possible result for a cluster with two segments:
        
        ```sql
        gp_segment_id|count|
        -------------+-----+
                    0| 5013|
                    1| 4987|
        ```

    1. End the connection session. To do this, open the connection context menu and select **Disconnect**.

- psql {#cli}

    1. Make sure you are connected to `sample_db`:

        ```sql
        SELECT current_database();
        ```

        If the query returns a different database name, e.g., `postgres`, connect to the database you need:

        ```sql
        \connect sample_db;
        ```

    1. Create a table and populate it with data:

        ```sql
        CREATE TABLE sample_table (a int)
            DISTRIBUTED BY (a);
        
        INSERT INTO sample_table
            SELECT * FROM GENERATE_SERIES(1, 10000);
        ```

        The table will be created and populated with numbers from 1 to 10,000.

        The `CREATE TABLE` and `INSERT INTO` queries do not return any results.

    1. Get the sum of all numbers in the table:

        ```sql
        SELECT sum(a) FROM sample_table;
        ```
        
        Expected result:
        
        ```sql
        sum     |
        --------+
        50005000|
        ```

    1. Get information on how the 10,000 table rows are distributed across Yandex MPP Analytics for PostgreSQL segments:

        ```sql
        SELECT gp_segment_id, count(*)
            FROM sample_table
            GROUP BY gp_segment_id;
        ```
        
        The result will depend on the number of segments in the cluster. Distribution of strings by segments may vary as well.
        
        Here is a possible result for a cluster with two segments:
        
        ```sql
        gp_segment_id|count|
        -------------+-----+
                    0| 5013|
                    1| 4987|
        ```

    1. End the `psql` session:

        ```sql
        \quit
        ```

{% endlist %}

## What's next {#whats-next}

* Read about the [service concepts](concepts/index.md).
* Learn more about [creating a cluster](operations/cluster-create.md) and [connecting to a cluster](operations/connect/index.md).

_Greenplum® and Greenplum Database® are registered trademarks or trademarks of Broadcom Inc. in the United States and/or other countries._