数据库管理-第九十五期 19c OCM之路-第五堂(20230728)

第九十五期 19c OCM之路-第五堂(20230728)

倒数第二堂,Configuring Data Guard,DG配置,这里开始除了大量需要操作需要去记,我个人认为是没啥难度。

1 考题

  1. Create a standby database
    host01,上PROD5数据库为主库,实例名是PROD5,数据库唯一名为PROD5H1;
    host02上为PROD5创建备库,实例名是PROD5,数据库唯一名为PROD5H2;
    所有目录对象应该在主备上均存在;
    连接到PROD5H1和PROD5H2时,连接方式均为独立模式;
    当全局临时表更新时,应产生最小化redo。
  2. Configuring the standby database for testing purposes
    备库转换至快照备库;
    备库执行测试脚本;
    备库切换回物理备库。
  3. Other Standby Database Configurations
    备库可用于查询、报表;
    减小主备数据库增量备份时的压力;
    配置日志备库应用删除策略。
  4. Administration automation
    配置PROD5H1自动失败转移至PROD5H2;
    日志传输间隔超过30秒,应当告警;
    日志应用间隔超过45秒,应当告警。
  5. Perform switchover
    将主库切换至PROD5H2;
    新的主库应当是读写状态;
    新的备库仍可提供查询能力。

2 操作

host01与host02配置tnsname:

PROD5H1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = host01)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PROD5)
    )
  )
PROD5H2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = host02)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PROD5)
    )
  )
 
lsnrctl reload

主库配置:

sqlplus sys/oracle
	alter system set db_unique_name=PROD5H1 scope=spfile;
	shut immediate;
	startup mount;
	alter database archivelog;
	alter database force logging;
	alter database flashback on; --用于快速失败转移
	alter system set local_listener='';
	alter system set standby_file_management=auto;
	alter database add standby logfile; --注意需要与redo日志组大小一致
	alter database add standby logfile;
	alter database add standby logfile;
	alter database add standby logfile;
	alter database add standby logfile;
	alter database open;
	shut immediate;
	startup
	alter system switch logfile;

	create pfile='/home/oracle/scripts/initPROD5.ora' from spfile;

修改备库参数文件并传输至备库:

db_unique_name='PROD5H2';

scp /home/oracle/scripts/initPROD5.ora host02:/u01/app/oracle/product/19.0.0/dbhome_1/dbs

host02操作:

mkdir /u01/app/oracle/oradata/PROD5
mkdir /u01/app/oracle/fast_recovery_area/PROD5
mkdir /u01/app/oracle/admin/PROD5/adump -p
# 根据参数文件目录创建其他前面题目变更了的目录

orapwd file=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/orapwPROD5 force=y password=oracle ignorecase=y
# 从主库拷贝亦可
export ORACLE_SID=PROD5
sqlplus / as sysdba
	create spfile from pfile;
	startup nomount

创建物理备库:

rman target sys/oracle@prod5h1 auxiliary sys/oracle@prod5h2
	duplicate target database for standby nofilenamecheck from active database;

sqlplus sys/oracle@prod5h1 as sysdba
	alter system set dg_broker_start=true;
sqlplus sys/oracle@prod5h2 as sysdba
	alter system set dg_broker_start=true;

dgmgrl sys/oracle@prod5h1
	create configuration dg1 as primary database is prod5h1 connect identifier is prod5h1;
	add database prod5h2 as connect identifier is prod5h2;
	enable configuration;
	show configuration;
	edit database prod5h1 set property logxptmode=sync;
	edit database prod5h2 set property logxptmode=sync;
	disable configuration;
	enable configuration;

最小化临时表redo:

sqlplus sys/oracle@prod5h1 as sysdba
	alter system set temp_undo_enabled=true;

快照备库:

dgmgrl sys/oracle@prod5h1
	convert database prod5h2 to snapshot standby;
	-- 根据题目执行测试脚本
	convert database prod5h2 to physical standby;

备库可读:

sqlplus sys/oracle@prod5h2 as sysdba
	alter database open;
	alter database recover managed standby database using current logfile disconnect;

降低增量备份压力:

sqlplus sys/oracle@prod5h1 as sysdba
	alter database enable block change tracking using file '/u01/app/oracle/blockprod5.txt';
rman target sys/oracle@prod5h1
	configure backup optimization on;
sqlplus sys/oracle@prod5h2 as sysdba
	alter database enable block change tracking using file '/u01/app/oracle/blockprod5.txt';
rman target sys/oracle@prod5h2
	configure backup optimization on;

配置日志删除策略:

rman target sys/oracle@prod5h1
	configure archivelog deletion policy to applied on all standby;
rman target sys/oracle@prod5h2
	configure archivelog deletion policy to applied on all standby;

自动切换相关配置:

dgmgrl sys/oracle@prod5h1
	edit database prod5h1 set property FastStartFailoverTarget='prod5h2';
	
	edit configuration set protection mode as MaxAvailability;
	enable fast_start failover;
	
	edit database prod5h1 set property TransportLagThreshold=30;
	edit database prod5h2 set property TransportLagThreshold=30;

	edit database prod5h1 set property ApplyLagThreshold=45;
	edit database prod5h2 set property ApplyLagThreshold=45;

执行主备切换:

dgmgrl sys/oracle@prod5h1
	switchover to prod5h2;

总结

DG配置看似命令较多,其实还是挺简单的,尤其是使用dg broker协助配置,很多操做都被简化了,通过show database prod5h1 verbose也可以不用背那些复杂参数即可找到参数名,切换就更为方便了。
当然除了命令行,使用EMCC也能创建备库,这里就不做展示了。
老规矩,知道写了些啥。

你可能感兴趣的:(Oracle,数据库)