技术分享
Oracle 11g DG搭建文档
2022-05-31
目 录
1 环境配置
2 系统环境配置
3 配置DG
1 环境配置
物理DG参数 | ||||||
HOSTNAME | IP | DB_NAME | DB_UNIQUE_NAME | INSTANCE_NAME | SERVICE_NAME | TNSNAME |
dg1 | 192.168.93.25 | orcl | uni_dg1 | orcl | dg1 | uni_dg1 |
dg2 | 192.168.93.26 | orcl | uni_dg2 | orcl_stdby | dg2 | uni_dg2 |
文件物理路径 | ||||
datafile | controlfile | logfile | archivelog | auditfile |
/home/oracle/app/oradata/orcl | /home/oracle/app/oradata/orcl /home/oracle/app/flash_recovery_area/orcl | /home/oracle/app/oradata/orcl | /home/oracle/app/arch | /home/oracle/app/admin/orcl/adump |
/home/oracle/app/oradata/orcl_stdby | /home/oracle/app/oradata/orcl_stdby /home/oracle/app/flash_recovery_area/orcl | /home/oracle/app/oradata/orcl_stdby | /home/oracle/app/arch | /home/oracle/app/admin/orcl_stdby/adump |
2 系统环境配置
1、 配置域名解析,两台主机都需配置
192.168.93.25 dg1
192.168.93.26 dg2
2、 修改备库实例名
su – oracle
vi .bash_profile
source .bash_profile
env | grep SID
3、 建立备库相应目录
/home/oracle/app/oradata/orcl_stdby
/home/oracle/app/oradata/orcl_stdby
/home/oracle/app/flash_recovery_area/orcl
/home/oracle/app/oradata/orcl_stdby
/home/oracle/app/arch(主备库都需创建)
/home/oracle/app/admin/orcl_stdby/adump
3 配置DG
1、 主库强制记录日志
[oracle@dg1 ~]$ sqlplus / as sysdba
SQL> select log_mode,force_logging from v$database;
LOG_MODE FOR
------------ ---
NOARCHIVELOG NO
SQL> alter database force logging;
SQL> select log_mode,force_logging from v$database;
LOG_MODE FOR
------------ ---
NOARCHIVELOG YES
SQL> shutdown immediate
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;
SQL> select log_mode,force_logging from v$database;
LOG_MODE FOR
------------ ---
ARCHIVELOG YES
2、 配置主备监听
添加红框配置,主备库配置一致
3、 配置主库信息
创建pfile文件
create pfile='/home/oracle/dg1_spfile' from spfile;
修改pfile文件如图
通过pfile文件启动数据库
[oracle@dg1 u01]$ sqlplus / as sysdba
SQL> shutdown immediate
[oracle@dg1 u01]$ sqlplus / as sysdba
SQL> startup force nomount pfile=/home/oracle/dg1_spfile
ORACLE instance started.
Total System Global Area 521936896 bytes
检查数据库参数
通过pfile 创建spfile
create spfile from pfile=’/home/oracle/dg1_spfile’;
启动数据库
Startup force
生成controlfile文件
alter database create standby controlfile as ‘/home/oracle/stdby_ctrl_file.bak’;
退出数据库,传输主库文件到备库相应目录
数据文件、日志文件
cd /home/oracle/app/oradata/orcl
scp * dg2:/home/oracle/app/oradata/orcl_stdby
密码文件
cd /home/oracle/app/product/11.2.0/dbhome_1/dbs
scp orapwprod oracle@dg2: /home/oracle/app/product/11.2.0/dbhome_1/dbs/orapworcl_stdby
控制文件
scp /home/oracle/stdby_ctrl_file.bak oracle@dg2:/home/oracle/app/oradata/orcl_stdby/control02.ctl
scp /home/oracle/stdby_ctrl_file.bak oracle@dg2:/home/oracle/app/flash_recovery_area/orcl_stdby/control02.ctl
对传输文件赋权oracle权限
chown –R oracle:oinstall 相应目录
4、 配置备库信息
su – oracle
sqlplus / as sysdba
生成pfile文件 create pfile from spfile;
退出数据库 exit
cd $ORACLE_HOME/dbs
cp initorcl.ora initorcl_stdby.ora
vi initorcl_stdby.ora
修改如图
启动备库到nomount状态
startup force nomount pfile=‘/home/oracle/app/product/11.2.0.4/dbhome_1/dbs/initorcl_stdby.ora’;
生成spfile文件
create spfile from pfile;
startup force mount;
startup force;
alter database open;
recover managed standby database disconnect from session;
5、 配置实时应用
将备库启动中mount状态,添加4组standby日志
alter database add standby logfile group 4'/home/oracle/app/oradata/orcl_stdby/stdredo01.log' size 50m;
alter database add standby logfile group 5'/home/oracle/app/oradata/orcl_stdby/stdredo02.log' size 50m;
alter database add standby logfile group 6'/home/oracle/app/oradata/orcl_stdby/stdredo03.log' size 50m;
alter database add standby logfile group 7'/home/oracle/app/oradata/orcl_stdby/stdredo04.log' size 50m;
打开数据库
启动实时应用
4 DG模式配置
1、 将Oracle的最大性能模式切换至最大可用模式
备库 sqlplus / as sysdba
alter database recover managed standby database cancel;
主库 shutdown immediate;
startup mount;
ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE AVAILABILITY;
alter database open;
select protection_mode,database_role,protection_level,open_mode from v$database;
备库 ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
注意:备库重启时,都要执行如下的操作,才能保持主备同步关系
sqlplus / as sysdba;
startup;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
附件:最大性能模式切换至最大可用模式的操作步骤,供参考
备库 sqlplus / as sysdba
alter database recover managed standby database cancel;
主库 alter system set log_archive_dest_2='SERVICE=server2 OPTIONAL LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=server2';
shutdown immediate;
startup mount;
ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE AVAILABILITY;
alter database open;
select protection_mode,database_role,protection_level,open_mode from v$database;
备库 alter system set log_archive_dest_2='SERVICE=server1 OPTIONAL LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=server1';
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
最大性能 ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
alter database recover managed standby database cancel
欢迎查看云祺数据库备份方案详情,点击即可免费试用云祺容灾备份系统。
关注云祺,获取更多精彩信息。
- 标签:
-
技术分享