合 Windows平台搭建Oracle物理DG脚本
这是很久之前的脚本,接的私活,当时是给一个公司搭建的DG,今天分享出来:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | -- 主库查询 select name , open_mode, log_mode,force_logging,DATABASE_ROLE,switchover_status from v$database; alter database force logging; alter database archivelog; select * from v$standby_log; select group#,bytes/1024/1024 ||'M' from v$log ; SELECT * FROM V$LOGFILE; -- 主库创建standby logfile alter database add standby logfile group 5 ( 'Z:\APP\ADMINISTRATOR\ORADATA\ORCL\standby_redo05A.log','Z:\APP\ADMINISTRATOR\ORADATA\ORCL\standby_redo05B.log') size 100m; alter database add standby logfile group 6 ( 'Z:\APP\ADMINISTRATOR\ORADATA\ORCL\standby_redo06A.log','Z:\APP\ADMINISTRATOR\ORADATA\ORCL\standby_redo06B.log') size 100m; alter database add standby logfile group 7 ( 'Z:\APP\ADMINISTRATOR\ORADATA\ORCL\standby_redo07A.log','Z:\APP\ADMINISTRATOR\ORADATA\ORCL\standby_redo07B.log') size 100m; alter database add standby logfile group 8 ( 'Z:\APP\ADMINISTRATOR\ORADATA\ORCL\standby_redo08A.log','Z:\APP\ADMINISTRATOR\ORADATA\ORCL\standby_redo08B.log') size 100m; alter database add standby logfile group 9 ( 'Z:\APP\ADMINISTRATOR\ORADATA\ORCL\standby_redo09A.log','Z:\APP\ADMINISTRATOR\ORADATA\ORCL\standby_redo09B.log') size 100m; select * from v$standby_log; -- 主库修改参数 alter system set db_unique_name='orcl' scope=spfile; alter system set log_archive_config='DG_CONFIG=(orcl,orcldg)'; alter system set log_archive_dest_1='LOCATION=Z:\archive db_unique_name=orcl valid_for=(ALL_LOGFILES,ALL_ROLES)'; alter system set log_archive_dest_2='SERVICE=orcldg LGWR ASYNC db_unique_name=orcldg valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE)'; alter system set log_archive_dest_state_1=ENABLE; alter system set log_archive_dest_state_2=ENABLE; alter system set log_archive_max_processes=4; alter system set remote_login_passwordfile='EXCLUSIVE' scope=spfile; alter system set db_file_name_convert='orcldg','orcl' scope=spfile; alter system set log_file_name_convert='orcldg','orcl' scope=spfile; alter system set standby_file_management='AUTO'; alter system set fal_server='orcldg'; alter system set fal_client='orcl'; 重启主库 ---------备库操作 oradim -new -sid orcldg 主备库配置监听和tnsnames.ora ---配置静态监听 -由于要求主库与备库sys使用相同的密码,在此处,我们直接复制了主库的密码文件到备库 echo db_name=orcl >$ORACLE_HOME/database/initorcldg.ora 而且db_name必须相同 创建相关路径 mkdir D:\app\Administrator\admin\orcldg\adump mkdir Z:\archive mkdir Z:\app\Administrator\oradata\orcldg\ set ORACLE_SID=orcldg services.msc 中 启动服务 sqlplus sys/lhr as sysdba startup nomount rman target sys/lhr@orcl auxiliary sys/lhr@orcldg duplicate target database for standby nofilenamecheck from active database DORECOVER spfile set db_unique_name='orcldg' set log_archive_dest_1='LOCATION=Z:\archive\orcldg valid_for=(ALL_LOGFILES,ALL_ROLES) db_unique_name=orcldg' set log_archive_dest_2='service=orcl async lgwr register valid_for=(online_logfile,primary_role) db_unique_name=orcl' set standby_file_management='AUTO' set fal_server='orcl' set fal_client='orcldg' set control_files='Z:\app\Administrator\oradata\orcldg\control01.ctl','Z:\app\Administrator\oradata\orcldg\control02.ctl' set db_file_name_convert='orcl','orcldg' set log_file_name_convert='orcl','orcldg' set memory_target='161061273600' set audit_file_dest='D:\app\Administrator\admin\orcldg\adump' ; -------校验 select open_mode from v$database; show parameter instance_name alter database open; select * from v$log; set line 9999 select dbid,name,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from v$database; alter database recover managed standby database using current logfile disconnect; --主库切换日志 ALTER SYSTEM SWITCH LOGFILE; |