【Step By Step】Oracle 11gR2 RAC to RAC ADG安装


0.Summary

1. 配置DG专用网络
.   1.1 Primary添加网络和监听
.   1.2 Standby添加网络和监听
2. 主库准备
3. 备库配置tnsnames.ora和监听
4. 主库创建pfile
5. 修改备库pfile
6. 主库修改参数
7. 主库添加standby日志
8. 同步数据
9. 注册OCR并打开备库
10. 备库应用日志
11. 检查角色和保护等级
12. 处理遗留问题

1. 配置DG专用网络

1.1 Primary添加网络和监听

cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.27    oratest1
192.168.1.28    oratest2
192.168.2.27    oratest1-priv
192.168.2.28    oratest2-priv
192.168.1.29    oratest1-vip
192.168.1.30    oratest2-vip
192.168.1.26    oradb-scan

192.168.4.27    oratest1-dg
192.168.4.28    oratest2-dg
192.168.4.29    oratest1-dg-vip
192.168.4.30    oratest2-dg-vip

192.168.4.53    oradg1-dg-vip
192.168.4.54    oradg2-dg-vip

# srvctl add network -k 2 -S 192.168.4.0/255.255.255.0/eth6 -w static -v
# crsctl stat res -t | grep network 
ora.net1.network
ora.net2.network
# crsctl start res ora.net2.network
# srvctl add vip -n oratest1 -A 192.168.4.29/255.255.255.0 -k 2
# srvctl add vip -n oratest2 -A 192.168.4.30/255.255.255.0 -k 2

$ netca

Oracle Net Services Configuration:
Oracle Net Configuration Assistant is launched from Grid Infrastructure home. Network configuration will be clusterwide.
Configuring Listener:LISTENER_DG
oratest1...
oratest2...
Listener configuration complete.
Oracle Net Listener Startup:
    Listener started successfully.
Oracle Net Services configuration successful. The exit code is 0

将数据库实例注册到新建的监听地址中

alter system set local_listener='(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.29)(PORT = 1521))','(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.4.29)(PORT = 1555))' scope=both sid='oradb1';
alter system set local_listener='(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.30)(PORT = 1521))','(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.4.30)(PORT = 1555))' scope=both sid='oradb2';

1.2 Standby添加网络和监听

cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.51    oradg1
192.168.1.52    oradg2
192.168.2.51    oradg1-priv
192.168.2.52    oradg2-priv
192.168.1.53    oradg1-vip
192.168.1.54    oradg2-vip
192.168.1.50    oradg-scan

192.168.4.51    oradg1-dg
192.168.4.52    oradg2-dg
192.168.4.53    oradg1-dg-vip
192.168.4.54    oradg2-dg-vip

192.168.4.29    oratest1-dg-vip
192.168.4.30    oratest2-dg-vip

# srvctl add network -k 2 -S 192.168.4.0/255.255.255.0/eth3 -w static -v
# crsctl stat res -t | grep network
ora.net1.network
ora.net2.network
# crsctl start res ora.net2.network
# srvctl add vip -n oradg1 -A 192.168.4.53/255.255.255.0 -k 2
# srvctl add vip -n oradg2 -A 192.168.4.54/255.255.255.0 -k 2

$ netca 

Oracle Net Services Configuration:
Oracle Net Configuration Assistant is launched from Grid Infrastructure home. Network configuration will be clusterwide.
Configuring Listener:LISTENER_DG
oradg1...
oradg2...
Listener configuration complete.
Oracle Net Listener Startup:
    Listener started successfully.
Oracle Net Services configuration successful. The exit code is 0

2. 主库准备

alter database force logging;
select log_mode,
       supplemental_log_data_min,
       supplemental_log_data_pk,
       supplemental_log_data_ui,
       force_logging
  from v$database;

LOG_MODE     SUPPLEME SUP SUP FOR
------------ -------- --- --- ---
ARCHIVELOG   NO       NO  NO  YES

Best Practices for Corruption Detection, Prevention, and Automatic Repair - in a Data Guard Configuration (Doc ID 1302539.1)

alter system set db_lost_write_protect=typical scope=both sid='*';
alter system set db_block_checksum=full scope=both sid='*';
alter system set db_block_checking=medium scope=both sid='*';

配置主库的tnsnames.ora和监听

$ cat tnsnames.ora 
......

ORADB_P =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.4.29)(PORT = 1555))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.4.30)(PORT = 1555))
      (LOAD_BALANCE = off)
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORADB)
    )
  )

