Oracle遷移:Linux->Windows

kunlunzhiying發表於2017-01-02

源環境:RHEL6.4 + Oracle 11.2.0.4
目的環境:Windows 2003
需求:研發測試環境的Oracle資料庫從Linux遷移到Windows,可以停機。

1.Windows安裝同版本資料庫軟體

首先在MOS上確定Oracle Database 11.2.0.4.0 已在 Microsoft Windows x64 (64-bit) 2003 上透過認證。
然後在MOS上下載11.2.0.4的安裝介質

p13390677_112040_MSWIN-x86-64_1of7.zip p13390677_112040_MSWIN-x86-64_2of7.zip

注意:
本次安裝時選擇 "僅安裝資料庫軟體" -> "單例項資料庫安裝"

2.Windows使用oradim建立例項

在Windows系統上,Oracle連線到例項需要此步驟,
本案例建立例項vas,sqlplus登入到vas例項的具體過程:

C:\Documents and Settings\Administrator>oradim -NEW -SID vas
例項已建立。

C:\Documents and Settings\Administrator>set ORACLE_SID=vas

C:\Documents and Settings\Administrator>echo %ORACLE_SID%
vas

C:\Documents and Settings\Administrator>sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on 星期日 214 12:38:48 2016 Copyright (c) 1982, 2013, Oracle.  All rights reserved.

已連線到空閒例程。

SQL>

關於oradim命令,具體參考官檔:Database Administrator's Guide -> 2 Creating and Configuring an Oracle Database -> Creating a Database with the CREATE DATABASE Statement部分的步驟5:

Step 5: (Windows Only) Create an Instance
On the Windows platform, before you can connect to an instance, you must manually create it if it does not already exist. The ORADIM command creates an Oracle instance by creating a new Windows service.

To create an instance:

Enter the following command at a Windows command prompt:

oradim -NEW -SID sid -STARTMODE MANUAL -PFILE pfile
where sid is the desired SID (for example mynewdb) and pfile is the full path to the text initialization parameter file. This command creates the instance but does not start it.

步驟14,修改為自動啟動

Step 14: (Optional) Enable Automatic Instance Startup
You might want to configure the Oracle instance to start automatically when its host computer restarts. See your operating system documentation for instructions. For example, on Windows, use the following command to configure the database service to start the instance upon computer restart:

ORADIM -EDIT -SID sid -STARTMODE AUTO -SRVCSTART SYSTEM [-SPFILE]
You must use the -SPFILE argument if you want the instance to read an SPFILE upon automatic restart.

我們還可以直接透過oradim -h看到oradim命令的說明幫助:

C:\Documents and Settings\Administrator>oradim -h DIM-00002: 指定的命令無效。
輸入以下命令之一:
透過指定以下選項建立例項:
     -NEW -SID sid | -SRVC srvc | -ASMSID sid | -ASMSRVC srvc [-SYSPWD pass]
 [-STARTMODE auto|manual] [-SRVCSTART system|demand] [-PFILE file | -SPFILE]
 [-SHUTMODE normal|immediate|abort] [-TIMEOUT secs] [-RUNAS osusr/ospass]
透過指定以下選項編輯例項:
     -EDIT -SID sid | -ASMSID sid [-SYSPWD pass]
 [-STARTMODE auto|manual] [-SRVCSTART system|demand] [-PFILE file | -SPFILE]
 [-SHUTMODE normal|immediate|abort] [-SHUTTYPE srvc|inst] [-RUNAS osusr/ospass]
透過指定以下選項刪除例項:
     -DELETE -SID sid | -ASMSID sid | -SRVC srvc | -ASMSRVC srvc
透過指定以下選項啟動服務和例項:
     -STARTUP -SID sid | -ASMSID sid [-SYSPWD pass]
 [-STARTTYPE srvc|inst|srvc,inst] [-PFILE filename | -SPFILE]
透過指定以下選項關閉服務和例項:
     -SHUTDOWN -SID sid | -ASMSID sid [-SYSPWD pass]
 [-SHUTTYPE srvc|inst|srvc,inst] [-SHUTMODE normal|immediate|abort]
 透過指定以下引數查詢幫助: -? | -h | -help

oradim命令幾個常用的引數:

--建立例項vas oradim -NEW -SID vas --刪除例項vas oradim -DELETE -SID vas --編輯例項vas oradim -EDIT -SID vas -STARTMODE auto -SRVCSTART system

3.Windows建立密碼檔案

Windows上Oracle的密碼檔案和Linux上Oracle的密碼檔案,預設規範路徑有點區別。
Windows平臺,Oracle密碼檔案在%ORACLE_HOME%/database/下;名稱是PWD.ora;
Unix/Linux平臺,Oracle密碼檔案在$ORACLE_HOME/dbs/下;名稱一般是orapw;
類似的,Oracle引數檔案的預設路徑也是這種區別。

--建立密碼檔案
orapwd file=F:\app\Administrator\product\11.2.0\dbhome_1\database\PWDvas.ora password=oracle

4.Linux建立pfile,正常關閉資料庫

