Several Methods to view the variation trend of scn headroom, scnheadroom

Source: Internet
Author: User

Several Methods to view the variation trend of scn headroom, scnheadroom
Methods for viewing the variation trend of scn headroom

This article does not explain the scn headroom problem.

This article summarizes the script from the oracle sr technical engineer.

Reprinted please indicate the source http://blog.csdn.net/msdnchina/article/details/38404501


The first method is to query the smon_scn_time table.

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; 


Method 2: Query awr report information:


1. How to extract the historical values of a statistic from AWR Repository (Doc ID 948272.1)
Copy the Script part to the local machine of the two instances in the generated database and name it awr. SQL


The script is:
Set trimspool onset pages 50000 set lines 132 set tab offset feedback offclear 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 specifiedcolumn 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; promptpromptprompt instances IN this workload repository SCHEMAprompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ 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 hostFROM dba_hist_database_instance wr, v $ database cd, v $ instance ci; promptprompt USING & dbid for database id- --- Set up the binds for dbid and instance_numbervariable dbid NUMBER; BEGIN: dbid: = & dbid; END;/-- Error reportingwhenever 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 Da Tabase 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: 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 displayset 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 '; promptpromptprompt specify the number of days OF snapshots TO choose FROMprompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~ Prompt entering the number of days (n) will result IN the most recentprompt (n) days OF snapshots being listed. pressing withoutprompt specifying a number lists all completed snapshots. promptpromptset 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_daysFROM sys. dual; set heading ON; -- List available snapshotsbreak 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, s. snap_id, To_char (s. end_interval_time, 'dd Mon YYYY HH24: Mi ') snapdat, s. snap_level lvlFROM dba_hist_snapshot s, dba_hist_database_instance diWHERE 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 comparedpromptpromptprompt specify the begin and end snapshot idsprompt ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~ Prompt begin snapshot id specified: & amp; end snapshot id specified: & amp; end_snapprompt -- 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 -- promptpromptprompt search statisticprompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ Prompt search by statistics name. pressing withoutprompt 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_searchFROM sys. dual; set heading ON; column stat_id heading "Statistic ID" format 9999999999999; column name heading "Statistic Name" format a64; col Umn 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, NameFROM v $ sysstatWHERE Upper (name) LIKE Trim (Upper ('% & stat_search %') order by class, name/-- Ask for the statisticsvariable stat_filter_id NUMBERvariable stat_filter_name VARCHAR2 (64) promptpromptprompt specify the STATISTICSprompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ Prompt enter STATISTICS id or statistics name. promptBEGIN 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_inputcolumn 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 9 9999; 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_VALUEFROM (SELECT snap_id, dbi D, 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 nation X, dba_hist_snapshot SN, (SELECT instance_number, Min (startup_time) STARTUP_TIME FROM dba_hist_snapshot WHERE snap_id BETWEEN: bid AND: eid GROU 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 dbidundefine num_daysundefine begin_snapundefine end_snapundefine stat_idundefine stat_searchundefine stat_filter_nameundefine stat_filter_idundefine stat_input --- the script ends.



2. Run the script in SQLPLUS and enter




Instances IN this workload repository SCHEMA
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~


DB Id Inst Num DB Name INST_NAME Host
--------------------------------------------------------------------
* 1163866261 1 RBIG5 RBIG5 xxx
M


Enter value for dbid: 1163866261 <=== input instance 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
Specifying a number lists all completed snapshots.




Enter value for num_days: 2 <== Enter AWR Sampling days




Specify the begin and end snapshot ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 1605
Begin snapshot id specified: 1605 <== enter the starting snapshot number based on the Dialog


Enter value for end_snap: 1639
End snapshot id specified: 1639 <== enter the END snapshot number based on the dialog box








Search statistic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Search by statistics name. pressing
Specifying anything show all statistics.
Enter value for stat_search: callto kcmgas <=== Enter the required statistical item: callto kcmgas


Statistic Name Filter: callto kcmgas


Statistic ID Statistic Name
----------------------------------------------------------------------------------------
4072914524 DEBUG callto kcmgas




Specify the STATISTICS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter STATISTICS id or statistics name.


Enter value for stat_input: 4072914524 <=== ID returned by the input statistics






Finally, a list is returned, such


Inst
Snap Id DB Id Num Elapsed Snap Started Stat Value
-----------------------------------------------------------------
1605 1163866261 1 3600 08 Sep 2013 0
1606 1163866261 1 3601 08 Sep 2013 170
1607 1163866261 1 3600 08 Sep 2013 164
...
1626 1163866261 1 3600 08 Sep 2013 155
1627 1163866261 1 3600 08 Sep 2013 165
1628 1163866261 1 3600 08 Sep 2013 2065 "=" if a similar hop occurs, it indicates that the internal transaction of the database changes dramatically, not caused by DBLINK.
...
1636 1163866261 1 3600 09 Sep 2013 145
1637 1163866261 1 3601 09 Sep 2013 174
1638 1163866261 1 3600 09 Sep 2013 156
1639 1163866261 1 3600 09 Sep 2013 142

Please provide your output results as the result of the investigation that the SCN non-External Database DBLINK causes a hop change.



Method 3: query the v $ archived_log view (provided that the archive mode is enabled for the database)
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 ; 





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.