Logical replication slots retain write-ahead logging (WAL) files until a subscriber reads them. When a slot goes inactive, WAL files accumulate indefinitely. If the disk fills up, the cluster locks and data writes fail, disrupting your business.
To prevent this, monitor your replication slots regularly and drop any that are no longer in use.
Prerequisites
Before you begin, make sure:
For a centralized cluster (Enterprise Edition or Standard Edition): set the
wal_levelparameter tologicalfrom the PolarDB console. The cluster restarts after the change — plan accordingly.For a distributed cluster:
wal_levelis set tologicalby default. No action required.
View logical replication slots
If no logical replication slots exist in your cluster, create the relevant resources first. To enable the logical replication slot view in the PolarDB console, contact us.
Log on to the PolarDB console. In the left-side navigation pane, select Clusters, choose the region of your cluster, and click the cluster ID to go to the Basic Information page.
In the left-side navigation pane, choose Settings and Management > Subscription Management. On the WAL File Management tab, view the logical replication slots for the cluster. The following table describes each field.
Field Description Slot Name The name of the logical replication slot. Slot Type The type of the logical replication slot. Only logicalis supported.Use Plug-in The output plugin used by the slot. PolarDB for PostgreSQL supports decoderbufs,decoder_raw,wal2json, andpgoutput.Temporary Slot Whether the slot is temporary. A temporary slot exists only for the current session and is deleted automatically when the session ends. true= temporary;false= persistent.Database Name The database where the slot resides. Accumulated WAL Files The amount of WAL data retained by this slot. Unit: MB. Logical Subscription Latency The replication lag between the publisher and subscriber for this slot. Unit: seconds. Whether Active The current status of the slot: ACTIVE(a subscriber is connected) orINACTIVE(no subscriber is connected).(Optional) If the Whether Active field shows
INACTIVE, WAL files are accumulating. Resolve this as soon as possible using one of the following methods:Activate the slot to change its status to
ACTIVE.Drop the slot if it is no longer needed:
SELECT pg_drop_replication_slot('slot_name');
(Optional) Create a logical replication slot
Use the following steps to set up logical replication between two databases in the same cluster.
In the publisher database, create a publication for the table you want to replicate.
CREATE PUBLICATION <publication_name> FOR TABLE <table_name>;Example:
CREATE PUBLICATION pub1 FOR TABLE public.t1;To list existing publications, run:
SELECT * FROM pg_publication;In the publisher database, use the privileged account to create a logical replication slot.
SELECT pg_create_logical_replication_slot('<slot_name>', 'pgoutput');In the subscriber database, create a table with the same schema and name as the publisher table.
In the subscriber database, create the subscription. Reference the slot you created in step 2 and set
create_slot=falseto reuse it.CREATE SUBSCRIPTION my_subscription CONNECTION 'channel_name=localhost dbname=<publisher_database> user=<privileged_account> password=<password>' PUBLICATION pub1 WITH (create_slot=false, slot_name=<slot_name>);ImportantWhen the publisher and subscriber are in the same cluster, you must add
WITH (create_slot=false)to instruct the subscriber not to create a new replication slot and instead use the existing one.