1. 程式人生 > 實用技巧 >使用資料泵(expdp、impdp)遷移資料庫流程

使用資料泵(expdp、impdp)遷移資料庫流程

轉載原文地址為:http://blog.itpub.net/26736162/viewspace-2652256/

使用資料泵遷移資料庫流程

How To Move Or Copy A Database Using DataPump (檔案 ID 855268.1)

In this Document

Oracle Database Cloud Schema Service - Version N/A and later


APPLIES TO:

Oracle Database Exadata Express Cloud Service - Version N/A and later
Oracle Database Exadata Cloud Machine - Version N/A and later

Oracle Cloud Infrastructure - Database Service - Version N/A and later
Oracle Database Backup Service - Version N/A and later
Information in this document applies to any platform.
***Checked for relevance on 26-Jan-2018***

GOAL

This note explains how to use data pump to copy or move a database.

SOLUTION

The following steps provide a general overview of how to move a database between platforms.

1. On source database query the views dba_tablespaces, dba_data_files. You will need this information later in the process. An easy method to get the ddl for tablespace creation that you can modify for the target directory structure is to use the dbms_metadata.get_ddl procedure.

set long 1000000
select dbms_metadata.get_ddl('TABLESPACE',tablespace_name) from dba_tablespaces;

2. Perform a full export from the source database:

#> expdp FULL=Y DUMPFILE=full%U.dmp PARALLEL=4 LOGFILE=<LOG_NAME> EXCLUDE=SCHEMA:"in ('SYSMAN')"

SeeNote 365459.1Parallel Capabilities of Oracle Data Pump for discussion on using parallelism with data pump.

If you use dbcontrol on source, recommend excluding that schema from export with EXCLUDE=SCHEMA:"in ('SYSMAN')" . This schema and objects can be created when installing dbcontrol.

Invalid Sysman Objects After Upgrading The Db Via Export/ImportNote 604129.1.
Drop the DB Control configuration and repository then recreate usingNote 278100.1.

3. Transfer the export dumpfile in binary mode to the target server.

4. Create a new database on the target server.

You can use the note below to make sure you have desired database features and options installed.

Note 286775.1How to Perform a Full Database Export Import during Upgrade, Migrate, Copy, or Move of a Database

5. Before importing the dump file, you must first create the user tablespaces, using the information obtained in step 1. Otherwise, the import will try to create the corresponding datafiles in the same file structure as at the source database, which may not be compatible with the file structure on the target system. As an alternative to precreating the tablespaces, you can use the data pump parameter REMAP_DATAFILE to instruct data pump to create the datafile to new directory structure.

REMAP_DATAFILE=source_datafile:target_datafile

The source datafile directory structure can be determined from step 1output using dbms_metadata.get_ddl

If the source database is not available to extract tablespace DDL you can pull the DDL from the export dump file.

Run a full import with additional data pump parameter SQLFILE=yourname.txt. This will not import, but just write DDL for all objects to that file name.

You can pull the tablespace ddl from this file and edit to desired directory path. Then, run ddl to create the user tablespaces prior to import.

6. Perform a full import

#> impdp FULL=Y DUMPFILE=full%U.dmp PARALLEL=4 LOGFILE=<LOG_NAME>

Note that if the database is an Oracle Applications installation, then specific instructions must be followed as per the applicable notes:

Note 362205.110g Release 2 Export/Import Process for Oracle Applications Release 11i
Note 454616.1Export/Import Process for Oracle E-Business Suite Release 12 using 10gR2
Note 557738.1Export/import notes on Applications 11i Database 11g

A note concerning use of data pump PARALLEL parameter.

On 10.2 data pump may use other nodes for px processes. This cannot be controlled, unless you either shutdown other nodes during export or do not use parallel. This means all db nodes need access to the data pump directory location for the dumpfiles otherwise the px processes will give errors and cause export to fail.

The same is true on 11.2 only more so. Not only can px processes be used on other nodes, but the data pump worker processes as well could be run on other nodes. Again, this requires all db nodes need access to the data pump directory location for the dumpfiles. On 11.2 you can control where parallel would be used if other nodes do not have access to the directory location. Simplest method is use data pump parameter CLUSTER=N. This forces all worker process and px process to be run on the instance where the job was started. A more complex method would be to specify which services would be available for the data pump using data pump parameter SERVICE_NAME. Specify only services that have access to the directory locations.

To improve the time for export and import you can also exclude statistics from being exported with data pump parameter EXCLUDE=STATISTICS. Statistics can then be gathered on the target system. See Note:749227.1 Master Note: Recommendations for Gathering Optimizer Statistics on 11g. When moving to a new database version, new optimizer statistics should be gathered, and data pump parameter EXCLUDE=STATISTICS should be used.

Regarding Character set change

If you will be changing character sets between source and target database, recommend using the csscan tool to determine if there will be any issues with character conversion. This is especially true when moving from a single byte character set to multibyte character set or moving from WE8MSWIN1252 or US7ASCII character sets.

In order to identify any potential issues, run the csscan utility on the source db to list columns that will a problem.

See the Oracle doc Oracle® Database Globalization Support Guide and these notes for information regarding the character set scanner.

