oracle數據泵、表空間、庫導入導出

2014-04-28sql

1.查找文件shell

[oracle@oracle53 ~]$ which expdp         oracle

/u01/app/oracle/11.2.0/db_1/bin/expdpapp

[oracle@oracle53 ~]$ locate expdpspa

/u01/app/oracle/11.2.0/db_1/bin/expdp日誌

/u01/app/oracle/11.2.0/db_1/bin/expdpO對象

[oracle@oracle53 ~]$ whereis expdpit

2.數據泵導出io

##hr用戶table

shell>expdp hr/hr directory=DATA_PUMP_DIR dumpfile=cc.cc tables=hr.jobs

ORA-39087: directory name DATA_PUMP_DIR is invalid

##系統用戶

shell>expdp system/322815 directory=DATA_PUMP_DIR dumpfile=cc.cc tables=hr.jobs

**********************************************************************

Dump file set for SYSTEM.SYS_EXPORT_TABLE_01 is:

  /u01/app/oracle/admin/orcl/dpdump/cc.cc

Job "SYSTEM"."SYS_EXPORT_TABLE_01" successfully completed at 09:09:02

##也能夠不指定目錄

shell>expdp system/322815  dumpfile=cc.cc tables=hr.jobs

##基於scott用戶

shell>expdp scott/tiger directory=DATA_PUMP_DIR dumpfile=scott.dmp schemas=scott

3.建立目錄對象 --須要先建立/u01/expdp目錄 

SQL> create directory exp_home as '/u01/expdp';

SQL> grant read,write on directory exp_home to scott;

SQL>select  * from DBA_DIRECTORIES;

4.全庫導出和導入  --須要EXP_FULL_DTABASE,IMP_FULL_DTABASE角色

導出:expdp scott/tiger directory=exp_dir full=y dumpfile=full_db.dmp 

導入:impdp scott/tiger directory=exp_dir full=y dumpfile=full_db.dmp

5.表空間的導出和導入

導出:expdp scott/tiger directory=exp_home dumpfile=tbs_01.dmp tablespaces=tbs_01;

//若是刪除表空間後恢復表空間數據,須要先建立表空間再恢復表空間數據

SQL> drop tablespace tbs_01 including contents; --不會物理刪除磁盤上的datafile

##查看datafile並刪除

shell>cd /u01/app/oracle/oradata/orcl/

shell>rm tbs_01.dbf 

##導入

[oracle@ora243 expdp]$ impdp scott/tiger directory=exp_home dumpfile=tbs_01.dmp tablespaces=tbs_01

錯誤顯示:ORA-00959: tablespace 'TBS_01' does not exist

##建立表空間

SQL>create tablespace tbs_01 datafile '/u01/app/oracle/oradata/orcl/tbs_01.dbf' size 100m;

##導入

impdp scott/tiger directory=data_pump_dir dumpfile=tbs_01.dmp tablespaces=tbs_01

6.schema的導入和導出

$ expdp scott/tiger directory=exp_home dumpfile=hr.dmp schemas=hr

$ impdp scott/tiger directory=exp_home dumpfile=hr.dmp schemas=hr

7.表的導入和導出

expdp scott/tiger directory=exp_home dumpfile=tble_emp.dmp tables=scott.emp reuse_dumpfiles=y

impdp scott/tiger directory=exp_home dumpfile=tble_emp.dmp tables=emp

8.數據泵導出參數

reuse_dumpfiles:默認不覆蓋轉儲文件,覆蓋用resue_dumpfiles=y

compression:指定壓縮那些數據,在導出數據寫入轉儲文件前.data_only只壓縮全部數據,metadata_only,只壓縮全部元數據(表結構)

//擴展

##查看角色權限

SQL>select * from role_sys_privs where role='EXP_FULL_DTABASE';

SQL>select * from role_sys_privs where role='CONNECT'

ROLE       PRIVILEGE ADM

------------------------------ ---------------------------------------- ---

CONNECT       CREATE SESSION NO

metalink:oracle內部的付費帳號

9.導出hr.employees用戶中JOB_ID=IT_PROG,薪水大於8000的僱員信息  --加query參數

shell>expdp hr/hr directory=data_pump_file dumpfile=emp.dmp tables=hr.employees query=hr.employees:"where job_id='IT_PROG' and salary>8000"

出錯信息:

LRM-00101: unknown parameter name 'job_id'

正解:

expdp scott/tiger directory=data_pump_dir dumpfile=emp.dmp tables=hr.employees query=hr.employees:\"where JOB_ID\=\'IT_PROG\' and SALARY\>8000\"

10.SCN系統更改號

數據泵:精確到行記錄,只能還原到備份的狀態

rman:最小粒度爲文件,和歸檔日誌結合,能夠還原到任什麼時候間點.

##查看當前SCN

sql>select current_scn from v$database;

CURRENT_SCN

-----------

    2280109

##插入數據

sql>insert into dept values(22,'ha','luoyang');

##查看更改過的SCN

sql>select current_scn from v$database;

CURRENT_SCN

-----------

    2280147

相關文章
相關標籤/搜索