ORACLE 10G DATAGUARD實戰步驟
具體步驟如下:
一、主庫操作
1、修改主庫屬性:
alter system force logging;
##查看狀態
select FORCE_LOGGING from v$database;
2、修改資料庫為歸檔模式:
archive log list;
shutdown immediate;
startup mount;
alter database archivelog;(alter database noarchivelog;關掉歸檔模式)
archive log list;
3、添加standby logfile(也可以不加)
為主要資料庫添加"備用聯機記錄檔",這裡要保證備記錄檔與主庫聯機記錄檔相同大小。
添加備用記錄檔是規則:
備用日誌最少應該比redo log 多一個。推薦的備重做日誌數依賴於主要資料庫上的線程數。
(每線程記錄檔最大數目 + 1 ) * 線程數
alter database add standby logfile
group 4 ('/oracle2/app/oracle/oradata/std_redo04a.log','/oracle2/app/oracle/oradata/std_redo04b.log') size 50m,
group 5 ('/oracle2/app/oracle/oradata/std_redo05a.log','/oracle2/app/oracle/oradata/std_redo05b.log') size 50m,
group 6 ('/oracle2/app/oracle/oradata/std_redo06a.log','/oracle2/app/oracle/oradata/std_redo06b.log') size 50m,
group 7 ('/oracle2/app/oracle/oradata/std_redo07a.log','/oracle2/app/oracle/oradata/std_redo08b.dbf') size 50m;
否則備庫在應用時報如下資訊:
RFS[1]: No standby redo logfiles created
RFS[1]: Archived Log: '/oracle2/arch/1_30_633287861.dbf'
在主庫添加完standby logfile後,當主庫切換後備庫後會自動使用備庫的redo logfile,具體應用資訊如下:
RFS[1]: Successfully opened standby log 4: '/oracle2/app/oracle/oradata/10g/redo04.log'
RFS[1]: Successfully opened standby log 4: '/oracle2/app/oracle/oradata/10g/redo04.log'
4、修改主庫參數檔案:
10g.__db_cache_size=1207959552
10g.__java_pool_size=16777216
10g.__large_pool_size=16777216
10g.__shared_pool_size=352321536
10g.__streams_pool_size=0
*.audit_file_dest='/oracle2/app/oracle/admin/10g/adump'
*.background_dump_dest='/oracle2/app/oracle/admin/10g/bdump'
*.compatible='10.2.0.3.0'
*.control_files='/oracle2/app/oracle/oradata/10g/control01.ctl','/oracle2/app/oracle/oradata/10g/control02.ctl','/oracle2/app/oracle/oradata/10g/control03.ctl'
*.core_dump_dest='/oracle2/app/oracle/admin/10g/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='10g'
*.DB_UNIQUE_NAME='10gpri' [color=Red]###必須 定義每個資料庫的唯一標識[/color]
*.log_archive_config='DG_CONFIG=(10gpri,10gstandby)' [color=Red]###必須[/color]
*.log_archive_dest_1='location=/oracle2/arch/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES)' DB_UNIQUE_NAME='10gpri' [color=Red]###必須 本地的歸檔路徑[/color]
*.LOG_ARCHIVE_DEST_2='SERVICE=10gstandby arch ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=10gstandby' [color=Red]###必須(遠程伺服器端的歸檔日誌)[/color]
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.FAL_SERVER=10gpri [color=Red] ### 定義FAL伺服器的Oracle Net服務的名稱[/color]*.FAL_CLIENT=10gstandby [color=Red]### 定義備資料庫的Oracle Net服務名 (這兩個參數在主庫可有可無,但備庫必須有。ORACLE 老外工程師說這個必須有^_^) [/color]
*.db_recovery_file_dest='/oracle2/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=10gXDB)'
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=1707081728
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=1610612736
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/oracle2/app/oracle/admin/10g/udump'
*.STANDBY_FILE_MANAGEMENT=AUTO [color=Red] ###設定為AUTO,使得當資料檔案添加到主要資料庫或者從主要資料庫刪除的時候,對應的修改能夠在備用資料庫中自動執行.[/color]
5、用pfile啟動,再重新建立spfile.
shutdown immediate;
startup pfile='./pfile.pra';
create spfile from pfile='./pfile.ora';
shutdown immediate;
startup;
6、在主庫建立密碼檔案、以及控制檔案。
orapwd file=orapw10gstandby.ora password=change_on_install entries=10
alter database create standby database controlfile '/tmp/standby.ctl';
7、TNS資訊如下:
主庫
10g=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.169.1.204)(PORT = 1921))
)
(CONNECT_DATA =
(SID = 10g)
)
)
10gpri=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.169.1.224)(PORT = 1921))
)
(CONNECT_DATA =
(SID = 10g)
)
)
10gstandby =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.169.1.204)(PORT = 1921))
)
(CONNECT_DATA =
(SID = 10g)
)
)
8、對主庫進行全庫備份
run {
allocate channel t1 type disk;
allocate channel t2 type disk;
backup database format '/tmp/full_%s';
release channel t1;
release channel t2;
}
二、備庫操作如下:
1、依照主庫的資料檔案位置,在備庫上建立相應的目錄結構(最好與主庫一致);
mkdir -p /oracle/app/oracle/oradata/....
2、通過FTP把在主庫建立的密碼檔案、standby controlfile、full backup database檔案到備庫主機上。
3、備份的參數檔案內容:
10g.__db_cache_size=1207959552
10g.__java_pool_size=16777216
10g.__large_pool_size=16777216
10g.__shared_pool_size=352321536
10g.__streams_pool_size=0
*.audit_file_dest='/oracle2/app/oracle/admin/10g/adump'
*.background_dump_dest='/oracle2/app/oracle/admin/10g/bdump'
*.compatible='10.2.0.3.0'
*.control_files='/oracle2/app/oracle/oradata/10g/control01.ctl','/oracle2/app/oracle/oradata/10g/control02.ctl','/oracle2/app/oracle/oradata/10g/control03.ctl'
*.core_dump_dest='/oracle2/app/oracle/admin/10g/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='10g'
[color=Lime]*.DB_UNIQUE_NAME='10gstandby' ##
*.log_archive_config='DG_CONFIG=(10gpri,10gstandby)' ##[/color]
[color=Lime]*.log_archive_dest_1='location=/oracle2/arch/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES)' DB_UNIQUE_NAME='10gstandby' ##
*.LOG_ARCHIVE_DEST_2='SERVICE=10gpri arch ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=10gpri' ##[/color]
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
[color=Lime]*.FAL_SERVER=10gstandby ##
*.FAL_CLIENT=10gpri ##[/color]*.db_recovery_file_dest='/oracle2/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=10gXDB)'
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=1707081728
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=1610612736
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/oracle2/app/oracle/admin/10g/udump'
*.STANDBY_FILE_MANAGEMENT=AUTO ##
4、分別對備庫進行全庫恢複,並啟動到standby database mount狀態下。
用PFILE檔案起動到nomount狀態下,恢複控制檔案;起動到mount狀態下,然後再恢複全庫。
5、TNS資訊如下:
10g=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.169.1.204)(PORT = 1921))
)
(CONNECT_DATA =
(SID = 10g)
)
)
10gpri=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.169.1.224)(PORT = 1921))
)
(CONNECT_DATA =
(SID = 10g)
)
)
10gstandby =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.169.1.204)(PORT = 1921))
)
(CONNECT_DATA =
(SID = 10g)
)
)
用TNSPING 對方是否通。
6、修改備庫處於應用歸檔狀態
alter database recover managed standby database disconnect from session;
如果主庫從不過來歸檔,可以通過在主庫側手工修改參數如下:
ALTER SYSTEM SET log_archive_dest_state_2='DEFER' SCOPE=MEMORY;
ALTER SYSTEM SET log_archive_dest_state_2='ENABLE' SCOPE=MEMORY;
7、測試
通過在主庫執行alter system switch logfile;切換日誌可以觀察到備庫會自動應用通過主庫傳過來的日誌。
三、切換測試
1、在主庫端
select switchover_stats from v$database;
如果是to standby 表可以正常切換.
直接執行 ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;
否則執行: ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;
shutdown immediate;
startup nomount;
alter database mount standby database;
2、在備庫
在備庫
SELECT SWITCHOVER_STATUS FROM V$DATABASE;
如果是to_primary 表可以正常切換.
執行:ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
否則執行: ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;
shutdown immediate;
startup;
然後觀察主備庫日誌,如果正常的話會看到備庫會自動應用日誌.
轉載自:http://space.itpub.net/15843490/viewspace-584423