F Copying Bulk Data from Oracle Database to RDS

Overview

Use Oracle Data Pump to move bulk data and a limited set of custom-schema objects from a source Oracle database into an RDS custom schema. This pattern is intended for initial data seeding and repeatable refreshes during a customer-managed porting effort. It is not a full lift-and-shift migration of source customizations.

The workflow exports the source schema with expdp, places the dump files in a dedicated Object Storage bucket, and starts the RDS import using the Data Pump import procedure available in the target environment. The procedure reads the dump through an Object Storage pre-authenticated request (PAR) URL, remaps the source schema to the RDS target schema, and writes an import log to DATA_PUMP_DIR.

WARNING:

The import uses TABLE_EXISTS_ACTION=REPLACE. It drops and recreates target objects that have the same name as imported objects. Run it only against the intended target custom schema, and obtain any required change approval before starting.

Why export to a file system first? Exporting with Data Pump to a source file system and then uploading the completed dump files and export log to Object Storage is the reliable transfer pattern. There are cases where a Data Pump export directly to Object Storage does not work. Staging the files first also makes it possible to retain every dump piece and to review the export log before starting a potentially destructive import.

Why run the import as a scheduler job? A bulk import can take longer than the 300-second limit for an interactive request. The scheduler job starts Data Pump asynchronously, allowing the import to continue after the request that submitted it has ended. Monitor the Data Pump job and import log rather than relying only on the scheduler launch result.

Scope and Behavior

The RDS import utility imports only these object types:

  • TABLE
  • VIEW
  • MATERIALIZED_VIEW
  • TRIGGER

It does not import grants, privileges, sequences, or other schema object types. Apply any required privileges separately after import.

For objects in scope:

  • A target object with the same name is replaced by the imported definition and data.
  • A target object that is not present in the dump is left in place; this is not a schema-cleanup operation.
  • Data that relies on sequence-generated values, identity behavior, or sequence defaults needs special preparation because sequences are not included. Materialize the required values in an exportable staging or duplicate table before export when necessary.

Valid Destination Schemas

Import data only into an approved, writable RDS custom schema. The valid primary custom-schema destinations are:

  • MFCS_RDS_CUSTOM
  • CE_RDS_CUSTOM
  • SIOCS_RDS_CUSTOM
  • OB_RDS_CUSTOM
  • XO_RDS_CUSTOM
  • SE_RDS_CUSTOM
  • BC_RDS_CUSTOM
  • RICS_RDS_CUSTOM
  • RSCH_RDS_CUSTOM
  • OM_RDS_CUSTOM
  • RDS_CUSTOM_1 - RDS_CUSTOM_10

The RDS_CUSTOM_1 through RDS_CUSTOM_10 schemas begin with a more restrictive privilege model, so any required cross-schema access must be granted separately.

Do not import into an RDS replicat schema, including schemas with names such as MFCS_RDS, BC_RDS, or XO_RDS. Replicat schemas are read-only copies of source cloud-service data and are not valid destinations for this procedure.

Prerequisites

Before beginning, confirm all of the following:

  1. You have the source database access and permissions required to run a Data Pump schema export.
  2. The target RDS schema exists and is the schema approved for the refresh.
  3. The RDS Data Pump import procedures submit_import_job and copy_import_log_to_par are available in the target environment and you have permission to execute them.
  4. You have a dedicated Object Storage bucket for this schema’s import artifacts. Use one bucket per schema and keep only the relevant dump files and logs in it.
  5. You have a read PAR URL for the dump file or dump-file set and a write PAR URL for the import log. Ensure the PARs remain valid for the full export, import, and log-retrieval window.
  6. You have an approved maintenance window for the expected data volume and have notified affected application users, as appropriate.

Install the Import Procedures

Run the following scripts once in the approved RDS target schema before the first import. They create the procedures used in the later steps.

The import procedure expects a PAR URL for the dump file. It creates a placeholder database credential named DUMMY_CRED only because the Data Pump URI file interface requires a credential name even when the PAR URL contains the authorization information. Do not use this placeholder-credential pattern for an Object Storage URL that does not use a PAR.

The procedure sets Data Pump parallelism to 24. Validate that setting against the capacity available in the target RDS environment before using this appendix for large imports.

submit_import_job

CREATE OR REPLACE PROCEDURE submit_import_job(
	p_par_url IN VARCHAR2,
	p_source_schema IN VARCHAR2,
	p_target_schema IN VARCHAR2,
	p_log_filename IN VARCHAR2,
	p_job_name OUT VARCHAR2
) AUTHID CURRENT_USER
AS
	l_job_action CLOB;
BEGIN
	p_job_name := 'IMP_DP_' || TO_CHAR(SYSTIMESTAMP, 'YYYYMMDDHH24MISSFF3');
	l_job_action :=
		q'[
