oracle dg 狀態檢查 先檢查備庫的歸檔日誌同步情況 SELECT NAME,applied FROM v$archived_log; alter database recover managed standby database cancel; select thread#,sequence ...
oracle dg 狀態檢查
先檢查備庫的歸檔日誌同步情況
SELECT NAME,applied FROM v$archived_log;
alter database recover managed standby database cancel;
select thread#,sequence#,standby_dest,archived,applied,status from v$archived_log order by 1,2;
alter database recover managed standby database using current logfile disconnect from session;
.在備庫 查看gap
1. select * from v$archive_gap;
ALTER DATABASE RECOVER MANAGED
STANDBY DATABASE DISCONNECT FROM SESSION;
查看主庫的基本信息:
SYS@enmo1 hey~1->select open_mode,protection_mode,database_role,switchover_status from v$database;
OPEN_MODE
PROTECTION_MODE
DATABASE_ROLE
SWITCHOVER_STATUS
-------------------- -----------------------------
------------------------ ------------------------
READ WRITE MAXIMUM PERFORMANCE
PRIMARY
TO STANDBY
查看備庫的基本信息:
SYS@enmo2 hey~2->select open_mode,protection_mode,database_role,switchover_status from v$database;
OPEN_MODE
PROTECTION_MODE
DATABASE_ROLE
SWITCHOVER_STATUS
------------------------- -----------------------------
------------------------ ------------------------
READ ONLY WITH APPLY MAXIMUM PERFORMANCE PHYSICAL
STANDBY NOT ALLOWED
備庫應用日誌保持和主庫數據一致(如果不一致,執行如下語句應用日誌)
SYS@enmo2
hey~2->recover managed standby database using current logfile disconnect
from session;
Media recovery complete.
SYS@enmo2
hey~2->recover managed standby database cancel;
Media recovery complete.
主庫切換到備庫角色並查看切換之後的狀態為RECOVERY NEEDED
SYS@enmo1 hey~1->alter database commit to switchover to physical standby with session shutdown;
Database altered.
SYS@enmo1 hey~1->shutdown abort;
ORACLE instance started.
Total System
Global Area 830930944 bytes
Fixed Size 2257800 bytes
Variable Size 700451960 bytes
Database Buffers 121634816 bytes
Redo Buffers 6586368 bytes
Database mounted.
SYS@enmo1 hey~1->select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
RECOVERY NEEDED
切換應用日誌,然後在查看切換狀態為TO primary正常:
SYS@enmo1
hey~1->recover managed standby database using current logfile disconnect
from session;
Media recovery complete.
SYS@enmo1 hey~1->select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO PRIMARY
備庫切主庫:
SYS@enmo2 hey~2->select open_mode,protection_mode,database_role,switchover_status from v$database;
OPEN_MODE
PROTECTION_MODE DATABASE_ROLE SWITCHOVER_STATUS
-------------------- -------------------- ----------------
--------------------
MOUNTED MAXIMUM PERFORMANCE PHYSICAL STANDBY TO PRIMARY
SYS@enmo2 hey~2->alter database commit to switchover to primary with session shutdown;
Database altered.
SYS@enmo2 hey~2->alter database open;
Database altered.
SYS@enmo2 hey~2->select switchover_status,database_role from v$database;
SWITCHOVER_STATUS
DATABASE_ROLE
-------------------- ----------------
FAILED DESTINATION PRIMARY
SYS@enmo2 hey~2->select open_mode,protection_mode,database_role from v$database;
OPEN_MODE
PROTECTION_MODE DATABASE_ROLE
-------------------- -------------------- ----------------
READ WRITE MAXIMUM PERFORMANCE PRIMARY
二、備庫不同步的問題檢查方法
1、檢查主備兩邊的序號
select max(sequence#) from v$log; ---檢查發現一致
2、備庫執行,查看是否有數據未應用
select name,SEQUENCE#,APPLIED from v$archived_log order by sequence#;
select SEQUENCE#,FIRST_TIME,NEXT_TIME ,APPLIED from v$archived_log order by 1;
3、檢查備庫是否開啟實時應用
select recovery_mode from v$archive_dest_status where dest_id=2;
4、檢查備庫狀態
select switchover_status from v$database; --發現狀態not allowed
3、看看進程MRP是否存在
ps aux|grep mrp --發現進程不存在
4、如果不存在執行以下:
alter database recover managed standby database using current logfile
disconnect;
alter database recover managed standby database disconnect from session; --後臺執行
alter database recover managed standby database --前臺執行,執行這個可以看到報錯的情況
如果有報錯,查看alert日誌和log.xml日誌
5、驗證是否正常
select process,status from v$managed_standby;
select process,status,sequence# from v$managed_standby;
如果看到mrp0正常
6、以上步驟處理好後,如果數據還不正常,接著處理
關閉備庫,接著處理:
把主庫上 undotbs01.dbf 文件,物理的重拷到備庫機上以前undotbs01.dbf 所在目錄下;
$scp /data/oracle/oradata/voip/undotbs01.dbf 192.168.122.204:/data/oracle/oradata/voip
再在主庫上重新生成一個standby control file ,拷到備庫機上相應目錄下,
alter database create standby controlfile as '/data/oracle/oradata/voip/qyqdg01.ctl'
$scp
/data/oracle/oradata/voip/qyqdg01.ctl
192.168.122.204:/data/oracle/oradata/voip
$ mv qyqdg01.ctl control01.ctl
$ cp control01.ctl /data/oracle/flash_recovery_area/qyq/
$cd /data/oracle/flash_recovery_area/qyq/
$ mv control01.ctl control02.ctl
接著
STARTUP NOMOUNT;
ALTER DATABASE MOUNT STANDBY DATABASE;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
--------------------------------------
session恢復完成後,重啟打開備庫;
alter database open read only;