PuglieseWeb
  • Home
  • Software development
    • Cloud Data Security Principles
      • Separation of Duties (SoD)
      • Security Controls and Data Protection Framework
      • Vaultless Tokenization
    • Multi-cloud strategies
    • DMS
      • How CDC Checkpoints Work
      • Oracle to PostgreSQL Time-Window Data Reload Implementation Guide
      • Join tables separate PostgreSQL databases
      • Multi-Stage Migration Implementation Plan
      • Notes
      • Oracle Golden Gate to PostgreSQL Migration
      • Step-by-Step CDC Recovery Guide: Oracle to PostgreSQL Migration
    • AWS Pro
      • My notes
        • Data Migration Strategy
        • OpsWorks VS CloudFormation
      • Implementation Guides
        • AWS Lambda Scaling and Concurrency Optimization Guide
        • Understanding Cross-Account IAM Roles in AWS
        • HA TCP with Redundant DNS
        • Understanding 429 (Too Many Requests) & Throttling Pattern
        • EC2 Auto Scaling Log Collection Solutions Comparison
        • AWS PrivateLink Implementation Guide for Third-Party SaaS Integration
        • AWS Cross-Account Network Sharing Implementation Guide
        • Cross-Account Route 53 Private Hosted Zone Implementation Guide
          • Route 53
            • Routing Policies
              • Using a Weighted Routing Policy
              • Simple Routing Policy
              • Multivalue Answer Routing
            • Latency Routing Policy
            • Route 53 Traffic Flow
        • Direct Connect Gateway Implementation Guide
        • CICD for Lambda
        • AWS IAM Identity Center Integration with Active Directory
        • AWS Transit Gateway Multi-Account Implementation Guide
          • AWS Multi-Account Network Architecture with Infrastructure Account
      • Links
      • Cloud Adoption Framework
      • Data Stores
        • Data Store Types and Concepts in AWS
        • S3
          • Amazon S3 (Simple Storage Service)
            • Bucket Policies
          • Managing Permissions in Amazon S3
          • Amazon Glacier: AWS Archive Storage Service
          • Lab: Querying Data in Amazon S3 with Amazon Athena
          • LAB: Loading Data into a Redshift Cluster
        • Attached Storage
          • EBS
          • AWS Elastic File System (EFS): From Sun Microsystems to Modern Cloud Storage
          • AWS FSx Service Guide
          • Amazon Storage Gateway Guide
        • Databases
          • Amazon Storage Gateway Guide
          • Amazon RDS (Relational Database Service)
          • Aurora DB
          • Dynamo DB
          • Document DB
          • Amazon Redshift Overview
          • Data Pipeline
            • Data Lake VS Lake Formation
          • AWS Data Preparation Services
          • Amazon Neptune
          • Amazon ElastiCache
          • AWS Specialized Database Services
          • LAB - Deploy an Amazon RDS Multi-AZ and Read Replica in AWS
      • Networking
        • Concept
        • Basics
          • VPG
          • VPC
            • VPC endpoints
              • Interface Endpoint VS Elastic Network Interface (ENI)
            • PrivateLink
              • PrivateLink SAAS Use case
            • Transit Gateway
            • 5G Networks
            • VPN CloudHub
            • VPC security
            • VPC peering
            • VPC Endpoint
            • Route Table (and Routers)
            • Network Access Control List (NACL)
            • Network Security Group
            • NAT Gateway
              • NACL vs NAT
          • Elastic Load Balancing (ELB)
            • Gateway Load Balancer (GWLB)
          • CIDR ranges examples
          • Enhanced Networking
          • Elastic Fabric Adapter (EFA)
          • Elastic Network Interface (ENI)
        • Network to VPC Connectivity
          • Transit VS Direct Connect Gateway
          • Direct Connect
            • VIF (Virtual Interfaces)
            • VIF VS ENI
            • Customer Routers VS Customer Gateways
        • VPC-to-VPC
        • NAT & Internet Gateway
        • Routing
          • IPv4 Address Classes and Subnet Masks
          • VPC's DNS server
          • Transit VPC VS Transit Gateway
          • Example Routing tables configuration
          • Cross-regions failover
          • Loopback
        • Enhanced Networking
        • Hybrid and Cross-Account Networking
        • AWS Global Accelerator
        • Route 53
        • Cross-Account Route 53
        • CloudFront SSL/TLS and SNI Configuration
        • ELB
        • Lab: Creating a Multi-Region Network with VPC Peering Using SGs, IGW, and RTs
        • LAB - Creating a CloudFront Distribution with Regional S3 Origins
        • Lab: Creating and Configuring a Network Load Balancer in AWS
        • Lab: Troubleshooting Amazon EC2 Network Connectivity
        • Lab: Troubleshooting VPC Networking
      • Security
        • Cloud Security
          • IAM
            • SCIM
            • Use case 1
          • Core Concepts of AWS Cloud Security
            • OAuth VS OpenID Connect
          • Understanding User Access Security in AWS Organizations
          • Exploring Organizations
          • Controlling Access in AWS Organizations
            • SCP (Service Control Policy) implementation types
        • Network Controls and Security Groups
          • Firewalls
            • Network Controls and Security Groups Overview
          • AWS Directory Services
          • AWS Identity and Access Management (IAM) and Security Services
            • ASW Identity Sources
          • AWS Resource Access Manager (RAM): Cross-Account Resource Sharing
            • AWS App Mesh
        • Encryption
          • History and Modern Implementation of Encryption in AWS
          • Secret Manager
          • DDoS Attacks and AWS Protection Strategies: Technical Overview
          • AWS Managed Security Services Overview
          • IDS and IPS
          • AWS Service Catalog
      • Migrations
        • Migration Concepts
          • Hybrid Cloud Architectures
          • Migration Strategies
        • Migration Application
          • Services and Strategies
          • AWS Data Migration Services
          • Network Migrations and Cutovers
            • Network and Broadcast Addresses
            • VPC DNS
          • AWS Snow Family
      • Architecting to scale
        • Scaling Concepts and Services
          • Auto-Scaling
          • Compute Optimizer
          • Kinesis
          • DynamoDB Scaling
          • CloudFront Part Duex
            • CloudFront's Behavior
            • Lambda@Edge and CloudFront Functions
        • Event-Driven Architecture
          • SNS and Fan-out Architecture
            • SNS & outbox pattern
          • AWS Messaging Services: SQS and Amazon MQ
          • Lab: Scaling EC2 Using SQS
          • Lambda
          • Scaling Containers in AWS
          • Step Function and Batch
          • Elastic MapReduce
          • AWS Data Monitoring and Visualization Services
      • Business Continuity
        • AWS High Availability and Disaster Recovery
        • AWS Disaster Recovery Architectures
        • EBS Volumes
        • AWS Compute Options for High Availability
        • AWS Database High Availability Options
        • AWS Network High Availability Options
        • Lab: Connect Multiple VPCs with Transit Gateway
        • Deployment and Operations Management
          • Software Deployment Strategies
            • AWS CI/CD
            • Elastic Beanstalk
              • Elastic Beanstalk and App Runner
            • CloudFormation
            • Cross-Account Infrastructure Deployment
              • Example Code Pipeline
            • AWS Container Services
            • AWS API Gateway
            • LAB: Understanding CloudFormation Template Anatomy
          • Management Tool
            • Config and OpsWorks
            • System Manager
            • Enterprise Apps
            • AWS Machine Learning Landscape
            • AWS IoT Services
      • Cost Management and Optimization
        • Concepts
        • AWS Cost Optimization Strategies
        • AWS Tagging and Resource Groups
        • Managing Costs Across AWS Accounts
        • AWS Instance Purchasing Options
        • AWS Cost Management Tools
      • Others
        • SCPs vs AWS Config
        • Questions notes
        • Comparison of Deployment Strategies in AWS
        • Bedrock vs EMR
        • Software Deployment Strategies
    • AWS
      • Others
        • AWS Example architectures
          • Gaming application
          • Digital Payment System
            • Marketplace Application
            • Analytics & Reporting System MVP
            • Reporting System 2
            • Data Pipeline
            • Monitoring and visualization solution for your event-driven architecture (EDA) in AWS.
              • Visualize how services are linked together for each business flow
              • Visualize flow and metrics
            • Reporting
            • Data
        • AWS Key Learning
        • AWS NFRs
          • AWS Integration Pattern Comparison Matrix
          • AWS 99.999% Architecture
        • AWS Best Practices
          • use S3 for data migration
          • Principle of centralized control
          • For CPU Spikes in DB use RDS Proxy
          • API Security
          • Lambda VS ECS
          • Use CloudFront for Dynamic content
        • ECS Sizing
        • AWS Q&A
          • AWS Prep
          • prepexam
          • Big Data/ AI Q&A
          • DB Q&A
          • AWS Application Servers Q&A
          • General Q&A
          • VPC Q&A
      • DRs
      • AI, Analytics, Big Data, ML
        • EMR
          • Flink
          • Spark
          • Hadoop
            • Hive
        • Extra
          • Glue and EMR
          • Redshift Use Cases
        • AI
          • Media Services (Elastic Transcoder, Kinesis)
          • Textract
          • Rekognition (part of the exam)
          • Comprehend
          • Kendra
          • Fraud Detector
          • Transcribe, Polly, Lex
          • Translate
          • Time-series and Forecast
        • Big Data
          • Processing & Analytics
            • Amazon Athena VS Amazon Redshift
            • Athena & AWS Glue: Serverless Data Solutions
          • BigData Storage Solutions
          • EMR
        • Business intelligence
        • Sagemaker
          • SageMaker Neo
          • Elastic Inference (EI)
          • Integration patterns with Amazon SageMaker
          • Common Amazon SageMaker Endpoint usage patterns
          • Real-time interfaces
          • ML Example
        • Machine Learning
          • Data Engineering
            • Understanding Data Preparation
            • Feature Engineering: Transforming Raw Data into Powerful Model Inputs
            • Feature Transformation and Scaling in Machine Learning
            • Data Binning: Transforming Continuous Data into Meaningful Categories
          • Exploratory Data Analysis
            • Labs
              • Perform Feature Engineering Using Amazon SageMaker
            • Categorical Data Encoding: Converting Categories to Numbers
            • Text Feature Extraction for Machine Learning
            • Feature Extraction from Images and Speech: Understanding the Fundamentals
            • Dimensionality Reduction and Feature Selection in Machine Learning
          • Modelling
            • Prerequisites for Machine Learning Implementation
            • Classification Algorithms in Machine Learning
            • Understanding Regression Algorithms in Machine Learning
            • Time Series Analysis: Fundamentals and Applications
            • Clustering Algorithms in Machine Learning
      • Databases
        • Capturing data modification events
        • Time-Series Data (Amazon Timestream)
        • Graph DBs
          • Amazon Neptune
        • NoSQL
          • Apache Cassandra (Amazon Keyspaces)
          • Redshift
            • Redshift's ACID compliance
          • MongoDB (Amazon DocumentDB)
          • DynamoDB
            • Additional DynamoDB Features and Concepts
            • DynamoDB Consistency Models and ACID Properties
            • DynamoDB Partition Keys
          • Amazon Quantum Ledger DB (QLDB)
        • RDS
          • DR for RDS
          • RDS Multi-AZ VS RDS Proxy
          • Scaling Relational Databases
          • Aurora Blue/Green deployments
          • Aurora (Provisioned)
          • Amazon Aurora Serverless
        • Sharing RDS DB instance with an external auditor
      • Caching
        • DAX Accelerator
        • ElastiChache
        • CloudFront (External Cache)
        • Global Accelerator (GA)
      • Storages
        • S3
          • MFA Delete VS Object Lock
          • S3 Standard VS S3 Intelligent-Tiering
        • Instance Storage
        • EBS Volumes
          • Burst Capacity & Baseline IOPS
          • Provisioned IOPS vs GP3
          • EBS Multi-Attach
        • Snapshots
        • AWS Backup
        • File Sharing
          • FSx (File system for Windows or for Lustre)
          • EFS (Elastic File System)
      • Migration
        • Migration Hub
        • Application Discovery Service
        • Snow Family
        • DMS
        • SMS (Server Migration Service)
        • MGN (Application Migration Service)
        • Transfer family
        • DataSync
        • Storage Gateway
          • Volume gateway
          • Tape Gateway
          • File Gateway
          • Storage Gateway Volume Gateway VS Storage Gateway File Gateway
        • DataSync VS Storage Gateway File Gateway
      • AWS Regional Practices and Data Consistency Regional Isolation and Related Practices
      • Front End Web application
        • Pinpoint
        • Amplify
        • Device Farm
      • Glossary
      • Governance
        • Well-Architected Tool
        • Service Catalog and Proton
          • AWS Service Catalog
          • AWS Proton
        • AWS Health
        • AWS Licence Manager
        • AWS Control Tower
        • AWS Trusted Advisor
        • Saving Plans
        • AWS Compute Optimizer
        • AWS CUR
        • Cost Explorer and Budgets
        • Directory Service
        • AWS Config
        • Cross-Account Role Access
        • Resource Access Manager (RAM)
        • Organizations, Accouts, OU, SCP
      • Automation
        • System Manager (mainly for inside EC2 instances)
        • Elastic Beanstalk (for simple solutions)
        • IaC
          • SAM
          • CloudFormation
            • !Ref VS !GetAtt
            • CloudFormation examples
      • Security
        • Identity Management Services
          • IAM
            • Identity, Permission, Trust and Resource Policies
              • IAM Policy Examples
              • Trust policy
            • IAM roles cannot be attached to IAM Groups
            • AWS IAM Policies Study Guide
            • Cross-Account Access in AWS: Resource-Based Policies vs IAM Roles
            • EC2 instance profile VS Trust policy
          • Cognito
        • STS
        • AI based security
          • GuardDuty
          • Macie (S3)
        • AWS Network Firewall
        • Security Hub
        • Detective (Root Cause Analysis)
        • Inspector (EC2 and VPCs)
        • System Manager Parameter Store
        • Secret Manager
          • Secret Manger VS System Manager's Parameter Store
          • Secret Manager VS AWS KMS
        • Shield
          • DDoS
        • KMS vs CloudHSM
        • Firewall Manager
        • AWS WAF
      • Compute
        • Containers
          • ECS
            • ECS Anywhere
          • EKS
            • EKS Anywhere
          • Fargate
            • ECS Fargate VS EKS Fargate
          • ECR (Elastic Container Registry)
        • EC2
          • EC2 Purchase Options
            • Spot instances VS Spot Fleet
          • EC2 Instance Types
            • T Instance Credit System
          • Auto Scaling Groups (ASG)
          • Launch Template vs. Launch Configuration
          • AMI
          • EC2 Hibernation
        • Lambda
          • Publish VS deploy
      • Data Pipeline
      • ETL
      • AppFlow
      • AppSync
      • Step Functions
      • Batch
        • Spring Boot Batch VS AWS Batch
      • Decoupling Workflow
      • Elastic Load Balancers
      • Monitoring
        • OpenSearch
        • CloudWatch Logs Insights VS AWS X-Ray
        • QuickSight
        • Amazon Managed Service for Prometheus
        • Amazon Managed Grafana
        • CloudWatch Logs Insights
          • CloudWatch Logs Insights VS Kibana VS Grafana
        • CloudWatch Logs
        • CloudTrail
        • CloudWatch
        • X-Ray
      • On-Premises
        • ECS/EKS Anyware
        • SSM Agent
      • Serverless Application Repository
      • Troubleshooting
      • Messaging, Events and Streaming
        • Kinesis (Event Stream)
        • EventBridge (Event Router)
          • EventBridge Rule Example
          • EventBridge vs Apache Kafka
          • EventBridge VS Kinesis(Event Stream)
          • Event Bridge VS SNS
        • SNS (Event broadcaster)
        • SQS (Message Queue)
        • MSK
        • Amazon MQ
        • DLQ
    • Software Design
      • CloudEvents
        • CloudEvents Kafka
      • Transaction VS Operation DBs
      • Event-based Microservices
        • Relations database to event messages
      • Hexagonal Architecture with Java Spring
      • Distributed Systems using DDD
        • Scaling a distributed system
        • Zookeeper
        • Aggregates
        • Bounded Context
      • API Gateway
      • Cloud
        • The Twelve Factors
        • Open Service Broker API
      • Microservices
    • Design technique
    • Technologies
      • Kafka
      • Docker
        • Docker Commands
        • Artifactory
        • Dockerfile
      • ReactJs
        • Progressive Web App (PWA)
        • Guide to File Extensions in React Projects
    • Guides
      • OCP
      • AWS
        • Creating and Assuming an Administrator AWS IAM Role
        • Standing Up an Amazon Aurora Database with an Automatically Rotated Password Using AWS Secrets Manag
        • Standing Up an Apache Web Server EC2 Instance and Sending Logs to Amazon CloudWatch
        • Creating a Custom AMI and Deploying an Auto Scaling Group behind an Application Load Balancer
        • Assigning Static IPs to NLBs with ALB Target Groups
        • Hosting a Wordpress Application on ECS Fargate with RDS, Parameter Store, and Secrets Manager
        • Amazon Athena, Amazon S3, and VPC Flow Logs
      • Creating a CloudTrail Trail and EventBridge Alert for Console Sign-Ins
      • Load Balancer VS Reverse Proxy
      • Health check
      • Load Balancer
      • HTTP Protocol
      • TCP/IP Network Model
      • Event-base Microservices Implementation Guideline
      • How to write a service
      • Observability
      • Kafka Stream
      • Security
        • Securing Properties
          • HashiCorp Vault
      • Kubernates
      • Unix
        • Networking
        • Firewall
        • File system
        • alternatives
      • Setup CentOS 8 and Docker
    • Dev Tools
      • Docker Commands
      • Intellij
      • CheatSheets
        • Unix Commands
        • Vim Command
      • Templates
  • Working for an enterprise
    • Next step
    • Job roles
      • SME role
    • Common issues
