前面整理过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 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 / total 670M -rw-r----- 1 oracle oinstall 6.8M Oct 31 15:32 ctl_asm_05mqg6vt_1_1 -rw-r----- 1 oracle oinstall 64M Oct 31 15:28 dg_01mqg6o9_1_1 -rw-r----- 1 oracle oinstall 592M Oct 31 15:29 dg_02mqg6oj_1_1 -rw-r----- 1 oracle oinstall 6.9M Oct 31 15:29 dg_03mqg6qa_1_1 -rw-r----- 1 oracle oinstall 25K Oct 31 15:29 dg_04mqg6qh_1_1 -rw-r--r-- 1 oracle oinstall 1.5K Oct 31 15:24 initorcl.ora |
二:备库上的配置
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
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日志组搞定! |