1. 程式人生 > >Oracle 12c expdp&impdp

Oracle 12c expdp&impdp

OS

Windows

Oracle Version

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit
Production

Expdp

  1. 在c盤建立dump資料夾,允許寫
  2. 以sys使用者連線oracle,建立邏輯目錄,該命令不會在作業系統建立真正的目錄,最好以system等管理員建立。
    create directory dpdata1 as 'c:\dump';
  3. 檢視管理理員目錄(同時檢視作業系統是否存在,因為Oracle並不關心該目錄是否存在,如果不存在,則出錯,所以要有第1步)
    select * from dba_directories;
  4. 給vkc2使用者賦予在指定目錄的操作許可權,最好以system等管理員賦予。
    grant read,write on directory dpdata1 to vkc2;
  5. 執行命令(在cmd命令列裡)
按使用者匯出
expdp user/[email protected]*.***.***.***/xe dumpfile=full_20180
702.dmp  DIRECTORY=dpdata1 schemas=test
匯出整個資料庫
expdp '/ as sysdba' DIRECTORY=dpdata1 DUMPFILE=full_20180
702.dmp FULL
=y PARALLEL=3 LOGFILE=export_20180702.log

Impdp

在sql developer裡面,以sys身份連線 建立表空間
create tablespace tabspace
logging datafile 'datafilepath_C:\ORACLEXE\APP\ORACLE\ORADATA\XE\tabspace.DBF' 
size 50m autoextend on next 50m maxsize 10768m extent management local;
建立新的使用者
Alter session set “_oracle_script“=true
;
DROP USER testuser CASCADE; CREATE USER testuser identified by testuser default tablespace tabspace temporary tablespace TEMP; GRANT CONNECT,RESOURCE,UNLIMITED TABLESPACE TO testuser; create directory dpdata1 as 'c:\dump'; grant read,write on directory dpdata1 to testuser;
把dmp檔案拷貝到 C:\dump,執行cmd
impdp testuser/testuser DIRECTORY=dpdata1 
DUMPFILE=full_20180702.dmp FULL=y 

Note

  1. 官網原文:Data Pump Export
  2. 表空間查詢(sqlplus / as sysdba)
    表空間使用情況
SELECT UPPER(F.TABLESPACE_NAME) "表空間名",D.TOT_GROOTTE_MB "表空間大小(M)",
    D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空間(M)",
    TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES)/D.TOT_GROOTTE_MB * 100,2),'990.99')"使用比",
    F.TOTAL_BYTES "空閒空間(M)",F.MAX_BYTES "最大塊(M)"
  FROM (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,
               ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES
        FROM SYS.DBA_FREE_SPACE
        GROUP BY TABLESPACE_NAME
       ) F,
      (SELECT DD.TABLESPACE_NAME,ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB
       FROM SYS.DBA_DATA_FILES DD
       GROUP BY DD.TABLESPACE_NAME
      ) D
  WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
  ORDER BY 4 DESC;

表空間是否具有自動擴充套件的能力

SELECT T.TABLESPACE_NAME,D.FILE_NAME,D.AUTOEXTENSIBLE,ROUND(D.BYTES / (1024 * 1024), 2) BYTES_MB,ROUND(D.MAXBYTES/ (1024 * 1024), 2) MAXBYTES_MB,D.STATUS  
FROM DBA_TABLESPACES T,DBA_DATA_FILES D
WHERE T.TABLESPACE_NAME =D.TABLESPACE_NAME
ORDER BY TABLESPACE_NAME,FILE_NAME;

操作表空間檔案

   alter tablespace system add datafile 'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSTEM.DBF' resize 1024M;
   alter database datafile 'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSTEM.DBF' autoextend on;  
   alter database datafile 'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSTEM.DBF' resize 1024M;

清理多餘表空間

SELECT T.TABLESPACE_NAME,D.FILE_NAME,D.AUTOEXTENSIBLE,ROUND(D.BYTES / (1024 * 1024), 2) BYTES_MB,ROUND(D.MAXBYTES/ (1024 * 1024), 2) MAXBYTES_MB,D.STATUS  
FROM DBA_TABLESPACES T,DBA_DATA_FILES D
WHERE T.TABLESPACE_NAME =D.TABLESPACE_NAME
ORDER BY TABLESPACE_NAME,FILE_NAME;

DROP TABLESPACE test INCLUDING CONTENTS AND DATAFILES;

create tablespace test
logging 
datafile 'C:\APP\ROOT\ORADATA\XE\test.DBF' 
size 50m 
autoextend on 
next 50m maxsize 10768m 
extent management local;