Note 227338.1Character Set Scanner - Frequently Asked Questions
Note 458122.1Installing and configuring CSSCAN in 8i and 9i
Note 745809.1Installing and configuring CSSCAN in 10g and 11g
Note 444701.1Csscan output explained

Basically you will want to run the csscan as follows on the source db.

#> CSSCAN <username>/<password> FULL=y FROMCHAR= TOCHAR= ARRAY=10240 PROCESS=4

where the FROMCHAR will be the source db character set and TOCHAR the target db character set.

Ideally, you want all user application data to be changeless or convertible.

在升級/遷移/複製/行動資料庫的時候如何執行全庫匯出匯入 (檔案 ID 2227040.1)

適用於:

Oracle Cloud Infrastructure - Database Service - 版本 N/A 和更高版本
Oracle Database Cloud Exadata Service - 版本 N/A 和更高版本
Oracle Database Backup Service - 版本 N/A 和更高版本
Oracle Database Cloud Service - 版本 N/A 和更高版本
Oracle Database - Personal Edition - 版本 8.1.7.0 到 18.3.0.0.0 [發行版 8.1.7 到 18]
本檔案所含資訊適用於所有平臺

用途

本文描述了怎樣在源庫執行全庫匯出以及如何將匯出的 dump 檔案匯入到目標庫。

適用範圍

本文為那些想用 DataPump 或者 EXPORT/IMPORT 工具來執行在 oracle 版本 X 上做全庫匯出,並且將資料全庫匯入到另外一個 oracle 版本 Y 的 Oracle7, Oracle8, Oracle8i, Oracle9i, Oracle10g, Oracle11g 和 Oracle12c 的 DBA 而寫。

本文提供的步驟不適用於 EBS 資料庫。對於 Oracle E-Business Suite 資料庫,有獨立的方法,參考如下檔案:

Oracle EBS 11i:
Note 230627.1- 9i Export/Import Process for Oracle Applications Release 11i
Note 331221.1- 10g Export/Import Process for Oracle Applications Release 11i
Note 362205.1- 10g Release 2 Export/Import Process for Oracle Applications Release 11i
Note 557738.1- Export/import notes on Applications 11i Database 11g
Note 1585257.1- Export/Import Process for EBS 11i on RDBMS 12c

Oracle EBS 12.0 以及 12.1:
Note 454616.1- Export/Import Process for Oracle E-Business Suite Release 12 using 10gR2
Note 741818.1- Export/import process for 12.0 or 12.1 using 11gR1 or 11gR2

Oracle EBS 12.2:
Note 1613716.1- Export/Import Process for Oracle E-Business Suite Release 12.2 Database Instances Using Oracle Database 11.2 (Doc ID 1613716.1)

本文提供的步驟也不適用於 export 和 import 其他某些特殊的 schema,因為它們也有自己特有的方法。參考如下檔案:
Note 1439066.1- Exporting/Importing in Oracle Portal 11g
Note 1359656.1- OIM 11gR1: Schema Backup and Restoration using Data Pump Client Utility

詳細資訊

簡介

對於如何升級資料庫,參考如下聯機手冊:
-Oracle Database Upgrade Guide, 10g Release 2 (10.2)
-Oracle Database Upgrade Guide, 11g Release 1 (11.1)
-Oracle Database Upgrade Guide, 11g Release 2 (11.2)
-Oracle Database Upgrade Guide, 12c Release 1 (12.1)

關於 Oracle export 和 import 工具如何用於跨平臺和跨 32-bit/64-bit 伺服器轉換資料,schame,tablespace,database 的資訊,參考:
Note 277650.1- How to Use Export and Import when Transferring Data Across Platforms or Across 32-bit and 64-bit Servers

當遷移或者升級資料庫的時候,請確保您已經參閱了本文底部的參考檔案。

重要提醒!
在您對生產/開發資料庫做全庫 export/import 之前:
- 對全部步驟至少做一次完整的測試,並且:
- 研究 export/import 過程中丟擲的任何錯誤,修正您的步驟來消除這些錯誤,並且:
- 瞭解為什麼還有其他錯誤和警告資訊報出來並且知道還需要哪些額外的操作來解決它們
如果需要測試,建議採用最近克隆的源生產庫。

第1部分 – 準備目標資料庫

1.1. 如果在目標主機上已經安裝了其他 oracle 資料庫,對這些資料庫發起一次 clean shutdown(SHUTDOWN IMMEDIATE),然後對所有這些資料庫建立一個全庫備份。這樣可以確保您在全庫匯入時遇到任何錯誤(比如匯入的時候搞錯了ORACLE_SID),都能從這個備份中恢復資料庫。

1.2. 在目標主機上,安裝 oracle 軟體。確保源主機和目標主機具有相同的 Edition,比如: 如果您的源主機上的是 Oracle RDBMS Enterprise Edition,那麼在目標主機上也應當安裝 Enterprise Edition。
如果您的源主機安裝的是 Oracle RDBMS Standard Edition,那麼目標主機安裝 Standard 或者 Enterprise Edition 都可以。

CONNECT / as sysdba

SELECT * FROM v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for 64-bit Windows: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production

