根据视频演示,请自己手动完成视频中的实验内容并把关键步骤截图
一 主库LEO1配置
LEO1
1.启动归档模式并打开force logging
[oracle@odd ~]$ export ORACLE_SID=LEO1
[oracle@odd ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Mar 1 17:29:56 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.
Total System Global Area 419430400 bytes
Fixed Size 1219784 bytes
Variable Size 167772984 bytes
Database Buffers 247463936 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/oracle/arcdata
Oldest online log sequence 13
Next log sequence to archive 15
Current log sequence 15
SQL> alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FOR
---
YES
SQL> alter database open;
Database altered.
SQL> select member from v$logfile where rownum=1;
MEMBER
--------------------------------------------------------------------------------
/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/redo01.log
SQL> !ls /home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/redo*
/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/redo01.log /home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/redo03.log
/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/redo02.log
SQL> select group# from v$log;
GROUP#
----------
1
2
3
2.添加standby logfile 用于接收来自主库的redo日志
SQL> alter database add standby logfile group 4 ('/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/standbylog4a.log','/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/standbylog4b.log') size 100m;
Database altered.
SQL> alter database add standby logfile group 5 ('/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/standbylog5a.log','/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/standbylog5b.log') size 100m;
Database altered.
SQL> alter database add standby logfile group 6 ('/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/standbylog6a.log','/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/standbylog6b.log') size 100m;
Database altered.
SQL> alter database add standby logfile group 7 ('/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/standbylog7a.log','/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/standbylog7b.log') size 100m;
Database altered.
SQL> select group#,status from v$standby_log;
GROUP# STATUS
---------- ----------
4 UNASSIGNED
5 UNASSIGNED
6 UNASSIGNED
7 UNASSIGNED
SQL>
3.配置网络
在tnsnames.ora文件中添加LEO3连接串
[oracle@odd ~]$ vim /home/oracle/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
[oracle@odd ~]$ tail -n 8 /home/oracle/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
LEO3=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=even)(PORT=1521))
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=LEO3)
)
)
[oracle@odd ~]$
[oracle@odd ~]$ mkdir -p /home/oracle/arch/LEO1
[oracle@odd ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Mar 1 18:10:17 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> create pfile from spfile;
File created.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
4.修改主库LEO1参数文件
[oracle@odd ~]$ vim /home/oracle/oracle/product/10.2.0/db_1/dbs/initLEO1.ora
[oracle@odd ~]$ tail -n 18 /home/oracle/oracle/product/10.2.0/db_1/dbs/initLEO1.ora
##parameter for Primary Database
db_name='LEO1'
db_unique_name=LEO1
log_archive_format=%t_%s_%r.arc
log_archive_config='DG_CONFIG=(LEO1,LEO3)'
log_archive_dest_1='location=/home/oracle/arch/LEO1 valid_for=(all_logfiles,all_roles) db_unique_name=LEO1'
log_archive_dest_2='service=LEO3 lgwr sync valid_for=(online_logfiles,primary_role) db_unique_name=LEO3'
log_archive_dest_state_1=enable
log_archive_dest_state_2=enable
remote_login_passwordfile=exclusive
##parameter for Standby Database
fal_server=LEO3
fal_client=LEO1
standby_file_management=auto
db_file_name_convert='LEO3','LEO1'
log_file_name_convert='LEO3','LEO1'
[oracle@odd ~]$
[oracle@odd ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Mar 1 18:18:28 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> show parameter listener
NAME TYPE
------------------------------------ --------------------------------
VALUE
------------------------------
local_listener string
LISTENER_LEO1
remote_listener string
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> create spfile from pfile;
File created.
SQL>
二 备库LEO3配置
1.创建密码文件
注意密码文件需要保持与主库一致,我们采用复制主库密码文件到备库的方式,如果用重建的方式可能引起两边不一致报错
[oracle@odd ~]$ scp /home/oracle/oracle/product/10.2.0/db_1/dbs/orapwLEO1 even:/home/oracle/oracle/product/10.2.0/db_2/dbs/orapwLEO3
oracle@even's password:
orapwLEO1 100% 1536 1.5KB/s 00:00
[oracle@odd ~]$
2.创建转储目录和归档目录
[oracle@even ~]$ mkdir -p /home/oracle/oracle/admin/LEO3/{a,b,c,u}dump
[oracle@even ~]$ mkdir -p /home/oracle/arch/LEO3
[oracle@even ~]$
3.冷备主库
[oracle@odd ~]$ cd /home/oracle/oracle/product/10.2.0/db_1/oradata/
[oracle@odd oradata]$ ls
LEO1
[oracle@odd oradata]$ tar -czvf LEO1.tar LEO1
LEO1/
LEO1/control01.ctl
LEO1/redo01.log
LEO1/standbylog6b.log
LEO1/sysaux01.dbf
LEO1/standbylog6a.log
LEO1/control02.ctl
LEO1/part2_01.dbf
LEO1/standbylog7a.log
LEO1/standbylog5a.log
LEO1/redo03.log
LEO1/undotbs01.dbf
LEO1/leo101.dbf
LEO1/part3_01.dbf
LEO1/move_tbs.dbf
LEO1/standbylog5b.log
LEO1/users01.dbf
LEO1/standbylog4a.log
LEO1/redo02.log
LEO1/standbylog7b.log
LEO1/system01.dbf
LEO1/assm01.dbf
LEO1/standbylog4b.log
LEO1/part4_01.dbf
LEO1/part1_01.dbf
LEO1/tsport01.dbf
LEO1/temp01.dbf
LEO1/control03.ctl
LEO1/mssm01.dbf
[oracle@odd oradata]$ scp LEO1.tar even:/home/oracle/oracle/oradata/
oracle@even's password:
LEO1.tar 100% 105MB 52.5MB/s 00:02
[oracle@odd oradata]$ scp /home/oracle/oracle/product/10.2.0/db_1/dbs/initLEO1.ora even:/home/oracle/oracle/product/10.2.0/db_2/dbs/initLEO3.ora
oracle@even's password:
initLEO1.ora 100% 1995 2.0KB/s 00:00
[oracle@odd oradata]$
[oracle@even ~]$ cd /home/oracle/oracle/oradata/
[oracle@even oradata]$ ls
LEO1.tar LEO2 TEST
[oracle@even oradata]$ mkdir LEO3
[oracle@even oradata]$ tar -zxvf LEO1.tar -C LEO3
LEO1/
LEO1/control01.ctl
LEO1/redo01.log
LEO1/standbylog6b.log
LEO1/sysaux01.dbf
LEO1/standbylog6a.log
LEO1/control02.ctl
LEO1/part2_01.dbf
LEO1/standbylog7a.log
LEO1/standbylog5a.log
LEO1/redo03.log
LEO1/undotbs01.dbf
LEO1/leo101.dbf
LEO1/part3_01.dbf
LEO1/move_tbs.dbf
LEO1/standbylog5b.log
LEO1/users01.dbf
LEO1/standbylog4a.log
LEO1/redo02.log
LEO1/standbylog7b.log
LEO1/system01.dbf
LEO1/assm01.dbf
LEO1/standbylog4b.log
LEO1/part4_01.dbf
LEO1/part1_01.dbf
LEO1/tsport01.dbf
LEO1/temp01.dbf
LEO1/control03.ctl
LEO1/mssm01.dbf
[oracle@even oradata]$ ls LEO3/
LEO1
[oracle@even oradata]$ mv LEO3/LEO1/* LEO3/
[oracle@even oradata]$ ls LEO3
assm01.dbf LEO1 part1_01.dbf redo01.log standbylog4b.log standbylog6b.log system01.dbf users01.dbf
control01.ctl leo101.dbf part2_01.dbf redo02.log standbylog5a.log standbylog7a.log temp01.dbf
control02.ctl move_tbs.dbf part3_01.dbf redo03.log standbylog5b.log standbylog7b.log tsport01.dbf
control03.ctl mssm01.dbf part4_01.dbf standbylog4a.log standbylog6a.log sysaux01.dbf undotbs01.dbf
[oracle@even oradata]$ rm LEO3/LEO1/ -r
[oracle@even oradata]$ rm LEO3/control0*.ctl -f
[oracle@even oradata]$ ls LEO3
assm01.dbf part1_01.dbf redo01.log standbylog4b.log standbylog6b.log system01.dbf users01.dbf
leo101.dbf part2_01.dbf redo02.log standbylog5a.log standbylog7a.log temp01.dbf
move_tbs.dbf part3_01.dbf redo03.log standbylog5b.log standbylog7b.log tsport01.dbf
mssm01.dbf part4_01.dbf standbylog4a.log standbylog6a.log sysaux01.dbf undotbs01.dbf
[oracle@even oradata]$
4.生成备库的控制文件@LEO1
[oracle@odd oradata]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Mar 1 20:14:37 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.
Total System Global Area 419430400 bytes
Fixed Size 1219784 bytes
Variable Size 167772984 bytes
Database Buffers 247463936 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> alter database create standby controlfile as '/home/oracle/control01.ctl';
Database altered.
SQL> !
[oracle@odd oradata]$ scp /home/oracle/control01.ctl even:/home/oracle/oracle/oradata/
oracle@even's password:
control01.ctl 100% 6896KB 6.7MB/s 00:00
[oracle@odd oradata]$
[oracle@even oradata]$ pwd
/home/oracle/oracle/oradata
[oracle@even oradata]$ ls
control01.ctl LEO1.tar LEO2 LEO3 TEST
[oracle@even oradata]$ cp control01.ctl LEO3/control01.ctl
[oracle@even oradata]$ cp control01.ctl LEO3/control02.ctl
[oracle@even oradata]$ cp control01.ctl LEO3/control03.ctl
[oracle@even oradata]$
5.准备备库的参数文件initLEO3.ora,这里仅列出需要修改的部分
[oracle@even oradata]$ vim /home/oracle/oracle/product/10.2.0/db_2/dbs/initLEO3.ora
[oracle@even ~]$ tail -n22 /home/oracle/oracle/product/10.2.0/db_2/dbs/initLEO3.ora
*.control_files='/home/oracle/oracle/oradata/LEO3/control01.ctl','/home/oracle/oracle/oradata/LEO3/control02.ctl','/home/oracle/oracle/oradata/LEO3/control03.ctl'
#as primary
DB_NAME='LEO1'
DB_UNIQUE_NAME=LEO3
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_CONFIG='DG_CONFIG=(LEO1,LEO3)'
LOG_ARCHIVE_DEST_1='LOCATION=/home/oracle/arch/LEO3 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=LEO3'
LOG_ARCHIVE_DEST_2='SERVICE=LEO1 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=LEO1'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
#as standby
FAL_SERVER=LEO1
FAL_CLIENT=LEO3
DB_FILE_NAME_CONVERT='/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1','/home/oracle/oracle/oradata/LEO3'
LOG_FILE_NAME_CONVERT='/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1','/home/oracle/oracle/oradata/LEO3'
STANDBY_FILE_MANAGEMENT=AUTO
local_listener='LISTENER_LEO3'
audit_file_dest='/home/oracle/oracle/admin/LEO3/adump'
background_dump_dest='/home/oracle/oracle/admin/LEO3/bdump'
core_dump_dest='/home/oracle/oracle/admin/LEO3/cdump'
user_dump_dest='/home/oracle/oracle/admin/LEO3/udump'
[oracle@even ~]$
[oracle@even ~]$ tail -n12 /home/oracle/oracle/product/10.2.0/db_2/network/admin/tnsnames.ora
LEO3=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=even)(PORT=1521))
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=LEO3)
)
)
LISTENER_LEO3 =
(ADDRESS = (PROTOCOL = tcp)(HOST = even)(PORT = 1521))
[oracle@even ~]$
@LEO1
SQL> alter database open;
Database altered.
SQL> select sequence#,applied from v$archived_log;
SEQUENCE# APP
---------- ---
10 NO
11 NO
12 NO
13 NO
14 NO
15 NO
16 NO
16 YES
8 rows selected.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY SESSIONS ACTIVE
SQL> select process,status,group#,sequence# from v$managed_standby;
PROCESS STATUS GROUP# SEQUENCE#
--------- ------------ ---------------------------------------- ----------
ARCH CLOSING 1 16
ARCH CONNECTED N/A 0
LGWR WRITING 2 17
SQL> !
[oracle@odd LEO1]$ tail -50f /home/oracle/oracle/product/10.2.0/db_1/admin/LEO1/bdump/alert_LEO1.log
...
alter database open
Sat Mar 1 23:10:00 2014
LGWR: STARTING ARCH PROCESSES
ARC0 started with pid=15, OS id=17162
Sat Mar 1 23:10:00 2014
ARC0: Archival started
ARC1: Archival started
LGWR: STARTING ARCH PROCESSES COMPLETE
ARC1 started with pid=16, OS id=17164
Sat Mar 1 23:10:00 2014
******************************************************************
LGWR: Setting 'active' archival for destination LOG_ARCHIVE_DEST_2
******************************************************************
LNSb started with pid=17, OS id=17166
Sat Mar 1 23:10:03 2014
LGWR: Standby redo logfile selected for thread 1 sequence 17 for destination LOG_ARCHIVE_DEST_2
Thread 1 advanced to log sequence 17
Sat Mar 1 23:10:03 2014
ARC1: STARTING ARCH PROCESSES
Sat Mar 1 23:10:03 2014
ARC0: Becoming the 'no FAL' ARCH
ARC0: Becoming the 'no SRL' ARCH
ARC0: LGWR is actively archiving destination LOG_ARCHIVE_DEST_2
Sat Mar 1 23:10:03 2014
Thread 1 opened at log sequence 17
Current log# 2 seq# 17 mem# 0: /home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/redo02.log
Successful open of redo thread 1
Sat Mar 1 23:10:03 2014
MTTR advisory is disabled because FAST_START_MTTR_TARGET is not set
Sat Mar 1 23:10:03 2014
SMON: enabling cache recovery
Sat Mar 1 23:10:03 2014
ARC2: Archival started
ARC1: STARTING ARCH PROCESSES COMPLETE
ARC1: Becoming the heartbeat ARCH
ARC2 started with pid=18, OS id=17170
Sat Mar 1 23:10:03 2014
ARC0: Standby redo logfile selected for thread 1 sequence 16 for destination LOG_ARCHIVE_DEST_2
Sat Mar 1 23:10:05 2014
Successfully onlined Undo Tablespace 1.
Sat Mar 1 23:10:05 2014
SMON: enabling tx recovery
Sat Mar 1 23:10:05 2014
Database Characterset is US7ASCII
Sat Mar 1 23:10:06 2014
Incremental checkpoint up to RBA [0x11.3.0], current log tail at RBA [0x11.28.0]
Sat Mar 1 23:10:07 2014
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
QMNC started with pid=19, OS id=17172
Sat Mar 1 23:10:09 2014
Completed: alter database open
Sat Mar 1 23:16:06 2014
Shutting down archive processes
Sat Mar 1 23:16:11 2014
ARCH shutting down
ARC2: Archival stopped
6.启动备库LEO3到mount状态
@LEO3
[oracle@even ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Mar 1 23:14:32 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining options
SQL> alter database recover managed standby database disconnect from session parallel 2;
Database altered.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY SESSIONS ACTIVE
SQL> select process,status,group#,sequence# from v$managed_standby;
PROCESS STATUS GROUP# SEQUENCE#
--------- ------------ ---------------------------------------- ----------
ARCH CLOSING 5 16
ARCH CONNECTED N/A 0
RFS IDLE 2 17
RFS IDLE N/A 0
RFS IDLE N/A 0
MRP0 WAIT_FOR_LOG N/A 17
6 rows selected.
SQL> !
[oracle@even ~]$ tail /home/oracle/oracle/admin/LEO3/bdump/alert_LEO3.log
...
Completed: ALTER DATABASE MOUNT
Sat Mar 1 23:10:03 2014
Using STANDBY_ARCHIVE_DEST parameter default value as /home/oracle/arch/LEO3
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[1]: Assigned to RFS process 31791
RFS[1]: Identified database type as 'physical standby'
Primary database is in MAXIMUM PERFORMANCE mode
Sat Mar 1 23:10:03 2014
RFS LogMiner: Client disabled from further notification
Primary database is in MAXIMUM PERFORMANCE mode
RFS[1]: Successfully opened standby log 4: '/home/oracle/oracle/oradata/LEO3/standbylog4a.log'
Sat Mar 1 23:10:03 2014
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[2]: Assigned to RFS process 31793
RFS[2]: Identified database type as 'physical standby'
RFS[2]: Successfully opened standby log 5: '/home/oracle/oracle/oradata/LEO3/standbylog5a.log'
Sat Mar 1 23:11:01 2014
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[3]: Assigned to RFS process 31895
RFS[3]: Identified database type as 'physical standby'
Sat Mar 1 23:14:34 2014
alter database recover managed standby database disconnect from session parallel 2
Sat Mar 1 23:14:34 2014
Attempt to start background Managed Standby Recovery process (LEO3)
MRP0 started with pid=20, OS id=32201
Sat Mar 1 23:14:34 2014
MRP0: Background Managed Standby Recovery process started (LEO3)
Managed Standby Recovery not using Real Time Apply
parallel recovery started with 2 processes
Clearing online redo logfile 1 /home/oracle/oracle/oradata/LEO3/redo01.log
Clearing online log 1 of thread 1 sequence number 17
Sat Mar 1 23:14:40 2014
Completed: alter database recover managed standby database disconnect from session parallel 2
Sat Mar 1 23:14:41 2014
Clearing online redo logfile 1 complete
Clearing online redo logfile 2 /home/oracle/oracle/oradata/LEO3/redo02.log
Clearing online log 2 of thread 1 sequence number 17
Clearing online redo logfile 2 complete
Clearing online redo logfile 3 /home/oracle/oracle/oradata/LEO3/redo03.log
Clearing online log 3 of thread 1 sequence number 15
Clearing online redo logfile 3 complete
Media Recovery Log /home/oracle/arch/LEO3/1_16_837172792.arc
Media Recovery Waiting for thread 1 sequence 17 (in transit)
三 第一次切换(LEO1=>LEO3)
换前LEO1库上创建swtich_tbs表空间 -> 切换 -> 检查表空间和对应的数据文件是否应用到了LEO3库
创建表空间
SQL> create tablespace swtich_tbs datafile '/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/swtich_tbs.dbf' size 10m;
Tablespace created.
SQL> alter system archive log current;
System altered.
SQL>
@LEO3
SQL> select * from v$tablespace where name='SWTICH_TBS';
TS# NAME INC BIG FLA ENC
---------- ------------------------------ --- --- --- ---
14 SWTICH_TBS YES NO YES
SQL> !
[oracle@even oradata]$ tail /home/oracle/oracle/admin/LEO3/bdump/alert_LEO3.log
...
Sat Mar 1 23:32:40 2014
Primary database is in MAXIMUM PERFORMANCE mode
RFS[1]: Successfully opened standby log 4: '/home/oracle/oracle/oradata/LEO3/standbylog4a.log'
Sat Mar 1 23:32:44 2014
Media Recovery Log /home/oracle/arch/LEO3/1_18_837172792.arc
Recovery created file /home/oracle/oracle/oradata/LEO3/swtich_tbs.dbf
Successfully added datafile 14 to media recovery
Datafile #14: '/home/oracle/oracle/oradata/LEO3/swtich_tbs.dbf'
Media Recovery Waiting for thread 1 sequence 19 (in transit)
查看LEO1库状态
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY SESSIONS ACTIVE
SQL>
查看LEO3库状态
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY SESSIONS ACTIVE
SQL>
主库切换成备库,并终止存活的会话
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY SESSIONS ACTIVE
SQL> alter database commit to switchover to physical standby with session shutdown;
Database altered.
SQL> select status,instance_name from v$instance;
STATUS INSTANCE_NAME
------------ ----------------
STARTED LEO1
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 419430400 bytes
Fixed Size 1219784 bytes
Variable Size 171967288 bytes
Database Buffers 243269632 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY TO PRIMARY
SQL> select status,instance_name from v$instance;
STATUS INSTANCE_NAME
------------ ----------------
MOUNTED LEO1
SQL> alter database recover managed standby database disconnect from session parallel 2;
Database altered.
SQL>
备库切换成主库,并终止存活的会话
SQL> alter database recover managed standby database cancel;
alter database recover managed standby database cancel
*
ERROR at line 1:
ORA-16136: Managed Standby Recovery not active
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY SESSIONS ACTIVE
SQL> alter database commit to switchover to primary with session shutdown;
Database altered.
SQL> alter database open;
Database altered.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY SESSIONS ACTIVE
SQL> select sequence#,applied from v$archived_log;
SEQUENCE# APP
---------- ---
16 YES
17 YES
18 YES
19 YES
20 YES
21 NO
21 YES
7 rows selected.
SQL> select process,status,group#,sequence# from v$managed_standby;
PROCESS STATUS GROUP# SEQUENCE#
--------- ------------ ---------------------------------------- ----------
ARCH CLOSING 5 18
ARCH CLOSING N/A 21
ARCH CONNECTED N/A 0
LNS WRITING 1 22
SQL>
四 第二次切换(LEO3=>LEO1)
切换前LEO3库上创建一张表 -> 切换 -> 检查表和记录是否应用到LEO1库上
SQL> create table leo3 as select * from dba_objects;
Table created.
SQL> select count(*) from leo3;
COUNT(*)
----------
9895
SQL> alter system archive log current;
System altered.
SQL> select process,status,group#,sequence# from v$managed_standby;
PROCESS STATUS GROUP# SEQUENCE#
--------- ------------ ---------------------------------------- ----------
ARCH CLOSING 5 18
ARCH CLOSING N/A 21
ARCH CONNECTED N/A 0
LNS WRITING 3 23
SQL>
备库LEO1的alert中记录着恢复的过程
[oracle@odd bdump]$ tail -50f /home/oracle/oracle/product/10.2.0/db_1/admin/LEO1/bdump/alert_LEO1.log
...
Sat Mar 1 23:42:53 2014
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[3]: Assigned to RFS process 18578
RFS[3]: Identified database type as 'physical standby'
Sat Mar 1 23:44:41 2014
RFS[2]: Possible network disconnect with primary database
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[4]: Assigned to RFS process 18761
RFS[4]: Identified database type as 'physical standby'
Primary database is in MAXIMUM PERFORMANCE mode
Primary database is in MAXIMUM PERFORMANCE mode
RFS[4]: Successfully opened standby log 5: '/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/standbylog5a.log'
Sat Mar 1 23:44:52 2014
Fetching gap sequence in thread 1, gap sequence 22-22
Sat Mar 1 23:44:55 2014
RFS[3]: Successfully opened standby log 4: '/home/oracle/oracle/product/10.2.0/db_1/oradata/LEO1/standbylog4a.log'
Sat Mar 1 23:45:22 2014
Media Recovery Log /home/oracle/arch/LEO1/1_22_837172792.arc
Media Recovery Waiting for thread 1 sequence 23 (in transit)
LEO1上检查leo3表,如果可以查到说明我们传递成功
SQL> alter database open read only;
alter database open read only
*
ERROR at line 1:
ORA-01154: database busy. Open, close, mount, and dismount not allowed now
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database open read only;
Database altered.
SQL> select count(*) from leo3;
COUNT(*)
----------
9895
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 419430400 bytes
Fixed Size 1219784 bytes
Variable Size 171967288 bytes
Database Buffers 243269632 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> alter database recover managed standby database disconnect from session parallel 2;
Database altered.
SQL>
LEO3库切换成备库状态
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY SESSIONS ACTIVE
SQL> alter database commit to switchover to physical standby with session shutdown;
Database altered.
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 419430400 bytes
Fixed Size 1219784 bytes
Variable Size 176161592 bytes
Database Buffers 239075328 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> alter database recover managed standby database disconnect from session parallel 2;
Database altered.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY SESSIONS ACTIVE
SQL>
LEO1库切换成主库状态
SQL> alter database recover managed standby database cancel;
alter database recover managed standby database cancel
*
ERROR at line 1:
ORA-16136: Managed Standby Recovery not active
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY TO PRIMARY
SQL> alter database commit to switchover to primary with session shutdown;
Database altered.
SQL> alter database open;
Database altered.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY TO STANDBY
SQL>
--EOF--