Last week I got a fairly common DBA request: copy a set of application schemas, with all their data, from an old Oracle server to a new one. It was Oracle to Oracle, with two databases (a DEV and a QA) and between 8 and 10 schemas in each. In this post I walk through exactly how I did it with Oracle Data Pump (expdp / impdp), from the first pre-checks to the post-import validation, with the commands and the output at every step.
Note: I have changed the server names, database names, schema names and tablespace names from the real environment. The outputs are trimmed so they are easier to read.
The setup
| Source (copy from) | Target (copy to) | |
|---|---|---|
| Server | srcdbhost01 | tgtdbhost01 |
| Databases | FINDEV, FINQA | FINDEV, FINQA |
| Oracle version | 19c | 19c |
| Method | Data Pump schema-mode export, then scp, then import | |
FINDEV schemas (8): AP_APP, AP_AUTO, INVENTORY, DW_USER, HRAPP, SUPPORT_APP, SCM_APP_DEV, SCM_ARCH
FINQA schemas (10): AP_APP, AP_AUTO, INVENTORY, DW_USER, HRAPPQA, SUPPORT_APP, FIN_RO, SCM_APP_QA, SCM_APP_QA_RO, SCM_ARCH
The application tablespaces had already been created on the target. Below I walk through FINQA in full. FINDEV follows exactly the same steps with its own schema list, and I give its parameter files at the end.
Step 1: Check the schema users exist on the source
A schema missing from the source makes expdp log ORA-39165: Schema ... was not found, so I check that first. This query shows each user's status and how many objects, tables and segments it owns:
export ORACLE_SID=FINQA
sqlplus / as sysdba
SET LINESIZE 200 PAGESIZE 100
COL username FORMAT A20
COL status FORMAT A10
SELECT u.username,
CASE WHEN du.username IS NULL THEN 'MISSING' ELSE du.account_status END AS status,
(SELECT COUNT(*) FROM dba_objects o WHERE o.owner = u.username) AS total_objects,
(SELECT COUNT(*) FROM dba_tables t WHERE t.owner = u.username) AS tables,
(SELECT COUNT(*) FROM dba_segments s WHERE s.owner = u.username) AS segments
FROM (SELECT column_value AS username
FROM TABLE(sys.odcivarchar2list('AP_APP','AP_AUTO','INVENTORY','DW_USER',
'HRAPPQA','SUPPORT_APP','FIN_RO','SCM_APP_QA','SCM_APP_QA_RO','SCM_ARCH'))) u
LEFT JOIN dba_users du ON du.username = u.username
ORDER BY u.username;
Output:
USERNAME STATUS TOTAL_OBJECTS TABLES SEGMENTS -------------------- ---------- ------------- ---------- ---------- AP_APP OPEN 14 6 0 AP_AUTO OPEN 412 118 236 DW_USER OPEN 9 0 0 FIN_RO OPEN 22 0 0 HRAPPQA OPEN 57 21 38 INVENTORY OPEN 11 4 6 SCM_APP_QA OPEN 268 74 151 SCM_APP_QA_RO OPEN 31 0 0 SCM_ARCH OPEN 96 45 88 SUPPORT_APP OPEN 7 2 0 10 rows selected.
All 10 users exist. Five of them own no segments. That is fine: they own only views, synonyms, code or empty tables. Since 11gR2, deferred segment creation means an empty table has no segment. FIN_RO and SCM_APP_QA_RO are read-only accounts, so they own no tables at all.
Step 2: Check the size of the schemas
COL owner FORMAT A25
SELECT NVL(owner, '** TOTAL **') AS owner,
ROUND(SUM(bytes)/1024/1024, 2) AS size_mb,
ROUND(SUM(bytes)/1024/1024/1024, 2) AS size_gb
FROM dba_segments
WHERE owner IN ('AP_APP','AP_AUTO','INVENTORY','DW_USER','HRAPPQA',
'SUPPORT_APP','FIN_RO','SCM_APP_QA','SCM_APP_QA_RO','SCM_ARCH')
GROUP BY ROLLUP(owner)
ORDER BY GROUPING(owner), owner;
Output:
OWNER SIZE_MB SIZE_GB ------------------------- ---------- ---------- AP_AUTO 2014.63 1.97 HRAPPQA 10.63 .01 INVENTORY 1.06 0 SCM_APP_QA 386 .38 SCM_ARCH 761.81 .74 ** TOTAL ** 3174.13 3.1 6 rows selected.
Tip: only schemas that own segments appear here, which is why there are 5 rows plus the total and not 10. Using ORDER BY GROUPING(owner) puts the TOTAL row last.
You can also get the real dump size without exporting anything:
expdp "'/ as sysdba'" schemas=AP_APP,AP_AUTO,INVENTORY,DW_USER,HRAPPQA,SUPPORT_APP,FIN_RO,SCM_APP_QA,SCM_APP_QA_RO,SCM_ARCH estimate_only=yes estimate=blocks nologfile=yes
Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA . estimated "AP_AUTO"."INVOICE_DOCUMENTS" 1.152 GB . estimated "SCM_ARCH"."SHIPMENT_HIST" 512.0 MB . estimated "SCM_APP_QA"."PURCHASE_ORDER_LINES" 184.0 MB . . . Total estimation using BLOCKS method: 2.287 GB Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Fri Nov 27 09:41:12 2026 elapsed 0 00:00:14
The estimate is smaller than dba_segments because index space doesn't go into the dump. Indexes are rebuilt during the import.
Step 3: Find the tablespaces the schemas use
impdp needs two kinds of tablespace on the target: the ones holding the data, and each user's default tablespace (used when it creates the users).
COL username FORMAT A20
COL default_tablespace FORMAT A20
COL temporary_tablespace FORMAT A10
SELECT username, default_tablespace, temporary_tablespace
FROM dba_users
WHERE username IN ('AP_APP','AP_AUTO','INVENTORY','DW_USER','HRAPPQA',
'SUPPORT_APP','FIN_RO','SCM_APP_QA','SCM_APP_QA_RO','SCM_ARCH')
ORDER BY username;
USERNAME DEFAULT_TABLESPACE TEMPORARY_ -------------------- -------------------- ---------- AP_APP AP_DATA TEMP AP_AUTO AP_DATA TEMP DW_USER USERS TEMP FIN_RO USERS TEMP HRAPPQA HR_DATA TEMP INVENTORY SCM_DATA TEMP SCM_APP_QA SCM_DATA TEMP SCM_APP_QA_RO USERS TEMP SCM_ARCH ARCH_DATA TEMP SUPPORT_APP USERS TEMP 10 rows selected.
COL owner FORMAT A20
COL tablespace_name FORMAT A20
SELECT owner, tablespace_name, ROUND(SUM(bytes)/1024/1024, 2) AS size_mb
FROM dba_segments
WHERE owner IN ('AP_APP','AP_AUTO','INVENTORY','DW_USER','HRAPPQA',
'SUPPORT_APP','FIN_RO','SCM_APP_QA','SCM_APP_QA_RO','SCM_ARCH')
GROUP BY owner, tablespace_name
ORDER BY owner, tablespace_name;
OWNER TABLESPACE_NAME SIZE_MB -------------------- -------------------- ---------- AP_AUTO AP_DATA 2014.63 HRAPPQA HR_DATA 10.63 INVENTORY SCM_DATA 1.06 SCM_APP_QA SCM_DATA 386 SCM_ARCH ARCH_DATA 761.81
So the target needs 5 tablespaces: AP_DATA, ARCH_DATA, HR_DATA, SCM_DATA and USERS.
Step 4: Check the tablespaces and free space on the target
I ran this on tgtdbhost01. Any tablespace that comes back MISSING has to be created, or remapped with remap_tablespace, before the import.
SET LINESIZE 200 PAGESIZE 100
COL tablespace_name FORMAT A20
COL status FORMAT A10
COL autoextend FORMAT A10
SELECT t.name AS tablespace_name,
NVL(ts.status, 'MISSING') AS status,
ROUND(df.alloc_mb, 2) AS allocated_mb,
ROUND(df.alloc_mb - NVL(fs.free_mb, 0), 2) AS used_mb,
ROUND(NVL(fs.free_mb, 0), 2) AS free_mb,
ROUND(df.max_mb, 2) AS max_mb,
df.autoextend
FROM (SELECT column_value AS name
FROM TABLE(sys.odcivarchar2list('AP_DATA','ARCH_DATA','HR_DATA','SCM_DATA','USERS'))) t
LEFT JOIN dba_tablespaces ts ON ts.tablespace_name = t.name
LEFT JOIN (SELECT tablespace_name,
SUM(bytes)/1024/1024 AS alloc_mb,
SUM(GREATEST(bytes, NVL(maxbytes,0)))/1024/1024 AS max_mb,
MAX(autoextensible) AS autoextend
FROM dba_data_files GROUP BY tablespace_name) df ON df.tablespace_name = t.name
LEFT JOIN (SELECT tablespace_name, SUM(bytes)/1024/1024 AS free_mb
FROM dba_free_space GROUP BY tablespace_name) fs ON fs.tablespace_name = t.name
ORDER BY t.name;
Output (target):
TABLESPACE_NAME STATUS ALLOCATED_MB USED_MB FREE_MB MAX_MB AUTOEXTEND -------------------- ---------- ------------ ---------- ---------- ---------- ---------- AP_DATA ONLINE 1024 2 1022 32767.98 YES ARCH_DATA ONLINE 1024 2 1022 32767.98 YES HR_DATA ONLINE 512 1 511 32767.98 YES SCM_DATA ONLINE 1024 2 1022 32767.98 YES USERS ONLINE 100 5.31 94.69 32767.98 YES
All 5 are ONLINE and can autoextend to about 32 GB, which is plenty for about 2 GB in AP_DATA. No remap needed.
Step 5: Check the Data Pump directory on both servers
COL owner FORMAT A10
COL directory_name FORMAT A20
COL directory_path FORMAT A60
SELECT owner, directory_name, directory_path
FROM dba_directories
WHERE directory_name IN ('DP_DIR','DATA_PUMP_DIR')
ORDER BY directory_name;
OWNER DIRECTORY_NAME DIRECTORY_PATH ---------- -------------------- ------------------------------------------------------------ SYS DATA_PUMP_DIR /u01/app/oracle/admin/FINQA/dpdump/ SYS DP_DIR /u01/app/oracle/dpdump
If the directory doesn't exist on the target, create it and make sure the oracle OS user can write to the folder:
SQL> CREATE OR REPLACE DIRECTORY DP_DIR AS '/u01/app/oracle/dpdump'; Directory created. $ ls -ld /u01/app/oracle/dpdump drwxr-xr-x. 2 oracle oinstall 4096 Nov 27 09:30 /u01/app/oracle/dpdump $ df -h /u01 Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg01-u01 200G 71G 130G 36% /u01
Step 6: Export the schemas on the source
Common mistakes to avoid: don't split the schema list across several lines on the command line, because the shell treats each line as a new command, and check for a missing comma between schema names. A parameter file avoids both problems.
$ cat finqa_exp.par schemas=AP_APP,AP_AUTO,INVENTORY,DW_USER,HRAPPQA,SUPPORT_APP,FIN_RO,SCM_APP_QA,SCM_APP_QA_RO,SCM_ARCH directory=DP_DIR dumpfile=FINQA_20261127.dmp logfile=FINQA_20261127_EXP.log exclude=STATISTICS $ export ORACLE_SID=FINQA $ expdp "'/ as sysdba'" parfile=finqa_exp.par
Output:
Export: Release 19.0.0.0.0 - Production on Fri Nov 27 10:12:41 2026 Version 19.21.0.0.0 Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Starting "SYS"."SYS_EXPORT_SCHEMA_01": "/******** AS SYSDBA" parfile=finqa_exp.par Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Processing object type SCHEMA_EXPORT/USER Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE Processing object type SCHEMA_EXPORT/TABLE/TABLE Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type SCHEMA_EXPORT/TABLE/COMMENT Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_SPEC Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE Processing object type SCHEMA_EXPORT/VIEW/VIEW Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_BODY Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/TRIGGER . . exported "AP_AUTO"."INVOICE_DOCUMENTS" 1.127 GB 184522 rows . . exported "SCM_ARCH"."SHIPMENT_HIST" 498.3 MB 4120877 rows . . exported "SCM_APP_QA"."PURCHASE_ORDER_LINES" 176.9 MB 1893304 rows . . exported "AP_AUTO"."INVOICE_HEADER" 92.41 MB 612047 rows . . . . . exported "INVENTORY"."STOCK_LOCATION" 48.21 KB 312 rows . . exported "SUPPORT_APP"."APP_SETTINGS" 0 KB 0 rows Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is: /u01/app/oracle/dpdump/FINQA_20261127.dmp Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Fri Nov 27 10:16:03 2026 elapsed 0 00:03:22
The last line should say successfully completed. If it says completed with X error(s), search the log for ORA-. If a previous attempt left the dump file behind, add reuse_dumpfiles=yes, or the job fails with ORA-27038.
Step 7: Copy the dump file to the target server
$ cd /u01/app/oracle/dpdump $ ls -lh FINQA_20261127.dmp -rw-r-----. 1 oracle oinstall 2.1G Nov 27 10:16 FINQA_20261127.dmp $ scp FINQA_20261127.dmp oracle@tgtdbhost01:/u01/app/oracle/dpdump/ FINQA_20261127.dmp 100% 2148MB 102.3MB/s 00:21 $ md5sum FINQA_20261127.dmp 5c3b8e0f1a7d24e9b6f0c2d8a41e97b3 FINQA_20261127.dmp $ ssh oracle@tgtdbhost01 md5sum /u01/app/oracle/dpdump/FINQA_20261127.dmp 5c3b8e0f1a7d24e9b6f0c2d8a41e97b3 /u01/app/oracle/dpdump/FINQA_20261127.dmp
The checksums match, so the file arrived intact.
Step 8: Import the schemas on the target
$ cat finqa_imp.par schemas=AP_APP,AP_AUTO,INVENTORY,DW_USER,HRAPPQA,SUPPORT_APP,FIN_RO,SCM_APP_QA,SCM_APP_QA_RO,SCM_ARCH directory=DP_DIR dumpfile=FINQA_20261127.dmp logfile=FINQA_20261127_IMP.log $ export ORACLE_SID=FINQA $ impdp "'/ as sysdba'" parfile=finqa_imp.par
Output:
Import: Release 19.0.0.0.0 - Production on Fri Nov 27 10:31:08 2026 Version 19.21.0.0.0 Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Master table "SYS"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded Starting "SYS"."SYS_IMPORT_SCHEMA_01": "/******** AS SYSDBA" parfile=finqa_imp.par Processing object type SCHEMA_EXPORT/USER Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE Processing object type SCHEMA_EXPORT/TABLE/TABLE Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA . . imported "AP_AUTO"."INVOICE_DOCUMENTS" 1.127 GB 184522 rows . . imported "SCM_ARCH"."SHIPMENT_HIST" 498.3 MB 4120877 rows . . imported "SCM_APP_QA"."PURCHASE_ORDER_LINES" 176.9 MB 1893304 rows . . imported "AP_AUTO"."INVOICE_HEADER" 92.41 MB 612047 rows . . . Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT ORA-39083: Object type OBJECT_GRANT failed to create with error: ORA-01917: user or role 'REPORT_USER' does not exist Failing sql is: GRANT SELECT ON "SCM_ARCH"."SHIPMENT_HIST" TO "REPORT_USER" Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_SPEC Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE Processing object type SCHEMA_EXPORT/VIEW/VIEW Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_BODY Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/TRIGGER Job "SYS"."SYS_IMPORT_SCHEMA_01" completed with 1 error(s) at Fri Nov 27 10:38:44 2026 elapsed 0 00:07:36
The one error is a grant to a user (REPORT_USER) that isn't part of this refresh and doesn't exist on the target. Errors like this are common and harmless. Either create the user and re-run the grant, or ignore it if the application team confirms it isn't needed.
Optional impdp parameters:
remap_tablespace=OLD_TS:NEW_TS: if a source tablespace doesn't exist on the target.table_exists_action=REPLACE: if the schemas already exist on the target with tables in them (only with sign-off).parallel=4: speeds up larger imports.
Step 9: Recompile invalid objects
SQL> @?/rdbms/admin/utlrp.sql
TIMESTAMP
--------------------------------------------------------------------------------
COMP_TIMESTAMP UTLRP_BGN 2026-11-27 10:41:02
...
OBJECTS WITH ERRORS
-------------------
0
ERRORS DURING RECOMPILATION
---------------------------
0
PL/SQL procedure successfully completed.
SELECT owner, object_type, COUNT(*)
FROM dba_objects
WHERE status = 'INVALID'
AND owner IN ('AP_APP','AP_AUTO','INVENTORY','DW_USER','HRAPPQA',
'SUPPORT_APP','FIN_RO','SCM_APP_QA','SCM_APP_QA_RO','SCM_ARCH')
GROUP BY owner, object_type;
no rows selected
Step 10: Gather fresh statistics
The export used exclude=STATISTICS, so gather new statistics on the target:
BEGIN
FOR s IN (SELECT username FROM dba_users
WHERE username IN ('AP_APP','AP_AUTO','INVENTORY','DW_USER','HRAPPQA',
'SUPPORT_APP','FIN_RO','SCM_APP_QA','SCM_APP_QA_RO','SCM_ARCH')) LOOP
DBMS_STATS.GATHER_SCHEMA_STATS(ownname => s.username, degree => 4);
END LOOP;
END;
/
PL/SQL procedure successfully completed. Elapsed: 00:01:47.22
Step 11: Validate source against target
Run the same object count on both servers and compare:
SELECT owner, COUNT(*) AS objects,
SUM(CASE WHEN object_type = 'TABLE' THEN 1 ELSE 0 END) AS tables,
SUM(CASE WHEN status = 'INVALID' THEN 1 ELSE 0 END) AS invalid
FROM dba_objects
WHERE owner IN ('AP_APP','AP_AUTO','INVENTORY','DW_USER','HRAPPQA',
'SUPPORT_APP','FIN_RO','SCM_APP_QA','SCM_APP_QA_RO','SCM_ARCH')
GROUP BY owner
ORDER BY owner;
| Owner | Objects (source) | Objects (target) | Tables (source / target) | Invalid (target) | Match |
|---|---|---|---|---|---|
| AP_APP | 14 | 14 | 6 / 6 | 0 | ✔ |
| AP_AUTO | 412 | 412 | 118 / 118 | 0 | ✔ |
| DW_USER | 9 | 9 | 0 / 0 | 0 | ✔ |
| FIN_RO | 22 | 22 | 0 / 0 | 0 | ✔ |
| HRAPPQA | 57 | 57 | 21 / 21 | 0 | ✔ |
| INVENTORY | 11 | 11 | 4 / 4 | 0 | ✔ |
| SCM_APP_QA | 268 | 268 | 74 / 74 | 0 | ✔ |
| SCM_APP_QA_RO | 31 | 31 | 0 / 0 | 0 | ✔ |
| SCM_ARCH | 96 | 96 | 45 / 45 | 0 | ✔ |
| SUPPORT_APP | 7 | 7 | 2 / 2 | 0 | ✔ |
Everything matches. As a final check, look for database links that still point at the old hostname:
COL owner FORMAT A15
COL db_link FORMAT A25
COL host FORMAT A40
SELECT owner, db_link, host FROM dba_db_links
WHERE owner IN ('AP_APP','AP_AUTO','INVENTORY','DW_USER','HRAPPQA',
'SUPPORT_APP','FIN_RO','SCM_APP_QA','SCM_APP_QA_RO','SCM_ARCH');
no rows selected
FINDEV: same steps, different schema list
For FINDEV I repeated steps 1 to 11 with these parameter files:
# findev_exp.par (run on srcdbhost01, ORACLE_SID=FINDEV) schemas=AP_APP,AP_AUTO,INVENTORY,DW_USER,HRAPP,SUPPORT_APP,SCM_APP_DEV,SCM_ARCH directory=DP_DIR dumpfile=FINDEV_20261127.dmp logfile=FINDEV_20261127_EXP.log exclude=STATISTICS # findev_imp.par (run on tgtdbhost01, ORACLE_SID=FINDEV) schemas=AP_APP,AP_AUTO,INVENTORY,DW_USER,HRAPP,SUPPORT_APP,SCM_APP_DEV,SCM_ARCH directory=DP_DIR dumpfile=FINDEV_20261127.dmp logfile=FINDEV_20261127_IMP.log
Checklist
- Users exist on the source (no ORA-39165 surprises).
- Schema sizes and estimated dump size known.
- Data and default tablespaces identified.
- Tablespaces present on the target with enough space (or remapped).
- Data Pump directory exists on both sides with enough free disk.
- Export with a parameter file and
exclude=STATISTICS. - Copy the dump and verify the checksum.
- Import and review the log for ORA- errors.
- Recompile with utlrp.sql and confirm 0 invalid objects.
- Gather schema statistics.
- Compare object counts and check DB links.
Lessons learned
- Use parameter files. Schema lists pasted over several lines, and a missing comma, were the two problems I hit in the commands I was given.
- Quote usernames in SQL.
WHERE owner IN (AP_APP, ...)without quotes gives ORA-00904: invalid identifier. - Don't paste long queries into SQL*Plus. Echoed
SQL>prompts can land in the middle of the text. Save the query to a .sql file and run it with @. - Size requests can be wrong. The request said the dump would be under 100 MB; the real size was about 2 GB. Always check before you start.
I hope this helps with your next schema refresh. Questions are welcome in the comments!
ConversionConversion EmoticonEmoticon