關於各 edition 之間的詳細差異,參考:
Note 112591.1- Differences Between Enterprise, Standard and Personal Editions on Oracle 8.1
Note 269040.1- Differences Between Enterprise, Standard and Personal Editions on Oracle 9.2
Note 271886.1- Differences Between Different Editions of Oracle Database 10G Release 1
Note 465465.1- Differences Between Enterprise, Standard and Personal Editions on Oracle 10.2
Note 1084132.1- Differences Between Enterprise, Standard and Standard One Editions on Oracle 11.2
Note 1628809.1- Differences Between Enterprise, Standard and Standard One Editions on Oracle 12.1

如果您的源庫是 Oracle RDBMS Enterprise Edition 而目標庫是 Standard Edition,那麼某些在 Enterprise Edition 包含而在 Standard Edition 不包含的特性會在 import 的時候丟擲一些錯誤,這是正常行為,比如以下檔案:
Note 1087325.1- Error ORA-439 When Importing Tables Created With Enabled Deferred Segment Into Oracle 11g Standard Edition

1.3. 在作全庫 import 之前,為了消除一些已知而且已經有修復的問題,推薦對 $ORACLE_HOME 打上最新的 patchset,關於最新的 Oracle Server release 的清單,參考:
Note 161818.1- Oracle Server (RDBMS) Releases Support Status Summary
Note 756671.1- Oracle Recommended Patches -- Oracle Database
Note 454507.1- ALERT: Oracle 11g Release 1 (11.1) Support Status and Alerts
Note 880782.1- ALERT: Oracle 11g Release 2 (11.2) Support Status and Alerts
Note 1565065.1- ALERT: Oracle 12c Release 1 (12.1) Support Status and Alerts

第二部分 - 準備源資料庫

2.1. 在作全庫 export 之前,為了消除一些已知而且已經有修復的問題,推薦對 $ORACLE_HOME 打上最新的 patchset,關於最新的 Oracle Server release 的清單,參考:
Note 161818.1- Oracle Server (RDBMS) Releases Support Status Summary
Note 756671.1- Oracle Recommended Patches -- Oracle Database
Note 189908.1- ALERT: Oracle9i Release 2 (9.2) Support Status and Alerts
Note 263719.1- ALERT: Oracle 10g Release 1 (10.1) Support Status and Alerts
Note 316900.1- ALERT: Oracle 10g Release 2 (10.2) Support Status and Alerts
Note 454507.1- ALERT: Oracle 11g Release 1 (11.1) Support Status and Alerts
Note 880782.1- ALERT: Oracle 11g Release 2 (11.2) Support Status and Alerts
Note 1565065.1- ALERT: Oracle 12c Release 1 (12.1) Support Status and Alerts

2.2. 對於全庫 export/import 來說,我們不會重建目標庫的資料字典物件,目標庫的資料字典是在目標庫建立的時候產生的,並且在 import 的時候已經存在了。這樣的情況同樣適用於其他 component 和 schema 的資料字典。在源庫上,檢查哪些 component 安裝了。為了找出哪些 component 在使用,可能的方法有:

  1. 採用如下的查詢(針對 Oracle9i 9.2.0. 和以上版本):

    CONNECT / as sysdba

    SET lines 90 NUMWIDTH 12 PAGES 10000 LONG 2000000000
    ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';
    COL versionFORMAT a12
    COL comp_idFORMAT a8
    COL schema LIKE version
    COL comp_nameFORMAT a35
    COL status FORMAT a12

    SELECT comp_id,schema,status,version,comp_name
    FROM dba_registry
    ORDER BY 1;

    COMP_ID SCHEMA STATUS VERSION COMP_NAME
    -------- ------------ ------------ ------------ -----------------------------------
    AMD OLAPSYS VALID 11.2.0.4.0 OLAP Catalog
    APEX APEX_030200 VALID 3.2.1.00.12 Oracle Application Express
    APS SYS VALID 11.2.0.4.0 OLAP Analytic Workspace
    CATALOG SYS VALID 11.2.0.4.0 Oracle Database Catalog Views
    CATJAVA SYS VALID 11.2.0.4.0 Oracle Database Java Packages
    CATPROC SYS VALID 11.2.0.4.0 Oracle Database Packages and Types
    CONTEXT CTXSYS VALID 11.2.0.4.0 Oracle Text
    EM SYSMAN VALID 11.2.0.4.0 Oracle Enterprise Manager
    EXF EXFSYS VALID 11.2.0.4.0 Oracle Expression Filter
    JAVAVM SYS VALID 11.2.0.4.0 JServer JAVA Virtual Machine
    ORDIM ORDSYS VALID 11.2.0.4.0 Oracle Multimedia
    OWB OWBSYS VALID 11.2.0.4.0 OWB
    OWM WMSYS VALID 11.2.0.4.0 Oracle Workspace Manager
    RUL EXFSYS VALID 11.2.0.4.0 Oracle Rules Manager
    SDO MDSYS VALID 11.2.0.4.0 Spatial
    XDB XDB VALID 11.2.0.4.0 Oracle XML Database
    XML SYS VALID 11.2.0.4.0 Oracle XDK
    XOQ SYS VALID 11.2.0.4.0 Oracle OLAP API

  2. 採用 Database Configuration Assistant(選擇 modify database)
  3. 查詢 DBA_OBJECTS: CONNECT / as sysdba

    SET lines 80 NUMWIDTH 12 PAGES 10000 LONG 2000000000
    ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';
    COL versionFORMAT a12
    COL comp_idFORMAT a8
    COL schema LIKE version
    COL comp_nameFORMAT a35
    COL status FORMAT a12

    COL owner FORMAT a25
    SELECT owner, count(*)
    FROM dba_objects
    WHERE owner IN ('CTXSYS', 'OLAPSYS', 'MDSYS', 'DMSYS', 'WKSYS', 'LBACSYS',
    'ORDSYS', 'XDB', 'EXFSYS', 'OWBSYS', 'WMSYS', 'SYSMAN')
    OR owner LIKE 'APEX%'
    GROUP BY owner
    ORDER BY 1;

    OWNER COUNT(*)
    ------------------------- ------------
    APEX_030200 2561
    CTXSYS 389
    EXFSYS 312
    MDSYS 2011
    OLAPSYS 721
    ORDSYS 2513
    OWBSYS 2
    SYSMAN 3554
    WMSYS 333
    XDB 1170

    SELECT owner, object_type, COUNT(*)
    FROM dba_objects
    WHERE object_type LIKE 'JAVA%'
    GROUP BY owner, object_type
    ORDER BY 1,2;

    OWNER OBJECT_TYPE COUNT(*)
    ------------------------- ------------------- ------------
    EXFSYS JAVA CLASS 47
    EXFSYS JAVA RESOURCE 1
    MDSYS JAVA CLASS 544
    MDSYS JAVA RESOURCE 3
    ORDSYS JAVA CLASS 1877
    ORDSYS JAVA RESOURCE 72
    SYS JAVA CLASS 26500
    SYS JAVA DATA 323
    SYS JAVA RESOURCE 864
    SYS JAVA SOURCE 2

