Creating PostgreSQL clusters
A PostgreSQL cluster consists of one or more database hosts you can configure replication between. Replication is enabled by default in any cluster consisting of more than one host: the master host accepts write requests and duplicates changes on replicas. The transaction is confirmed if the data is written to disk both on the master host and on a certain number of replicas sufficient to establish a quorum.
Note
- The number of hosts you can create together with a PostgreSQL cluster depends on the selected host class.
- If DB storage is 95% full, the cluster switches to read-only mode. Plan and increase the required storage size in advance.
By default, Managed Service for PostgreSQL sets the maximum number of connections to each PostgreSQL cluster host. This maximum cannot be greater than the value of Max connections.
Warning
Managed Service for PostgreSQL reserves 15 connections for service users per PostgreSQL host. For example, if the cluster has Max connections 100
, you can reserve a maximum of 85 connections for cluster users.
How to create a PostgreSQL cluster
-
In the management console
, select Managed Service for PostgreSQL. -
Click Create cluster.
-
Name the cluster in the Cluster name field.
-
Select the host class that defines the technical specifications of the VMs where the DB hosts will be deployed. All available options are listed in PostgreSQL host classes. When you change the host class for the cluster, the characteristics of all existing hosts change, too.
-
Under Storage size:
-
Select the disk type.
-
Select the storage size for data and backups. For more information about how backups take up storage space, see Backups in Managed Service for PostgreSQL.
-
-
Under Database, specify the DB attributes:
-
DB name.
A database name may contain Latin letters, numbers, underscores, and hyphens. The maximum name length is 63 characters. The names
postgres
,template0
andtemplate1
are reserved for Managed Service for PostgreSQL. You cannot create databases with these names. -
The DB owner username and password. By default, the new user is assigned 50 connections to each host in the cluster.
Note
A username may contain letters, numbers, hyphens and underscores, but must start with a letter (other than
pg_
), number or underscore. The maximum name length is 63 characters.The names
admin
,repl
,monitor
,postgres
,mdb_admin
,mdb_monitor
andmdb_replication
are reserved for Managed Service for PostgreSQL. You cannot create users with these names.The password must be between 8 and 128 characters.
-
Locale for sorting and character set locale. These settings define the rules for sorting strings (
LC_COLLATE
) and classifying characters (LC_CTYPE
). In Managed Service for PostgreSQL, locale settings apply at the individual DB level.PostgreSQL uses locales to support various language standards. The locale you choose affects:
- Sort order in the queries that use the
ORDER BY
operator or standard text data matching operators. - The functions
upper
,lower
,initcap
, and theto_char
family of functions. - Pattern matching operators (
LIKE
,ILIKE
,SIMILAR TO
, regular expressions). - Support of indexes with the
LIKE
operator.
By default, the
C
locale is used. if you use theC
encoding for text data containing non-Latin characters, errors might occur in the data sort order and data display in the case of pattern search. If this locale is not suitable for valid processing of tables in your database, select another encoding from the list. However, please keep in mind that a non-standard locale might decrease the database query processing rate.For more information about locale settings, see the PostgreSQL documentation
.You cannot change locale settings after you create a database. However, you can set the sorting locale for columns when creating and modifying individual tables. Learn more in the PostgreSQL documentation
. - Sort order in the queries that use the
-
-
Under Hosts, select the parameters for the DB hosts created with the cluster: If you open Advanced settings, you can choose specific subnets for each host. By default, each host is created in a separate subnet.
-
Configure additional cluster settings, if required:
-
Backup start time (UTC): UTC time in 24-hour format when you would like to start creating a cluster backup. If the time is not set, the backup will start at 22:00 UTC.
-
Pooling mode: Choose one of connection pooler modes.
-
Deletion protection: Manages cluster protection from accidental deletion by a user.
Cluster deletion protection will not prevent a manual connection to delete the contents of a database.
-
-
If required, configure DBMS cluster-level settings.
Note
Some PostgreSQL settings depend on the selected host class or storage size.
-
Click Create cluster.
If you don't have the Nebius AI command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To create a cluster:
-
View a description of the create cluster CLI command:
ncp managed-postgresql cluster create --help
-
Specify cluster parameters in the create command (the list of supported parameters in the example is not exhaustive):
ncp managed-postgresql cluster create \ --name <cluster name> \ --network-name <network name> \ --host zone-id=<availability zone>,subnet-id=<subnet ID> \ --resource-preset <host class> \ --user name=<username>,password=<user password> \ --database name=<DB name>,owner=<DB owner name> \ --disk-size <storage size, GB> \ --disk-type <disk type> \ --connection-pooling-mode=<connection manager mode> \ --deletion-protection=<cluster deletion protection: true or false>
You need to specify
subnet-id
if the selected availability zone has two or more subnets.Warning
The cloud network selected for cluster deployment can't be changed. If you need to move your cluster to a different cloud network later, use the restore from a backup feature and specify the desired network for the cluster backup.
Available connection pooler modes include:
SESSION
,TRANSACTION
, orSTATEMENT
.A database name may contain Latin letters, numbers, underscores, and hyphens. The maximum name length is 63 characters. The names
postgres
,template0
andtemplate1
are reserved for Managed Service for PostgreSQL. You cannot create databases with these names.Note
The password must be between 8 and 128 characters.
Cluster deletion protection will not prevent a manual connection to delete the contents of a database.
Examples
Creating a single-host cluster
To create a cluster with a single host, provide a single --host
parameter.
Create a Managed Service for PostgreSQL cluster with test characteristics:
- Named
mypg
. - In the
default
network. - With one
s3-c2-m8
host in theb0rcctk2rvtr8efcch64
subnet in theeu-north1-c
availability zone. - With 20 GB of storage.
- With one user,
user1
, with the passworduser1user1
. - With one
db1
database owned byuser1
. - With protection against accidental cluster deletion.
Run the following command:
ncp managed-postgresql cluster create \
--name mypg \
--network-name default \
--resource-preset s3-c2-m8 \
--host zone-id=eu-north1-c,subnet-id=b0rcctk2rvtr8efcch64 \
--disk-size 20 \
--user name=user1,password=user1user1 \
--database name=db1,owner=user1 \
--deletion-protection=true