Data Gurad的作用就不多說了,主在這說下物理standby的搭建步驟。
大致有這三種方式創建standby庫
方式一:用rman的方式生成standby. (用rman的duplice方式直接創建,無須先備份)
方式二:用rman的restore方式生成。(先用rman全備份主庫後,再用rman通過restore的方式創建)
方式三:用cp的方式生成 (關閉主庫後,復制控件文件,密碼文件,數據文件到備庫所在位置)
我主要在這用duplice方式,優點無須多說,假設你的數據庫上T,你會選哪種方法?
Oracle測試版本為11g;
1. 設置好主備庫的環境變量,及創建好相關目錄
主庫:
su - oracle --歸檔日志存放目錄 --例子放在/u01/app/oracle/archivelog/xcldb 下 mkdir -p $ORACLE_BASE/archivelog/$ORACLE_SID環境變量注意下面兩個參數:
su - oracle --生成相關的目錄,還要注意下權限, 另11g就這幾個,10G還有幾個目錄 mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/{adump,bdump,cdump,dpdump,udump,pfile} --數據庫所在目錄 mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID --閃回 mkdir -p $ORACLE_BASE/flash_recovery_area/$ORACLE_SID --歸檔日志存放目錄 mkdir -p $ORACLE_BASE/archivelog/$ORACLE_SID環境變量注意下面兩個參數:
--查看當前模式 archive log list --設定歸檔日志的路徑,可以生成多份一樣的日志,保存多個位置,以防丟失 --如果沒設置,默認會設到$ORACLE_HOME/dbs下。 alter system set log_archive_dest_1='location=/u01/app/oracle/archivelog/xcldb'; shutdown immediate startup mount alter database archivelog; archive log list;
alter database force logging select force_logging from v$database; --取消此模式:alter database no force logging; --手工切換日志,好生成歸檔日志 alter system switch logfile --執行個三次 select name from v$archived_log; --查看已有的日志文件 select * from v$logfile;
--找到最大的group#,因為group#不能重復 select max(group#) from v$log; --可用這兩條查詢看到組號及文件大小, 11g默認是52428800 SELECT GROUP#, BYTES FROM V$LOG; SELECT GROUP#, BYTES FROM V$STANDBY_LOG; --注意下大小一致,我是測試,沒管size alter database add standby logfile thread 1 group 11 '/u01/app/oracle/oradata/xcldb/redo11.log' size 50m; alter database add standby logfile thread 1 group 12 '/u01/app/oracle/oradata/xcldb/redo12.log' size 50m; alter database add standby logfile thread 1 group 13 '/u01/app/oracle/oradata/xcldb/redo13.log' size 50m; alter database add standby logfile thread 1 group 14 '/u01/app/oracle/oradata/xcldb/redo14.log' size 50m;
--------------------------------------------------- set serveroutput on; --alter system set db_unique_name='xcldb' scope=spfile; alter system set log_archive_config='dg_config=(xcldb,xcldbdg)'; alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog/xcldb VALID_FOR=(all_logfiles,all_roles) db_unique_name=xcldb'; alter system set log_archive_dest_2='service=xcldbdg LGWR ASYNC NOAFFIRM valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=xcldbdg'; alter system set log_archive_dest_state_1='enable'; alter system set log_archive_dest_state_2='enable'; alter system set standby_file_management='AUTO'; alter system set fal_server='xcldbdg'; alter system set db_file_name_convert='/xcldb/','/xcldbdg/' scope=spfile; alter system set log_file_name_convert='/xcldb/','/xcldbdg/' scope=spfile; ---------------------------- show parameter log_archive_config; show parameter db_file_name_convert; show parameter log_file_name_convert; ---------------------------要注意fal_client參數,11g已經廢了它,11g之前的版本還是需要這個參數
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = xcldb) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = xcldb) ) ) LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.18.2.32)(PORT = 1521)) ) ADR_BASE_LISTENER = /u01/app/oracle
[oracle@xcldg1] :cat tnsnames.ora # tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. XCLDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.18.2.32)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = xcldb) ) ) XCLDBDG = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.18.2.34)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = xcldbdg) ) )
run{ allocate channel prmy1 type disk; allocate channel prmy2 type disk; allocate auxiliary channel stby type disk; duplicate target database for standby from active database nofilenamecheck spfile parameter_value_convert 'xcldb','xcldbdg' set db_unique_name='xcldbdg' set log_archive_config='dg_config=(xcldb,xcldbdg)' set log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog/xcldbdg VALID_FOR=(all_logfiles,all_roles) db_unique_name=xcldbdg' set log_archive_dest_2='service=xcldbdg LGWR ASYNC NOAFFIRM valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=xcldbdg' set log_archive_dest_state_1='enable' set log_archive_dest_state_2='enable' set standby_file_management='AUTO' set fal_server='xcldb' set db_file_name_convert='/xcldb/','/xcldbdg/' set log_file_name_convert='/xcldb/','/xcldbdg/' set control_files='/u01/app/oracle/oradata/xcldbdg/xcldbdg.ctl' set log_archive_max_processes=30 ; } --set fal_client='xcldbdg'
--查看兩邊的數據庫狀態 select name,open_mode,database_role,dataguard_broker,guard_status,force_logging,db_unique_name from v$database; --在主庫執行日志切換 alter system switch logfile; --對比兩邊的日志情況,檢查是否有同步過來。 SELECT sequence#,first_time,next_time,name FROM v$archived_log ORDER BY sequence#;
至此,物理的Standby就順利搭建好了。
MAIL: [email protected]
BLOG: http://blog.csdn.net/xcl168