查看scn headroom变化趋势的几种方法



scn headroom问题,本文不做解释。

本文为自己的总结,脚本来自于oracle sr技术project师。

转载请注明出处http://blog.csdn.net/msdnchina/article/details/38404501

第一个方法:查询smon_scn_time表获得。

conn / as sysdba
set numwidth 17
set pages 1000
alter session set nls_date_format='DD/Mon/YYYY HH24:MI:SS';
with t1 as(
select time_dp , 24*60*60*(time_dp - lag(time_dp) over (order by time_dp)) timediff,
scn - lag(scn) over(order by time_dp) scndiff
from smon_scn_time
)
select time_dp , timediff, scndiff,
trunc(scndiff/timediff) rate_per_sec
from t1
order by 1;

第二个方法:查询awr报告的信息:





1. 通过How to extract the historical values of a statistic from AWR Repository (Doc ID 948272.1) 

将Script 部分拷贝到您生成数据库两个实例本地,命名为 比如 awr.sql 





该脚本为:

set trimspool on
set pages 50000
set lines 132
set tab off
set feedback off clear break compute;
repfooter off;
ttitle off;
btitle off;
set timing off veri off space 1 flush on pause off termout on numwidth 10;
set echo off feedback off pagesize 50000 linesize 1000 newpage 1 recsep off;
set trimspool on trimout on; --
-- Request the DB Id and Instance Number, if they are not specified column instt_num heading "Inst Num" format 99999;
column instt_name heading "Instance" format a12;
column dbb_name heading "DB Name" format a12;
column dbbid heading "DB Id" format a12 just c;
column host heading "Host" format a20; prompt
prompt
prompt instances IN this workload repository SCHEMA
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SELECT DISTINCT ( CASE
WHEN cd.dbid = wr.dbid
AND cd.name = wr.db_name
AND ci.instance_number = wr.instance_number
AND ci.instance_name = wr.instance_name THEN '* '
ELSE ' '
END )
|| wr.dbid dbbid,
wr.instance_number instt_num,
wr.db_name dbb_name,
wr.instance_name inst_name,
wr.host_name host
FROM dba_hist_database_instance wr,
v$database cd,
v$instance ci; prompt
prompt USING &&dbid FOR DATABASE id
--
-- Set up the binds for dbid and instance_number
variable dbid NUMBER;
BEGIN
:dbid := &dbid;
END;
/
-- Error reporting
whenever SQLERROR EXIT;
variable max_snap_time CHAR(10);
DECLARE
CURSOR cidnum IS
SELECT 'X'
FROM dba_hist_database_instance
WHERE dbid = :dbid;
CURSOR csnapid IS
SELECT To_char(Max(end_interval_time), 'dd/mm/yyyy')
FROM dba_hist_snapshot
WHERE dbid = :dbid;
vx CHAR(1);
BEGIN
-- Check Database Id/Instance Number is a valid pair
OPEN cidnum; FETCH cidnum INTO vx; IF cidnum%NOTFOUND THEN
Raise_application_error(-20200, 'Database/Instance '
|| :dbid
|| '/'
||
' does not exist in DBA_HIST_DATABASE_INSTANCE');
END IF; CLOSE cidnum; -- Check Snapshots exist for Database Id/Instance Number
OPEN csnapid; FETCH csnapid INTO :max_snap_time; IF csnapid%NOTFOUND THEN
Raise_application_error(-20200,
'No snapshots exist for Database/Instance '
||:dbid
||'/');
END IF; CLOSE csnapid;
END;
/ whenever SQLERROR CONTINUE;
--
-- Ask how many days of snapshots to display
set termout ON;
column instart_fmt noprint;
column inst_name format a12 heading 'Instance';
column db_name format a12 heading 'DB Name';
column snap_id format 99999990 heading 'Snap Id';
column snapdat format a18 heading 'Snap Started' just c;
column lvl format 99 heading 'Snap|Level';
prompt
prompt
prompt specify the NUMBER OF days OF snapshots TO choose FROM
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prompt entering the NUMBER OF days (n) will result IN the most recent
prompt (n) days OF snapshots being listed. pressing without
prompt specifying a NUMBER LISTS ALL completed snapshots.
prompt
prompt
set heading OFF;
column num_days new_value num_days noprint;
SELECT 'Listing '
|| Decode(Nvl('&&num_days', 3.14), 0, 'no snapshots',
3.14, 'all Completed Snapshots',
1,
'the last day''s Completed Snapshots',
'the last &num_days days of Completed Snapshots'
),
Nvl('&&num_days', 3.14) num_days
FROM sys.dual; set heading ON;
--
-- List available snapshots
break ON inst_name ON db_name ON host ON instart_fmt skip 1;
ttitle OFF;
SELECT To_char(s.startup_time, 'dd Mon "at" HH24:mi:ss') instart_fmt,
di.instance_name inst_name,
di.db_name db_name,
s.snap_id snap_id,
To_char(s.end_interval_time, 'dd Mon YYYY HH24:mi') snapdat,
s.snap_level lvl
FROM dba_hist_snapshot s,
dba_hist_database_instance di
WHERE s.dbid = :dbid
AND di.dbid = :dbid
AND di.dbid = s.dbid
AND di.instance_number = s.instance_number
AND di.startup_time = s.startup_time
AND s.end_interval_time >= Decode(&num_days, 0, To_date('31-JAN-9999',
'DD-MON-YYYY'
),
3.14, s.end_interval_time,
To_date(:max_snap_time,
'dd/mm/yyyy')
- ( &num_days - 1 ))
ORDER BY db_name,
instance_name,
snap_id; clear break;
ttitle OFF;
--
-- Ask for the snapshots Id's which are to be compared
prompt
prompt
prompt specify the BEGIN AND END SNAPSHOT ids
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prompt BEGIN SNAPSHOT id specified: &&begin_snap
prompt
prompt END SNAPSHOT id specified: &&end_snap
prompt
--
-- Set up the snapshot-related binds
--
variable bid NUMBER;
variable eid NUMBER;
BEGIN
:bid := &begin_snap; :eid := &end_snap;
END;
/ prompt
--
-- Ask for Statistics Name Filter
--
prompt
prompt
prompt search statistic
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prompt search BY STATISTICS name. pressing without
prompt specifying anything show ALL STATISTICS.
set heading OFF;
column stat_search new_value stat_search noprint;
SELECT 'Statistic Name Filter: '
|| Nvl('&&stat_search', '%'),
Nvl('&&stat_search', '%') stat_search
FROM sys.dual; set heading ON;
column stat_id heading "Statistic ID" format 9999999999999;
column name heading "Statistic Name" format a64;
column class_name heading "Statistic Class" format a10;
SELECT stat_id,
( CASE
WHEN class = 1 THEN 'USER'
WHEN class = 2 THEN 'REDO'
WHEN class = 4 THEN 'ENQUEUE'
WHEN class = 8 THEN 'CACHE'
WHEN class = 16 THEN 'OS'
WHEN class = 32 THEN 'RAC'
WHEN class = 40 THEN 'RAC-CACHE'
WHEN class = 64 THEN 'SQL'
WHEN class = 72 THEN 'SQL-CACHE'
WHEN class = 128 THEN 'DEBUG'
ELSE To_char(class)
END ) CLASS_NAME,
name
FROM v$sysstat
WHERE Upper(name) LIKE Trim(Upper('%&stat_search%'))
ORDER BY class,
name
/ --
-- Ask for the statistics
variable stat_filter_id NUMBER
variable stat_filter_name VARCHAR2(64)
prompt
prompt
prompt specify the STATISTICS
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prompt enter STATISTICS id OR STATISTICS name.
prompt
BEGIN
SELECT To_number('&&stat_input')
INTO :stat_filter_id
FROM dual;
EXCEPTION
WHEN invalid_number THEN
:stat_filter_name := '&stat_input';
END;
/ prompt STATISTICS specified : &&stat_input
column end_interval_time heading 'Snap Started' format a18 just c;
column dbid heading 'DB Id' format a12 just c;
column instance_number heading 'Inst|Num' format 99999;
column elapsed heading 'Elapsed' format 999999;
column stat_value heading 'Stat Value' format 999999999999
column stat_name heading 'Stat Name' format a64 just l;
SELECT snap_id,
To_char(dbid) DBID,
instance_number,
elapsed,
To_char(end_interval_time, 'dd Mon YYYY HH24:mi') END_INTERVAL_TIME,
--stat_name,
( CASE
WHEN stat_value > 0 THEN stat_value
ELSE 0
END ) STAT_VALUE
FROM (SELECT snap_id,
dbid,
instance_number,
elapsed,
end_interval_time,
stat_name,
( stat_value - Lag (stat_value, 1, stat_value)
over (
PARTITION BY dbid, instance_number
ORDER BY snap_id) ) AS STAT_VALUE
FROM (SELECT snap_id,
dbid,
instance_number,
elapsed,
end_interval_time,
stat_name,
SUM(stat_value) AS STAT_VALUE
FROM (SELECT X.snap_id,
X.dbid,
X.instance_number,
Trunc(SN.end_interval_time, 'mi')
END_INTERVAL_TIME,
X.stat_name,
Trunc(( Cast(SN.end_interval_time AS DATE) -
Cast(SN.begin_interval_time AS DATE) ) *
86400) ELAPSED,
( CASE
WHEN ( X.stat_name = :stat_filter_name
OR X.stat_id = :stat_filter_id ) THEN
X.value
ELSE 0
END ) AS STAT_VALUE
FROM dba_hist_sysstat X,
dba_hist_snapshot SN,
(SELECT instance_number,
Min(startup_time) STARTUP_TIME
FROM dba_hist_snapshot
WHERE snap_id BETWEEN :bid AND :eid
GROUP BY instance_number) MS
WHERE X.snap_id = sn.snap_id
AND X.dbid = sn.dbid
AND x.dbid = :dbid
AND x.snap_id BETWEEN :bid AND :eid
AND SN.startup_time = MS.startup_time
AND SN.instance_number = MS.instance_number
AND X.instance_number = sn.instance_number
AND ( X.stat_name = :stat_filter_name
OR X.stat_id = :stat_filter_id ))
GROUP BY snap_id,
dbid,
instance_number,
elapsed,
end_interval_time,
stat_name)); undefine dbid
undefine num_days
undefine begin_snap
undefine end_snap
undefine stat_id
undefine stat_search
undefine stat_filter_name
undefine stat_filter_id
undefine stat_input ---该脚本结束。

