- 简述
Standby db的一个作用是用于基于时间点的报表查询,或者分担主库的部分统计报表消耗。我们可以将一个standby db启动到read-only状态,这时就可以提供给客户端查询访问,在standby db打开的过程中,主库的日志文件还是传递过来,只不过不做日志的应用。所以standby db打开的时间越长,以后做日志应用的时间就越长,如果主库故障,则启用备库到正常状态的时间就越长,这是需要您来权衡的。
stndby db数据库打开后,如果需要从read-only状态回到standby状态,我们不需要关闭standby db,只需要执行命令'alter database recover managed standby database disconnect from session'就可以重新回到standby状态.
[@more@]2. 基本环境描述
2.1 主库基本情况
[root@primarydb ~]# more /etc/hosts
168.0.3.92 primarydb
168.0.3.93 standbydb
[oracle@primarydb ~]$ sqlplus / as sysdba
SQL> select * from v$version where rownum<2;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
---------- ----------------
READ WRITE PRIMARY
2.2备库基本情况
[oracle@standbydb ~]$ sqlplus / as sysdba
SQL> select * from v$version where rownum<2;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
---------- ----------------
MOUNTED PHYSICAL STANDBY
2.3 主库创建一个表,用于备库打开时验证数据
[oracle@primarydb ~]$ sqlplus / as sysdba
SQL>create table test02 as select * from v$parameter;
SQL>commit;
SQL>alter system switch logfile;
3. 启动standby db到read-only状态
3.1 如果standby db处于mount状态,则可以通过下面的命令启动到read-only状态
[oracle@standbydb ~]$ sqlplus / as sysdba
SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
-------[oracle@standbydb ~]$ sqlplus / as sysdba
--- ----------------
MOUNTED PHYSICAL STANDBY
SQL>alter database recover managed standby database cancel;
SQL>alter database open;
3.2 如果standby db数据库处于关闭状态,则执行下面的命令启动到read-only状态
[oracle@standbydb ~]$ sqlplus / as sysdba
SQL>startup
3.3 检查确认standby db处于打开状态,并且可以查询普通的表数据
[oracle@standbydb ~]$ sqlplus / as sysdba
SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
---------- ----------------
READ ONLY PHYSICAL STANDBY
SQL> select count(1) from test02;
COUNT(1)
----------
259
4. 切换回standby状态.
4.1 切换回standby 状态
[oracle@standbydb ~]$ sqlplus / as sysdba
SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
---------- ----------------
MOUNTED PHYSICAL STANDBY
4.2 主库切换日志,验证日志应用状态
[oracle@primarydb ~]$ sqlplus / as sysdba
SQL> alter system archive log current;
System altered.
[root@standbydb bdump]# tail -f alert_newgridctl.log
Completed: alter database recover managed standby database disconnect from session
Tue Sep 14 12:26:35 2010
RFS[1]: Archived Log: '/oradata/archivelog/newstandby_arc/1_278_724504451.dbf'
Tue Sep 14 12:26:38 2010
Media Recovery Log /oradata/archivelog/newstandby_arc/1_278_724504451.dbf
Media Recovery Waiting for thread 1 sequence 279
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/32980/viewspace-1038315/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/32980/viewspace-1038315/