ORADB_S =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.4.53)(PORT = 1555))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.4.54)(PORT = 1555))
      (LOAD_BALANCE = off)
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORADB)
    )
  )

注意使用静态监听

$ cat listener.ora
......

SID_LIST_LISTENER_DG =
 (SID_LIST =
   (SID_DESC =
     (GLOBAL_DBNAME = oradb)
     (ORACLE_HOME = /oracle/app/oracle/product/11.2.0/db_1)
     (SID_NAME = oradb1)
    )
  )

$ cat listener.ora
......

SID_LIST_LISTENER_DG =
 (SID_LIST =
   (SID_DESC =
     (GLOBAL_DBNAME = oradb)
     (ORACLE_HOME = /oracle/app/oracle/product/11.2.0/db_1)
     (SID_NAME = oradb2)
    )
  )

重启监听

$ srvctl stop listener -l listener_dg
$ srvctl start listener -l listener_dg

3. 备库配置tnsnames.ora和监听

$ cat tnsnames.ora 

ORADB_P =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.4.29)(PORT = 1555))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.4.30)(PORT = 1555))
      (LOAD_BALANCE = off)
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORADB)
    )
  )

ORADB_S =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.4.53)(PORT = 1555))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.4.54)(PORT = 1555))
      (LOAD_BALANCE = off)
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORADB)
    )
  )

$ cat listener.ora
......

SID_LIST_LISTENER_DG =
 (SID_LIST =
   (SID_DESC =
     (GLOBAL_DBNAME = oradb)
     (ORACLE_HOME = /oracle/app/oracle/product/11.2.0/db_1)
     (SID_NAME = oradb1)
    )
  )

$ cat listener.ora
......

SID_LIST_LISTENER_DG =
 (SID_LIST =
   (SID_DESC =
     (GLOBAL_DBNAME = oradb)
     (ORACLE_HOME = /oracle/app/oracle/product/11.2.0/db_1)
     (SID_NAME = oradb2)
    )
  )

重启监听

$ srvctl stop listener -l listener_dg
$ srvctl start listener -l listener_dg

备库创建必要的目录

cd $ORACLE_BASE
mkdir -p admin/oradb/{adump,dpdump,pfile,hdump}

主库将pwd文件复制到备库

cd $ORACLE_HOME/dbs
scp orapworadb1 oradg1-dg-vip:`pwd`

cd $ORACLE_HOME/dbs
scp orapworadb2 oradg2-dg-vip:`pwd`

4. 主库创建pfile

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

将pfile复制到备库

cd /home/oracle
scp init_p.ora oradg1-dg-vip:`pwd`/init_s.ora

5. 修改备库pfile

oradb1.local_listener='(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.53)(PORT = 1521))','(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.4.53)(PORT = 1555))'
oradb2.local_listener='(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.54)(PORT = 1521))','(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.4.54)(PORT = 1555))'
*.db_unique_name='oradb_s'
*.log_archive_config='dg_config=(oradb_s,oradb)'
*.log_archive_dest_1='LOCATION=+FRA valid_for=(all_logfiles,all_roles) db_unique_name=oradb_s'
*.log_archive_dest_2='service=oradb_p valid_for=(online_logfiles,primary_role) lgwr async db_unique_name=oradb'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.standby_file_management='auto'
*.fal_server='oradb'
*.db_file_name_convert='+DATADG/ORADB_S','+DATADG/ORADB'
*.log_file_name_convert='+DATADG/ORADB_S','+DATADG/ORADB'
*.remote_listener='oradg-scan:1521'

ORA-19527 reported in Standby Database when starting Managed Recovery (Doc ID 352879.1)

LOG_FILE_NAME_CONVERT目录一致主要为了解决主备角色切换时,online redo clear的问题。即使路径一致的情况,如果不设置这个参数,在rman duplicate也会发生类似告警,不过不影响应用启动。

备库创建spfile

SYS@+ASM1>alter diskgroup datadg add directory '+DATADG/ORADB_S';
SYS@oradb1>create spfile='+DATADG/oradb_s/spfileoradb.ora' from pfile='/home/oracle/init_s.ora';

cd $ORACLE_HOME/dbs
echo "SPFILE='+DATADG/oradb_s/spfileoradb.ora'" > initoradb1.ora
cd $ORACLE_HOME/dbs
echo "SPFILE='+DATADG/oradb_s/spfileoradb.ora'" > initoradb2.ora

备库启动到nomount状态

