dataguard讀書筆記

foxmile發表於2007-12-23
1、主從庫均Install Oracle 9i,且只選擇安裝軟體,不建立資料庫

2. 在主庫上使用DBCA,建立dbguard例項

3. 建立測試環境,主庫建立之後將以前有的一個邏輯備份匯入主庫。

4. 修改資料庫為歸檔方式

SQL*Plus: Release 9.2.0.1.0 - Production on 星期二 10月 9 20:02:24 2007

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

SQL> connect sys/sys as sysdba;

SQL> startup mount;

SQL> alter database archivelog;

SQL> alter system set log_archive_dest_1='c:\arc_zero' scope=both;

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

SQL> alter system set log_archive_start=true scope=spfile;

SQL> alter database open;

SQL> archive log list;
資料庫日誌模式            存檔模式
自動存檔             啟用
存檔終點            C:\arc_zero
最早的概要日誌序列     29
下一個存檔日誌序列   31
當前日誌序列           31
SQL> show parameter archive

NAME                                 TYPE                 VALUE
------------------------------------ -------------------- --------------------
archive_lag_target                   integer              0
log_archive_dest                     string
log_archive_dest_1                   string               LOCATION=C:\arc_zero
log_archive_dest_10                  string
log_archive_dest_2                   string               service=standby
log_archive_dest_3                   string
log_archive_dest_4                   string
log_archive_dest_5                   string
log_archive_dest_6                   string
log_archive_dest_7                   string
log_archive_dest_8                   string

NAME                                 TYPE                 VALUE
------------------------------------ -------------------- --------------------
log_archive_dest_9                   string
log_archive_dest_state_1             string               enable
log_archive_dest_state_10            string               enable
log_archive_dest_state_2             string               enable
log_archive_dest_state_3             string               enable
log_archive_dest_state_4             string               enable
log_archive_dest_state_5             string               enable
log_archive_dest_state_6             string               enable
log_archive_dest_state_7             string               enable
log_archive_dest_state_8             string               enable
log_archive_dest_state_9             string               enable

NAME                                 TYPE                 VALUE
------------------------------------ -------------------- --------------------
log_archive_duplex_dest              string
log_archive_format                   string               ARC%S.%T
log_archive_max_processes            integer              2
log_archive_min_succeed_dest         integer              1
log_archive_start                    boolean              FALSE
log_archive_trace                    integer              0
remote_archive_enable                string               true
standby_archive_dest                 string               %ORACLE_HOME%\RDBMS
SQL>
SQL> shutdown immediate;
 


5. 建立standby 控制檔案和便於修改的pfile

SQL> alter database force logging;

資料庫已更改。

SQL> select name,force_logging from v$database;

NAME FOR

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

DBGUARD YES

SQL> create pfile='c:\standbypfile.ora' from spfile;

檔案已建立。

SQL> alter database create standby controlfile as 'c:\oraclecontrol01.ctl';


6. 確定需要複製相應的資料檔案、日誌檔案等,並關閉資料庫

SQL> select file_name from dba_data_files;

SQL> select file_name from dba_data_files;

FILE_NAME
----------------------------------------------
D:\ORACLE\ORADATA\ZERO\SYSTEM01.DBF
D:\ORACLE\ORADATA\ZERO\UNDOTBS01.DBF
D:\ORACLE\ORADATA\ZERO\DRSYS01.DBF
D:\ORACLE\ORADATA\ZERO\INDX01.DBF
D:\ORACLE\ORADATA\ZERO\TOOLS01.DBF
D:\ORACLE\ORADATA\ZERO\USERS01.DBF
D:\ORACLE\ORADATA\ZERO\XDB01.DBF
D:\ORACLE\ORADATA\ZERO\MOF.ORA

已選擇8行。


SQL> select member from v$logfile;

MEMBER
------------------------------------------------
D:\ORACLE\ORADATA\ZERO\REDO03.LOG
D:\ORACLE\ORADATA\ZERO\REDO02.LOG
D:\ORACLE\ORADATA\ZERO\REDO01.LOG

7. 建立standby伺服器相應的Oracle目錄,並把主庫檔案複製到standby機器的指定目錄下

Mkdir d:\oracle\admin\zero\bdump

Mkdir d:\oracle\admin\zero\cdump

Mkdir d:\oracle\admin\zero\create

Mkdir d:\oracle\admin\zero\pfile

Mkdir d:\oracle\admin\zero\udump

Mkdir D:\oracle\oradata\zero

Mkdir C:\arc_zero
 


8. 建立dbguard的window服務

Oradim –NEW –SID zero –STARDMODE manual
 
複製透過主庫建立的standby控制檔案,並分別複製為control02.ctl,control03.ctl,並複製到相應的目錄下

複製透過主庫建立的引數檔案並加以修改,新增以下資訊

