在Oracle中,欧博abg物理DG维护中常用到的SQL语句有哪些?
♣
答案部分
1.启用日志应用
代码语言:javascript
复制
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
2.启用实时的日志应用
代码语言:javascript
复制
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
DISCONNECT FROM SESSION子句并非必需,该子句的作用是指定启动完应用后自动退出到命令操作符前。如果不指定该子句的话,那么当前SESSION就会一直停留处理Redo应用,如果想做其它操作,那么就只能新建一个连接。
3.停止日志应用服务
代码语言:javascript
复制
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
4.查看DG备机是否启用了日志应用,欧博官网有两种办法可以判断:①可以查看是否有mrp进程,如果看不到mrp进程,那么说明没有启用日志应用。②查看V$ARCHIVE_DEST_STATUS的RECOVERY_MODE列,若启用了实时应用,则在Oracle 11g显示MANAGED REAL TIME APPLY,欧博在Oracle 10g显示MANAGED。
代码语言:javascript
复制
[oracle@dg ~]$ ps -ef|grep ora_mrp oracle 19592 1 0 10:15 ? 00:00:01 ora_mrp0_phydb
5.DG总体情况查询
以下的SQL是一个非常有用的SQL语句,可以查询出当前DG的运行和配置的总体情况:
代码语言:javascript
复制
SET LINE 9999 COL DEST_NAME FORMAT A20 COL DESTINATION FORMAT A15 COL GAP_STATUS FORMAT A10 COL DB_UNIQUE_NAME FORMAT A15 COL ERROR FORMAT A10 COL APPLIED_SCN FOR 999999999999999 SELECT AL.THREAD#, ADS.DEST_ID, ADS.DEST_NAME, (SELECT ADS.TYPE || ' ' || AD.TARGET FROM V$ARCHIVE_DEST AD WHERE AD.DEST_ID = ADS.DEST_ID) TARGET, ADS.DATABASE_MODE, ADS.STATUS, ADS.ERROR, ADS.RECOVERY_MODE, ADS.DB_UNIQUE_NAME, ADS.DESTINATION, ADS.GAP_STATUS, (SELECT MAX(SEQUENCE#) FROM V$LOG NA WHERE NA.THREAD# = AL.THREAD#) CURRENT_SEQ#, MAX(SEQUENCE#) LAST_ARCHIVED, MAX(CASE WHEN AL.APPLIED = 'YES' AND ADS.TYPE <> 'LOCAL' THEN AL.SEQUENCE# END) APPLIED_SEQ#, (SELECT AD.APPLIED_SCN FROM V$ARCHIVE_DEST AD WHERE AD.DEST_ID = ADS.DEST_ID) APPLIED_SCN FROM (SELECT * FROM V$ARCHIVED_LOG V WHERE V.RESETLOGS_CHANGE# = (SELECT D.RESETLOGS_CHANGE# FROM V$DATABASE D)) AL, V$ARCHIVE_DEST_STATUS ADS WHERE AL.DEST_ID(+) = ADS.DEST_ID AND ADS.STATUS != 'INACTIVE' GROUP BY AL.THREAD#, ADS.DEST_ID, ADS.DEST_NAME, ADS.STATUS, ADS.ERROR, ADS.TYPE, ADS.DATABASE_MODE, ADS.RECOVERY_MODE, ADS.DB_UNIQUE_NAME, ADS.DESTINATION, ADS.GAP_STATUS ORDER BY ADS.DEST_ID,AL.THREAD#;
如下是一个运行结果截图,由于太长,作者分割成了2块图,可以看到主库和备库都是RAC环境,欧博娱乐RAC1当前的日志号为26,DG应用到了25,而RAC2当前的日志号为16,DG应用到了14号日志,备库的模式都是实时应用模式(MANAGED REAL TIME APPLY),说明当前的RAC和DG环境是正常的环境。
6.日志应用情况
检查是否存在GAP的SQL语句:
代码语言:javascript
复制
SELECT THREAD#,LOW_SEQUENCE#,HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;
物理DG日志应用情况:
代码语言:javascript
复制
COL NAME FOR A100 SET LINESIZE 9999 PAGESIZE 9999 COL NEXT_CHANGE# FOR 999999999999999 SELECT THREAD#, NAME, SEQUENCE#, ARCHIVED, APPLIED, A.NEXT_CHANGE# FROM V$ARCHIVED_LOG A WHERE A.SEQUENCE# >= (SELECT MAX(B.SEQUENCE#) - 3 FROM V$ARCHIVED_LOG B WHERE B.THREAD# = A.THREAD# AND B.RESETLOGS_CHANGE# = A.RESETLOGS_CHANGE# AND B.RESETLOGS_CHANGE# = (SELECT D.RESETLOGS_CHANGE# FROM V$DATABASE D) AND B.APPLIED = 'YES' GROUP BY B.THREAD#) ORDER BY A.THREAD#, A.SEQUENCE#;
假设有如下的结果:
代码语言:javascript
复制
THREAD# NAME SEQUENCE# ARC APPLIED NEXT_CHANGE# ---------- ----------------------------- ---------- --- --------- ---------------- 1 /arch/1_121_916055651.dbf 121 YES YES 5792359 1 /arch/1_122_916055651.dbf 122 YES YES 5799614 1 /arch/1_123_916055651.dbf 123 YES NO 5839995 2 /arch/2_94_916055651.dbf 94 YES YES 5782610 2 /arch/2_95_916055651.dbf 95 YES YES 5799607 2 /arch/2_96_916055651.dbf 96 YES YES 5839974
可以看出,实例1日志应用到了123号,而实例2日志应用到了96号。
7.物理备库进程信息
代码语言:javascript
复制
COL GROUP_# FORMAT A5 COL CLIENT_PID FORMAT A8 SET LINE 9999 PAGESIZE 9999 SELECT A.INST_ID, A.PROCESS, A.CLIENT_PROCESS, A.CLIENT_PID, A.STATUS, A.GROUP# GROUP_#, A.THREAD#, A.SEQUENCE#, A.DELAY_MINS, A.RESETLOG_ID, C.SID, C.SERIAL#, A.PID SPID, B.PNAME FROM GV$MANAGED_STANDBY A, GV$PROCESS B, GV$SESSION C WHERE A.PID = B.SPID AND B.ADDR = C.PADDR AND A.INST_ID = B.INST_ID AND B.INST_ID = C.INST_ID ORDER BY A.INST_ID,B.PNAME;
① PROCESS:进程名称,如ARCH、RFS、MRP0等
② CLIENT_PID:在备库查询时对应的Primary数据库中的进程,如ARCH、LGWR等,在主库查询时就是后台进程
③ SEQUENCE#:归档序号
④ STATUS:进程的当前状态,值较多,常见的有:
l ALLOCATED:正准备连接Primary数据库
l ATTACHED:正在连接Primary数据库
l CONNECTED:已连接至Primary数据库
l IDLE:空闲中
l RECEIVING:归档文件接收中
l OPENING:归档文件处理中
l CLOSING:归档文件处理完,收尾中
l WRITING:Redo数据库写向归档文件中
l WAIT_FOR_LOG:等待新的Redo数据中
l WAIT_FOR_GAP:归档有中断,正等待中断的那部分Redo数据
l APPLYING_LOG:应用Redo数据中
8.手动注册日志
如果有日志文件未被传输或未被注册到备库,那么可以使用如下命令手工注册到备库。下面的SQL语句可以生成物理和逻辑DG注册的SQL语句,日志号从1980到2000:
代码语言:javascript
复制
SELECT 'alter database register or replace logical logfile ''/arch/log_1_' || A || ' _666200636.arc'';' LOGICAL_DG, 'alter database register or replace logfile ''/arch/log_1_' || A || ' _666200636.arc'';' PHYSICAL_DG FROM (SELECT LEVEL A FROM DUAL CONNECT BY LEVEL <= 2000) WHERE A >= 1980;