resources

Oracle Data Pump: Export and Import a Schema in 19c

To move a schema between Oracle Database 19c pluggable databases (PDBs), export it with Data Pump Export (expdp), copy the dump file to a directory accessible to the target database server, and load it with Data Pump Import (impdp). Run both clients against PDB services, not the CDB root. An import is not synchronization: plan how to handle writes that occur after the export.

Untested: The examples are for Oracle Database 19c on Linux. Use a disposable target first; do not run this on an existing production schema.

Before you start

  • Confirm that the placeholders sourcepdb and targetpdb resolve to the intended PDB services. See connecting with SQL*Plus for a client setup reference. If using Instant Client, install the matching Tools package for expdp and impdp.
  • Have a DBA precreate the empty target account with the same schema name. On both PDBs, the account needs CREATE SESSION to connect and CREATE TABLE plus sufficient quota for the Data Pump job table. On the target, also check the privileges needed to recreate the source object types and ensure the referenced tablespaces exist with sufficient quota. The example uses the schema owner on both sides, without the full-database Data Pump roles.
  • In each PDB, have a DBA with CREATE ANY DIRECTORY provision DP_STAGE on the database server. For these commands, the source writes the dump and export log; the target reads the dump and writes the import log. Grant the corresponding directory object permissions to app_user and check the separate OS permissions of the database processes.
  • Check free space, external dependencies, and the source backup before migration. Keep the source intact until the target has been accepted. Use non-sensitive rehearsal data and an access-restricted staging location.

1. Confirm the connection context

Run this from a SQL session on each service before starting either job. Confirm the user and PDB name against your migration plan.

SELECT SYS_CONTEXT('USERENV', 'CON_NAME') AS container_name,
       SYS_CONTEXT('USERENV', 'SESSION_USER') AS session_user
FROM dual;

2. Export the source schema

For a rehearsal, pause application writes while taking the export and collecting the reference counts. Run the client from a shell; enter the password at the prompt. Choose fresh dump and log names for each run: Data Pump can overwrite a log with the same name.

expdp app_user@sourcepdb SCHEMAS=app_user DIRECTORY=DP_STAGE DUMPFILE=app_user_run01.dmp LOGFILE=app_user_export_run01.log

Review the export log before proceeding. Use your approved file-transfer process to copy the dump into the OS path mapped by DP_STAGE on the target. Verify its checksum before and after transfer and confirm the target database can read it. Do not copy the dump into a public share.

3. Import into the empty target schema

impdp app_user@targetpdb SCHEMAS=app_user DIRECTORY=DP_STAGE DUMPFILE=app_user_run01.dmp LOGFILE=app_user_import_run01.log

Expect the supported objects owned by the source schema and their data to be loaded into the target schema. This import does not recreate the user definition. Review dependencies in other schemas separately; for example, a trigger owned by a different schema is not imported by this workflow. Do not treat a retry over a partially loaded schema as a clean import.

4. Verify before switching the application

Read the import log and account for each warning or error. Compare row counts on selected business-critical tables against the recorded source counts; matching counts do not prove that the contents match. As the target schema owner, check invalid objects and run representative application reads against the target.

SELECT object_type, object_name
FROM user_objects
WHERE status = 'INVALID'
ORDER BY object_type, object_name;

If an import fails, leave the application on the source. Inspect quotas, directory and operating-system permissions, missing tablespaces, and cross-schema grants. Rehearse again against a fresh target after addressing the cause. Do not switch writes until you have a rollback plan that accounts for any writes accepted on the target after cutover.

For ongoing replication rather than a file-based move, see the GoldenGate overview. For pre-migration backup checks, see RMAN backup validation.

Oracle Database 19c references

For an approved offline transfer between lab systems, a portable SSD can carry a copy of the dump. Keep sensitive dumps encrypted, verify the copy, and place it in the target server directory that Data Pump can access before importing.

Photo of Kingston XS1000 Portable SSD, 1 TB

Kingston XS1000 Portable SSD, 1 TB
SXS1000/1000G · USB 3.2 Gen 2
View on Amazon (paid link)