利用STANDBY將單例項資料庫升級為RAC環境(二)

yangtingkun發表於2009-12-11

利用OracleSTANDBY技術,可以將單例項資料庫升級到RAC資料庫。這種方式可以有效的降低單例項遷移到RAC環境的停機時間。

這篇文章介紹STANDBY資料庫的建立。

利用STANDBY將單例項資料庫升級為RAC環境(一):http://yangtingkun.itpub.net/post/468/494736

 

 

上一篇完成了絕大部分準備的工作,下面在開啟資料庫之前,還要設定一下目標資料庫上的密碼檔案。

STANDBYRAC環境的兩個節點上分別複製密碼檔案:

bash-3.00$ cd $ORACLE_HOME/dbs
bash-3.00$ ftp 172.0.2.61
Connected to 172.0.2.61.
220 netdb1 FTP server ready.
Name (172.0.2.61:oracle): oracle
331 Password required for oracle.
Password:
230 User oracle logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> bin
200 Type set to I.
ftp> cd /data/oracle/product/11.1/dbs
250 CWD command successful.
ftp> prompt
Interactive mode off.
ftp> mget orapwtest11g
200 PORT command successful.
150 Opening BINARY mode data connection for orapwtest11g (1536 bytes).
226 Transfer complete.
local: orapwtest11g remote: orapwtest11g
1536 bytes received in 0.017 seconds (87.65 Kbytes/s)
ftp> exit
?Invalid command
ftp> quit
221-You have transferred 1536 bytes in 1 files.
221-Total traffic for this session was 2229 bytes in 2 transfers.
221-Thank you for using the FTP service on netdb1.
221 Goodbye.

bash-3.00$ mv orapwtest11g orapwtest11gr1

在節點2上,密碼檔案應該重新命名為orapwtest11gr2

修改STANDBY資料庫節點1上的監聽配置,在SID_LIST_LISTENER的配置中,新增test11gr1的配置:

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = rac11g1)
      (ORACLE_HOME = /data/oracle/product/11.1/database)
    )
    (SID_DESC =
      (SID_NAME = test11gr1)
      (ORACLE_HOME = /data/oracle/product/11.1/database)
    )
  )

下面重啟監聽:

bash-3.00$ lsnrctl stop

LSNRCTL for Solaris: Version 11.1.0.6.0 - Production on 13-7 -2009 17:21:39

Copyright (c) 1991, 2007, Oracle.  All rights reserved.

正在連線到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ser1-vip)(PORT=1521)))
命令執行成功
bash-3.00$ lsnrctl start

LSNRCTL for Solaris: Version 11.1.0.6.0 - Production on 13-7 -2009 17:21:42

Copyright (c) 1991, 2007, Oracle.  All rights reserved.

啟動/data/oracle/product/11.1/database/bin/tnslsnr: 請稍候...

TNSLSNR for Solaris: Version 11.1.0.6.0 - Production
系統引數檔案為/data/oracle/product/11.1/database/network/admin/listener.ora
寫入/data/oracle/diag/tnslsnr/ser1/listener/alert/log.xml的日誌資訊
監聽: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.0.2.68)(PORT=1521)))
監聽: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ser1)(PORT=1521)))
監聽: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))

正在連線到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ser1-vip)(PORT=1521)))
LISTENER
STATUS
------------------------
別名                      LISTENER
版本                      TNSLSNR for Solaris: Version 11.1.0.6.0 - Production
啟動日期                  13-7 -2009 17:21:42
正常執行時間              0 0 小時 0 0
跟蹤級別                  off
安全性                    ON: Local OS Authentication
SNMP                      OFF
監聽程式引數檔案          /data/oracle/product/11.1/database/network/admin/listener.ora
監聽程式日誌檔案          /data/oracle/diag/tnslsnr/ser1/listener/alert/log.xml
監聽端點概要...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.0.2.68)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ser1)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))
服務摘要..
服務 "rac11g1" 包含 1 個例程。
 
例程 "rac11g1", 狀態 UNKNOWN, 包含此服務的 1 個處理程式...
服務 "test11gr1" 包含 1 個例程。
 
例程 "test11gr1", 狀態 UNKNOWN, 包含此服務的 1 個處理程式...
命令執行成功

修改兩個節點上的TNSNAMES.ORA的配置,新增主庫的配置:

TEST11G =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.0.2.61)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = TEST11G.netdb)
      (SERVER = DEDICATED)
    )
  )

確保STANDBY資料庫可以透過服務名訪問主庫:

bash-3.00$ tnsping test11g

TNS Ping Utility for Solaris: Version 11.1.0.6.0 - Production on 13-7 -2009 17:33:07

Copyright (c) 1997, 2007, Oracle.  All rights reserved.

已使用的引數檔案:


已使用 TNSNAMES 介面卡來解析別名
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.0.2.61)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = NEW11G.netdb) (SERVER = DEDICATED)))
OK (10
毫秒)

監測ASM例項是否已經啟動,如果ASM沒有啟動,透過srvctl start asm的方式啟動ASM例項:

bash-3.00$ export ORACLE_SID=+ASM1
bash-3.00$ sqlplus "/ as sysdba"

SQL*Plus: Release 11.1.0.6.0 - Production on 星期三 7 15 15:09:08 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


