【DATAGUARD】物理dg的switchover切換(五)

Appleses發表於2016-01-30

DATAGUARD】物理dgswitchover切換(五)

1.1  BLOG文件結構圖

 

image

 

1.2  前言部分

 

1.2.1  導讀

各位技術愛好者,看完本文後,你可以掌握如下的技能,也可以學到一些其它你所不知道的知識,~O(∩_∩)O~:

物理dg的switchover切換演練過程

物理dg管理和維護的一些sql

 

注意:本篇BLOG中程式碼部分需要特別關注的地方我都用黃色背景和紅色字型來表示,比如下邊的例子中,thread 1的最大歸檔日誌號為33thread 2的最大歸檔日誌號為43是需要特別關注的地方。

  List of Archived Logs in backup set 11

  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time

  ---- ------- ---------- ------------------- ---------- ---------

  1    32      1621589    2015-05-29 11:09:52 1625242    2015-05-29 11:15:48

  1    33      1625242    2015-05-29 11:15:48 1625293    2015-05-29 11:15:58

  2    42      1613951    2015-05-29 10:41:18 1625245    2015-05-29 11:15:49

  2    43      1625245    2015-05-29 11:15:49 1625253    2015-05-29 11:15:53

 

 

 

 

 

本文如有錯誤或不完善的地方請大家多多指正,ITPUB留言或QQ皆可,您的批評指正是我寫作的最大動力。

1.2.2  實驗環境介紹

 

 專案

主庫

dg

db 型別

單例項

單例項

db version

11.2.0.3

11.2.0.3

db 儲存

FS type

FS type

ORACLE_SID

oradg11g

oradgphy

db_name

oradg11g

oradg11g

主機IP地址:

192.168.59.130

192.168.59.130

OS版本及kernel版本

RHEL6.5 64位,2.6.32-504.16.2.el6.x86_64

RHEL6.5 64位,2.6.32-504.16.2.el6.x86_64

OS hostname

rhel6_lhr

rhel6_lhr

 

 

 

1.2.3  相關參考文章連結

 

【DATAGUARD】 基於同一個主機建立物理備庫和邏輯備庫(一): http://blog.itpub.net/26736162/viewspace-1448197/
【DATAGUARD】 基於同一個主機建立物理備庫和邏輯備庫(二 ):  http://blog.itpub.net/26736162/viewspace-1448207/
【DATAGUARD】 基於同一個主機建立物理備庫和邏輯備庫(三 ):  http://blog.itpub.net/26736162/viewspace-1481972/
【DATAGUARD】 基於同一個主機建立物理備庫和邏輯備庫 (四)--新增一個物理dg節點 :http://blog.itpub.net/26736162/viewspace-1484878/

 

 

1.2.4  本文簡介

 

這段時間比較忙,一直沒有更新blog了,看了大神們一直在堅持寫blog,真心佩服。這幾天一個客戶要搭建物理dg,順便演示switchover的切換,這裡我整理了一下共享出來,希望對大家有用,本次實驗的環境基於http://blog.itpub.net/26736162/viewspace-1448197/ 文章中搭建的環境,下一章中介紹failover的切換。

 

 

1.3  相關知識點掃盲

1.角色

Oracle 資料庫中含有兩種角色。

使用者角色:定義了一組許可權的集合,該角色可以分配給使用者,也可以分配給其他角色。

資料庫角色:在備庫中資料庫扮演什麼樣的角色,primary還是standby。

v$database.DATABASE_ROLE標識了資料庫的執行角色。

處於備庫環境中,資料庫有兩種型別:phsical standby、logical standby。

2.角色管理服務

一個資料庫執行在如下互相排斥的角色中。

Primary role:一個資料庫執行在primary role,那麼log transport services傳遞重做日誌到備庫。

Standby role:一個資料庫執行在standby role,那麼log apply services應用歸檔日誌到備庫。

角色管理服務允許使用者動態地在主、備庫中進行角色切換。

使用者可以使用角色管理服務,進行主、備庫的計劃中的角色切換,這個叫switchover,或者是非計劃中的角色切換,叫failover。

3.Switchover&Failover

切換是在主資料庫與其備資料庫之間進行角色反轉,切換確保不丟失資料。這是對於主系統計劃維護的典型操作。在切換期間,主資料庫轉換到備角色,備資料庫轉換到主角色。轉換髮生不需要重建任何資料庫。