2. 在SQLPLUS中执行该脚本。并依据您系统实际情况输入 









instances IN this workload repository SCHEMA 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 





DB Id Inst Num DB Name INST_NAME Host 

------------ -------- ------------ ---------------- -------------------- 

* 1163866261 1 RBIG5 RBIG5 xxx 







Enter value for dbid: 1163866261 《=====输入实例ID 

USING 1163866261 FOR DATABASE id 









specify the NUMBER OF days OF snapshots TO choose FROM 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

entering the NUMBER OF days (n) will result IN the most recent 

(n) days OF snapshots being listed. pressing without 

specifying a NUMBER LISTS ALL completed snapshots. 









Enter value for num_days: 2 <===输入AWR採样天数 









specify the BEGIN AND END SNAPSHOT ids 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

Enter value for begin_snap: 1605 

BEGIN SNAPSHOT id specified: 1605 《===依据对话输入起始snapshot 序号 





Enter value for end_snap: 1639 

END SNAPSHOT id specified: 1639《===依据对话输入结束snapshot 序号 

















search statistic 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

search BY STATISTICS name. pressing without 

specifying anything show ALL STATISTICS. 

Enter value for stat_search: calls to kcmgas 《======输入须要显示的统计项: calls to kcmgas 





Statistic Name Filter: calls to kcmgas 





