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_gailover_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.
Parameter settings
TencentDB for PostgreSQL has added a new parameter failover_slot_timeline_diverged_option
with the type of enum
, which is convenient for you to configure for abnormal situations. You can log in to the TencentDB for PostgreSQL console, and configure this parameter on Instance Details > Parameter Settings. The default value of this parameter is error
, and the optional values are error
and rewind
. In extreme cases, the log receiving speed of the standby database is slower than that of logical replication and the HA switch occurs. If error
is set as the value, it means that logical replication will be paused, and both the publisher and subscriber can receive an error report and wait for you to process it. If the value is set to rewind
, the logical replication will start from the time point when the switch is performed. Note
Currently, only logical replication slot failover is supported, whereas physical replication slot failover is not.
Was this page helpful?