1 主庫設置為 force loging 模式
5:48:54 sys@felix SQL>alter database force logging;
-- 驗證 :
16:10:00 sys@felix SQL>selectforce_logging from v$database;
FORCE_
------
YES
查看主備庫監聽配置問題:
[oracle@felix ~]$ tnsping felix_st
TNS Ping Utility for Linux: Version11.2.0.3.0 - Production on 26-MAR-2014 16:12:49
Copyright (c) 1997, 2011, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS =(PROTOCOL = TCP)(HOST = 192.168.10.14)(PORT = 1521))) (CONNECT_DATA =(SERVICE_NAME = felix_st)))
OK (110 msec)
******************************************************************************************************************************************
[oracle@standby ~]$ tnsping felix_pd
TNS Ping Utility for Linux: Version11.2.0.3.0 - Production on 26-MAR-2014 16:12:37
Copyright (c) 1997, 2011, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS =(PROTOCOL = TCP)(HOST = 192.168.10.13)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME= felix_pd)))
OK (50 msec)
用spfile將備庫處於nomount狀態下:
開始進行duplicate:
這個操作主備庫都可以,只要RMAN連接時沒有寫錯就行了。
rman targetsys/oracle@felix_st auxiliary sys/oracle@felix_pd
duplicate target database for standby fromactive database;
如果路徑相同,使用這個:
duplicate target database for standby fromactive database nofilenamecheck;
以下是輸出日志:
RMAN> duplicate target database for standby fromactive database nofilenamecheck;
(注意觀察日志內容)
Starting Duplicate Db at 26-MAR-14
using target database control file insteadof recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=21 devicetype=DISK
contents of Memory Script:
{
backup as copy reuse
targetfile '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwfelix' auxiliary format
'/u01/app/oracle/product/11.2.0/db_1/dbs/orapwfelix' ;
}
----這個是目錄格式轉換
executing Memory Script
Starting backup at 26-MAR-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=44 device type=DISK
Finished backup at 26-MAR-14
contents of Memory Script:
{
backup as copy current controlfile for standbyauxiliary format '/u01/app/oracle/oradata/felix/control01.ctl';
restore clone controlfile to '/u01/app/oracle/fast_recovery_area/felix/control02.ctl'from
'/u01/app/oracle/oradata/felix/control01.ctl';
}
executing Memory Script
Starting backup at 26-MAR-14
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying standby control file
output filename=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_felix.ftag=TAG20140326T162408 RECID=2 STAMP=843236650
channel ORA_DISK_1: datafile copy complete,elapsed time: 00:00:07
Finished backup at 26-MAR-14
Starting restore at 26-MAR-14
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: copied control filecopy
Finished restore at 26-MAR-14
contents of Memory Script:
{
sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standbydatabase
contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/oracle/oradata/felix/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/u01/app/oracle/oradata/felix/system01.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/felix/sysaux01.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/felix/undotbs01.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/felix/users01.dbf";
set newname for datafile 5 to
"/u01/app/oracle/oradata/felix/example01.dbf";
backup as copy reuse
datafile 1 auxiliary format
"/u01/app/oracle/oradata/felix/system01.dbf" datafile
2 auxiliary format
"/u01/app/oracle/oradata/felix/sysaux01.dbf" datafile
3 auxiliary format
"/u01/app/oracle/oradata/felix/undotbs01.dbf" datafile
4 auxiliary format
"/u01/app/oracle/oradata/felix/users01.dbf" datafile
5 auxiliary format
"/u01/app/oracle/oradata/felix/example01.dbf" ;
sql 'alter system archive logcurrent';
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to/u01/app/oracle/oradata/felix/temp01.dbf in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting backup at 26-MAR-14
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001name=/u01/app/oracle/oradata/felix/system01.dbf
output filename=/u01/app/oracle/oradata/felix/system01.dbf tag=TAG20140326T162424
channel ORA_DISK_1: datafile copy complete,elapsed time: 00:02:05
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002name=/u01/app/oracle/oradata/felix/sysaux01.dbf
output filename=/u01/app/oracle/oradata/felix/sysaux01.dbf tag=TAG20140326T162424
channel ORA_DISK_1: datafile copy complete,elapsed time: 00:01:36
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005name=/u01/app/oracle/oradata/felix/example01.dbf
output filename=/u01/app/oracle/oradata/felix/example01.dbf tag=TAG20140326T162424
channel ORA_DISK_1: datafile copy complete,elapsed time: 00:01:06
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003name=/u01/app/oracle/oradata/felix/undotbs01.dbf
output filename=/u01/app/oracle/oradata/felix/undotbs01.dbf tag=TAG20140326T162424
channel ORA_DISK_1: datafile copy complete,elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004name=/u01/app/oracle/oradata/felix/users01.dbf
output filename=/u01/app/oracle/oradata/felix/users01.dbf tag=TAG20140326T162424
channel ORA_DISK_1: datafile copy complete,elapsed time: 00:00:15
Finished backup at 26-MAR-14
sql statement: alter system archive logcurrent
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=2 STAMP=843236998file name=/u01/app/oracle/oradata/felix/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=843236998file name=/u01/app/oracle/oradata/felix/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=843236998file name=/u01/app/oracle/oradata/felix/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=843236998file name=/u01/app/oracle/oradata/felix/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=6 STAMP=843236998file name=/u01/app/oracle/oradata/felix/example01.dbf
Finished Duplicate Db at 26-MAR-14
打開備庫:
16:35:27 sys@felix SQL>alter databaseopen;
Database altered.
16:35:45 sys@felix SQL>select statusfrom v$instance;
STATUS
------------------------
OPEN
16:36:32 sys@felix SQL>select open_modefrom v$database;
OPEN_MODE
----------------------------------------
READ ONLY
查看主庫:
16:35:56 sys@felix SQL>select statusfrom v$instance;
STATUS
------------------------
OPEN
16:36:13 sys@felix SQL>select open_modefrom v$database;
OPEN_MODE
----------------------------------------
READ WRITE
驗證數據庫:
啟動實時應用:
16:40:18 sys@felix SQL>alter databaserecover managed standby database using current logfile disconnect from session;
Database altered.
desc v$managed_standby;
Name Null? Type
-----------------------------------------------------------------------------
PROCESS VARCHAR2(9)
PID NUMBER
STATUS VARCHAR2(12)
CLIENT_PROCESS VARCHAR2(8)
CLIENT_PID VARCHAR2(40)
CLIENT_DBID VARCHAR2(40)
GROUP# VARCHAR2(40)
RESETLOG_ID NUMBER
THREAD# NUMBER
SEQUENCE# NUMBER
BLOCK# NUMBER
BLOCKS NUMBER
DELAY_MINS NUMBER
KNOWN_AGENTS NUMBER
ACTIVE_AGENTS NUMBER
sys@felix SQL>selectprocess,thread#,status from v$managed_standby;
PROCESS THREAD# STATUS
------------------ ----------------------------------
ARCH 1 CLOSING
ARCH 1 CLOSING
ARCH 0 CONNECTED
ARCH 1 CLOSING
RFS 0 IDLE
RFS 0 IDLE
RFS 0 IDLE
RFS 1 IDLE
MRP0 1 APPLYING_LOG
實時應用已經成功運行;
然後再主庫進行日志切換:
16:54:57 sys@felix SQL>alter systemswitch logfile;
System altered.
16:55:15 sys@felix SQL>alter systemswitch logfile;
System altered.
查看主庫日志最大序列:
SQL>select max(sequence#) from v$log;
MAX(SEQUENCE#)
--------------
14
再查看備庫的最大序列:
SQL>select max(sequence#) from v$log;
MAX(SEQUENCE#)
--------------
14
說明已經同步成功
現在開始進行主備庫切換:(切換到原來的主庫)
啟動備庫到mount狀態:
17:02:11 SQL>startup mount;
ORACLE instance started.
Total System Global Area 417546240 bytes
Fixed Size 2228944 bytes
Variable Size 322964784 bytes
Database Buffers 88080384 bytes
Redo Buffers 4272128 bytes
Database mounted.
17:02:33 SQL>select status from v$instance;
STATUS
------------------------
MOUNTED
17:03:03 SQL>
主庫再open狀態:
16:55:20 sys@felix SQL>select statusfrom v$instance;
STATUS
------------------------
OPEN
查看主庫的switchover狀態:
7:03:09 sys@felix SQL>selectswitchover_status from v$database;
SWITCHOVER_STATUS
----------------------------------------
TO STANDBY
執行切換命令:
17:05:14 sys@felix SQL>alter databasecommit to switchover to physical standby;
alter database commit to switchover tophysical standby
*
ERROR at line 1:
ORA-01093: ALTER DATABASE CLOSE onlypermitted with no sessions connected
17:07:36 sys@felix SQL>alter databasecommit to switchover to physical standby with session shutdown;
Database altered.
備庫執行切換命令:
17:03:03 SQL>alter database commit to switchover to primary;
alter database commit to switchover toprimary
*
ERROR at line 1:
ORA-16139: media recovery required
啟動mrp實時應用,進行media恢復;
17:15:02 SQL>alter database recover managed standby database using currentlogfile disconnect from session;
Database altered.
17:17:04 SQL>select switchover_status from v$database;
SWITCHOVER_STATUS
----------------------------------------
TO PRIMARY
17:17:40 SQL>alter database commit to switchover to primary;
Database altered.
驗證:
(1)主庫執行
17:20:51 SQL>select name,DATABASE_ROLE,DB_UNIQUE_NAME from v$database;
NAME DATABASE_ROLE DB_UNIQUE_NAME
-------------------------------------------------------------- ------------------------------------------------------------
FELIX PRIMARY felix_pd
(2)備庫執行
17:14:34 SQL>select name,DATABASE_ROLE,DB_UNIQUE_NAME from v$database;
NAME DATABASE_ROLE DB_UNIQUE_NAME
--------------------------------------------------------------------------------------------------------------------------
FELIX PHYSICAL STANDBY felix_st
然後打開主備庫:
alter database open;
進行日志切換:
alter system switch logile;
查看日志是否同步:
(主庫)17:22:42 SQL>selectmax(sequence#) from v$log;
MAX(SEQUENCE#)
--------------
20
(備庫)17:23:18 SQL>selectmax(sequence#) from v$log;
MAX(SEQUENCE#)
--------------
20
OK,到此全部執行完成!!