[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for PostgreSQL](../index.md) > [Tutorials](index.md) > Creating a PostgreSQL cluster for 1C

# Creating a PostgreSQL cluster for 1C:Enterprise


Managed Service for PostgreSQL allows creating fault-tolerant PostgreSQL clusters optimized for 1C:Enterprise. To this end, the service supports PostgreSQL versions 14-1c, 15-1c, 16-1c, 17-1c, 18-1c with all the required [extensions](#extensions) installed and the connection pooler configuration modified.

{% note warning %}

You can only connect 1C:Enterprise to 14-1c, 15-1c, 16-1c, 17-1c, 18-1c clusters.

{% endnote %}

Select your [host class](../concepts/instance-types.md) based on the number of users in your 1C:Enterprise installation. The **s2.small** hosts can accommodate up to 50 users at a time. We recommend using the **s2.medium** class if 50 or more users are going to access the database. Choose the storage size based on your expected data scope and allow for possible growth in your data volumes.


## Required paid resources {#paid-resources}

The support cost includes:

* Managed Service for PostgreSQL cluster: computing resources allocated to hosts, storage and backup size (see [Managed Service for PostgreSQL pricing](../pricing.md)).
* Public IP addresses if public access is enabled for cluster hosts (see [Virtual Private Cloud pricing](../../vpc/pricing.md)).


## Create a Managed Service for PostgreSQL cluster {#create-cluster}

{% list tabs group=instructions %}

- Manually {#manual}

    [Create](../operations/cluster-create.md#create-cluster) a Managed Service for PostgreSQL cluster of any suitable configuration with the following settings:

    * **Environment**: `PRODUCTION`.
    * **Version**: PostgreSQL version for 1C:Enterprise. The names of such versions end with `-1c`.
    * **Host class**: `s2.small` or higher.
    * **Hosts**: Add at least two more hosts in different availability zones. This provides the fault tolerance of the cluster. The database is automatically replicated. For more information, see [Replication in Managed Service for PostgreSQL](../concepts/replication.md).

- 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. Download the [postgresql-1c.tf](https://github.com/yandex-cloud-examples/yc-postgresql-1c/blob/main/postgresql-1c.tf) configuration file to the same working directory.

        This file describes:

        * [Network](../../vpc/concepts/network.md#network).
        * [Subnet](../../vpc/concepts/network.md#subnet).
        * [Security group](../../vpc/concepts/security-groups.md) and rule enabling cluster connections.
        * Managed Service for PostgreSQL cluster for 1C:Enterprise with a database and a user.

    1. Specify the infrastructure settings in the `postgresql-1c.tf` configuration file under `locals`:

        * `cluster_name`: Cluster name.
        * `pg_version`: PostgreSQL version for 1C:Enterprise. The names of such versions end with `-1c`.
        * `db_name`: Database name.
        * `username` and `password`: Database owner username and password.

    1. Validate your Terraform configuration files using this command:

       ```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 %}

Creating a DB cluster may take a few minutes.

## Connect the database to 1C:Enterprise {#connect-to-1c}

Add the created database as an information base to 1C:Enterprise. When adding the database, use the following parameters:

* **Server cluster**: Name of the 1C:Enterprise server to create the information base on.
* **Information base name in cluster**: Name of the information base to create on the 1C:Enterprise server.
* **Secure connection**: Disabled.
* **DBMS type**: `PostgreSQL`.
* **Database server**: `c-<cluster_ID>.rw.mdb.yandexcloud.net port=6432`.
* **Database name**: Name of the database you specified when creating the Managed Service for PostgreSQL cluster.
* **Database user**: Username of the database owner.
* **User password**: Password of the database owner.
* **Create a database if none exists**: Disabled.

### PostgreSQL extensions to support 1C:Enterprise {#extensions}

List of extensions installed in PostgreSQL 14-1c, 15-1c, 16-1c, 17-1c, 18-1c clusters:

* [online_analyze](https://postgrespro.ru/docs/postgrespro/10/online-analyze?lang=en)

* [plantuner](https://postgrespro.ru/docs/postgrespro/10/plantuner?lang=en)

* [fasttrun](https://postgrespro.ru/docs/postgrespro/10/fasttrun?lang=en)

* [fulleq](https://postgrespro.ru/docs/postgrespro/10/fulleq?lang=en)

* [mchar](https://postgrespro.ru/docs/postgrespro/10/mchar?lang=en)

## Delete the resources you created {#clear-out}

Delete the resources you no longer need to avoid paying for them:

{% list tabs group=instructions %}

- Manually {#manual}

    [Delete the Managed Service for PostgreSQL cluster](../operations/cluster-delete.md).

- Terraform {#tf}

    1. In the terminal window, go to the directory containing the infrastructure plan.
    
        {% note warning %}
    
        Make sure the directory has no Terraform manifests with the resources you want to keep. Terraform deletes all resources that were created using the manifests in the current directory.
    
        {% endnote %}
    
    1. Delete resources:
    
        1. Run this command:
    
            ```bash
            terraform destroy
            ```
    
        1. Confirm deleting the resources and wait for the operation to complete.
    
        All the resources described in the Terraform manifests will be deleted.

{% endlist %}