m6米乐安卓版下载-米乐app官网下载
9

最佳实践,19c rac到单机adg部署方式,全程broker管理 -m6米乐安卓版下载

一、前言

前面我的文章列举了几种adg常见的搭建方式,此处我以最佳的方式作为实践过程演示;架构为rac到单机,通常这种架构大家用得比较多;
这里实践的案例adg全程是broker进行管理,broker其实是adg非常简单易用的工具,尽量我们将相关的工作交给oracle本身管理是最好的。
比如broker本身自动守护mrp进程就很不错了。

二、主库参数环境配置

1、添加备库日志

查看日志组数

select thread#,group#,members,bytes/1024/1024/1024 from v$log order by thread#;
select thread#,group#,bytes/1024/1024/1024 from v$standby_log;

note:这里我们查出来主库的redo日志组数为4组,所以我们standby log创建5组;因为官方建议是比主库多一组,没有硬性要求。

添加

alter database add standby logfile thread 1 group 13(' dg_data',' dg_arch') size 1024m;
alter database add standby logfile thread 1 group 14(' dg_data',' dg_arch') size 1024m;
alter database add standby logfile thread 1 group 15(' dg_data',' dg_arch') size 1024m;
alter database add standby logfile thread 1 group 16(' dg_data',' dg_arch') size 1024m;
alter database add standby logfile thread 1 group 17(' dg_data',' dg_arch') size 1024m;
alter database add standby logfile thread 2 group 18(' dg_data',' dg_arch') size 1024m;
alter database add standby logfile thread 2 group 19(' dg_data',' dg_arch') size 1024m;
alter database add standby logfile thread 2 group 20(' dg_data',' dg_arch') size 1024m;
alter database add standby logfile thread 2 group 21(' dg_data',' dg_arch') size 1024m;
alter database add standby logfile thread 2 group 22(' dg_data',' dg_arch') size 1024m;

note:注意thread 数要跟主库对应上。

2、开启归档和强制日志

archive log list;
alter database archivelog;
note:这里不详细展开
select force_logging from v$database;
alter database force logging;

3、主库参数配置

alter system set log_archive_config='dg_config=(rick,rickdg)';
select * from v$dataguard_config;
alter system set db_unique_name='rick'scope=spfile;
alter system set standby_file_management='auto';                                        
alter system set db_file_name_convert='/data/oradata/rickdg/',' dg_data/rick/datafile/' scope=spfile;
alter system set log_file_name_convert='/data/oradata/rickdg/',' dg_data/rick/onlinelog/' scope=spfile;

note:备库为单机环境,所以转换参数要配好

三、备库参数环境配置

note:备库参数这里看个人习惯,我习惯性拿主库的参数过来修改,出错率小

1、主库创建个pfile

create pfile='/home/oracle/pfile.bak' from spfile;

2、备库参数修改

*.audit_file_dest='/u01/app/oracle/admin/rickdg/adump'
*.audit_trail='db'
*.cluster_database=false
*.compatible='19.0.0'
*.control_files='/data/oradata/rickdg/controlfile01.ctl'
*.db_block_size=8192
*.db_file_name_convert=' dg_data/rick/datafile/','/data/oradata/rickdg/',' dg_data/rick/tempfile/','/data/oradata/rickdg/'
*.db_files=4000
*.db_name='rick'
*.db_recovery_file_dest_size=536870912000
*.db_recovery_file_dest='/data/oradata/fast_recovery_area'
*.db_unique_name='rickdg'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers=''
family:dw_helper.instance_mode='read-only'
*.local_listener='-oraagent-dummy-'
*.log_archive_config='dg_config=(rick,rickdg)'
*.log_file_name_convert=' dg_data/rick/onlinelog/','/data/oradata/rickdg/',' dg_arch/rick/onlinelog/','/data/oradata/rickdg/'
*.nls_language='american'
*.nls_territory='america'
*.open_cursors=2000
*.pga_aggregate_limit=12g
*.pga_aggregate_target=6g
*.processes=2000
*.remote_login_passwordfile='exclusive'
*.sga_max_size=10g
*.sga_target=10g
*.standby_file_management='auto'
*.undo_tablespace='undotbs1'

note:参数样例,供大家参考,注意很多细节改对,集群相关的参数要去掉

3、创建备库关键目录

mkdir -p /u01/app/oracle/admin/rickdg/adump
mkdir /data/oradata/rickdg
mkdir /data/oradata/fast_recovery_area