Powered by GitBook
On this page
  • Architecture Overview
  • Step 1: Initial Oracle to PostgreSQL Migration
  • Step 2: Set Up Cross-Database FDW Connection
  • Step 3: Migrate View Data to Target Table
  • Step 4: Set Up Ongoing Synchronization (Optional)
  • Step 5: Validation and Monitoring
  • Troubleshooting

Was this helpful?

  1. Software development
  2. DMS

Multi-Stage Migration Implementation Plan

This plan details how to implement a multi-stage migration from an on-premises Oracle database to AWS PostgreSQL, with cross-database joins and final target tables.

Architecture Overview

┌───────────────┐         ┌─────────────────────────────────────────────────────┐
│               │         │                      AWS                             │
│  On-Premises  │         │                                                      │
│     Oracle    │─────┐   │  ┌──────────────┐        ┌──────────────┐           │
│   Database    │     │   │  │  PostgreSQL  │        │  PostgreSQL  │           │
│ (Source Table)│     │   │  │  Database 1  │        │  Database 2  │           │
└───────────────┘     │   │  │              │        │              │           │
                      │   │  │ ┌──────────┐ │        │ ┌──────────┐ │           │
                      └───┼──►│  Staging  │◄├────────┼─┤ Existing │ │           │
                          │  │ │  Table   │ │        │ │  Table   │ │           │
                 DMS Task 1  │ └────┬─────┘ │        │ └──────────┘ │           │
                          │  │      │       │        │              │           │
                          │  │      │       │        └──────────────┘           │
                          │  │      │       │            ▲                      │
                          │  │      │       │            │                      │
                          │  │      ▼       │            │                      │
                          │  │ ┌──────────┐ │            │                      │
                          │  │ │  Cross-  │ │            │                      │
                          │  │ │ Database │─┼────────────┘                      │
                          │  │ │   View   │ │       FDW Connection              │
                          │  │ └────┬─────┘ │                                   │
                          │  │      │       │                                   │
                          │  │      │       │                                   │
                          │  │      ▼       │                                   │
                          │  │ ┌──────────┐ │                                   │
                          │  │ │  Target  │ │                                   │
                          │  │ │  Table   │◄┼───────────────────────────────────┘
                          │  │ └──────────┘ │        DMS Task 2
                          │  │              │
                          │  └──────────────┘
                          │
                          └────────────────────────────────────────────┘
                                           AWS DMS

