Using Oracle Data Guard with a Sharded Database

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Using Oracle Data Guard with a Sharded Database相关的知识,希望对你有一定的参考价值。

本文介绍如何部署一个带有adg功能的sharded database。

1、环境介绍

各个节点的角色以及数据库版本如下表所示:
技术图片
其中实例名是系统自己命名的。

2、创建Shard Catalog Database

这里使用静默方式在odb01上创建目录数据库。

[[email protected] ~]$ vi /tmp/dbca.rsp
responseFileVersion=/oracle/assistants/rspfmt_dbca_response_schema_v12.2.0
gdbName=shcdb
sid=shcdb
databaseConfigType=SI
RACOneNodeServiceName=
policyManaged=false
createServerPool=false
force=false
createAsContainerDatabase=false
useLocalUndoForPDBs=true
templateName=/u01/app/oracle/product/19.3.0/db_1/assistants/dbca/templates/General_Purpose.dbc
sysPassword=abcABC12
systemPassword=abcABC12
serviceUserPassword=abcABC12
emConfiguration=DBEXPRESS
emExpressPort=5500
runCVUChecks=FALSE
dbsnmpPassword=abcABC12
dvConfiguration=false
olsConfiguration=false
datafileJarLocation=ORACLE_HOME/assistants/dbca/templates/
datafileDestination=ORACLE_BASE/oradata/DB_UNIQUE_NAME/
recoveryAreaDestination=ORACLE_BASE/fast_recovery_area/DB_UNIQUE_NAME
storageType=FS
characterSet=ZHS16GBK
nationalCharacterSet=AL16UTF16
registerWithDirService=false
variables=ORACLE_BASE_HOME=/u01/app/oracle/product/19.3.0/db_1,DB_UNIQUE_NAME=shcdb,ORACLE_BASE=/u01/app/oracle,PDB_NAME=,DB_NAME=shcdb,ORACLE_HOME=/u01/app/oracle/product/19.3.0/db_1,SID=shcdb
initParams=sga_target=3GB,nls_language=AMERICAN,remote_login_passwordfile=EXCLUSIVE,db_create_file_dest=ORACLE_BASE/oradata/DB_UNIQUE_NAME/,audit_file_dest=ORACLE_BASE/admin/DB_UNIQUE_NAME/adump,processes=1000,pga_aggregate_target=1GB,nls_territory=AMERICA,db_recovery_file_dest_size=30GB,open_cursors=300,db_name=shcdb,db_recovery_file_dest=ORACLE_BASE/fast_recovery_area/DB_UNIQUE_NAME,audit_trail=NONE
sampleSchema=false
memoryPercentage=65
databaseType=MULTIPURPOSE
automaticMemoryManagement=false
totalMemory=0
[[email protected] ~]$ dbca -silent -ignorePreReqs -createDatabase -responseFile /tmp/dbca.rsp -enableArchive true -redoLogFileSize 1024  

待数据库创建完成后,执行下面的SQL,完成后重启数据库实例。

alter system set open_links=16 scope=spfile;
alter system set open_links_per_instance=16 scope=spfile;
alter user gsmcatuser account unlock;
alter user gsmcatuser identified by oracle;                
create user gdsadmin identified by oracle;
GRANT connect, create session, gsmadmin_role to gdsadmin;
grant inherit privileges on user SYS to GSMADMIN_INTERNAL; 
execute dbms_xdb.sethttpport(8080);
commit;
@?/rdbms/admin/prvtrsch.plb
exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS(‘oracle‘);
SQL> shutdown immediate
SQL> startup

3、安装并配置GSM

GSM的安装很简单,这里使用静默方式安装,静默文件内容如下:

[[email protected] ~]$ vi /tmp/gsm.rsp 
oracle.install.responseFileVersion=/oracle/install/rspfmt_gsminstall_response_schema_v19.0.0
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oraInventory
ORACLE_HOME=/u01/app/oracle/product/19.3.0/gsm
ORACLE_BASE=/u01/app/oracle
[[email protected] ~]$ /u02/tmp/gsm/runInstaller -silent -ignorePrereq -responseFile /tmp/gsm.rsp
  • 创建shard catalog
