High availability and load balancing
-
Why do I get an error when setting up cascading replication?
-
Can I configure multimaster in a cluster or between two clusters?
-
How to configure load balancing so that read requests go to replicas?
-
Why does the master fail over to a randomly selected host when autofailover is off?
-
Why does the master fail over when the cluster recovers, even though autofailover is off?
How to exclude a host from the master selection?
You can exclude a host from the master selection when replacing the master host automatically or manually. To do this, set up cascade replication: specify 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 host 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
The error occurs if you specify a replication source for a single non-cascading replica.
To ensure high availability, your cluster must have at least one replica without a replication source. During maintenance or if the master host fails, this replica will take over as the master.
To learn more about replication, see this guide.
How do I always connect to the master host?
To connect to the current master host, use a special FQDN. It has this format: c-<cluster_ID>.rw.mdb.yandexcloud.net. When connected to this FQDN, you will be able to perform read and write operations.
Example of command for connection to a master
psql "host=c-<cluster_ID>.rw.mdb.yandexcloud.net \
port=6432 \
sslmode=verify-full \
dbname=<DB_name> \
user=<username>"
How do I always connect to the most recent replica?
To connect to the most recent replica, use a special FQDN. It has this format: c-<cluster_ID>.ro.mdb.yandexcloud.net. When connected to this FQDN, you can perform only read operations.
Example of command for connection 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 the replicas switch places?
This means the master has failed over to the replica host. Failover ensures cluster availability during maintenance or if the master fails.
Use a special FQDN to always connect to the current master.
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 multimaster in a cluster or between two clusters?
No, Managed Service for PostgreSQL does not support multimaster configuration.
For more information on how to ensure high availability of a cluster, see High availability managed databases (MDB).
How do I configure load balancing so that read requests only go to replicas?
As Managed Service for PostgreSQL does not perform any load balancing, you need to configure it in your application backend. To send read requests to replicas, the application must independently recognize master and replica hosts, e.g., using libpq. For more information, see this PostgreSQL article
Alternatively, use a special FQDN that points to the most recent replica.
For more information, see High availability.
Why does the master fail over to a randomly selected host when autofailover is off?
Even with autofailover disabled, the master host may switch to another host during maintenance or cluster updates. This helps keep the cluster working correctly during these operations.
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.
Why does the cluster switch masters after recovery, even though autofailover is disabled?
Even with autofailover disabled, the master host may switch to another host after recovery. This helps keep the cluster working correctly under such conditions. For more information, see High availability of a Managed Service for PostgreSQL cluster.
Why does the master fails over automatically during maintenance operations, even though autofailover is off?
Even with autofailover disabled, the master host may switch to another host to allow maintenance.