其他可能的資料字典物件:

- Oracle OLAP - schema: OLAPSYS
- Oracle Data Mining - schema: DMSYS
- Oracle Ultra Search - schema: WKSYS
- Oracle Label Security - schema: LBACSYS
- Oracle Warehouse Builder - schema: OWBSYS

對於不同資料庫的 component 和 schema 的詳情,也可以參考:
Note 472937.1- Information On Installed Database Components and Schemas

2.3. 在源庫上檢查資料庫的字符集:

CONNECT / as sysdba

SET lines 80 NUMWIDTH 12 PAGES 10000 LONG 2000000000
ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';
COL value FORMAT a15
SELECT * FROM nls_database_parameters
WHERE parameter LIKE '%SET'
ORDER BY 1;

PARAMETER VALUE
------------------------------ ---------------
NLS_CHARACTERSET WE8MSWIN1252
NLS_NCHAR_CHARACTERSET AL16UTF16

2.4. 在源庫上,建立一個 spool out 的檔案來檢查 redo logfile 的詳情:

CONNECT / as sysdba

SET lines 140 NUMWIDTH 12 PAGES 10000 LONG 2000000000
ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';
COL member FORMAT a100

SPOOL redo.out

SELECT group#,bytes,blocksize,members,status
FROM v$log
ORDER BY 1;

SELECT * FROM v$logfile
ORDER BY 1,3;

SPOOL off

2.5. 在源庫上,建立一個包含 tablespace/datafile 的清單,和 tablespace 的 DDL 的 spool out 的檔案,比如:

CONNECT / as sysdba

SET lines 170 NUMWIDTH 12 PAGES 10000 LONG 2000000000
ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';
COL file_name FORMAT a100

SPOOL tbsp.out

SELECT tablespace_name, bytes, status, online_status, file_name
FROM dba_data_files
ORDER BY 1,5;

SET lines 100
COL ddlFORMAT a100
SELECT dbms_metadata.get_ddl('TABLESPACE','USERS') "DDL" FROM dual;

-- do this for all tablespaces

SPOOL off

2.6. 在源庫上,檢查哪些使用者可以通過 as sysdba 的方式連線:

CONNECT / as sysdba

SET lines 80 NUMWIDTH 12 PAGES 10000 LONG 2000000000
ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';
COL file_name FORMAT a100

SELECT * FROM v$pwfile_users;

USERNAME SYSDB SYSOP SYSAS
------------------------------ ----- ----- -----
SYS TRUE TRUE FALSE

2.7. 在源庫的 $ORACLE_HOME/network/admin 下開啟 TNSNAMES.ORA 檔案,記錄(或者複製)那些用於源庫本地訪問或者用於源庫連線到遠端資料庫 db-link 的 TNS 記錄。

2.8. 如果是 Database Vault 環境,將必要的許可權授予給實施匯出的使用者,詳情參考:
Note 822048.1- How To Export / Import Objects In Database Vault Environment

2.9. 如果資料庫安裝了 Enterprise Manager (EM) 元件(schema SYSMAN - 參見本文上面的步驟 2.2),那麼還需要額外的步驟。詳情參考:
Note 1302281.1- 11g Grid Control: Steps for Migrating the 11g Grid Control Repository from One Database to Another

第三部分 - 建立目標資料庫

