前言
用虚拟机做实验搭建个dg环境很轻松,但是实际操作的时候,总会遇到各种困难,比如用户不让随意重启业务数据库。本文介绍了在不重启主库的前提下,搭建dg备库遇到的故障,文末会给出解决办法,写出来给大家参考(肯定不是为了墨值)
实施步骤
1、 前期规划
省略…有条件的话主备库的操作系统最好一致
2、检查归档模式
archive log list
3、主库开启force logging
alter database force logging;
4、tnsname.ora新增解析
vi $ORACLE_HOME/network/admin/tnsnames.ora
primary =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx.xx)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = db)
)
)
standby =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx.xx)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dbdg)
)
)
5、监听文件新增静态监听
主库
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = db)
(ORACLE_HOME = $ORACLE_HOME)
(SID_NAME = db)
)
)
备库
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dbdg)
(ORACLE_HOME = $ORACLE_HOME)
(SID_NAME = db)
)
)
6、备库创建相应目录
对照主库的pfile创建
mkdir -p /u01/oracle/admin/orcl/adump
mkdir -p /u01/oracle/omf/
mkdir /u01/oracle/oradata/orcl/
mkdir -p /u01/oracle/flash_recovery_area/orcl/
mkdir -p /u01/oracle/recover
7、主库传输密码文件到备库
#这步挺关键的,有时候网络都没问题,就卡在这了
8、备份主库
rman target /
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup database format ‘/backup/backup_db_%T_%U.bak’;
release channel c1;
release channel c2;
}
#备份集转移到备库的/backup目录
9、备库创建standby控制文件,对原有的文件进行替换
startup nomount
alter database create standby controlfile
as ‘/oracle/app/product/11.2.0/dbhome_1/dbs/control_std.file’;
#复制到备库的两个控制文件目录里来
10、还原备库
alter database mount;
rman>catalog start with ‘/backup’;
restore database;
11、修改参数
主库(主库不重启)
alter system set db_unique_name=‘db’ scope=spfile sid=’’;
alter system set log_archive_config=‘dg_config=(db,dbdg)’ scope=both sid=’’;
alter system set log_archive_dest_1=‘location=/bak valid_for=(all_logfiles,all_roles) db_unique_name=db’ scope=both sid=’*’;
alter system set
log_archive_dest_2=‘service=standby
valid_for=(online_logfiles,primary_role) db_unique_name=dbdg’ scope=both sid=’*’;
alter system set log_archive_dest_state_1=enable scope=both sid=’’;
alter system set log_archive_dest_state_2=enable scope=both sid=’’;
alter system set standby_file_management=‘auto’ scope=both sid=’’;
alter system set fal_server=‘standby’ scope=both sid=’’;
备库
alter system set db_unique_name=‘dbdg’ scope=spfile ;
alter system set log_archive_config=‘dg_config=(db,dbdg)’ scope=spfile ;
alter system set log_archive_dest_1=‘location=/bak valid_for=(all_logfiles,all_roles) db_unique_name=dbdg’ scope=spfile ;
alter system set log_archive_dest_2=‘service=primary valid_for=(online_logfiles,primary_role) db_unique_name=db’ scope=spfile ;
alter system set log_archive_dest_state_1=enable scope=spfile ;
alter system set log_archive_dest_state_2=enable scope=spfile ;
alter system set standby_file_management=‘auto’ scope=spfile ;
alter system set fal_server=‘primary’ scope=spfile ;
alter system set db_file_name_convert=’/dat/db/’,’/dat/db/’ scope=spfile;
alter system set log_file_name_convert=’/dat/db/’,’/dat/db/’ scope=spfile;
#重启生效(unique_name生效)
12、主备库创建standby logfile
alter database add standby logfile ‘/dat/redo10.log’ size 100m;
alter database add standby logfile ‘/dat/redo11.log’ size 100m;
alter database add standby logfile ‘/dat/redo12.log’ size 100m;
#数量比redo log多一个,大小一样
13、 测试监听是否通畅
tnsping primary
tnsping standby
14、 备库执行应用日志
alter database recover managed standby database disconnect from session;
#主库日志里出现报错
FAL[server,ARC3]:FAL archive failed,see trace file
ARCH:FAL archive failed. Archiver continuing
ORACLE Instance db – Archival Error。 Archiver continuing
#检查了网络,防火墙,参数设置,TNSNAME设置,数据库密码文件等等,都没问题,几近抓狂,最后重置了主库的log_archive_dest_2,扶正log_archive_dest_3,故障解决。
alter system set
log_archive_dest_2=’ ’ scope=both sid=’*’;
alter system set
log_archive_dest_3=‘service=standby
valid_for=(online_logfiles,primary_role) db_unique_name=dbdg’ scope=both sid=’*’;
alter system set log_archive_dest_state_3=enable scope=both sid=’*’;
15、启库
alter database open;
总结
重启大法好虽好,但是实际干活的时候,得找点小技巧,不然协调用户和开发很麻烦。