連線到:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options

SQL> select instance_name, status from v$instance;

INSTANCE_NAME                    STATUS
-------------------------------- ------------------------
+ASM1                            STARTED

SQL> select instance_name, status from gv$instance;

INSTANCE_NAME                    STATUS
-------------------------------- ------------------------
+ASM1                            STARTED
+ASM2                            STARTED

SQL> select name from v$asm_diskgroup;

NAME
------------------------------------------------------------
DATA

下面就可以在RAC的節點1上嘗試啟動STANDBY資料庫。

bash-3.00$ export ORACLE_SID=test11gr1
bash-3.00$ sqlplus "/ as sysdba"

SQL*Plus: Release 11.1.0.6.0 - Production on 星期一 7 13 16:47:52 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

已連線到空閒例程。

SQL> startup nomount pfile=/export/home/oracle/inittest11gr1.ora
ORACLE
例程已經啟動。

Total System Global Area 7418036224 bytes
Fixed Size                  2095808 bytes
Variable Size            3183650112 bytes
Database Buffers         4227858432 bytes
Redo Buffers                4431872 bytes
SQL> alter database mount;

資料庫已更改。

SQL> alter database recover managed standby database disconnect from session;

資料庫已更改。

至此STANDBY資料庫已經建立成功。

檢查STANDBY資料庫的狀態:

SQL> select pid, status, client_process, group#, resetlog_id, thread#, sequence#
  2  from v$managed_standby;

       PID STATUS       CLIENT_P GROUP#     RESETLOG_ID    THREAD#  SEQUENCE#
---------- ------------ -------- ---------- ----------- ---------- ----------
     24384 CONNECTED    ARCH     N/A                  0          0          0
     24386 CONNECTED    ARCH     N/A                  0          0          0
     24388 CONNECTED    ARCH     N/A                  0          0          0
     24395 CONNECTED    ARCH     N/A                  0          0          0
     24549 WAIT_FOR_LOG N/A      N/A          683602501          1        156
     26208 IDLE         UNKNOWN  N/A                  0          0          0
     26214 IDLE         UNKNOWN  N/A                  0          0          0
     26229 IDLE         UNKNOWN  N/A                  0          0          0
      7061 IDLE         LGWR     3            683602501          1        156

已選擇9行。

堅持主資料庫的歸檔情況:

SQL> select name, dest_id, thread#, sequence#, creator
  2  from v$archived_log
  3  where sequence# = 155;

NAME                                                   DEST_ID  THREAD#  SEQUENCE# CREATOR
----------------------------------------------------- -------- -------- ---------- --------
TEST11GR                                                     2        1        155 LGWR
/data/oradata/test11g/archivelog/1_155_683602501.dbf         1        1        155 ARCH

現在STANDBY的進度已經和主庫保持一致了。

下面關閉恢復歸檔狀態,並已只讀方式開啟資料庫:

SQL> alter database recover managed standby database cancel;

資料庫已更改。

SQL> alter database open read only;

資料庫已更改。

檢查例項狀態:

SQL> select instance_name, status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
test11gr1        OPEN

SQL> select instance_name, status from gv$instance;

INSTANCE_NAME    STATUS
---------------- ------------
test11gr1        OPEN

ASM上建立共享的SPFILE檔案:

SQL> create spfile = '+DATA/TEST11G/spfiletest11gr.ora'              
  2  from pfile = '/export/home/oracle/inittest11gr1.ora';

檔案已建立。

在例項2對應的節點上,嘗試只讀方式開啟資料庫:

bash-3.00$ echo spfile=+DATA/TEST11G/spfiletest11gr.ora >> /export/home/oracle/inittest11gr2.ora
bash-3.00$ more /export/home/oracle/inittest11gr2.ora
spfile=+DATA/TEST11G/spfiletest11gr.ora
bash-3.00$ export ORACLE_SID=test11gr2
bash-3.00$ sqlplus "/ as sysdba"

SQL*Plus: Release 11.1.0.6.0 - Production on 星期五 7 17 19:37:32 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

已連線到空閒例程。

SQL> startup open read only pfile=/export/home/oracle/inittest11gr2.ora
ORACLE
例程已經啟動。

Total System Global Area 7418036224 bytes
Fixed Size                  2095808 bytes
Variable Size            3250758976 bytes
Database Buffers         4160749568 bytes
Redo Buffers                4431872 bytes
資料庫裝載完畢。
資料庫已經開啟。
SQL> select instance_name, status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
test11gr2        OPEN

SQL> select instance_name, status from gv$instance;

INSTANCE_NAME    STATUS
---------------- ------------
test11gr2        OPEN
test11gr1        OPEN

檢查資料庫資訊:

SQL> select name, db_unique_name, primary_db_unique_name, database_role
  2  from v$database;

NAME      DB_UNIQUE_NAME                 PRIMARY_DB_UNIQUE_NAME         DATABASE_ROLE
--------- ------------------------------ ------------------------------ ----------------
TEST11G   TEST11GR                       TEST11G                        PHYSICAL STANDBY

至此單例項資料庫的RAC環境STANDBY資料庫建立完成。

下面可以準備進行SWITCHOVER切換了。

 

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

相關文章