DECLARE
	l_dump_filename VARCHAR2(32767) := ]' || DBMS_ASSERT.ENQUOTE_LITERAL(p_par_url) || q'[;
	l_log_filename VARCHAR2(4000) := ]' || DBMS_ASSERT.ENQUOTE_LITERAL(p_log_filename) || q'[;
	l_source_schema VARCHAR2(128) := ]' || DBMS_ASSERT.ENQUOTE_LITERAL(UPPER(p_source_schema)) || q'[;
	l_target_schema VARCHAR2(128) := ]' || DBMS_ASSERT.ENQUOTE_LITERAL(UPPER(p_target_schema)) || q'[;
	l_credential VARCHAR2(128) := 'DUMMY_CRED';
	l_datapump_dir VARCHAR2(30) := 'DATA_PUMP_DIR';
	l_parallel PLS_INTEGER := 24;
	l_datapump_handle NUMBER;
	l_count PLS_INTEGER;
BEGIN
	SELECT COUNT(*)
		INTO l_count
		FROM USER_CREDENTIALS
	WHERE UPPER(credential_name) = UPPER(l_credential);
	IF l_count = 0 THEN
		DBMS_CLOUD.CREATE_CREDENTIAL(
			credential_name => l_credential,
			username => 'dummy_user',
			password => 'dummy_password'
		);
	END IF;
	DBMS_OUTPUT.PUT_LINE('p_par_url=' || l_dump_filename);
	DBMS_OUTPUT.PUT_LINE('p_source_schema=' || l_source_schema);
	DBMS_OUTPUT.PUT_LINE('p_target_schema=' || l_target_schema);
	DBMS_OUTPUT.PUT_LINE('p_log_filename=' || l_log_filename);
	l_datapump_handle := DBMS_DATAPUMP.OPEN(
		operation => 'IMPORT',
		job_mode => 'TABLE'
	);
	DBMS_DATAPUMP.ADD_FILE(
		handle => l_datapump_handle,
		filename => l_dump_filename,
		directory => l_credential,
		filetype => DBMS_DATAPUMP.KU$_FILE_TYPE_URIDUMP_FILE
	);
	DBMS_DATAPUMP.ADD_FILE(
		handle => l_datapump_handle,
		filename => l_log_filename,
		directory => l_datapump_dir,
		filetype => DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE
	);
	DBMS_DATAPUMP.METADATA_FILTER(
		handle => l_datapump_handle,
		name => 'INCLUDE_PATH_EXPR',
		value => q'| IN (
			'TABLE',
			'VIEW',
			'MATERIALIZED_VIEW',
			'TRIGGER'
		) |'
	);
	DBMS_DATAPUMP.METADATA_FILTER(
		handle => l_datapump_handle,
		name => 'SCHEMA_LIST',
		value => '''' || l_source_schema || ''''
	);
	DBMS_DATAPUMP.METADATA_REMAP(
		handle => l_datapump_handle,
		name => 'REMAP_SCHEMA',
		old_value => l_source_schema,
		value => l_target_schema
	);
	DBMS_DATAPUMP.SET_PARAMETER(
		handle => l_datapump_handle,
		name => 'METRICS',
		value => 1
	);
		DBMS_DATAPUMP.SET_PARAMETER(
		handle => l_datapump_handle,
		name => 'LOGTIME',
		value => 'ALL'
	);
	DBMS_DATAPUMP.SET_PARAMETER(
		handle => l_datapump_handle,
		name => 'TABLE_EXISTS_ACTION',
		value => 'REPLACE'
	);
	DBMS_DATAPUMP.SET_PARALLEL(
		handle => l_datapump_handle,
		degree => l_parallel
	);
	DBMS_DATAPUMP.START_JOB(l_datapump_handle);DBMS_DATAPUMP.DETACH(l_datapump_handle);
EXCEPTION
	WHEN OTHERS THEN
		BEGIN
			IF l_datapump_handle IS NOT NULL THEN
				DBMS_DATAPUMP.DETACH(l_datapump_handle);
			END IF;
		EXCEPTION
			WHEN OTHERS THEN NULL;
		END;
		RAISE;
END;
]';
	DBMS_SCHEDULER.CREATE_JOB(
		job_name => p_job_name,
		job_type => 'PLSQL_BLOCK',
		job_action => l_job_action,
		start_date => SYSTIMESTAMP,
		enabled => TRUE,
		auto_drop => FALSE,
		comments => 'Launch Data Pump import from PAR URL'
);
END;
/
SHOW ERRORS

copy_import_log_to_par

CREATE OR REPLACE PROCEDURE copy_import_log_to_par(
	p_log_filename IN VARCHAR2,
	p_target_par_url IN VARCHAR2,
	p_directory_name IN VARCHAR2 DEFAULT 'DATA_PUMP_DIR'
	) AUTHID CURRENT_USER
AS
BEGIN
	DBMS_CLOUD.PUT_OBJECT(
		credential_name => NULL,
		object_uri => p_target_par_url,
		directory_name => p_directory_name,
		file_name => p_log_filename
	);
END;
/
SHOW ERRORS

1. Prepare the Source Export

Avoid DDL changes to in-scope objects while the export is running. In particular, do not issue CREATE, ALTER, DROP, TRUNCATE, or RENAME statements for those objects during the export. If DDL occurs or the export log reports errors, correct the issue and create a new export.

