Skip to main content
Enterprise applications
本繁體中文版使用機器翻譯,譯文僅供參考,若與英文版本牴觸,應以英文版本為準。

透過記錄傳送進行 Oracle 資料庫移轉

貢獻者

使用記錄傳送進行移轉的目標是在新位置建立原始資料檔案的複本、然後建立將變更傳送到新環境的方法。

一旦建立、記錄傳送和重播就能自動進行、使複本資料庫與來源保持大致同步。例如、 cron 工作可排程至( a )將最近的記錄複製到新位置、並( b )每 15 分鐘重播一次。這樣做可在轉換時將中斷次數降至最低、因為必須重播不超過 15 分鐘的歸檔記錄。

以下程序基本上也是資料庫複製作業。所示邏輯類似於 NetApp SnapManager for Oracle ( SMO )和 NetApp SnapCenter Oracle Plug-in 內的引擎。有些客戶已使用指令碼或 WFA 工作流程中所示的程序來進行自訂的複製作業。雖然此程序比使用 SnapCenter 或 SMO 更為手冊化、但仍可輕鬆撰寫指令碼、而 ONTAP 中的資料管理 API 則可進一步簡化程序。

記錄傳送 - 檔案系統至檔案系統

本範例示範如何將名為華夫餅的資料庫從一般檔案系統移轉至位於不同伺服器上的其他一般檔案系統。它也說明 SnapMirror 可用來快速複製資料檔案、但這並不是整體程序不可或缺的一部分。

建立資料庫備份

第一步是建立資料庫備份。具體而言、此程序需要一組資料檔案、可用於歸檔記錄重新執行。

環境

在此範例中、來源資料庫位於 ONTAP 系統上。建立資料庫備份最簡單的方法是使用快照。將資料庫置於熱備份模式幾秒鐘 snapshot create 在託管資料檔案的磁碟區上執行作業。

SQL> alter database begin backup;
Database altered.
Cluster01::*> snapshot create -vserver vserver1 -volume jfsc1_oradata hotbackup
Cluster01::*>
SQL> alter database end backup;
Database altered.

結果是磁碟上的快照稱為 hotbackup 包含處於熱備份模式時的資料檔案映像。如果結合適當的歸檔記錄以使資料檔案一致、則此快照中的資料可作為還原或複製的基礎。在這種情況下、它會複寫到新的伺服器。

還原至新環境

現在必須在新環境中還原備份。這可以透過多種方式完成、包括 Oracle RMAN 、從備份應用程式(如 NetBackup )還原、或是簡單複製置於熱備份模式的資料檔案。

在此範例中、 SnapMirror 用於將快照熱備份複寫到新位置。

  1. 建立新的磁碟區以接收快照資料。從初始化鏡像 jfsc1_oradatavol_oradata

    Cluster01::*> volume create -vserver vserver1 -volume vol_oradata -aggregate data_01 -size 20g -state online -type DP -snapshot-policy none -policy jfsc3
    [Job 833] Job succeeded: Successful
    Cluster01::*> snapmirror initialize -source-path vserver1:jfsc1_oradata -destination-path vserver1:vol_oradata
    Operation is queued: snapmirror initialize of destination "vserver1:vol_oradata".
    Cluster01::*> volume mount -vserver vserver1 -volume vol_oradata -junction-path /vol_oradata
    Cluster01::*>
  2. 在 SnapMirror 設定狀態後、表示同步已完成、請特別根據所需的快照來更新鏡像。

    Cluster01::*> snapmirror show -destination-path vserver1:vol_oradata -fields state
    source-path             destination-path        state
    ----------------------- ----------------------- ------------
    vserver1:jfsc1_oradata vserver1:vol_oradata SnapMirrored
    Cluster01::*> snapmirror update -destination-path vserver1:vol_oradata -source-snapshot hotbackup
    Operation is queued: snapmirror update of destination "vserver1:vol_oradata".
  3. 您可以透過檢視來驗證同步成功與否 newest-snapshot 鏡射磁碟區上的欄位。

    Cluster01::*> snapmirror show -destination-path vserver1:vol_oradata -fields newest-snapshot
    source-path             destination-path        newest-snapshot
    ----------------------- ----------------------- ---------------
    vserver1:jfsc1_oradata vserver1:vol_oradata hotbackup
  4. 然後鏡射可能會中斷。

    Cluster01::> snapmirror break -destination-path vserver1:vol_oradata
    Operation succeeded: snapmirror break for destination "vserver1:vol_oradata".
    Cluster01::>
  5. 掛載新的檔案系統。使用區塊型檔案系統時、精確的程序會因使用中的 LVM 而異。必須設定 FC 分區或 iSCSI 連線。建立與 LUN 的連線後、命令如 Linux pvscan 可能需要探索哪些磁碟區群組或 LUN 需要正確設定、才能讓 ASM 發現。

    在此範例中、使用簡單的 NFS 檔案系統。此檔案系統可直接掛載。

    fas8060-nfs1:/vol_oradata        19922944   1639360   18283584   9% /oradata
    fas8060-nfs1:/vol_logs            9961472       128    9961344   1% /logs

建立控制檔建立範本

接下來必須建立控制檔範本。。 backup controlfile to trace 命令會建立文字命令以重新建立控制檔。在某些情況下、此功能可用於從備份還原資料庫、而且通常用於執行資料庫複製等工作的指令碼。

  1. 以下命令的輸出用於爲遷移的數據庫重新創建控制文件。

    SQL> alter database backup controlfile to trace as '/tmp/waffle.ctrl';
    Database altered.
  2. 建立控制檔之後、請將檔案複製到新伺服器。

    [oracle@jfsc3 tmp]$ scp oracle@jfsc1:/tmp/waffle.ctrl /tmp/
    oracle@jfsc1's password:
    waffle.ctrl                                              100% 5199     5.1KB/s   00:00

備份參數檔案

在新環境中也需要一個參數檔。最簡單的方法是從目前的 spfile 或 pfile 建立 pfile 。在此範例中、來源資料庫使用的是 spfile 。

SQL> create pfile='/tmp/waffle.tmp.pfile' from spfile;
File created.

建立 oratab 項目

需要建立 oratab 項目、才能正常運作如 oraenv 等公用程式。若要建立 oratab 項目、請完成下列步驟。

WAFFLE:/orabin/product/12.1.0/dbhome_1:N

準備目錄結構

如果所需目錄尚未存在、您必須建立它們、否則資料庫啟動程序會失敗。若要準備目錄結構、請完成下列最低需求。

[oracle@jfsc3 ~]$ . oraenv
ORACLE_SID = [oracle] ? WAFFLE
The Oracle base has been set to /orabin
[oracle@jfsc3 ~]$ cd $ORACLE_BASE
[oracle@jfsc3 orabin]$ cd admin
[oracle@jfsc3 admin]$ mkdir WAFFLE
[oracle@jfsc3 admin]$ cd WAFFLE
[oracle@jfsc3 WAFFLE]$ mkdir adump dpdump pfile scripts xdb_wallet