四、配置tns网络

note:主备库之间同步是走tcp网络,故要配好tns;有条件的话,建议配置专门的网络,避免走业务网

1、配置tns客户端信息

vi tnsnames.ora
rick=
  (description =
    (address = (protocol = tcp)(host = rick-scan)(port = 1521))
    (connect_data =
      (server = dedicated)
      (service_name = rick)
      	   (failover_mode = 
              (type = select)(method = base)(retires = 20)(delay = 15)
            )
    )
  )
rickdg =
  (description =
    (address = (protocol = tcp)(host = rickdg)(port = 1521))
    (connect_data =
      (server = dedicated)
      (service_name = rickdg)
    )
  )

2、配置静态监听

主库
sid_list_listener =
  (sid_list =
    (sid_desc =
      (global_dbname = rick)
      (oracle_home = /u01/app/oracle/product/19.0.0/dbhome_1)
      (sid_name = rick1)
    )
    (sid_desc =
      (global_dbname = rick_dgmgrl)
      (oracle_home = /u01/app/oracle/product/19.0.0/dbhome_1)
      (sid_name = rick1)
    )
  )
note:两个节点配置好
重启下监听
srvctl stop lisenter
srvctl start lisenter
备库
sid_list_listener =
  (sid_list =
    (sid_desc =
      (global_dbname = rickdg)
      (oracle_home = /u01/app/oracle/product/19.0.0/dbhome_1)
      (sid_name = rickdg)
    )
    (sid_desc =
      (global_dbname = rickdg_dgmgrl)
      (oracle_home = /u01/app/oracle/product/19.0.0/dbhome_1)
      (sid_name = rickdg)
    )
  )
重启下监听
lsnrctl start
lsnrctl stat

五、backup-based方式搭建备库

1、拷贝密码文件

主库
asmcmd
cp  dg_data/rick/password/pwdrick.282.1093287491 /home/grid
scp /home/grid/pwdrick.282.1093287491 oracle@rickdg:/u01/app/oracle/product/19.0.0/dbhome_1/dbs
备库
cd $oracle_home/dbs
mv pwdrick.282.1093287491 orapwrickdg

2、备库启动nomount

create spfile from pfile='/home/oracle/pfile.bak';
startup nomount

3、主库备份

创建备份目录

mkdir /home/oracle/backup

note:此目录主备库要创建一致

