Logical Replication Slot Failover

Last updated: 2024-05-10 09:50:52

Feature Background

Currently, you will create a logical replication slot when using logical replication in the TencentDB for PostgreSQL. As this information is not recorded in the catalog, it will not be synchronized from the primary database to the standby database. If an HA switchover occurs, the logical replication slot will be lost, causing the logical replication to be disconnected and causing inconvenience to the business. Therefore, the logical replication slot need to be failed over.

Feature Overview

The failover slot feature can synchronize the slot information from the primary database to the standby database, so that the disconnection of the logical subscription can be avoided after the HA switchover, and the user can continue to use the logical subscription without disruption. TencentDB for PostgreSQL provides tencent_failover_slot, a plugin for users to create failover slots, convert them to non-failover slots, view failover slot information, and delete failover slots. At the same time, GUC parameters are added to help you configure for abnormal situations. The details are as follows.

Creating a failover slot

create extension tencentdb_failover_slot;--Create a plugin first
select pg_create_logical_failover_slot('slotname','pluginname');--Create a failover slot
Note:
Slots are at the instance level, while plugins are at the database level. If you need to call functions in the plugins after switching the database, you need to recreate the tencentdb_failover_slot plugin.
The pg_create_logical_failover_slot function contains two parameters:
slotname: The name of the failover slot.
Pluginname: The name of the plugin.

Converting a failover slot to non-failover slot

select transform_slot_to_nonfailover('slotname');
Note:
Slotname: The name of the slot.
Make sure that the slot is currently inactive, meaning that no publication or subscription is using it.

Viewing the information of a failover slot

postgres=# select * from pg_failover_slots;
slot_name
-----------------
fs
fsg
(2 rows)
Note:
The pg_failover_slots view contains a column showing the names of all current failover slots. For more information about failover slots, go to the pg_replication_slots view.

Deleting a failover slot

select * from pg_drop_replication_slot('slotname');
Note:
Slotname: The name of the slot.

Setting parameters

A new parameter failover_slot_timeline_diverged_option has been added, which is an enum type, allowing users to configure settings for handling abnormal situations. You can set this parameter in the TencentDB for PostgreSQL Console by navigating to Cloud Database PostgreSQL Console > Instance Details > Parameter Settings. The default value of this parameter is error, with optional values error and rewind. In extreme cases, when the standby log reception speed is slower than the logical replication and an HA event occurs, if the parameter is set to error, the logical replication will pause, and both the publisher and subscriber will receive an error message, waiting for the user to handle it. If the parameter is set to rewind, the logical replication will start from the switchover time point.

Supports and Limits

Currently, only logical replication slot failover is supported, whereas physical replication slot failover is not.