SYS@oradb1>startup nomount;
ORA-01565: error in identifying file '+DATADG/oradb_s/spfileoradb.ora'
ORA-17503: ksfdopn:2 Failed to open file +DATADG/oradb_s/spfileoradb.ora
ORA-15001: diskgroup "DATADG" does not exist or is not mounted
ORA-15040: diskgroup is incomplete

Converting R12 11g To RAC/ASM using rconfig failed with ORA-19504, ORA-17502, and ORA-15001 errors (Doc ID 1941108.1)

$ ls -ltr $ORACLE_HOME/bin/oracle
-rwsr-s--x 1 oracle oinstall 239839854 Oct  4 13:33 /oracle/app/oracle/product/11.2.0/db_1/bin/oracle
$ /oracle/app/11.2.0/grid/bin/setasmgidwrap o=$ORACLE_HOME/bin/oracle
$ ls -ltr $ORACLE_HOME/bin/oracle                                    
-rwsr-s--x 1 oracle asmadmin 239839854 Oct  4 13:33 /oracle/app/oracle/product/11.2.0/db_1/bin/oracle

SYS@oradb1>startup nomount

6. 主库修改参数

主要修改db_unique_name需要重启,如果不修改主库的这个参数,可以不用重启。ASM情况下最好不要修改,默认会减到OMF指定DG下的db_unique_name路径下,如果修改了那么convert参数需要注意设置全至少两个转换路径。

下面这个例子实际上db_unique_name没变

alter system set db_unique_name='oradb' scope=spfile sid='*';
alter system set log_archive_config='dg_config=(oradb,oradb_s)' scope=spfile sid='*';
alter system set log_archive_dest_1='location=+FRA valid_for=(all_logfiles,all_roles) db_unique_name=oradb' scope=spfile sid='*';
alter system set log_archive_dest_2='service=oradb_s valid_for=(online_logfiles,primary_role) lgwr async db_unique_name=oradb_s' scope=spfile sid='*';
alter system set log_archive_dest_state_1=enable scope=spfile sid='*';
alter system set log_archive_dest_state_2=enable scope=spfile sid='*';
alter system set standby_file_management='auto' scope=spfile sid='*';
alter system set fal_server='oradb_s' scope=spfile sid='*';
alter system set db_file_name_convert='+DATADG/ORADB_S','+DATADG/ORADB' scope=spfile sid='*';
alter system set log_file_name_convert='+DATADG/ORADB_S','+DATADG/ORADB' scope=spfile sid='*';

重启主库

srvctl stop database -d oradb
srvctl start database -d oradb  

7. 主库添加standby日志

alter database add standby logfile thread 1 group 7  '+DATADG' size 100M;
alter database add standby logfile thread 1 group 8  '+DATADG' size 100M;
alter database add standby logfile thread 1 group 9  '+DATADG' size 100M;
alter database add standby logfile thread 1 group 10 '+DATADG' size 100M;
alter database add standby logfile thread 2 group 11 '+DATADG' size 100M;
alter database add standby logfile thread 2 group 12 '+DATADG' size 100M;
alter database add standby logfile thread 2 group 13 '+DATADG' size 100M;
alter database add standby logfile thread 2 group 14 '+DATADG' size 100M;

set lines 200 pages 200
col member for a60
select a.group#,b.thread#,a.member, b.status,b.bytes/1024/1024 MB from v$logfile a, v$log b
 where a.group#=b.group#
 union all
select a.group#,b.thread#,a.member, b.status,b.bytes/1024/1024 MB from v$logfile a, v$standby_log b
 where a.group#=b.group#
 order by 2,1,3;

8. 同步数据

主库做全备,并将备份集传到备库

cd /home/oracle/backup
scp * oradg1-dg-vip:`pwd`

恢复数据库

RMAN> restore standby controlfile from '/home/oracle/backup/oradb1_ctl_file_10sgbonq_1_1_20171006';
RMAN> sql 'alter database mount standby database';
RMAN> restore database;
RMAN> recover database;

最后出现的报错可以忽略,因为少的是online redo log。

unable to find archived log
archived log thread=1 sequence=125
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 10/06/2017 20:39:23
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 125 and starting SCN of 5673763

备库数据文件头

SYS@oradb1>select file#, status, checkpoint_change#, checkpoint_count from v$datafile_header order by 1;

     FILE# STATUS  CHECKPOINT_CHANGE# CHECKPOINT_COUNT
---------- ------- ------------------ ----------------
         1 ONLINE             5673763              137
         2 ONLINE             5673763              137
         3 ONLINE             5673763              137
         4 ONLINE             5673763              136
         5 ONLINE             5673763              136
         6 ONLINE             5673763              105

