---
title: 'Ресурс selectel_dbaas_postgresql_datastore_v1'
sidebar_label: "selectel_dbaas_postgresql_datastore_v1"
description: 'Creates and manages a PostgreSQL cluster in Selectel Managed Databases using public API v1'
sidebar_position: 11
---

# Ресурс selectel\_dbaas\_postgresql\_datastore\_v1

:::info

Эта инструкция — копия документации Selectel Terraform-провайдера в [Terraform Registry](https://registry.terraform.io/providers/selectel/selectel/latest/docs).

:::

Creates and manages a PostgreSQL cluster using public API v1. Applicable to PostgreSQL, PostgreSQL for 1C, and PostgreSQL TimescaleDB clusters. For more information about Managed Databases, see the official Selectel documentation for [PostgreSQL](/managed-databases/postgresql/), [PostgreSQL for 1C](/managed-databases/postgresql-for-1c/), and [PostgreSQL TimescaleDB](/managed-databases/timescaledb/).

## Example usage \{#example-usage}

### PostgreSQL and PostgreSQL TimescaleDB \{#postgresql-and-postgresql-timescaledb}

```hcl
resource "selectel_dbaas_postgresql_datastore_v1" "cluster_1" {
  name       = "cluster-1"
  project_id = selectel_vpc_project_v2.project_1.id
  region     = "ru-3"
  type_id    = data.selectel_dbaas_datastore_type_v1.datastore_type_1.datastore_types[0].id
  subnet_id  = selectel_vpc_subnet_v2.subnet.subnet_id
  node_count = 3
  flavor {
    vcpus     = 4
    ram       = 4096
    disk      = 32
    disk_type = "network-ultra"
  }
  pooler {
    mode = "transaction"
    size = 50
  }
  security_groups = ["796f1f0a-d97d-4a8e-904e-4fd5ef57465c", "b9c2e73d-a6c5-4def-994d-ce85e3ce98d3"]
}
```

### PostgreSQL for 1C \{#postgresql-for-1c}

```hcl
resource "selectel_dbaas_postgresql_datastore_v1" "cluster_1" {
  name       = "cluster-1"
  project_id = selectel_vpc_project_v2.project_1.id
  region     = "ru-3"
  type_id    = data.selectel_dbaas_datastore_type_v1.datastore_type_1.datastore_types[0].id
  subnet_id  = selectel_vpc_subnet_v2.subnet.subnet_id
  node_count = 3
  flavor {
    vcpus     = 4
    ram       = 4096
    disk      = 32
    disk_type = "network-ultra"
  }
  security_groups = ["796f1f0a-d97d-4a8e-904e-4fd5ef57465c", "b9c2e73d-a6c5-4def-994d-ce85e3ce98d3"]
}
```

## Argument Reference \{#argument-reference}

* `name` — (Required) Cluster name. Changing this creates a new cluster.

* `project_id` — (Required) Unique identifier of the associated project. Changing this creates a new cluster. Retrieved from the [selectel\_vpc\_project\_v2](/terraform/selectel-provider-reference/resources/vpc_project_v2) resource. Learn more about [Projects](/access-control/projects/about-projects/).

* `region` — (Required) Pool where the database is located, for example, `ru-3`. Changing this creates a new cluster. Learn more about available pools in the [Availability matrix](/infrastructure/availability-matrix/#managed-databases).

* `subnet_id` — (Required) Unique identifier of the associated subnet. Changing this creates a new cluster. Retrieved from the [selectel\_vpc\_subnet\_v2](/terraform/selectel-provider-reference/resources/vpc_subnet_v2) resource for a public subnet, or from the [openstack\_networking\_subnet\_v2](/terraform/openstack-provider-reference/networking-neutron/resources/openstack_networking_subnet_v2) resource of the OpenStack provider for a private subnet.

* `type_id` — (Required) Unique identifier of the cluster type. Changing this creates a new cluster. Retrieved from the [selectel\_dbaas\_datastore\_type\_v1](/terraform/selectel-provider-reference/data-sources/dbaas_datastore_type_v1) data source.

* `node_count` — (Required) Number of nodes in the cluster. The available range is from 1 to 6. Learn more about [Replication](/managed-databases/about/about-managed-databases/#fault-tolerance-and-replication).

* `flavor_id` — (Optional) Unique identifier of the flavor for the cluster. Can be skipped when `flavor` is set. You can retrieve information about available flavors with the [selectel\_dbaas\_flavor\_v1](/terraform/selectel-provider-reference/data-sources/dbaas_flavor_v1) data source.

* `flavor` — (Optional) Flavor configuration for the cluster. You can retrieve information about available flavors with the [selectel\_dbaas\_flavor\_v1](/terraform/selectel-provider-reference/data-sources/dbaas_flavor_v1) data source. Learn more about available configurations for [PostgreSQL](/managed-databases/postgresql/configurations/), [PostgreSQL for 1C](/managed-databases/postgresql-for-1c/configurations/), and [PostgreSQL TimescaleDB](/managed-databases/timescaledb/configurations/).

  * `vcpus` — (Required) Number of vCPUs.

  * `ram` — (Required) Amount of RAM in MB.

  * `disk` — (Required) Volume size in GB.

  * `disk_type` — (Optional) Volume type. Available values are `local` and `network-ultra`. The default value is `local.` Learn more about volumes for [PostgreSQL](/managed-databases/postgresql/volumes/), [PostgreSQL for 1C](/managed-databases/postgresql-for-1c/volumes/) and [PostgreSQL TimescaleDB](/managed-databases/timescaledb/volumes).

* `pooler` — (Optional) Configures a connection pooler for the cluster. Applicable to PostgreSQL and PostgreSQL TimescaleDB.

  * `mode` — (Required) Pooling mode. Available values are `session`, `transaction`, and `statement`. The default value is `transaction.` Learn more about pooling modes for [PostgreSQL](/managed-databases/postgresql/connection-pooler/#pooling-modes) and [PostgreSQL TimescaleDB](/managed-databases/timescaledb/connection-pooler/#pooling-modes).

  * `size` — (Required) Pool size. The available range is from 1 to 500. The default value is `30`. Learn more about pool size for [PostgreSQL](/managed-databases/postgresql/connection-pooler/#pool-size) and [PostgreSQL TimescaleDB](/managed-databases/timescaledb/connection-pooler/#pool-size).

* `firewall` — (Deprecated) Remove this argument as it is no longer in use and will be removed in the next major version of the provider. To manage a list of IP-addresses with access to the cluster, use the [selectel\_dbaas\_firewall\_v1](/terraform/selectel-provider-reference/resources/dbaas_firewall_v1) resource.

* `restore` — (Optional) Restores parameters for the cluster. Changing this creates a new cluster.

  * `datastore_id` — (Optional) Unique identifier of the cluster from which you restore. To get the cluster ID, in the [Control panel](https://my.selectel.ru/vpc/default/dbaas/), go to **Cloud Platform** ⟶ **Managed Databases** ⟶ copy the ID under the cluster name.

  * `target_time` — (Optional) Time within seven previous days when you have the cluster state to restore.

* `config` — (Optional) Configuration parameters for the cluster. You can retrieve information about available configuration parameters with the [selectel\_dbaas\_configuration\_parameter\_v1](/terraform/selectel-provider-reference/data-sources/dbaas_configuration_parameter_v1) data source.

* `floating_ips` — (Optional) Assigns public IP addresses to the nodes in the cluster. The network configuration must meet the requirements. Learn more about [public IP addresses and the required network configuration](/managed-databases/postgresql/public-ip/).

  * master — (Required) Number of public IPs associated with the master. Available values are `0` and `1`.

  * replica — (Required) Number of public IPs associated with the replicas. The minimum value is `0`. The maximum value must be 1 less than the value of the `node_count` argument.

* `backup_retention_days` — (Optional) Number of days to retain backups.

* `logs` — (Optional) Name of an existing or a new log group in the [Logs](/logs/about-logs/) service. The name must start with the prefix 's/dbaas/'. It can contain uppercase and lowercase letters, digits and symbols (underscore, hyphen, forward slash, period and hash). The name cannot exceed 512 symbols. For example, s/dbaas/My-first-group. Learn more about logs for [PostgreSQL](/managed-databases/postgresql/logs/), [PostgreSQL for 1C](/managed-databases/postgresql-for-1c/logs/) and [PostgreSQL TimescaleDB](/managed-databases/timescaledb/logs/).

* `security_groups` — (Optional) List of security groups. If no security group UUIDs are specified when creating the cluster, a default security group will be created and its UUID will be assigned automatically. A cluster must have at least one security group. Learn more about security groups for [PostgreSQL](/managed-databases/postgresql/network-access-control/#security-groups-in-managed-databases), [PostgreSQL for 1C](/managed-databases/postgresql-for-1c/network-access-control-1c/#security-groups-in-managed-databases) and [PostgreSQL TimescaleDB](/managed-databases/timescaledb/network-access-control/#security-groups-in-managed-databases).

## Attributes Reference \{#attributes-reference}

* `status` — Cluster status.

* `connections` — DNS addresses to connect to the cluster.

## Import \{#import}

You can import a cluster:

```shell
export OS_DOMAIN_NAME=<account_id>
export OS_USERNAME=<username>
export OS_PASSWORD=<password>
export INFRA_PROJECT_ID=<selectel_project_id>
export INFRA_REGION=<selectel_pool>
terraform import selectel_dbaas_mysql_datastore_v1.cluster_1 <datastore_id>
```

where:

* `<account_id>` — Selectel account ID. The account ID is in the top right corner of the [Control panel](https://my.selectel.ru/). Learn more about [Registration](/account/registration/).

* `<username>` — Name of the service user. To get the name, in the [Control panel](https://my.selectel.ru/iam/users_management/users?type=service), go to **Identity & Access Management** ⟶ **User management** ⟶ the **Service users** tab ⟶ copy the name of the required user. Learn more about [Service users](/access-control/access-management/).

* `<password>` — Password of the service user.

* `<selectel_project_id>` — Unique identifier of the associated project. To get the ID, in the [Control panel](https://my.selectel.ru/vpc/default/dbaas/), go to **Cloud Platform** ⟶ project name ⟶ copy the ID of the required project. Learn more about [Projects](/access-control/projects/about-projects/).

* `<selectel_pool>` — Pool where the cluster is located, for example, `ru-3`. To get information about the pool, in the [Control panel](https://my.selectel.ru/vpc/default/dbaas/), go to **Cloud Platform** ⟶ **Managed Databases**. The pool is in the **Pool** column.

* `<datastore_id>` — Unique identifier of the cluster, for example, `b311ce58-2658-46b5-b733-7a0f418703f2`. To get the cluster ID, in the [Control panel](https://my.selectel.ru/vpc/default/dbaas/), go to **Cloud Platform** ⟶ **Managed Databases** ⟶ copy the ID under the cluster name.
