使用數據泵(expdp、impdp)遷移數據庫流程

使用數據泵遷移數據庫流程

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


In this Document 


Goal

Solution

References


APPLIES TO:

Oracle Database Cloud Schema Service - Version N/A and later 
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')"

See  Note 365459.1  Parallel 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/Import  Note 604129.1 
Drop the DB Control configuration and repository then recreate using  Note 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.1  How 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.1  10g Release 2 Export/Import Process for Oracle Applications Release 11i 
Note 454616.1  Export/Import Process for Oracle E-Business Suite Release 12 using 10gR2 
Note 557738.1  Export/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.1  Character Set Scanner - Frequently Asked Questions 
Note 458122.1  Installing and configuring CSSCAN in 8i and 9i 
Note 745809.1  Installing and configuring CSSCAN in 10g and 11g 
Note 444701.1  Csscan 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 version FORMAT a12 
    COL comp_id FORMAT a8 
    COL schema LIKE version 
    COL comp_name FORMAT 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 version FORMAT a12 
    COL comp_id FORMAT a8 
    COL schema LIKE version 
    COL comp_name FORMAT 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 ddl FORMAT 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_type FORMAT a20; 
COL owner.object FORMAT 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 version FORMAT a12 
COL comp_id FORMAT a8 
COL schema LIKE version 
COL comp_name FORMAT 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_type FORMAT a20; 
COL owner.object FORMAT 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 ddl FORMAT 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 的兼容性:

  • 升級: 

    • 用 data pump expdp 工具執行全庫導出。

    • 用任意版本的 data pump expdp(推薦使用與源庫版本匹配的 data pump client)。 

    • 用原始的 exp 客戶端做全庫導出。

    • 用與源庫匹配的 exp 客戶端版本。

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

    • 源庫爲 Oracle 10g 或者更高版本: 

  • 降級: 

    • 用 data pump expdp 工具執行全庫導出。

    • 用任意版本的 data pump expdp(推薦使用與源庫版本匹配的 data pump client)並且指定 data pump expdp 的參數 VERSION=<value>

    • 用原始的 exp 客戶端做全庫導出。

    • 用與目標庫匹配的 exp 客戶端版本。

    • 目標庫爲 Oracle9i 或者更低版本: 

    • 目標庫爲 Oracle 10g 或者更高版本: 

參考: 
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 及以上):

鄭州人流醫院:https://yyk.familydoctor.com.cn/21521/

$ 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_type FORMAT a20; 
COL owner.object FORMAT 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_type FORMAT a20; 
COL owner.object FORMAT 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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章