分类: Oracle
2008-04-11 20:44:50
10.现在可做一个测试,在standby主机上进行数据修改(standby主机现在做primary)
SQL> create table t as select * from dba_users;
Table created.
SQL> alter system switch logfile;
System altered.
在从库上(primary主机上)以read only打开数据库,执行查询
SQL> select username from t;
select username from t
*
ERROR at line 1:
ORA-01219: database not open: queries allowed on fixed tables/views only
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
Database altered.
SQL> ALTER DATABASE OPEN READ ONLY;
Database altered.
SQL> select username from t;
USERNAME
------------------------------
SYS
SYSTEM
DBSNMP
OUTLN
WMSYS
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered.
常见问题
至此,主副的配置已基本完成,可做以下实验来验证配置的准确性。
1. 在主库上新建一个表,看修改时候能马上传到副库上;
2. 在主库上新建一个表空间,新增加一个datafile,看修改时候能马上传到副库上(应该是只要在副库上执行恢复模式,就能在副库上看到新建的表空间;
3. 在主库上新建一个临时表空间,rename datafile 均不能应用到副库上;
4. 应当实时察看standby库的alert文件,就能清晰明了地知道主副更新的情况;
5. 关于启动关闭顺序。
启动的时候,先从库的listener,再启动从库,再启动主库的listener,再主库。
关闭的时候,先关闭主库,再启动从库。
6. 8i副数据库切换为主的话,将无法再切为副。主数据库也是! 也就是说,只能完成一次切换,这叫failover!9i可实现主副数据库任意切换,这叫switchover
7. 察看主机当前的运行状态:
SQL> select name,open_mode,PROTECTION_MODE,DATABASE_ROLE from v$database;
NAME OPEN_MODE PROTECTION_MODE DATABASE_ROLE
--------- ---------- -------------------- ----------------
PRIMARY MOUNTED MAXIMUM PERFORMANCE PHYSICAL STANDBY
8.查看主数据库日志是否全部传送到副数据库,可查看v$archive_gap,更简单的方法是查看各自主机的日志归档目录的日志序号即可。
11. 常用的一些方法:
可在副数据库上运行一些脚本,确保主数据库上的更新能及时在副数据库上得到实现。可将以下脚本放在crontab表中。
oracle@standby $cat refresh (刷新脚本)
ORACLE_SID=oracle
ORACLE_HOME=/home/oracle/product/9.2.0
export ORACLE_SID ORACLE_HOME
DATE=`date '+%Y%m%d'`
touch /home/oracle/refresh_$DATE.log
$ORACLE_HOME/bin/sqlplus /nolog << EOF
spool /home/oracle/refresh_$DATE.log
connect sys/abc123 as sysdba
shutdown immediate;
quit
EOF
$ORACLE_HOME/bin/sqlplus /nolog << EOF2
spool /home/oracle/refresh_2_$DATE.log
connect sys/abc123 as sysdba
startup nomount pfile=$ORACLE_HOME/dbs/initoracle.ora;
alter database mount standby database;
alter database set standby database to maximize performance;
alter database recover managed standby database disconnect from session;
spool off
EOF2
oracle@standby $cat readonly (更新脚本)
#!/bin/sh
ORACLE_SID=oracle
ORACLE_HOME=/home/oracle/product/9.2.0
export ORACLE_SID ORACLE_HOME
$ORACLE_HOME/bin/sqlplus /nolog << EOF
spool /home/oracle/refresh-read.log
connect sys/abc123 as sysdba
rem change from recover mode to read-only
alter database recover managed standby database cancel;
alter database open read only ;
spool off
EOF
switchover过程。
12.把数据库切换回到主节点
先将standby此时的initoracle.ora恢复为以前是standby时的参数。
在主节点(standby主机上)
SQL> alter database commit to switchover to physical standby;
Database altered.
SQL> shutdown immediate
ORA-01507: database not mounted
statORACLE instance shut down.
SQL> startup nomount pfile=/home/oracle/product/9.2.0/dbs/initoracle.ora;
;
ORACLE instance started.
Total System Global Area 135337420 bytes
Fixed Size 452044 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
SQL> alter database mount standby database;
Database altered.
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered.
在备用节点(在primary主机上)
先将primary此时的initoracle.ora恢复为以前是primary时的参数。
SQL> alter database commit to switchover to primary;
Database altered.
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup pfile=/home/oracle/product/9.2.0/dbs/initoracle.ora;
ORACLE instance started.
Total System Global Area 135337420 bytes
Fixed Size 452044 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened. |