CREATE or REPLACE DIRECTORY datapump AS 'C:\temp\datapump';
Then, as you use Data Pump you can reference this DIRECTORY as a parameter for export where you would like the dump or log files to end up.Oracle 12c datapump have the following clauses:
EXCLUDE – This is used to filter the metadata from the export operation. This is more like a where clause which you can use to exclude any object or schema from the export job.
Example if you want a full database export except 1 schema (say TEST), then:-
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp FULL=YES EXCLUDE=SCHEMA:"='TEST'" LOGFILE=test.log |
Similarly suppose you want to exclude all indexes from a schema export and the condition is to export only indexes that starts with TEST_%, then:-
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST EXCLUDE=INDEX:"LIKE 'TEST_%'" LOGFILE=test.log |
So using this clause you can exclude any specific content from the dump, try and explore this option more. To get a list of available objects that can be excluded query the OBJECT_PATH column of DATABASE_EXPORT_OBJECTS, SCHEMA_EXPORT_OBJECTS and TABLE_EXPORT_OBJECTS views.
INCLUDE – Exactly opposite to EXCLUDE clause, this is used when you explicitly want to export, say only some tables, indexes along with views, packages in a schema dump, so only the the object types explicitly mentioned in the include clause would be imported and nothing else.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST INCLUDE=TABLE:"IN ('EMP', 'DEPT')" INCLUDE=PROCEDURE INCLUDE=INDEX:"LIKE 'TEST%'" LOGFILE=test.log |
So the above expdp command would only export tables EMP & DEPT, PROCEDURE and all indexes starting with TEST% no other objects of TEST schema would be exported.
QUERY – This clause allows you to filter the data that gets exported, think of it as EXCLUDE & INCLUDE clause but with more control over filtering, thus this is more like a WHERE clause of the expdp command.
When the QUERY parameter is specified for a table, Data Pump uses external tables to unload the target table.
It accepts values in the form:- QUERY = [schema.][table_name:] query_clause
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST QUERY=TEST.EMP:"WHERE DEPT_ID > 90 AND SAL > 90000" LOGFILE=test.log |
Above command would export all tables of TEST schema but only specific records of EMP table.
CLUSTER – This is used in RAC env. and used to spread the worker process on other oracle instances to utilize RAC resources for datapump jobs.
It accepts values as:- CLUSTER=[YES | NO]
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test_%U.dmp SCHEMAS=TEST CLUSTER=YES NOLOGFILE=YES |
SERVICE_NAME – This parameter is used with CLUSTER clause in RAC env. As you know CLUSTER clause if specified as YES allows MCP to use creates worker process in all the instances depending upon the degree of parallelism. But if you want to restrict the cluster resources for data pump you can specify SERVICE_NAME clause with CLUSTER=YES then MCP could only fork worker process on the instances that lies with the specified service name.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test_%U.dmp SCHEMAS=TEST CLUSTER=YES SERVICE_NAME=SERVICE_HA NOLOGFILE=YES |
ESTIMATE – This is used to estimate how much space each table in the export job will consume (in bytes).
It accepts values as:- ESTIMATE=[BLOCKS | STATISTICS]
1 |
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST ESTIMATE=STATISTICS LOGFILE=test.log |
ESTIMATE_ONLY – This is used to estimate the space that a job would consume, without actually performing the export operation.
It accepts values as:- ESTIMATE_ONLY=[YES | NO]
1 |
expdp user/password SCHEMAS=TEST ESTIMATE_ONLY=YES |
FILESIZE – This is used to specify the maximum size of each dump file. When the max file size for the dump file is reached MCP then closes this file and creates a new file for further write operations.
It accepts values as:- FILESIZE=integer[B | KB | MB | GB | TB]
If using this clause please do remember to assign a variable in DUMPFILE parameter else you’ll receive ORA-39095: Dump file space has been exhausted: Unable to allocate xxxxxxx bytes.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test_%U.dmp SCHEMAS=TEST EXCLUDE=INDEX:"LIKE 'TEST_%'" FILESIZE=1GB LOGFILE=test.log |
FLASHBACK_SCN – If you want the dump to be consistent with a specific SCN this clause can be used. By default datapump dumps are consistent on a per table basis but if you want all the tables to be consistent then FLASHBACK_SCN or FLASHBACK_TIME clauses should be used, depending upon the requirement.
Therefore the export operation is performed with data that is consistent up to the specified SCN in the FLASHBACK_SCN clause.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST COMPRESSION=DATA_ONLY FLASHBACK_SCN=103713102 LOGFILE=test.log |
To get the current SCN value you can use the below queries:-
|
SELECT current_scn FROM v$database; SELECT DBMS_FLASHBACK.get_system_change_number FROM dual; SELECT TIMESTAMP_TO_SCN(SYSTIMESTAMP) FROM dual; |
To convert time to SCN you can use TIMESTAMP_TO_SCN function as:-
|
SELECT TIMESTAMP_TO_SCN(SYSTIMESTAMP) FROM dual; |
FLASHBACK_TIME – This is similar to FLASHBACK_SCN, in this case the SCN that most closely matches the specified time is found, and then this SCN is used to get the consistent data.
1 |
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST COMPRESSION=DATA_ONLY FLASHBACK_TIME="TO_TIMESTAMP('21-09-2016 12:36:00', 'DD-MM-YYYY HH24:MI:SS')" NOLOGFILE=YES REUSE_DUMPFILES=YES |
FULL – This is used when you want to export full data dump.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=full_%U.dmp full=Y PARALLEL=6 ENCRYPTION=data_only ENCRYPTION_PASSWORD=T3sT NOLOGFILE=YES REUSE_DUMPFILES=YES |
JOB_NAME – This
is used to give a specific name to the export job, by
default the job name is in the format SYS_EXPORT__NN.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=full_%U.dmp full=Y PARALLEL=6 ENCRYPTION=data_only ENCRYPTION_PASSWORD=T3sT NOLOGFILE=YES JOB_NAME=Encrypt_full_dump REUSE_DUMPFILES=YES |
KEEP_MASTER – As we saw in Oracle datapump Architecture & Internals master table is used to store information (Export/import parameters, current status, object info etc) about the data pump job and is automatically deleted once the job is completed successfully or killed.
But what if you want to retain the information stored in master table to analyze the job, KEEP_MASTER clause is used if we need to retain the master table even after a successful job or killed job.
It accepts values as:- KEEP_MASTER=[YES | NO]
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=full_%U.dmp full=Y PARALLEL=6 ENCRYPTION=data_only ENCRYPTION_PASSWORD=T3sT NOLOGFILE=YES JOB_NAME=Encrypt_full_dump KEEP_MASTER=YES |
LOGTIME – This clause is used to include timestamp in the output messages.
It accepts values as:- LOGTIME=[NONE | STATUS | LOGFILE | ALL]
1 |
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST COMPRESSION=DATA_ONLY FLASHBACK_TIME="TO_TIMESTAMP('21-09-2016 12:36:00', 'DD-MM-YYYY HH24:MI:SS')" LOGTIME=ALL REUSE_DUMPFILES=YES |
METRICS – This clause is used to include additional information about the export job in the log file.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST CLUSTER=NO METRICS=YES |
NETWORK_LINK – Used in cases where database is exported via a database Link over the network. The data from the source database instance is written to a dump file set on the connected database instance.
This means that the system to which the expdp client is connected contacts the source database referenced by the DB link and writes the data to a dump file set back on the connected system.
|
expdp user/password FULL=YES DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp EXCLUDE=SCHEMA:"='TEST'" NETWORK_LINK=TEST_LINK LOGFILE=test.log |
NOLOGFILE – This clause can be used to suppress the creation of logfile.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=full_%U.dmp full=Y PARALLEL=6 ENCRYPTION=data_only ENCRYPTION_PASSWORD=T3sT NOLOGFILE=YES JOB_NAME=Encrypt_full_dump REUSE_DUMPFILES=YES |
PARALLEL – This clause is used to authorize MCP to fork worker process and then further parallel query process upto the integer specified with the PARALLEL clause.
Since each active worker process and slave process writes exclusively on the dumpfiles to utilize actual parallelization benefits the DUMPFILE needs to be specified with a variable so that MCP could open appropriate number of files to accommodate the integer specified with PARALLEL clause.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=full_%U.dmp full=Y PARALLEL=6 NOLOGFILE=YES JOB_NAME=Encrypt_full_dump LOGTIME=ALL |
PARFILE – There can be times when there are several clauses of expdp used or due to operating system special characters the expdp parameters are impacted, in such cases you can use a parameter file specifying all the parameters as per your requirement and specify the parameter file with PARFILE Clause.
Here is a parameter file (say, full.par):-
|
DIRECTORY=DATA_PUMP_DIR DUMPFILE=full_%U.dmp full=Y PARALLEL=6 NOLOGFILE=YES JOB_NAME=Encrypt_full_dump LOGTIME=ALL |
And it can be called via PARFILE clause, as:-
|
expdp user/password PARFILE=full.par |
REMAP_DATA – This clause is mostly used to mask the data when moving production dump to a test system. So using remap_data clause sensitive data can be replaced with random data.
It accepts values in the form:- REMAP_DATA=[schema.]table_name.column_name:[schema.]pkg.function
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST REMAP_DATA=TEST.EMP.DEPT_ID:EMP.REMAP.MIN10 METRICS=YES LOGFILE=test.log |
REUSE_DUMPFILES – If the dumpfile with the same name as you specified in the DUMPFILE clause is found at the path specified under the directory path, datapump would abort giving error.
You can however instruct MCP to overwrite the dumpfile using the REUSE_DUMPFILE clause.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST REUSE_DUMPFILES=YES METRICS=YES LOGFILE=test.log |
SAMPLE – This is used to specify a percentage of data rows to be exported in the dumpfile set.
It accepts values in the form:- SAMPLE=[[schema_name.]table_name:]sample_percent
where sample_percent is the percentage of data to be exported.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST SAMPLE=60 LOGFILE=test.log |
SCHEMAS – This is used to specify the comma separated list of schemas that you want to be exported.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST1,TEST2 SAMPLE=60 LOGFILE=test.log |
STATUS – As we read in the article Queries to Monitor Datapump Jobs, STATUS can be used from another expdp session to get the current picture of all the Datapump Processes. But if you want the STATUS output to be print in the same session from where export operation is being initiated, you can use the command line argument STATUS.
It accepts values as:- STATUS=[integer]
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST LOGFILE=test.log STATUS=100 |
With the above command the information of STATUS clause would be printed in the standard output after every 100 seconds.
TABLES – As the name suggests this is used to specify if you want to export one or more set of tables and partitions/sub-partitions.
It accepts values in the form:- TABLES=[schema_name.]table_name[:partition_name] [, …]
1 |
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp TABLES=TEST.EMP:TEST2:DEPT LOGFILE=test.log METRICS=Y |
TABLESPACES – This clause is used to specify the list of tablespaces that you want to export in tablespace mode. In tablespace mode, only the tables contained in a specified set of tablespaces are unloaded. If a table is unloaded, then its dependent objects are also unloaded. Both object metadata and data are unloaded. If any part of a table resides in the specified set, then that table and all of its dependent objects are exported.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp TABLESPACES=TEST_TBS1,TEST_TBS2 LOGFILE=test.log METRICS=Y |
TRANSPORT_FULL_CHECK – When this parameter is set to YES, the export job verifies that there are no dependencies between those objects inside the transportable set and those outside the transportable set.
For example, if a table is inside the transportable set but its index is not, then a failure is returned and the export operation is terminated. Similarly, a failure is also returned if an index is in the transportable set but the table is not.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp TABLESPACES=TEST_TBS1 TRANSPORT_FULL_CHECK=YES LOGFILE=test.log METRICS=Y |
TRANSPORT_TABLESPACES – This parameter is used to specify a list of tablespace names for which object metadata will be exported from the source database into the target database.
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp TRANSPORT_TABLESPACES=TEST_TBS1 TRANSPORT_FULL_CHECK=YES LOGFILE=test.log METRICS=Y |
TRANSPORTABLE –
Specifies whether the transportable option should be
used during a table mode export (specified with the
TABLES parameter) to export metadata for specific
tables, partitions, and subpartitions.
It accepts value as:- TRANSPORTABLE = [ALWAYS | NEVER]
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp TABLES=TEST.EMP:TEST2:DEPT TRANSPORTABLE=ALWAYS LOGFILE=test.log |
VERSION – This clause is used to create a dumpfile set that is compatible with an older release of Oracle Database.
It accepts values as:- VERSION=[COMPATIBLE | LATEST | version_string]
So if you want to export a dump from 11.2.0.3 Oracle DB version and to make dumpfile compatible with 10.2.0.4 version:-
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST VERSION=10.2 METRICS=YES LOGFILE=test.log |
VIEWS_AS_TABLES – This clause is used if you want to export a view as a table. Data Pump exports a table with the same columns as the view and with row data fetched from the view. Data Pump also exports objects dependent on the view, such as grants and constraints.
It accepts values in the form:- VIEWS_AS_TABLES=[schema_name.]view_name[:table_name], …
1 |
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp VIEW_AS_TABLES=TEST:EMP_V,TEST2:DEPT LOGFILE=test.log |
ABORT_STEP – Used to stop the job after it is initialized, it can be used if you want to test a script or to populate master table with data from the dumpfile.
It accepts values as:- ABORT_STEP=[n | -1],
n — If the value is zero or greater, then the export operation is started and the job is aborted at the object that is stored in the master table with the corresponding process order number.
-1 — If the value is negative one (-1) then abort the job after setting it up, but before exporting any objects or data.
|
expdp us0er/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST ABORT_STEP=-1 LOGFILE=test.log |
CONTENT – Lets you filter out what to export, this is basically used when you want METADATA to be exported and imported across to a different database, to copy the structure.
It accepts values as:- CONTENT=[ALL | DATA_ONLY | METADATA_ONLY]
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST CONTENT=METADATA_ONLY LOGFILE=test.log |
ACCESS_METHOD – Hope you have gone through Oracle datapump Architecture & Internals as to understand this further its manadatory to know the architecture and data movement methodologies of datapump APIs.
As you know that there are 3 choices available for data movement in datapump, using ACCESS_METHOD clause you can instruct MCP to choose a method regardless of the other factors.
It accepts values as:- ACCESS_METHOD=[AUTOMATIC | DIRECT_PATH | EXTERNAL_TABLE]
1 |
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST ACCESS_METHOD=EXTERNAL_TABLE LOGFILE=test.log |
ATTACH – This clause is to attach a new datapump session to any existing JOB. This is used if you want to check STATUS of a running job or KILL/RESUME/STOP etc a JOB.
It accepts values as:- ATTACH= [job_name]
The JOB Name can be fetched from DBA_DATAPUMP_JOBS view.
|
expdp ATTACH=TEST.TEST_IMPORT_SCHEMA_02 |
COMPRESSION– To use compression in the dump file sets this clause is used.
It accepts values as:- COMPRESSION=[ALL | DATA_ONLY | METADATA_ONLY | NONE]
1 |
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST COMPRESSION=DATA_ONLY LOGFILE=test.log |
COMPRESSION_ALGORITHM – To specify the compression algorithm to be used.
It accepts values as:- COMPRESSION_ALGORITHM=[BASIC], LOW, MEDIUM and HIGH
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST COMPRESSION=DATA_ONLY COMPRESSION_ALGORITHM=HIGH LOGFILE=test.log |
DIRECTORY – Used to specify the Oracle directory where MCP would write the dumpfiles, thus the user invoking the expdp should have read/write access on this Oracle directory.
DUMPFILE – This is the dumpfile name that is created at the DIRECTORY. Variable %U can be used when assigning the dumpfile name, it is required if you use FILESIZE or PARALLEL parameters.
LOGFILE – This clause is used to specify the logfile name which is created in the directory specified by DIRECTORY clause.
By default the dumpfile name of export job, if the clause is not specified is export.log.
ENCRYPTION – This is used to encrypt part or all of the dump file.
It accepts values as:- ENCRYPTION = [ALL | DATA_ONLY | ENCRYPTED_COLUMNS_ONLY | METADATA_ONLY | NONE]
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST ENCRYPTION=data_only ENCRYPTION_PASSWORD=T3sT LOGFILE=test.log |
ENCRYPTION_ALGORITHM – Specifies which cryptographic algorithm should be used to perform the encryption.
It accepts values as:- [AES128 | AES192 | AES256]
|
expdp user/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=test.dmp SCHEMAS=TEST ENCRYPTION=data_only ENCRYPTION_PASSWORD=T3sT ENCRYPTION_ALGORITHM=AES128 LOGFILE=test.log |
In addition to Data Masking Pack in Grid Control, Oracle Data
Pump provides a method to mask data: REMAP_DATA parameter
introduced in Oracle Database 11g.
Oracle Data Pump’s REMAP_DATA feature uses a remapping function to
rewrite data.
For example, a column with phone numbers could be replaced by a
numbers generated by a REMAP_DATA function.
REMAP_DATA allows transformation of column’s data while exporting
(expdp) or importing (impdp) by using a remapping function in the
database.
REMAP_DATA with Data Pump is usually faster than a custom UPDATE
statement for masking data.
To mask multiple columns in the same process and command, the
REMAP_DATA parameter can be used multiple times.
Restrictions
- Data types must be same in the table column, masking function
parameter, and function return value.
- No commits or rollbacks should be done in the masking function.
- No direct path loads can be used in import process with
REMAP_DATA.
Note: Operation of long export/import data pump processes can be
monitored from the v$session_longops view, but the estimated
values do not take into account REMAP_DATA operations.
Quick Example:
REMAP_DATA=[schema.]tablename.column_name:[schema.]pkg.function
[schema1.]tablename.column_name:
[schema2.]pkg.function
Create a table in the CUSTOMERS schema called phones
CREATE TABLE CUSTOMERS.PHONES (
MODELNAME VARCHAR(20) NOT NULL,
PHONENUMBER VARCHAR2(50));
insert into CUSTOMERS.PHONES
values(’N900’,’+3581234567’);
insert into CUSTOMERS.PHONES values(’N8’,’+3589817654’);
insert into CUSTOMERS.PHONES values(’N7’,’+3584834819’);
Commit;
We then need to create a function for remapping. The function
masknumber will accept a varchar2 type and returns a random phone
number in varchar2 type
create or replace package customers.maskpkg
as
function masknumber(phonenumber
varchar2) return varchar2;
end;
/
create or replace package body customers.maskpkg as
function masknumber (phonenumber varchar2)
return varchar2 is
begin
return
substr(phonenumber,1,4)||round(dbms_random.value (100,999))||
lpad(round(dbms_random.value (1,9999)),4,'0');
end;
end;
/
This example will mask one column: phonenumber to the export
output file
expdp customers tables=customers.phones
dumpfile=phones_masked.dmp directory=dumpdir
remap_data=customers.phones.phonenumber:customers.maskpkg.masknumber
REMAP_DATA parameter can also be used in the import process
impdp dumpfile=data.dmp
REMAP_DATA=scott.orders.customer_name:scott.maskpkg.mask
expdp dumpfile=data.dmp
REMAP_DATA=scott.orders.customer_name:scott.maskpkg.mask
Compression
Usually, when you have to use expdp you need to
compress/uncompress the exported file, adding more time and also
taking more CPU time. In oracle 11g, there is no need to use
OS-level compress utility, the COMPRESSION option not only is
faster, it also makes the file much smaller. Valid values are:
ALL, (METADATA_ONLY), DATA_ONLY and NONE.
Example:
nohup expdp system schemas=test directory=data_pump_dir
dumpfile=test.dmp logfile=test.log compression=all &
In all this cases we will be using ORCL as the
original DB, and DEST as the destination DB.
Scenario1 Export the whole ORCL database.
expdp userid=system/password@ORCL dumpfile=expfulldp.dmp
logfile=expfulldp.log full=y
directory=dumplocation
Scenario2 Export the scott schema from ORCL and
import into DEST database.
expdp userid=system/password@ORCL dumpfile=schemaexpdb.dmp
logfile=schemaexpdb.log directory=dumplocation schemas=scott
impdp userid=system/password@DEST
dumpfile=schemaexpdb.dmp logfile=schemaimpdb.log
directory=dumplocation
Another Example: While import,
exclude some objects(sequence,view,package,cluster,table).
Load the objects which came from RES tablespace into USERS
tablespace in target database.
impdp userid=system/password@DEST dumpfile=schemaexpdb.dmp
logfile=schemaimpdb.log directory=dumplocation table_exists_action=replace
remap_tablespace=res:users
exclude=sequence,view,package,cluster,table:"in('LOAD_EXT')"
Scenario
3
Clone
a
User
In the past when a DBA had the need to create a new user with the
same structure (All objects, tablespaces quota, synonyms, grants,
system privileges, etc) was a very painful experience, now all can
be done very easily using Data Pump, let use as an example that
you want to create the user ”Z” exactly like the user “A”, to
achieve this goal all you will need to do is first export the
schema “A” definition and then import it again saying to the Data
Pump to change the schema “A” for the new schema named “Z” using
the “remap_schema” parameter available with impdp.
expdp user/password schemas=A
directory=datapump
dumpfile=Schema_A.dmp
[optional: content=metadata_only]
impdp user/password remap_schema=A:Z
directory=datapump dumpfile= Schema_A.dmp
And your new user Z is now created like your existing user A ,
that easy!
Scenario
4
Create
a
Metadata File
You can generate a SQL File from an existing exported file. As an
Example, I am going to expdp the Schema Fraudguard, after that, I
will use the impdp command with the sqlfile option to generate a
sql containing all the objects that I already exported:
expdp system schemas=fraudguard content=metadata_only
directory=EXPORTPATH dumpfile=metadata_24112010.dmp
impdp system directory=EXPORTPATH dumpfile= metadata_24112010.dmp
sqlfile=metadata_24112010.sql
Scenario5 Export the emp table from scott schema at
ORCL instance and import into DEST
instance.
expdp userid=system/password@ORCL logfile=tableexpdb.log
directory=dumplocation tables=scott.part_emp
dumpfile=tableexpdb.dmp
impdp userid=system/password@DEST dumpfile=tableexpdb.dmp
logfile=tabimpdb.log directory=dumplocation table_exists_action=REPLACE
Scenario
6
Create
smaller
Copies of PROD
That is a very common task for a DBA, you have a task to create a
copy of your Database (for development or test purpose) but your
destination server don’t have enough space to create a full copy
of it!
This can be easily solved with Data Pump, for this example, let
say that you only have space for 70% of your production database,
now to know how to proceed, we need to decide if the copy will
contain metadata only (no data/rows) or if it will include the
data also. Let’s see how to do each way:
a) Metadata Only
First do a full export of your source database.
expdp user/password
content=metadata_only full=y directory=datapump
dumpfile=metadata_24112010.dmp
Then, let’s import the metadata and tell the Data Pump to reduce
the size of extents to 70%, you can do it using the parameter
“transform” available with “impdp”, it represent the percentage
multiplier that will be used to alter extent allocations and
datafiles size.
impdp user/password
transform=pctspace:70 directory=datapump
dumpfile=metadata_24112010.dmp
b) Metadata and data
First does a full export of your source database using the export
parameter “sample”, this parameter specify a percentage of the
data rows to be sampled and unload from your source database, in
this case let’s use 70%.
expdp user/password
sample=70 full=y directory=datapump
dumpfile=expdp_70_24112010.dmp
Then, all you need to do as the example before is to import it
telling the Data Pump to reduce the size of extents to 70%, and
that’s it!
impdp user/password
transform=pctspace:70 directory=datapump
dumpfile=expdp_70_24112010.dmp
Scenario 7 Export only specific partition in emp
table from scott schema at orcl and import into ordb
database.
expdp userid=system/password@ORCL dumpfile=partexpdb.dmp
logfile=partexpdb.log directory=dumplocation tables=scott.part_emp:part10,scott.part_emp:part20
If we want to overwrite the exported data in target
database, then we need to delete emp table for deptno
in(10,20).
scott@DEST> delete part_emp where deptno in (10,20);
scott@DEST> commit;
impdp userid=system/password@DEST dumpfile=partexpdb.dmp
logfile=tabimpdb.log directory=dumplocation table_exists_action=append
Scenario 8 Export only tables (no code) in scott schema
at ORCL and import into DEST database
expdp userid=system/password@ORCL dumpfile=schemaexpdb.dmp
logfile=schemaexpdb.log directory=dumplocation include=table schemas=scott
impdp userid=system/password@DEST dumpfile=schemaexpdb.dmp
logfile=schemaimpdb.log directory=dumplocation table_exists_action=replace
Scenario 9 Export only rows belonging to department 10
and 20 in emp and dept table from ORCLdatabase.
Import the dump file in @DESTdatabase.
While importing, load only deptno 10 in target database.
expdp userid=system/password@ORCL
dumpfile=data_filter_expdb.dmp logfile=data_filter_expdb.log
directory=dumplocation content=data_only
schemas=scott include=table:"in('EMP','DEPT')"
query="where deptno
in(10,20)"
impdp userid=system/password@DEST
dumpfile=data_filter_expdb.dmp logfile=data_filter_impdb.log
directory=dumplocation schemas=scott
query="where deptno =
10" table_exists_action=APPEND
Scenario 10 Export the scott schema from ORCLdatabase
and
split
the
dump file into 50M sizes. Import the dump file into DEST datbase.
Expdp parfile content:
userid=system/password@ORCL
logfile=schemaexp_split.log
directory=dumplocation
dumpfile=schemaexp_split_%U.dmp
filesize=50M
schemas=scott
include=table
As per the above expdp parfile, initially,
schemaexp_split_01.dmp file will be created. Once the file is
50MB, the next file called schemaexp_split_02.dmp will be
created. Let us say, the dump file size is 500MB, then it
creates 10 dump file as each file size is 50MB.
Impdp parfile content:
userid=system/password@DEST
logfile=schemaimp_split.log
directory=dumplocation
dumpfile=schemaexp_split_%U.dmp
table_exists_action=replace
remap_tablespace=res:users
exclude=grant
Scenario 11 Export the scott schema from ORCL
database and split the dump file into four files. Import the
dump file into DEST datbase.
Expdp parfile content:
userid=system/password@ORCL
logfile=schemaexp_split.log
directory=dumplocation
dumpfile=schemaexp_split_%U.dmp
parallel=4
schemas=scott
include=table
As per the above parfile content, initially four files will be
created - schemaexp_split_01.dmp, schemaexp_split_02.dmp,
schemaexp_split_03.dmp, schemaexp_split_04.dmp. Notice that
every occurrence of the substation variable is incremented
each time. Since there is no FILESIZE parameter, no more files
will be created.
Impdp parfile content:
userid=system/password@DEST
logfile=schemaimp_split.log
directory=dumplocation
dumpfile=schemaexp_split_%U.dmp
table_exists_action=replace
remap_tablespace=res:users
exclude=grant
Scenario 12 Export the scott schema from ORCL database
and split the dump file into three files.
The dump files will be stored in three different location.
This method is especially useful if you do not have enough
space in one file system to perform the complete expdp job.
After export is successful, import the dump file into DEST database.
Expdp parfile content:
userid=system/password@ORCL
logfile=schemaexp_split.log
directory=dumplocation
dumpfile=dump1:schemaexp_%U.dmp,dump2:schemaexp_%U.dmp,dump3:schemaexp_%U.dmp
filesize=50M
schemas=scott
include=table
As per above expdp par file content, it place the dump file
into three different location. Let us say, entire expdp dump
file size is 1500MB. Then it creates 30 dump files(each dump
file size is 50MB) and place 10 files in each file system.
Impdp parfile content:
userid=system/password@DEST
logfile=schemaimp_split.log
directory=dumplocation
dumpfile=dump1:schemaexp_%U.dmp,dump2:schemaexp_%U.dmp,dump3:schemaexp_%U.dmp
table_exists_action=replace
Scenario 13 Expdp scott schema in ORCL
and impdp the dump file in training schema in DEST database.
expdp userid=scott/tiger@ORCL logfile=netwrokexp1.log
directory=dumplocation dumpfile=networkexp1.dmp schemas=scott
include=table
impdp userid=system/password@DEST logfile=networkimp1.log
directory=dumplocation dumpfile=networkexp1.dmp
table_exists_action=replace remap_schema=scott:training
Scenario 14 Expdp table on ORCL
database and imdp in DEST.
When we export the data, export only 20 percent of the table
data. We use SAMPLE parameter to accomplish this task.
SAMPLE parameter allows you to export subsets of data by
specifying the percentage of data to be sampled and exported.
The sample_percent indicates the probability that a block of
rows will be selected as part of the sample. It does not mean
that the database will retrieve exactly that amount of rows
from the table. The value you supply for sample_percent can be
anywhere from .000001 up to, but not including, 100.
If no table is specified, then the sample_percent value
applies to the entire export job. The SAMPLE parameter is not
valid for network exports.
expdp userid=system/password@ORCL dumpfile=schemaexpdb.dmp
logfile=schemaexpdb.log directory=dumplocation
tables=scott.part_emp SAMPLE=20
As per the above expdp parfile, it exports only 20 percent of
the data in part_emp table.
impdp userid=system/password@DEST dumpfile=schemaexpdb.dmp
logfile=schemaimpdb.log directory=dumplocation
table_exists_action=replace
Exclude Objects
The exclude parameter allows any database object type to be
excluded from an export or import operation. The optional name
qualifier allows you finer selectivity within each object type
specified. For example, the following three lines in a parameter
file:
Exclude=function
Exclude=procedure
Exclude=package:”like ‘PAYROLL%' “
Would exclude all functions, procedures and packages with names
starting with ‘PAYROLL' from the job.
Include
The include parameter includes only the specified object
types and objects in an operation. For example, if the above three
specifications were INCLUDE parameters in a full database export,
only functions, procedures and packages with names starting with
‘PAYROLL' would be written to the dumpfile set. You can use the
clause INCLUDE=TABLE:"LIKE 'TAB%'" to export only those tables
whose name start with TAB. Similarly, you could use the construct
INCLUDE=TABLE:"NOT LIKE 'TAB%'" to exclude all tables starting
with TAB. Alternatively you can use the EXCLUDE parameter to
exclude specific objects.
Content
The content parameter allows one to request for the current
operation just metadata, just data or both. The exp ‘ROWS=N'
parameter is equivalent to content=metadata_only, but there is no
equivalent for content=data_only.
Query
The query parameter operates much as it did in original export,
but with two significant enhancements:
1. It can be qualified with a table name such
that it only applies to that table
2. It can be used during import as well as
export.
table_exists_action
The TABLE_EXISTS_ACTION=APPEND parameter allows data to be
imported into existing tables. Other uses:
* skip
* append
* truncate
* replace
I/O BANDWIDTH IS MOST IMPORTANT FACTOR
It is important to make sure there is sufficient I/O bandwidth to
handle the number of parallel threads specified; otherwise
performance can actually degrade with additional parallel threads.
Care should be taken to make sure the dumpfile set is located on
spindles other than those holding the instance's data files.
Wildcard file support makes it easy to spread the I/O load over
multiple spindles. For example, a specification such as:
Dumpfile=dmpdir1:full1%u.dmp,dmpdir2:full2%u.dmp
Dumpfile=dmpdir3:full3%u.dmp,dmpdir4:full4%u.dmp
will create files named full101.dmp, full201.dmp,
full301.dmp, full401.dmp, full102.dmp, full202.dmp, full302.dmp,
etc. in a round-robin fashion across the four directories pointed
to by the four directory objects.
In parallel mode, the status screen will show four worker
processes. (In default mode, only one process will be visible.)
All worker processes extract data simultaneously and show their
progress on the status screen
INITIALIZATION
PARAMETERS
Essentially no tuning is required to achieve maximum Data Pump
performance. Initialization parameters should be sufficient out of
the box.
Monitoring
Export:
While Data Pump Export is running, press Control-C; it will stop
the display of the messages on the screen, but not the export
process itself. Instead, it will display the Data Pump Export
prompt as shown below. The process is now said to be in
"interactive" mode:
Export>
This approach allows several commands to be entered on that Data
Pump Export job. To find a summary, use the STATUS command at the
prompt:
Export> status
Job: CASES_EXPORT
Operation:
EXPORT
Mode:
TABLE
State:
EXECUTING
Degree: 1
Job Error Count: 0
Dump file: /u02/dpdata1/expCASES.dmp
bytes written = 2048
Worker 1 Status:
State:
EXECUTING
Object Schema: DWOWNER
Object Name: CASES
Object Type: TABLE_EXPORT/TBL_TABLE_DATA/TABLE/TABLE_DATA
Completed Objects: 1
Total Objects: 1
Completed Rows: 4687818
Remember, this is merely the status display. The export is working
in the background. To continue to see the messages on the screen,
use the command CONTINUE_CLIENT from the Export prompt.
While Data Pump jobs are running, you can pause them by issuing
STOP_JOB on the Data Pump Export or Data Pump Import prompts and
then restart them with START_JOB.
This functionality comes in handy when you run out of space and
want to make corrections before continuing.
A simple way to gain insight into the status of a Data Pump job is
to look into a few views maintained within the Oracle instance the
Data Pump job is running.
These views are DBA_DATAPUMP_JOBS, DBA_DATAPUMP_SESSIONS, and
V$SESSION_LOGOPS and they are critical in the monitoring of your
export jobs so, you can attach to a Data Pump job and modify the
execution of the that job.
DBA_DATAPUMP_JOBS
This view will show the active Data Pump jobs, their state, degree
of parallelism, and the number of sessions attached.
select * from dba_datapump_jobs
OWNER_NAME JOB_NAME OPERATION JOB_MODE STATE DEGREE ATTACHED_SESSIONS
---------- ---------------------- ---------- ---------- ------------- --------- -----------------
JKOOP SYS_EXPORT_FULL_01 EXPORT FULL EXECUTING 1 1
JKOOP SYS_EXPORT_SCHEMA_01 EXPORT SCHEMA EXECUTING 1 1
DBA_DATAPUMP_SESSIONS
This view give gives the SADDR that assist in determining why a
Data Pump session may be having problems. Join to the V$SESSION
view for further information.
SELECT * FROM DBA_DATAPUMP_SESSIONS
OWNER_NAME JOB_NAME SADDR
---------- ------------------------------ --------
JKOOPMANN SYS_EXPORT_FULL_01 225BDEDC
JKOOPMANN SYS_EXPORT_SCHEMA_01 225B2B7C
V$SESSION_LONGOPS
This view helps determine how well a Data Pump export is doing. It
also shows you any operation that is taking long time to execute.
Basically gives you a progress indicator through the MESSAGE
column.
select username, opname, target_desc,
sofar, totalwork, message
from V$SESSION_LONGOPS
USERNAME OPNAME TARGET_DES SOFAR TOTALWORK MESSAGE
-------- -------------------- ---------- ----- ---------- ------------------------------------------------
JKOOP SYS_EXPORT_FULL_01 EXPORT 132 132 SYS_EXPORT_FULL_01:EXPORT:132 out of 132 MB done
JKOOP SYS_EXPORT_FULL_01 EXPORT 90 132 SYS_EXPORT_FULL_01:EXPORT:90 out of 132 MB done
JKOOP SYS_EXPORT_SCHEMA_01 EXPORT 17 17 SYS_EXPORT_SCHEMA_01:EXPORT:17 out of 17 MB done
JKOOP SYS_EXPORT_SCHEMA_01 EXPORT 19 19 SYS_EXPORT_SCHEMA_01:EXPORT:19 out of 19 MB done
set serveroutput on size 999999Let's examine each of these columns carefully. There may be more than one long running operation in the session—especially because the view contains the history of all long running operations in previous sessions. The column OPNAME shows that this record is for "Transaction Rollback," which points us in the right direction. The column TIME_REMAINING shows the estimated remaining time in seconds, described earlier and the column ELAPSED_SECONDS shows the time consumed so far. So how does this table offer an estimate of the remaining time? Clues can be found in the columns TOTALWORK, which shows the total amount of "work" to do, and SOFAR, which shows how much has been done so far. The unit of work is shown in column UNITS. In this case, it's in blocks; therefore, a total of 10,234 blocks have been rolled back so far, out of 20,554. The operation so far has taken 77 seconds. Hence the remaining blocks will take: 77 * ( 10234 / (20554-10234) ) ≈ 77 seconds But you don't have to take that route to get the number; it's shown clearly for you. Finally, the column LAST_UPDATE_TIME shows the time as of which the view contents are current, which will serve to reinforce your interpretation of the results.
exec print_table('select * from v$session_longops where sid = 9');
SID : 9
SERIAL# : 68
OPNAME : Transaction Rollback
TARGET :
TARGET_DESC : xid:0x000e.01c.00000067
SOFAR : 10234
TOTALWORK : 20554
UNITS : Blocks
START_TIME : 07-dec-2003 21:20:07
LAST_UPDATE_TIME : 07-dec-2003 21:21:24
TIME_REMAINING : 77
ELAPSED_SECONDS : 77
CONTEXT : 0
MESSAGE : Transaction Rollback: xid:0x000e.01c.00000067 :
10234 out of 20554 Blocks done
USERNAME : SYS
SQL_ADDRESS : 00000003B719ED08
SQL_HASH_VALUE : 1430203031
SQL_ID : 306w9c5amyanr
QCSID : 0