码迷,mamicode.com
首页 > 数据库 > 详细

使用dataguard将单实例数据库转换为rac数据库

时间:2015-07-27 16:19:33      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:dataguard   rac   数据库   oracle rac   

我们经常将oracle rac数据库通过dataguard容灾到一个单实例数据库中,当生产库出现故障后可以将生产库切换到dg服务器上。而当生产库rac修复完成后,我们同样可以通过dg将数据回切到生产库中。

此次测试将单实例数据库通过dg转换为rac数据库,这个单实例是刚创建的,并不是由rac通过dg生成的。

在做dg之前需要安装完成grid,不需要创建数据库实例。在日志应用的时候必须只能是一个实例应用。

具体环境如下:

单实例库:

数据库版本:11.2.0.4.0

sid:suq

db_unique_name=suq

ip:192.168.56.35

hostname:11g1


rac数据库:

数据库版本:11.2.0.4.0

sid:suq1、suq2

db_unique_name=suq1

ip地址规划:

#PUBLIC
192.168.56.110  suq1 
192.168.56.112  suq2
#VIP
192.168.56.111   suq1-vip
192.168.56.113   suq2-vip
#PRIV
172.168.1.21    suq1-priv
172.168.1.23    suq2-priv
#SCAN
192.168.56.25   suq-cluster-scan

具体步骤如下:

1.配置一些rac和dg的基本参数,包括:

修改主库force logging、创建standby logfile、创建密码文件并且拷贝到rac下、添加主库和备库的服务命名:

alter database force logging;

alter database add standby logfile group 4 ('/opt/oracle/oradata/suq/stand_redo04.log') size 50m;

alter database add standby logfile group 5 ('/opt/oracle/oradata/suq/stand_redo05.log') size 50m;

alter database add standby logfile group 6 ('/opt/oracle/oradata/suq/stand_redo06.log') size 50m;

alter database add standby logfile group 7 ('/opt/oracle/oradata/suq/stand_redo07.log') size 50m;


##
primary=
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.35)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = suq)
    )
  )

standby=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.111)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = suq1)
      (UR = A)
    )
  )
  

注意:standby端即rac端的ip地址写的是suq1的vip地址,而且需要加上(UR=A)选项,否则通过sqlplus连接不到rac实例。


2.生成standby端的oracle 参数文件,这一步参数里面的内容及其重要,必须写正确,特别是rac和dg的参数,目前我的rac有三个磁盘组

[grid@suq2 ~]$ asmcmd lsdg
State    Type    Rebal  Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Voting_files  Name
MOUNTED  EXTERN  N         512   4096  1048576      3435     3329                0            3329              0             N  BACKUP/
MOUNTED  EXTERN  N         512   4096  1048576      4305     1988                0            1988              0             N  DATADG/
MOUNTED  EXTERN  N         512   4096  1048576      1458     1058                0            1058              0             Y  SYSTEMDG/

下面是我写好的一个参数文件:

suq.__db_cache_size=335544320
suq.__java_pool_size=4194304
suq.__large_pool_size=4194304
suq.__oracle_base='/u01/app'
suq.__pga_aggregate_target=335544320
suq.__sga_target=503316480
suq.__shared_io_pool_size=0
suq.__shared_pool_size=146800640
suq.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/suq'
*.audit_trail='none'
*.compatible='11.2.0.4.0'
*.control_files='+DATADG/suq/control.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='suq'
*.db_recovery_file_dest='+BACKUP'
*.db_recovery_file_dest_size=5218762752
*.diagnostic_dest='/u01/app/oracle'
*.memory_target=838860800
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
#### rac parameter 
suq1.local_listener='(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.111)(PORT=1521))'
suq2.local_listener='(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.113)(PORT=1521))'
suq1.undo_tablespace='UNDOTBS1'
suq2.undo_tablespace='UNDOTBS2'
suq1.remote_listener='suq-cluster-scan:1521'
suq2.remote_listener='suq-cluster-scan:1521'
suq1.instance_name=suq1
suq2.instance_name=suq2
suq1.instance_number=1
suq2.instance_number=2
*.cluster_database=true
*.cluster_database_instances=2
*.db_create_file_dest='+DATADG'
*.db_create_online_log_dest_1='+DATADG'
suq1.thread=1
suq2.thread=2
### dg parameter 
*.db_unique_name=suq1
*.log_archive_config='dg_config=(suq,suq1)'
*.standby_file_management='AUTO'
*.db_file_name_convert='/opt/oracle/oradata/suq','+DATADG/suq/datafile'
*.log_file_name_convert='/opt/oracle/oradata/suq','+DATADG/suq/datafile'
*.log_archive_dest_1='location=+datadg/suq/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=suq1'
*.log_archive_dest_2='service=primary lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=suq'
*.fal_server=primary
*.fal_client=standby


