oracle 搭建實時同步data guard的最高可用-切換主備
搭建實時同步data guard的最高可用-切換主備
首先保證主庫在歸檔模式下:錯過N次了
準備二臺機器(hostname gw hosts ech0)host-only
[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:9C:CC:51
inet addr:192.168.56.147 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe9c:cc51/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:750606 errors:0 dropped:0 overruns:0 frame:0
TX packets:132742 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:179921301 (171.5 MiB) TX bytes:2845074889 (2.6 GiB)
eth0:1 Link encap:Ethernet HWaddr 08:00:27:9C:CC:51
inet addr:192.168.1.147 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
主庫
ip 192.168.1.147 node1.dg.com 安裝好ORACLE,正常執行的資料庫
ipadd: 192.168.1.147 gw:192.168.1.1
oracle sid: orcl
database name :orcl
service name :orcl
備庫
ip 192.168.1.157 node1.dg.com 只安裝軟體就可以了
ipadd: 192.168.1.157
gw:192.168.1.1
oracle sid: orcl02
database name :orcl -->??
service name :orcl -->??
步驟
1 --在二臺機器上都建立oracleNET 即生成listner.ora及tnsnames.ora
--主庫已有listner.ora and tnsnames.ora,需要增加tnsnames.ora到備庫network service names
netmgr
--只需要在備庫上建立(監聽為靜態監聽)和tnsnames
--以上建立完畢,需要主備都啟監聽(注意VBOX可以調介面)
1.1 ssh 192.168.1.147---> on primary
netmgr
/*1.1 cp -v $ORACLE_HOME/network/admin/listner.ora $ORACLE_HOME/network/admin/listner.ora.std
cp -v $ORACLE_HOME/network/admin/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora.std
vi listner.ora.std
vi tnsnames.ora.std
scp listner.ora.std
scp tnsnames.ora.std [email protected]:$ORACLE_HOME/network/admin/tnsnames.ora
[[email protected] ~]$ cat /u01/app/oracle/product/11.2.0.1/db_1/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0.1/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0.1/db_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.147)(PORT = 1521))
)
ADR_BASE_LISTENER = /u01/app/oracle
*/
lsnrctl start -->on primary,stdby二邊都要做
2 --準備備庫的parameter file
--on primary
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ -----------
db_file_name_convert string
db_name string orcl
db_unique_name string orcl
global_names boolean FALSE
instance_name string orcl
lock_name_space string
log_file_name_convert string
service_names string orcl
SQL>
SQL> select name from v$controlfile;
NAME
------------------------------------------------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/control01.ctl
/u01/app/oracle/flash_recovery_area/orcl/control02.ctl
SQL> select name from v$datafile;
NAME
------------------------------------------------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/users01.dbf
/u01/app/oracle/oradata/orcl/undotbs1.dbf
7 rows selected.
SQL>
--add parameter in spfile on primary
SQL> alter system set db_unique_name='orcl' scope=spfile;
SQL> alter system set service_names='orcl' scope=spfile;
SQL> alter system set log_archive_config='dg_config=(orcl,orclstd)' ;
SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/archivelog/orcl valid_for=(all_logfiles,all_roles) db_unique_name=orcl' ;
SQL> alter session set log_archive_dest_state_2=defer;
SQL> alter system set log_archive_dest_2='service=to_157 valid_for=(online_logfile,primary_role) db_unique_name=orclstd';
dg_config 註冊成員例項名:oracle_sid
location 本地相關資訊
service=to_157 輸送到備庫監聽名稱 to_157字串
--
-- alter system set log_file_name_convert='remote_archive_path','local_archive_path'
-- /home/oracle/archive,/opt/oracle/oradata
-- alter system set db_file_name_convert='remote_oardata_path','local_oradata_path'
-- /home/oracle/oradata,/opt/oracle/oradata
SQL> alter system set dispatchers='';--在備庫中一定刪除掉
SQL> create pfile='/home/oracle/p.ora' from spfile;
[[email protected] ~]$ cp -v p.ora s.ora
`p.ora' -> `s.ora'
[[email protected] ~]$ vim s.ora
[[email protected] ~]$ diff p.ora s.ora
1,9d0
< orcl.__db_cache_size=37748736
< orcl.__java_pool_size=4194304
< orcl.__large_pool_size=4194304
< orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
< orcl.__pga_aggregate_target=117440512
< orcl.__sga_target=218103808
< orcl.__shared_io_pool_size=0
< orcl.__shared_pool_size=130023424
< orcl.__streams_pool_size=4194304
22c13
< *.db_unique_name='orcl'
---
> *.db_unique_name='orclstd'
24d14
< *.dispatchers='(protocol=TCP)'
27,28c17,18
< *.log_archive_dest_1='location=/u01/app/oracle/archivelog/orcl valid_for=(all_logfiles,all_roles) db_unique_name=orcl'
< *.log_archive_dest_2='service=to_157 valid_for=(online_logfile,primary_role) db_unique_name=orcl02'
*.log_arvhice_dest_state_2=defer;
---
> *.log_archive_dest_1='location=/u01/app/oracle/archivelog/orcl valid_for=(all_logfiles,all_roles) db_unique_name=orclstd'
> *.log_archive_dest_2='service=to_147 valid_for=(online_logfile,primary_role) db_unique_name=orcl'
-- on stdby
[[email protected] ~]$ export ORACLE_SID=orcl02
[[email protected] ~]$ cat s.oar
--下面照著引數檔案進行修改一下
mkdir -pv /u01/app/oracle/admin/orcl/adump
mkdir -pv /u01/app/oracle/oradata/orcl
mkdir -pv /u01/app/oracle/flash_recovery_area/orcl
mkdir -pv /u01/app/oracle/archivelog/orcl
SQL> startup nomount pfile='/home/oracle/s.ora';
SQL>create spfile from pfile='/home/oracle/s.ora';
--處於NOMOUNT狀態,備庫
Recovery Manager: Release 11.2.0.1.0 - Production on Thu Mar 8 12:00:44 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1334497743)
connected to auxiliary database: ORCL (not mounted)
`
duplicate target database for standby from active database nofilenamecheck;
--duplicate target database for standby from active database nofilenamecheck dorecover;
--on standby
SQL>alter database open read only--這一步是相當重要的
SQL> alter database open;
SQL> alter database recover managed standby database disconnect from session;
SQL>
SQL> alter database recover managed standby database cancel;
SQL> ho lsnrctl stop
SQL> shutdown immeidate;
測試是否歸檔時,資料能夠同步到對面去:
SQL> alter system set log_archive_dest_state_2=enable;
System altered.
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
關機順序
主庫:
SQL> alter system set log_archive_dest_state_2=defer;
System altered.
備庫:
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
注意Data Guard 啟動順序:
啟動順序:先standby ,後primary;
閉順序:先primary 後standby;
手工註冊沒有同步的日誌,手工COPE過去,這樣才能認得到
alter database register logfile '/home/oracle/archive/1_13_67867676.dbf';
alter database register logfile '/home/oracle/archive/1_14_67867676.dbf';
alter database register logfile '/home/oracle/archive/1_15_67867676.dbf';
select open_mod,protection_mode,database_role from v$database;
select dest_id,error from v$archive_dest where DEST_ID in (1,2);
select sequence#,archvie
--最大可用的學習筆記
SQL> select database_role from v$database;
DATABASE_ROLE
----------------
PHYSICAL STANDBY
二邊都要做主備庫都要建立為以後切換作準備
SQL> ho mkdir -vp /home/oracle/orcl_stdlog
mkdir: created directory `/home/oracle/orcl_stdlog'
SQL> show parameter standby
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
standby_archive_dest string ?/dbs/arch
standby_file_management string MANUAL
SQL> alter database add standby logfile '//home/oracle/orcl_stdlog/stdbylog01.dbf' size .
SQL> alter database recover managed standby database cancel;
Database altered.
select * from v$standby_log;
SQL> alter database add standby logfile '/home/oracle/orcl_stdlog/stdbylog01.dbf' size 50m;
Database altered.
--下面修改了SQL後加"/"執行一遍一定要大於線上三組的日誌,在這裡面建立了四組日誌
SQL> c/01/02;
1* alter database add standby logfile '/home/oracle/orcl_stdlog/stdbylog02.dbf' size 50m
SQL> c/02/03
1* alter database add standby logfile '/home/oracle/orcl_stdlog/stdbylog03.dbf' size 50m
SQL> c/03/04
1* alter database add standby logfile '/home/oracle/orcl_stdlog/stdbylog04.dbf' size 50m
SQL> alter system set standby_file_management=auto;
System altered.
SQL>
SQL> alter system set standby_file_management=auto;--注意二邊都要設定成自動,增加stdbylog之前
手動:
-----------------
主庫:
alter system set log_archive_dest_1='location=/home/oracle/log_archive lgwr affirm sync valid_for=(all_logfiles,all_roles) db_unique_name=orcl';
alter system set log_archive_dest_2='service=to_157 lgwr affirm sync valid_for=(online_logfile,primary_role) db_unique_name=orcl02';
alter system set log_archive_dest_3='location=/home/oracle/standbylog_archive valid_for=(standby_logfile,standby_role) db_unique_name=orcl';
ho mkdir -pv /home/oracle/standbylog_archive;
ho mkdir -pv /home/oracle/standbylog_archive;
standby--備庫,為未來做切換做好準備
主庫假設就是切換成備庫
ho mkdir -pv /home/oracle/standbylog_archive;
alter system set log_archive_dest_1='location=/home/oracle/log_archive lgwr affirm sync valid_for=(all_logfiles,all_roles) db_unique_name=orcl02';
alter system set log_archive_dest_2='service=to_147 lgwr affirm sync valid_for=(online_logfle,primary_role) db_unique_name=orcl';
alter system set log_archive_dest_3='location=/home/oracle/standbylog_archive valid_for=(standby_logfile,standby_role) db_unique_name=orcl02';
ho mkdir -pv /home/oracle/standbylog_archive;
查詢是否已經應用:
select sequence#,applied,archived from v$archived_log;
show parameter log_archive_dest
備庫:
--準備這一次在建立好,實時應用日誌
alter database recover managed standby database using current logfile disconnect from session
主庫:
select protection_mode from v$database;
SQL> alter system set log_archive_dest_state_2=enable;
System altered.
SQL> select SWITCHOVER_STATUS from v$database;
SWITCHOVER_STATUS
--------------------
TO STANDBY
alter database set standby database to maximize availability;
查詢自己建立了多少組備庫的日誌組
SQL> select * from v$standby_log;
select group#,dbid,thread#,sequence# from v$standby_log;
SQL> select status from v$instance;
STATUS
------------
OPEN
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
select protection_mode,database_role,protection_level from v$database;
主庫主動關閉
SQL> select SWITCHOVER_STATUS from v$database;
SWITCHOVER_STATUS
--------------------
TO STANDBY
SQL> alter system switch logfile;
System altered.
SQL> /
Database altered.
select open_mode from v$database;
select dest_id,status,destination,error from v$archive_dest where dest_id<=5;
SELECT NAME FROM V$ARCHIVED_LOG WHERE THREAD#=1 AND DEST_ID=1
AND SEQUENCE# BETWEEN 50 AND 202;
----------切換主備 切換之前前再一TNSPING 網路 切換之後記得改ENABLE 新主庫alter system set log_archive_dest_state_2=enable;
主庫
在最大可用的物理standby要擁有自己的聯機日誌:接收主庫傳送過來的redo條目
alter database add standby logfile '' size 50m;
alter database add standby logfile '' size 50m;
alter database add standby logfile '' size 50m;
alter database add standby logfile '' size 50m;
SQL> alter system set standby_file_management=auto;
SQL> alter database set standby database to maximize availability;
Database altered.
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO STANDBY
SQL> alter database commit to switchover to physical standby;
Database altered.
SQL> select status from v$instance;
STATUS
------------
STARTED
SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 931143680 bytes
Fixed Size 2218872 bytes
Variable Size 578815112 bytes
Database Buffers 343932928 bytes
Redo Buffers 6176768 bytes
Database mounted.
Database opened.
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
SQL> alter system set standby_file_management=auto;
System altered.
SQL> select protection_mode,database_role,protection_level from v$database;
PROTECTION_MODE DATABASE_ROLE PROTECTION_LEVEL
-------------------- ---------------- --------------------
MAXIMUM AVAILABILITY PHYSICAL STANDBY RESYNCHRONIZATION
SQL>
備庫SQL> select PROTECTION_MODE from v$database;
PROTECTION_MODE
--------------------
MAXIMUM AVAILABILITY
SQL> alter system set log_archive_dest_state_2=enable;
System altered.
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
NOT ALLOWED
SQL> alter database commit to switchover to primary;
Database altered.
SQL> alter system set log_archive_dest_state_2=enable;--理解這二個地方的意思
System altered.
SQL> alter system set standby_file_management=auto;--理解這二個地方的意思,切換時會報錯
System altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
MOUNTED
SQL> alter database open;
Database altered.
SQL> select protection_mode,database_role,protection_level from v$database;
PROTECTION_MODE DATABASE_ROLE PROTECTION_LEVEL
-------------------- ---------------- --------------------
MAXIMUM AVAILABILITY PRIMARY RESYNCHRONIZATION
實踐體現:
1、oracle資料庫每天凌晨4:00:00會對現網的adway的資料做一個exp匯出整個使用者的操作,在現網資料有問題時,可以恢復到前一天的凌晨4點的狀態。
需要整個資料庫至昨天的狀態步驟如下:
SQL> drop user zboss_user;
SQL> create user zboss_user identified by izptec;
SQL> grant connect,resource to zboss_user;
cd /home/oracle/backdm/
imp zboss_user/izptec file=./zboss1_date_2010-12-20.dmp full=y
需要恢復表table1、table2至昨天的狀態
cd /home/oracle/backdm/
進入資料庫把兩張表清空,
imp zboss_user/izptec file=./zboss1_date_2010-12-20.dmp tables=table1,table2
2、oracle在武漢111.175.242.22伺服器上做了dataguard,對現網資料庫進行實時同步,若現網資料庫down機了,恢復只需要15分鐘
主庫需要做的操作
Dataguard 角色切換(由PRIMARY DB到STANDBY DB)
首先應把primary db切換成standby db(如果主庫已經down掉了,就不用做這一步了)
SQL>alter database commit to switchover to physical standby with session shutdown;
SQL>shutdown immediate;
SQL>startup mount;
SQL>alter database recover managed standby database disconnect from session;
檢視狀態
SQL>select name,database_role from v$database;
NAME DB_UNIQUE_NAME PROTECTION_MODE
--------- ------------------------------ --------------------
STANDBY STANDBY UNPROTECTED
看到主庫已經成了備庫.
備庫需要做的操作
接著把standby db 切換成primary db
SQL> alter database commit to switchover to primary;
SQL> shutdown immediate;
SQL> startup;
檢視狀態
SQL> select name,database_role from v$database;
NAME DATABASE_ROLE
--------- ----------------
STANDBY PRIMARY
從primary關鍵字可以看出備庫切換成了主庫.
這樣就恢復到主庫down機前的狀態了。
===========================================主庫一輪切換======================
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=825206190 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=6 STAMP=825206190 file name=/u01/app/oracle/oradata/orcl/users01.dbf
contents of Memory Script:
{
set until scn 1050293;
recover
standby
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 04-SEP-13
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 2 is already on disk as file /u01/app/oracle/product/11.2.0.1/db_1/dbs/arch1_2_825206525.dbf
archived log file name=/u01/app/oracle/product/11.2.0.1/db_1/dbs/arch1_2_825206525.dbf thread=1 sequence=2
media recovery complete, elapsed time: 00:00:01
Finished recover at 04-SEP-13
Finished Duplicate Db at 04-SEP-13
RMAN> exit
Recovery Manager complete.
[[email protected] ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 4 00:14:14 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select group#,dbid,thread# from v$standby_log;
GROUP# DBID THREAD#
---------- ---------------------------------------- ----------
4 UNASSIGNED 1
5 UNASSIGNED 1
6 UNASSIGNED 0
7 UNASSIGNED 0
SQL> ho /home/oracle/standby_log_archive;
/bin/bash: /home/oracle/standby_log_archive: No such file or directory
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[[email protected] ~]$ ls /home/oracle/standbylog_archive
1_19_825119295.dbf 1_21_825119295.dbf
1_20_825119295.dbf o1_mf_2_92ct2t1v_.log
[[email protected] ~]$ ls /home/oracle/standbylog_archive -l
total 62844
-rw-r----- 1 oracle oinstall 1024 Sep 3 22:56 1_19_825119295.dbf
-rw-r----- 1 oracle oinstall 9760256 Sep 3 22:57 1_20_825119295.dbf
-rw-r----- 1 oracle oinstall 2073088 Sep 3 23:01 1_21_825119295.dbf
-rw-r----- 1 oracle oinstall 52429312 Sep 3 23:25 o1_mf_2_92ct2t1v_.log
[[email protected] ~]$ ls -l /home/oracle/standbylog_archive
total 62844
-rw-r----- 1 oracle oinstall 1024 Sep 3 22:56 1_19_825119295.dbf
-rw-r----- 1 oracle oinstall 9760256 Sep 3 22:57 1_20_825119295.dbf
-rw-r----- 1 oracle oinstall 2073088 Sep 3 23:01 1_21_825119295.dbf
-rw-r----- 1 oracle oinstall 52429312 Sep 3 23:25 o1_mf_2_92ct2t1v_.log
[[email protected] ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 4 00:22:42 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/standbylog_archive
Oldest online log sequence 4
Next log sequence to archive 6
Current log sequence 6
SQL> alter system set log_archive_dest_3='location=/home/oracle/standbylog_archive valid_for=(standby_logfile,standby_role) db_unique_name=orcl';
System altered.
SQL> alter system set standby_file_management=auto;
System altered.
SQL> alter system set log_archive_dest_state_2=enable;
System altered.
SQL> ho tnsping to_157;
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 04-SEP-2013 00:33:46
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
/u01/app/oracle/product/11.2.0.1/db_1/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.157)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
OK (20 msec)
SQL> create table scott.yun as select * from dba_tables;
Table created.
SQL> select protection_mode from v$database;
PROTECTION_MODE
--------------------
MAXIMUM AVAILABILITY
SQL> select sequence#,applied,archived from v$archived_log;
SEQUENCE# APPLIED ARC
---------- --------- ---
7 YES YES
8 YES YES
9 YES YES
10 YES YES
10 YES YES
11 YES YES
11 YES YES
12 YES YES
12 YES YES
13 YES YES
13 YES YES
SEQUENCE# APPLIED ARC
---------- --------- ---
14 YES YES
14 YES YES
15 YES YES
15 YES YES
16 YES YES
16 YES YES
17 YES YES
17 YES YES
18 YES YES
18 YES YES
19 YES YES
SEQUENCE# APPLIED ARC
---------- --------- ---
19 YES YES
20 NO YES
20 YES YES
21 NO YES
21 YES YES
1 NO YES
2 NO YES
3 NO YES
3 YES YES
4 NO YES
4 YES YES
SEQUENCE# APPLIED ARC
---------- --------- ---
5 NO YES
5 YES YES
6 NO YES
6 YES YES
7 NO YES
7 NO YES
39 rows selected.
SQL> ho ls -l /home/oracle/standbylog_archive;
total 62844
-rw-r----- 1 oracle oinstall 1024 Sep 3 22:56 1_19_825119295.dbf
-rw-r----- 1 oracle oinstall 9760256 Sep 3 22:57 1_20_825119295.dbf
-rw-r----- 1 oracle oinstall 2073088 Sep 3 23:01 1_21_825119295.dbf
-rw-r----- 1 oracle oinstall 52429312 Sep 3 23:25 o1_mf_2_92ct2t1v_.log
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO STANDBY
SQL> alter database commit to switchover to physical standby;
Database altered.
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 931143680 bytes
Fixed Size 2218872 bytes
Variable Size 578815112 bytes
Database Buffers 343932928 bytes
Redo Buffers 6176768 bytes
Database mounted.
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
SQL> select name,database_role from v$database;
NAME DATABASE_ROLE
--------- ----------------
ORCL PHYSICAL STANDBY
SQL> alter system set standby_file_management=auto;
System altered.
SQL> alter system set log_archive_dest_state_2=enable;
System altered.
--一般備庫下的狀態為NOT ALLOWED是不能切換的,因為一山不容二虎,第一先把主庫降下來後,才能把主庫提上去,提之前,新備庫得進恢復模式,新主庫得DEST_STATE_2再次重置enable
SQL> select SWITCHOVER_STATUS from v$database;
SWITCHOVER_STATUS
--------------------
NOT ALLOWED
SQL> ho tnsping to_157
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 04-SEP-2013 00:46:36
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
/u01/app/oracle/product/11.2.0.1/db_1/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.157)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
OK (0 msec)
SQL> select SWITCHOVER_STATUS from v$database;
SWITCHOVER_STATUS
--------------------
NOT ALLOWED
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
MOUNTED
--在恢復模式下不能開庫,得取消恢復狀態
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-10456: cannot open standby database; media recovery session may be in
progress
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database open;
Database altered.
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
SQL> select count(*) from scott.cwm;
COUNT(*)
----------
2730
SQL> ho tnsping to_157
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 04-SEP-2013 00:51:28
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
/u01/app/oracle/product/11.2.0.1/db_1/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.157)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
OK (10 msec)
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
NOT ALLOWED
SQL> alter database commit to switchover to primary;
Database altered.
SQL> alter system set log_archive_dest_state_2=enable;
System altered.
SQL> alter system set standby_file_management=auto;
System altered.
SQL> alter system set log_archive_dest_state_2=enable;
System altered.
--由於第二輪切換時的新主庫還未處於OPEN狀態下面
SQL> create table scott.chenjian as select * from dba_objects;
create table scott.chenjian as select * from dba_objects
*
ERROR at line 1:
ORA-01109: database not open
SQL> alter database open;
Database altered.
SQL> alter system set log_archive_dest_state_2=enable;
System altered.
SQL> create table scott.chenjian as select * from dba_objects;
Table created.
SQL> show parameter date
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
fixed_date string
nls_date_format string
nls_date_language string
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.
SQL> select sysdate from dual;
SYSDATE
-------------------
2013-09-04 01:05:55
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[[email protected] ~]$ exit
logout
[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:9C:CC:51
inet addr:192.168.56.147 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe9c:cc51/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:750606 errors:0 dropped:0 overruns:0 frame:0
TX packets:132742 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:179921301 (171.5 MiB) TX bytes:2845074889 (2.6 GiB)
eth0:1 Link encap:Ethernet HWaddr 08:00:27:9C:CC:51
inet addr:192.168.1.147 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
[[email protected] ~]# su - oracle
[[email protected] ~]$ cat /u01/app/oracle/product/11.2.0.1/db_1/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0.1/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0.1/db_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.147)(PORT = 1521))
)
ADR_BASE_LISTENER = /u01/app/oracle
===========================備庫=192.168.56.157==========================================================
GROUP# DBID THREAD#
---------- ---------------------------------------- ----------
4 1352900027 1
5 1352900027 1
6 1352900027 1
7 UNASSIGNED 0
SQL> ho ls /home/oracle/standbylog_archive
1_14_825119295.dbf 1_15_825119295.dbf 1_16_825119295.dbf 1_17_825119295.dbf 1_18_825119295.dbf
SQL> ho ls /home/oracle/ -l
total 2297868
drwxr-xr-x 8 oracle oinstall 4096 Aug 21 2009 database
-rw-r--r-- 1 root root 1239269270 Dec 1 2012 linux.x64_11gR2_database_1of2.zip
-rw-r--r-- 1 root root 1111416131 Dec 1 2012 linux.x64_11gR2_database_2of2.zip
drwxrwxr-x 2 oracle oinstall 4096 Sep 3 23:01 log_archive
drwxr-xr-x 3 oracle oinstall 4096 Sep 1 10:10 oradiag_oracle
drwxr-xr-x 2 oracle oinstall 4096 Sep 3 22:09 orcl_stdlog
-rw-r--r-- 1 oracle oinstall 845 Sep 3 21:20 s.ora
drwxr-xr-x 2 oracle oinstall 4096 Sep 3 22:32 standbylog_archive
SQL> ho ls -l /home/oracle/standbylog_archive
total 2660
-rw-r----- 1 oracle oinstall 858624 Sep 3 22:14 1_14_825119295.dbf
-rw-r----- 1 oracle oinstall 1043968 Sep 3 22:18 1_15_825119295.dbf
-rw-r----- 1 oracle oinstall 786432 Sep 3 22:32 1_16_825119295.dbf
-rw-r----- 1 oracle oinstall 1536 Sep 3 22:32 1_17_825119295.dbf
-rw-r----- 1 oracle oinstall 13312 Sep 3 22:32 1_18_825119295.dbf
SQL> alter system set standby_file_management=auto
2 ;
System altered.
SQL> alter system set log_archive_dest_1='location=/home/oracle/log_archive lgwr affirm sync valid_for=(all_logfiles,all_roles) db_unique_name=orcl02';
System altered.
SQL> alter system set log_archive_dest_2='service=to_147 lgwr affirm sync valid_for=(online_logfile,primary_role) db_unique_name=orcl';
System altered.
SQL> ho mkdir -pv /home/oracle/standbylog_archive;
SQL> alter system set log_archive_dest_3='location=/home/oracle/standbylog_archive valid_for=(standby_logfile,standby_role) db_unique_name=orcl02';
System altered.
SQL> alter system set standby_file_management=auto;
System altered.
SQL> alter database recover managed standby database using current logfile disconnect from session
2 ;
Database altered.
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 931143680 bytes
Fixed Size 2218872 bytes
Variable Size 545260680 bytes
Database Buffers 377487360 bytes
Redo Buffers 6176768 bytes
Database mounted.
raDatabase opened.
SQL> show parameter archive
SP2-0734: unknown command beginning "rashow par..." - rest of line ignored.
SQL> show parameter log_archive_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest string
log_archive_dest_1 string location=/home/oracle/log_arch
ive valid_for=(all_logfiles,al
l_roles) db_unique_name=orcl
log_archive_dest_10 string
log_archive_dest_11 string
log_archive_dest_12 string
log_archive_dest_13 string
log_archive_dest_14 string
log_archive_dest_15 string
log_archive_dest_16 string
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_17 string
log_archive_dest_18 string
log_archive_dest_19 string
log_archive_dest_2 string service=to_157 valid_for=(onli
ne_logfile,primary_role) db_un
ique_name=orcl02
log_archive_dest_20 string
log_archive_dest_21 string
log_archive_dest_22 string
log_archive_dest_23 string
log_archive_dest_24 string
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_25 string
log_archive_dest_26 string
log_archive_dest_27 string
log_archive_dest_28 string
log_archive_dest_29 string
log_archive_dest_3 string
log_archive_dest_30 string
log_archive_dest_31 string
log_archive_dest_4 string
log_archive_dest_5 string
log_archive_dest_6 string
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_7 string
log_archive_dest_8 string
log_archive_dest_9 string
log_archive_dest_state_1 string enable
log_archive_dest_state_10 string enable
log_archive_dest_state_11 string enable
log_archive_dest_state_12 string enable
log_archive_dest_state_13 string enable
log_archive_dest_state_14 string enable
log_archive_dest_state_15 string enable
log_archive_dest_state_16 string enable
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_state_17 string enable
log_archive_dest_state_18 string enable
log_archive_dest_state_19 string enable
log_archive_dest_state_2 string enable
log_archive_dest_state_20 string enable
log_archive_dest_state_21 string enable
log_archive_dest_state_22 string enable
log_archive_dest_state_23 string enable
log_archive_dest_state_24 string enable
log_archive_dest_state_25