主库日志

SYS@oradb1>select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME   NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------ ------------ ------------
         1          1        125  104857600        512          1 NO  CURRENT                5673763 06-OCT-17      2.8147E+14
         2          1        123  104857600        512          1 YES INACTIVE               5671679 06-OCT-17         5671744 06-OCT-17
         3          1        124  104857600        512          1 YES INACTIVE               5671744 06-OCT-17         5673763 06-OCT-17
         4          2         52  104857600        512          1 NO  CURRENT                5673778 06-OCT-17      2.8147E+14
         5          2         50  104857600        512          1 YES INACTIVE               5671725 06-OCT-17         5671860 06-OCT-17
         6          2         51  104857600        512          1 YES INACTIVE               5671860 06-OCT-17         5673778 06-OCT-17

另外这里的例子是ASM,默认指定了路径,如果是恢复到不同路径,可以使用set newname,如下:

run{
allocate channel t1 type disk ;
allocate channel t2 type disk ;
set newname for datafile '/oradata/bbed/system01.dbf' to '/oradata/test/system01.dbf';
set newname for datafile '/oradata/bbed/sysaux01.dbf' to '/oradata/test/sysaux01.dbf';
set newname for datafile '/oradata/bbed/undotbs01.dbf' to '/oradata/test/undotbs01.dbf';
set newname for datafile '/oradata/bbed/users01.dbf' to '/oradata/test/users01.dbf';
set newname for datafile '/oradata/bbed/example01.dbf' to '/oradata/test/example01.dbf';
restore database;                                   
switch datafile all;
release channel t1;
release channel t2;
}

9. 注册OCR并打开备库

srvctl add database -d oradb -o $ORACLE_HOME
srvctl add instance -d oradb -i oradb1 -n oradg1
srvctl add instance -d oradb -i oradb2 -n oradg2

SYS@oradb1>shutdown immediate
$ srvctl start database -d oradb -o 'read only'

10. 备库应用日志

SYS@oradb1>alter database recover managed standby database using current logfile disconnect from session;

11. 检查角色和保护等级

SYS@oradb1>select protection_mode, protection_level, database_role role, switchover_status from v$database;

PROTECTION_MODE      PROTECTION_LEVEL     ROLE             SWITCHOVER_STATUS
-------------------- -------------------- ---------------- --------------------
MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE  PRIMARY          TO STANDBY

SYS@oradb1>select protection_mode, protection_level, database_role role, switchover_status from v$database;

PROTECTION_MODE      PROTECTION_LEVEL     ROLE             SWITCHOVER_STATUS
-------------------- -------------------- ---------------- --------------------
MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE  PHYSICAL STANDBY NOT ALLOWED

12. 处理遗留问题

ASMCMD [+datadg] > cd oradb_s
ASMCMD [+datadg/oradb_s] > ls -l
Type           Redund  Striped  Time             Sys  Name
                                                 Y    CONTROLFILE/
                                                 Y    DATAFILE/
                                                 Y    ONLINELOG/
                                                 Y    TEMPFILE/
                                                 N    spfileoradb.ora => +DATADG/DB_UNKNOWN/PARAMETERFILE/SPFILE.256.956694647

生成PFILE,停日志应用

create pfile='/home/oracle/init_s.ora' from spfile;
alter database recover managed standby database cancel;

停库

srvctl stop database -d oradb

重新创建SPFILE

startup nomount pfile='/home/oracle/init_s.ora';
create spfile='+DATADG/oradb_s/spfileoradb.ora' from pfile='/home/oracle/init_s.ora';
shutdown immediate

srvctl start database -d oradb -o 'read only'

启用日志应用

alter database recover managed standby database using current logfile disconnect from session;

验证

ASMCMD [+datadg/oradb_s] > ls -l
Type           Redund  Striped  Time             Sys  Name
                                                 Y    CONTROLFILE/
                                                 Y    DATAFILE/
                                                 Y    ONLINELOG/
                                                 Y    PARAMETERFILE/
                                                 Y    TEMPFILE/
                                                 N    spfileoradb.ora => +DATADG/ORADB_S/PARAMETERFILE/spfile.256.956699423
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,456评论 5 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,370评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,337评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,583评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,596评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,572评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,936评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,595评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,850评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,601评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,685评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,371评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,951评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,934评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,167评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,636评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,411评论 2 342

推荐阅读更多精彩内容