*.standby_archive_dest='c:\arc_zero'
*.fal_client='satndby'
*.fal_server='primary'
*.standby_file_management='auto'
*.remote_archive_enable='true'

9. 建立密碼檔案

C:>orapwd file=d:\oracle\ora92\database\PWDzero.ora password=test
或者直接複製主庫的pwd檔案

10. 配置主從伺服器的listener.ora

--主庫

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.6.45)(PORT = 1521))

)

)

)

--從庫
LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.6.38)(PORT = 1521))

)

)

)


11. 分別配置主從伺服器的tnsname.ora保持一致

STANDBY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.6.38)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = zero)
      (SERVER = DEDICATED)
    )
  )

PRIMARY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.6.45)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = zero)
      (SERVER = DEDICATED)
    )
  )


12. 偵聽檢視主從機是否能夠監聽


C:\Documents and Settings\zero>tnsping standby

TNS Ping Utility for 32-bit Windows: Version 9.2.0.1.0 - Production on 16-12月-2007 01:39:33

Copyright (c) 1997 Oracle Corporation.  All rights reserved.

已使用的引數檔案:
D:\oracle\ora92\network\admin\sqlnet.ora


已使用 TNSNAMES 介面卡來解析別名
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.6.38)(PORT = 1521))) (CO
NNECT_DATA = (SID = zero) (SERVER = DEDICATED)))
OK(30毫秒)

C:\Documents and Settings\zero>
Tnsping primary
 
C:\Documents and Settings\zero>tnsping standby

TNS Ping Utility for 32-bit Windows: Version 9.2.0.1.0 - Production on 16-12月-2007 01:39:33

Copyright (c) 1997 Oracle Corporation.  All rights reserved.

已使用的引數檔案:
D:\oracle\ora92\network\admin\sqlnet.ora


已使用 TNSNAMES 介面卡來解析別名
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.6.45)(PORT = 1521))) (CO
NNECT_DATA = (SID = zero) (SERVER = DEDICATED)))
OK(30毫秒)

C:\Documents and Settings\zero>

13.啟動物理Standby資料庫

SQL> conn sys/sys@standby as sysdba
已連線到空閒例程。
SQL> startup nomount;
ORACLE 例程已經啟動。

Total System Global Area  135338868 bytes
Fixed Size                   453492 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
SQL> alter database mount standby database;

資料庫已更改。


14. 在Standby資料庫上,初始化Log Apply 服務

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

資料庫已更改。

15. 安裝完的的驗證

在primary上

SQL> select sequence#,first_time,next_time from v$archived_log;

SEQUENCE# FIRST_TIME NEXT_TIME

 SEQUENCE# FIRST_TIME NEXT_TIME
---------- ---------- ----------
        16 10-12月-07 10-12月-07
        17 10-12月-07 10-12月-07
        18 10-12月-07 11-12月-07
        19 11-12月-07 11-12月-07
        20 11-12月-07 12-12月-07
        21 12-12月-07 12-12月-07
        22 12-12月-07 13-12月-07
        23 13-12月-07 14-12月-07
        25 14-12月-07 15-12月-07
        24 14-12月-07 14-12月-07
        26 15-12月-07 16-12月-07

 SEQUENCE# FIRST_TIME NEXT_TIME
---------- ---------- ----------
        27 16-12月-07 16-12月-07
        28 16-12月-07 16-12月-07

已選擇79行。

在standby上

SQL> select sequence#,first_time,next_time from v$archived_log;

未選定行



在primary上

SQL>  alter system archive log current;

系統已更改。

SQL> select sequence#,first_time,next_time from v$archived_log;

SEQUENCE# FIRST_TIME NEXT_TIME

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

 SEQUENCE# FIRST_TIME NEXT_TIME
---------- ---------- ----------
        16 10-12月-07 10-12月-07
        17 10-12月-07 10-12月-07
        18 10-12月-07 11-12月-07
        19 11-12月-07 11-12月-07
        20 11-12月-07 12-12月-07
        21 12-12月-07 12-12月-07
        22 12-12月-07 13-12月-07
        23 13-12月-07 14-12月-07
        25 14-12月-07 15-12月-07
        24 14-12月-07 14-12月-07
        26 15-12月-07 16-12月-07

 SEQUENCE# FIRST_TIME NEXT_TIME
---------- ---------- ----------
        27 16-12月-07 16-12月-07
        28 16-12月-07 16-12月-07
        29 16-12月-07 16-12月-07

已選擇80行。


在standby上

SQL> select sequence#,first_time,next_time from v$archived_log;

 SEQUENCE# FIRST_TIME NEXT_TIME
---------- ---------- ----------
        29 16-12? -07 16-12? -07
 


SQL> select sequence#,applied from v$archived_log;

 SEQUENCE# APP
