1)impdp/expdp example01
1@@@@oltp ==> filter ==> data warehouse
Advantage:
~restartablility, start_job and stop_job.
~attaching and detaching from a job.
~performing network_link between two database.
~mapping of datafile names after a period impdp and expdp.
~remapping of tablespaces during import.
~filtering the objects are exported and imported. INCLUDE, EXCLUDE
~filtering the data that is exported. QUERY WHERE
~estimate the space an export job.
~the ability to use multiple dump files.
~control the degree of parallelism. PARALLEL
guide:
In this case, we make db_link transport data between oltp and dataware db.
@@@
@@@<1>(oltp)create user and directory object.
@@@
[oracle@station78 ~]$ sqlplus / as sysdba;
SYS@ocp> ed
CREATE USER oltp IDENTIFIED BY oltp
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp
QUOTA UNLIMITED ON users
/
SYS@ocp> /
User created.
SYS@ocp> !mkdir -p /home/oracle/datafiles
SYS@ocp> !mkdir -p /home/oracle/logfiles
SYS@ocp> CREATE OR REPLACE DIRECTORY data_file_dir AS '/home/oracle/datafiles';
Directory created.
SYS@ocp> CREATE OR REPLACE DIRECTORY log_file_dir AS '/home/oracle/logfiles';
Directory created.
SYS@ocp> GRANT READ, WRITE ON DIRECTORY data_file_dir TO oltp;
Grant succeeded.
SYS@ocp> GRANT READ, WRITE ON DIRECTORY log_file_dir TO oltp;
Grant succeeded.
SYS@ocp> GRANT create session TO oltp;
Grant succeeded.
SYS@ocp> grant resource to oltp;
Grant succeeded.
SYS@ocp> select * from dba_directories where directory_path like '%/home/%';
OWNER DIRECTORY_NAME DIRECTORY_PATH
-------------------- ------------------------------ ------------------------------
SYS DATA_FILE_DIR /home/oracle/datafiles
SYS LOG_FILE_DIR /home/oracle/logfiles
@@@
@@@<2>(oltp)create table and user on oltp database.
@@@
SYS@ocp> ed
1 CREATE TABLE oltp.orders
2 (order_id varchar2(8) NOT NULL,
3 product_id varchar2(8) NOT NULL,
4 customer_id varchar2(10) NOT NULL,
5 purchase_date date NOT NULL,
6 purchase_time number(4,0) NOT NULL,
7 purchase_price number(6,2) NOT NULL,
8 shipping_charge number(5,2) NOT NULL,
9 today_special_offer varchar2(1) NOT NULL,
10 sales_person_id varchar2(10) NOT NULL,
11 payment_method varchar2(10) NOT NULL
12 )
13* TABLESPACE users
SYS@ocp> /
Table created.
SYS@ocp> insert into oltp.orders values('a','b','c',to_date('01-NOV-2004','dd-mon-yyyy'),1,2,3,'d','e','f');
1 row created.
SYS@ocp> insert into oltp.orders values('a','b','c',to_date('01-DEC-2004','dd-mon-yyyy'),1,2,3,'d','e','f');
1 row created.
SYS@ocp> insert into oltp.orders values('a','b','c',to_date('31-DEC-2004','dd-mon-yyyy'),1,2,3,'d','e','f');
1 row created.
SYS@ocp> insert into oltp.orders values('a','b','c',to_date('15-DEC-2004','dd-mon-yyyy'),1,2,3,'d','e','f');
1 row created.
SYS@ocp> insert into oltp.orders values('a','b','c',to_date('01-DEC-2005','dd-mon-yyyy'),1,2,3,'d','e','f');
1 row created.
SYS@ocp> commit;
Commit complete.
SYS@ocp> select purchase_date from oltp.orders;
PURCHASE_DATE
------------------
01-NOV-04
01-DEC-04
31-DEC-04
15-DEC-04
01-DEC-05
@@@
@@@<3>(oltp)write the parameter and expdp with it.
@@@
[oracle@station78 datafiles]$ pwd
/home/oracle/datafiles
[oracle@station78 datafiles]$ ls
expdp_par.txt
@@@
[oracle@station78 datafiles]$ cat expdp_par.txt
SCHEMAS=(OLTP)
INCLUDE=TABLE:"IN ('ORDERS')"
QUERY=OLTP.ORDERS:"WHERE purchase_date BETWEEN
to_date('01-dec-2004','dd-mon-yyyy') AND to_date('31-dec-2004','dd-mon-yyyy')"
DIRECTORY=data_file_dir
DUMPFILE=exp1.dmp
LOGFILE=log_file_dir:exporders2004.log
@@@Note:
@@@we could specified the partition like this:
@@@"TABLES=OLTP.ORDERS:DEC04" (DEC04 is the name of partition)
@@@
[oracle@station78 datafiles]$ expdp oltp/oltp@ocp parfile=expdp_par.txt
Export: Release 10.2.0.1.0 - 64bit Production on Thursday, 23 August, 2012 20:32:12
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
FLASHBACK automatically enabled to preserve database integrity.
Starting "OLTP"."SYS_EXPORT_SCHEMA_01": oltp/********@ocp parfile=expdp_par.txt
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type SCHEMA_EXPORT/TABLE/TABLE
. . exported "OLTP"."ORDERS" 7.953 KB 3 rows
Master table "OLTP"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for OLTP.SYS_EXPORT_SCHEMA_01 is:
/home/oracle/datafiles/exp1.dmp
Job "OLTP"."SYS_EXPORT_SCHEMA_01" successfully completed at 20:32:19
[oracle@station78 datafiles]$ ls
exp1.dmp expdp_par.txt
@@@
@@@<4>(data warehouse)login data warehouse database, create user dw, and tbs stage
@@@
SYS@orcl> create user dw identified by dw account unlock ;
User created.
SYS@orcl> grant connect to dw;
Grant succeeded.
SYS@orcl> grant resource to dw;
Grant succeeded.
SYS@orcl> create tablespace stage datafile '/u01/app/oracle/oradata/orcl/stage.dbf' size 10M;
Tablespace created.
@@@
@@@<5>(data warehouse)create directory object.
@@@
SYS@orcl> !mkdir -p /home/oracle/datafiles
SYS@orcl> !mkdir -p /home/oracle/logfiles
SYS@orcl> create directory datafile_dir as '/home/oracle/datafiles';
Directory created.
SYS@orcl> create directory logfile_dir as '/home/oracle/datafiles';
Directory created.
SYS@orcl> grant read,write on directory datafile_dir to dw;
Grant succeeded.
SYS@orcl> grant read,write on directory logfile_dir to dw;
Grant succeeded.
@@@
@@@<6>(data warehouse)copy all the dmp file to target dir.
@@@
[root@station78 datafiles]# scp exp1.dmp station243:/home/oracle/datafiles/
root@station243's password:
exp1.dmp 100% 140KB 140.0KB/s 00:00
[root@station78 datafiles]# ssh station243
root@station243's password:
Last login: Thu Aug 23 12:41:11 2012 from station78.example.com
[root@station243 ~]# cd /home/oracle
[root@station243 oracle]# cd datafiles/
[root@station243 datafiles]# chown oracle:oinstall exp1.dmp
@@@
@@@<7>(data warehouse)begin impdp data and inspect the result.
@@@
[oracle@station243 datafiles]$ impdp dw/dw@orcl DIRECTORY=datafile_dir \
> DUMPFILE=exp1.dmp LOGFILE=logfile_dir:imporders2004.log \
> REMAP_TABLESPACE=users:stage REMAP_SCHEMA=oltp:dw
Import: Release 10.2.0.1.0 - 64bit Production on Thursday, 23 August, 2012 13:14:13
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Master table "DW"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "DW"."SYS_IMPORT_FULL_01": dw/********@orcl DIRECTORY=datafile_dir
DUMPFILE=exp1.dmp LOGFILE=logfile_dir:imporders2004.log REMAP_TABLESPACE=users:stage REMAP_SCHEMA=oltp:dw
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "DW"."ORDERS" 7.953 KB 3 rows
Job "DW"."SYS_IMPORT_FULL_01" successfully completed at 13:14:17
@@@
@@@inspect the result.
@@@the data was filtered, and include the boundary value.
SYS@orcl> select purchase_date from dw.orders;
PURCHASE_DATE
------------------
01-DEC-04
31-DEC-04
15-DEC-04
SQL> select tablespace_name from dba_tables where table_name = 'ORDERS' and owner='DW';
TABLESPACE_NAME
--------------------------------------------------------------------------------
STAGE