Step 1: Initial Oracle to PostgreSQL Migration

1.1. Set Up Source Oracle Database for Migration

-- Connect to Oracle as a privileged user
-- Create a dedicated user for DMS
CREATE USER dms_user IDENTIFIED BY "complex_password";

-- Grant necessary privileges
GRANT CREATE SESSION TO dms_user;
GRANT SELECT ANY TABLE TO dms_user;
GRANT SELECT ANY TRANSACTION TO dms_user;
GRANT SELECT ON V_$ARCHIVED_LOG TO dms_user;
GRANT SELECT ON V_$LOG TO dms_user;
GRANT SELECT ON V_$LOGFILE TO dms_user;
GRANT SELECT ON V_$DATABASE TO dms_user;
GRANT SELECT ON V_$THREAD TO dms_user;
GRANT SELECT ON V_$PARAMETER TO dms_user;
GRANT SELECT ON V_$NLS_PARAMETERS TO dms_user;
GRANT SELECT ON V_$TIMEZONE_NAMES TO dms_user;
GRANT SELECT ON V_$TRANSACTION TO dms_user;
GRANT SELECT ON ALL_INDEXES TO dms_user;
GRANT SELECT ON ALL_OBJECTS TO dms_user;
GRANT SELECT ON ALL_TABLES TO dms_user;
GRANT SELECT ON ALL_USERS TO dms_user;
GRANT SELECT ON ALL_CATALOG TO dms_user;
GRANT SELECT ON ALL_CONSTRAINTS TO dms_user;
GRANT SELECT ON ALL_CONS_COLUMNS TO dms_user;
GRANT SELECT ON ALL_TAB_COLS TO dms_user;
GRANT SELECT ON ALL_IND_COLUMNS TO dms_user;
GRANT SELECT ON ALL_ENCRYPTED_COLUMNS TO dms_user;
GRANT SELECT ON ALL_LOG_GROUPS TO dms_user;
GRANT SELECT ON ALL_TAB_PARTITIONS TO dms_user;
GRANT SELECT ON SYS.DBA_REGISTRY TO dms_user;
GRANT SELECT ON SYS.OBJ$ TO dms_user;
GRANT SELECT ON DBA_TABLESPACES TO dms_user;
GRANT SELECT ON DBA_OBJECTS TO dms_user;
GRANT SELECT ON SYS.ENC$ TO dms_user;
GRANT SELECT ON SOURCE_TABLE TO dms_user; -- Replace SOURCE_TABLE with your actual table name