[[email protected] ~]$ gdsctl 
GDSCTL: Version 19.0.0.0.0 - Production on Mon Jul 15 11:09:20 CST 2019

Copyright (c) 2011, 2019, Oracle.  All rights reserved.

Welcome to GDSCTL, type "help" for information.

Warning:  GSM  is not set automatically because gsm.ora does not contain GSM entries. Use "set  gsm" command to set GSM for the session.
Current GSM is set to GSMORA
GDSCTL> create shardcatalog -database odb01:1521:shcdb -chunks 12 -user gdsadmin/oracle -sdb shcdb -region region1,region2
GDSCTL> add gsm -gsm sharddirector1 -listener 1531 -pwd oracle -catalog odb01:1521:shcdb -region region1
GDSCTL> add gsm -gsm sharddirector2 -listener 1531 -pwd oracle -catalog odb01:1521:shcdb -region region2
GDSCTL> start gsm -gsm sharddirector1
  • 添加操作系统凭证

    GDSCTL> add credential -credential cre_reg1 -osaccount oracle -ospassword oracle
  • shard node上启动代理并向shard catalog注册
[[email protected] ~]$ schagent -start;echo oracle|schagent -registerdatabase odb01 8080
[[email protected] ~]$ schagent -start;echo oracle|schagent -registerdatabase odb01 8080
[[email protected] ~]$ schagent -start;echo oracle|schagent -registerdatabase odb01 8080
[[email protected] ~]$ schagent -start;echo oracle|schagent -registerdatabase odb01 8080
  • shard node上创建数据库文件目录
    此路径要和shard catalog database的路径保持一致。
    [[email protected] ~]$ mkdir /u01/app/oracle/oradata,fast_recovery_area
    [[email protected] ~]$ mkdir /u01/app/oracle/oradata,fast_recovery_area
    [[email protected] ~]$ mkdir /u01/app/oracle/oradata,fast_recovery_area
    [[email protected] ~]$ mkdir /u01/app/oracle/oradata,fast_recovery_area

4、部署System-Managed Sharded Database

这里分别创建primary group和standby group。

  • 创建shardgroup
    GDSCTL> add shardgroup -shardgroup primary_sgp -region region1 -deploy_as primary
    GDSCTL> add shardgroup -shardgroup standby_sgp -region region2 -deploy_as active_standby
  • 向组添加成员
    这里将odb05和odb06添加至primary group;odb07和odb08添加至standby group。
GDSCTL> add invitednode odb05
GDSCTL> create shard -shardgroup primary_sgp -destination odb05 -credential cre_reg1
The operation completed successfully
DB Unique Name: sh1
GDSCTL> add invitednode odb06
GDSCTL> create shard -shardgroup primary_sgp -destination odb06 -credential cre_reg1
The operation completed successfully
DB Unique Name: sh3
GDSCTL> add invitednode odb07
GDSCTL> create shard -shardgroup standby_sgp -destination odb07 -credential cre_reg1
The operation completed successfully
DB Unique Name: sh4
GDSCTL> add invitednode odb08
GDSCTL> create shard -shardgroup standby_sgp -destination odb08 -credential cre_reg1
The operation completed successfully
DB Unique Name: sh5

