Step-by-Step CDC Recovery Guide: Oracle to PostgreSQL Migration

When dealing with AWS DMS CDC failures, you have options for restoring CDC from specific points in time, but there are important constraints:

Recovery Point Options for CDC

  1. Using CdcStartPosition

    • You can modify a replication task to start from a specific transaction log position

    • For Oracle, this is an SCN (System Change Number)

    • For PostgreSQL, it's an LSN (Log Sequence Number)

    • For MySQL, it's a binary log position

  2. Using CdcStartTime

    • Instead of a specific log position, you can set a timestamp

    • DMS will attempt to find the corresponding position in the transaction logs

    • Example (AWS CLI):

    Copyaws dms modify-replication-task \
      --replication-task-arn <task-arn> \
      --cdc-start-time "2025-01-15T12:00:00Z"

Critical Limitations

  1. Transaction Log Retention

    • You can only go back as far as your source database retains transaction logs

    • For Oracle: redo logs and archived logs

    • For PostgreSQL: WAL segments

    • For MySQL: binary logs

  2. Log Availability

    • If logs have been purged or are unavailable, you cannot restart CDC from that point

    • Many database systems automatically purge older logs

  3. Database-Specific Constraints

    • Oracle: Requires ARCHIVELOG mode and appropriate retention

    • PostgreSQL: Requires logical replication slots to be maintained

    • MySQL: Binary log expiration policy limits recovery points

Best Practices for CDC Recovery

  1. Configure adequate log retention

    • Extend transaction log retention periods on source databases

    • For Oracle, ensure ARCHIVELOG mode is enabled with adequate retention

    • For PostgreSQL, monitor and maintain logical replication slots

    • For MySQL, set binlog_expire_logs_seconds appropriately

  2. Create recovery checkpoints

    • Periodically capture and store the current log position

    • Consider creating DMS task bookmarks for critical points

    • Document SCN/LSN positions after major data loads or changes

  3. Implement monitoring for log retention

    • Monitor source database log space and retention

    • Set up alerts for log purging events

    • Track CDC lag metrics in CloudWatch

If logs for your desired recovery point have been purged, your only option would be to perform a new full load and restart CDC from that point. This is why preventive measures like extended log retention are crucial for CDC recovery strategies.

Step-by-step Gide

This guide explains how to set up, maintain, and recover CDC (Change Data Capture) during an Oracle to PostgreSQL migration using AWS DMS.

Part 1: Prerequisites and Configuration

Step 1: Configure Oracle Source for Optimal CDC Recovery

  1. Enable ARCHIVELOG Mode (if not already enabled):

  2. Configure Supplemental Logging:

  3. Configure Adequate Redo Log Retention:

  4. Create a Regular SCN Checkpoint Process:

  5. Monitor Oracle Archive Log Generation:

Step 2: Configure PostgreSQL Target for CDC

  1. Set Up Target PostgreSQL with Appropriate Settings:

  2. Configure PostgreSQL for Performance During CDC:

Step 3: Configure AWS DMS for Recoverable CDC

  1. Create Initial DMS Task with CDC in Mind:

  2. Configure task-settings.json with Logging and Oracle Settings:

  3. Create a Checkpoint Recording Script:

  4. Schedule Checkpoint Script:

Part 2: CDC Recovery Procedures

Step 1: Identifying Available Recovery Points

  1. Check Available Oracle SCN Checkpoints:

  2. Check Available Archive Logs:

  3. Check Minimum Available SCN:

  4. Check Recorded DMS Checkpoints in PostgreSQL:

Step 2: Recover CDC from a Specific SCN

  1. Stop the Current DMS Task:

  2. Modify Task to Start from Specific SCN:

  3. Start Task with New SCN Position:

  4. Monitor CDC Recovery Progress:

Step 3: Recover CDC from a Specific Timestamp

  1. Stop the Current DMS Task:

  2. Find the Nearest SCN for a Timestamp:

  3. Modify Task to Start from a Specific Time:

  4. Start Task with New Time Position:

  5. Verify Recovery Point Success:

Step 4: Handling Recovery Failures

  1. Check for Oracle Archive Log Availability Issues:

  2. Validate SCN Visibility to LogMiner:

  3. If Recovery Point Unavailable, Find Nearest Available SCN:

  4. Create a New Recovery Task if Original Can't Be Recovered:

Part 3: Post-Recovery Validation

  1. Verify Data Consistency After Recovery:

  2. Monitor CDC Performance After Recovery:

  3. Create Regular Data Validation Checks:

Part 4: Automating Recovery for High Availability

  1. Create a CDCMonitor Function in AWS Lambda:

  2. Create Required PostgreSQL Tables for Lambda Function:

  3. Set up CloudWatch Events to Trigger Lambda Function:

This comprehensive guide covers the setup, maintenance, and recovery of CDC during an Oracle to PostgreSQL migration using AWS DMS. The procedures are specifically designed for Oracle on-premises to PostgreSQL on AWS migrations, with an emphasis on establishing reliable recovery points and automating the recovery process.

Part 5: Long-Term CDC Maintenance

Step 1: Database-Side Maintenance

  1. Oracle Archive Log Management:

  2. PostgreSQL Maintenance Procedures:

Step 2: Regular Health Checks

  1. Oracle-side Health Check Script:

  2. PostgreSQL-side Health Check Script:

Step 3: Backup and Disaster Recovery for CDC

  1. Oracle Archive Log Backup Strategy:

  2. PostgreSQL CDC Configuration Backup:

Part 6: Troubleshooting CDC Issues

Common CDC Issues and Solutions

  1. Issue: CDC Task Fails with "ORA-01291: missing logfile"

    Solution:

  2. Issue: CDC Latency Increasing

    Solution:

  3. Issue: Oracle SCN Jumps Unexpectedly

    Solution:

  4. Issue: Inconsistent Data After CDC Recovery

    Solution:

This comprehensive guide covers the setup, maintenance, and recovery of CDC during an Oracle to PostgreSQL migration using AWS DMS. The procedures are specifically designed for Oracle on-premises to PostgreSQL on AWS migrations, with an emphasis on establishing reliable recovery points and automating the recovery process.

Last updated

Was this helpful?