High availability and load balancing
-
Why do I get an error when setting up cascading replication?
-
How to ensure I am always connecting to the most up-to-date replica?
-
Can I configure multi-master within a single cluster or between two clusters?
-
How to configure load balancing so that all read requests are redirected to replicas?
How to remove a host from the master selection process?
You can exclude a host from the master selection process during an automatic or manual failover. To do this, set up cascading replication by specifying a replication source for the host you want to exclude.
Warning
To ensure high availability during maintenance, your cluster must have at least one replica without a replication source.
Why do I get an error when setting up cascading replication?
Error message:
cluster should have at least 2 HA hosts to use cascade host
This error occurs if you specify a replication source for the only non-cascading replica.
To ensure high availability, your cluster must have at least one replica without a replication source. This replica will be promoted to master if the master host fails during maintenance.
To learn more about replication, see this article.
How to ensure I am always connecting to the master host?
To connect to the current master host, use a special FQDN in the c-<cluster_ID>.rw.mdb.yandexcloud.net format. This FQDN supports read and write access.
Example command for connecting to the master host
psql "host=c-<cluster_ID>.rw.mdb.yandexcloud.net \
port=6432 \
sslmode=verify-full \
dbname=<DB_name> \
user=<username>"
How to ensure I am always connecting to the most up-to-date replica?
To connect to the most up-to-date replica, use a special FQDN in the c-<cluster_ID>.ro.mdb.yandexcloud.net format. This FQDN only supports read access.
Example command for connecting to a replica
psql "host=c-<cluster_ID>.ro.mdb.yandexcloud.net \
port=6432 \
sslmode=verify-full \
dbname=<DB_name> \
user=<username>"
If there are no active replicas in the cluster, this FQDN will point to the current master host.
Why did the master and replicas swap roles?
This means the master has failed over to the replica. Automatic master failover guarantees cluster availability during maintenance or in the event of the master host failure.
To connect to the current master host, use a special FQDN.
Warning
Use master host special FQDN-based connections only for processes that can cope with database being unavailable for writing for up to 10 minutes.
Can I configure multi-master within a single cluster or between two clusters?
No, Managed Service for PostgreSQL does not support multi-master configuration.
For more details on high availability cluster configuration, see High availability managed databases (MDB).
How to configure load balancing so that all read requests are redirected to replicas?
As Managed Service for PostgreSQL does not provide load balancing, you need to configure it in your application backend. To send read requests to replicas, your application must first identify the master and replica hosts, e.g., by using libpq. For more information, see this PostgreSQL article
Alternatively, use a special FQDN pointing to the most up-to-date replica.
For more information, see High availability.
When does automatic failover occur?
The master host can automatically fail over to another host:
- During cluster updates.
- On master host failure.
- Upon cluster recovery.
- During maintenance.
Master failover ensures the cluster works correctly under the listed conditions.
Note
To ensure high availability, the cluster always has at least one replica without an explicitly defined replication source. This replica can take over as master when needed.