WINDOWS下的程序员出身,偶尔也写一些linux平台下小程序, 后转行数据库行业,专注于ORACLE和DB2的运维和优化。 同时也是ios移动开发者。欢迎志同道合的朋友一起研究技术。 数据库技术交流群:58308065,23618606
全部博文(599)
分类: Oracle
2009-12-25 15:53:47
这篇文章描述为RAC环境创建STANDBY数据库。
由于篇幅限制,加上碰到了很多的bug,只能将文章拆分成多篇。
这章介绍STANDBY数据库创建的后续操作,并检查STANDBY运行机制:
RAC数据库建立STANDBY(一):http://yangtingkun.itpub.net/post/468/484988
首先登陆实例,检查数据库状态:
bash-3.00$ sqlplus "/ as sysdba"
SQL*Plus: Release 11.1.0.6.0 - Production on Wed Sep 10 13:56:13 2008
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
SQL> select instance_name, status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
rac11g1 MOUNTED
SQL> select name,
2 open_mode,
3 database_role,
4 guard_status,
5 db_unique_name,
6 primary_db_unique_name
7 from v$database;
NAME OPEN_MODE DATABASE_ROLE GUARD_S DB_UNIQUE_NAME PRIMARY_DB_UNIQUE_NAME
--------- ---------- ---------------- ------- --------------- -----------------------
RAC11G MOUNTED PHYSICAL STANDBY NONE rac11g_s
下面可以将数据库至于应用归档的状态:
SQL> alter database recover managed standby database
2 disconnect from session;
Database altered.
下面检查归档的是否可以正常发送到STANDBY数据库:
SQL> select sequence#, thread# from v$archived_log order by first_time;
no rows selected
SQL> conn sys/test@rac11g as sysdba
Connected.
SQL> alter system archive log current;
System altered.
SQL> conn / as sysdba
Connected.
SQL> select sequence#, thread# from v$archived_log order by first_time;
SEQUENCE# THREAD#
---------- ----------
533 1
198 2
SQL> select sequence#, thread#, applied from v$archived_log order by first_time;
SEQUENCE# THREAD# APP
---------- ---------- ---
532 1 YES
533 1 NO
198 2 YES
可以看到,两个数据库实例的归档日志文件已经发送到本地节点,而且LGWR进程已经将正在写的当前日志文件533写到了本地。
数据库的STANTDBY机制已经正常运行,下面看看能否将STANDBY数据库的两个实例以只读方式打开:
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database open;
Database altered.
SQL> select instance_name, status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
rac11g1 OPEN
SQL> select name,
2 open_mode,
3 database_role,
4 guard_status,
5 db_unique_name,
6 primary_db_unique_name
7 from v$database;
NAME OPEN_MODE DATABASE_ROLE GUARD_S DB_UNIQUE_NAME PRIMARY_DB_UNIQUE_NAME
--------- ---------- ---------------- ------- --------------- -----------------------
RAC11G READ ONLY PHYSICAL STANDBY NONE rac11g_s rac11g
由于SPFILE目前在本地,需要创建一个ASM上面的参数文件:
SQL> create pfile='/export/home/oracle/initrac11g.ora' from spfile;
File created.
SQL> create spfile='+DATA/RAC11G/spfilerac11g.ora'
2 from pfile='/export/home/oracle/initrac11g.ora';
File created.
下面分别编辑两个节点的$ORACLE_HOME/dbs目录下的初始化参数,使得spfile指向这个刚刚创建的spfile文件:
spfile=+DATA/RAC11G/spfilerac11g.ora
下面登陆节点二,尝试打开第二个实例:
$ sqlplus "/ as sysdba"
SQL*Plus: Release 11.1.0.6.0 - Production on 星期三 9月 10 14:53:09 2008
Copyright (c) 1982, 2007, Oracle. All rights reserved.
已连接到空闲例程。
SQL> startup
ORACLE 例程已经启动。
Total System Global Area 1.7108E+10 bytes
Fixed Size 2101632 bytes
Variable Size 3478638208 bytes
Database Buffers 1.3623E+10 bytes
Redo Buffers 4431872 bytes数据库装载完毕。数据库已经打开。
SQL> set pages 100 lines 120
SQL> select instance_name, status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
rac11g2 OPEN
SQL> select instance_name, status from gv$instance;
INSTANCE_NAME STATUS
---------------- ------------
rac11g2 OPEN
rac11g1 OPEN
SQL> select name,
2 open_mode,
3 database_role,
4 guard_status,
5 db_unique_name,
6 primary_db_unique_name
7 from v$database;
NAME OPEN_MODE DATABASE_ROLE GUARD_S DB_UNIQUE_NAME PRIMARY_DB_UNIQUE_NAME
--------- ---------- ---------------- ------- --------------- ----------------------
RAC11G READ ONLY PHYSICAL STANDBY NONE rac11g_s rac11g
从10g以后,不需要指定MOUNT STANDBY数据库,也不需要指定OPEN READ ONLY,Oracle自动会装载STANDBY数据库,并将实例以READ ONLY方式进行打开。
下面设置一下TEMP表空间:
SQL> alter database tempfile '+DATA/RAC11G/rac11g_temp_1_4g' drop;
Database altered.
SQL> alter tablespace temp add tempfile '+DATA/RAC11G/rac11g_temp_1_4g' size 4096m;
Tablespace altered.
至此RAC环境的STANDBY已经成功建立。从下一篇开始,介绍在STANDBY数据库创建过程中碰到的各种问题和解决方法。