--Linux建立pfile SQL> create pfile='/tmp/pfile20160214.ora' from spfile; File created.

--正常關閉資料庫 SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down.

5.Linux複製所有檔案到Windows

使用FileZilla 工具複製:
二進位制模式傳輸 所有控制檔案、資料檔案、重做日誌檔案、臨時檔案(可選)到Windows規劃目錄下。
ASCII模式傳輸pfile引數檔案。

查詢資料庫所有控制檔案、資料檔案、重做日誌檔案、臨時檔案(可選)資訊:

select name from v$controlfile union all select name from v$datafile union all select member from v$logfile union all select name from v$tempfile;

6.Windows修改pfile,指定控制檔案路徑

Windows修改pfile,修改引數檔案中的值,比如adump的路徑等,尤其注意指定控制檔案的路徑。
修改的pfile檔案全路徑是:%ORACLE_HOME%\database\pfilevas.ora
然後,

--啟動資料庫到nomount狀態 startup nomount pfile='%ORACLE_HOME%\database\pfilevas.ora' --更改資料庫到mount狀態 alter database mount; --根據pfile檔案,建立spfile檔案 create spfile='spfilevas.ora' from pfile='%ORACLE_HOME%\database\pfilevas.ora'; 

7.Windows備份控制檔案,重建控制檔案(noresetlog)

7.1 Windows備份控制檔案

SQL> alter database backup controlfile to trace; 
--生成的跟蹤檔案預設路徑為user_dump_dest引數指向的目錄下。

7.2 選取noresetlog部分重建控制檔案

--選取noresetlog部分重建控制檔案 --     Set #1. NORESETLOGS case -- -- The following commands will create a new control file and use it -- to open the database. -- Data used by Recovery Manager will be lost. -- Additional logs may be required for media recovery of offline -- Use this only if the current versions of all online logs are -- available. -- After mounting the created controlfile, the following SQL -- statement will place the database in the appropriate -- protection mode: --  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE STARTUP NOMOUNT CREATE CONTROLFILE REUSE DATABASE "VAS" NORESETLOGS NOARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 ( '/oradata/VAS/onlinelog/o1_mf_1_c1cm3pwr_.log', '/opt/app/oracle11/fast_recovery_area/VAS/onlinelog/o1_mf_1_c1cm3rn6_.log' ) SIZE 1024M BLOCKSIZE 512, GROUP 2 ( '/oradata/VAS/onlinelog/o1_mf_2_c1cm5nfs_.log', '/opt/app/oracle11/fast_recovery_area/VAS/onlinelog/o1_mf_2_c1cm5p2b_.log' ) SIZE 1024M BLOCKSIZE 512, GROUP 3 ( '/oradata/VAS/onlinelog/o1_mf_3_c1cm7l3v_.log', '/opt/app/oracle11/fast_recovery_area/VAS/onlinelog/o1_mf_3_c1cm7mnh_.log' ) SIZE 1024M BLOCKSIZE 512 -- STANDBY LOGFILE DATAFILE '/oradata/VAS/datafile/o1_mf_system_c1cm0o2x_.dbf', '/oradata/VAS/datafile/o1_mf_sysaux_c1cm0o5j_.dbf', '/oradata/VAS/datafile/o1_mf_undotbs1_c1cm0o7x_.dbf', '/oradata/VAS/datafile/o1_mf_users_c1cm0obx_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_dcdl_c1cndg32_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_d_cr_c1cnhxj3_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_icdl_c1cnj30n_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_d_cd_c1cnj8dk_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_d_cr_c1cnjg2t_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_d_ne_c1cnjmdh_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_d_pe_c1cnjrjv_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_d_rn_c1cnjy27_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_d_wo_c1cnk3lg_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_i_cd_c1cnk999_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_i_cr_c1cnkhct_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_i_ne_c1cnknpc_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_i_pe_c1cnksy1_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_i_rn_c1cnkz2m_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_i_wo_c1cnl4ny_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_cssp_c5qdmmgl_.dbf', '/oradata/VAS/datafile/o1_mf_dbs_d_ba_c5qdmtcz_.dbf' CHARACTER SET ZHS16GBK
; -- Commands to re-create incarnation table -- Below log names MUST be changed to existing filenames on -- disk. Any one log file from each branch can be used to -- re-create incarnation records. -- ALTER DATABASE REGISTER LOGFILE 'F:\APP\ADMINISTRATOR\FAST_RECOVERY_AREA\VAS\ARCHIVELOG\2016_02_14\O1_MF_1_1_%U_.ARC'; -- ALTER DATABASE REGISTER LOGFILE 'F:\APP\ADMINISTRATOR\FAST_RECOVERY_AREA\VAS\ARCHIVELOG\2016_02_14\O1_MF_1_1_%U_.ARC'; -- Recovery is required if any of the datafiles are restored backups, -- or if the last shutdown was not normal or immediate. RECOVER DATABASE -- Database can now be opened normally. ALTER DATABASE OPEN; -- Commands to add tempfiles to temporary tablespaces. -- Online tempfiles have complete space information. -- Other tempfiles may require adjustment. ALTER TABLESPACE TEMP ADD TEMPFILE '/oradata/VAS/datafile/o1_mf_temp_c1cm9jph_.tmp' REUSE; -- End of tempfile additions.

