ITPub博客

首页 > Linux操作系统 > Linux操作系统 > RAC + DG

RAC + DG

原创 Linux操作系统 作者:wshxgxiaoli 时间:2012-07-05 13:44:29 0 删除 编辑
1.环境准备:
主机:RAC
备机:ORACLE 软件安装

2. 密码文件准备:
orapwd file=$ORACLE_HOME/dbs/orapwfirstrac password=admin
cd $ORACLE_HOME/dbs
scp orapwfirstrac oracle@10.10.10.33:/home/oracle/oracle/product/10.2.0/db_1/dbs

3. 侦听准备
主库TNS文件配置: 两个节点一样
FIRSTRAC =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
    (LOAD_BALANCE = yes)
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = firstrac)
    )
  )

FIRSTRAC2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = firstrac)
      (INSTANCE_NAME = firstrac2)
    )
  )

FIRSTRAC1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = firstrac)
      (INSTANCE_NAME = firstrac1)
    )
  )

CRM =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
    (LOAD_BALANCE = yes)
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = CRM)
      (FAILOVER_MODE =
        (TYPE = SELECT)
        (METHOD = BASIC)
        (RETRIES = 180)
        (DELAY = 5)
      )
    )
  )

LISTENERS_FIRSTRAC =
  (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
  )

EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )

standby =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.133 )(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SID = firstrac)
    )
  )
备库TNS文件准备:
FIRSTRAC2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = firstrac)
      (INSTANCE_NAME = firstrac2)
    )
  )

FIRSTRAC1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = firstrac)
      (INSTANCE_NAME = firstrac1)
    )
  )

standby =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.1.333 )(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SID = firstrac)
    )
  )

4.侦听验证:
分别在主与备三台机器上执行连接命令
sqlplus sys/admin@standby as sysdba
sqlplus sys/admin@FIRSTRAC1 as sysdba
sqlplus sys/admin@FIRSTRAC2 as sysdba

5.参数文件准备
在主库任意一节点执行:create pfile='/home/oracle/initfirstrac.ora' from spfile;
COPY 为两份,一份为主库,一份为备库的。
cp initfirstrac.ora initfirstrac.ora.bak
修改主库参和文件:
只需在原配置文件下添加以下参数:
*.log_archive_config='dg_config=(FIRSTRAC,standby)'
*.log_archive_dest_3='service=standby VALID_FOR=(ALL_LOGFILES,ALL_ROLES) db_unique_name=standby'
*.db_file_name_convert='/home/oracle/oradata/firstrac','+DG1/fistrac/datafile','/home/oracle/oradata/firstrac','+DG1/firstrac/tempfile'
*.log_file_name_convert='/home/oracle/oradata/firstrac', '+DG1/firstrac/onlinelog'
*.standby_file_management=auto
*.fal_server='standby'
orcl1.fal_client='FIRSTRAC1'
orcl2.fal_client='FIRSTRAC2'
除了添加以上还要修改以下两行:
firstrac2.log_archive_dest_2='service=FIRSTRAC1 db_unique_name=firstrac'
firstrac1.log_archive_dest_2='service=FIRSTRAC2 db_unique_name=firstrac'
修改备库参数文件:
*.audit_file_dest='/home/oracle/admin/firstrac/adump'
*.background_dump_dest='/home/oracle/admin/firstrac/bdump'
*.cluster_database_instances=2
*.cluster_database=TRUE
*.compatible='10.2.0.1.0'
*.control_files='/home/oracle/oradata/firstrac/control01.ctl','/home/oracle/oradata/firstrac/control02.ctl','/home/oracle/oradata/firstrac/control03.ctl'
*.core_dump_dest='/home/oracle/admin/firstrac/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='firstrac'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=firstracXDB)'
*.job_queue_processes=10
*.log_archive_dest_1='location=/home/oracle/archivelog1'
*.log_archive_dest_state_2='ENABLE'
*.open_cursors=300
*.pga_aggregate_target=59768832
*.processes=150
*.remote_login_passwordfile='exclusive'
*.sga_target=179306496
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS2'
*.user_dump_dest='/home/oracle/admin/firstrac/udump'
*.db_unique_name=standby
*.log_archive_config='dg_config=(FIRSTRAC,standby)'
*.log_archive_dest_2='service=FIRSTRAC1 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) db_unique_name=firstrac1'
*.db_file_name_convert='+DG1/firstrac/datafile','/home/oracle/oradata/firstrac','+DG1/FIRSTRAC/tempfile','/home/oracle/oradata/firstrac'
*.log_file_name_convert='+DG1/FIRSTRAC/onlinelog','/home/oracle/oradata/firstrac','+RECOVERYDEST/firstrac/onlinelog','/home/oracle/oradata/firstrac'
*.standby_file_management=auto
*.standby_archive_dest='/home/oracle/archivelog1'
*.fal_server='FIRSTRAC1','FIRSTRAC2'
*.fal_client='standby'
将文件传到备库。
scp initfirstrac.ora oracle@192.168.1.33:/home/oracle/rman
在备库上创建所需的目录:
mkdir -P oradata/firstrac
mkdir flash_recovery_area
mkdir -P admin/firstrac/adump
mkdir -P admin/firstrac/bdump
mkdir -P admin/firstrac/cdump
mkdir -P admin/firstrac/udump
连接备库,用PFILE 启动到NOMOUNT 状态。
startup nomount pfile='/home/oracle/rman/initfirstrac.ora';

