一、实施最大性能的物理Standby
1、先建立主库orcl
2、主库需要配置db_unique_name参数,如果从来没有配置过,需要停库进行修改。
确认SPFILE中
DB_UNIQUE_NAME=orcl1
DB_NAME=orcl
LOG_ARCHIVE_CONFIG='dg_confg=(orcl1, orcl2)' #即log_archive_config='dg_config=(主库唯一名,从库唯一名)'
LOG_ARCHIVE_MAX_PROCESSES=4; #适当增加归档进程数量
LOG_ARCHIVE_DEST_1='location=/arc1 VALID_FOR=(ONLINE_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl1'
LOG_ARCHIVE_DEST_2='service=orcl2 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl2'
3、在从库上建立参数文件
*.background_dump_dest='/u01/oracle/admin/orcl2/bdump'
*.core_dump_dest='/u01/oracle/admin/orcl2/cdump'
*.user_dump_dest='/u01/oracle/admin/orcl2/udump'
*.compatible='10.2.0.1.0'
*.db_name=orcl
*.db_unique_name='orcl2'
*.control_files='/u01/app/oracle/oradata/orcl1/control01.ctl'
*.REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
*.db_block_size=8192
*.sga_target=160m
*.pga_aggregate_target=20m
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.standby_file_management='AUTO'
*.log_archive_config='dg_config=(orcl1,orcl2)'
*.log_archive_dest_10='location=/arch2 VALID_FOR=(ONLINE_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl2'
*.standby_archive_dest='/arc1'
#在oracle 11g r2里standby_archive_dest已经废弃
*.db_file_name_convert=('/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/orcl2/')
*.log_file_name_convert=('/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/orcl2/')
4、从主库拷贝口令文件
scp host1:/u01/app/oracle/product/10.2.0/db_1/dbs/orapworcl host2:/u01/app/oracle/product/10.2.0/db_1/dbs/orapworcl2
5、配置net
netmgr
静态注册orcl1,orcl2
6、备份主库
rman target /
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/home/oracle/orcl1/%d_%I_%s_%p.bkp';
BACKUP AS COMPRESSED BACKUPSET DATABASE INCLUDE CURRENT CONTROLFILE FOR STANDBY PLUS ARCHIVELOG;
7、拷贝备份片到从库
scp host1:/home/oracle/orcl1/* host2:/home/oracle/orcl2/
8、在主库使用RMAN对备库进行还原
rman target sys/oracle@orcl1 auxiliary sys/oracle@orcl2
DUPLICATE TARGET DATABASE FOR STANDBY;
执行结束后,从库会被启动到MOUNT模式,数据同步是ARCHIVELOG文件级别的。
9、其它步骤
注意:如果没有在从库配置
*.db_file_name_convert=('/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/orcl2/')
*.log_file_name_convert=('/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/orcl2/')
则有可能报RMAN-05001: auxiliary file name/u01/app/oracle…… conflicts with a file used by thetarget database错误
此时需要DUPLICATE TARGET DATABASE FOR STANDBY NOFILENAMECHECK;
确认环节:(在主库中执行)
col dest_name for a30
col error for a20
select dest_name,status,error,target,process from v$archive_dest;
查看一下结果集的各目标状态是否正常。
从库进入管理恢复模式:
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
在这之后可以将从库open
ALTER DATABASE OPEN;
10、将DataGuard从“最大性能模式”升级成为“最高可用模式(最高可用物理standby)”
(1)主库调整LOG粒度
ALTER SYSTEM SET log_archive_dest_1='service=orcl2 lgwr sync affirm VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl2'
(2)添加standby logfile用来接收从主库传过来的LOG
ALTER DATABASE ADD STANDBY LOGFILE 'XXX' SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE 'XXX' SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE 'XXX' SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE 'XXX' SIZE 50M;
建议比主库的LOGFILE多一组
(3)设置从库的归档路径
ALTER SYSTEM SET log_archive_dest_3='location=/arc3 valid_for=(STANDBY_LOGFILES,STANDBY_ROLE) db_unique_name=orcl2'
(4)主库设置为最高可用模式
alter database set standby database to maximize availability;
(5)确认数据库保护模式
select protection_mode,database_role,protection_level from v$database;
(6)从库进入管理恢复模式
开启物理standby的日志实时应用(从库):
alter database recover managed standby database using current logfile disconnect from session;
停止日志应用:
alter database recover managed standby database cancel;
打开数据库
alter database open;
这样就可以用从库充当主数据库使用了。