Updated on 2025-01-02 GMT+08:00

Configuring Replication Delay for a Read Replica

Scenarios

You can configure a replication delay for a read replica. The read replica replays the WAL logs received from the primary instance after the specified delay.

If any data is deleted from your DB instance by mistake, it will be deleted from the read replica after the specified delay. During this time period, you can stop WAL log replay on the read replica, dump the data from the read replica, and insert it into the primary instance to restore the data.

Constraints

  • To use this function, contact customer service to obtain required permissions.
  • This function is only available to read replicas of RDS for PostgreSQL 12 and later versions.
  • After you enable WAL replay to a specific time, the replication between the primary instance and read replica will be interrupted. During this period, if the WAL logs of the primary instance are rotated, the read replica will be disconnected from the primary instance (data of the primary instance cannot be synchronized to the read replica). To reconnect the read replica to the primary instance, reset the replay time and contact customer service to restore the read replica. The time required depends on how much data there is in the read replica and how many available resources there are in the primary instance.

Configuring Read Replica Delay

  1. Log in to the management console.
  2. Click in the upper left corner and select a region.
  3. Click in the upper left corner of the page and choose Databases > Relational Database Service.
  4. In the instance list, click in front of the target DB instance and then click the name of the target read replica.
  5. Go to the Read Replica Delay page or refresh the page. The read replica delay details at the current time are displayed.

    Figure 1 Read Replica Delay Details
    Table 1 Read replica delay details

    Parameter

    Description

    WAL Replay

    The WAL replay status of the read replica. You can pause or resume WAL replay by toggling the switch.

    • Toggling on the switch: WAL replay starts.
    • Toggling off the switch: WAL replay pauses.

    Actual Delay

    The actual delay for WAL replay on the read replica during page loading or refreshing, in ms.

    The value of this parameter is slightly different from that of Custom Delay. For example, if there are no data writes to the primary instance and no WAL logs are synchronized, the actual delay is 0 ms.

    Custom Delay

    User-defined delay, in ms. Click to edit it.

    The delay cannot be too long. Otherwise, if the primary instance is heavily loaded, a large number of WAL logs are stacked on the read replica, causing full storage issues or even read replica disconnection.

    Latest Replayed WAL Log Position

    The latest WAL log position replayed by the read replica.

    Latest Received WAL Log Position

    The latest WAL log position received by the read replica.

Replaying WAL Data to a Specific Time

  1. On the Read Replica Delay page of the read replica, pause WAL replay.

    Figure 2 Pausing replay

  2. Toggle on the replay switch and select To a specific time for Replay Type. The replay will be paused after the WAL logs are replayed to the specified time.

    Figure 3 Replaying to a specific time

    Automatic indicates the normal replay state. The read replica will continuously replay the received WAL logs.

  3. Specify Replay Time and click OK.

    The read replica replays WAL logs to the closest transaction commit time before the target replay time.

  4. Click Reboot to replay WAL logs to the specified time.

    Figure 4 Rebooting the read replica

  5. Check the replay status.

    Figure 5 Replaying
    Figure 6 Replay completed

  6. To restore the replay, reset the replay time and reboot the read replica.

    1. Click Reset Replay Time. In the displayed dialog box, click OK.

      After the read replica is rebooted, there will still be a replay delay. The delay depends on the value of recovery_min_apply_delay. If you want to immediately replay the WAL logs to the specified time, set this parameter to 0.

      Figure 7 Resetting the replay time
    2. Click Reboot.
      Figure 8 Rebooting the read replica
    3. Check whether the replay status becomes normal.
      Figure 9 Normal replay