參數檔案更新

  1. 若要將參數檔複製到新伺服器、請執行下列命令。預設位置為 $ORACLE_HOME/dbs 目錄。在這種情況下、 pfile 可以放在任何地方。它只是移轉程序中的中間步驟。

[oracle@jfsc3 admin]$ scp oracle@jfsc1:/tmp/waffle.tmp.pfile $ORACLE_HOME/dbs/waffle.tmp.pfile
oracle@jfsc1's password:
waffle.pfile                                             100%  916     0.9KB/s   00:00
  1. 視需要編輯檔案。例如、如果歸檔記錄位置已變更、則必須變更 pfile 以反映新位置。在此範例中、只有控制檔正在重新定位、部分是為了在記錄檔和資料檔案系統之間散佈。

    [root@jfsc1 tmp]# cat waffle.pfile
    WAFFLE.__data_transfer_cache_size=0
    WAFFLE.__db_cache_size=507510784
    WAFFLE.__java_pool_size=4194304
    WAFFLE.__large_pool_size=20971520
    WAFFLE.__oracle_base='/orabin'#ORACLE_BASE set from environment
    WAFFLE.__pga_aggregate_target=268435456
    WAFFLE.__sga_target=805306368
    WAFFLE.__shared_io_pool_size=29360128
    WAFFLE.__shared_pool_size=234881024
    WAFFLE.__streams_pool_size=0
    *.audit_file_dest='/orabin/admin/WAFFLE/adump'
    *.audit_trail='db'
    *.compatible='12.1.0.2.0'
    *.control_files='/oradata//WAFFLE/control01.ctl','/oradata//WAFFLE/control02.ctl'
    *.control_files='/oradata/WAFFLE/control01.ctl','/logs/WAFFLE/control02.ctl'
    *.db_block_size=8192
    *.db_domain=''
    *.db_name='WAFFLE'
    *.diagnostic_dest='/orabin'
    *.dispatchers='(PROTOCOL=TCP) (SERVICE=WAFFLEXDB)'
    *.log_archive_dest_1='LOCATION=/logs/WAFFLE/arch'
    *.log_archive_format='%t_%s_%r.dbf'
    *.open_cursors=300
    *.pga_aggregate_target=256m
    *.processes=300
    *.remote_login_passwordfile='EXCLUSIVE'
    *.sga_target=768m
    *.undo_tablespace='UNDOTBS1'
  2. 編輯完成後、請根據此 pfile 建立 spfile 。

    SQL> create spfile from pfile='waffle.tmp.pfile';
    File created.

重新建立控制檔

在前一個步驟中、的輸出 backup controlfile to trace 已複製到新伺服器。所需輸出的特定部分是 controlfile recreation 命令。此資訊可在檔案中標記的區段下找到 Set #1. NORESETLOGS。從這條線開始 create controlfile reuse database 並應包含這個字 noresetlogs。結尾是分號(;)字元。

  1. 在此範例程序中、檔案會讀取如下內容。

    CREATE CONTROLFILE REUSE DATABASE "WAFFLE" NORESETLOGS  ARCHIVELOG
        MAXLOGFILES 16
        MAXLOGMEMBERS 3
        MAXDATAFILES 100
        MAXINSTANCES 8
        MAXLOGHISTORY 292
    LOGFILE
      GROUP 1 '/logs/WAFFLE/redo/redo01.log'  SIZE 50M BLOCKSIZE 512,
      GROUP 2 '/logs/WAFFLE/redo/redo02.log'  SIZE 50M BLOCKSIZE 512,
      GROUP 3 '/logs/WAFFLE/redo/redo03.log'  SIZE 50M BLOCKSIZE 512
    -- STANDBY LOGFILE
    DATAFILE
      '/oradata/WAFFLE/system01.dbf',
      '/oradata/WAFFLE/sysaux01.dbf',
      '/oradata/WAFFLE/undotbs01.dbf',
      '/oradata/WAFFLE/users01.dbf'
    CHARACTER SET WE8MSWIN1252
    ;
  2. 視需要編輯此指令碼、以反映各種檔案的新位置。例如、已知可支援高 I/O 的某些資料檔案、可能會重新導向至高效能儲存層上的檔案系統。在其他情況下、這些變更可能純粹是因為系統管理員的理由、例如在專用磁碟區中隔離指定的 PDB 資料檔案。

  3. 在此範例中 DATAFILE stanza 保持不變、但重做記錄會移至中的新位置 /redo 而非與歸檔登入共用空間 /logs

    CREATE CONTROLFILE REUSE DATABASE "WAFFLE" NORESETLOGS  ARCHIVELOG
        MAXLOGFILES 16
        MAXLOGMEMBERS 3
        MAXDATAFILES 100
        MAXINSTANCES 8
        MAXLOGHISTORY 292
    LOGFILE
      GROUP 1 '/redo/redo01.log'  SIZE 50M BLOCKSIZE 512,
      GROUP 2 '/redo/redo02.log'  SIZE 50M BLOCKSIZE 512,
      GROUP 3 '/redo/redo03.log'  SIZE 50M BLOCKSIZE 512
    -- STANDBY LOGFILE
    DATAFILE
      '/oradata/WAFFLE/system01.dbf',
      '/oradata/WAFFLE/sysaux01.dbf',
      '/oradata/WAFFLE/undotbs01.dbf',
      '/oradata/WAFFLE/users01.dbf'
    CHARACTER SET WE8MSWIN1252
    ;
    SQL> startup nomount;
    ORACLE instance started.
    Total System Global Area  805306368 bytes
    Fixed Size                  2929552 bytes
    Variable Size             331353200 bytes
    Database Buffers          465567744 bytes
    Redo Buffers                5455872 bytes
    SQL> CREATE CONTROLFILE REUSE DATABASE "WAFFLE" NORESETLOGS  ARCHIVELOG
      2      MAXLOGFILES 16
      3      MAXLOGMEMBERS 3
      4      MAXDATAFILES 100
      5      MAXINSTANCES 8
      6      MAXLOGHISTORY 292
      7  LOGFILE
      8    GROUP 1 '/redo/redo01.log'  SIZE 50M BLOCKSIZE 512,
      9    GROUP 2 '/redo/redo02.log'  SIZE 50M BLOCKSIZE 512,
     10    GROUP 3 '/redo/redo03.log'  SIZE 50M BLOCKSIZE 512
     11  -- STANDBY LOGFILE
     12  DATAFILE
     13    '/oradata/WAFFLE/system01.dbf',
     14    '/oradata/WAFFLE/sysaux01.dbf',
     15    '/oradata/WAFFLE/undotbs01.dbf',
     16    '/oradata/WAFFLE/users01.dbf'
     17  CHARACTER SET WE8MSWIN1252
     18  ;
    Control file created.
    SQL>

