yandex_mdb_postgresql_cluster_v2 (Resource)
Written by
Updated at September 11, 2025
- Example Usage
- Schema
- Required
- Optional
- Read-Only
- Nested Schema for hosts
- Nested Schema for config
- Nested Schema for config.access
- Nested Schema for config.backup_window_start
- Nested Schema for config.disk_size_autoscaling
- Nested Schema for config.performance_diagnostics
- Nested Schema for config.pooler_config
- Nested Schema for config.resources
- Nested Schema for maintenance_window
- Nested Schema for restore
- Nested Schema for timeouts
- Import
Manages a PostgreSQL cluster within the Yandex Cloud. For more information, see the official documentation. How to connect to the DB. To connect, use port 6432. The port number is not configurable.
Example Usage
//
// Create a new MDB PostgreSQL Cluster (v2).
//
resource "yandex_mdb_postgresql_cluster_v2" "my_v2_cluster" {
name = "test"
environment = "PRESTABLE"
network_id = yandex_vpc_network.foo.id
config {
version = 17
resources {
resource_preset_id = "s2.micro"
disk_type_id = "network-ssd"
disk_size = 16
}
postgresql_config = {
max_connections = 395
enable_parallel_hash = true
autovacuum_vacuum_scale_factor = 0.34
default_transaction_isolation = "TRANSACTION_ISOLATION_READ_COMMITTED"
shared_preload_libraries = "SHARED_PRELOAD_LIBRARIES_AUTO_EXPLAIN,SHARED_PRELOAD_LIBRARIES_PG_HINT_PLAN"
}
}
maintenance_window {
type = "WEEKLY"
day = "SAT"
hour = 12
}
hosts = {
"host1d" = {
zone = "ru-central1-d"
subnet_id = yandex_vpc_subnet.foo.id
}
}
}
// Auxiliary resources
resource "yandex_vpc_network" "foo" {}
resource "yandex_vpc_subnet" "foo" {
zone = "ru-central1-d"
network_id = yandex_vpc_network.foo.id
v4_cidr_blocks = ["10.5.0.0/24"]
}
Schema
Required
environment(String) Deployment environment of the PostgreSQL cluster.hosts(Attributes Map) A host configuration of the PostgreSQL cluster. (see below for nested schema)name(String) Name of the PostgreSQL cluster. Provided by the client when the cluster is created.network_id(String) TheVPC Network IDof subnets which resource attached to.
Optional
config(Block, Optional) Configuration of the PostgreSQL cluster. (see below for nested schema)deletion_protection(Boolean) Thetruevalue means that resource is protected from accidental deletion.description(String) Description of the PostgreSQL cluster.disk_encryption_key_id(String) ID of the KMS key for cluster disk encryption.folder_id(String) The folder identifier that resource belongs to. If it is not provided, the default providerfolder-idis used.labels(Map of String) A set of key/value label pairs which assigned to resource.maintenance_window(Attributes) Maintenance policy of the PostgreSQL cluster. (see below for nested schema)restore(Attributes) The cluster will be created from the specified backup. (see below for nested schema)security_group_ids(Set of String) The list of security groups applied to resource or their components.timeouts(Attributes) (see below for nested schema)
Read-Only
id(String) The resource identifier.
Nested Schema for hosts
Required:
zone(String) The availability zone where the host is located.
Optional:
assign_public_ip(Boolean) Whether the host should get a public IP address.replication_source(String) FQDN of the host that is used as a replication source.subnet_id(String) ID of the subnet where the host is located.
Read-Only:
fqdn(String) The fully qualified domain name of the host.
Nested Schema for config
Required:
version(String) Version of the PostgreSQL cluster.
Optional:
access(Attributes) Access policy to the PostgreSQL cluster. (see below for nested schema)autofailover(Boolean) Configuration setting which enables/disables automatic failover in the cluster.backup_retain_period_days(Number) The period in days during which backups are stored.backup_window_start(Attributes) Time to start the daily backup, in the UTC timezone. (see below for nested schema)disk_size_autoscaling(Attributes) Cluster disk size autoscaling settings. (see below for nested schema)performance_diagnostics(Attributes) Cluster performance diagnostics settings. The structure is documented below. (see below for nested schema)pooler_config(Attributes) Configuration of the connection pooler. (see below for nested schema)postgresql_config(Map of String) PostgreSQL cluster configuration. For detailed information specific to your PostgreSQL version, please refer to the API proto specifications .resources(Block, Optional) Resources allocated to hosts of the PostgreSQL cluster. (see below for nested schema)
Nested Schema for config.access
Optional:
data_lens(Boolean) Allow access for Yandex DataLens.data_transfer(Boolean) Allow access for DataTransferserverless(Boolean) Allow access for connection to managed databases from functionsweb_sql(Boolean) Allow access for SQL queries in the management console
Nested Schema for config.backup_window_start
Optional:
hours(Number) The hour at which backup will be started (UTC).minutes(Number) The minute at which backup will be started.
Nested Schema for config.disk_size_autoscaling
Required:
disk_size_limit(Number) The overall maximum for disk size that limit all autoscaling iterations. See the documentation for details.
Optional:
emergency_usage_threshold(Number) Threshold of storage usage (in percent) that triggers immediate automatic scaling of the storage. Zero value means disabled threshold.planned_usage_threshold(Number) Threshold of storage usage (in percent) that triggers automatic scaling of the storage during the maintenance window. Zero value means disabled threshold.
Nested Schema for config.performance_diagnostics
Required:
sessions_sampling_interval(Number) Interval (in seconds) for pg_stat_activity sampling. Acceptable values are 1 to 86400, inclusive.statements_sampling_interval(Number) Interval (in seconds) for pg_stat_statements sampling. Acceptable values are 60 to 86400, inclusive.
Optional:
enabled(Boolean) Enable performance diagnostics
Nested Schema for config.pooler_config
Optional:
pool_discard(Boolean) Setting pool_discard parameter in Odyssey.pooling_mode(String) Mode that the connection pooler is working in. See descriptions of all modes in the documentation for Odyssey
Nested Schema for config.resources
Required:
disk_size(Number) Size of the disk in bytes.disk_type_id(String) ID of the disk type that determines the disk performance characteristics.resource_preset_id(String) ID of the resource preset that determines the number of CPU cores and memory size for the host.
Nested Schema for maintenance_window
Optional:
day(String) Day of the week (in DDD format). Allowed values: "MON", "TUE", "WED", "THU", "FRI", "SAT","SUN"hour(Number) Hour of the day in UTC (in HH format). Allowed value is between 1 and 24.type(String) Type of maintenance window. Can be either ANYTIME or WEEKLY. A day and hour of window need to be specified with weekly window.
Nested Schema for restore
Required:
backup_id(String) Backup ID. The cluster will be created from the specified backup. How to get a list of PostgreSQL backups.
Optional:
time(String) Timestamp of the moment to which the PostgreSQL cluster should be restored. (Format:2006-01-02T15:04:05- UTC). When not set, current time is used.time_inclusive(Boolean) Flag that indicates whether a database should be restored to the first backup point available just after the timestamp specified in the [time] field instead of just before. Possible values:
false(default) — the restore point refers to the first backup moment before [time].true— the restore point refers to the first backup point after [time].
Nested Schema for timeouts
Optional:
create(String) A string that can be parsed as a duration consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).delete(String) A string that can be parsed as a duration consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.update(String) A string that can be parsed as a duration consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
Import
The resource can be imported by using their resource ID. For getting the resource ID you can use Yandex Cloud Web Console
# terraform import yandex_mdb_postgresql_cluster_v2.<resource Name> <resource Id>
terraform import yandex_mdb_postgresql_cluster_v2.my_v2_cluster ...