6.备份主数据库
 run{
allocate channel a1 type disk;
allocate channel a2 type disk;
sql'alter system archive log current';
backup format='/home/oracle/rman/full_%d_%T_%s' skip inaccessible filesperset 5 database;
backup format='/home/oracle/rman/arch_%d_%T_%s' skip inaccessible filesperset 5 archivelog all delete input;
backup format='/home/oracle/rman/ctl_%U' current controlfile for standby;
release channel a2;
 release channel a1;
}
将备份传到备库:
scp * oracle@192.168.1.33:/home/oracle/rman

7.在主库创建STANDBY 控制文件
alter database create standby controlfile as '/home/oracle/control01.ctl';
移动至备库相应位置。

8.在主库的第一个节点恢复备库数据库
rman target / auxiliary sys/admin@standby
duplicate target database for standby;

9.在备库创建SPFILE 并重新启动到MOUNT 状态。
create spfile from pfile='/home/oracle/initfirstrac.ora';
shutdown abort;
startup nomount;
alter database mount standby database;
recover managed standby database disconnect from session;

10.添加standby redo log 日志
RAC 每个Redo Thread 都需要创建对应的Standby Redo Log。 创建原则和单实例一样,包括日志文件大小相等,日志组数量要多1组。
export ORACLE_SID=firstrac2
sqlplus / as sysdba
Alter database add standby logfile thread 1 group 5 ('/home/oracle/oradata/firstrac/redo_st_05.log') size 50m;
Alter database add standby logfile thread 1 group 6 ('/home/oracle/oradata/firstrac/redo_st_06.log') size 50m;
Alter database add standby logfile thread 1 group 7 ('/home/oracle/oradata/firstrac/redo_st_07.log') size 50m;
Alter database add standby logfile thread 2 group 8 ('/home/oracle/oradata/firstrac/redo_st_08.log') size 50m;
Alter database add standby logfile thread 2 group 9 ('/home/oracle/oradata/firstrac/redo_st_09.log') size 50m;
Alter database add standby logfile thread 2 group 10 ('/home/oracle/oradata/firstrac/redo_st_10.log') size 50m;

11.停止RAC 实例, 用刚刚生成的PFILE 去启动。
srvctl stop database -d firstrac
export ORACLE_SID=firstrac1
sqlplus / as sysdba
create spfile from pfile='/home/oracle/initfirstrac.ora';
startup;

至此为止!  RAC+单实例的DG 就告一段落了。

12 切换为RAIL TIME
首先停掉恢复进程: alter database recover managed standby database cancel;
启动恢复进程:alter database recover managed standby database using current logfile disconnect from session;
报错:ERROR at line 1:
ORA-38500: USING CURRENT LOGFILE option not available without stand
解决办法, 添加LOG,然后再重新启动RAIL TIME
Alter database add standby logfile  group 5 ('/home/oracle/oradata/firstrac/redo_st_05.log') size 50m;
Alter database add standby logfile  group 6 ('/home/oracle/oradata/firstrac/redo_st_06.log') size 50m;
Alter database add standby logfile  group 7 ('/home/oracle/oradata/firstrac/redo_st_07.log') size 50m;
再次启动:alter database recover managed standby database using current logfile disconnect from session;

Database altered.


RAC 环境下,切换Primary 和 Standby 时,只能有一个实例是活动的, 其他实例必须关闭。
这里我们关闭rac2节点。
SQL> select instance_name from v$instance;
INSTANCE_NAME

----------------

firstrac2

 

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL>

 

在RAC1 节点将主库切换到备库:

SQL> select instance_name from v$instance;

INSTANCE_NAME

----------------

FIRSTRAC1

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS

--------------------

SESSIONS ACTIVE

SQL> alter database commit to switchover to physical standby with session shutdown;

Database altered.


SQL> shutdown immediate;

将备库切换成主库:
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS

--------------------

TO PRIMARY
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY with session shutdown;
SQL> shutdown immediate;
在rac1(原来的主库)节点上创建standby redo log file:
SQL> select thread#,group#,bytes/1024/1024 from v$log;
SQL> alter database add standby logfile thread 1 group 5 size 50m;
SQL> alter database add standby logfile thread 1 group 6 size 50m;
SQL> alter database add standby logfile thread 1 group 7 size 50m;
SQL> alter database add standby logfile thread 2 group 8 size 50m;
SQL> alter database add standby logfile thread 2 group 9 size 50m;
SQL> alter database add standby logfile thread 2 group 10 size 50m;

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22740983/viewspace-734626/,如需转载,请注明出处,否则将追究法律责任。

上一篇: RAC 开关顺序
下一篇: 数据库闪回
请登录后发表评论 登录
全部评论

注册时间:2012-03-30

  • 博文量
    33
  • 访问量
    51662