在同一台机器上搭建物理备用数据库的步骤,linux环境 oracle 11.2.0.1
主库:orcl
备库:stby
1 检查侦听是否启动
2 配置主备数据库的初始化参数文件
sqlplus "/as sysdba"
create pfile='/home/oracle/initprim.ora' from spfile;
cp /home/oracle/initprim.ora /home/oracle/initstby.ora
vi /home/oracle/initprim.ora
orcl.__db_cache_size=104857600
orcl.__java_pool_size=4194304
orcl.__large_pool_size=4194304
orcl.__oracle_base='/oracle'#oracle_base set from environment
orcl.__pga_aggregate_target=155189248
orcl.__sga_target=268435456
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=142606336
orcl.__streams_pool_size=4194304
*.audit_file_dest='/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/oradata/orcl/control01.ctl','/oradata/flash_recovery_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='/oradata/flash_recovery_area'
*.db_recovery_file_dest_size=4039114752
*.diagnostic_dest='/oracle'
*.dispatchers='(protocol=tcp) (service=orclxdb)'
*.memory_target=422576128
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='exclusive'
*.undo_tablespace='undotbs1'
*.fal_client='prim'
*.fal_server='stby'
*.standby_file_management=auto
*.log_archive_dest_1='location=/oradata/arch/orcl valid_for=(all_logfiles,all_roles) db_unique_name=prim'
*.log_archive_dest_2='service=stby valid_for=(online_logfiles,primary_role) db_unique_name=stby'
*.db_unique_name=prim
*.log_archive_config='dg_config=(prim,stby)'
编辑备库的参数文件
vi /home/oracle/initstby.ora
stby.__db_cache_size=104857600
stby.__java_pool_size=4194304
stby.__large_pool_size=4194304
stby.__oracle_base='/oracle'#oracle_base set from environment
stby.__pga_aggregate_target=155189248
stby.__sga_target=268435456
stby.__shared_io_pool_size=0
stby.__shared_pool_size=142606336
stby.__streams_pool_size=4194304
*.audit_file_dest='/oracle/admin/stby/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/oradata/stby/control01.ctl','/oradata/flash_recovery_area/stby/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl' #<-- 在同一台机器上搭建dg 要与主库的一样 否则ora-01103
*.db_recovery_file_dest='/oradata/flash_recovery_area'
*.db_recovery_file_dest_size=4039114752
*.diagnostic_dest='/oracle'
*.dispatchers='(protocol=tcp) (service=stbyxdb)'
*.memory_target=622576128
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='exclusive'
*.undo_tablespace='undotbs1'
*.db_file_name_convert='/oradata/orcl','/oradata/stby'
*.log_file_name_convert='/oradata/orcl','/oradata/stby'
*.fal_client='stby'
*.fal_server='prim'
*.standby_file_management=auto
*.log_archive_dest_1='location=/oradata/arch/stby valid_for=(all_logfiles,all_roles) db_unique_name=stby'
*.log_archive_dest_2='service=prim valid_for=(online_logfiles,primary_role) db_unique_name=prim'
*.db_unique_name='stby'
*.log_archive_config='dg_config=(prim,stby)'
备份主库
rman target /
backup database format '/u01/oradata/dbfull%u';
创建备库控制文件
export oracle_sid=orcl
sqlplus "/as sysdba"
alter database create standby controlfile as '/oradata/stby/stbycontrol.ctl';
cp /oradata/stby/stbycontrol.ctl /oradata/stby/control01.ctl
cp /oradata/stby/stbycontrol.ctl /oradata/flash_recovery_area/stby/control02.ctl
处理备库
export oracle_sid=stby
orapwd file=/oracle/product/11.2.0/db_1/dbs/orapwstby password=oracle entries=5 ignorecase=y #一定要加ignorecase=y 要不然归档传不到备用库上
sqlplus "/as sysdba"
startup nomount
alter database mount;
rman target /
restore database;
重启主库
export oracle_sid=orcl
sqlplus "/as sysdba"
shutdown immediate
startup pfile='/home/oracle/initprim.ora'
配置tnsnames.ora(因为在同一台机器上,所以就改这一个文件)
orcl =
(description =
(address_list =
(address = (protocol = tcp)(host = localhost)(port = 1521))
)
(connect_data =
(sid = orcl)
(server = dedicated)
)
)
stby =
(description =
(address_list =
(address = (protocol = tcp)(host = localhost)(port = 1521))
)
(connect_data =
(sid = stby)
(server = dedicated)
)
)
将备库置于接收归档日志状态
export oracle_sid=stby
sqlplus "/as sysdba"
alter database recover managed standby database disconnect from session;
过一会儿检查是否收到日志
export oracle_sid=orcl
sqlplus "/as sysdba"
select max(sequence#) from v$archived_log; --查看归档日志序列号
alter system switch logfile;
alter system switch logfile;
export oracle_sid=stby
sqlplus "/as sysdba"
select sequence#,applied from v$archived_log order by 1; --查看归档日志序列号
主备库角色切换
角色切换
步骤1:验证主库能否进行角色切换,to standby表示可以进行
sql> select switchover_status from v$database;
switchover_status
-----------------
to standby
步骤2:在主库上执行角色切换到从库角色
sql> alter database commit to switchover to physical standby;
步骤3:关闭并重新启动之前的主库实例
sql> shutdown immediate
sql> startup mount
步骤4:在备库的v$database视图中查看备库的切换状态
sql> select switchover_status from v$database;
switchover_status
-----------------
to_primary
步骤5:切换备库到主库角色
sql> alter database commit to switchover to primary;
步骤6:完成备库到主库的切换
1. 如果备库没有以只读模式打开,直接执行以下语句打开到新的主库。
sql> alter database open;
2. 如果备库以只读模式打开,先关闭数据,然后再重新启动。
sql> shutdown immediate;
sql> startup;
步骤7:如果有必要,重新启动一下新的备库上的重做日志应用服务
sql> alter database recover managed standby database disconnect from session;
(注:可以通过select message from v$dataguard_status;查看当前备库应用重做日志的状态)
步骤8:开始发送重做数据到备库上
issue the following statement on the new primary database:
sql> alter system switch logfile;
备注:
alter database recover managed standby database using current logfile;
如果有缺失的归档日志文件,手工考背后,在备库上:
alter database register physical logfile 'filespec1';
force 关键词终止目标物理备数据库上活动的rfs 进程,使得故障转移能不用等待网络连接超时而立即进行。
alter database recover managed standby database finish force;
阅读(3358) | 评论(1) | 转发(0) |