前面整理過Oracle物理備庫的配置文件,資料檔案是儲存在檔案系統上的,在生產環境中的DBA,往往都是面對幾十上百G的資料,甚至可能是T級別的,檔案系統儲存資料檔案在這些場合下的I/O問題就會逐漸暴露,因而在生產環境中的資料儲存一般都使用ASM,或者裸裝置,oracle 11g開始就不支援裸裝置儲存資料了,因而本講主要介紹在ASM環境下配置Data guard物理備庫!
環境介紹:
主庫IP:192.168.227.20/24
主庫SID: orcl
主庫DB_NAME:orcl
主庫DB_UNIQUE_NAME:primary
主庫SERVICES_NAME: primary.yang.com
備庫IP:192.168.227.30/24
備庫SID: orcl
備庫DB_NAME:orcl
備庫DB_UNIQUE_NAME:physical
備庫SERVICES_NAME: physical.yang.com
一:主庫準備工作
1:配置ASM環境 exec /u01/app/oracle/product/10.2.0/db_1/bin/ocssd ` [root@primary ~]# cd /u01/app/oracle/product/10.2.0/db_1/bin/ [oracle@primary ~]# ps -ef |grep -i asm [oracle@primary ~]$ export ORACLE_SID=+ASM INSTANCE_N STATUS SQL> create diskgroup data normal redundancy SQL> create diskgroup fra external redundancy SQL> select name,path,failgroup from v$asm_disk; NAME PATH FAILGROUP SQL> select name,total_mb,free_mb,usable_file_mb from v$asm_diskgroup; NAME TOTAL_MB FREE_MB USABLE_FILE_MB
2:建庫 SQL> select file_name from dba_data_files; FILE_NAME SQL> select member from v$logfile; MEMBER SQL> show parameter spfile; NAME TYPE VALUE NAME TYPE VALUE SQL> archive log list;
NAME TYPE VALUE
SQL> select member,type from v$logfile; MEMBER TYPE MEMBER TYPE 4:配置Data guard相關引數 SQL> alter system set db_unique_name=`primary` scope=spfile; SQL> alter system set log_archive_config=`DG_CONFIG=(primary,physical)`; SQL> show parameter remote_login; NAME TYPE VALUE
SQL> alter system set log_archive_dest_2=`service=physical lgwr async valid_for=(online_logfile,primary_role) db_unique_name=physical` scope=spfile; SQL> alter system set log_archive_dest_state_2=enable; SQL> alter system set log_archive_format=`%t_%s_%r.arc` scope=spfile; SQL> alter system set fal_server=`physical`; SQL> alter system set fal_client=`primary`; SQL> alter database force logging; [oracle@primary ~]$ cat $ORACLE_HOME/network/admin/tnsnames.ora [oracle@primary ~]$ sqlplus /nolog [oracle@primary ~]$ lsnrctl stop [oracle@primary ~]$ sqlplus /nolog SQL> conn sys/123456@primary as sysdba NAME TYPE VALUE 6:備份主庫相關檔案 [oracle@primary ~]$ rman target / [oracle@primary ~]$ ll -h /home/oracle/dg_backup/ |
二:備庫上的配置
1:配置ASM NAME PATH FAILGROUP 2:複製主庫上的備份資料 [oracle@physical ~]$ cp dg_backup/initorcl.ora $ORACLE_HOME/dbs OPEN_MODE NAME SQL> alter database recover managed standby database disconnect from session; Total System Global Area 167772160 bytes [oracle@physical ~]$ rman target sys/123456@primary auxiliary / SQL> alter database recover managed standby database disconnect from session; 驗證: SQL> select sequence#,first_time,next_time,applied from v$archived_log order by 1; SEQUENCE# FIRST_TIME NEXT_TIME APP 檢視日誌資訊: 主庫上切換日誌: SQL> alter system switch logfile; 備庫上再次查詢: SEQUENCE# FIRST_TIME NEXT_TIME APP 檢視日誌資訊: |
三:排錯
1:資料不同步問題排錯 SQL> archive log list; SQL> select * from v$archive_gap; [oracle@physical ~]$ cd /u01/app/oracle/admin/orcl/bdump/ 主庫上檢視歸檔日誌資訊 在備庫上還原歸檔日誌 RMAN-00571: =========================================================== [oracle@physical dg_backup]$ export ORACLE_SID=+ASM RMAN> restore archivelog all; 2:關閉主庫後,重啟物理備庫,報錯如下,找不到控制檔案 [oracle@physical dbs]$ grep -i control_files initorcl.ora //該路徑需要和asmcmd命令找到的控制檔案路徑一致 SQL> conn /as sysdba Total System Global Area 167772160 bytes SQL> alter database recover managed standby database disconnect from session; 配置物理備庫以spfile方式啟動,spfile不使用ASM管理 SQL> alter database recover managed standby database cancel; SQL> shutdown immediate SQL> alter database recover managed standby database disconnect from session; SQL> show parameter spfile; NAME TYPE VALUE 3:配置ASM報錯如下 Adding to inittab [root@physical ~]# /etc/init.d/init.cssd run >/dev/null 2>&1 </dev/null & [root@physical ~]# cd /u01/app/oracle/product/10.2.0/db_1/bin/ [root@physical bin]# ./crsctl check crs
4:物理備庫standby日誌組invalid問題排錯
MEMBER TYPE MEMBER TYPE 備庫: MEMBER TYPE MEMBER TYPE 在主庫上刪除所有的standby日誌組,並切換日誌組 備庫查詢: MEMBER TYPE 在主庫上新增新的standby日誌組並切換日誌,發現備庫上依然無法同步 [oracle@physical admin]$ tail -f /u01/app/oracle/admin/orcl/bdump/alert_orcl.log 猜想可能是ASM磁碟組下沒有primary目錄的原因,在ASM磁碟組下建立相關的目錄,在主庫上刪除standby日誌組後新增新的日誌組,並切換日誌,發現standby日誌組依然無法同步;後來嘗試在主庫上將standby日誌組放在檔案系統上,切換日誌後,備庫依然無法同步建立! 後來這個問題通過switchover後,在原物理備庫上手動建立standby日誌組搞定! |