如果有任何檔案放錯位置或參數設定錯誤、就會產生錯誤、指出必須修正的項目。資料庫已掛載、但尚未開啟且無法開啟、因為使用中的資料檔案仍標示為處於熱備份模式。必須先套用歸檔記錄檔、才能使資料庫一致。

初始記錄複寫

為了使資料檔案一致、至少需要執行一項記錄回覆作業。有許多選項可供重播記錄。在某些情況下、原始伺服器上的原始歸檔記錄檔位置可以透過 NFS 共用、而且記錄回覆可以直接完成。在其他情況下、必須複製歸檔記錄。

例如、簡單 scp 作業可將所有目前記錄從來源伺服器複製到移轉伺服器:

[oracle@jfsc3 arch]$ scp jfsc1:/logs/WAFFLE/arch/* ./
oracle@jfsc1's password:
1_22_912662036.dbf                                       100%   47MB  47.0MB/s   00:01
1_23_912662036.dbf                                       100%   40MB  40.4MB/s   00:00
1_24_912662036.dbf                                       100%   45MB  45.4MB/s   00:00
1_25_912662036.dbf                                       100%   41MB  40.9MB/s   00:01
1_26_912662036.dbf                                       100%   39MB  39.4MB/s   00:00
1_27_912662036.dbf                                       100%   39MB  38.7MB/s   00:00
1_28_912662036.dbf                                       100%   40MB  40.1MB/s   00:01
1_29_912662036.dbf                                       100%   17MB  16.9MB/s   00:00
1_30_912662036.dbf                                       100%  636KB 636.0KB/s   00:00

初始記錄重新播放

檔案在歸檔記錄位置後、可以發出命令來重新播放 recover database until cancel 接著是回應 AUTO 自動重播所有可用的記錄。

SQL> recover database until cancel;
ORA-00279: change 382713 generated at 05/24/2016 09:00:54 needed for thread 1
ORA-00289: suggestion : /logs/WAFFLE/arch/1_23_912662036.dbf
ORA-00280: change 382713 for thread 1 is in sequence #23
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
AUTO
ORA-00279: change 405712 generated at 05/24/2016 15:01:05 needed for thread 1
ORA-00289: suggestion : /logs/WAFFLE/arch/1_24_912662036.dbf
ORA-00280: change 405712 for thread 1 is in sequence #24
ORA-00278: log file '/logs/WAFFLE/arch/1_23_912662036.dbf' no longer needed for
this recovery
...
ORA-00279: change 713874 generated at 05/26/2016 04:26:43 needed for thread 1
ORA-00289: suggestion : /logs/WAFFLE/arch/1_31_912662036.dbf
ORA-00280: change 713874 for thread 1 is in sequence #31
ORA-00278: log file '/logs/WAFFLE/arch/1_30_912662036.dbf' no longer needed for
this recovery
ORA-00308: cannot open archived log '/logs/WAFFLE/arch/1_31_912662036.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

最終的歸檔記錄回覆會回報錯誤、但這是正常現象。記錄會指出這一點 sqlplus 正在尋找特定的記錄檔、但找不到該檔案。原因很可能是記錄檔尚未存在。

如果在複製歸檔記錄之前可以關閉來源資料庫、則此步驟只能執行一次。歸檔記錄會複製並重新播放、然後程序會直接繼續進行轉換程序、以複寫重要的重作記錄。

遞增記錄複寫及重新播放

在大多數情況下、移轉作業不會立即執行。移轉程序可能在幾天甚至幾週前完成、這表示記錄必須持續運送至複本資料庫並重新執行。因此、當轉換程式到達時、必須傳輸和重播最少的資料。

這樣做有許多方式可以撰寫指令碼、但其中最受歡迎的方法之一是使用 rsync 、這是通用的檔案複寫公用程式。使用此公用程式最安全的方法是將其設定為常駐程式。例如、 rsyncd.conf 下列檔案顯示如何建立名為的資源 waffle.arch 使用 Oracle 使用者認證存取、並對應至 /logs/WAFFLE/arch。最重要的是、資源設為唯讀、可讀取正式作業資料、但不變更。

[root@jfsc1 arch]# cat /etc/rsyncd.conf
[waffle.arch]
   uid=oracle
   gid=dba
   path=/logs/WAFFLE/arch
   read only = true
[root@jfsc1 arch]# rsync --daemon

下列命令會將新伺服器的保存檔記錄目的地與 rsync 資源同步 waffle.arch 在原始伺服器上。。 t 引數 rsync - potg 根據時間戳記比較檔案清單、只複製新檔案。此程序提供新伺服器的遞增更新。此命令也可在 cron 中排程為定期執行。

[oracle@jfsc3 arch]$ rsync -potg --stats --progress jfsc1::waffle.arch/* /logs/WAFFLE/arch/
1_31_912662036.dbf
      650240 100%  124.02MB/s    0:00:00 (xfer#1, to-check=8/18)
1_32_912662036.dbf
     4873728 100%  110.67MB/s    0:00:00 (xfer#2, to-check=7/18)
1_33_912662036.dbf
     4088832 100%   50.64MB/s    0:00:00 (xfer#3, to-check=6/18)
1_34_912662036.dbf
     8196096 100%   54.66MB/s    0:00:00 (xfer#4, to-check=5/18)
1_35_912662036.dbf
    19376128 100%   57.75MB/s    0:00:00 (xfer#5, to-check=4/18)
1_36_912662036.dbf
       71680 100%  201.15kB/s    0:00:00 (xfer#6, to-check=3/18)
1_37_912662036.dbf
     1144320 100%    3.06MB/s    0:00:00 (xfer#7, to-check=2/18)
1_38_912662036.dbf
    35757568 100%   63.74MB/s    0:00:00 (xfer#8, to-check=1/18)
1_39_912662036.dbf
      984576 100%    1.63MB/s    0:00:00 (xfer#9, to-check=0/18)
Number of files: 18
Number of files transferred: 9
Total file size: 399653376 bytes
Total transferred file size: 75143168 bytes
Literal data: 75143168 bytes
Matched data: 0 bytes
File list size: 474
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 204
Total bytes received: 75153219
sent 204 bytes  received 75153219 bytes  150306846.00 bytes/sec
total size is 399653376  speedup is 5.32

在收到記錄之後、必須重新播放記錄。前面的範例顯示使用 sqlplus 來手動執行 recover database until cancel,這是一種可以輕鬆自動化的程序。此處顯示的範例使用中所述的指令碼 "重播資料庫上的記錄"。指令碼會接受指定需要重新執行作業之資料庫的引數。如此可在多資料庫移轉作業中使用相同的指令碼。

[oracle@jfsc3 logs]$ ./replay.logs.pl WAFFLE
ORACLE_SID = [WAFFLE] ? The Oracle base remains unchanged with value /orabin
SQL*Plus: Release 12.1.0.2.0 Production on Thu May 26 10:47:16 2016
Copyright (c) 1982, 2014, Oracle.  All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> ORA-00279: change 713874 generated at 05/26/2016 04:26:43 needed for thread 1
ORA-00289: suggestion : /logs/WAFFLE/arch/1_31_912662036.dbf
ORA-00280: change 713874 for thread 1 is in sequence #31
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00279: change 814256 generated at 05/26/2016 04:52:30 needed for thread 1
ORA-00289: suggestion : /logs/WAFFLE/arch/1_32_912662036.dbf
ORA-00280: change 814256 for thread 1 is in sequence #32
ORA-00278: log file '/logs/WAFFLE/arch/1_31_912662036.dbf' no longer needed for
this recovery
ORA-00279: change 814780 generated at 05/26/2016 04:53:04 needed for thread 1
ORA-00289: suggestion : /logs/WAFFLE/arch/1_33_912662036.dbf
ORA-00280: change 814780 for thread 1 is in sequence #33
ORA-00278: log file '/logs/WAFFLE/arch/1_32_912662036.dbf' no longer needed for
this recovery
...
ORA-00279: change 1120099 generated at 05/26/2016 09:59:21 needed for thread 1
ORA-00289: suggestion : /logs/WAFFLE/arch/1_40_912662036.dbf
ORA-00280: change 1120099 for thread 1 is in sequence #40
ORA-00278: log file '/logs/WAFFLE/arch/1_39_912662036.dbf' no longer needed for
this recovery
ORA-00308: cannot open archived log '/logs/WAFFLE/arch/1_40_912662036.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

轉換

當您準備好切換至新環境時、必須執行最後一次同步、其中包括歸檔記錄和重做記錄。如果尚未知道原始的重做記錄位置、可以如下所示識別:

SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/logs/WAFFLE/redo/redo01.log
/logs/WAFFLE/redo/redo02.log
/logs/WAFFLE/redo/redo03.log
  1. 關閉來源資料庫。

  2. 使用所需的方法、在新伺服器上執行歸檔記錄的最後一次同步。

  3. 來源重做記錄檔必須複製到新伺服器。在此範例中、重做記錄會重新定位到新的目錄 /redo

    [oracle@jfsc3 logs]$ scp jfsc1:/logs/WAFFLE/redo/* /redo/
    oracle@jfsc1's password:
    redo01.log                                                              100%   50MB  50.0MB/s   00:01
    redo02.log                                                              100%   50MB  50.0MB/s   00:00
    redo03.log                                                              100%   50MB  50.0MB/s   00:00
  4. 在此階段、新的資料庫環境包含所有必要的檔案、使其與來源完全相同。歸檔記錄必須最後重播一次。

    SQL> recover database until cancel;
    ORA-00279: change 1120099 generated at 05/26/2016 09:59:21 needed for thread 1
    ORA-00289: suggestion : /logs/WAFFLE/arch/1_40_912662036.dbf
    ORA-00280: change 1120099 for thread 1 is in sequence #40
    Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
    AUTO
    ORA-00308: cannot open archived log '/logs/WAFFLE/arch/1_40_912662036.dbf'
    ORA-27037: unable to obtain file status
    Linux-x86_64 Error: 2: No such file or directory
    Additional information: 3
    ORA-00308: cannot open archived log '/logs/WAFFLE/arch/1_40_912662036.dbf'
    ORA-27037: unable to obtain file status
    Linux-x86_64 Error: 2: No such file or directory
    Additional information: 3
  5. 完成後、必須重新執行重作記錄。如果出現此訊息 Media recovery complete 會傳回、程序成功、資料庫會同步、並可開啟。

    SQL> recover database;
    Media recovery complete.
    SQL> alter database open;
    Database altered.

記錄傳送 - ASM 至檔案系統

本範例說明如何使用 Oracle RMAN 移轉資料庫。這與先前的檔案系統傳送檔案系統記錄檔範例非常類似、但主機看不到 ASM 上的檔案。唯一用於移轉位於 ASM 裝置上的資料的選項是重新放置 ASM LUN 、或使用 Oracle RMAN 來執行複製作業。

雖然 RMAN 是從 Oracle ASM 複製檔案的必要條件、但 RMAN 的使用不限於 ASM 。RMAN 可用於從任何類型的儲存設備移轉至任何其他類型。

此範例顯示將名為 pake 的資料庫從 ASM 儲存設備重新放置到位於路徑上不同伺服器上的一般檔案系統 /oradata/logs

建立資料庫備份

第一步是建立要移轉到替代伺服器的資料庫備份。由於來源使用 Oracle ASM 、因此必須使用 RMAN 。簡單的 RMAN 備份可執行如下。此方法會建立標記備份、可在稍後的程序中由 RMAN 輕鬆識別。

第一個命令定義備份的目的地類型和要使用的位置。第二個只會啟動資料檔案的備份。

RMAN> configure channel device type disk format '/rman/pancake/%U';
using target database control file instead of recovery catalog
old RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/rman/pancake/%U';
new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/rman/pancake/%U';
new RMAN configuration parameters are successfully stored
RMAN> backup database tag 'ONTAP_MIGRATION';
Starting backup at 24-MAY-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=251 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=+ASM0/PANCAKE/system01.dbf
input datafile file number=00002 name=+ASM0/PANCAKE/sysaux01.dbf
input datafile file number=00003 name=+ASM0/PANCAKE/undotbs101.dbf
input datafile file number=00004 name=+ASM0/PANCAKE/users01.dbf
channel ORA_DISK_1: starting piece 1 at 24-MAY-16
channel ORA_DISK_1: finished piece 1 at 24-MAY-16
piece handle=/rman/pancake/1gr6c161_1_1 tag=ONTAP_MIGRATION comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 24-MAY-16
channel ORA_DISK_1: finished piece 1 at 24-MAY-16
piece handle=/rman/pancake/1hr6c164_1_1 tag=ONTAP_MIGRATION comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 24-MAY-16

備份控制檔

稍後的程序中需要備份控制檔 duplicate database 營運。

RMAN> backup current controlfile format '/rman/pancake/ctrl.bkp';
Starting backup at 24-MAY-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 24-MAY-16
channel ORA_DISK_1: finished piece 1 at 24-MAY-16
piece handle=/rman/pancake/ctrl.bkp tag=TAG20160524T032651 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 24-MAY-16

備份參數檔案

在新環境中也需要一個參數檔。最簡單的方法是從目前的 spfile 或 pfile 建立 pfile 。在此範例中、來源資料庫使用 spfile 。

RMAN> create pfile='/rman/pancake/pfile' from spfile;
Statement processed

ASM 檔案重新命名指令碼

移動資料庫時、控制檔中目前定義的數個檔案位置會變更。下列指令碼會建立 RMAN 指令碼、以簡化程序。此範例顯示的資料庫資料檔案數量極少、但資料庫通常包含數百個甚至數千個資料檔案。

此指令碼位於 "ASM 至檔案系統名稱轉換" 它有兩件事。

首先、它會建立一個參數、重新定義稱為的重做記錄位置 log_file_name_convert。基本上是交替欄位清單。第一個欄位是目前重做記錄檔的位置、第二個欄位是新伺服器上的位置。然後重複該模式。

第二個功能是提供資料檔案重新命名的範本。指令碼會循環瀏覽資料檔案、擷取名稱和檔案編號資訊、並將其格式化為 RMAN 指令碼。然後、它會對暫存檔案執行相同的操作。結果是一個簡單的 RMAN 指令碼、可視需要加以編輯、以確保檔案還原至所需的位置。

SQL> @/rman/mk.rename.scripts.sql
Parameters for log file conversion:
*.log_file_name_convert = '+ASM0/PANCAKE/redo01.log',
'/NEW_PATH/redo01.log','+ASM0/PANCAKE/redo02.log',
'/NEW_PATH/redo02.log','+ASM0/PANCAKE/redo03.log', '/NEW_PATH/redo03.log'
rman duplication script:
run
{
set newname for datafile 1 to '+ASM0/PANCAKE/system01.dbf';
set newname for datafile 2 to '+ASM0/PANCAKE/sysaux01.dbf';
set newname for datafile 3 to '+ASM0/PANCAKE/undotbs101.dbf';
set newname for datafile 4 to '+ASM0/PANCAKE/users01.dbf';
set newname for tempfile 1 to '+ASM0/PANCAKE/temp01.dbf';
duplicate target database for standby backup location INSERT_PATH_HERE;
}
PL/SQL procedure successfully completed.

擷取此畫面的輸出。。 log_file_name_convert 參數會如下所述放置在 pfile 中。RMAN 資料檔案重新命名和重複指令碼必須據此編輯、才能將資料檔案放置在所需的位置。在此範例中、所有的項目都放在中 /oradata/pancake

run
{
set newname for datafile 1 to '/oradata/pancake/pancake.dbf';
set newname for datafile 2 to '/oradata/pancake/sysaux.dbf';
set newname for datafile 3 to '/oradata/pancake/undotbs1.dbf';
set newname for datafile 4 to '/oradata/pancake/users.dbf';
set newname for tempfile 1 to '/oradata/pancake/temp.dbf';
duplicate target database for standby backup location '/rman/pancake';
}

準備目錄結構

指令碼幾乎可以執行、但首先必須有目錄結構。如果所需目錄尚未存在、則必須建立這些目錄、否則資料庫啟動程序會失敗。以下範例反映最低需求。

[oracle@jfsc2 ~]$ mkdir /oradata/pancake
[oracle@jfsc2 ~]$ mkdir /logs/pancake
[oracle@jfsc2 ~]$ cd /orabin/admin
[oracle@jfsc2 admin]$ mkdir PANCAKE
[oracle@jfsc2 admin]$ cd PANCAKE
[oracle@jfsc2 PANCAKE]$ mkdir adump dpdump pfile scripts xdb_wallet

建立 oratab 項目

下列命令是 oraenv 等公用程式正常運作所需的命令。

PANCAKE:/orabin/product/12.1.0/dbhome_1:N

參數更新

必須更新儲存的 pfile 、以反映新伺服器上的任何路徑變更。資料檔案路徑變更是由 RMAN 複製指令碼所變更、幾乎所有資料庫都需要變更 control_fileslog_archive_dest 參數。也可能有必須變更的稽核檔案位置和參數、例如 db_create_file_dest 在 ASM 之外可能無關緊要。經驗豐富的 DBA 應仔細審查建議的變更、然後再繼續。

在此範例中、主要變更為控制檔位置、記錄歸檔目的地、以及新增 log_file_name_convert 參數。

PANCAKE.__data_transfer_cache_size=0
PANCAKE.__db_cache_size=545259520
PANCAKE.__java_pool_size=4194304
PANCAKE.__large_pool_size=25165824
PANCAKE.__oracle_base='/orabin'#ORACLE_BASE set from environment
PANCAKE.__pga_aggregate_target=268435456
PANCAKE.__sga_target=805306368
PANCAKE.__shared_io_pool_size=29360128
PANCAKE.__shared_pool_size=192937984
PANCAKE.__streams_pool_size=0
*.audit_file_dest='/orabin/admin/PANCAKE/adump'
*.audit_trail='db'
*.compatible='12.1.0.2.0'
*.control_files='+ASM0/PANCAKE/control01.ctl','+ASM0/PANCAKE/control02.ctl'
*.control_files='/oradata/pancake/control01.ctl','/logs/pancake/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='PANCAKE'
*.diagnostic_dest='/orabin'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=PANCAKEXDB)'
*.log_archive_dest_1='LOCATION=+ASM1'
*.log_archive_dest_1='LOCATION=/logs/pancake'
*.log_archive_format='%t_%s_%r.dbf'
'/logs/path/redo02.log'
*.log_file_name_convert = '+ASM0/PANCAKE/redo01.log', '/logs/pancake/redo01.log', '+ASM0/PANCAKE/redo02.log', '/logs/pancake/redo02.log', '+ASM0/PANCAKE/redo03.log',  '/logs/pancake/redo03.log'
*.open_cursors=300
*.pga_aggregate_target=256m
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=768m
*.undo_tablespace='UNDOTBS1'

確認新參數之後、必須使參數生效。存在多個選項、但大多數客戶會根據文字 pfile 建立 spfile 。

bash-4.1$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Fri Jan 8 11:17:40 2016
Copyright (c) 1982, 2014, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> create spfile from pfile='/rman/pancake/pfile';
File created.

啟動 nomount

複寫資料庫之前的最後一個步驟是啟動資料庫程序、但不要掛載檔案。在此步驟中、 spfile 可能會出現問題。如果是 startup nomount 命令因參數錯誤而失敗、關機很簡單、請修正 pfile 範本、將其重新載入為 spfile 、然後再試一次。

SQL> startup nomount;
ORACLE instance started.
Total System Global Area  805306368 bytes
Fixed Size                  2929552 bytes
Variable Size             373296240 bytes
Database Buffers          423624704 bytes
Redo Buffers                5455872 bytes

複製資料庫

將先前的 RMAN 備份還原至新位置、比此程序中的其他步驟花費更多時間。必須複製資料庫、而不需變更資料庫 ID ( DBID )或重新設定記錄。這可防止套用記錄、這是完全同步複本的必要步驟。

使用 RMAN AS aux 連線至資料庫、並使用在前一個步驟中建立的指令碼發出重複資料庫命令。

[oracle@jfsc2 pancake]$ rman auxiliary /
Recovery Manager: Release 12.1.0.2.0 - Production on Tue May 24 03:04:56 2016
Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.
connected to auxiliary database: PANCAKE (not mounted)
RMAN> run
2> {
3> set newname for datafile 1 to '/oradata/pancake/pancake.dbf';
4> set newname for datafile 2 to '/oradata/pancake/sysaux.dbf';
5> set newname for datafile 3 to '/oradata/pancake/undotbs1.dbf';
6> set newname for datafile 4 to '/oradata/pancake/users.dbf';
7> set newname for tempfile 1 to '/oradata/pancake/temp.dbf';
8> duplicate target database for standby backup location '/rman/pancake';
9> }
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting Duplicate Db at 24-MAY-16
contents of Memory Script:
{
   restore clone standby controlfile from  '/rman/pancake/ctrl.bkp';
}
executing Memory Script
Starting restore at 24-MAY-16
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=243 device type=DISK
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/oradata/pancake/control01.ctl
output file name=/logs/pancake/control02.ctl
Finished restore at 24-MAY-16
contents of Memory Script:
{
   sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standby database
released channel: ORA_AUX_DISK_1
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=243 device type=DISK
contents of Memory Script:
{
   set newname for tempfile  1 to
 "/oradata/pancake/temp.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to
 "/oradata/pancake/pancake.dbf";
   set newname for datafile  2 to
 "/oradata/pancake/sysaux.dbf";
   set newname for datafile  3 to
 "/oradata/pancake/undotbs1.dbf";
   set newname for datafile  4 to
 "/oradata/pancake/users.dbf";
   restore
   clone database
   ;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /oradata/pancake/temp.dbf in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 24-MAY-16
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /oradata/pancake/pancake.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /oradata/pancake/sysaux.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /oradata/pancake/undotbs1.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /oradata/pancake/users.dbf
channel ORA_AUX_DISK_1: reading from backup piece /rman/pancake/1gr6c161_1_1
channel ORA_AUX_DISK_1: piece handle=/rman/pancake/1gr6c161_1_1 tag=ONTAP_MIGRATION
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 24-MAY-16
contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=912655725 file name=/oradata/pancake/pancake.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=912655725 file name=/oradata/pancake/sysaux.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=7 STAMP=912655725 file name=/oradata/pancake/undotbs1.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=912655725 file name=/oradata/pancake/users.dbf
Finished Duplicate Db at 24-MAY-16

初始記錄複寫

您現在必須將變更從來源資料庫傳送至新位置。這樣做可能需要多個步驟的組合。最簡單的方法是讓來源資料庫上的 RMAN 將歸檔記錄寫入共用網路連線。如果無法使用共用位置、則另一種方法是使用 RMAN 寫入本機檔案系統、然後使用 rcp 或 rsync 複製檔案。

在此範例中 /rman 目錄是一種 NFS 共用、可同時用於原始和移轉的資料庫。

此處的一個重要問題是 disk format 條款。備份的磁碟格式為 %h_%e_%a.dbf,這表示您必須使用資料庫的執行緒編號、序號和啟動 ID 格式。雖然字母不同、但這與相符 log_archive_format='%t_%s_%r.dbf pfile 中的參數。此參數也會以執行緒編號、序號和啟動 ID 的格式來指定封存記錄。最終結果是來源上的記錄檔備份使用資料庫預期的命名慣例。如此一來、就能執行像這樣的作業 recover database 更簡單、因為 sqlplus 能正確預測要重新播放的歸檔記錄名稱。

RMAN> configure channel device type disk format '/rman/pancake/logship/%h_%e_%a.dbf';
old RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/rman/pancake/arch/%h_%e_%a.dbf';
new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/rman/pancake/logship/%h_%e_%a.dbf';
new RMAN configuration parameters are successfully stored
released channel: ORA_DISK_1
RMAN> backup as copy archivelog from time 'sysdate-2';
Starting backup at 24-MAY-16
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=373 device type=DISK
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=54 RECID=70 STAMP=912658508
output file name=/rman/pancake/logship/1_54_912576125.dbf RECID=123 STAMP=912659482
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=41 RECID=29 STAMP=912654101
output file name=/rman/pancake/logship/1_41_912576125.dbf RECID=124 STAMP=912659483
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
...
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=45 RECID=33 STAMP=912654688
output file name=/rman/pancake/logship/1_45_912576125.dbf RECID=152 STAMP=912659514
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=47 RECID=36 STAMP=912654809
output file name=/rman/pancake/logship/1_47_912576125.dbf RECID=153 STAMP=912659515
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
Finished backup at 24-MAY-16

初始記錄重新播放

檔案在歸檔記錄位置後、可以發出命令來重新播放 recover database until cancel 接著是回應 AUTO 自動重播所有可用的記錄。參數檔目前正在將歸檔記錄導向 `/logs/archive`但這與 RMAN 用於保存日誌的位置不匹配。在恢復資料庫之前、可依下列方式暫時重新導向位置。

SQL> alter system set log_archive_dest_1='LOCATION=/rman/pancake/logship' scope=memory;
System altered.
SQL> recover standby database until cancel;
ORA-00279: change 560224 generated at 05/24/2016 03:25:53 needed for thread 1
ORA-00289: suggestion : /rman/pancake/logship/1_49_912576125.dbf
ORA-00280: change 560224 for thread 1 is in sequence #49
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
AUTO
ORA-00279: change 560353 generated at 05/24/2016 03:29:17 needed for thread 1
ORA-00289: suggestion : /rman/pancake/logship/1_50_912576125.dbf
ORA-00280: change 560353 for thread 1 is in sequence #50
ORA-00278: log file '/rman/pancake/logship/1_49_912576125.dbf' no longer needed
for this recovery
...
ORA-00279: change 560591 generated at 05/24/2016 03:33:56 needed for thread 1
ORA-00289: suggestion : /rman/pancake/logship/1_54_912576125.dbf
ORA-00280: change 560591 for thread 1 is in sequence #54
ORA-00278: log file '/rman/pancake/logship/1_53_912576125.dbf' no longer needed
for this recovery
ORA-00308: cannot open archived log '/rman/pancake/logship/1_54_912576125.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

最終的歸檔記錄回覆會回報錯誤、但這是正常現象。此錯誤表示 sqlplus 正在尋找特定的記錄檔、但找不到該檔案。原因很可能是記錄檔尚未存在。

如果在複製歸檔記錄之前可以關閉來源資料庫、則此步驟只能執行一次。歸檔記錄會複製並重新播放、然後程序會直接繼續進行轉換程序、以複寫重要的重作記錄。

遞增記錄複寫及重新播放

在大多數情況下、移轉作業不會立即執行。移轉程序可能在幾天甚至幾週前完成、這表示記錄必須持續運送至複本資料庫並重新執行。這樣做可確保轉換程序到達時、必須傳輸和重播最少的資料。

此程序很容易撰寫指令碼。例如、您可以在原始資料庫上排程下列命令、以確保用於記錄傳送的位置持續更新。

[oracle@jfsc1 pancake]$ cat copylogs.rman
configure channel device type disk format '/rman/pancake/logship/%h_%e_%a.dbf';
backup as copy archivelog from time 'sysdate-2';
[oracle@jfsc1 pancake]$ rman target / cmdfile=copylogs.rman
Recovery Manager: Release 12.1.0.2.0 - Production on Tue May 24 04:36:19 2016
Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.
connected to target database: PANCAKE (DBID=3574534589)
RMAN> configure channel device type disk format '/rman/pancake/logship/%h_%e_%a.dbf';
2> backup as copy archivelog from time 'sysdate-2';
3>
4>
using target database control file instead of recovery catalog
old RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/rman/pancake/logship/%h_%e_%a.dbf';
new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/rman/pancake/logship/%h_%e_%a.dbf';
new RMAN configuration parameters are successfully stored
Starting backup at 24-MAY-16
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=369 device type=DISK
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=54 RECID=123 STAMP=912659482
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/24/2016 04:36:22
ORA-19635: input and output file names are identical: /rman/pancake/logship/1_54_912576125.dbf
continuing other job steps, job failed will not be re-run
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=41 RECID=124 STAMP=912659483
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/24/2016 04:36:23
ORA-19635: input and output file names are identical: /rman/pancake/logship/1_41_912576125.dbf
continuing other job steps, job failed will not be re-run
...
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=45 RECID=152 STAMP=912659514
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/24/2016 04:36:55
ORA-19635: input and output file names are identical: /rman/pancake/logship/1_45_912576125.dbf
continuing other job steps, job failed will not be re-run
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=47 RECID=153 STAMP=912659515
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/24/2016 04:36:57
ORA-19635: input and output file names are identical: /rman/pancake/logship/1_47_912576125.dbf
Recovery Manager complete.

在收到記錄之後、必須重新播放記錄。先前的範例顯示使用 sqlplus 來手動執行 `recover database until cancel`可輕鬆自動化。此處顯示的範例使用中所述的指令碼 "重播待命資料庫上的記錄"。指令碼會接受一個引數、指定需要重新執行作業的資料庫。此程序允許在多資料庫移轉工作中使用相同的指令碼。

[root@jfsc2 pancake]# ./replaylogs.pl PANCAKE
ORACLE_SID = [oracle] ? The Oracle base has been set to /orabin
SQL*Plus: Release 12.1.0.2.0 Production on Tue May 24 04:47:10 2016
Copyright (c) 1982, 2014, Oracle.  All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> ORA-00279: change 560591 generated at 05/24/2016 03:33:56 needed for thread 1
ORA-00289: suggestion : /rman/pancake/logship/1_54_912576125.dbf
ORA-00280: change 560591 for thread 1 is in sequence #54
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00279: change 562219 generated at 05/24/2016 04:15:08 needed for thread 1
ORA-00289: suggestion : /rman/pancake/logship/1_55_912576125.dbf
ORA-00280: change 562219 for thread 1 is in sequence #55
ORA-00278: log file '/rman/pancake/logship/1_54_912576125.dbf' no longer needed for this recovery
ORA-00279: change 562370 generated at 05/24/2016 04:19:18 needed for thread 1
ORA-00289: suggestion : /rman/pancake/logship/1_56_912576125.dbf
ORA-00280: change 562370 for thread 1 is in sequence #56
ORA-00278: log file '/rman/pancake/logship/1_55_912576125.dbf' no longer needed for this recovery
...
ORA-00279: change 563137 generated at 05/24/2016 04:36:20 needed for thread 1
ORA-00289: suggestion : /rman/pancake/logship/1_65_912576125.dbf
ORA-00280: change 563137 for thread 1 is in sequence #65
ORA-00278: log file '/rman/pancake/logship/1_64_912576125.dbf' no longer needed for this recovery
ORA-00308: cannot open archived log '/rman/pancake/logship/1_65_912576125.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

轉換

準備好切換至新環境時、您必須執行最後一次同步。使用一般檔案系統時、由於原始的重作記錄會複製並重新播放、因此很容易確保移轉的資料庫與原始資料庫 100% 同步。使用 ASM 執行此作業的方法並不理想。只有歸檔日誌可以輕鬆地重新記錄。為了確保不會遺失任何資料、必須謹慎執行原始資料庫的最終關機。

  1. 首先、必須將資料庫暫時禁用、確保不會進行任何變更。這種停止可能包括停用排程作業、關閉接聽程式及 / 或關閉應用程式。

  2. 執行此步驟後、大多數 DBA 會建立一個虛擬表格、做為關機的標記。

  3. 強制記錄歸檔、以確保在歸檔記錄檔中記錄建立虛擬表格。若要這麼做、請執行下列命令:

    SQL> create table cutovercheck as select * from dba_users;
    Table created.
    SQL> alter system archive log current;
    System altered.
    SQL> shutdown immediate;
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
  4. 若要複製最後一個歸檔記錄檔、請執行下列命令。資料庫必須可用、但不可開啟。

    SQL> startup mount;
    ORACLE instance started.
    Total System Global Area  805306368 bytes
    Fixed Size                  2929552 bytes
    Variable Size             331353200 bytes
    Database Buffers          465567744 bytes
    Redo Buffers                5455872 bytes
    Database mounted.
  5. 若要複製歸檔記錄檔、請執行下列命令:

    RMAN> configure channel device type disk format '/rman/pancake/logship/%h_%e_%a.dbf';
    2> backup as copy archivelog from time 'sysdate-2';
    3>
    4>
    using target database control file instead of recovery catalog
    old RMAN configuration parameters:
    CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/rman/pancake/logship/%h_%e_%a.dbf';
    new RMAN configuration parameters:
    CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/rman/pancake/logship/%h_%e_%a.dbf';
    new RMAN configuration parameters are successfully stored
    Starting backup at 24-MAY-16
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=8 device type=DISK
    channel ORA_DISK_1: starting archived log copy
    input archived log thread=1 sequence=54 RECID=123 STAMP=912659482
    RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/24/2016 04:58:24
    ORA-19635: input and output file names are identical: /rman/pancake/logship/1_54_912576125.dbf
    continuing other job steps, job failed will not be re-run
    ...
    channel ORA_DISK_1: starting archived log copy
    input archived log thread=1 sequence=45 RECID=152 STAMP=912659514
    RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/24/2016 04:58:58
    ORA-19635: input and output file names are identical: /rman/pancake/logship/1_45_912576125.dbf
    continuing other job steps, job failed will not be re-run
    channel ORA_DISK_1: starting archived log copy
    input archived log thread=1 sequence=47 RECID=153 STAMP=912659515
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/24/2016 04:59:00
    ORA-19635: input and output file names are identical: /rman/pancake/logship/1_47_912576125.dbf
  6. 最後、在新伺服器上重播剩餘的歸檔記錄。

    [root@jfsc2 pancake]# ./replaylogs.pl PANCAKE
    ORACLE_SID = [oracle] ? The Oracle base has been set to /orabin
    SQL*Plus: Release 12.1.0.2.0 Production on Tue May 24 05:00:53 2016
    Copyright (c) 1982, 2014, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
    SQL> ORA-00279: change 563137 generated at 05/24/2016 04:36:20 needed for thread 1
    ORA-00289: suggestion : /rman/pancake/logship/1_65_912576125.dbf
    ORA-00280: change 563137 for thread 1 is in sequence #65
    Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
    ORA-00279: change 563629 generated at 05/24/2016 04:55:20 needed for thread 1
    ORA-00289: suggestion : /rman/pancake/logship/1_66_912576125.dbf
    ORA-00280: change 563629 for thread 1 is in sequence #66
    ORA-00278: log file '/rman/pancake/logship/1_65_912576125.dbf' no longer needed
    for this recovery
    ORA-00308: cannot open archived log '/rman/pancake/logship/1_66_912576125.dbf'
    ORA-27037: unable to obtain file status
    Linux-x86_64 Error: 2: No such file or directory
    Additional information: 3
    SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
  7. 在此階段、複寫所有資料。資料庫已準備好從待命資料庫轉換為作用中的作業資料庫、然後開啟。

    SQL> alter database activate standby database;
    Database altered.
    SQL> alter database open;
    Database altered.
  8. 確認虛擬表格是否存在、然後將其丟棄。

    SQL> desc cutovercheck
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     USERNAME                                  NOT NULL VARCHAR2(128)
     USER_ID                                   NOT NULL NUMBER
     PASSWORD                                           VARCHAR2(4000)
     ACCOUNT_STATUS                            NOT NULL VARCHAR2(32)
     LOCK_DATE                                          DATE
     EXPIRY_DATE                                        DATE
     DEFAULT_TABLESPACE                        NOT NULL VARCHAR2(30)
     TEMPORARY_TABLESPACE                      NOT NULL VARCHAR2(30)
     CREATED                                   NOT NULL DATE
     PROFILE                                   NOT NULL VARCHAR2(128)
     INITIAL_RSRC_CONSUMER_GROUP                        VARCHAR2(128)
     EXTERNAL_NAME                                      VARCHAR2(4000)
     PASSWORD_VERSIONS                                  VARCHAR2(12)
     EDITIONS_ENABLED                                   VARCHAR2(1)
     AUTHENTICATION_TYPE                                VARCHAR2(8)
     PROXY_ONLY_CONNECT                                 VARCHAR2(1)
     COMMON                                             VARCHAR2(3)
     LAST_LOGIN                                         TIMESTAMP(9) WITH TIME ZONE
     ORACLE_MAINTAINED                                  VARCHAR2(1)
    SQL> drop table cutovercheck;
    Table dropped.

不中斷的重作記錄移轉

有時資料庫會在整體上正確組織、但重做記錄除外。這可能是因為許多原因、其中最常見的原因與快照有關。SnapManager for Oracle 、 SnapCenter 和 NetApp Snap Creator 儲存管理架構等產品可讓您近乎即時地恢復資料庫、但前提是您必須還原資料檔案磁碟區的狀態。如果重做記錄檔與資料檔案共用空間、則無法安全執行還原、因為還原會導致重做記錄檔毀損、這可能表示資料遺失。因此、重做記錄必須重新定位。

此程序很簡單、可在不中斷營運的情況下執行。

目前的重做記錄組態

  1. 識別重做記錄群組的數目及其各自的群組編號。

    SQL> select group#||' '||member from v$logfile;
    GROUP#||''||MEMBER
    --------------------------------------------------------------------------------
    1 /redo0/NTAP/redo01a.log
    1 /redo1/NTAP/redo01b.log
    2 /redo0/NTAP/redo02a.log
    2 /redo1/NTAP/redo02b.log
    3 /redo0/NTAP/redo03a.log
    3 /redo1/NTAP/redo03b.log
    rows selected.
  2. 輸入重做記錄檔的大小。

    SQL> select group#||' '||bytes from v$log;
    GROUP#||''||BYTES
    --------------------------------------------------------------------------------
    1 524288000
    2 524288000
    3 524288000

建立新記錄

  1. 針對每個重做記錄、建立一個大小和成員數目相符的新群組。

    SQL> alter database add logfile ('/newredo0/redo01a.log', '/newredo1/redo01b.log') size 500M;
    Database altered.
    SQL> alter database add logfile ('/newredo0/redo02a.log', '/newredo1/redo02b.log') size 500M;
    Database altered.
    SQL> alter database add logfile ('/newredo0/redo03a.log', '/newredo1/redo03b.log') size 500M;
    Database altered.
    SQL>
  2. 驗證新組態。

    SQL> select group#||' '||member from v$logfile;
    GROUP#||''||MEMBER
    --------------------------------------------------------------------------------
    1 /redo0/NTAP/redo01a.log
    1 /redo1/NTAP/redo01b.log
    2 /redo0/NTAP/redo02a.log
    2 /redo1/NTAP/redo02b.log
    3 /redo0/NTAP/redo03a.log
    3 /redo1/NTAP/redo03b.log
    4 /newredo0/redo01a.log
    4 /newredo1/redo01b.log
    5 /newredo0/redo02a.log
    5 /newredo1/redo02b.log
    6 /newredo0/redo03a.log
    6 /newredo1/redo03b.log
    12 rows selected.

刪除舊記錄

  1. 刪除舊記錄(群組 1 、 2 和 3 )。

    SQL> alter database drop logfile group 1;
    Database altered.
    SQL> alter database drop logfile group 2;
    Database altered.
    SQL> alter database drop logfile group 3;
    Database altered.
  2. 如果您遇到錯誤、導致無法刪除作用中記錄、請強制切換至下一個記錄檔、以釋放鎖定並強制建立全域檢查點。請參閱下列此程序範例。由於此記錄檔中仍有作用中的資料、因此拒絕嘗試丟棄位於舊位置的記錄檔群組 2 。

    SQL> alter database drop logfile group 2;
    alter database drop logfile group 2
    *
    ERROR at line 1:
    ORA-01623: log 2 is current log for instance NTAP (thread 1) - cannot drop
    ORA-00312: online log 2 thread 1: '/redo0/NTAP/redo02a.log'
    ORA-00312: online log 2 thread 1: '/redo1/NTAP/redo02b.log'
  3. 記錄歸檔之後再加上檢查點、可讓您捨棄記錄檔。

    SQL> alter system archive log current;
    System altered.
    SQL> alter system checkpoint;
    System altered.
    SQL> alter database drop logfile group 2;
    Database altered.
  4. 然後從檔案系統刪除記錄。您應該非常小心地執行此程序。