(1)Switchover

用到的場景:計劃中的角色轉換或使用者作業系統和硬體的維護等。

(2)Failover

故障轉移是當主資料庫不可用時執行的。故障轉移只有在主資料庫災難故障的情況下執行,並且故障轉移導致備資料庫轉換到主角色。用到的場景:非計劃中的角色切換,一般在緊急情況下使用。根據保護模式的不同,可能會沒有或者很少的資料損失。

(3)角色轉換決策樹

角色轉換(switchover&failover)的最終目的是儘快地使主庫線上,而同時儘量減少資料損失或者是實現無資料損失。儘量選擇當機時間最短,同時資料損失最小的策略。總之在失敗切換前,應該先考慮修復主資料庫或者進行無資料損失的角色轉換。

即使使用無資料損失的備庫方案,修復主庫可能會比切換到備庫更快點。如果修復了主庫,那麼就不需要修改客戶端的連線。但是如果修復工作導致了任何的資料損失,那麼可能需要重新建立所有的備用資料庫。

通常情況下,最合適切換的備庫為已經應用了最多的歸檔日誌的備用資料庫。

 

 

 

 

1.4  實驗部分

 

1.4.1  實驗目標

 

 

① 主庫和物理dgswitchover切換

② 還原為最初始的狀態

 

1.4.2  實驗過程

 

1.4.2.1  主庫oradg11g的引數設定檢查

 

這裡主要有2個內容需要檢測:

① fal_clientfal_serverstandby_file_managementdb_file_name_convert log_filename_convert是否合理

② standbylog file 是否已經建立

 

[oracle@rhel6_lhr ~]$ echo $ORACLE_SID

oradg11g

[oracle@rhel6_lhr ~]$