run{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup database format '/home/oracle/backup/%u' plus archivelog;
backup format '/home/oracle/backup/%u'  current controlfile ;
}
scp /home/oracle/backup/* rickdg:/home/oracle/backup

4、备库恢复还原

rman target sys/oracle123@rick auxiliary sys/oracle123
note:注意要进行主备库连接,要利用主库的catalog信息进行恢复
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate auxiliary channel c3 type disk;
allocate auxiliary channel c4 type disk;
duplicate target database for standby;
}

恢复过程:


recovery manager: release 19.0.0.0.0 - production on fri jan 7 12:00:29 2022
version 19.13.0.0.0
米乐app官网下载 copyright (c) 1982, 2019, oracle and/or its affiliates.  all rights reserved.
connected to target database: rick (dbid=3475847471)
connected to auxiliary database: rick (not mounted)
rman> run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate auxiliary channel c3 type disk;
allocate auxiliary channel c4 type disk;
duplicate target database for standby;
}2> 3> 4> 5> 6> 7> 
using target database control file instead of recovery catalog
allocated channel: c1
channel c1: sid=197 instance=hip1 device type=disk
allocated channel: c2
channel c2: sid=2465 instance=hip1 device type=disk
allocated channel: c3
channel c3: sid=1513 device type=disk
allocated channel: c4
channel c4: sid=1137 device type=disk
starting duplicate db at 07-jan-22
contents of memory script:
{
   restore clone standby controlfile;
}
executing memory script
starting restore at 07-jan-22
channel c3: starting datafile backup set restore
channel c3: restoring control file
channel c3: reading from backup piece  dg_arch/rick/autobackup/2022_01_07/s_1093348509.298.1093348509
channel c3: ora-19870: error while restoring backup piece  dg_arch/rick/autobackup/2022_01_07/s_1093348509.298.1093348509
ora-19505: failed to identify file " dg_arch/rick/autobackup/2022_01_07/s_1093348509.298.1093348509"
ora-17503: ksfdopn:2 failed to open file  dg_arch/rick/autobackup/2022_01_07/s_1093348509.298.1093348509
ora-15001: diskgroup "dg_arch" does not exist or is not mounted
failover to previous backup
channel c3: starting datafile backup set restore
channel c3: restoring control file
channel c3: reading from backup piece /home/oracle/backup/0a0imb4r_10_1_1
channel c3: piece handle=/home/oracle/backup/0a0imb4r_10_1_1 tag=tag20220107t115506
channel c3: restored backup piece 1
channel c3: restore complete, elapsed time: 00:00:01
output file name=/data/oradata/rickdg/controlfile01.ctl
finished restore at 07-jan-22
contents of memory script:
{
   sql clone 'alter database mount standby database';
}
executing memory script
sql statement: alter database mount standby database
contents of memory script:
{
   set newname for tempfile  1 to 
 "/data/oradata/rickdg/temp.290.1093287863";
   set newname for tempfile  2 to 
 "/data/oradata/rickdg/temp.293.1093346713";
   set newname for tempfile  3 to 
 "/data/oradata/rickdg/temp.292.1093346713";
   switch clone tempfile all;
   set newname for datafile  1 to 
 "/data/oradata/rickdg/system.283.1093287729";
   set newname for datafile  2 to 
 "/data/oradata/rickdg/system.289.1093346719";
   set newname for datafile  3 to 
 "/data/oradata/rickdg/sysaux.284.1093287763";
   set newname for datafile  4 to 
 "/data/oradata/rickdg/undotbs1.285.1093287789";
   set newname for datafile  5 to 
 "/data/oradata/rickdg/undotbs2.291.1093288043";
   set newname for datafile  7 to 
 "/data/oradata/rickdg/users.286.1093287789";
   set newname for datafile  8 to 
 "/data/oradata/rickdg/undotbs1.288.1093346723";
   set newname for datafile  9 to 
 "/data/oradata/rickdg/undotbs1.320.1093346727";
   set newname for datafile  10 to 
 "/data/oradata/rickdg/undotbs2.321.1093346731";
   set newname for datafile  11 to 
 "/data/oradata/rickdg/undotbs2.322.1093346735";
   restore
   clone database
   ;
}
executing memory script
executing command: set newname
executing command: set newname
executing command: set newname
renamed tempfile 1 to /data/oradata/rickdg/temp.290.1093287863 in control file
renamed tempfile 2 to /data/oradata/rickdg/temp.293.1093346713 in control file
renamed tempfile 3 to /data/oradata/rickdg/temp.292.1093346713 in control file
executing command: set newname
executing command: set newname
executing command: set newname
executing command: set newname
executing command: set newname
executing command: set newname
executing command: set newname
executing command: set newname
executing command: set newname
executing command: set newname
starting restore at 07-jan-22
channel c3: starting datafile backup set restore
channel c3: specifying datafile(s) to restore from backup set
channel c3: restoring datafile 00002 to /data/oradata/rickdg/system.289.1093346719
channel c3: restoring datafile 00005 to /data/oradata/rickdg/undotbs2.291.1093288043
channel c3: restoring datafile 00007 to /data/oradata/rickdg/users.286.1093287789
channel c3: restoring datafile 00009 to /data/oradata/rickdg/undotbs1.320.1093346727
channel c3: restoring datafile 00011 to /data/oradata/rickdg/undotbs2.322.1093346735
channel c3: reading from backup piece /home/oracle/backup/070imb48_7_1_1
channel c4: starting datafile backup set restore
channel c4: specifying datafile(s) to restore from backup set
channel c4: restoring datafile 00001 to /data/oradata/rickdg/system.283.1093287729
channel c4: restoring datafile 00003 to /data/oradata/rickdg/sysaux.284.1093287763
channel c4: restoring datafile 00004 to /data/oradata/rickdg/undotbs1.285.1093287789
channel c4: restoring datafile 00008 to /data/oradata/rickdg/undotbs1.288.1093346723
channel c4: restoring datafile 00010 to /data/oradata/rickdg/undotbs2.321.1093346731
channel c4: reading from backup piece /home/oracle/backup/060imb48_6_1_1
channel c3: piece handle=/home/oracle/backup/070imb48_7_1_1 tag=tag20220107t115447
channel c3: restored backup piece 1
channel c3: restore complete, elapsed time: 00:00:25
channel c4: piece handle=/home/oracle/backup/060imb48_6_1_1 tag=tag20220107t115447
channel c4: restored backup piece 1
channel c4: restore complete, elapsed time: 00:00:25
finished restore at 07-jan-22
contents of memory script:
{
   switch clone datafile all;
}
executing memory script
datafile 1 switched to datafile copy
input datafile copy recid=1 stamp=1093348896 file name=/data/oradata/rickdg/system.283.1093287729
datafile 2 switched to datafile copy
input datafile copy recid=2 stamp=1093348896 file name=/data/oradata/rickdg/system.289.1093346719
datafile 3 switched to datafile copy
input datafile copy recid=3 stamp=1093348896 file name=/data/oradata/rickdg/sysaux.284.1093287763
datafile 4 switched to datafile copy
input datafile copy recid=4 stamp=1093348896 file name=/data/oradata/rickdg/undotbs1.285.1093287789
datafile 5 switched to datafile copy
input datafile copy recid=5 stamp=1093348896 file name=/data/oradata/rickdg/undotbs2.291.1093288043
datafile 7 switched to datafile copy
input datafile copy recid=6 stamp=1093348896 file name=/data/oradata/rickdg/users.286.1093287789
datafile 8 switched to datafile copy
input datafile copy recid=7 stamp=1093348896 file name=/data/oradata/rickdg/undotbs1.288.1093346723
datafile 9 switched to datafile copy
input datafile copy recid=8 stamp=1093348897 file name=/data/oradata/rickdg/undotbs1.320.1093346727
datafile 10 switched to datafile copy
input datafile copy recid=9 stamp=1093348897 file name=/data/oradata/rickdg/undotbs2.321.1093346731
datafile 11 switched to datafile copy
input datafile copy recid=10 stamp=1093348897 file name=/data/oradata/rickdg/undotbs2.322.1093346735
finished duplicate db at 07-jan-22
released channel: c1
released channel: c2
released channel: c3
released channel: c4
rman>

note:至此备库恢复完成

六、配置broker

note:剩下关键步骤,配置broker建立主备库之间的通讯同步

1、主库启动broker

alter system set dg_broker_config_file1 = ' dg_data/rick/broker/dr1.dat' scope=both;
alter system set dg_broker_config_file2 = ' dg_data/rick/broker/dr2.dat' scope=both;
alter system set dg_broker_start=true;

note:这里我们将broker配置文件放在asm当中

2、备库启动broker

alter system set dg_broker_start=true;

3、创建dg配置

note:主备库任意节点操作即可

连接
dgmgrl /
创建
create configuration 'rickadg' as primary database is 'rick' connect identifier is 'rick';
添加备库
add database 'rickdg' as connect identifier is 'rickdg';

4、启用配置

enable configuration;

note:启用后自动同步配置文件到主库或者备库,次过程为关键过程,会自动建立主备库的通讯连接,配置arch dest、fal server 等参数,启动启动mrp等进程

5、查看配置

show configuration;
configuration - rickadg
  protection mode: maxperformance
  members:
  rick   - primary database
    rickdg - physical standby database 
fast-start failover:  disabled
configuration status:
success   (status updated 52 seconds ago)

note:可以看到配置状态正常

6、查看数据库配置

show database verbose rickdg;
database - rickdg
  role:               physical standby
  intended state:     apply-on
  transport lag:      0 seconds (computed 0 seconds ago)
  apply lag:          0 seconds (computed 0 seconds ago)
  average apply rate: 1.00 kbyte/s
  active apply rate:  40.00 kbyte/s
  maximum apply rate: 40.00 kbyte/s
  real time query:    on
  instance(s):
    rickdg
  properties:
    dgconnectidentifier             = 'rickdg'
    observerconnectidentifier       = ''
    faststartfailovertarget         = ''
    preferredobserverhosts          = ''
    logshipping                     = 'on'
    redoroutes                      = ''
    logxptmode                      = 'async'
    delaymins                       = '0'
    binding                         = 'optional'
    maxfailure                      = '0'
    reopensecs                      = '300'
    nettimeout                      = '30'
    redocompression                 = 'disable'
    preferredapplyinstance          = ''
    applyinstancetimeout            = '0'
    applylagthreshold               = '30'
    transportlagthreshold           = '30'
    transportdisconnectedthreshold  = '30'
    applyparallel                   = 'auto'
    applyinstances                  = '0'
    standbyfilemanagement           = ''
    archivelagtarget                = '0'
    logarchivemaxprocesses          = '0'
    logarchiveminsucceeddest        = '0'
    dataguardsynclatency            = '0'
    logarchivetrace                 = '0'
    logarchiveformat                = ''
    dbfilenameconvert               = ''
    logfilenameconvert              = ''
    archivelocation                 = ''
    alternatelocation               = ''
    standbyarchivelocation          = ''
    standbyalternatelocation        = ''
    inconsistentproperties          = '(monitor)'
    inconsistentlogxptprops         = '(monitor)'
    logxptstatus                    = '(monitor)'
    sendqentries                    = '(monitor)'
    recvqentries                    = '(monitor)'
    hostname                        = 'rickdg'
    staticconnectidentifier         = '(description=(address=(protocol=tcp)(host=hipdg)(port=1521))(connect_data=(service_name=rickdg_dgmgrl)(instance_name=hipdg)(server=dedicated)))'
    topwaitevents                   = '(monitor)'
    sidname                         = '(monitor)'
  log file locations:
    alert log               : /u01/app/oracle/diag/rdbms/rickdg/hipdg/trace/alert_rickdg.log
    data guard broker log   : /u01/app/oracle/diag/rdbms/rickdg/hipdg/trace/drchipdg.log
database status:
success
dgmgrl> 

note:至此adg搭建完成

七、后续配置与主备切换

一个合格的adg是可以进行主备之前来回任意切换的,并且创建数据文件和切换归档是正常同步的

1、配置最高可用模式

edit database 'rick' set property 'logxptmode'='sync';
edit database 'rickdg' set property 'logxptmode'='sync';
edit configuration set protection mode as maxavailability;

查看

show configuration;
dgmgrl> show configuration;
configuration - rickadg
  protection mode: maxavailability
  members:
  rick   - primary database
    rickdg - physical standby database 
fast-start failover:  disabled
configuration status:
success   (status updated 52 seconds ago)

note:可以看到已经改变为最高可用模式了

2、主备切换

连接

dgmgrl
connect sys/oracle123@rick

note:注意一定要使用密码连接。

开启转换

switchover to rickdg;
dgmgrl> switchover to rickdg
performing switchover now, please wait...
new primary database "rickdg" is opening...
operation requires start up of instance "rick" on database "rick"
starting instance "rick"...
connected to an idle instance.
oracle instance started.
connected to "rick"
database mounted.
database opened.
connected to "rick"
switchover succeeded, new primary is "rickdg"
dgmgrl> 

note:可以看到切换是相当的方便,在切换的过程中注意观察主备库之间alert日志,监测实时过程。

查看配置

show configuration;
configuration - rickadg
  protection mode: maxavailability
  members:
  rickdg - primary database
    rick   - physical standby database 
fast-start failover:  disabled
configuration status:
success   (status updated 27 seconds ago)
dgmgrl> 

note:等待一会,进行查看,可以看到角色已经互换了。

3、同步测试

创建数据文件

新主库:
create tablespace test datafile '/data/oradata/rickdg/test01.dbf' size 100m
completed: create tablespace test datafile '/data/oradata/rickdg/test01.dbf' size 100m
新备库:
2022-01-07t14:16:52.894528 08:00
successfully added datafile 12 to media recovery
datafile #12: ' dg_data/rick/datafile/test.326.1093357013'

切换归档测试

新主库:
2022-01-07t14:19:36.844258 08:00
thread 1 advanced to log sequence 32 (lgwr switch),  current scn: 3333166
  current log# 8 seq# 32 mem# 0: /data/oradata/rickdg/group_8.315.1093346407
  current log# 8 seq# 32 mem# 1: /data/oradata/rickdg/group_8.274.1093346411
2022-01-07t14:19:36.861642 08:00
arc3 (pid:7472): archived log entry 28 added for t-1.s-31 id 0xcf2e0982 lad:1
新备库:
2022-01-07t14:19:33.730141 08:00
pr00 (pid:10498): media recovery waiting for t-1.s-32 (in transit)
2022-01-07t14:19:33.734836 08:00
recovery of online redo log: thread 1 group 13 seq 32 reading mem 0
  mem# 0:  dg_data/rick/onlinelog/group_13.297.1093304763
  mem# 1:  dg_arch/rick/onlinelog/group_13.256.1093304767

note:可以看到同步正常

最后修改时间:2022-02-16 23:44:23
「喜欢文章,快来给作者赞赏墨值吧」
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

网站地图