注意:suq1、suq2的local_listener和remote_listener必须配置正确,否则打开库之后scan ip可能失效


3.配置主库的dg参数:

alter system set log_archive_config='dg_config=(suq,suq1)' scope=both;  

alter system set log_archive_dest_1='location=/opt/arch valid_for=(all_logfiles,all_roles) db_unique_name=suq' scope=both;

alter system set log_archive_dest_2='service=standby lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=suq1' scope=both;

alter system set fal_server=suq1 scope=both;

alter system set fal_client=suq scope=both;


4.在保证所有需要的目录都已经创建完成的情况下,将备库启动到nomount,并且测试tnsnames的连通性:

SQL>startup nomount pfile='/home/oracle/initsuq1.ora'
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size		    2257840 bytes
Variable Size		  553651280 bytes
Database Buffers	  272629760 bytes
Redo Buffers		    6565888 bytes
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
[oracle@suq1 ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 26-JUL-2015 21:27:45

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                26-JUL-2015 18:58:27
Uptime                    0 days 2 hr. 29 min. 17 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/11.2.0/grid/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/suq1/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.110)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.111)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "suq1" has 1 instance(s).
  Instance "suq1", status BLOCKED, has 1 handler(s) for this service...
The command completed successfully


[oracle@11g1 ~]$  sqlplus sys/manager@standby as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Sun Jul 26 21:48:08 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> exit

[oracle@suq1 ~]$ sqlplus sys/manager@primary as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Sun Jul 26 21:50:25 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> exit

5.使用duplicate 创建standby database:

[oracle@11g1 arch]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Sun Jul 26 22:28:11 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: SUQ (DBID=1469685490)

RMAN> connect auxiliary sys/manager@standby

connected to auxiliary database: SUQ (not mounted)

RMAN> duplicate target database for standby from active database; 

Starting Duplicate Db at 26-JUL-15
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=141 instance=suq1 device type=DISK

contents of Memory Script:
{
   backup as copy reuse
   targetfile  '/opt/oracle/product/OraHome11204/dbs/orapwsuq' auxiliary format 
 '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwsuq1'   ;
}
executing Memory Script

Starting backup at 26-JUL-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=147 device type=DISK
Finished backup at 26-JUL-15

contents of Memory Script:
{
   backup as copy current controlfile for standby auxiliary format  '+DATADG/suq/control.ctl';
}
executing Memory Script

Starting backup at 26-JUL-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying standby control file
output file name=/opt/oracle/product/OraHome11204/dbs/snapcf_suq.f tag=TAG20150726T222820 RECID=3 STAMP=886112900
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 26-JUL-15

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 
 "+DATADG/suq/datafile/temp01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to 
 "+DATADG/suq/datafile/system01.dbf";
   set newname for datafile  2 to 
 "+DATADG/suq/datafile/sysaux01.dbf";
   set newname for datafile  3 to 
 "+DATADG/suq/datafile/undotbs01.dbf";
   set newname for datafile  4 to 
 "+DATADG/suq/datafile/users01.dbf";
   backup as copy reuse
   datafile  1 auxiliary format 
 "+DATADG/suq/datafile/system01.dbf"   datafile 
 2 auxiliary format 
 "+DATADG/suq/datafile/sysaux01.dbf"   datafile 
 3 auxiliary format 
 "+DATADG/suq/datafile/undotbs01.dbf"   datafile 
 4 auxiliary format 
 "+DATADG/suq/datafile/users01.dbf"   ;
   sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to +DATADG/suq/datafile/temp01.dbf in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 26-JUL-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/opt/oracle/oradata/suq/system01.dbf
