標籤:12c impdp expdp
12c推出了可插拔資料庫,在一個容器cdb中以多租戶的形式同時存在多個資料庫pdb。在為pdb做資料泵匯入匯出時和傳統的資料庫有少許不同。
1,需要為pdb添加tansnames
2,匯入匯出時需要在userid參數內指定其tansnames的值,比如 userid=user/[email protected]
資料泵匯出
1、查看當前的SID,查看pdb並切換到容器資料庫,這裡的pluggable資料庫是pdborcl
[[email protected] admin]$ echo $ORACLE_SID[[email protected] admin]orcl
登入cdb,查看pdb,
SQL> show con_nameCON_NAME------------------------------CDB$ROOTSQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ----------PDB$SEED READ ONLY NOPDBORCL MOUNTEDSQL> alter pluggable database all open;Pluggable database altered.SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ----------PDB$SEED READ ONLY NOPDBORCL READ WRITE NO
切換到pdborcl
SQL> alter session set container=pdborcl;Session altered.SQL>
2、查看樣本使用者scott,以後的schema層級匯入匯出就使用該使用者的資料。
SQL> select owner, table_name from dba_tables where owner='SCOTT';OWNER TABLE_NAME------------------------------ ----------------------------------------SCOTT SALGRADESCOTT BONUSSCOTT EMPSCOTT DEPT
3、單獨建立一個dba許可權的資料泵使用者
SQL> grant dba to dp identified by dp;Grant succeeded.
4、建立一個資料泵目錄dp_dir,路徑為oracle家目錄
SQL> create or replace directory dp_dir as '/home/oracle';Directory created.SQL> exit
5、授予dp使用者在資料泵路徑有讀寫權限
(如果是dba許可權的這一步可以省略,為了實驗的完整性這裡保留)
SQL> grant read,write on directory dp_dir to dp;Grant succeeded.
6、設定tnsnames.ora,增加pdborocl。SERVICE_NAME為pdb的執行個體名,這裡為pdborcl
[[email protected] admin]$ pwd/data/app/oracle/product/12.1.0/dbhome_1/network/admin[[email protected] admin]$ cat tnsnames.ora # tnsnames.ora Network Configuration File: /data/app/oracle/product/12.1.0/dbhome_1/network/admin/tnsnames.ora# Generated by Oracle configuration tools.ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xqzt)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) )PDBORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xqzt)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME =pdborcl) ) )
7、測試tnsnames.ora的有效性,如果返回OK (0 msec)表示配置成功
[[email protected] admin]$ tnsping pdborclTNS Ping Utility for Linux: Version 12.1.0.2.0 - Production on 10-DEC-2015 09:10:34Copyright (c) 1997, 2014, Oracle. All rights reserved.Used parameter files:/data/app/oracle/product/12.1.0/dbhome_1/network/admin/sqlnet.oraUsed TNSNAMES adapter to resolve the aliasAttempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xqzt)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME =pdborcl)))OK (0 msec)
8、資料泵匯出
使用者名稱密碼為dp/dp,並且通過tnsnames指向pdborcl
資料泵目錄為:dp_dir, OS路徑是/home/oracle
匯出檔案為:/home/oracle/scott_pdborcl.dmp
匯出日誌為:/home/oracle/scott_pdborcl.log
匯出模式為scheme,也可以理解為使用者:scott
[[email protected] ~]$ expdp dp/[email protected] directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl.log schemas=scottExport: Release 12.1.0.2.0 - Production on Thu Dec 10 09:32:05 2015Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit ProductionWith the Partitioning, OLAP, Advanced Analytics and Real Application Testing optionsStarting "DP"."SYS_EXPORT_SCHEMA_01": dp/********@pdborcl directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl.log schemas=scott Estimate in progress using BLOCKS method...Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATATotal estimation using BLOCKS method: 192 KBProcessing object type SCHEMA_EXPORT/USERProcessing object type SCHEMA_EXPORT/SYSTEM_GRANTProcessing object type SCHEMA_EXPORT/ROLE_GRANTProcessing object type SCHEMA_EXPORT/DEFAULT_ROLEProcessing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMAProcessing object type SCHEMA_EXPORT/TABLE/TABLEProcessing object type SCHEMA_EXPORT/TABLE/INDEX/INDEXProcessing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINTProcessing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICSProcessing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINTProcessing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICSProcessing object type SCHEMA_EXPORT/STATISTICS/MARKER. . exported "SCOTT"."DEPT" 6.023 KB 4 rows. . exported "SCOTT"."EMP" 8.773 KB 14 rows. . exported "SCOTT"."SALGRADE" 6.023 KB 10 rows. . exported "SCOTT"."BONUS" 0 KB 0 rowsMaster table "DP"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded******************************************************************************Dump file set for DP.SYS_EXPORT_SCHEMA_01 is: /home/oracle/scott_pdborcl.dmpJob "DP"."SYS_EXPORT_SCHEMA_01" successfully completed at Thu Dec 10 09:32:29 2015 elapsed 0 00:00:21[[email protected] ~]$
10、查看匯出檔案
[[email protected] ~]$ ls -l scott_pdborcl.dmp scott_pdborcl.log-rw-r----- 1 oracle oinstall 356352 12月 10 09:32 scott_pdborcl.dmp-rw-r--r-- 1 oracle oinstall 1960 12月 10 09:32 scott_pdborcl.log
11、為了測試匯出檔案是否能夠正常匯入,我們先刪除pdborcl的scott使用者
SQL> select count(*) from scott.DEPT; COUNT(*)----------SQL> drop user scott cascade ;User dropped.SQL>
此時訪問該使用者的表已經不存在了
SQL> select count(*) from scott.DEPT;select count(*) from scott.DEPT *ERROR at line 1:ORA-00942: table or view does not exist
12、 匯入scott使用者
[[email protected] ~]$ impdp dp/[email protected] directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl_imp.log schemas=scottImport: Release 12.1.0.2.0 - Production on Thu Dec 10 09:39:02 2015Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit ProductionWith the Partitioning, OLAP, Advanced Analytics and Real Application Testing optionsMaster table "DP"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloadedStarting "DP"."SYS_IMPORT_SCHEMA_01": dp/********@pdborcl directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl_imp.log schemas=scott Processing object type SCHEMA_EXPORT/USERProcessing object type SCHEMA_EXPORT/SYSTEM_GRANTProcessing object type SCHEMA_EXPORT/ROLE_GRANTProcessing object type SCHEMA_EXPORT/DEFAULT_ROLEProcessing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMAProcessing object type SCHEMA_EXPORT/TABLE/TABLEProcessing object type SCHEMA_EXPORT/TABLE/TABLE_DATA. . imported "SCOTT"."DEPT" 6.023 KB 4 rows. . imported "SCOTT"."EMP" 8.773 KB 14 rows. . imported "SCOTT"."SALGRADE" 6.023 KB 10 rows. . imported "SCOTT"."BONUS" 0 KB 0 rowsProcessing object type SCHEMA_EXPORT/TABLE/INDEX/INDEXProcessing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINTProcessing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICSProcessing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINTProcessing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICSProcessing object type SCHEMA_EXPORT/STATISTICS/MARKERJob "DP"."SYS_IMPORT_SCHEMA_01" successfully completed at Thu Dec 10 09:39:06 2015 elapsed 0 00:00:04[[email protected] ~]$
13、 測試匯入結果
SQL> select count(*) from scott.DEPT; COUNT(*)---------- 4
匯入成功!
Oracle 12c pdb使用expdp/impdp匯入匯出