oracle 11g datagurd主從切換
前言:
環境介紹:
主庫:10.9.21.57
備庫:10.9.21.59
要想完成主從切換,需要保證如下幾點:
1.需要保證主備庫都得設定了下面的引數
*.log_archive_config='DG_CONFIG=(stdb59,testdb57)'
*.log_archive_dest_2='SERVICE=testdb57
LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=testdb57'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.LOG_FILE_NAME_CONVERT='/data/u01/app/oracle/oradata/testdb57','/data/u01/app/oracle/oradata/stdb59'
*.DB_FILE_NAME_CONVERT='/data/u01/app/oracle/oradata/testdb57','/data/u01/app/oracle/oradata/stdb59'
最好都設定:
FAL_SERVER
2.如果你想實時應用的話,主備庫都得新增了standby redo log;
概述:本文首先介紹正常的switchover,這樣方式用於主從切換演練,資料庫遷移等等,接著會介紹另一種切換方式是failover,也就是當主庫crash了,需要把從庫提升為新的主庫,failover可能會丟失部分資料!
首先介紹switchover:
一:在主庫上執行(10.9.21.57)
1.檢視主庫的狀態:
SQL> select name,open_mode,protection_mode from v$database;
NAME OPEN_MODE PROTECTION_MODE
--------- -------------------- --------------------
TESTDB57 READ WRITE MAXIMUM PERFORMANCE
SQL> select switchover_status ,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------
TO STANDBY PRIMARY
SWITCHOVER_STATUS–>TO STANDBY,表示可以正常切換.
SWITCHOVER_STATUS–>SESSIONS ACTIVE,表示當前有會話處於ACTIVE狀態,此時切換的話,需要加引數with session shutdown wait
2.在主庫執行切換:
SQL> alter database commit to switchover to physical standby with session shutdown wait ;
Database altered.
3.主庫執行切換之後,發現主庫例項已經down了!
SQL> select switchover_status ,database_role from v$database;
select switchover_status ,database_role from v$database
*
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 18269
Session ID: 196 Serial number: 9
4.啟動主庫到mount狀態
SQL> startup mount
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2253664 bytes
Variable Size 973081760 bytes
Database Buffers 620756992 bytes
Redo Buffers 7319552 bytes
Database mounted.
5檢視主庫的狀態,發現資料庫已經變成了PHYSICAL STANDBY的角色
SQL> select switchover_status ,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------
RECOVERY NEEDED PHYSICAL STANDBY
6.以redo only方式啟動新的standby 庫
SQL> alter database open read only;
Database altered.
二:備庫上操作:(10.9.21.59)
1.主庫的切換操作會傳輸到備庫,備庫的狀態就會自動轉換為to primary狀態;接下來檢視備庫的狀態:
SQL> select name,open_mode,protection_mode from v$database;
NAME OPEN_MODE PROTECTION_MODE
--------- -------------------- -----------------------------------------------------------------
TESTDB57 READ ONLY WITH APPLY MAXIMUM PERFORMANCE
SQL> select switchover_status ,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------
TO PRIMARY PHYSICAL STANDBY
2.確認沒有問題後,可以進行切換轉換standby 到primary 角色,這個過程會把資料庫從open read only的狀態變成為mounted的狀態,他必須這樣,因為之前是read only的,現在他要變成主了,需要以read write方式從新open;
SQL> alter database commit to switchover to primary;
Database altered.
3.再次檢視備庫的狀態,發現資料庫角色變成了primary,
SQL> select switchover_status ,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------
NOT ALLOWED PRIMARY
4.此時檢視新的主庫的狀態,發現確實已經由之前的open read only的狀態變成為mounted的狀態,
SQL> select status from v$instance;
STATUS
------------
MOUNTED
5.以read write方式從新open
SQL> alter database open;
Database altered.
三:回到新的從庫( 10.9.21.57)
1.開啟mrp程式應用日誌,重演變化!
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
2.檢視從庫的各個程式的狀態,
SQL> select process,status from v$managed_standby;
PROCESS STATUS
--------- ------------
ARCH CLOSING
ARCH CONNECTED
ARCH CONNECTED
ARCH CLOSING
MRP0 APPLYING_LOG
RFS IDLE
RFS IDLE
RFS IDLE
驗證:
在主庫建立一個表
1.10.9.21.59 上操作:
SQL> create table liuwenhe.liuwenhe(id int ,name varchar(100));
Table created.
SQL> insert into liuwenhe.liuwenhe values ( 1,'liuwenhe');
1 row created.
SQL> commit;
Commit complete.
2.在10.9.21.57 上檢視是夠已經同步過來,如下已經同步過來了!
SQL> select * from liuwenhe.liuwenhe;
ID NAME
---------- ------------------------------------------
1 liuwenhe
至此主從switchover切換完畢了
接著介紹failover的操作過程:
一:在主庫上操作(10.9.21.57)
1.模擬主庫crash的場景:
[root@testdb57 ~]# reboot
二:在從庫執行:( 10.9.21.59)
1.檢視有沒有gap
SQL> select * from v$archive_gap;
no rows selected
2.檢視此時的狀態:
SQL> select name,open_mode,switchover_status, DATABASE_ROLE,PROtection_mode from v$database;
NAME OPEN_MODE SWITCHOVER_STATUS DATABASE_ROLE PROTECTION_MODE
--------- -------------------- -------------------- ---------------- --------------------
TESTDB57 READ ONLY WITH APPLY NOT ALLOWED PHYSICAL STANDBY MAXIMUM PERFORMANCE
3.初始化failover,相當於switchover的時候在主庫執行了 alter database commit to switchover to physical standby with session shutdown wait;
SQL> alter database recover managed standby database finish force;
Database altered.
4.再次檢視備庫的狀態,發現SWITCHOVER_STATUS 變成了TO PRIMARY;
SQL> select name,open_mode,switchover_status, DATABASE_ROLE,protection_mode from v$database;
NAME OPEN_MODE SWITCHOVER_STATUS DATABASE_ROLE PROTECTION_MODE
--------- -------------------- -------------------- ---------------- --------------------
TESTDB57 MOUNTED TO PRIMARY PHYSICAL STANDBY MAXIMUM PERFORMANCE
5.將備課轉換成主庫!
SQL> alter database commit to switchover to primary;
Database altered.
6.再次檢視備庫的狀態,發現database_role變成了 PRIMARY了!並且open_mode變成了mounted的狀態了!
SQL> select name,open_mode,switchover_status, DATABASE_ROLE,PROtection_mode from v$database;
NAME OPEN_MODE SWITCHOVER_STATUS DATABASE_ROLE PROTECTION_MODE
--------- -------------------- -------------------- ---------------- --------------------
TESTDB57 MOUNTED NOT ALLOWED PRIMARY MAXIMUM PERFORMANCE
7.開啟新的主
SQL> alter database open ;
Database altered.
至此oracle11g的主從failover切換完畢!
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29654823/viewspace-2158290/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle 11g 一主多備切換方案Oracle
- Oracle 11g dg switchover切換操作流程Oracle
- Redis主從切換Redis
- 手工切換MySQL主從MySql
- Redis sentinel主從切換Redis
- ORACLE 12C DATAGUARD環境搭建和主從切換Oracle
- Oracle 單機切換為主備Oracle
- keepalived配置redis主從切換Redis
- ostgreSQL主從切換-手動SQL
- Oracle DataGuard 主備切換 (switchover) oracle11gOracle
- StoneDB 主從切換實踐方案
- Redis叢集的主從切換研究Redis
- REDIS主從頻繁切換事件排查Redis事件
- Mongodb資料同步和主從切換MongoDB
- 一個月後,我們又從 MySQL 雙主切換成了主 - 從!MySql
- oracle 11g dg broker 開啟fast-start failover自動故障切換OracleASTAI
- MySQL 主從切換延時高問題分析MySql
- (九)主題切換
- postgresql10主從+keepalived高可用自動切換(切換關鍵在指令碼)SQL指令碼
- MYSQL5.6主從+keepalive高可用自動切換MySql
- Dledger是如何實現主從自動切換的
- docker Redis單機主從哨兵模式切換失敗DockerRedis模式
- mysql 5.7+keepalived主從切換步驟簡述MySql
- oracle dg切換操作示例Oracle
- Oracle 11g單主搭建物理DGOracle
- 小程式切換主題配色
- echarts 主題動態切換Echarts
- Oracle Temp 表空間切換Oracle
- oracle11g dataguard切換Oracle
- Oracle RAC DG手動切換Oracle
- 生產環境中mysql資料庫由主從關係切換為主主關係MySql資料庫
- Redis哨兵叢集:哨兵掛了,主從庫還能切換嗎?Redis
- 從遠端桌面連線切換回主螢幕的快捷鍵
- MHA實現mysql主從資料庫手動切換的方法MySql資料庫
- Flutter主題切換之flutter reduxFlutterRedux
- Oracle MySQL PG主從OracleMySql
- MySQL 5.7傳統複製到GTID線上切換(一主一從)MySql
- Redis哨兵模式(sentinel)學習總結及部署記錄(主從複製、讀寫分離、主從切換)Redis模式