---------- ---
        29 YES
        26 YES
        27 YES
        28 YES

SQL>


--Yes即OK
 


在standby上

SQL> select process,status from v$managed_standby;

PROCESS STATUS
------- ------------
MRP0    WAIT_FOR_LOG
RFS     ATTACHED
RFS     RECEIVING

SQL>

16、看到有個文件說standby的redo log要比主庫多,就新增了兩組重做日誌
SQL> alter database recover managed standby database finish;

資料庫已更改。

SQL> alter database add standby logfile group 4 ('d:/oracle/oradata/zero/standby04.redo') size 100m;

資料庫已更改。


SQL> alter database add standby logfile group 5 ('d:/oracle/oradata/zero/standby05.redo') size 100m;

資料庫已更改。


附:standby的pfile
*.background_dump_dest='D:\oracle\admin\zero\bdump'
*.compatible='9.2.0.0.0'
*.control_files='D:\oracle\oradata\zero\control01.ctl','D:\oracle\oradata\zero\control02.ctl','D:\oracle\oradata\zero\control03.ctl'
*.core_dump_dest='D:\oracle\admin\zero\cdump'
*.db_block_size=8192
*.db_cache_size=25165824
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='zero'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=zeroXDB)'
*.fal_client='satndby'
*.fal_server='primary'
*.fast_start_mttr_target=300
*.hash_join_enabled=TRUE
*.instance_name='zero'
*.java_pool_size=33554432
*.large_pool_size=8388608
*.log_archive_dest_1='LOCATION=C:\arc_zero'
*.open_cursors=300
*.pga_aggregate_target=25165824
*.processes=150
*.query_rewrite_enabled='FALSE'
*.remote_archive_enable='true'
*.remote_login_passwordfile='EXCLUSIVE'
*.shared_pool_size=50331648
*.sort_area_size=524288
*.sql_trace=TRUE
*.standby_archive_dest='c:\arc_zero'
*.standby_file_management='auto'
*.star_transformation_enabled='FALSE'
*.timed_statistics=TRUE
*.undo_management='AUTO'
*.undo_retention=10800
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='D:\oracle\admin\zero\udump'


維護注意:
1、如何增加standby庫的standby redo log

SQL> alter database recover managed standby database finish;

Database altered.

如果沒有停止自動恢復狀態就新增standby logfile,會報錯:
ORA-01156: recovery in progress may need access to files

SQL> alter database add standby logfile group 4 ('d:/oracle/oradata/test/standby04.redo') size 10m;

2、如何讓dataguard從max performance轉為max available模式
主庫的init檔案修改:
*.log_archive_dest_2='service=STANDBY LGWR SYNC AFFIRM'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE

從庫的init檔案修改:
*.log_archive_dest_2='service=PRIMARY LGWR SYNC AFFIRM'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
同時從庫需要將自動歸檔設定為true:
SQL>alter system set log_archive_start=true scope=spfile;

3、切換角色
檢視當前資料庫的角色:
select database_role from v$database;
主庫操作:
檢視主庫是否已經準備好切換:
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
-----------------
TO STANDBY
1 row selected

如果為SESSIONS ACTIVE,檢查是否有活動的會話並殺掉它
確認為TO STANDBY之後,執行:

ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;
SQL> shutdown immediate;
ORA-01507: 未安裝資料庫


ORACLE 例程已經關閉。

SQL> startup nomount;
ORACLE 例程已經啟動。

Total System Global Area  135338868 bytes
Fixed Size                   453492 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
SQL> alter database mount standby database;

資料庫已更改。

SQL> alter database recover managed standby database disconnect from session;
資料庫已更改。
SQL>

備庫操作:
SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
------------------
TO PRIMARY

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
------------------
SESSIONS ACTIVE

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;

資料庫已更改。

SQL> alter database open;
alter database open
*
ERROR 位於第 1 行:
ORA-01507: 未安裝資料庫


SQL> shutdown immediate;
ORA-01507: 未安裝資料庫


ORACLE 例程已經關閉。
SQL> startup;
ORACLE 例程已經啟動。

Total System Global Area  135338868 bytes
Fixed Size                   453492 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
資料庫裝載完畢。
資料庫已經開啟。

SQL>
SQL> select count(1) from t1;

  COUNT(1)
----------
     56622

SQL>

角色切換成功

期間我把PWDzero.ora不小心給刪除了。結果主庫報錯:

*
ERROR 位於第 1 行:
ORA-01990: ??????'D:\oracle\ora92\DATABASE\PWDzero.ORA'??
ORA-27041: ??????
OSD-04002: N^7(4r?*NDO/S-Error: (OS 2) O5M3UR2;5=V86(5DND
嚇我一跳。後來檢視了原因,從standby庫複製了一個。萬幸沒有出什麼問題。

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