[oracle@rhel6_lhr ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on 星期日 7月 26 17:33:53 2015

 

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

 

 

連線到:

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

17:33:53 SQL> col name format a25

17:33:55 SQL> col VALUE format a20

17:33:55 SQL> SELECT a.NAME,a.VALUE

17:33:55   2  FROM   v$parameter a

17:33:55   3  WHERE  a.NAME LIKE '%file_name_convert'

17:33:55   4  OR     a.NAME LIKE 'fal%'

17:33:55   5  OR     a.NAME LIKE 'standby_file%';

 

NAME                      VALUE

------------------------- --------------------

db_file_name_convert      oradgphy, oradg11g

log_file_name_convert     oradgphy, oradg11g

fal_client                oradg11g

fal_server                oradgphy

standby_file_management   AUTO

 

已用時間:  00: 00: 00.01

17:33:56 SQL>

20:32:09 SQL> set line 9999 pagesize 9999

20:36:47 SQL> col  db_id  format a15

20:36:47 SQL> select  GROUP#, DBID db_id, THREAD#, SEQUENCE#, BYTES,  USED, ARCHIVED, STATUS, FIRST_CHANGE#,  NEXT_CHANGE#,LAST_CHANGE# from v$standby_log ;

 

    GROUP# DB_ID              THREAD#  SEQUENCE#      BYTES       USED ARC STATUS     FIRST_CHANGE# NEXT_CHANGE# LAST_CHANGE#

---------- --------------- ---------- ---------- ---------- ---------- --- ---------- ------------- ------------ ------------

         4 UNASSIGNED               1          0   52428800          0 YES UNASSIGNED

         5 UNASSIGNED               1          0   52428800          0 YES UNASSIGNED

         6 UNASSIGNED               0          0   52428800          0 YES UNASSIGNED

         7 UNASSIGNED               0          0   52428800          0 YES UNASSIGNED

 

已用時間:  00: 00: 00.02

20:36:47 SQL> select * from v$logfile;

 

    GROUP# STATUS  TYPE    MEMBER                                                                                                                                                                                     IS_

---------- ------- ------- --------------------------------------------------- ---

         3         ONLINE  /u01/app/oracle/oradata/oradg11g/redo03.log                                                                                                                                                NO

         2         ONLINE  /u01/app/oracle/oradata/oradg11g/redo02.log                                                                                                                                                NO

         1         ONLINE  /u01/app/oracle/oradata/oradg11g/redo01.log                                                                                                                                                NO

         4         STANDBY /u01/app/oracle/oradata/oradg11g/standby_redo04.log                                                                                                                                        NO

         5         STANDBY /u01/app/oracle/oradata/oradg11g/standby_redo05.log                                                                                                                                        NO

         6         STANDBY /u01/app/oracle/oradata/oradg11g/standby_redo06.log                                                                                                                                        NO

         7         STANDBY /u01/app/oracle/oradata/oradg11g/standby_redo07.log                                                                                                                                        NO

 

已選擇7行。

 

已用時間:  00: 00: 00.00

20:37:00 SQL> ! ls  /u01/app/oracle/oradata/oradg11g/standby*

/u01/app/oracle/oradata/oradg11g/standby_redo04.log  /u01/app/oracle/oradata/oradg11g/standby_redo06.log

/u01/app/oracle/oradata/oradg11g/standby_redo05.log  /u01/app/oracle/oradata/oradg11g/standby_redo07.log

 

20:37:11 SQL>

 

1.4.2.2  主庫oradg11g執行切換

17:35:45 SQL> select name, LOG_MODE, OPEN_MODE, database_role, SWITCHOVER_STATUS, db_unique_name from v$database;

 

NAME      LOG_MODE     OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS    DB_UNIQUE_NAME

--------- ------------ -------------------- ---------------- -------------------- ------------------------------

ORADG11G  ARCHIVELOG   READ WRITE          PRIMARY          TO STANDBY           oradg11g

 

已用時間:  00: 00: 00.01

17:35:46 SQL> alter database commit to switchover to physical standby with session shutdown;

 

資料庫已更改。

 

已用時間:  00: 00: 06.22

17:36:14 SQL> shutdown immediate

ORA-01092: ORACLE instance terminated. Disconnection forced

17:36:35 SQL> ORA-24324: 未初始化服務控制程式碼

ORA-01041: 內部錯誤, hostdef 副檔名不存在

17:36:35 SQL> exit

從 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options 斷開

[oracle@rhel6_lhr ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on 星期日 7月 26 17:36:39 2015

 

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

 

已連線到空閒例程。

 

17:36:39 SQL> startup  mount;

ORACLE 例程已經啟動。

 

Total System Global Area  325685248 bytes

Fixed Size                  2228064 bytes

Variable Size             192938144 bytes

Database Buffers          125829120 bytes

Redo Buffers                4689920 bytes

資料庫裝載完畢。

17:36:52 SQL> select name, LOG_MODE, OPEN_MODE, database_role, SWITCHOVER_STATUS, db_unique_name from v$database;

 

NAME      LOG_MODE     OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS    DB_UNIQUE_NAME

--------- ------------ -------------------- ---------------- -------------------- ------------------------------

ORADG11G  ARCHIVELOG   MOUNTED             PHYSICAL STANDBY RECOVERY NEEDED      oradg11g

 

已用時間:  00: 00: 00.01

17:37:04 SQL>

 

告警日誌:

Sun Jul 26 17:36:07 2015

alter database commit to switchover to physical standby with session shutdown

ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY [Process Id: 37669] (oradg11g)

Sun Jul 26 17:36:07 2015

Thread 1 advanced to log sequence 127 (LGWR switch)

  Current log# 1 seq# 127 mem# 0: /u01/app/oracle/oradata/oradg11g/redo01.log

Sun Jul 26 17:36:07 2015

Stopping background process CJQ0

Stopping background process QMNC

All dispatchers and shared servers shutdown

CLOSE: killing server sessions.

Active process 37415 user 'grid' program 'oracle@rhel6_lhr'

Active process 37413 user 'grid' program 'oracle@rhel6_lhr'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37415 user 'grid' program 'oracle@rhel6_lhr'

Active process 37413 user 'grid' program 'oracle@rhel6_lhr'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37415 user 'grid' program 'oracle@rhel6_lhr'

Active process 37413 user 'grid' program 'oracle@rhel6_lhr'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37415 user 'grid' program 'oracle@rhel6_lhr'

Active process 37413 user 'grid' program 'oracle@rhel6_lhr'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37415 user 'grid' program 'oracle@rhel6_lhr'

Active process 37413 user 'grid' program 'oracle@rhel6_lhr'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37415 user 'grid' program 'oracle@rhel6_lhr'

Active process 37413 user 'grid' program 'oracle@rhel6_lhr'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37415 user 'grid' program 'oracle@rhel6_lhr'

Active process 37413 user 'grid' program 'oracle@rhel6_lhr'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37415 user 'grid' program 'oracle@rhel6_lhr'

Active process 37413 user 'grid' program 'oracle@rhel6_lhr'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37415 user 'grid' program 'oracle@rhel6_lhr'

Active process 37413 user 'grid' program 'oracle@rhel6_lhr'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37415 user 'grid' program 'oracle@rhel6_lhr'

Active process 37413 user 'grid' program 'oracle@rhel6_lhr'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37415 user 'grid' program 'oracle@rhel6_lhr'

Active process 37413 user 'grid' program 'oracle@rhel6_lhr'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37415 user 'grid' program 'oracle@rhel6_lhr'

Active process 37413 user 'grid' program 'oracle@rhel6_lhr'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37415 user 'grid' program 'oracle@rhel6_lhr'

Active process 37413 user 'grid' program 'oracle@rhel6_lhr'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37415 user 'grid' program 'oracle@rhel6_lhr'

Active process 37413 user 'grid' program 'oracle@rhel6_lhr'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

Active process 37483 user 'oracle' program 'oracle@rhel6_lhr (W000)'

CLOSE: all sessions shutdown successfully.

Waiting for all non-current ORLs to be archived...

Waiting for the ORL for thread 1 sequence 126 to be archived...

Sun Jul 26 17:36:11 2015

Archived Log entry 349 added for thread 1 sequence 126 ID 0x5441e6d9 dest 1:

ORL for thread 1 sequence 126 has been archived...

All non-current ORLs have been archived.

Waiting for all FAL entries to be archived...

All FAL entries have been archived.

Waiting for potential Physical Standby switchover target to become synchronized...

Active, synchronized Physical Standby switchover target has been identified

Switchover End-Of-Redo Log thread 1 sequence 127 has been fixed

Switchover: Primary highest seen SCN set to 0x0.0x1a1f6f

ARCH: Noswitch archival of thread 1, sequence 127

ARCH: End-Of-Redo Branch archival of thread 1 sequence 127

ARCH: LGWR is actively archiving destination LOG_ARCHIVE_DEST_2

ARCH: Standby redo logfile selected for thread 1 sequence 127 for destination LOG_ARCHIVE_DEST_2

Archived Log entry 350 added for thread 1 sequence 127 ID 0x5441e6d9 dest 1:

ARCH: Archiving is disabled due to current logfile archival

Primary will check for some target standby to have received alls redo

Final check for a synchronized target standby. Check will be made once.

LOG_ARCHIVE_DEST_2 is a potential Physical Standby switchover target

Active, synchronized target has been identified

Target has also received all redo

Backup controlfile written to trace file /u01/app/oracle/diag/rdbms/oradg11g/oradg11g/trace/oradg11g_ora_37669.trc

Clearing standby activation ID 1413605081 (0x5441e6d9)

The primary database controlfile was created using the

'MAXLOGFILES 16' clause.

There is space for up to 13 standby redo logfiles

Use the following SQL commands on the standby database to create

standby redo logfiles that match the primary database:

ALTER DATABASE ADD STANDBY LOGFILE 'srl1.f' SIZE 52428800;

ALTER DATABASE ADD STANDBY LOGFILE 'srl2.f' SIZE 52428800;

ALTER DATABASE ADD STANDBY LOGFILE 'srl3.f' SIZE 52428800;

ALTER DATABASE ADD STANDBY LOGFILE 'srl4.f' SIZE 52428800;

Archivelog for thread 1 sequence 127 required for standby recovery

Switchover: Primary controlfile converted to standby controlfile succesfully.

Switchover: Complete - Database shutdown required

Completed: alter database commit to switchover to physical standby with session shutdown

Sun Jul 26 17:36:15 2015

Process (ospid 26918) is suspended due to switchover to physical standby operation.

 

 

Sun Jul 26 17:36:33 2015

Performing implicit shutdown abort due to switchover to physical standby

Shutting down instance (abort)

License high water mark = 7

USER (ospid: 37669): terminating the instance

Instance terminated by USER, pid = 37669

Sun Jul 26 17:36:35 2015

Instance shutdown complete

ORA-1092 : opitsk aborting process

Sun Jul 26 17:36:44 2015

Starting ORACLE instance (normal)

****************** Large Pages Information *****************

 

Total Shared Global Region in Large Pages = 0 KB (0%)

 

Large Pages used by this instance: 0 (0 KB)

Large Pages unused system wide = 0 (0 KB) (alloc incr 4096 KB)

Large Pages configured system wide = 0 (0 KB)

Large Page size = 2048 KB

 

RECOMMENDATION:

  Total Shared Global Region size is 314 MB. For optimal performance,

  prior to the next instance restart increase the number

  of unused Large Pages by atleast 157 2048 KB Large Pages (314 MB)

  system wide to get 100% of the Shared

  Global Region allocated with Large pages

***********************************************************

LICENSE_MAX_SESSION = 0

LICENSE_SESSIONS_WARNING = 0

Picked latch-free SCN scheme 3

Autotune of undo retention is turned on.

IMODE=BR

ILAT =27

LICENSE_MAX_USERS = 0

SYS auditing is disabled

Starting up:

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options.

ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1

System name:    Linux

Node name:      rhel6_lhr

Release:        2.6.32-504.16.2.el6.x86_64

Version:        #1 SMP Tue Apr 21 08:37:59 PDT 2015

Machine:        x86_64

VM name:        VMWare Version: 6

Using parameter settings in server-side spfile /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileoradg11g.ora

System parameters with non-default values:

  processes                = 150

  sga_target               = 312M

  control_files            = "/u01/app/oracle/oradata/oradg11g/control01.ctl"

  control_files            = "/u01/app/oracle/flash_recovery_area/oradg11g/control02.ctl"

  db_file_name_convert     = "oradgphy"

  db_file_name_convert     = "oradg11g"

  log_file_name_convert    = "oradgphy"

  log_file_name_convert    = "oradg11g"

  db_block_size            = 8192

  compatible               = "11.2.0.0.0"

  log_archive_dest_1       = "LOCATION=USE_DB_RECOVERY_FILE_DEST db_unique_name=oradg11g valid_for=(ALL_LOGFILES,ALL_ROLES)"

  log_archive_dest_2       = "SERVICE=tns_oradgphy LGWR ASYNC db_unique_name=oradgphy valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE)"

  log_archive_dest_3       = "SERVICE=tns_oradglg LGWR ASYNC db_unique_name=oradglg valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE)"

  log_archive_dest_4       = "SERVICE=tns_oradgss LGWR ASYNC db_unique_name=oradgss valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE)"

  log_archive_dest_state_1 = "ENABLE"

  log_archive_dest_state_2 = "ENABLE"

  log_archive_dest_state_3 = "defer"

  log_archive_dest_state_4 = "defer"

  fal_client               = "oradg11g"

  fal_server               = "oradgphy"

  log_archive_config       = "DG_CONFIG=(oradg11g,oradgphy,oradglg,oradgss)"

  log_archive_max_processes= 6

  db_recovery_file_dest    = "/u01/app/oracle/flash_recovery_area"

  db_recovery_file_dest_size= 4122M

  standby_file_management  = "AUTO"

  undo_tablespace          = "UNDOTBS1"

  remote_login_passwordfile= "EXCLUSIVE"

  db_domain                = ""

  dispatchers              = "(PROTOCOL=TCP) (SERVICE=oradg11gXDB)"

  audit_file_dest          = "/u01/app/oracle/admin/oradg11g/adump"

  audit_trail              = "DB"

  db_name                  = "oradg11g"

  db_unique_name           = "oradg11g"

  open_cursors             = 300

  pga_aggregate_target     = 78M

  diagnostic_dest          = "/u01/app/oracle"

Sun Jul 26 17:36:45 2015

PMON started with pid=2, OS id=37709

Sun Jul 26 17:36:45 2015

PSP0 started with pid=3, OS id=37711

Sun Jul 26 17:36:46 2015

VKTM started with pid=4, OS id=37713 at elevated priority

VKTM running at (1)millisec precision with DBRM quantum (100)ms

Sun Jul 26 17:36:46 2015

GEN0 started with pid=5, OS id=37717

Sun Jul 26 17:36:46 2015

 

 

這一步容易出現問題,注意下邊的問題:

alter database commit to switchover to physical standby with session shutdown;

稍等。。。。等待資料庫掛掉後再啟動到mount,千萬別shutdown immediate,應該用shutdown abort,等待告警日誌中出現如下提示再進行下一步操作,否則可能導致switchover切換失敗,主庫將不可用

--Switchover: Primary controlfile converted to standby controlfile succesfully.

--Switchover: Complete - Database shutdown required

--Completed: alter database commit to switchover to physical standby with session shutdown

--Sun Jul 26 17:36:15 2015

--Process (ospid 26918) is suspended due to switchover to physical standby operation.

 

 

 

1.4.2.3  備庫oradgphy執行切換

[oracle@rhel6_lhr admin]$ echo $ORACLE_SID

oradgphy

[oracle@rhel6_lhr admin]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on 星期日 7月 26 17:40:24 2015

 

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

 

 

連線到:

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

17:40:24 SQL> select name, LOG_MODE, OPEN_MODE, database_role, SWITCHOVER_STATUS, db_unique_name from v$database;

 

NAME      LOG_MODE     OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS    DB_UNIQUE_NAME

--------- ------------ -------------------- ---------------- -------------------- ------------------------------

ORADG11G  ARCHIVELOG   READ ONLY WITH APPLY PHYSICAL STANDBY TO PRIMARY           oradgphy

 

已用時間:  00: 00: 00.01

17:40:28 SQL> alter database commit to switchover to primary with session shutdown;

 

資料庫已更改。

 

已用時間:  00: 00: 02.07

17:40:44 SQL> select name, LOG_MODE, OPEN_MODE, database_role, SWITCHOVER_STATUS, db_unique_name from v$database;

 

NAME      LOG_MODE     OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS    DB_UNIQUE_NAME

--------- ------------ -------------------- ---------------- -------------------- ------------------------------

ORADG11G  ARCHIVELOG   MOUNTED             PRIMARY          NOT ALLOWED          oradgphy

 

已用時間:  00: 00: 00.01

17:40:56 SQL>

17:42:47 SQL> alter database open;

 

資料庫已更改。

 

已用時間:  00: 00: 01.88

17:43:04 SQL>

 

告警日誌:

Sun Jul 26 17:40:42 2015

alter database commit to switchover to primary with session shutdown

ALTER DATABASE SWITCHOVER TO PRIMARY (oradgphy)

Maximum wait for role transition is 15 minutes.

Switchover: Media recovery is still active

Role Change: Canceling MRP - no more redo to apply

Sun Jul 26 17:40:44 2015

MRP0: Background Media Recovery cancelled with status 16037

Errors in file /u01/app/oracle/diag/rdbms/oradgphy/oradgphy/trace/oradgphy_pr00_28229.trc:

ORA-16037: user requested cancel of managed recovery operation

Managed Standby Recovery not using Real Time Apply

Recovery interrupted!

Sun Jul 26 17:40:44 2015

MRP0: Background Media Recovery process shutdown (oradgphy)

Role Change: Canceled MRP

All dispatchers and shared servers shutdown

CLOSE: killing server sessions.

CLOSE: all sessions shutdown successfully.

Sun Jul 26 17:40:44 2015

SMON: disabling cache recovery

Backup controlfile written to trace file /u01/app/oracle/diag/rdbms/oradgphy/oradgphy/trace/oradgphy_ora_37868.trc

SwitchOver after complete recovery through change 1711983

Online log /u01/app/oracle/oradata/oradgphy/redo01.log: Thread 1 Group 1 was previously cleared

Online log /u01/app/oracle/oradata/oradgphy/redo02.log: Thread 1 Group 2 was previously cleared

Online log /u01/app/oracle/oradata/oradgphy/redo03.log: Thread 1 Group 3 was previously cleared

Standby became primary SCN: 1711981

AUDIT_TRAIL initialization parameter is changed back to its original value as specified in the parameter file.

Switchover: Complete - Database mounted as primary

Completed: alter database commit to switchover to primary with session shutdown

Sun Jul 26 17:41:14 2015

idle dispatcher 'D000' terminated, pid = (17, 1)

 

1.4.2.4  新備庫oradg11g開啟實時應用

[oracle@rhel6_lhr ~]$ echo $ORACLE_SID

oradg11g

[oracle@rhel6_lhr ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on 星期日 7月 26 17:45:47 2015

 

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

 

 

連線到:

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

17:45:47 SQL>  select name, LOG_MODE, OPEN_MODE, database_role, SWITCHOVER_STATUS, db_unique_name from v$database;

 

NAME      LOG_MODE     OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS    DB_UNIQUE_NAME

--------- ------------ -------------------- ---------------- -------------------- ------------------------------

ORADG11G  ARCHIVELOG   MOUNTED             PHYSICAL STANDBY RECOVERY NEEDED      oradg11g

 

已用時間:  00: 00: 00.01

17:45:53 SQL> alter database recover managed standby database using current logfile disconnect;

 

資料庫已更改。

 

已用時間:  00: 00: 06.02

17:46:13 SQL> alter database recover managed standby database cancel;

 

資料庫已更改。

 

已用時間:  00: 00: 01.48

17:46:16 SQL> alter database open;

 

資料庫已更改。

 

已用時間:  00: 00: 00.56

17:46:21 SQL> alter database recover managed standby database using current logfile disconnect;

 

資料庫已更改。

 

已用時間:  00: 00: 06.02

17:46:35 SQL>

 

1.4.2.5  測試切換後的情況

 

17:47:42 SQL> select name, LOG_MODE, OPEN_MODE, database_role, SWITCHOVER_STATUS, db_unique_name from v$database;

 

NAME      LOG_MODE     OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS    DB_UNIQUE_

--------- ------------ -------------------- ---------------- -------------------- ----------

ORADG11G  ARCHIVELOG   READ WRITE           PRIMARY          TO STANDBY           oradgphy

 

已用時間:  00: 00: 00.00

17:47:54 SQL> create table test as select * from scott.emp;

 

表已建立。

 

已用時間:  00: 00: 00.86

17:48:21 SQL> select count(1) from test;

 

  COUNT(1)

----------

        14

 

已用時間:  00: 00: 00.00

17:50:27 SQL>

17:50:27 SQL> conn sys/lhr@tns_oradg11g as sysdba

已連線。

17:50:42 SQL> select count(1) from test;

 

  COUNT(1)

----------

        14

 

已用時間:  00: 00: 00.01

17:50:46 SQL> conn sys/lhr@tns_oradgphy as sysdba

已連線。

17:51:08 SQL> drop table test;

 

表已刪除。

 

已用時間:  00: 00: 01.14

17:51:13 SQL> conn sys/lhr@tns_oradgphy as sysdba

已連線。

17:51:17 SQL> conn sys/lhr@tns_oradg11g as sysdba

已連線。

17:51:21 SQL> select count(1) from test;

select count(1) from test

                     *

第 1 行出現錯誤:

ORA-00942: 表或檢視不存在

 

 

已用時間:  00: 00: 00.00

17:51:24 SQL>

1.4.2.6  切換回原來最初的狀態

新主庫ordgphy操作:

 

20:28:43 SQL> alter database commit to switchover to physical standby with session shutdown;

 

資料庫已更改。

 

已用時間:  00: 00: 04.65

20:30:01 SQL> shutdown immediate

ORA-01092: ORACLE instance terminated. Disconnection forced

20:30:33 SQL> startup  mount;

ORA-24324: 未初始化服務控制程式碼

ORA-01041: 內部錯誤, hostdef 副檔名不存在

20:30:41 SQL> exit

從 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options 斷開

[oracle@rhel6_lhr admin]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on 星期日 7月 26 20:30:45 2015

 

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

 

已連線到空閒例程。

 

20:30:45 SQL> startup  mount;

ORACLE 例程已經啟動。

 

Total System Global Area  242171904 bytes

Fixed Size                  2227256 bytes

Variable Size             188744648 bytes

Database Buffers           46137344 bytes

Redo Buffers                5062656 bytes

資料庫裝載完畢。

 

新備庫oradg11g操作:

20:28:46 SQL> select name, LOG_MODE, OPEN_MODE, database_role, SWITCHOVER_STATUS, db_unique_name from v$database;

 

NAME      LOG_MODE     OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS    DB_UNIQUE_NAME

--------- ------------ -------------------- ---------------- -------------------- ------------------------------

ORADG11G  ARCHIVELOG   READ ONLY WITH APPLY PHYSICAL STANDBY TO PRIMARY           oradg11g

 

已用時間:  00: 00: 00.01

20:31:20 SQL> alter database commit to switchover to primary with session shutdown;

 

資料庫已更改。

 

已用時間:  00: 00: 02.07

20:31:32 SQL> alter database open;

 

資料庫已更改。

 

已用時間:  00: 00: 00.34

20:31:38 SQL> select name, LOG_MODE, OPEN_MODE, database_role, SWITCHOVER_STATUS, db_unique_name from v$database;

 

NAME      LOG_MODE     OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS    DB_UNIQUE_NAME

--------- ------------ -------------------- ---------------- -------------------- ------------------------------

ORADG11G  ARCHIVELOG   READ WRITE           PRIMARY          RESOLVABLE GAP       oradg11g

 

已用時間:  00: 00: 00.00

 

 

oradgphy 操作:

20:30:54 SQL> alter database recover managed standby database using current logfile disconnect;

 

資料庫已更改。

 

已用時間:  00: 00: 06.04

20:32:23 SQL> alter database recover managed standby database cancel;

 

資料庫已更改。

 

已用時間:  00: 00: 01.01

20:32:36 SQL> alter database open;

 

資料庫已更改。

 

已用時間:  00: 00: 00.21

20:32:42 SQL> alter database recover managed standby database using current logfile disconnect;

 

 

資料庫已更改。

 

已用時間:  00: 00: 06.02

20:32:53 SQL> 20:32:53 SQL>  select name, LOG_MODE, OPEN_MODE, database_role, SWITCHOVER_STATUS, db_unique_name from v$database;

 

NAME      LOG_MODE     OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS    DB_UNIQUE_NAME

--------- ------------ -------------------- ---------------- -------------------- ------------------------------

ORADG11G  ARCHIVELOG   READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED          oradgphy

 

已用時間:  00: 00: 00.00

20:33:21 SQL>

 

OK,切換完成。

 

 

 

1.4.3  實驗總結

 

切換過程中尤其注意主庫執行alter database commit to switchover to physical standby with session shutdown;後需要等待資料庫abort掉,或者我們手動的shutdown abort,否則可能導致實驗失敗,主庫脫離dg環境不可用從而變為了failover切換了,所以實驗之前還是對主庫做rman備份比較穩妥一些。

 

 

1.5  總結

 

進行Dataguard switchoverfailover是非常常見的運維需求,在實際場景下,我們儘可能選擇穩妥完全的策略進行操作SQL命令還是我們比較好的選擇多操作幾次就熟悉了

 

 

 





About Me

.............................................................................................................................................

● 本文作者:小麥苗,只專注於資料庫的技術,更注重技術的運用

● 本文在itpub(http://blog.itpub.net/26736162/abstract/1/)、部落格園(http://www.cnblogs.com/lhrbest)和個人微信公眾號(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/viewspace-1753111/

● 本文部落格園地址:http://www.cnblogs.com/lhrbest

● 本文pdf版、個人簡介及小麥苗雲盤地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 資料庫筆試面試題庫及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● DBA寶典今日頭條號地址:

.............................................................................................................................................

● QQ群號:230161599(滿)、618766405

● 微信群:可加我微信,我拉大家進群,非誠勿擾

● 聯絡我請加QQ好友646634621,註明新增緣由

● 於 2015-07-26 09:00~ 2015-07-27 19:00 在魔都完成

● 文章內容來源於小麥苗的學習筆記,部分整理自網路,若有侵權或不當之處還請諒解

● 版權所有,歡迎分享本文,轉載請保留出處

.............................................................................................................................................

小麥苗的微店

小麥苗出版的資料庫類叢書http://blog.itpub.net/26736162/viewspace-2142121/

.............................................................................................................................................

使用微信客戶端掃描下面的二維碼來關注小麥苗的微信公眾號(xiaomaimiaolhr)及QQ群(DBA寶典),學習最實用的資料庫技術。

   小麥苗的微信公眾號      小麥苗的DBA寶典QQ群1     小麥苗的DBA寶典QQ群2        小麥苗的微店

.............................................................................................................................................

【DATAGUARD】物理dg的switchover切換(五)
DBA筆試面試講解群1
DBA筆試面試講解群2
歡迎與我聯絡



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

相關文章