output file name=+DATADG/suq/datafile/system01.dbf tag=TAG20150726T222829
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/opt/oracle/oradata/suq/sysaux01.dbf
output file name=+DATADG/suq/datafile/sysaux01.dbf tag=TAG20150726T222829
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/opt/oracle/oradata/suq/undotbs01.dbf
output file name=+DATADG/suq/datafile/undotbs01.dbf tag=TAG20150726T222829
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/opt/oracle/oradata/suq/users01.dbf
output file name=+DATADG/suq/datafile/users01.dbf tag=TAG20150726T222829
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 26-JUL-15

sql statement: alter system archive log current

contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=3 STAMP=886113015 file name=+DATADG/suq/datafile/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=4 STAMP=886113015 file name=+DATADG/suq/datafile/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=886113015 file name=+DATADG/suq/datafile/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=6 STAMP=886113015 file name=+DATADG/suq/datafile/users01.dbf
Finished Duplicate Db at 26-JUL-15

RMAN> exit


Recovery Manager complete.

6.standby开启实时应用:

SQL> alter database recover managed standby database disconnect from session;

SQL> alter database recover managed standby database cancel;

SQL> alter database open read only;

Database altered.

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

Database altered.

注意:我在做到这一步的时候一开始发现主库怎么也不向备库发送归档文件,也没有任何报错信息,搞了很长时间,后来将log_archive_dest_state_2重新设置为enable后就正常了。


7.switch over,将备库转换为主库,分别在主库我备库进行角色转换:

主库:

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS
--------------------
SESSIONS ACTIVE

注:当SWITCHOVER_STATUS的值为TO STANDBY or SESSIONS ACTIVE的时候表示主库可以支持SWITCHOVER.

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;

Database altered.



备库:

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS
--------------------
SESSIONS ACTIVE

注:只有SWITCHOVER_STATUS的值为TO PRIMARY or SESSIONS ACTIVE的状态时,表示备库当前支持switch over操作。

SQL>  ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY with session shutdown;

Database altered.

SQL> select status from v$instance;

STATUS
------------
MOUNTED

SQL> alter database open;

Database altered.


8.到这一步,rac的一个节点已经可以正常打开数据库了,但是节点2需要的redo,undo表空间都还没有,需要手工创建:

SQL> alter database add logfile thread 2 group 8 ('+DATADG/suq/datafile/redo08.log') size 50m;

Database altered.

SQL> alter database add logfile thread 2 group 9 ('+DATADG/suq/datafile/redo09.log') size 50m;

Database altered.

SQL> alter database add logfile thread 2 group 10 ('+DATADG/suq/datafile/redo10.log') size 50m;

Database altered.

SQL> create undo tablespace undotbs2 datafile '+DATADG/suq/datafile/undotbs02.dbf' size 20m;

Tablespace created.

SQL> alter database enable public thread 2; 

Database altered.


SQL> @?/rdbms/admin/catclust.sql

Package created.


Package body created.


PL/SQL procedure successfully completed.


View created.


Synonym created.


Grant succeeded.


View created.


Grant succeeded.


Synonym created.


View created.


Grant succeeded.


Synonym created.


View created.


Grant succeeded.


Synonym created.


View created.


Grant succeeded.


Synonym created.


View created.


Grant succeeded.


Synonym created.


View created.


Grant succeeded.


Synonym created.


View created.


Grant succeeded.


Synonym created.


View created.


Grant succeeded.


View created.


Grant succeeded.


Synonym created.


Synonym created.


Synonym created.


Synonym created.


Synonym created.


Synonym created.


Synonym created.


Synonym created.


Synonym created.


Synonym created.


Synonym created.


Synonym created.


View created.


Grant succeeded.


Synonym created.


View created.


Grant succeeded.


Synonym created.


PL/SQL procedure successfully completed.


节点2打开数据库,测试数据库是否正常:

