[Yandex Cloud documentation](../../index.md) > [Yandex MPP Analytics for PostgreSQL](../index.md) > [Step-by-step guides](index.md) > Clusters > Creating a cluster

# Creating a cluster Yandex MPP Analytics for PostgreSQL


A Yandex MPP Analytics for PostgreSQL cluster consists of master hosts that get client queries and segment hosts that process and store data.

For more information, see [Resource relationships in Yandex MPP Analytics for PostgreSQL](../concepts/index.md).


## Creating a cluster {#create-cluster}


To create a Yandex MPP Analytics for PostgreSQL cluster, you need the [vpc.user](../../vpc/security/index.md#vpc-user) role along with the [managed-greenplum.editor role or higher](../security/index.md#roles-list). For information on assigning roles, see [this Identity and Access Management guide](../../iam/operations/roles/grant.md).


{% list tabs group=instructions %}

- Management console {#console}

    To create a Yandex MPP Analytics for PostgreSQL cluster:

    1. In the [management console](https://console.yandex.cloud), select the folder where you want to create a database cluster.
    1. Navigate to **Yandex MPP Analytics&nbsp;for&nbsp;PostgreSQL**.
    1. Click **Create cluster**.
    1. Enter a name for the cluster. It must be unique within the folder.
    1. Optionally, enter a description for the cluster.
    1. Select the environment where you want to create your cluster (you cannot change the environment once the cluster is created):
        * `PRODUCTION`: For stable versions of your applications.
        * `PRESTABLE`: For testing purposes. The prestable environment is similar to the production environment and likewise covered by an SLA, but it is the first to get new features, improvements, and bug fixes. In the prestable environment, you can test new versions for compatibility with your application.
    1. Select the DBMS version.

    
    1. Optionally, select groups of [dedicated hosts](../../compute/concepts/dedicated-host.md) to place master hosts or segment hosts on dedicated hosts. You can assign groups to one of the two Yandex MPP Analytics for PostgreSQL host types or to both of them at once.

        You must first [create](../../compute/operations/dedicated-host/create-host-group.md) a group of dedicated hosts in Yandex Compute Cloud.

        You cannot edit this setting after you create a cluster. 
        
        If using dedicated hosts, the cluster cost is a sum of the charge for [computing resources Yandex Compute Cloud](../../compute/pricing.md#prices-dedicated-host) and the [markup Yandex MPP Analytics for PostgreSQL](../pricing/index.md#dedicated-hosts).


    1. Under **Network settings**, select:

        * [Cloud network](../../vpc/concepts/network.md#network) to host the cluster.

        * [Security groups](../../vpc/concepts/security-groups.md) for the cluster's network traffic. You may need to additionally [set up security groups](connect/index.md#configuring-security-groups) to be able connect to the cluster.

        * [Availability zone](../../overview/concepts/geo-scope.md) and [subnet](../../vpc/concepts/network.md#subnet) to host the cluster. To create a new subnet, click **Create subnet** in the list of subnets.

           {% note warning %}
           
           You will not be able to change the availability zone selected for cluster deployment.
           
           {% endnote %}

           For clusters with hosts residing in the `ru-central1-d` [availability zone](../../overview/concepts/geo-scope.md), local SSD storage is not available if using Intel Cascade Lake.

        
        * The **Public access** option to enable connecting to the cluster from the internet.


    1. Optionally, enable **Hybrid storage**.

        It enables [hybrid storage](../concepts/hybrid-storage.md). You cannot disable hybrid storage after you save your cluster settings.

        When hybrid storage is enabled, you can use the [Yezzey extension](extensions/yezzey.md) to move part of your [AO and AOCO tables](../concepts/tables.md) from the cluster storage to a cold storage, and vice versa.
        
        Cold storage is a convenient option if you need to store your table data for a long time without using it much. This will make data storage [less costly](../pricing/index.md#rules-storage).

        
        {% note info %}
        
        This feature is at the [Preview](../../overview/concepts/launch-stages.md) stage and is free of charge.
        
        {% endnote %}


    1. Specify the admin user credentials. This special user is required for managing the cluster and cannot be deleted. For more information, see [Users and roles](../concepts/cluster-users.md).

        * **Username** 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 %}

        * The **Password** must be from 8 to 128 characters long.

    1. Specify additional cluster settings, if required:

        * **Backup start time (UTC)**: Time interval during which the cluster backup starts. Time is specified in 24-hour UTC format. The default time is `22:00 - 23:00` UTC.
        * **Maintenance**: [Maintenance](../concepts/maintenance.md) window settings:

            * To enable maintenance at any time, select **At any time** (default).
            * To specify the preferred maintenance start time, select **By schedule** and specify the day of the week and the UTC time interval. For example, you can choose a time when the cluster is least loaded.
            
            Both active and stopped clusters are subject to maintenance. Maintenance operations include DBMS updates, patches, etc.

        
        * **Service account**: Select an existing service account for accessing Yandex Cloud services or create a new one.
        * **Write logs**: Enables logging of cluster operations. You pay for log storage according to the Yandex Cloud Logging pricing policy. For logging, [assign](../../iam/operations/sa/assign-role-for-sa.md) the `logging.writer` role to the service account you selected.

          If you enable this option, configure the logging settings:

          * Specify the logging destination:

             * **Folder**: Log to the default log group for the selected folder.
             * **Group**: Log either to a new [log group](../../logging/concepts/log-group.md) or one selected from the list.

          * Select the logs you need:

             * **Command Center logs**: Enables [Command Center](../concepts/command-center.md) logs.
             * **Greenplum logs**: Enables DBMS logging. Use [Log min messages](../concepts/settings-list.md#setting-log-min-messages) under **DBMS settings** to specify the logging level.


        
        * **DataLens access**: Allows you to analyze cluster data in [Yandex DataLens](../../datalens/concepts/index.md).
        * The **Yandex Query access** option enables you to run YQL queries from [Yandex Query](../../query/concepts/index.md) to a managed database in Yandex MPP Analytics for PostgreSQL.
        * **WebSQL access**: This option allows sending queries to cluster databases using [Yandex WebSQL](../../websql/index.md).



        * **Deletion protection**: Manages cluster protection against accidental deletion.

            Even with deletion protection enabled, one can still connect to the cluster manually and delete the data.

    1. Optionally, configure the operating mode and [connection pooler](../concepts/pooling.md) settings under **Connection pooler**:

        * **Mode**: `SESSION` (session mode) or `TRANSACTION` (transaction mode, default).
        * **Size**: Maximum number of client connections. The default value is `0` (not limited).
        * **Client Idle Timeout**: Idle timeout for a client connection (in seconds). The default value is `28800`.
        * **Transaction idle timeout**: Idle timeout for a client connection with an open transaction (in seconds). The default value is `0` (not limited).

    1. Optionally, under **Managing background processes**, edit the settings for [routine maintenance operations](../concepts/maintenance.md#regular-ops):

        * **Start time (UTC)**: `VACUUM` start time. The default value is `19:00 UTC`. Once the `VACUUM` operation is completed, the `ANALYZE` operation starts.
        * **VACUUM timeout**: Maximum `VACUUM` execution time, in seconds. Valid values: from `7,200` to `86,399`, with `36,000` by default. As soon as this period expires, `VACUUM` will be forced to terminate.
        * **ANALYZE timeout**: Maximum `ANALYZE` execution time, in seconds. Valid values: from `7,200` to `86,399`, with `36,000` by default. As soon as this period expires, the `ANALYZE` operation will be forced to terminate.
        
        The combined `VACUUM` and `ANALYZE` execution time may not exceed 24 hours.

    1. Specify the master host properties on the **Master** tab. For the recommended configuration, see [Calculating the cluster configuration](../concepts/calculate-specs.md#master).

        * [Host class](../concepts/instance-types.md): Defines the technical properties of the VMs on which the cluster's master hosts will be deployed.

        * Under **Storage**, select the [disk type](../concepts/storage.md) and specify its size. The available disk types [depend](../concepts/storage.md) on the selected host class.

          {% note warning %}
          
          * You cannot change disk type after you create a cluster.
          * You cannot decrease the storage size after automatic expansion.
          * When scaling your storage, the cluster hosts will be unavailable.
          
          {% endnote %}

    1. Specify the properties of segment hosts on the **Segment** tab. For the recommended configuration, see [Calculating the cluster configuration](../concepts/calculate-specs.md#segment).

        * Number of segment hosts.
        * [Number of segments per host](../concepts/index.md). The maximum value of this setting depends on the host class.

            The segment host class and the number of segments per host [affect](../concepts/instance-types.md#select-class-segment-hosts) the maximum amount of memory allocated to each Yandex MPP Analytics for PostgreSQL server process. If you select a host class with small RAM and specify a large number of segments, an [error](../qa/cluster-hosts.md#memory-limit) may occur.

        * [Host class](../concepts/instance-types.md): Defines the technical properties of the VMs on which the cluster's segment hosts will be deployed.
        * Under **Storage**, select the [disk type](../concepts/storage.md) and specify its size. The available disk types [depend](../concepts/storage.md) on the selected host class.

           {% note warning %}
           
           * You cannot change disk type after you create a cluster.
           * You cannot decrease the storage size after automatic expansion.
           * When scaling your storage, the cluster hosts will be unavailable.
           
           {% endnote %}

           * Select the storage size.

    1. If required, configure the [cluster-level DBMS settings](../concepts/settings-list.md#dbms-cluster-settings).

    1. Click **Create**.

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

    To create a Yandex MPP Analytics for PostgreSQL cluster:

    
    1. Check whether the folder has any subnets for cluster hosts:

        ```bash
        yc vpc subnet list
        ```

        If there are no subnets in the folder, [create the right ones](../../vpc/operations/subnet-create.md) in VPC.


    1. View the description of the CLI command for creating a cluster:

        ```bash
        yc managed-greenplum cluster create --help
        ```

    1. Specify the cluster properties in this command (the example does not show all that are available):

        
        ```bash
        yc managed-greenplum cluster create <cluster_name> \
           --greenplum-version=<DBMS_version> \
           --environment=<environment> \
           --network-name=<network_name> \
           --user-name=<username> \
           --user-password=<user_password> \
           --master-config resource-id=<host_class>,`
                          `disk-size=<storage_size_in_GB>,`
                          `disk-type=<network-ssd|network-ssd-nonreplicated|local-ssd> \
           --segment-config resource-id=<host_class>,`
                          `disk-size=<storage_size_in_GB>,`
                          `disk-type=<network-ssd-nonreplicated|local-ssd> \
           --zone-id=<availability_zone> \
           --subnet-id=<subnet_ID> \
           --assign-public-ip=<enable_public_access_to_cluster_hosts> \
           --security-group-ids=<list_of_security_group_IDs> \
           --deletion-protection
        ```

        {% note info %}

        The cluster name must be unique within a folder. It may contain Latin letters, numbers, hyphens, and underscores. The name may be up to 63 characters long.

        {% endnote %}

        Where:

        * `--greenplum-version`: DBMS version, 6.28 or 6.29 or Cloudberry 2.
        * `--environment`: Environment:
            * `PRODUCTION`: For stable versions of your applications.
            * `PRESTABLE`: For testing purposes. The prestable environment is similar to the production environment and likewise covered by an SLA, but it is the first to get new features, improvements, and bug fixes. In the prestable environment, you can test new versions for compatibility with your application.
        * `--network-name`: [Network name](../../vpc/concepts/network.md#network).
        * `--user-name`: Username. It may contain Latin letters, numbers, hyphens, and underscores, and must start with a letter, number, or underscore. It must be from 1 to 32 characters long.
        * `--user-password`: Password. It must be from 8 to 128 characters long.
        * `--master-config` and `--segment-config`: Master and segment host configuration:
            * `resource-id`: [Host class](../concepts/instance-types.md).

                The segment host class and the number of segments per host [affect](../concepts/instance-types.md#select-class-segment-hosts) the maximum amount of memory allocated to each Yandex MPP Analytics for PostgreSQL server process. If you select a host class with small RAM and specify a large number of segments, an [error](../qa/cluster-hosts.md#memory-limit) may occur.

            * `disk-size`: Storage size in GB.
            * `disk-type`: [Disk type](../concepts/storage.md):
                * `network-ssd` (for master hosts only)
                * `local-ssd`
                * `network-ssd-nonreplicated`

        * `--zone-id`: [Availability zone](../../overview/concepts/geo-scope.md).
        * `--subnet-id`: [Subnet ID](../../vpc/concepts/network.md#subnet). You need to specify the ID if the selected availability zone has two or more subnets.
        * `--assign-public-ip`: Flag used if [public access](../concepts/network.md#public-access-to-a-host) to the hosts is required, `true` or `false`.
        * `--security-group-ids`: List of [security group](../../vpc/concepts/security-groups.md) IDs.
        * `--deletion-protection`: Cluster protection from accidental deletion, `true` or `false`.


            Even with deletion protection enabled, one can still connect to the cluster manually and delete the data.

    1. To set the start time for the backup, provide a value in `HH:MM:SS` format under `--backup-window-start`:

        ```bash
        yc managed-greenplum cluster create <cluster_name> \
           ...
           --backup-window-start=<backup_start_time>
        ```

    
    1. Optionally, to create a cluster based on [dedicated host](../../compute/concepts/dedicated-host.md) groups, specify their IDs as a comma-separated list in the `--master-host-group-ids` and `--segment-host-group-ids` parameters:

        ```bash
        yc managed-greenplum cluster create <cluster_name> \
           ...
           --master-host-group-ids=<IDs_of_dedicated_host_groups_for_master_hosts> \
           --segment-host-group-ids=<IDs_of_dedicated_host_groups_for_segment_hosts>
        ```

        You can assign groups to one of the two Yandex MPP Analytics for PostgreSQL host types or to both of them at once.

        You must first [create](../../compute/operations/dedicated-host/create-host-group.md) a group of dedicated hosts in Yandex Compute Cloud.

        You cannot edit this setting after you create a cluster. 
        
        If using dedicated hosts, the cluster cost is a sum of the charge for [computing resources Yandex Compute Cloud](../../compute/pricing.md#prices-dedicated-host) and the [markup Yandex MPP Analytics for PostgreSQL](../pricing/index.md#dedicated-hosts).


    1. To set up a [maintenance](../concepts/maintenance.md) window (including for disabled clusters), provide a value in the `--maintenance-window` parameter when creating your cluster:

        ```bash
        yc managed-greenplum cluster create <cluster_name> \
           ...
           --maintenance-window type=<maintenance_type>,`
                               `day=<day_of_week>,`
                               `hour=<hour> \
        ```

        Where `type` is the maintenance type:

        * `anytime`: Any time (default).
        * `weekly`: On a schedule. For this value, also specify the following:
            * `day`: Day of week, i.e., `MON`, `TUE`, `WED`, `THU`, `FRI`, `SAT`, or `SUN`.
            * `hour`: Sequence number of UTC hour interval, from `1` to `24`.
        
              > For example, `1` stands for the interval from `00:00` to `01:00`, and `5`, from `04:00` to `05:00`.

    
    1. To allow access to the cluster from different services, provide the `true` value in the relevant parameters when creating the cluster:

        ```bash
        yc managed-greenplum cluster create <cluster_name> \
           ...
           --datalens-access=<allow_access_from_DataLens> \
           --yandexquery-access=<allow_access_from_Yandex_Query> \
           --websql-access=<allow_access_from_WebSQL>
        ```

        Available services:

        * `--datalens-access`: [Yandex DataLens](../../datalens/concepts/index.md)
        * `--yandexquery-access`: [Yandex Query](../../query/concepts/index.md)
        * `--websql-access`: [Yandex WebSQL](../../websql/concepts/index.md)



    
    1. To enable [transferring logs to Yandex Cloud Logging](mgp-to-cloud-logging.md), specify the following parameters when creating the cluster:

        ```bash
        yc managed-greenplum cluster create <cluster_name> \
           ...
           --service-account <service_account_ID> \
           --log-enabled \
           --log-command-center-enabled \
           --log-greenplum-enabled \
           --log-pooler-enabled \
           --log-folder-id <folder_ID>
        ```

        Where:

        * `--service-account`: Service account ID.
        * `--log-enabled`: Enables log transfer. Required for other flags responsible for transferring specific logs, e.g., `--log-greenplum-enabled`.
        * `--log-command-center-enabled`: Transferring [Command Center](../concepts/command-center.md) logs.
        * `--log-greenplum-enabled`: Transferring DBMS logs.
        * `--log-pooler-enabled`: Transferring [connection pooler](../concepts/pooling.md) logs.
        * `--log-folder-id`: Specify the ID of the folder whose log group you want to use.
        * `--log-group-id`: ID of the log group to write logs to.

            Specify either `--log-folder-id` or `--log-group-id`.


- Terraform {#tf}

  
  With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
  
  Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.
  
  For more information about the provider resources, see the guides on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../terraform/index.md).


  To create a Yandex MPP Analytics for PostgreSQL cluster:

  1. In the command line, navigate to the directory that will contain the Terraform configuration files describing your infrastructure. If there is no such directory, create one.

  
  1. If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
     
     
     To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.

  1. Create a configuration file describing the [cloud network](../../vpc/concepts/network.md#network) and [subnets](../../vpc/concepts/network.md#subnet).

      The cluster is hosted on a cloud network. If you already have a network in place, you do not need to describe it again.

      Cluster hosts are located on the selected cloud network's subnets. If you already have suitable subnets, you do not need to describe them again.

      Below is an example of a configuration file describing a single-subnet cloud network:

      ```hcl
      resource "yandex_vpc_network" "<network_name_in_Terraform>" { name = "<network_name>" }
      resource "yandex_vpc_subnet" "<subnet_name_in_Terraform>" {
        name           = "<subnet_name>"
        zone           = "<availability_zone>"
        network_id     = yandex_vpc_network.<network_name_in_Terraform>.id
        v4_cidr_blocks = ["<subnet>"]
      }
      ```


  1. Create a configuration file with a description of the cluster and its hosts.

      Here is an example of the configuration file structure:

      
      ```hcl
      resource "yandex_mdb_greenplum_cluster" "<cluster_name_in_Terraform>" {
        name                = "<cluster_name>"
        environment         = "<environment>"
        network_id          = yandex_vpc_network.<network_name_in_Terraform>.id
        zone                = "<availability_zone>"
        subnet_id           = yandex_vpc_subnet.<subnet_name_in_Terraform>.id
        assign_public_ip    = <enable_public_access_to_cluster_hosts>
        deletion_protection = <protect_cluster_from_deletion>
        version             = "<DBMS_version>"
        master_host_count   = <number_of_master_hosts>
        segment_host_count  = <number_of_segment_hosts>
        segment_in_host     = <number_of_segments_per_host>
        master_subcluster {
          resources {
            resource_preset_id = "<host_class>"
            disk_size          = <storage_size_in_GB>
            disk_type_id       = "<disk_type>"
          }
        }
        segment_subcluster {
          resources {
            resource_preset_id = "<host_class>"
            disk_size          = <storage_size_in_GB>
            disk_type_id       = "<disk_type>"
          }
        }

        access {
          data_lens    = <allow_access_from_DataLens>
          yandex_query = <allow_access_from_Yandex_Query>
        }

        user_name     = "<username>"
        user_password = "<password>"

        security_group_ids = ["<list_of_security_group_IDs>"]
      }
      ```




      Where:

      
      * `assign_public_ip`: Public access to cluster hosts, `true` or `false`.


      * `deletion_protection`: Cluster deletion protection, `true` or `false`.

          Even with deletion protection enabled, one can still connect to the cluster manually and delete the data.

      * `version`: DBMS version.
      * `master_host_count`: Number of master hosts, 2.
      * `segment_host_count`: Number of segment hosts, between 2 and 32.
      * `segment_in_host`: [Number of segments per host](../concepts/index.md). The maximum value of this setting depends on the host class.

          The segment host class and the number of segments per host [affect](../concepts/instance-types.md#select-class-segment-hosts) the maximum amount of memory allocated to each Yandex MPP Analytics for PostgreSQL server process. If you select a host class with small RAM and specify a large number of segments, an [error](../qa/cluster-hosts.md#memory-limit) may occur.

      
      * `access.data_lens`: Access to the cluster from [Yandex DataLens](../../datalens/concepts/index.md), `true` or `false`.

      * `access.yandex_query`: Access to the cluster from [Yandex Query](../../query/concepts/index.md), `true` or `false`.



      For more information about the resources you can create with Terraform, see [this provider guide](../../terraform/resources/mdb_greenplum_cluster.md).

  
  1. Optionally, specify [dedicated host](../../compute/concepts/dedicated-host.md) groups to place master or segment hosts on dedicated hosts:

      ```hcl
      resource "yandex_mdb_greenplum_cluster" "<cluster_name_in_Terraform>" {
        ...
        master_host_group_ids = [<IDs_of_dedicated_host_groups_for_master_hosts>]
        segment_host_group_ids = [<IDs_of_dedicated_host_groups_for_segment_hosts>]
        ...
      }
      ```

      You can assign groups to one of the two Yandex MPP Analytics for PostgreSQL host types or to both of them at once.

      You must first [create](../../compute/operations/dedicated-host/create-host-group.md) a group of dedicated hosts in Yandex Compute Cloud.

      You cannot edit this setting after you create a cluster. 
      
      If using dedicated hosts, the cluster cost is a sum of the charge for [computing resources Yandex Compute Cloud](../../compute/pricing.md#prices-dedicated-host) and the [markup Yandex MPP Analytics for PostgreSQL](../pricing/index.md#dedicated-hosts).

  1. To enable [transferring logs to Yandex Cloud Logging](mgp-to-cloud-logging.md), specify the following parameters:

      ```hcl
      resource "yandex_mdb_greenplum_cluster" "<cluster_name_in_Terraform>" {
        ...
        service_account_id="<service_account_ID>"
        logging {
          enabled                = <enable_transferring_logs>
          command_center_enabled = <transfer_Yandex_Command_Center_logs>
          greenplum_enabled      = <transfer_DBMS_logs>
          pooler_enabled         = <transfer_connection_pooler_logs>
          folder_id              = "<folder_ID>"
        }
      }
      ```

      Where:

      * `service_account_id`: Service account ID.
      * `logging`: Log transfer settings:

          * `enabled`: Manages log transfer, `true` or `false`. To enable parameters responsible for transferring specific logs, provide the `true` value.
          * `command_center_enabled`: Transferring [Command Center](../concepts/command-center.md) logs, `true` or `false`.
          * `greenplum_enabled`: Transferring DBMS logs, `true` or `false`.
          * `pooler_enabled`: Transferring [connection pooler](../concepts/pooling.md) logs, `true` or `false`.
          * `folder_id`: Specify the ID of the folder whose log group you want to use.
          * `log_group_id`: ID of the log group to write logs to.

              Specify either `folder_id` or `log_group_id`.


  1. Make sure the Terraform configuration files are correct:

      1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
      1. Run this command:
      
         ```bash
         terraform validate
         ```
      
         Terraform will show any errors found in your configuration files.

  1. Create a cluster:

      1. Run this command to view the planned changes:
      
         ```bash
         terraform plan
         ```
      
         If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
      
      1. If everything looks correct, apply the changes:
         1. Run this command:
      
            ```bash
            terraform apply
            ```
      
         1. Confirm updating the resources.
         1. Wait for the operation to complete.

      All the required resources will be created in the specified folder. You can check resource availability and their settings in the [management console](https://console.yandex.cloud).

- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Create a file named `body.json` and paste the following code into it:

        
        ```json
        {
          "folderId": "<folder_ID>",
          "name": "<cluster_name>",
          "environment": "<environment>",
          "config": {
            "version": "<DBMS_version>",
            "access": {
              "dataLens": <allow_access_from_DataLens>,
              "yandexQuery": <allow_access_from_Yandex_Query>
            },
            "zoneId": "<availability_zone>",
            "subnetId": "<subnet_ID>",
            "assignPublicIp": <enable_public_access_to_cluster_hosts>
          },
          "masterConfig": {
            "resources": {
              "resourcePresetId": "<host_class>",
              "diskSize": "<storage_size_in_bytes>",
              "diskTypeId": "<disk_type>"
            }
          },
          "segmentConfig": {
            "resources": {
              "resourcePresetId": "<host_class>",
              "diskSize": "<storage_size_in_bytes>",
              "diskTypeId": "<disk_type>"
            }
          },
          "masterHostCount": "<number_of_master_hosts>",
          "segmentHostCount": "<number_of_segment_hosts>",
          "segmentInHost": "<number_of_segments_per_host>",
          "userName": "<username>",
          "userPassword": "<user_password>",
          "networkId": "<network_ID>",
          "securityGroupIds": [
              "<security_group_1_ID>",
              "<security_group_2_ID>",
              ...
              "<security_group_N_ID>"
          ],
          "deletionProtection": <protect_cluster_from_deletion>,
          "configSpec": {
            "pool": {
              "mode": "<operation_mode>",
              "size": "<number_of_client_connections>",
              "clientIdleTimeout": "<client_timeout>",
              "idleInTransactionTimeout": "<client_timeout_during_transaction>"
            }
          },
          "cloudStorage": {
            "enable": <use_hybrid_storage>
          },
          "masterHostGroupIds": [
            "string"
          ],
          "segmentHostGroupIds": [
            "string"
          ],
          "serviceAccountId": "<service_account_ID>",
          "logging": {
            "enabled": "<enable_transferring_logs>",
            "commandCenterEnabled": "<transfer_Yandex_Command_Center_logs>",
            "greenplumEnabled": "<transfer_DBMS_logs>",
            "poolerEnabled": "<transfer_connection_pooler_logs>",
            "folderId": "<folder_ID>"
          }
        }
        ```




        Where:

        * `folderId`: Folder ID. You can get it from the [list of your cloud folders](../../resource-manager/operations/folder/get-id.md).
        * `name`: Cluster name.
        * `environment`: Cluster environment, `PRODUCTION` or `PRESTABLE`.
        * `config`: Cluster settings:

            * `version`: DBMS version.

            
            * `access`: Settings for access to the cluster from the following Yandex Cloud services:

                * `dataLens`: [Yandex DataLens](../../datalens/index.md), `true` or `false`.
                * `yandexQuery`: [Yandex Query](../../query/concepts/index.md), `true` or `false`.



            * `zoneId`: [Availability zone](../../overview/concepts/geo-scope.md).
            * `subnetId`: [Subnet ID](../../vpc/concepts/network.md#subnet).
            * `assignPublicIp`: Public access to cluster hosts, `true` or `false`.

        * `masterConfig.resources`, `segmentConfig.resources`: Master and segment host configuration in the cluster:

            * `resourcePresetId`: [Host class](../concepts/instance-types.md).
            * `diskSize`: Disk size, in bytes.
            * `diskTypeId`: [Disk type](../concepts/storage.md).

        * `masterHostCount`: Number of master hosts, `1` or `2`.
        * `segmentHostCount`: Number of segment hosts, from `2` to `32`.
        * `segmentInHost`: [Number of segments per host](../concepts/index.md). The maximum value of this setting depends on the host class.

            The segment host class and the number of segments per host [affect](../concepts/instance-types.md#select-class-segment-hosts) the maximum amount of memory allocated to each Yandex MPP Analytics for PostgreSQL server process. If you select a host class with small RAM and specify a large number of segments, an [error](../qa/cluster-hosts.md#memory-limit) may occur.

        * `userName`: Username.
        * `userPassword`: User password.
        * `networkId`: ID of the [network](../../vpc/concepts/network.md#network) the cluster will be in.

        
        * `securityGroupIds`: [Security group](../concepts/network.md#security-groups) IDs.


        * `deletionProtection`: Cluster deletion protection, `true` or `false`.

            Even with deletion protection enabled, one can still connect to the cluster manually and delete the data.

        * `configSpec.pool`: [Connection pooler](../concepts/pooling.md) settings:

            * `mode`: Operation mode, `SESSION` or `TRANSACTION`.
            * `size`: Maximum number of client connections.
            * `clientIdleTimeout`: Idle timeout for a client connection, in seconds.
            * `idleInTransactionTimeout`: Idle timeout for a client connection with an open transaction (in seconds).

        * `cloudStorage.enable`: Use of hybrid storage. Set it to `true` to enable the Yandex Cloud [Yezzey](https://github.com/yezzey-gp/yezzey/) extension in a cluster. This extension is used to export [AO and AOCO tables](../tutorials/yezzey.md) from disks within the Yandex MPP Analytics for PostgreSQL cluster to cold storage in Yandex Object Storage. This way, the data will be stored in a service bucket compressed and encrypted. This is a [more cost-efficient storage method](../../storage/pricing.md).

            You cannot disable hybrid storage after you save your cluster settings.

            
            {% note info %}
            
            This feature is at the [Preview](../../overview/concepts/launch-stages.md) stage and is free of charge.
            
            {% endnote %}


        
        * `masterHostGroupIds` and `segmentHostGroupIds`: Optionally, IDs of [dedicated host](../../compute/concepts/dedicated-host.md) groups for master and segment hosts.

            You must first [create](../../compute/operations/dedicated-host/create-host-group.md) a group of dedicated hosts in Yandex Compute Cloud.

            You cannot edit this setting after you create a cluster. 
            
            If using dedicated hosts, the cluster cost is a sum of the charge for [computing resources Yandex Compute Cloud](../../compute/pricing.md#prices-dedicated-host) and the [markup Yandex MPP Analytics for PostgreSQL](../pricing/index.md#dedicated-hosts).

        * `serviceAccountId`: Service account ID.
        * `logging`: Settings for [transferring logs to Yandex Cloud Logging](mgp-to-cloud-logging.md):

            * `enabled`: Manages log transfer, `true` or `false`. To enable parameters responsible for transferring specific logs, provide the `true` value.
            * `commandCenterEnabled`: Transferring [Command Center](../concepts/command-center.md) logs, `true` or `false`.
            * `greenplumEnabled`: Transferring DBMS logs, `true` or `false`.
            * `poolerEnabled`: Transferring [connection pooler](../concepts/pooling.md) logs, `true` or `false`.
            * `folderId`: Specify the ID of the folder whose log group you want to use.
            * `logGroupId`: ID of the log group to write logs to.

                Specify either `folderId` or `logGroupId`.


    1. Call the [Cluster.Create](../api-ref/Cluster/create.md) method, e.g., via the following [cURL](https://curl.se/) request:

        ```bash
        curl \
            --request POST \
            --header "Authorization: Bearer $IAM_TOKEN" \
            --header "Content-Type: application/json" \
            --url 'https://mdb.api.cloud.yandex.net/managed-greenplum/v1/clusters' \
            --data "@body.json"
        ```

    1. Check the [server response](../api-ref/Cluster/create.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.

    1. Create a file named `body.json` and paste the following code into it:

        
        ```json
        {
          "folder_id": "<folder_ID>",
          "name": "<cluster_name>",
          "environment": "<environment>",
          "config": {
            "version": "<DBMS_version>",
            "access": {
              "data_lens": <allow_access_from_DataLens>,
              "yandex_query": <allow_access_from_Yandex_Query>
            },
            "zone_id": "<availability_zone>",
            "subnet_id": "<subnet_ID>",
            "assign_public_ip": <enable_public_access_to_cluster_hosts>
          },
          "master_config": {
            "resources": {
              "resource_preset_id": "<host_class>",
              "disk_size": "<storage_size_in_bytes>",
              "disk_type_id": "<disk_type>"
            }
          },
          "segment_config": {
            "resources": {
              "resource_preset_id": "<host_class>",
              "disk_size": "<storage_size_in_bytes>",
              "disk_type_id": "<disk_type>"
            }
          },
          "master_host_count": "<number_of_master_hosts>",
          "segment_host_count": "<number_of_segment_hosts>",
          "segment_in_host": "<number_of_segments_per_host>",
          "user_name": "<username>",
          "user_password": "<user_password>",
          "network_id": "<network_ID>",
          "security_group_ids": [
              "<security_group_1_ID>",
              "<security_group_2_ID>",
              ...
              "<security_group_N_ID>"
          ],
          "deletion_protection": <protect_cluster_from_deletion>
          "config_spec": {
            "pool": {
              "mode": "<operation_mode>",
              "size": "<number_of_client_connections>",
              "client_idle_timeout": "<client_timeout>",
              "idle_in_transaction_timeout": "<client_timeout_during_transaction>"
            }
          },
          "cloud_storage": {
            "enable": <use_hybrid_storage>
          },
          "master_host_group_ids": [
            "string"
          ],
          "segment_host_group_ids": [
            "string"
          ],
          "service_account_id": "<service_account_ID>",
          "logging": {
            "enabled": "<enable_transferring_logs>",
            "command_center_enabled": "<transfer_Yandex_Command_Center_logs>",
            "greenplum_enabled": "<transfer_DBMS_logs>",
            "pooler_enabled": "<transfer_connection_pooler_logs>",
            "folder_id": "<folder_ID>"
          }
        }
        ```




        Where:

        * `folder_id`: Folder ID. You can get it with the [list of folders in the cloud](../../resource-manager/operations/folder/get-id.md).
        * `name`: Cluster name.
        * `environment`: Cluster environment, `PRODUCTION` or `PRESTABLE`.
        * `config`: Cluster settings:

            * `version`: DBMS version.

            
            * `access`: Cluster settings for access to the following Yandex Cloud services:

                * `data_lens`: [Yandex DataLens](../../datalens/index.md), `true` or `false`.
                * `yandex_query`: [Yandex Query](../../query/concepts/index.md), `true` or `false`.



            * `zone_id`: [Availability zone](../../overview/concepts/geo-scope.md).

            
            * `subnet_id`: [Subnet](../../vpc/concepts/network.md#subnet) ID.
            * `assign_public_ip`: Public access to cluster hosts, `true` or `false`.


        * `master_config.resources`, `segment_config.resources`: Master and segment host configuration in the cluster:

            * `resource_preset_id`: [Host class](../concepts/instance-types.md).
            * `disk_size`: Disk size, in bytes.
            * `disk_type_id`: [Disk type](../concepts/storage.md).

        * `master_host_count`: Number of master hosts, `1` or `2`.
        * `segment_host_count`: Number of segment hosts, from `2` to `32`.
        * `segment_in_host`: [Number of segments per host](../concepts/index.md). The maximum value of this setting depends on the host class.

            The segment host class and the number of segments per host [affect](../concepts/instance-types.md#select-class-segment-hosts) the maximum amount of memory allocated to each Yandex MPP Analytics for PostgreSQL server process. If you select a host class with small RAM and specify a large number of segments, an [error](../qa/cluster-hosts.md#memory-limit) may occur.

        * `user_name`: Username.
        * `user_password`: User password.
        * `network_id`: ID of the [network](../../vpc/concepts/network.md#network) the cluster will be in.

        
        * `security_group_ids`: [Security group](../concepts/network.md#security-groups) IDs.


        * `deletion_protection`: Cluster deletion protection, `true` or `false`.

            Even with deletion protection enabled, one can still connect to the cluster manually and delete the data.

        * `config_spec.pool`: [Connection pooler](../concepts/pooling.md) settings:

            * `mode`: Operation mode, `SESSION` or `TRANSACTION`.
            * `size`: Maximum number of client connections.
            * `client_idle_timeout`: Idle timeout for a client connection, in seconds.
            * `idle_in_transaction_timeout`: Idle timeout for a client connection with an open transaction (in seconds).

        * `cloud_storage.enable`: Use of hybrid storage. Set it to `true` to enable the Yandex Cloud [Yezzey](https://github.com/yezzey-gp/yezzey/) extension in a cluster. This extension is used to export [AO and AOCO tables](../tutorials/yezzey.md) from disks within the Yandex MPP Analytics for PostgreSQL cluster to cold storage in Yandex Object Storage. This way, the data will be stored in a service bucket compressed and encrypted. This is a [more cost-efficient storage method](../../storage/pricing.md).

            You cannot disable hybrid storage after you save your cluster settings.

            
            {% note info %}
            
            This feature is at the [Preview](../../overview/concepts/launch-stages.md) stage and is free of charge.
            
            {% endnote %}


        
        * `master_host_group_ids` and `segment_host_group_ids`: Optionally, IDs of [dedicated host](../../compute/concepts/dedicated-host.md) groups for master and segment hosts.

            You must first [create](../../compute/operations/dedicated-host/create-host-group.md) a group of dedicated hosts in Yandex Compute Cloud.

            You cannot edit this setting after you create a cluster. 
            
            If using dedicated hosts, the cluster cost is a sum of the charge for [computing resources Yandex Compute Cloud](../../compute/pricing.md#prices-dedicated-host) and the [markup Yandex MPP Analytics for PostgreSQL](../pricing/index.md#dedicated-hosts).

        * `service_account_id`: Service account ID.
        * `logging`: Settings for [transferring logs to Yandex Cloud Logging](mgp-to-cloud-logging.md):

            * `enabled`: Manages log transfer, `true` or `false`. To enable parameters responsible for transferring specific logs, provide the `true` value.
            * `command_center_enabled`: Transferring [Command Center](../concepts/command-center.md) logs, `true` or `false`.
            * `greenplum_enabled`: Transferring DBMS logs, `true` or `false`.
            * `pooler_enabled`: Transferring [connection pooler](../concepts/pooling.md) logs, `true` or `false`.
            * `folder_id`: Specify the ID of the folder whose log group you want to use.
            * `log_group_id`: ID of the log group to write logs to.

                Specify either `folder_id` or `log_group_id`.


    1. Call the [ClusterService.Create](../api-ref/grpc/Cluster/create.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

        ```bash
        grpcurl \
            -format json \
            -import-path ~/cloudapi/ \
            -import-path ~/cloudapi/third_party/googleapis/ \
            -proto ~/cloudapi/yandex/cloud/mdb/greenplum/v1/cluster_service.proto \
            -rpc-header "Authorization: Bearer $IAM_TOKEN" \
            -d @ \
            mdb.api.cloud.yandex.net:443 \
            yandex.cloud.mdb.greenplum.v1.ClusterService.Create \
            < body.json
        ```

    1. View the [server response](../api-ref/grpc/Cluster/create.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

## Creating a cluster copy {#duplicate}

You can create a Yandex MPP Analytics for PostgreSQL cluster with the settings of another one created earlier. Do this by importing the original Yandex MPP Analytics for PostgreSQL cluster configuration into Terraform. This way, you can either create an identical copy or use the imported configuration as the baseline and modify it as needed. The import feature is handy when the original Yandex MPP Analytics for PostgreSQL cluster has a lot of settings and you need to create a similar one.

To create a Yandex MPP Analytics for PostgreSQL cluster copy:

{% list tabs group=instructions %}

- Terraform {#tf}

    1. If you do not have Terraform yet, [install it](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
    1. [Get the authentication credentials](../../tutorials/infrastructure-management/terraform-quickstart.md#get-credentials). You can add them to environment variables or specify them later in the provider configuration file.
    1. [Configure and initialize a provider](../../tutorials/infrastructure-management/terraform-quickstart.md#configure-provider). There is no need to create a provider configuration file manually, you can [download it](https://github.com/yandex-cloud-examples/yc-terraform-provider-settings/blob/main/provider.tf).
    1. Place the configuration file in a separate working directory and [specify the parameter values](../../tutorials/infrastructure-management/terraform-quickstart.md#configure-provider). If you did not add the authentication credentials to environment variables, specify them in the configuration file.

    1. In the same working directory, place a `.tf` file with the following contents:

        ```hcl
        resource "yandex_mdb_greenplum_cluster" "old" { }
        ```

    1. Save the ID of the original Yandex MPP Analytics for PostgreSQL cluster to an environment variable:

        ```bash
        export GREENPLUM_CLUSTER_ID=<cluster_ID>
        ```

        You can get the cluster ID from the [list of clusters in your folder](cluster-list.md#list-clusters).

    1. Import the original Yandex MPP Analytics for PostgreSQL cluster settings to the Terraform configuration:

        ```bash
        terraform import yandex_mdb_greenplum_cluster.old ${GREENPLUM_CLUSTER_ID}
        ```

    1. Get the imported configuration:

        ```bash
        terraform show
        ```

    1. Copy it from your terminal and paste it into the `.tf` file.
    1. Create a new directory `imported-cluster` and move your configuration file there.
    1. Modify the configuration so that you can use it to create a new cluster:

        * Specify the new cluster name in the `resource` string and the `name` parameter.
        * Delete the `created_at`, `health`, `id`, `status`, `master_hosts`, and `segment_hosts` parameters.
        * Add the `user_password` parameter.
        * If the `maintenance_window` section has `type = "ANYTIME"`, delete the `hour` parameter.
        * Optionally, make further changes if you need a customized configuration.

    1. [Get the authentication credentials](../../tutorials/infrastructure-management/terraform-quickstart.md#get-credentials) in the `imported-cluster` directory.

    1. In the same directory, [configure and initialize the provider](../../tutorials/infrastructure-management/terraform-quickstart.md#configure-provider). Instead of manually creating the provider configuration file, you can [download it](https://github.com/yandex-cloud-examples/yc-terraform-provider-settings/blob/main/provider.tf).

    1. Move the configuration file to the `imported-cluster` directory and [specify the arguments](../../tutorials/infrastructure-management/terraform-quickstart.md#configure-provider). If you have not set the authentication credentials as environment variables, specify them in the configuration file.

    1. Validate your Terraform configuration:

        ```bash
        terraform validate
        ```

        Terraform will display any configuration errors detected in your files.

    1. Create the required infrastructure:

        1. Run this command to view the planned changes:
        
           ```bash
           terraform plan
           ```
        
           If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
        
        1. If everything looks correct, apply the changes:
           1. Run this command:
        
              ```bash
              terraform apply
              ```
        
           1. Confirm updating the resources.
           1. Wait for the operation to complete.

        All the required resources will be created in the specified folder. You can check resource availability and their settings in the [management console](https://console.yandex.cloud).

{% endlist %}

## Examples {#examples}

### Creating a cluster {#create-example}

{% list tabs group=instructions %}

- CLI {#cli}

    Create a Yandex MPP Analytics for PostgreSQL cluster with the following test specifications:

    
    * Name: `gp-cluster`.
    * Version: `6.29`.
    * Environment: `PRODUCTION`.
    * Network: `default`.
    * User: `user1`.
    * Password: `user1user1`.
    * Master and segment hosts:

        * Class: `s2.medium`.
        * With 100 GB of local SSD (`local-ssd`) storage.

    * Availability zone: `ru-central1-a`, subnet: `b0rcctk2rvtr8efcch64`.
    * With public access to hosts.
    * Security group: `enp6saqnq4ie244g67sb`.
    * Deletion protection: Enabled.


    Run this command:

    
    ```bash
    yc managed-greenplum cluster create \
       --name=gp-cluster \
       --greenplum-version=6.29 \
       --environment=PRODUCTION \
       --network-name=default \
       --user-name=user1 \
       --user-password=user1user1 \
       --master-config resource-id=s2.medium,`
                      `disk-size=100,`
                      `disk-type=local-ssd \
       --segment-config resource-id=s2.medium,`
                       `disk-size=100,`
                       `disk-type=local-ssd \
       --zone-id=ru-central1-a \
       --subnet-id=b0rcctk2rvtr8efcch64 \
       --assign-public-ip=true \
       --security-group-ids=enp6saqnq4ie244g67sb \
       --deletion-protection
    ```


{% endlist %}

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