-- Enable supplemental logging if you plan to use CDC
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;
ALTER TABLE SOURCE_TABLE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;

1.2. Set Up Target PostgreSQL Database on AWS

-- Connect to PostgreSQL Database 1 as admin user
-- Create a staging schema to hold the migrated data
CREATE SCHEMA staging;

-- Create a schema for the final target table
CREATE SCHEMA target;

-- Create a user for DMS to connect with
CREATE USER dms_user WITH PASSWORD 'complex_password';

-- Grant necessary permissions
GRANT USAGE ON SCHEMA staging TO dms_user;
GRANT USAGE ON SCHEMA target TO dms_user;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA staging TO dms_user;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA target TO dms_user;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA staging TO dms_user;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA target TO dms_user;

-- Create extension for Foreign Data Wrapper
CREATE EXTENSION postgres_fdw;

1.3. Set Up AWS DMS for Initial Migration

  1. Create Oracle Source Endpoint:

aws dms create-endpoint \
  --endpoint-identifier oracle-source-endpoint \
  --endpoint-type source \
  --engine-name oracle \
  --username dms_user \
  --password complex_password \
  --server-name oracle-server.your-domain.com \
  --port 1521 \
  --database-name YOUR_SID \
  --extra-connection-attributes "useLogminerReader=N;useBfile=Y" \
  --region your-aws-region
  1. Create PostgreSQL Target Endpoint:

aws dms create-endpoint \
  --endpoint-identifier postgresql-target-endpoint \
  --endpoint-type target \
  --engine-name postgres \
  --username dms_user \
  --password complex_password \
  --server-name postgres-db1.abcdef123456.region.rds.amazonaws.com \
  --port 5432 \
  --database-name postgres_db1 \
  --region your-aws-region
  1. Create a Replication Instance:

aws dms create-replication-instance \
  --replication-instance-identifier dms-replication-instance \
  --replication-instance-class dms.c5.large \
  --allocated-storage 50 \
  --vpc-security-group-ids sg-abcdef123456 \
  --replication-subnet-group-id default-vpc-subnet-group \
  --region your-aws-region
  1. Create Task Settings JSON File (task-settings.json):

{
  "TargetMetadata": {
    "TargetSchema": "staging",
    "SupportLobs": true,
    "FullLobMode": false,
    "LobChunkSize": 64,
    "LimitedSizeLobMode": true,
    "LobMaxSize": 32
  },
  "FullLoadSettings": {
    "TargetTablePrepMode": "DROP_AND_CREATE",
    "CreatePkAfterFullLoad": true,
    "StopTaskCachedChangesApplied": false,
    "StopTaskCachedChangesNotApplied": false,
    "MaxFullLoadSubTasks": 8,
    "TransactionConsistencyTimeout": 600,
    "CommitRate": 10000
  },
  "Logging": {
    "EnableLogging": true,
    "LogComponents": [
      {
        "Id": "SOURCE_UNLOAD",
        "Severity": "LOGGER_SEVERITY_DEFAULT"
      },
      {
        "Id": "TARGET_LOAD",
        "Severity": "LOGGER_SEVERITY_DEFAULT"
      },
      {
        "Id": "TASK_MANAGER",
        "Severity": "LOGGER_SEVERITY_DEFAULT"
      }
    ]
  },
  "OracleSettings": {
    "ReadTableSpaceName": false,
    "EnableHomogenousTablespace": false,
    "StandbyDelayTime": 0,
    "ArchivedLogsOnly": false,
    "ArchivedLogDestId": 0,
    "UseDirectPathFullLoad": true,
    "UseParallelReadThreads": true,
    "NumberOfThreads": 4,
    "ParallelASMReadThreads": 2,
    "ReadAheadBlocks": 10000,
    "AccessAlternateDirectly": false,
    "UseAlternateFolderForOnline": false,
    "OraclePathPrefix": "",
    "UsePathPrefix": false,
    "ReplacePathPrefix": false,
    "EnableHomogenousPartitionOps": false
  }
}
  1. Create Table Mappings JSON File (table-mappings.json):