[oracle@suq2 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Jul 27 09:54:00 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size		    2257840 bytes
Variable Size		  553651280 bytes
Database Buffers	  272629760 bytes
Redo Buffers		    6565888 bytes
Database mounted.
Database opened.
SQL> 

SQL> select * from v$active_instances;

INST_NUMBER INST_NAME
----------- --------------------------------------------------
	  1 suq1:suq1


	  2 suq2:suq2
	  
SQL> select * from v$Log;

    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE	  MEMBERS ARC STATUS	       FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------
	 1	    1	      35   52428800	   512		1 NO  CURRENT		      288331 27-JUL-15	 2.8147E+14
	 2	    1	      33   52428800	   512		1 YES INACTIVE		      281944 27-JUL-15	     282047 27-JUL-15
	 3	    1	      34   52428800	   512		1 YES ACTIVE		      282047 27-JUL-15	     288331 27-JUL-15
	 8	    2	       4   52428800	   512		1 NO  CURRENT		      288227 27-JUL-15	 2.8147E+14
	 9	    2	       2   52428800	   512		1 YES INACTIVE		      286810 27-JUL-15	     286815 27-JUL-15
	10	    2	       3   52428800	   512		1 YES ACTIVE		      286815 27-JUL-15	     288227 27-JUL-15

8.此时的数据库是可以正常打开使用了,一般还需将参数文件写到asm中,而且此时的数据库都是本地管理,并没有注册到grid中,还需要手工注册:

[grid@suq1 admin]$ srvctl config database
[grid@suq1 admin]$ 
[grid@suq1 admin]$ crsctl stat res -t
--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.BACKUP.dg
               ONLINE  ONLINE       suq1                                         
               ONLINE  ONLINE       suq2                                         
ora.DATADG.dg
               ONLINE  ONLINE       suq1                                         
               ONLINE  ONLINE       suq2                                         
ora.LISTENER.lsnr
               ONLINE  ONLINE       suq1                                         
               ONLINE  ONLINE       suq2                                         
ora.SYSTEMDG.dg
               ONLINE  ONLINE       suq1                                         
               ONLINE  ONLINE       suq2                                         
ora.asm
               ONLINE  ONLINE       suq1                     Started             
               ONLINE  ONLINE       suq2                     Started             
ora.gsd
               OFFLINE OFFLINE      suq1                                         
               OFFLINE OFFLINE      suq2                                         
ora.net1.network
               ONLINE  ONLINE       suq1                                         
               ONLINE  ONLINE       suq2                                         
ora.ons
               ONLINE  ONLINE       suq1                                         
               ONLINE  ONLINE       suq2                                         
ora.registry.acfs
               ONLINE  ONLINE       suq1                                         
               ONLINE  ONLINE       suq2                                         
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       suq2                                         
ora.cvu
      1        ONLINE  ONLINE       suq2                                         
ora.oc4j
      1        ONLINE  ONLINE       suq2                                         
ora.scan1.vip
      1        ONLINE  ONLINE       suq2                                         
ora.suq1.vip
      1        ONLINE  ONLINE       suq1                                         
ora.suq2.vip
      1        ONLINE  ONLINE       suq2  
      
[oracle@suq1 ~]$ srvctl add database -d suq -o /u01/app/oracle/product/11.2.0/db_1
[oracle@suq1 ~]$ srvctl config database
suq
[oracle@suq1 ~]$ srvctl add instance -d suq -n suq1 -i suq1
[oracle@suq1 ~]$ srvctl add instance -d suq -n suq2 -i suq2

SQL> create spfile='+datadg' from pfile;

File created.
[root@suq1 cssd]# srvctl modify database -d suq -p '+datadg/suq1/parameterfile/spfile.325.886161615' 


[oracle@suq1 dbs]$ srvctl config database -d suq -a
Database unique name: suq
Database name: 
Oracle home: /u01/app/oracle/product/11.2.0/db_1
Oracle user: oracle
Spfile: +datadg/suq1/parameterfile/spfile.325.886161615
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: suq
Database instances: suq1,suq2
Disk Groups: 
Mount point paths: 
Services: 
Type: RAC
Database is enabled
Database is administrator managed

查看一下监听,有可能还需要修改services_name参数:

SQL> alter system set service_names=suq scope=both;

到此,单实例已经转换完成了rac数据库。可以重启一下机器,看看数据库能否自动启动,资源是否正常。

good luck!

版权声明:本文为博主原创文章,未经博主允许不得转载。

使用dataguard将单实例数据库转换为rac数据库

标签:dataguard   rac   数据库   oracle rac   

原文地址:http://blog.csdn.net/su377486/article/details/47084469

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!