3.1. 在目標主機,決定目標庫的字符集。如果資料庫字符集不需要改變,那麼採用與源庫相同的字符集。參考本文的2.3步驟和如下檔案:
Note 77441.1- Steps to Create a New Database With a Character Set Other Than US7ASCII

如果您需要從單字符集(比如 WE8ISO88859P15)的源庫轉換到變寬多位元組字符集(比如 AL32UTF8)的目標庫,那麼需要在源庫執行字符集掃描工具來檢查一些轉換過程中可能發生的問題。詳情參考:
Note 745809.1- Installing and configuring Csscan in 10g and 11g (Database Character Set Scanner)
Note 444701.1- Csscan Output Explained
Note 1297961.1- ORA-01401 / ORA-12899 / ORA-01461 While Importing Data In An AL32UTF8 / UTF8 (Unicode) Or Other Multibyte NLS_CHARACTERSET Database.

3.2. 對於 Oracle9i 或者更高版本的資料庫,需要確定 undo 管理方式:手動或者自動。對於 Oracle9i 或者更高版本,推薦採用 Automatic Undo Managment。參考:
Note 135090.1- Managing Rollback/Undo Segments in AUM (Automatic Undo Management)

3.3. 對於 Oracle8i 或者更高版本的資料庫,需要確定 tablespace 的 space management 管理方式。對於 Oracle9i 或者更高版本,推薦採用 locally managed tablespaces。參考:
Note 105120.1- Advantages of Using Locally Managed vs Dictionary Managed Tablespaces

3.4. 在目標主機上,建立一個新的包含啟動引數的 parameter file。對於 Oracle9i 或者更高版本,需要確定初始化引數存放的方式是舊式的 pfile(init.ora) 或者採用新的 server parameter file(spfile-推薦)。詳情參考:
Note 249664.1- Pfile vs SPfile

3.5. 在目標主機上,通過 Database Configuration Assistant 來建立目標資料庫。您可以通過 Database Configuration Assistant(dbca) 選擇需要安裝哪些資料庫 option。選擇與源庫相同的 component,除非您絕對確認源庫的那些component 雖然安裝了但是從來沒有被使用過(參考本文上面的步驟2.2)。當降級遷移的時候,注意某些在源庫的特性和元件可能在低版本的目標資料庫不存在或者不相容。
對於 redo log 檔案來說,參見上面的步驟2.4。也可以通過一個已經存在的指令碼或者您自己寫的指令碼來建立資料庫。對於這樣的情況,確保這個指令碼呼叫了用於新增目標庫所需的 option 和 component 的所有其他指令碼。

3.5. 當使用老的(Oracle9i 之前)manual undo management 管理方式時,需要在 SYSTEM 表空間建立一個額外的 rollback segment 並且將其 online。詳情請參考:
Note 112479.1- ORA-01552 Error Creating a Rollback Segment in a Locally-Managed Tablespace

3.6. 檢查目標庫中是否所有的物件都是 valid 的:

CONNECT / as sysdba

SET lines 100 NUMWIDTH 12 PAGES 10000 LONG 2000000000
ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';
COL status FORMAT a9
COL object_typeFORMAT a20;
COL owner.objectFORMAT a50

SELECT status, object_id, object_type, owner||'.'||object_name "OWNER.OBJECT"
FROM dba_objects
WHERE status != 'VALID' AND object_name NOT LIKE 'BIN$%'
ORDER BY 4,2;

如果有 invalid 的物件,編譯它們。詳情請參考:
Note 213600.1- How to Compile Invalid Objects in SYS Schema after RDBMS 8.0

3.7. 對於 Oracle9i Release 2 (9.2.0) 和更高的版本,檢查資料字典的狀態:

CONNECT / as sysdba

SET lines 90 NUMWIDTH 12 PAGES 10000 LONG 2000000000
ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';
COL versionFORMAT a12
COL comp_idFORMAT a8
COL schema LIKE version
COL comp_nameFORMAT a35
COL status FORMAT a12

SELECT comp_id,schema,status,version,comp_name
FROM dba_registry
ORDER BY 1;

確保資料字典元件比如 CATALOG 和 CATPRO 具有與 Oracle 可執行檔案相同的版本:

CONNECT / as sysdba

SET lines 80 NUMWIDTH 12 PAGES 10000 LONG 2000000000
ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';

SELECT * FROM v$version;

3.8. 如果目標庫用於組成表空間的資料檔案的目錄結構與源庫不同,那麼需要提前在目標資料庫建立所有的的表空間(除了 SYSTEM,SYSAUX,UNDO 外)。對於原始 DDL,參見上面的步驟2.5。

3.9. 如果資料庫是 Database Vault 的環境,那麼對用於執行 import 的使用者授予必要的許可權,詳情參見:
Note 822048.1- How To Export / Import Objects In Database Vault Environment

3.10. 如果您的源庫安裝有 Enterprise Manager (EM) (schema SYSMAN - 參考上面的2.2步驟),那麼目標庫還需要額外的準備步驟,詳情請參考:
Note 1302281.1- 11g Grid Control: Steps for Migrating the 11g Grid Control Repository from One Database to Another

3.11. 對目標庫做一次 clean shutdown,然後通過 RMAN 或者作業系統(datafiles,controlfiles,redolog files)做一次 full backup。如果稍後您需要重新執行 import 的時候,您可以用這個備份來恢復資料庫。