{
  "rules": [
    {
      "rule-type": "selection",
      "rule-id": "1",
      "rule-name": "1",
      "object-locator": {
        "schema-name": "SCHEMA_NAME",
        "table-name": "SOURCE_TABLE"
      },
      "rule-action": "include"
    },
    {
      "rule-type": "transformation",
      "rule-id": "2",
      "rule-name": "2",
      "rule-action": "rename",
      "rule-target": "schema",
      "object-locator": {
        "schema-name": "SCHEMA_NAME"
      },
      "value": "staging"
    },
    {
      "rule-type": "transformation",
      "rule-id": "3",
      "rule-name": "3",
      "rule-action": "rename",
      "rule-target": "table",
      "object-locator": {
        "schema-name": "SCHEMA_NAME",
        "table-name": "SOURCE_TABLE"
      },
      "value": "staging_table"
    }
  ]
}
  1. Create the DMS Task:

aws dms create-replication-task \
  --replication-task-identifier oracle-to-postgres-task \
  --source-endpoint-arn arn:aws:dms:region:account:endpoint:oracle-source-endpoint \
  --target-endpoint-arn arn:aws:dms:region:account:endpoint:postgresql-target-endpoint \
  --replication-instance-arn arn:aws:dms:region:account:rep:dms-replication-instance \
  --migration-type full-load-and-cdc \
  --table-mappings file://table-mappings.json \
  --replication-task-settings file://task-settings.json \
  --region your-aws-region
  1. Start the DMS Task:

aws dms start-replication-task \
  --replication-task-arn arn:aws:dms:region:account:task:oracle-to-postgres-task \
  --start-replication-task-type start-replication \
  --region your-aws-region

Step 2: Set Up Cross-Database FDW Connection

2.1. Set Up Foreign Data Wrapper in PostgreSQL Database 1

-- Connect to PostgreSQL Database 1
-- Create server connection to PostgreSQL Database 2
CREATE SERVER postgres_db2_server
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'postgres-db2.abcdef123456.region.rds.amazonaws.com', port '5432', dbname 'postgres_db2');

-- Create user mapping
CREATE USER MAPPING FOR dms_user
SERVER postgres_db2_server
OPTIONS (user 'fdw_user', password 'complex_password');

-- Create foreign table referring to the table in PostgreSQL Database 2
CREATE FOREIGN TABLE staging.foreign_table (
    id integer,
    name varchar(255),
    value numeric,
    created_at timestamp,
    -- Add all columns from the remote table
    -- Make sure data types match exactly
    PRIMARY KEY (id)
)
SERVER postgres_db2_server
OPTIONS (schema_name 'public', table_name 'existing_table');

-- Grant permissions
GRANT SELECT ON staging.foreign_table TO dms_user;

2.2. Create the Cross-Database View

-- Connect to PostgreSQL Database 1
-- Create a view that joins the staging table with the foreign table
CREATE OR REPLACE VIEW staging.combined_view AS
SELECT 
    s.id,
    s.column1,
    s.column2,
    f.name,
    f.value,
    -- Add all columns needed from both tables
    s.created_at AS source_created_at,
    f.created_at AS related_created_at
FROM 
    staging.staging_table s
JOIN 
    staging.foreign_table f ON s.id = f.id;  -- Adjust join condition

-- Grant permissions
GRANT SELECT ON staging.combined_view TO dms_user;

Step 3: Migrate View Data to Target Table

3.1. Create the Target Table

-- Connect to PostgreSQL Database 1
-- Create the target table with the desired schema
CREATE TABLE target.final_table (
    id integer PRIMARY KEY,
    column1 varchar(255),
    column2 varchar(255),
    name varchar(255),
    value numeric,
    source_created_at timestamp,
    related_created_at timestamp,
    -- Add any additional columns
    migration_timestamp timestamp DEFAULT CURRENT_TIMESTAMP
);

-- Grant permissions
GRANT ALL PRIVILEGES ON target.final_table TO dms_user;

3.2. Set Up Second DMS Task for View Migration

  1. Create Table Mappings for View Migration (view-mappings.json):

{
  "rules": [
    {
      "rule-type": "selection",
      "rule-id": "1",
      "rule-name": "1",
      "object-locator": {
        "schema-name": "staging",
        "table-name": "combined_view"
      },
      "rule-action": "include"
    },
    {
      "rule-type": "transformation",
      "rule-id": "2",
      "rule-name": "2",
      "rule-action": "rename",
      "rule-target": "schema",
      "object-locator": {
        "schema-name": "staging"
      },
      "value": "target"
    },
    {
      "rule-type": "transformation",
      "rule-id": "3",
      "rule-name": "3",
      "rule-action": "rename",
      "rule-target": "table",
      "object-locator": {
        "schema-name": "staging",
        "table-name": "combined_view"
      },
      "value": "final_table"
    }
  ]
}
  1. Create DMS Task Settings for View Migration (view-task-settings.json):

{
  "TargetMetadata": {
    "TargetSchema": "target",
    "SupportLobs": true,
    "FullLobMode": false,
    "LobChunkSize": 64,
    "LimitedSizeLobMode": true,
    "LobMaxSize": 32
  },
  "FullLoadSettings": {
    "TargetTablePrepMode": "DO_NOTHING",
    "CreatePkAfterFullLoad": false,
    "StopTaskCachedChangesApplied": false,
    "StopTaskCachedChangesNotApplied": false,
    "MaxFullLoadSubTasks": 8,
    "TransactionConsistencyTimeout": 600,
    "CommitRate": 10000
  },
  "Logging": {
    "EnableLogging": true
  }
}
  1. Create a New DMS Task for View Migration:

aws dms create-replication-task \
  --replication-task-identifier view-to-target-task \
  --source-endpoint-arn arn:aws:dms:region:account:endpoint:postgresql-target-endpoint \
  --target-endpoint-arn arn:aws:dms:region:account:endpoint:postgresql-target-endpoint \
  --replication-instance-arn arn:aws:dms:region:account:rep:dms-replication-instance \
  --migration-type full-load \
  --table-mappings file://view-mappings.json \
  --replication-task-settings file://view-task-settings.json \
  --region your-aws-region
  1. Start the View Migration Task:

aws dms start-replication-task \
  --replication-task-arn arn:aws:dms:region:account:task:view-to-target-task \
  --start-replication-task-type start-replication \
  --region your-aws-region

3.3. Alternative: Direct SQL-based Migration

If DMS has trouble with the view, you can use SQL for the final step:

-- Connect to PostgreSQL Database 1
-- Migrate data from view to target table
INSERT INTO target.final_table (
    id, column1, column2, name, value, source_created_at, related_created_at
)
SELECT 
    id, column1, column2, name, value, source_created_at, related_created_at
FROM 
    staging.combined_view;

Step 4: Set Up Ongoing Synchronization (Optional)

If you need ongoing data synchronization from Oracle to the final target table:

4.1. Create a Trigger-Based Approach

-- Connect to PostgreSQL Database 1
-- Create a function to handle updates
CREATE OR REPLACE FUNCTION staging.update_final_table()
RETURNS TRIGGER AS $$
BEGIN
    -- For inserts/updates to the staging table
    UPSERT INTO target.final_table (
        id, column1, column2, name, value, source_created_at, related_created_at
    )
    SELECT 
        s.id, s.column1, s.column2, f.name, f.value, s.created_at, f.created_at
    FROM 
        staging.staging_table s
    JOIN 
        staging.foreign_table f ON s.id = f.id
    WHERE 
        s.id = NEW.id;
        
    RETURN NEW;
END;
$$ LANGUAGE plpgsql;

-- Create trigger on staging table
CREATE TRIGGER sync_to_final_table
AFTER INSERT OR UPDATE ON staging.staging_table
FOR EACH ROW
EXECUTE FUNCTION staging.update_final_table();

Step 5: Validation and Monitoring

5.1. Validate Data Migration

-- Check row counts
SELECT COUNT(*) FROM staging.staging_table;
SELECT COUNT(*) FROM staging.foreign_table;
SELECT COUNT(*) FROM staging.combined_view;
SELECT COUNT(*) FROM target.final_table;

-- Validate data integrity
SELECT 
    (SELECT COUNT(*) FROM staging.combined_view) AS view_count,
    (SELECT COUNT(*) FROM target.final_table) AS target_count,
    CASE 
        WHEN (SELECT COUNT(*) FROM staging.combined_view) = (SELECT COUNT(*) FROM target.final_table)
        THEN 'MATCH'
        ELSE 'MISMATCH'
    END AS status;

-- Check for missing records
SELECT v.id
FROM staging.combined_view v
LEFT JOIN target.final_table t ON v.id = t.id
WHERE t.id IS NULL;

5.2. Monitor DMS Tasks

# Check task status
aws dms describe-replication-tasks \
  --filters Name=replication-task-arn,Values=arn:aws:dms:region:account:task:oracle-to-postgres-task \
  --region your-aws-region

aws dms describe-replication-tasks \
  --filters Name=replication-task-arn,Values=arn:aws:dms:region:account:task:view-to-target-task \
  --region your-aws-region

# Monitor CloudWatch logs
aws logs get-log-events \
  --log-group-name /aws/dms/replication-task/oracle-to-postgres-task \
  --log-stream-name dms-task-oracle-to-postgres-task \
  --limit 10

Troubleshooting

Foreign Data Wrapper Issues

-- Test FDW connection
SELECT * FROM staging.foreign_table LIMIT 10;

-- Check PostgreSQL logs for FDW errors
-- In AWS RDS, check the PostgreSQL error logs in CloudWatch

DMS Task Failures

# Get detailed task status
aws dms describe-replication-task-assessment-results \
  --replication-task-arn arn:aws:dms:region:account:task:oracle-to-postgres-task

# Check table statistics
aws dms describe-table-statistics \
  --replication-task-arn arn:aws:dms:region:account:task:oracle-to-postgres-task

View Migration Issues

-- Verify view access
SELECT * FROM staging.combined_view LIMIT 10;

-- Check for any errors in target table constraints
SELECT * FROM information_schema.constraint_column_usage
WHERE table_schema = 'target' AND table_name = 'final_table';

This implementation plan provides all the necessary steps to migrate data from an on-premises Oracle database to AWS PostgreSQL, create a cross-database view, and load the final data into a target table within the same PostgreSQL database.

PreviousJoin tables separate PostgreSQL databasesNextNotes

Last updated 3 months ago

Was this helpful?