Run an export for the source schema. The following is an example; replace the directory, credentials, schema, and filenames with values for the source database.

expdp <source_user>/<password>@<source_service> \
DIRECTORY=<source_data_pump_directory> \
DUMPFILE=<source_schema>_export_%U.dmp \
LOGFILE=<source_schema>_export.log \
SCHEMAS=<source_schema>

If the export produces multiple dump pieces (for example, because DUMPFILE uses %U), retain every piece. Do not select only the first dump file.

Review the export log before you upload or import anything. Resolve any errors and re-export if the dump is incomplete or inconsistent.

2. Upload Artifacts and Create PARs

Upload every dump file and the export log to the dedicated Object Storage bucket. Keep the export log with the dump files so that it is available during validation.

Create:

  • a read PAR URL that gives RDS access to the dump file or validated dump-file set; and
  • a write PAR URL for the eventual RDS import log.

Do not alter the PAR URL manually. When the export has several dump pieces, use the dump-file naming pattern and PAR format documented for your RDS environment. Do not start the import until you have confirmed that every dump piece is accessible.

3. Submit the RDS Import

Connect to RDS as the approved target-schema user and submit the scheduler job. Substitute the actual PAR URL, source schema, target schema, and unique import-log name.

DECLARE
l_job_name VARCHAR2(128);
BEGIN
submit_import_job(
p_par_url => '<dump_par_url>',
p_source_schema => '<SOURCE_SCHEMA>',
p_target_schema => '<TARGET_RDS_SCHEMA>',
p_log_filename => '<source_schema>_to_<target_schema>_import.log',
p_job_name => l_job_name
);
DBMS_OUTPUT.PUT_LINE('Submitted scheduler job: ' || l_job_name);
END;
/

Record the scheduler job name returned by the block. It is required for monitoring and cleanup.

The submitted scheduler job starts the import asynchronously. The scheduler launch can therefore finish before the Data Pump import has completed; monitor the Data Pump job and review the import log before considering the refresh complete.

4. Monitor the Import

First, verify that the scheduler launch block succeeded. A successful scheduler entry confirms only that it started the Data Pump job; it does not prove that the entire import has finished successfully.

SELECT log_id,
job_name,
status,
error#,
log_date,
req_start_date,
actual_start_date,
run_duration,
additional_info
FROM user_scheduler_job_run_details
WHERE job_name = :job_name
ORDER BY log_id DESC;

Use the Data Pump job view to monitor the actual import:

SELECT owner_name,
job_name,
operation,
job_mode,
state,
degree,
attached_sessions
FROM user_datapump_jobs
ORDER BY job_name;

Typical states are interpreted as follows:

  • RUNNING or EXECUTING: the import is active.
  • NOT RUNNING: the job exists but is not currently executing.
  • No row: the job may have completed and removed its Data Pump job record; validate through the import log.

For additional scheduler event detail, use:

SELECT log_id,
job_name,
operation,
status,
log_date,
additional_info
FROM user_scheduler_job_log
WHERE job_name = :job_name
ORDER BY log_id DESC;

5. Upload and Review the Import Log

After the import finishes, upload the log from DATA_PUMP_DIR to its write PAR URL:

BEGIN
copy_import_log_to_par(
p_log_filename => '<source_schema>_to_<target_schema>_import.log',
p_target_par_url => '<import_log_par_url>'
);
END;
/

Retrieve and review the uploaded import log with the source export log. The logs together are the evidence for import validation. Confirm that expected tables and row counts were processed, all required in-scope objects were created, and any warnings have an understood disposition.

Perform application-level validation appropriate to the data being refreshed before allowing dependent processes to use the target schema.

Optional Scheduler Cleanup

The utility retains the scheduler job so it can be inspected after execution. When the job and its history are no longer needed, remove it using the recorded job name:

BEGIN
DBMS_SCHEDULER.DROP_JOB(job_name => :job_name, force => TRUE);
END;
/

Troubleshooting

Symptom Checks and response
Scheduler job failed Query USER_SCHEDULER_JOB_RUN_DETAILS; review STATUS, ERROR#, and ADDITIONAL_INFO.
Scheduler job succeeded but import is incomplete Check USER_DATAPUMP_JOBS; then review the import log. Scheduler success only confirms the launch block completed.
Dump file cannot be opened Verify that the PAR URL is complete, unexpired, points to the intended object, and supports the required read operation. For multi-piece exports, confirm the expected naming and URL pattern.
Imported objects or data are missing Review both the source export and target import logs. Confirm that the object type is in scope and that the source export contained the object.
Schema remap is incorrect Confirm the exact source schema name stored in the dump and the intended RDS target schema name before retrying.
Import log cannot be uploaded Confirm the log filename, DATA_PUMP_DIR access, and that the destination PAR allows writing to the specified object path.

Related Information

For more information, see the Oracle Database Utilities documentation for Data Pump Export and Import; the Oracle Database PL/SQL Packages and Types Reference for DBMS_DATAPUMP and DBMS_SCHEDULER; and the Oracle Cloud Infrastructure documentation for Object Storage pre-authenticated requests.