Statistic ID Statistic Statistic Name 

-------------- ---------- ---------------------------------------------------------------- 

4072914524 DEBUG calls to kcmgas 









specify the STATISTICS 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

enter STATISTICS id OR STATISTICS name. 





Enter value for stat_input: 4072914524 《======输入统计项返回的ID 













最后,将返回一个列表,比如 





Inst 

Snap Id DB Id Num Elapsed Snap Started Stat Value 

--------- ------------ ------ ------- ------------------ ------------- 

1605 1163866261 1 3600 08 Sep 2013 00:00 0 

1606 1163866261 1 3601 08 Sep 2013 01:00 170 

1607 1163866261 1 3600 08 Sep 2013 02:00 164 

。。。 

1626 1163866261 1 3600 08 Sep 2013 21:00 155 

1627 1163866261 1 3600 08 Sep 2013 22:00 165 

1628 1163866261 1 3600 08 Sep 2013 23:00 2065《===假设有类似跳变发生,则表示数据库内部交易产生的剧烈变化。非DBLINK造成。 

。。

1636 1163866261 1 3600 09 Sep 2013 07:00 145 

1637 1163866261 1 3601 09 Sep 2013 08:00 174 

1638 1163866261 1 3600 09 Sep 2013 09:00 156 

1639 1163866261 1 3600 09 Sep 2013 10:00 142 



