思路:
1.需要相同版本(最好环境也一样)
2.主库有实例,从库上要求没有实例
3.主库需要归档
3.1查看主库是否是force loging 模式
select force_logging from v$database; 若为no,则执行alter database force logging
3.2是否开启归档
archive log list 查看:
若没有归档,将主库启动到mount状态
然后执行:alter database archivelog;
4.主库和备库都配置tns监听
orcl_p = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 主库ip)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) ) orcl_s = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 备库ip)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) )
5.主库修改初始化参数(重启才能生效)
sql>alter system set DB_UNIQUE_NAME=orcl_p scope=spfile; sql>alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl_s,orcl_p)' scope=both; sql>alter system set LOG_ARCHIVE_DEST_1='LOCATION=/oradata/orcl/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) db_unique_name=orcl_p' scope=spfile; sql>alter ssytem set LOG_ARCHIVE_DEST_2='SERVICE=orcl_s ASYNC VALID_FOR=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=orcl_s' scope=spfile; sql>alter system set LOG_ARCHIVE_DEST_STATE_2=DEFER scope=both; sql>alter system set LOG_ARCHIVE_MAX_PROCESSES=4 scope=4; sql>alter system set FAL_SERVER=orcl_s scope=both; sql>alter system set FAL_CLIENT=orcl_p scope=both; sql>alter system set STANDBY_FILE_MANAGEMENT=AUTO scope=both; sql>alter system set log_file_name_convert='/oradata/orcl/redo','/oradat/orcl/redo/'scope=spfile;
6.主库全备份(这里注意一定要将主库启动到mount状态而不是open状态才能开始全备)
run { backup database format '/oracle/backup/db_%t_%s_%U.bak' tag='db_full01';' backup archivelog all format '/oracle/backup/arch_%t_%s_%U.bak' tag='arch01';' }
7.在主库上中创建standby controlfile(这个文件最后是要传到备库中的相应位置上的,这里主库也是mount状态)
sql>alter dabase create standby controlfile as '/oracle/backup/control01.ctl'
8.创建备库初始化参数(这里根据实际路径进行修改) 然后再根据主库的参数文件进行修改
这里主要说一下要注意的几个参数:
*.control_files='/xxxx/xxxx/control01.ctl','/xxxx/xxxx/control02.ctl' *.DB_UNIQUE_NAME=orcl_s *.LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl_s,orcl_p)' LOG_ARCHIVE_DEST_1='LOCATION=/oradata/orcl/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) db_unique_name=orcl_p' LOG_ARCHIVE_DEST_2='SERVICE=orcl_s ASYNC VALID_FOR=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=orcl_s' LOG_ARCHIVE_DEST_STATE_2=DEFER LOG_ARCHIVE_MAX_PROCESSES=4 FAL_SERVER=orcl_s FAL_CLIENT=orcl_p STANDBY_FILE_MANAGEMENT=AUTO set log_file_name_convert='/oradata/orcl/redo','/oradat/orcl/redo/'
9.将主库的密码文件到备库中
10.在备库中创建参数文件中相应的路径(这里指的是目录,用mkdir进行创建,且注意权限)
11.将在主库中生成的standby controlfile传输到备库的相应目录中
12.这里将第6步中的数据文件和归档日志文件的备份集拷贝到从库中(这里注意目录和权限)
13.在主备库中分别添加standby redo log(该日志一般会比online redolog多一个)
alter database add standby logfile thread 1 group 8('/oradata/orcl/redo/redo10.log') size 200M;
....
14.将备库启动到mount状态,然后执行如下命令
rman>restore database from tag='db_full01'; rman>restore archivelog all; rman>recove database;
15.然后将备库开启open状态
alter database open read only
16.开启日志日志传输(主库上操作)
sql>alter system set log_archive_dest_state_2=enable scope=both;
17.开启日志应用进程(备库上操作)
sql>alter database recover managed Standby database disconnect from session no timeout;
验证同步是否正常:
18.在主库和备库分别查询v$ARCHIVED_LOG的最大序列号,将所得结果相比,相同表名同步正常
sql>select max(sequence#),thread# from v$archived_log group by thread#
对于使用redo apply同步方式,可以在备库通过MRPn状态进一步确认同步情况
sql>select m.PROCESS,m.STATUS from v$managed_standby m where m.PROCESS like 'MRP%';
如果使用redo apply 方式同步,同步过程中应有MRPn进程存在,如果redo apply正常,MRPn状态为applying_log
总结:
好了,以上备份需要注意一定要将主库启动到mount状态才能进行全备,生成standby controlfile 文件也一定要在mount状态才行,否则,在后续的备份恢复中,备库不能进行open状态(由于datafile的scn和controlfile的scn不一致导致的),这一点很重要!!!