Help Center/ Relational Database Service_RDS for PostgreSQL/ Best Practices/ Creating Replication Slots to Enable CDC
Updated on 2025-09-04 GMT+08:00

Creating Replication Slots to Enable CDC

Function Description

Open-source PostgreSQL uses replication slots to enable Change Data Capture (CDC). Replication slots are the core for logical replication. They can:

  1. Ensure that WAL logs of the primary database are not cleared until all logs are consumed by secondary databases or subscribers.
  2. Record subscribers' consumption positions (LSNs) to prevent data loss or repeated consumption.
  3. Parse WAL logs into readable change data (such as INSERT, UPDATE, and DELETE operations) using logical decoding plugins (like test_decoding and wal2json) to implement CDC.

This topic describes how to enable CDC for an RDS for PostgreSQL instance.

Prerequisites

Precautions

  • You can enable CDC and consume captured data only on the primary instance. Read replicas do not support this feature.
  • RDS for PostgreSQL supports logical replication slot failover. A primary/standby switchover does not affect CDC. For more information, see Failover Slot for Logical Subscriptions.
  • Before enabling CDC, modify RDS for PostgreSQL instance parameters and reboot the instance. To prevent impact on workloads, modify parameters during off-peak hours.

Enabling CDC

Disabling CDC

RDS for PostgreSQL instances with CDC enabled require more space for storing WAL logs. If CDC is no longer needed, to prevent replication slots from running out of storage space, disable CDC by performing the following operations:

  1. Connect to the RDS for PostgreSQL instance using the account root.
    psql -h <instance-address> -p 5432 -U root -d testdb
  2. (Optional) Check for the replication slot.
    SELECT slot_name FROM pg_replication_slots WHERE slot_name = 'cdc_replication_slot';
  3. Delete the replication slot. This operation cannot be undone. Exercise caution when performing this operation.
     SELECT pg_drop_replication_slot('cdc_replication_slot');
  4. Verify that CDC is disabled.
    SELECT slot_name FROM pg_replication_slots;

    If the query result does not contain cdc_replication_slot, the feature has been disabled.