DG维护常用命令---oracle DG dataguard

DG维护常用命令


10g alter日志位置
/opt/app/oracle/admin/moe/bdump
/u01/app/oracle/product/10.2.0/db_1/rdbms/log
11g alter日志位置
cd /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert
/u01/app/oracle/diag/rdbms/orcl/orcl/trace
:可使用show parameter dump查看

standby logfile
主库查看log
SQL> select group#,thread#,bytes/1024/1024 M,status from v$log;
备库查看standby log
SQL> select group#,thread#,bytes/1024/1024 M,status,last_change#,last_time from v$standby_log;
注:备库的standby logfile一般比主库的log多一个(rac的对应的是节点),大小要一样,多出的那个大小和主库最大的log一样。

查看standby启动的DG进程
SQL> select process,client_process,sequence#,status from v$managed_standby;
注:
备库ARCH、MRPO和RFS都有表示正常;
主库没有RFS进程和MRP进程,有ARCH和LNS;

手动启动MRPO进程
alter database recover managed standby database disconnect from session

SQL> select open_mode,current_scn from v$database;

SQL> select * from v$standby_log;

select process,client_process,sequence#,status,BLOCK#,BLOCKS,THREAD# from v$managed_standby;

检查归档日志或dg是否正常
SQL> select GROUP#,DBID,STATUS,LAST_CHANGE#,BYTES,LAST_TIME from v$standby_log;
注:如果主库是rac,其中的status有两个为ACTIVE;LAST_CHANGE#值会增加,不是固定的;

查看最大归档序列号
SQL> select max(sequence#) from v$archived_log;

***开启实时日志应用
SQL> recover managed standby database using current logfile disconnect from session;

SQL> alter database recover managed standby database using current logfile disconnect;
注: using current logfile是一个可选项,选择了就必须要有standby日志;disconnect断开,即从当前的终端断开,在系统后台执行命令。

查询日志应用情况
SQL> select database_role,protection_mode,protection_level,open_mode from v$database;
SQL> select process,client_process,sequence#,status from v$managed_standby;

***停止redo日志应用
SQL> alter database recover managed standby database cancel;

***打开实例
SQL> alter database open read only;
打开到mount状态
SQL> startup mount;

手动归档
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;

select message from v$dataguard_status;

临时断开主库和备库的同步
alter system set log_archive_dest_state_2=DEFER;
打开主库和备库的同步
alter system set log_archive_dest_state_2 = ENABLE;

select sequence#,applied from v$archived_log;

主、备库查看当前日志状况
select sequence#,status from v$log;

备库执行,查看是否有数据未应用
select name,SEQUENCE#,APPLIED from v$archived_log order by sequence#;
select SEQUENCE#,FIRST_TIME,NEXT_TIME ,APPLIED from v$archived_log order by 2;

在备库手工注册拷贝过来的的归档日志
alter database register logfile '/opt/oracle/archive_log/1_27293_750772439.log'

standby日志相关
创建standby日志:
SQL> alter database add standby logfile '/oradata/orcl/standby01.log' size 50m;
SQL> alter database add standby logfile '/oradata/orcl/standby02.log' size 50m;
SQL> alter database add standby logfile '/oradata/orcl/standby03.log' size 50m;
SQL> alter database add standby logfile '/oradata/orcl/standby04.log' size 50m;

alter database add standby logfile thread 1 group 10 ('/oradata/xqdb/standby10.log') size 50M;
alter database add standby logfile thread 2 group 14 ('/oradata/xqdb/standby14.log') size 50M;

删除Standby Redo log日志组的语法:
(可以把数据库关闭启动到mount状态在删除以及文件后再添加)
SQL> ALTER DATABASE DROP STANDBY LOGFILE GROUP 4;
查询standby日志:
select group#,thread#,sequence#,archived,status from v$standby_log;

查看DG应用日志是否实时应用(备库查看)
SQL > select  DEST_NAME , STATUS , RECOVERY_MODE from v$archive_dest_status;
注:
recover_mode是 MANAGED REAL TIME APPLY是实时应用;
MANAGED是非实时应用。
如需要开启实时应用日志,停止日志应用
SQL> alter database recover managed standby database cancel;
再启动日志应用就好
SQL> alter database recover managed standby database using current logfile disconnect;
参数:using current logfile
在11g中,如要使用real time apply(实时应用),需要加using current logfile;
在12c中,如果要不使用real time apply,需要加using archived log,using current logfile已经过期作废。
不带using语句,在11g中,默认是不使用real time apply,而在12c中是默认使用real time apply。

 

 

查看主库是否传送日志,可以在主库的alter日志是否有LAN:这个选项

 

 

其他:
SELECT THREAD#, MAX(SEQUENCE#) AS "LAST_APPLIED_LOG" FROM V$LOG_HISTORY GROUP BY THREAD#;

SELECT LOCAL.THREAD#, LOCAL.SEQUENCE# FROM (SELECT THREAD#, SEQUENCE# FROM V$ARCHIVED_LOG WHERE DEST_ID=1) LOCAL WHERE LOCAL.SEQUENCE# NOT IN
(SELECT SEQUENCE# FROM V$ARCHIVED_LOG WHERE DEST_ID=2 AND THREAD# = LOCAL.THREAD#);

 

****查看dataguard最新状态****------干货,老司机大方分享出来的多年经验

alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
set line 160
set pagesize 1000
col type for a20

select process, status, thread#,sequence#, block#, blocks from v$managed_standby;

select GROUP#,THREAD#,SEQUENCE#,STATUS,LAST_CHANGE#,LAST_TIME from v$standby_log;

select START_TIME,TYPE, ITEM,UNITS,SOFAR,TIMESTAMP from v$recovery_progress where ITEM='Last Applied Redo';
注:需要备库在real-time apply(实时应用日志)状态下才能查看到



 

 

你可能感兴趣的:(Oracle-RAC&DG)