CONNECT / as sysdba

SHUTDOWN immediate

-- create a full backup of the complete database

STARTUP

3.12. 檢查 $ORACLE_HOME/network/admin 下的 TNSNAMES.ORA 檔案,確保用於本地訪問和用於從新庫上訪問其他遠端 db-link 的那些 tns alias 已經新增(參見上面的2.7步驟)。

第四部分 - 從源庫執行匯出

4.1. 對源庫做一次 clean shutdown,然後通過 RMAN 或者作業系統(datafiles,controlfiles,redolog files)做一次 full backup。如果稍後您需要重新執行 export 的時候,您可以用這個備份來恢復資料庫。

CONNECT / as sysdba

SHUTDOWN immediate

-- create a full backup of the complete database

STARTUP

4.2. 停止源庫上的監聽,確保沒有任何使用者和應用能連線到該資料庫。

4.3. 建立一個 spool out 檔案存放源庫中的各 schema 的物件清單。例如:

CONNECT / as sysdba

SET lines 100 NUMWIDTH 12 PAGES 10000 LONG 2000000000
ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';
COL status FORMAT a9
COL object_typeFORMAT a20;
COL owner.objectFORMAT a50

SPOOL obj_source.out

SELECT status, object_id, object_type, owner||'.'||object_name "OWNER.OBJECT"
FROM dba_objects
WHERE status != 'VALID' AND object_name NOT LIKE 'BIN$%'
ORDER BY 4,2;

COL owner FORMAT a30
SELECT owner, object_type, status, count(*)
FROM dba_objects
WHERE object_name NOT LIKE 'BIN$%'
GROUP BY owner, object_type, status
ORDER BY 1,2,3;

SPOOL off

4.4.Owner 為 SYS 的物件不會被匯出。建立一個 spool out 檔案來存放 Owner 為 SYS 的 trigger 清單,例如:

CONNECT / as sysdba

SET lines 180 NUMWIDTH 12 PAGES 10000 LONG 2000000000
ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';
COL triggering_event FORMAT a35

SPOOL trig.out

SELECT owner, trigger_name, trigger_type, triggering_event, table_owner, base_object_type, status
FROM dba_triggers
WHERE owner='SYS'
ORDER BY 2;

SET lines 100
COL ddlFORMAT a100
SELECT dbms_metadata.get_ddl('TRIGGER','LOGMNRGGC_TRIGGER','SYS') "DDL" FROM dual;

-- do this for all manually created triggers in the SYS schema

SPOOL off

4.5. Owner 為 SYS 的物件的 grants 不會被匯出,建立一個 spool out 檔案來存放 SYS 物件被授予各使用者的 grants 的清單,例如:

CONNECT / as sysdba

SET lines 80 NUMWIDTH 12 PAGES 10000 LONG 2000000000
ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';
COL grants FOR a80

SPOOL sysgrants.out

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- Add below the users and/or roles as appropriate for GRANTEE
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SELECT 'GRANT ' || privilege || ' ON ' || table_name ||
' TO ' || grantee || ';' "GRANTS"
FROM dba_tab_privs
WHERE owner = 'SYS' AND privilege NOT IN ('READ', 'WRITE')
AND grantee IN ('TC')
ORDER BY 1;

SPOOL OFF

另參見:
Note 1911151.1- Data Pump: GRANTs On SYS Owned Objects Are Not Transferred With Data Pump And Are Missing In The Target Database

4.6. 檢查 export/import 的相容性,和 export/import data pump 的相容性:

  • 升級:

    • 源庫為 Oracle9i 或者更低版本:

      • 用原始的 exp 客戶端做全庫匯出。
      • 用與源庫匹配的 exp 客戶端版本。
    • 源庫為 Oracle 10g 或者更高版本:
      • 用 data pump expdp 工具執行全庫匯出。
      • 用任意版本的 data pump expdp(推薦使用與源庫版本匹配的 data pump client)。
  • 降級:
    • 目標庫為 Oracle9i 或者更低版本:

      • 用原始的 exp 客戶端做全庫匯出。
      • 用與目標庫匹配的 exp 客戶端版本。
    • 目標庫為 Oracle 10g 或者更高版本:
      • 用 data pump expdp 工具執行全庫匯出。
      • 用任意版本的 data pump expdp(推薦使用與源庫版本匹配的 data pump client)並且指定 data pump expdp 的引數 VERSION=<value>

參考:
Note 132904.1- Compatibility Matrix for Export And Import Between Different Oracle Versions [Video]
Note 345187.1- Feature Obsolescence - Original Export 10.2
Note 553337.1- Export/Import DataPump Parameter VERSION - Compatibility of Data Pump Between Different Oracle Versions [Video]

例如對於原始的 exp 客戶端(在 10.2 後 de-support 了):

$ exp system/manager FILE=exp_f1.dmp,exp_f2.dmp,exp_f3.dmp LOG=exp_f.log FILESIZE=10g FULL=y CONSISTENT=y COMPRESS=n

或者 Data Pump (10.1 及以上):

$ mkdir /u01/expdp
$ sqplus /nolog

CONNECT / as sysdba

