事先要先建立物理standby,物理standby建立过程略;
逻辑DB的主体流程:
reader(读redo条目)--->prepare(生成LCR)--->builder(同一事务的LCR打包)--->analyzer(分析事务间的依赖关系)--->coordinator协调关系--->apply(应用SQL)
一:
确认主数据是否包含不支持的对象可以查询数据字典表DBA_LOGSTDBY_UNSUPPORTED:
SQL>SELECT DISTINCT OWNER,TABLE_NAME FROM DBA_LOGSTDBY_UNSUPPORTED ORDER BY OWNER,TABLE_NAME;
二:
在主数据库创建一个交替的表空间.并用DBMS_LOGMNR_D.SET_TABLESPACE将某些表放到这个表空间中.因为在逻辑备用数据库中有一些表是属于SYS和SYSTEM用户的,而这些是放在表空间的.这些表可能在一段时间后记录猛增.为了使SYSTEM表空间不会被用满而导致数据库DOWN机,建立这个交替的表空间来存放这些表.
alter system set undo_retention=1800 scope=both;
CREATE TABLESPACE logmnrts DATAFILE '/oradata/ORCL/logmnrts/logmnrts01.dbf' SIZE 25M AUTOEXTEND ON MAXSIZE 8000M;
SQL>EXECUTE DBMS_LOGMNR_D.SET_TABLESPACE('logmnrts');
(上面一步EXECUTE DBMS_LOGMNR_D.SET_TABLESPACE('logmnrts');可以在以后的维护中再做相应的维护)
三:
为了在逻辑standby端实时应用redo,必须建立stdandby redo,在为主库添加附加日志时,要生成较大的redo,所以redo log最好要大一点
在standby端,添加standby redo log,在为主库添加附加日志时,要生成较大的redo,所以redo log最好要大一点
shutdown immediate;
startup nomount;
alter database mount standby database;
alter database add standby logfile group 4 '/opt/oradata/ora1/standbyredo04.log' size 100m;
alter database add standby logfile group 5 '/opt/oradata/ora1/standbyredo05.log' size 100m;
alter database add standby logfile group 6 '/opt/oradata/ora1/standbyredo06.log' size 100m;
alter database add standby logfile group 7 '/opt/oradata/ora1/standbyredo07.log' size 100m;
primary也要将redo log改为100m,这里略
四:
验证是否存在表没有主键
select owner,table_name from dba_logstdby_not_unique where (owner,table_name) not in
(select distinct owner,table_name from dba_logstdby_unsupported) and bad_column='Y';
验证附加日志:
SELECT SUPPLEMENTAL_LOG_DATA_PK AS PK_LOG,SUPPLEMENTAL_LOG_DATA_UI AS UI_LOG FROM V$DATABASE;
PK_ UI_
--- ---
NO NO
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY, UNIQUE INDEX) COLUMNS;
激活supplemental logging属性以后,作一次日志切换,保证当前日志中不包含非追加日志数据(nonsupplemental log)。
此外,如果你在主数据库上激活补充日志进程之前已经创建了物理standby数据库,就必须在所有物理standby数据库上做同样的操作。
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
再验证
SELECT SUPPLEMENTAL_LOG_DATA_PK AS PK_LOG,SUPPLEMENTAL_LOG_DATA_UI AS UI_LOG FROM V$DATABASE;
PK_LOG UI_LOG
------ ------
YES YES
五:
为primary database添加部分参数
*.db_name='ORCL'
*.db_unique_name='primary'
*.log_archive_config='DG_CONFIG=(primary,phystandby,logstandby)'
*.log_archive_dest_1='LOCATION=/oradata/arch valid_for=(all_logfiles,all_roles) db_unique_name=primary'
*.log_archive_dest_2='SERVICE=phystandby LGWR SYNC AFFIRM valid_for=(online_logfiles,primary_role) db_unique_name=phystandby'
*.log_archive_dest_3='SERVICE=logstandby LGWR SYNC AFFIRM valid_for=(online_logfiles,primary_role) db_unique_name=logstandby'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_dest_state_3='ENABLE'
*.log_archive_format='%t_%s_%r_%sarch.dbf'
*.undo_retention=3600
注意:db_unique_name是参数文件里的db_unique_name
为standby database添加部分参数
*.db_name='ORCL'
*.db_unique_name='logstandby'
*.fal_client='logstandby'
*.fal_server='primary'
*.log_archive_config='DG_CONFIG=(primary,phystandby,logstandby)'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.LOG_ARCHIVE_DEST_1='LOCATION=/oradata/ORCL/arch VALID_FOR=(ONLINE_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=logstandby'
*.LOG_ARCHIVE_DEST_2='LOCATION=/oradata/ORCL/standbyarch VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=logstandby'
*.log_archive_format='%t_%s_%r_%sarch.dbf'
*.undo_retention=3600
生成spfile后,使用spfile启动standby,后面转换为逻辑standby时要更改spfile里的db_name的
六:
在standby端
alter database recover managed standby database cancel;
七:
在primary database上建立logminer字典
exec dbms_logstdby.build;
归档主库当前日志,确保包含数据字典信息的归档传递到备库
alter system archive log current;
八:
在standby端
alter database recover to logical standby newdb_name;
用spfile的话会自动更改spfile里的db_name,记得重新生成口令文件
备份一下备库的alert_SID.log
九:
在standby端
shutdown immediate;
startup mount;
alter database open resetlogs;
十:
在standby端
开始应用redo,如果之前没有使用standby redo log file,这里会出错
alter database start logical standby apply immediate;
十一:
调优逻辑standby参数
alter database stop logical standby apply;
execute dbms_logstdby.apply_set('PREPARE_SERVERS', 2);
execute dbms_logstdby.apply_set('APPLY_SERVERS', 8);
alter database start logical standby apply immediate;
alter database stop logical standby apply;
EXECUTE DBMS_LOGSTDBY.APPLY_SET('MAX_SGA', 1000);
alter database start logical standby apply immediate;
阅读(2174) | 评论(0) | 转发(0) |