如何将EC2实例上的Oracle .dmp文件导入AWS RDS实例的DATA_DUMP_DIR?
Absolutely, you don't have to circle back to the original source database to generate a new export. There are practical, workable ways to get your existing .dmp file into the RDS Oracle instance's DATA_DUMP_DIR. Here are the two most reliable approaches I’ve used in similar scenarios:
Method 1: Use S3 as a Middleman (AWS-Native & Recommended)
This is the most stable method since it leverages AWS’s native integration between S3 and RDS Oracle, avoiding complex network hoops:
Upload your .dmp file from EC2 to an S3 Bucket
On your EC2 instance, run this AWS CLI command to transfer the file to your target S3 bucket:aws s3 cp /path/to/your/local/file.dmp s3://your-target-bucket/desired/path/Make sure your EC2 instance has IAM permissions to write to this S3 bucket (attach a policy with
s3:PutObjectaccess if needed).Configure RDS IAM Permissions for S3 Access
- Create an IAM role with a policy that allows
s3:GetObjectaccess to your target bucket. - Attach this IAM role to your RDS Oracle instance via the RDS Console (navigate to Configuration > IAM roles to link it).
- Create an IAM role with a policy that allows
Pull the File from S3 to RDS's DATA_DUMP_DIR
First, create a credential in your RDS Oracle instance to link the IAM role:CREATE CREDENTIAL S3_ACCESS_CRED TYPE 'AWS_IAM' ROLE 'your-rds-iam-role-name';Then use
DBMS_CLOUD.GET_OBJECTto transfer the file directly intoDATA_DUMP_DIR:BEGIN DBMS_CLOUD.GET_OBJECT( credential_name => 'S3_ACCESS_CRED', object_uri => 'https://your-target-bucket.s3.your-region.amazonaws.com/desired/path/file.dmp', directory_name => 'DATA_DUMP_DIR', file_name => 'file.dmp' ); END; /Verify the File is Present
Confirm the file exists in the directory with this query:SELECT UTL_FILE.FGETATTR('DATA_DUMP_DIR', 'file.dmp', 0, 0, 0) FROM DUAL;A return value of
0means the file was successfully transferred.
Method 2: Use a Temporary Oracle Instance on EC2 (Alternative for Non-S3 Scenarios)
If S3 isn’t an option, you can set up a temporary Oracle database on your EC2 instance to act as a bridge:
Import the .dmp file into the EC2 Oracle instance
UseIMPDPto load your existing .dmp file into the temporary EC2 database:impdp your-ec2-db-user/password@ec2-db-service schemas=your-target-schemas dumpfile=file.dmp logfile=import.logCreate a Database Link from RDS to the EC2 Oracle Instance
In your RDS Oracle instance, create a DB link pointing to the EC2 database (ensure both are in the same VPC or have proper network connectivity):CREATE DATABASE LINK ec2_db_link CONNECT TO your-ec2-db-user IDENTIFIED BY your-password USING '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ec2-private-ip)(PORT=1521))(CONNECT_DATA=(SID=ec2-db-sid)))';Export/Transfer to RDS
You can either useIMPDPon the RDS side with theNETWORK_LINKparameter to pull data directly from the EC2 database, or if you specifically need the .dmp file inDATA_DUMP_DIR, runEXPDPon the EC2 instance and push the file to RDS usingUTL_FILE(this requires additional network setup for direct file transfer between EC2 and RDS).
Key Notes
- Ensure your RDS user has the necessary permissions to write to the directory:
GRANT WRITE ON DIRECTORY DATA_DUMP_DIR TO your-rds-user; - For Oracle 11g on RDS, confirm that
DBMS_CLOUDis available (it’s supported for most patched RDS Oracle 11g instances, but check your patch level if you hit errors).
内容的提问来源于stack exchange,提问作者Ajinkya Bapat