CREATE OR REPLACE DIRECTORY my_dir AS '/u01/expdp';
GRANT read, write ON DIRECTORY my_dir TO system;

接下來:

$ expdp system/manager DIRECTORY=my_dir DUMPFILE=expdp_f%U.dmp LOGFILE=expdp_f.log FILESIZE=10g FULL=y PARALLEL=8 FLASHBACK_TIME=systimestamp

檢查 export 的 log 檔案看是否有錯誤發生。

第五部分 - 向目標庫匯入

注意:
如同步驟2.2中的解釋,對於全庫 export/import 來說,我們不會重建目標庫的資料字典物件。這些 shcema 和他們(預設)的物件已經在目標庫建立的時候就存在了。這種情況同樣適用於其他字典元件 schema。如果源庫的 SYS 和 SYSTEM 物件被人為增加了或者修改了,那麼依賴他們的一些物件可能會變成 invalid 的。因此,請一定要檢查源庫的相關物件。

5.1. 以 binary 模式複製匯出的 dump 檔案到目標庫主機

5.2. (如果4.6採用了 exp)那麼以原始的 imp 客戶端執行全庫匯入,(如果4.6採用了 expdp)那麼通過 data pump 工具執行。總是採用與目標庫版本匹配的 import 客戶端。

例如原始的 imp 客戶端:

$ imp system/manager FILE=exp_f1.dmp,exp_f2.dmp,exp_f3.dmp LOG=imp_f.log FILESIZE=10g FULL=y

或者 DataPump:

$ mkdir /u01/expdp
$ sqplus /nolog

CONNECT / as sysdba

CREATE OR REPLACE DIRECTORY my_dir AS '/u01/expdp';
GRANT read, write ON DIRECTORY my_dir TO system;

接著:

$ impdp system/manager DIRECTORY=my_dir DUMPFILE=expdp_f%U.dmp LOGFILEimpdp_f.log FILESIZE=10g FULL=y PARALLEL=8

注意對於 imp 我們推薦採用預設的 default IGNORE=N,而對於 impdp 推薦採用 TABLE_EXIST_ACTION=skip

5.3. 檢測 import 的日誌檢視是否有錯誤。比較4.6步驟的 export log 以及5.2步驟的 import log

5.4. 在目標庫中建立源庫中的那些自定義的 trigger。詳情參見上面的4.4步驟。

5.5. 在目標庫中建立源庫那些被 grant 到其他使用者的 SYS 物件的許可權。詳情參見上面的4.5步驟。

5.6. 在目標庫建立一個 spool 檔案存放各 schema 下的物件清單。例如:

CONNECT / as sysdba

SET lines 100 NUMWIDTH 12 PAGES 10000 LONG 2000000000
ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';
COL status FORMAT a9
COL object_typeFORMAT a20;
COL owner.objectFORMAT a50

SPOOL obj_target.out

COL owner FORMAT a30
SELECT owner, object_type, status, count(*)
FROM dba_objects
WHERE object_name NOT LIKE 'BIN$%'
GROUP BY owner, object_type, status
ORDER BY 1,2,3;

SPOOL off

用這個清單同4.3步驟的清單作比較。
找出清單不一致的原因並且解決它們。

5.7. 在目標庫重新編譯 invalid 的物件,並且檢查是否還有剩餘的 invalid 的物件:

CONNECT / as sysdba

SET lines 100 NUMWIDTH 12 PAGES 10000 LONG 2000000000
ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';
COL status FORMAT a9
COL object_typeFORMAT a20;
COL owner.objectFORMAT a50

-- recompile all invalid objects:
@?\rdbms\admin\utlrp.sql

@?\rdbms\admin\utlrp.sql

SELECT status, object_id, object_type, owner||'.'||object_name "OWNER.OBJECT"
FROM dba_objects
WHERE status != 'VALID' AND object_name NOT LIKE 'BIN$%'
ORDER BY 4,2;

手工編譯在源庫 valid(參見上面的4.3步驟)而在目標庫 invalid 的物件。
如果物件仍然 invalid,找出原因並解決它們。

5.8. 如果從一個低版本的資料庫遷移到目標庫(比如從 9.2.0.8 到 11.2.0.3),無論採用的是 data pump 還是傳統的 exp/imp,還需要執行一些 post-import 步驟,這些步驟在如下檔案中概括了:
-Oracle Database Upgrade Guide, 10g Release 2 (10.2), Chapter 4:After Upgrading a Database
-Oracle Database Upgrade Guide, 11g Release 1 (11.1), Chapter 4:After Upgrading to the New Release
-Oracle Database Upgrade Guide, 11g Release 2 (11.2), Chapter 4:Post-Upgrade Tasks for Oracle Database
-Oracle Database Upgrade Guide, 12c Release 1 (12.1), Chapter 4:Post-Upgrade Tasks for Oracle Database

5.9. 檢查使用者和應用能否連線到目標庫。

第六部分 - 完成源庫中剩下的操作

6.1. Shutdown 舊的源庫

CONNECT / AS SYSDBA

SHUTDOWN IMMEDIATE

第七部分 - 完成目標庫中剩下的操作

7.1. 對目標庫做一次 clean shutdown,然後通過 RMAN 或者作業系統(datafiles,controlfiles,redolog files)對資料庫做一次全備份