7.3 正常關閉資料庫

SQL> shutdown immediate;

7.4 重建控制檔案

把7.2部分中的內容根據實際情況修改如下:

--選取noresetlog部分重建控制檔案(修改過) --     Set #1. NORESETLOGS case -- -- The following commands will create a new control file and use it -- to open the database. -- Data used by Recovery Manager will be lost. -- Additional logs may be required for media recovery of offline -- Use this only if the current versions of all online logs are -- available. -- After mounting the created controlfile, the following SQL -- statement will place the database in the appropriate -- protection mode: --  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE STARTUP NOMOUNT CREATE CONTROLFILE REUSE DATABASE "VAS" NORESETLOGS NOARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 ( 'F:\oradata\VAS\onlinelog\o1_mf_1_c1cm3pwr_.log' ) SIZE 1024M BLOCKSIZE 512, GROUP 2 ( 'F:\oradata\VAS\onlinelog\o1_mf_2_c1cm5nfs_.log' ) SIZE 1024M BLOCKSIZE 512, GROUP 3 ( 'F:\oradata\VAS\onlinelog\o1_mf_3_c1cm7l3v_.log' ) SIZE 1024M BLOCKSIZE 512 -- STANDBY LOGFILE DATAFILE 'F:\oradata\VAS\datafile\o1_mf_system_c1cm0o2x_.dbf', 'F:\oradata\VAS\datafile\o1_mf_sysaux_c1cm0o5j_.dbf', 'F:\oradata\VAS\datafile\o1_mf_undotbs1_c1cm0o7x_.dbf', 'F:\oradata\VAS\datafile\o1_mf_users_c1cm0obx_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_dcdl_c1cndg32_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_d_cr_c1cnhxj3_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_icdl_c1cnj30n_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_d_cd_c1cnj8dk_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_d_cr_c1cnjg2t_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_d_ne_c1cnjmdh_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_d_pe_c1cnjrjv_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_d_rn_c1cnjy27_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_d_wo_c1cnk3lg_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_i_cd_c1cnk999_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_i_cr_c1cnkhct_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_i_ne_c1cnknpc_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_i_pe_c1cnksy1_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_i_rn_c1cnkz2m_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_i_wo_c1cnl4ny_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_cssp_c5qdmmgl_.dbf', 'F:\oradata\VAS\datafile\o1_mf_dbs_d_ba_c5qdmtcz_.dbf' CHARACTER SET ZHS16GBK
; -- Commands to re-create incarnation table -- Below log names MUST be changed to existing filenames on -- disk. Any one log file from each branch can be used to -- re-create incarnation records. -- ALTER DATABASE REGISTER LOGFILE 'F:\APP\ADMINISTRATOR\FAST_RECOVERY_AREA\VAS\ARCHIVELOG\2016_02_14\O1_MF_1_1_%U_.ARC'; -- ALTER DATABASE REGISTER LOGFILE 'F:\APP\ADMINISTRATOR\FAST_RECOVERY_AREA\VAS\ARCHIVELOG\2016_02_14\O1_MF_1_1_%U_.ARC'; -- Recovery is required if any of the datafiles are restored backups, -- or if the last shutdown was not normal or immediate. RECOVER DATABASE -- Database can now be opened normally. ALTER DATABASE OPEN; -- Commands to add tempfiles to temporary tablespaces. -- Online tempfiles have complete space information. -- Other tempfiles may require adjustment. ALTER TABLESPACE TEMP ADD TEMPFILE 'F:\oradata\VAS\datafile\o1_mf_temp_c1cm9jph_.tmp' REUSE; -- End of tempfile additions.

至此已經在Windows上成功開啟資料庫。

8.Windows後續配置


8.1 監聽配置

在%ORACLE_HOME%/NETWORK\ADMIN\listener.ora加上以下內容

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = F:\app\Administrator\product\11.2.0\dbhome_1)
      (PROGRAM = extproc)
      (ENVS = "EXTPROC_DLLS=ONLY:F:\app\Administrator\product\11.2.0\dbhome_1\bin\oraclr11.dll")
    )
    (SID_DESC =
      (GLOBAL_DBNAME = vas)
      (ORACLE_HOME = F:\app\Administrator\product\11.2.0\dbhome_1)
      (SID_NAME = vas)
    )
  )

然後啟動監聽

lsnrctl start

8.2 環境變數

ORACLE_SID=vas

8.3 Oracle服務自動啟動

oradim -EDIT -SID vas -STARTMODE auto -SRVCSTART system

8.4 資料檔案關閉自動擴充套件(選做)

根據空間具體情況而定。

至此,此次oracle資料庫從linux平臺遷移到windows平臺的遷移需求就全部完成了



特別說明: 本文轉自 http://www.cnblogs.com/jyzhao/p/5189169.html

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28211342/viewspace-2131772/,如需轉載,請註明出處,否則將追究法律責任。

相關文章