使用config命令读取配置信息进行验证,如下图:
技术图片
技术图片

  • 部署shards
    执行deploy命令在各个节点部署。
    GDSCTL> deploy
    deploy: examining configuration...
    deploy: deploying primary shard ‘sh1‘ ...
    deploy: network listener configuration successful at destination ‘odb05‘
    deploy: starting DBCA at destination ‘odb05‘ to create primary shard ‘sh1‘ ...
    deploy: deploying primary shard ‘sh3‘ ...
    deploy: network listener configuration successful at destination ‘odb06‘
    deploy: starting DBCA at destination ‘odb06‘ to create primary shard ‘sh3‘ ...
    deploy: waiting for 2 DBCA primary creation job(s) to complete...
    deploy: waiting for 2 DBCA primary creation job(s) to complete...
    deploy: waiting for 2 DBCA primary creation job(s) to complete...
    deploy: waiting for 2 DBCA primary creation job(s) to complete...
    deploy: waiting for 2 DBCA primary creation job(s) to complete...
    deploy: waiting for 2 DBCA primary creation job(s) to complete...
    deploy: waiting for 2 DBCA primary creation job(s) to complete...
    deploy: waiting for 2 DBCA primary creation job(s) to complete...
    deploy: waiting for 2 DBCA primary creation job(s) to complete...
    deploy: waiting for 2 DBCA primary creation job(s) to complete...
    deploy: waiting for 2 DBCA primary creation job(s) to complete...
    deploy: waiting for 2 DBCA primary creation job(s) to complete...
    deploy: DBCA primary creation job succeeded at destination ‘odb05‘ for shard ‘sh1‘
    deploy: deploying standby shard ‘sh4‘ ...
    deploy: network listener configuration successful at destination ‘odb07‘
    deploy: starting DBCA at destination ‘odb07‘ to create standby shard ‘sh4‘ ...
    deploy: DBCA primary creation job succeeded at destination ‘odb06‘ for shard ‘sh3‘
    deploy: deploying standby shard ‘sh5‘ ...
    deploy: network listener configuration successful at destination ‘odb08‘
    deploy: starting DBCA at destination ‘odb08‘ to create standby shard ‘sh5‘ ...
    deploy: waiting for 2 DBCA standby creation job(s) to complete...
    deploy: waiting for 2 DBCA standby creation job(s) to complete...
    deploy: waiting for 2 DBCA standby creation job(s) to complete...
    deploy: waiting for 2 DBCA standby creation job(s) to complete...
    deploy: waiting for 2 DBCA standby creation job(s) to complete...
    deploy: DBCA standby creation job succeeded at destination ‘odb07‘ for shard ‘sh4‘
    deploy: waiting for 1 DBCA standby creation job(s) to complete...
    deploy: DBCA standby creation job succeeded at destination ‘odb08‘ for shard ‘sh5‘
    deploy: requesting Data Guard configuration on shards via GSM
    deploy: shards configured successfully
    The operation completed successfully

    部署完成后,进行验证,如下图所示:
    技术图片
    技术图片

  • 添加global service
GDSCTL> add service -service oltp_rw_srvc -role primary
The operation completed successfully
GDSCTL> start service -service oltp_rw_srvc
The operation completed successfully
GDSCTL> add service -service oltp_ro_srvc -role physical_standby
The operation completed successfully
GDSCTL> start service -service oltp_ro_srvc
The operation completed successfully
GDSCTL> services
Service "oltp_ro_srvc.shcdb.oradbcloud" has 2 instance(s). Affinity: ANYWHERE
   Instance "shcdb%21", name: "sh4", db: "sh4", region: "region2", status: ready.
   Instance "shcdb%31", name: "sh5", db: "sh5", region: "region2", status: ready.
Service "oltp_rw_srvc.shcdb.oradbcloud" has 2 instance(s). Affinity: ANYWHERE
   Instance "shcdb%1", name: "sh1", db: "sh1", region: "region1", status: ready.
   Instance "shcdb%11", name: "sh3", db: "sh3", region: "region1", status: ready.
  • 验证DataGuard状态
    技术图片
    技术图片

参考文献:
1、Using Oracle Sharding
2、Oracle 12C Sharding分片数据库

以上是关于Using Oracle Data Guard with a Sharded Database的主要内容,如果未能解决你的问题,请参考以下文章

Using Oracle Data Guard with a Sharded Database

12c Data guard Switchover Best Practices using SQLPLUS (Doc ID 1578787.1)

[译] Data Guard:Oracle Database 21c 中的 PREPARE DATABASE FOR DATA GUARD 命令

11.2 Data Guard Physical Standby Switchover Best Practices using SQL*Plus (Doc ID 1304939.1)

Oracle Active Data Guard和Data Guard的区别

Oracle Data Guard Protection Modes