CONNECT / AS SYSDBA

SHUTDOWN immediate

-- 對全庫做 full backup

STARTUP

7.2. 讓新的目標庫可用。

COL owner FORMAT a30
SELECT owner, object_type, status, count(*)
FROM dba_objects
WHERE object_name NOT LIKE 'BIN$%'
GROUP BY owner, object_type, status
ORDER BY 1,2,3;

參考

NOTE:316900.1- ALERT: Oracle 10g Release 2 (10.2) Support Status and Alerts
NOTE:1628809.1- Differences Between Enterprise, Standard and Standard One Editions on Oracle 12.1
NOTE:189908.1- ALERT: Oracle9i Release 2 (9.2) Support Status and Alerts
NOTE:1302281.1- EM 11g: How to Migrate the Enterprise Manager 11g Grid Control Repository from One Database to Another
NOTE:756671.1- Master Note for Database Proactive Patch Program
NOTE:1613716.1- Export/Import Process for Oracle E-Business Suite Release 12.2 Database Instances Using Oracle Database 11.2
NOTE:822048.1- How To Export / Import Objects In Database Vault Environment
NOTE:204015.1- Export/Import Process for Oracle Applications Release 11i Database Instances
NOTE:228516.1- How to copy (export/import) Portal database schemas of IAS 9.0.2 to another database
NOTE:132904.1- Compatibility Matrix for Export And Import Between Different Oracle Versions [Video]
NOTE:331221.1- 10g Export/Import Process for Oracle Applications Release 11i
NOTE:105120.1- Advantages of Using Locally Managed vs Dictionary Managed Tablespaces
NOTE:1087325.1- Error ORA-439 When Importing Tables Created With Enabled Deferred Segment Into Oracle 11g Standard Edition
NOTE:741818.1- Export/import process for 12.0 or 12.1 using 11gR1 or 11gR2
NOTE:135090.1- Managing Rollback/Undo Segments in AUM (Automatic Undo Management)
NOTE:249664.1- Pfile vs SPfile
NOTE:269040.1- Differences Between Enterprise, Standard and Personal Editions on Oracle 9.2
NOTE:271886.1- Differences Between Different Editions of Oracle Database 10G Release 1
NOTE:557738.1- Export/import notes on Applications 11i Database 11g
NOTE:454507.1- ALERT: Oracle 11g Release 1 (11.1) Support Status and Alerts
NOTE:880782.1- ALERT: Oracle 11g Release 2 (11.2) Support Status and Alerts
NOTE:213600.1- How to Compile Invalid Objects in SYS Schema after RDBMS 8.0
NOTE:77441.1- Steps to Create a New Database With a Character Set Other Than US7ASCII
NOTE:277650.1- How To Use Export And Import When Transferring Data Across Platforms Or Across 32-bit And 64-bit Servers
NOTE:1911151.1- Data Pump: GRANTs On SYS Owned Objects Are Not Transferred With Data Pump And Are Missing In The Target Database
NOTE:1565065.1- ALERT: Oracle 12c Release 1 (12.1) Support Status and Alerts
NOTE:745809.1- Installing and configuring Csscan in 10g and 11g (Database Character Set Scanner)
NOTE:230627.1- 9i Export/Import Process for Oracle Applications Release 11i
NOTE:345187.1- Feature Obsolescence - Original Export 10.2
NOTE:362205.1- 10g Release 2 Export/Import Process for Oracle Applications Release 11i
NOTE:1585257.1- Export/Import Process for EBS 11i on RDBMS 12c
NOTE:444701.1- Csscan Output Explained
NOTE:1084132.1- Differences Between Enterprise, Standard and Standard One Editions on Oracle 11.2
NOTE:1297961.1- ORA-01401 / ORA-12899 / ORA-01461 While Importing Or Loading Data In An AL32UTF8 / UTF8 (Unicode) Or Other Multibyte NLS_CHARACTERSET Database.
NOTE:112479.1- ORA-01552 Error Creating a Rollback Segment in a Locally-Managed Tablespace
NOTE:161818.1- Oracle Database (RDBMS) Releases Support Status Summary
NOTE:465460.1- Differences Between Enterprise, Standard and Personal Editions on Oracle 11.1
NOTE:159657.1- Complete Upgrade Checklist for Manual Upgrades from 8.X / 9.0.1 to Oracle9iR2 (9.2.0)
NOTE:263719.1- ALERT: Oracle 10g Release 1 (10.1) Support Status and Alerts
NOTE:112591.1- Differences Between Enterprise, Standard and Personal Editions on Oracle 8.1
NOTE:133920.1- Complete Upgrade Checklist for Manual Upgrades from 8.x to 8.x
NOTE:454616.1- Export/Import Process for Oracle E-Business Suite Release 12 using 10gR2
NOTE:1439066.1- Exporting/Importing in Oracle Portal 11g
NOTE:472937.1- Information On Installed Database Components and Schemas
NOTE:553337.1- Export/Import DataPump Parameter VERSION - Compatibility of Data Pump Between Different Oracle Versions
NOTE:465465.1- Differences Between Enterprise, Standard and Personal Editions on Oracle 10.2