Step By Step Configure DataGuard (10g) Physical Standby Database On Linux X86_64(2/2)

djb1008發表於2010-09-06

本文承接http://djb1008.itpub.net/post/42280/504822

[oracle@standbydb archivelog]$ pwd

/oradata/archivelog

[oracle@standbydb archivelog]$ ls -lt *

standby_arc:

total 47820

-rw-r----- 1 oracle oinstall 286208 Sep 3 18:41 1_212_724504451.dbf

-rw-r----- 1 oracle oinstall 197120 Sep 3 18:32 1_211_724504451.dbf

-rw-r----- 1 oracle oinstall 4096 Sep 3 18:31 1_210_724504451.dbf

-rw-r----- 1 oracle oinstall 48413184 Sep 3 18:31 1_209_724504451.dbf

primary_arc:

total 0

[@more@]

我們可以看到歸檔日誌檔案從主節點複製到了備節點,並且得到了應用。

[oracle@standbydb archivelog]$ sqlplus / as sysdba

SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;

SEQUENCE# FIRST_TIM NEXT_TIME

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

209 03-SEP-10 03-SEP-10

210 03-SEP-10 03-SEP-10

211 03-SEP-10 03-SEP-10

212 03-SEP-10 03-SEP-10

SQL> SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;

SEQUENCE# APP

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

209 YES

210 YES

211 YES

212 YES

到目前位置,主備資料庫環境已經完全搭建完成了,並投入使用。搭建的是Physical Standby Database。

. 主備資料庫切換

注意:

主庫伺服器的名稱為:primarydb,備庫伺服器的名稱為:standbydb。在下面的指令碼中可以透過命令列前面的提示符可以知道在那臺伺服器上執行的。例如"[oracle@primarydb /]$",就可以看出是在主庫伺服器上執行。

  1. 生產環境從主庫伺服器切換到備庫伺服器

1.1 停止主庫執行

[oracle@primarydb /]$ sqlplus / as sysdba

SQL> alter database commit to switchover to physical standby;

Database altered.

SQL> shutdown immediate;

ORA-01507: database notmount

ORACLE instance shut down.

1.2 將主庫執行在standby database狀態

[oracle@primarydb /]$ sqlplus / as sysdba

SQL> startup nomount;

ORACLE instance started.

Total System Global Area 1073741824 bytes

Fixed Size 2089472 bytes

Variable Size 578817536 bytes

Database Buffers 490733568 bytes

Redo Buffers 2101248 bytes

SQL> alter database mount standby database;

Database altered.

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

Database altered.

1.3 啟動備庫為生產環境

[oracle@standbydb ~]$ sqlplus / as sysdba

SQL> alter database commit to switchover to primary;

Database altered

備庫的alert日誌描述如下:

[oracle@standbydb ~]$tail -f alert_gridctl.log

alter database commit to switchover to primary

Mon Sep 6 11:24:30 2010

ALTER DATABASE SWITCHOVER TO PRIMARY (gridctl)

Mon Sep 6 11:24:30 2010

If media recovery active, switchover will wait 900 seconds

SwitchOver after complete recovery through change 9735881

Standby became primary SCN: 9735879

Converting standby mount to primary mount.

Mon Sep 6 11:24:34 2010

Switchover: Complete - Database mounted as primary (gridctl)

Completed: alter database commit to switchover to primary

SQL>shutdown immediate;

ORA-01507: database notmount

ORACLE instance shut down.

SQL>startup

ORACLE instance started.

。。。。。。

Database mounted.

Database opened.

1.4 修改主庫伺服器的引數log_archive_dest_2為空

[oracle@primarydb /]$ sqlplus / as sysdba

SQL> show parameter log_archive_dest_2

NAME TYPE VALUE

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

log_archive_dest_2 string service=standby mandatory reop

en=60

SQL>ALTER SYSTEM SET log_archive_dest_2='' SCOPE=BOTH;

1.5 修改備庫伺服器的引數log_archive_dest_2,將日誌應用到主庫伺服器

[oracle@standbydb ~]$ sqlplus / as sysdba

SQL> alter system set log_archive_dest_2='service=primary mandatory reopen=60' scope=both;

1.6 檢視備庫伺服器上資料庫的角色狀態,並進行日切換

[oracle@standbydb ~]$ sqlplus / as sysdba

SQL> select open_mode,database_role from v$database;

OPEN_MODE DATABASE_ROLE

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

READ WRITE PRIMARY

SQL> alter system switch logfile;

System altered.

1.7 檢查主庫伺服器的資料庫角色狀態,並檢視alert日誌檔案,驗證日誌是否得到了應用

[oracle@primarydb /]$ sqlplus / as sysdba

SQL> select open_mode,database_role from v$database;

OPEN_MODE DATABASE_ROLE

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

MOUNTED PHYSICAL STANDBY

[oracle@standbydb ~]$tail -f alert_gridctl.log

Mon Sep 6 16:15:20 2010

RFS[1]: Archived Log: '/oradata/archivelog/standby_arc/1_237_724504451.dbf'

Mon Sep 6 16:15:23 2010

Media Recovery Log /oradata/archivelog/standby_arc/1_237_724504451.dbf

Media Recovery Waiting for thread 1 sequence 238

  1. 生產環境從備庫伺服器切換回主庫伺服器

2.1 備庫伺服器將資料庫角色從primary轉換為standby

[oracle@standbydb ~]$ sqlplus / as sysdba

SQL> select open_mode,database_role from v$database;

OPEN_MODE DATABASE_ROLE

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

READ WRITE PRIMARY

SQL> alter database commit to switchover to standby;

SQL> shutdown immediate;

ORA-01507: database not mounted

ORACLE instance shut down.

SQL> startup nomount;

ORACLE instance started.

Total System Global Area 1073741824 bytes

Fixed Size 2089472 bytes

Variable Size 578817536 bytes

Database Buffers 490733568 bytes

Redo Buffers 2101248 bytes

SQL> alter database mount standby database;

SQL> alter system set log_archive_dest_2='' scope=both;

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

SQL> select open_mode,database_role from v$database;

OPEN_MODE DATABASE_ROLE

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

MOUNTED PHYSICAL STANDBY

2.2 主庫伺服器將資料庫角色從standby轉換為primary

[oracle@primarydb /]$ sqlplus / as sysdba

SQL> select open_mode,database_role from v$database;

OPEN_MODE DATABASE_ROLE

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

MOUNTED PHYSICAL STANDBY

SQL> alter database commit to switchover to primary;

SQL> shutdown immediate;

ORA-01109: database not open

Database dismounted.

ORACLE instance shut down.

SQL> startup

ORACLE instance started.

Total System Global Area 1073741824 bytes

Fixed Size 2089472 bytes

Variable Size 578817536 bytes

Database Buffers 490733568 bytes

Redo Buffers 2101248 bytes

Database mounted.

Database opened.

SQL> alter system set log_archive_dest_2='service=standby mandatory reopen=60' scope=both;

SQL> select open_mode,database_role from v$database;

OPEN_MODE DATABASE_ROLE

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

READ WRITE PRIMARY

SQL> alter system switch logfile;

檢視備庫伺服器的alert日誌檔案,可以看到來自主庫伺服器的日誌得到了應用。

[oracle@standbydb ~]$ tail -f alert_gridctl.log

。。。。。。

Media Recovery Log /oradata/archivelog/standby_arc/1_240_724504451.dbf

Media Recovery Log /oradata/archivelog/standby_arc/1_241_724504451.dbf

Media Recovery Waiting for thread 1 sequence 242

切換到此完成。

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

相關文章