请提供您的输出结果来作为SCN 非外部数据库DBLINK造成跳变的调查结果。 







第三个方法:查询v$archived_log视图(前提是数据库开启归档模式)

set numwidth 17
set pages 1000
alter session set nls_date_format='DD/Mon/YYYY HH24:MI:SS';
SELECT tim, gscn,
round(rate),
round((chk16kscn - gscn)/24/3600/16/1024,1) "Headroom"
FROM
(
select tim, gscn, rate,
((
((to_number(to_char(tim,'YYYY'))-1988)*12*31*24*60*60) +
((to_number(to_char(tim,'MM'))-1)*31*24*60*60) +
(((to_number(to_char(tim,'DD'))-1))*24*60*60) +
(to_number(to_char(tim,'HH24'))*60*60) +
(to_number(to_char(tim,'MI'))*60) +
(to_number(to_char(tim,'SS')))
) * (16*1024)) chk16kscn
from
(
select FIRST_TIME tim , FIRST_CHANGE# gscn,
((NEXT_CHANGE#-FIRST_CHANGE#)/
((NEXT_TIME-FIRST_TIME)*24*60*60)) rate
from v$archived_log
where (next_time > first_time)
)
)
order by 1,2
;

查看scn headroom变化趋势的几种方法的更多相关文章

  1. 【MySQL】锁——查看当前数据库锁请求的三种方法 20

    MySQL提供了查看当前数据库锁请求的三种方法:1. show  full  processlist命令  观察state和info列 2. show engine  innodb status\G ...

  2. 查看Linux系统版本信息的几种方法

    一.查看Linux内核版本命令(两种方法): 1.cat /proc/version 2.uname -a 二.查看Linux系统版本的命令(3种方法): 1.lsb_release -a,即可列出所 ...

  3. 查看sql server数据库连接数的三种方法

    怎样才能查看sql server数据库连接数呢?下面就将为您介绍三种查看的方法,供您参考,希望能够帮助到您. 1.通过系统的“性能”来查看:开始->管理工具->性能(或者是运行里面输入 m ...

  4. 百度经验:Win10查看已存储WiFi密码的两种方法

    方法一:网络和共享中心查询 具体步骤可以参考:Win10查看WIFI密码的方法 方法二:命令提示符查询 1.右键单击开始按钮,选择“命令提示符(管理员)” 2.输入如下命令(下图①号命令): nets ...

  5. Oracle SQL Developer中查看解释计划Explain Plan的两种方法

    方法一: 比如要查看解释计划的SQL是:select * from hy_emp 那么在输入窗口输入: EXPLAIN PLAN FOR select * from hy_emp 之后执行,输出窗口会 ...

  6. Linux/Centos查看进程占用内存大小的几种方法总结

    1.命令行输入top回车,然后按下大写M按照memory排序,按下大写P按照CPU排序. 2. ps -ef | grep "进程名"     ps -e -o 'pid,comm ...

  7. 使用Idea当中的快捷键快速查看继承关系或其图表的两种方法

    一.Idea当中有两种方法可以查看继承关系 在Idea当中选中一个类,然后按Ctrl+H,可以快速查看当前所选类的继承关系,如下图: ​ 同样选中一个类,按CTRL+ALT+U,即可生成当前类的继承关 ...

  8. 三种方法查看MySQL数据库的版本

    1.使用-V参数 首先我们想到的肯定就是查看版本号的参数命令,参数为-V(大写字母)或者--version 使用方法: D:\xampp\mysql\bin>mysql -V 或者 D:\xam ...

  9. C#代码像QQ的右下角消息框一样,无论现在用户的焦点在哪个窗口,消息框弹出后都不影响焦点的变化,那么有两种方法

    你QQ的右下角消息框一样,无论现在用户的焦点在哪个窗口,消息框弹出后都不影响焦点的变化,那么有两种方法: 要么重写需要弹出的窗体的事件: protected override CreateParams ...

随机推荐

  1. [转]Linux 正则表达式详解

    转自:http://www.jb51.net/article/42989.htm 一.linux文本查找命令 在说linux正规表达式之前,还介绍下linux中查找文本文件常用的三个命令: 1.gre ...

  2. Laravel5.1学习笔记20 EloquentORM 关系

    Eloquent: Relationships Introduction Defining Relationships One To One One To Many Many To Many Has ...

  3. viewpager无线轮播获取网络图片

    首先创建小圆点 小圆点的两个属性一共两个属性另一个跟这个一个样,只不过颜色能让我们区分的 <?xml version="1.0" encoding="utf-8&q ...

  4. mac中显示隐藏文件和.开头的文件

    在控制台中执行一下命令,即可在finder中看到此类文件: defaults write com.apple.Finder AppleShowAllFiles YES killall Finder

  5. MySQL主从备份配置

    MySQL主从热备配置 两台服务器的MySQL版本都是5.5.41master:192.168.3.119slave:192.168.3.120 MySQL主服务器配置:1.创建用于备份的用户 gra ...

  6. mysql_数据查询_单表查询

    1.单表查询: 1.1选中表中若干列: SELECT子句的<目标列表达式>可以是表中属性列,也可以是表达式,还可以是字符常量. SELECT Sname,'year of birth:', ...

  7. makefile 与 make

    所要完成的Makefile 文件描述了整个工程的编译.连接等规则.其中包括:工程中的哪些源文件需要编译以及如何编译.需要创建那些库文件以及如何创建这些库文件.如何最后产生我们想要的可执行文件.尽管看起 ...

  8. CorelDRAW快速制作抖音幻影图像效果

    本教程讲解非常受欢迎的幻影图像效果(Anaglyph 3d),也叫图像分色立体效果,这其中我们要用到CorelDRAW中的透明度工具. 在开始实施Anaglyph效应之前,应当知道,Anaglyph  ...

  9. 黑苹果开启retina,大分辨率的方法

    首先,管理分辨率RDM的软件这里下载: http://pan.baidu.com/s/1bpjL07P 在终端输入: curl -o ~/enable-HiDPI.sh https://raw.git ...

  10. Appium 教您完美win10安装Appium1.7.2支持win客户端自动化

    参考内容: https://testerhome.com/topics/10193https://testerhome.com/topics/8223https://testerhome.com/to ...