주로 쓰이는 옵션들..


[root@rac1 lib]# $GRID_HOME/crs/install/rootcrs.sh -help

rootcrs.sh  [-verbose] [-upgrade ]

             [-paramfile <parameter_file>]

             [-deconfig [-deinstall] [-keepdg] [-lastnode] | -downgrade [-ocrbackupfile <OCR_backup_file>] [-online]] [-force]

             [-unlock | -lock [-crshome <path_to_CRS_home>]]

             [-prepatch [-cleanpids] | -postpatch [-norestart] [-nonrolling] [-rollback]] [-dstcrshome <destination_patch_home>]

             [-join -existingnode <node_name>]

             [-move -dstcrshome <path to CRS home>]

             [-init] [-first -force] [-cleansockets]

  Options:

 -verbose    

 Run this script in verbose mode.

 -upgrade

 Oracle HA is being upgraded from previous version.

 -lock     

 Lock CRS home.

 -paramfile 

 Complete path of file specifying HA parameter values

 -lastnode   

 Force the node this is executing on to be considered the last node of the deconfiguration and  

 perform actions associated with deconfiguring the last node.

 -downgrade 

 Downgrade Oracle Clusterware.

 -deconfig   

 Remove Oracle Clusterware to allow it to be uninstalled or reinstalled.

 -deinstall 

 Reset the permissions on CRS home during deconfiguration.

 -keepdg     

 Keep existing diskgroups during deconfiguration.

 -force     

 Force the execution of steps in install or delete that cannot be verified to be safe.

 -unlock     

 Unlock CRS home.

 -crshome   

 Complete path of CRS home.

 -prepatch   

 Perform required steps before the Oracle patching tool (Opatch) is invoked.

 -cleanpids 

 Terminate Oracle Clusterware active processes. Must use with -prepatch option.

 -postpatch 

 Perform required steps after the Oracle patching tool (Opatch) is invoked.

 -nonrolling

 Perform steps for -prepatch and -postpatch in a non-rolling fashion.

 -norestart 

 Leave Oracle Clusterware stack stack down after patching.

 -rollback 

 Perform steps specific to rollback for -prepatch and -postpatch.

 -dstcrshome

 Complete path of CRS home for out-of-place patching only

 -join     

 Add the local node to an upgraded cluster.

 -existingnode

 An already upgraded cluster node. Must use with join option.

 -init       

 Reset the permissions of all files and directories under CRS home.

 -ocrbackupfile

 Restore OCR with the given OCR backup file.

 -first -force     

 Force a node other than the installer node as the first node, during install or upgrade.

 Must  use  with -force option.

 -cleansockets

 Remove socket files created by the Grid Infrastructure processes. Stop the GI stack if not

 already stopped (Option specific to Unix platform only).

 -online     

 Downgrade the cluster without bringing the stack down on all nodes. Must be used with -

 downgrade option.

 -converttoextended

 Convert the cluster to an extended cluster.

 -first -sites   

 List of sites to add to the cluster configuration on the first node.

 -site       

 The site the local node is associated with.

 -move     

 Change the Oracle Grid Infrastructure home path. The new home location is specified by

 the - dstcrshome option.

 

 

Posted by pat98

controlfile에서 백업정보 삭제하는 방법


dbms_backup_restore.resetcfilesection procdure 관련 Type별 값 조회 

============================================================

버전별로 살짝 틀림.


11.2.0.4 의 경우


set lines 120

col type for A25

select rownum,t.* from v$controlfile_record_section t;


해서 나온 결과로 지우고자 하는 항목 확인!!



    ROWNUM TYPE                           RECORD_SIZE RECORDS_TOTAL RECORDS_USED FIRST_INDEX LAST_INDEX LAST_RECID

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

         1 DATABASE                               316             1            1           0          0          0

         2 CKPT PROGRESS                         8180            11            0           0          0          0

         3 REDO THREAD                            256             8            1           0          0          0

         4 REDO LOG                                72            16            7           0          0         60

         5 DATAFILE                               520           100            6           0          0        326

         6 FILENAME                               524          2298           15           0          0          0

         7 TABLESPACE                              68           100            7           0          0         21

         8 TEMPORARY FILENAME                      56           100            1           0          0        364

         9 RMAN CONFIGURATION                    1108            50            0           0          0          0

        10 LOG HISTORY                             56           292          292          20         19        311

        11 OFFLINE RANGE                          200           163            0           0          0          0

        12 ARCHIVED LOG                           584           187          187          29         28        430

        13 BACKUP SET                              40           409            0           0          0          0

        14 BACKUP PIECE                           736           200            0           0          0          0

        15 BACKUP DATAFILE                        200           245            0           0          0          0

        16 BACKUP REDOLOG                          76           215            0           0          0          0

        17 DATAFILE COPY                          736           200            9           1          9          9

        18 BACKUP CORRUPTION                       44           371            0           0          0          0

        19 COPY CORRUPTION                         40           409            0           0          0          0

        20 DELETED OBJECT                          20           818          190           1        190        190

        21 PROXY COPY                             928           246            0           0          0          0

        22 BACKUP SPFILE                          124           131            0           0          0          0

        23 DATABASE INCARNATION                    56           292            1           1          1          1

        24 FLASHBACK LOG                           84          2048            0           0          0          0

        25 RECOVERY DESTINATION                   180             1            0           0          0          0

        26 INSTANCE SPACE RESERVATION              28          1055            1           0          0          0

        27 REMOVABLE RECOVERY FILES                32          1000            0           0          0          0

        28 RMAN STATUS                            116           141           65           1         65         65

        29 THREAD INSTANCE NAME MAPPING            80             8            8           0          0          0

        30 MTTR                                   100             8            1           0          0          0

        31 DATAFILE HISTORY                       568            57            0           0          0          0

        32 STANDBY DATABASE MATRIX                400            31           31           0          0          0

        33 GUARANTEED RESTORE POINT               212          2048            0           0          0          0

        34 RESTORE POINT                          212          2083            0           0          0          0

        35 DATABASE BLOCK CORRUPTION               80          8384            0           0          0          0

        36 ACM OPERATION                          104            64            6           0          0          0

        37 FOREIGN ARCHIVED LOG                   604          1002            0           0          0          0


해당되는 NUMBER 를 넣어서 삭제


SQL>exec dbms_backup_restore.resetcfilesection(12);

SQL>exec dbms_backup_restore.resetcfilesection(13);

SQL>exec dbms_backup_restore.resetcfilesection(14);

SQL>exec dbms_backup_restore.resetcfilesection(21);



================================================================

12.2.0.1 의 경우 (37번 이후로 몇개 더 생김)


set lines 120

col type for A25

select rownum,t.* from v$controlfile_record_section t;


    ROWNUM TYPE                      RECORD_SIZE RECORDS_TOTAL RECORDS_USED FIRST_INDEX LAST_INDEX LAST_RECID     CON_ID

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

         1 DATABASE                          316             1            1           0          0          0          0

         2 CKPT PROGRESS                    8180            35            0           0          0          0          0

         3 REDO THREAD                       256            32            2           0          0          2          0

         4 REDO LOG                           72           192            4           0          0          4          0

         5 DATAFILE                          520          1024            5           0          0         20          0

         6 FILENAME                          524          4674           10           0          0          0          0

         7 TABLESPACE                        180          1024            6           0          0          6          0

         8 TEMPORARY FILENAME                 56          1024            1           0          0          1          0

         9 RMAN CONFIGURATION               1108            50            0           0          0          0          0

        10 LOG HISTORY                        56           292            9           1          9          9          0

        11 OFFLINE RANGE                     200          1063            0           0          0          0          0

        12 ARCHIVED LOG                      584            28            0           0          0          0          0

        13 BACKUP SET                         96          1022            0           0          0          0          0

        14 BACKUP PIECE                      780          1006            0           0          0          0          0

        15 BACKUP DATAFILE                   200          1063            0           0          0          0          0

        16 BACKUP REDOLOG                     76           430            0           0          0          0          0

        17 DATAFILE COPY                     736          1000            0           0          0          0          0

        18 BACKUP CORRUPTION                  44          1115            0           0          0          0          0

        19 COPY CORRUPTION                    40          1227            0           0          0          0          0

        20 DELETED OBJECT                     20           818            0           0          0          0          0

        21 PROXY COPY                        928          1004            0           0          0          0          0

        22 BACKUP SPFILE                     124           131            0           0          0          0          0

        23 DATABASE INCARNATION               56           292            1           1          1          1          0

        24 FLASHBACK LOG                      84          2048            0           0          0          0          0

        25 RECOVERY DESTINATION              180             1            0           0          0          0          0

        26 INSTANCE SPACE RESERVATION         28          1055            1           0          0          0          0

        27 REMOVABLE RECOVERY FILES           32          1000            0           0          0          0          0

        28 RMAN STATUS                       116           141            0           0          0          0          0

        29 THREAD INSTANCE NAME MAPPING       80            32           32           0          0          0          0

        30 MTTR                              100            32            2           0          0          0          0

        31 DATAFILE HISTORY                  568            57            0           0          0          0          0

        32 STANDBY DATABASE MATRIX           400           128          128           0          0          0          0

        33 GUARANTEED RESTORE POINT          256          2048            0           0          0          0          0

        34 RESTORE POINT                     256          2108            0           0          0          0          0

        35 DATABASE BLOCK CORRUPTION          80          8384            0           0          0          0          0

        36 ACM OPERATION                     104            64           10           0          0          0          0

        37 FOREIGN ARCHIVED LOG              604          1002            0           0          0          0          0

        38 PDB RECORD                        780            10            0           0          0          0          0

        39 AUXILIARY DATAFILE COPY           584           128            0           0          0          0          0

        40 MULTI INSTANCE REDO APPLY         556             1            0           0          0          0          0

        41 PDBINC RECORD                     144           113            0           0          0          0          0

        42 TABLESPACE KEY HISTORY            108           151            0           0          0          0          0



Posted by pat98

2017. 11. 16. 15:46 오라클

wait event 정보찾기


오라클이 갑자기 느려졌을때 문제의 SQL찾기 


V$SESSION_WAIT 뷰로부터 실시간 Wait Event 정보얻기

======================================================================

select /*+ ordered / distinct /* 속도를 위해 v$sql을 조인할 경우 중복되는 레코드 제거 */

           s.sid SID, s.username, s.program, p.spid "OS-Pid",w.seconds_in_wait as "W_time(Sec)",

          decode(w.wait_time,0,'Wai-ting', 'Waited') Status, w.ename event,

--              p1text || ':' || decode(event,'latch free',p1raw, to_char(p1)) ||','||

--              p2text || ':' || to_char(p2) ||','|| p3text || ':' || to_char(p3) "Additional Info",

           q.sql_text

from ( select a.*, decode(a.event,'latch free', 'latch free (' ||b.name||')', 

                                         'row cache lock', 'row cache lock (' || c.parameter || ')',

                                         'enqueue', 'enqueue ('||chr(bitand(p1, -16777216)/16777215)||

                                                                             chr(bitand(p1,16711680)/65535)||':'||

                                                decode(bitand(p1,65535), 1, 'N', 2, 'SS',3,'SX',4,'S',5,'SSX',6,'X') ||')',

                              a.event ) ename

           from v$session_wait a, v$latchname b, v$rowcache c

         where a.p2 = b.latch#(+) and a.p1 = c.cache#(+) and c.type(+) = 'PARENT'

           and a.event not in ('rdbms ipc message','smon timer','pmon timer','slave wait','pipe get','null event',

                                     'SQL*Net message from client', 'SQL*Net message to client','PX Idle Wait', 

                                      'PX Deq: Execution Msg', 'KXFQ: kxfqdeq - normal deqeue',

                                         'ges remote message', 'wakeup time manager', /* idle event 적절히 수정 */

                                         'lock manager wait for remote message', 'single-task message')

        ) w, v$session s, v$process p, v$sql q

where w.sid = s.sid and s.paddr = p.addr

and s.sql_hash_value = q.hash_value(+) and s.sql_address = q.address(+)

order by w.ename;

=====================================================

Enqueue type별 누적 Wait현황을 확인


select q.ksqsttyp type, q.ksqstget gets, q.ksqstwat waits, round(q.ksqstwat/q.ksqstget,3) waitratio from sys.x$ksqst q

where q.inst_id = userenv('Instance') and q.ksqstget > 0 order by waits desc

/

=====================================================

set timing off

col user format a8

col event format a20 

col sid_serial format a10 

col wait format 99999

col program format a8 trunc

col machine format a8

set linesize 250


col p1_val format a15 heading 'P1'

col p2_val format a15 heading 'P2'

col p3_val format a15 heading 'P3'

prompt Session Informatiln


select /*+ no_merge */ b.username "user", p.spid, a.sid||':'||b.serial# sid_serial, a.event,a.p1text||':'||a.p1 p1_val,

a.p2text||':'||a.p2 p2_val , a.p3text||':'||a.p3 p3_val,

-- a.seconds_in_wait wait,

b.program, b.sql_hash_value

from v$session_wait a, v$session b, v$process p

where a.sid > 6 and a.event not like '%Net%'

and p.ADDR=b.paddr

and a.event not like '%timer%'

and a.event not like '%ipc%'

and a.event not like '%virtual%'

and a.event not like '%slave wait%'

and a.event not like '%wakeup time manager%'

and a.sid = b.sid

order by logon_time

/

Posted by pat98

==================================== 

- 해당기간 모두 조회

 

set markup html on spool on 

 spool session_diag2.html 

 SET echo on 

 select * from gv$active_session_history 

 where SAMPLE_TIME between to_timestamp('27-Apr-15 16:30:00.000000', 'DD-Mon-RR HH24:MI:SS.FF') 

 and to_timestamp('27-Apr-15 18:10:00.000000', 'DD-Mon-RR HH24:MI:SS.FF') 

 order by SAMPLE_TIME ; 

 spool off 

 set markup html off spool on 

====================================

- 시간대내 발생 이벤트


SELECT SAMPLE_TIME,

       SESSION_ID,

       SESSION_SERIAL#,

       USER_ID,

       SQL_ID,

       SQL_PLAN_OPERATION, - 11g 이상

       SQL_PLAN_OPTIONS,   - 11g 이상

       EVENT,

       P1,

       P2,

       P3,

       WAIT_TIME,

       TIME_WAITED

  FROM gv$active_session_history

 WHERE sample_time BETWEEN TO_DATE ('20131217 170000', 'YYYYMMDD HH24MISS')

                       AND TO_DATE ('20131217 171000', 'YYYYMMDD HH24MISS') ;

====================================


- 시간대내 이벤트 빈도 많은 순서로


SELECT USER_ID, SQL_ID, EVENT, COUNT*), SUM(WAIT_TIME), SUM(TIME_WAITED)

  FROM gv$active_session_history

 WHERE sample_time BETWEEN TO_DATE ('20131217 170000', 'YYYYMMDD HH24MISS')

                       AND TO_DATE ('20131217 171000', 'YYYYMMDD HH24MISS') ;

AND SESSION_TYPE < > 'BACKUPGROUD'

GROUP BY USER_ID, SQL_ID, EVENT

ORDER BY COUNT(*) DESC;

====================================


- TOP 5 wait event from v$active_session_history


col WAIT_CLASS FOR A40

col EVENT FOR A40


select * from (

select

WAIT_CLASS ,

EVENT,

count(sample_time) as EST_SECS_IN_WAIT

from v$active_session_history

where sample_time between sysdate - interval '1' hour and sysdate

group by WAIT_CLASS,EVENT

order by count(sample_time) desc

)

where rownum <6;

====================================

- 5분 동안 가장 많은 DB time을 차지한 query


SELECT activity_pct,

  db_time,

  sql_id

  FROM (

  SELECT round(100 * ratio_to_report(count(*)) OVER (), 1) AS activity_pct,

  count(*) AS db_time,

  sql_id

  FROM v$active_session_history

  WHERE sample_time BETWEEN to_timestamp('2016-04-15 10:00:00', 'YYYY-MM-DD HH24:MI:SS')

  AND to_timestamp('2014-04-15 10:05:00', 'YYYY-MM-DD HH24:MI:SS')

  AND sql_id IS NOT NULL

  GROUP BY sql_id

  ORDER BY count(*) DESC

  )

  WHERE rownum <= 10;


====================================

- Top 10 SQL Activity


SELECT trunc(sample_time,'MI'),sql_id,count(sql_id) as TOTAL FROM v$active_session_history WHERE sample_time between sysdate - interval '1' hour and sysdate AND sql_id in (select sql_id from (select SQL_ID, sum(decode(session_state,'WAITING',1,1))  as TOTAL_ACTIVITY

from v$active_session_history WHERE sample_time between sysdate - interval '1' hour and sysdate group by sql_id order by sum(decode(session_state,'WAITING',1,1))   desc) where rownum < 11) group by trunc(sample_time,'MI'),sql_id order by trunc(sample_time,'MI') desc;



Posted by pat98

Oracle 12.2 Response file 없이 silent mode 설치


./runInstaller -silent -debug -force \

FROM_LOCATION=/stage/12.2.0.1.0/database/stage/products.xml \

oracle.install.option=INSTALL_DB_SWONLY \

UNIX_GROUP_NAME=oinstall \

ORACLE_HOME=/u01/app/oracle/product/12.2.0.1 \

ORACLE_HOME_NAME="OraDb122_Home1" \

ORACLE_BASE=/u01/app/oracle \

oracle.install.db.InstallEdition=EE \

oracle.install.db.isCustomInstall=false \

oracle.install.db.DBA_GROUP=dba \

oracle.install.db.OPER_GROUP=dba \

oracle.install.db.OSBACKUPDBA_GROUP=dba \

oracle.install.db.OSDGDBA_GROUP=dba \

oracle.install.db.OSKMDBA_GROUP=dba \

oracle.install.db.OSRACDBA_GROUP=dba \

DECLINE_SECURITY_UPDATES=true

============================================================

Note: Following are new groups introduced in 12.2 oracle.install.db.OSRACDBA_GROUP=dba 

Posted by pat98

2017. 10. 31. 10:32 오라클

Exadata X7-2 발표



금번 10월 Oracle OOW17 에서 Exadata X7-2 가 발표되었습니다.


매번 그렇지만 기존 X6-2 와의 스펙상의 Up 이 있습니다. 빨간색 표시된 부분입니다.


1. CPU     : 24 core (2.1GHz) * 2 , Skylake, cell skylake/core 10core로 변함없음

2. Memory : 384G (default)

3. Network : 25G 지원가능 (client)

4. Flash    : 6.4 T *  4

5. Storage  : 10TB * 12 (7200rpm)   




Posted by pat98

2017. 10. 11. 17:26 오라클

qperf 사용법


linux 6.7 테스트


1. rpm 설치 (server와 client에 모두)


libibverbs-1.1.8-4.el6.x86_64.rpm

librdmacm-1.0.21-0.el6.x86_64.rpm

qperf-0.4.9-1.0.1.el6.x86_64.rpm


2. server에서 (default 로 TCP Port 19765번 listen함)


qperf


3. client 에서


qperf -t 60 --use_bits_per_sec <server hostname or ip address> tcp_bw


tcp_bw:

    bw  =  893 Mb/sec


-> 결과값은 client 에서만 확인 가능함

Posted by pat98

2017. 9. 20. 14:56 오라클

optimizer_adaptive_plans


Recommendations for Adaptive Features in Oracle Database 12c (Adaptive Statistics & 12c SQL Performance) (문서 ID 2187449.1)

자세한 것은 해당문서 참고.


-12.1 default 값

optimizer_adaptive_features=true


12cR1 에서는 optimizer_adaptive_features 파라미터로 옵티마이저 최적화 기능 관리됨. 

(optimizer_adaptive_plans, optimizer_adaptive_statistics 두개의 값이 같이 관리됨, 개별 적용불가)



-12.2 default 값

optimizer_adaptive_plans=true

optimizer_adaptive_statistics=false

 

12cR2 에서는optimizer_adaptive_features 파라미터는 없어지고 대신 optimizer_adaptive_plans  파라미터로 옵티마이저 최적화 기능 관리됨.

(optimizer_adaptive_plans, optimizer_adaptive_statistics 두개의 값을 개별적로 적용 가능) 

 

- Enterprise Edition 만 가능한 기능임

 

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

 

만약 12.1 에서 이 기능을 쓰고 싶다면 2개의 패치를 적용함으로써 12.2 의 이 기능을 활성화 할수 있음.


Patch 22652097 splits the parameter optimizer_adaptive_features into two, as above, and disables adaptive statistics.

Patch 21171382 disables the automatic creation of extended statistics unless the optimizer preference AUTO_STAT_EXTENSIONS is set to ON.


단 22652097 을 적용하면 SQL Plan Directive 가 disable 되기 때문에 한꺼번에 많은 Plan 들이 영향을 받을수 있으므로 반드시 테스트를 거친후에 적용할것을 권고하고 있음.

Posted by pat98

2017. 8. 29. 11:47 오라클

health check


prompt **********************************************************

prompt * Health Checker                                                          *

prompt ********************************************************** 

set feedback off

clear columns;


column timecol new_value today

column spool_extension new_value suffix

select to_char(sysdate,'YYYYMMDD') timecol,

'.txt' spool_extension from sys.dual;


column output new_value inst_name

select value || '_' output

from v$parameter where name = 'instance_name';


set linesize 160

set pages 150

spool health_&&inst_name&&today&&suffix


prompt

prompt *******************************************************

prompt *               host info                             *

prompt *******************************************************

prompt 

col Host format a15

col version for a10

col InstID for 99


select name "DB Name",  instance_number "InstID", instance_name "Inst Name",

      host_name "Host", version "Version", TO_CHAR(startup_time, 'YYYY-MM-DD HH24:MI:SS') "Startup Time",

      parallel "Parallel", log_mode "Log Mode", archiver "Archiver"

from v$instance, v$database

/


prompt

prompt *******************************************************

prompt *               parameter info                        *

prompt *******************************************************

prompt 


col name for a35

col value for a50

select name, value from v$parameter

where name IN ('cpu_count', 'db_name', 'db_block_size','db_cache_size', 'shared_pool_size','large_pool_size', 'java_pool_size', 'log_buffer');


select name, value from v$parameter order by 1;


clear columns;

prompt

prompt *******************************************************

prompt *               Memory Size                           *

prompt *******************************************************


select decode(pool,null,name,pool) as POOL ,trunc(sum(bytes)/1024/1024,1) as MB

from v$sgastat group by decode(pool,null,name,pool) order by 1

/


prompt

prompt *******************************************************

prompt *               version info                          *

prompt *******************************************************

prompt 

col comp_name for a40;

col version for a30;

select * from v$version;

select comp_name, version, status from dba_registry;

clear columns;


prompt 

prompt

prompt


clear columns;

prompt

prompt *******************************************************

prompt *               archived log mode                     *

prompt *******************************************************

prompt 

select name, log_mode from v$database;

archive log list;

 

prompt

prompt *******************************************************

prompt *               HOT BACKUP INFO                       *

prompt *******************************************************

prompt


col tablespace_name for a25

col file_name for a40

col BACKUP_TIME for a30

select /*+ use_nl (a, b) */ file#, tablespace_name, a.status, change#, to_char(TIME, 'YYYY-MM-DD HH24:MI') as BACKUP_TIME 

from v$backup a, dba_data_files b

where a.file#=b.file_id

order by 1, 2, 3;


clear columns;


prompt

prompt *******************************************************

prompt *               Resource Info                         *

prompt *******************************************************

prompt


select RESOURCE_NAME "Resource Name",

       CURRENT_UTILIZATION "Current Util",

       MAX_UTILIZATION "Max Util",

       INITIAL_ALLOCATION "Initial Alloc",

       LIMIT_VALUE "Limit"

from v$resource_limit

/


clear columns;



prompt *******************************************************

prompt *               Library Cache Hit Ratio (Namespace)   *

prompt *******************************************************

prompt

col "Gets" for 999,999,999,999

col "Pins" for 999,999,999,999

select namespace "Namespace",

 gets "Gets",  round(gethitratio*100,3) "GetHit Ratio",

 pins "Pins",  round(pinhitratio*100,3) "PinHit Ratio",

 invalidations "Invalidations",

 decode(pins,0,0,round((1-reloads/pins)*100, 3)) "Hit Ratio(Pins-Reloads)"

from v$librarycache

/


clear columns;


prompt

prompt *******************************************************

prompt *            DATA  DICTIONARY CACHE TUNING            *

prompt *******************************************************

prompt

select to_char(sysdate,'yyyy/mm/dd hh24:mi:ss') "Time", 

        trunc(sum(getmisses)/sum(gets)*100, 5)||'%  (less than 9.8%)' 

"Data dictionary miss ratio "

from v$rowcache

/


prompt

prompt *******************************************************

prompt *            Dictionary Cache Hit Ratio (Parameter)   *

prompt *******************************************************

prompt

SELECT parameter "Parameter",

         sum(gets) "Gets",

         sum(getmisses) "GetMisses" ,

         decode(sum(gets), 0, 0, round((1-sum(getmisses)/sum(gets))*100, 3)) "Hit Ratio"

FROM v$rowcache

GROUP BY parameter

/


prompt

prompt *******************************************************

prompt *               Shared Pool Free Space                *

prompt *******************************************************

prompt 

col "Shared Pool Reserved(MB)" format a40


select   s.total "Shared Pool Total(MB)",

         s.free - r.r_free "Shared Pool Free(MB)",

         'Free : ' || r.r_free || ',      Used : ' ||r.r_used "Shared Pool Reserved(MB)",

         s.other - r.r_used   "Shared Pool Other(MB)"

         from (select round(sum(bytes/1024/1024),2) total,

         round(sum(decode(name, 'free memory', bytes))/1024/1024,2) free,

         round(sum(decode(name, 'free memory',null, bytes))/1024/1024,2) other

         from   v$sgastat

         where  pool = 'shared pool' ) s,

         (select round(nvl(sum(free_space),0)/1024/1024,2) r_free,

         round(nvl(sum(used_space),0)/1024/1024,2) r_used

from v$shared_pool_reserved ) r

/


prompt

prompt *******************************************************

prompt *               Shared Pool Advice                    *

prompt *******************************************************

prompt 

select SHARED_POOL_SIZE_FOR_ESTIMATE "Shared Pool Size(MB)" ,SHARED_POOL_SIZE_FACTOR "Size Factor",

 ESTD_LC_SIZE "Estd Lib Cache Size", ESTD_LC_MEMORY_OBJECTS "Cached Objects",

 ESTD_LC_TIME_SAVED "Saved Time", ESTD_LC_TIME_SAVED_FACTOR "Saved Time Factor", ESTD_LC_MEMORY_OBJECT_HITS "Object Hits"

from v$shared_pool_advice

/


prompt

prompt *******************************************************

prompt *              BUFFER CACHE TUNING                    *

prompt *******************************************************

prompt

col "Logical Reads" for 999,999,999,999

col "Physical Reads" for 999,999,999,999

select   to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') "Time",

sum(decode(name,'session logical reads', value)) "Logical Reads",

sum(decode(name,'physical reads', value)) "Physical Reads",

sum(decode(name,'physical reads direct', value)) "Phy-Reads Direct",

sum(decode(name,'physical reads direct (lob)', value)) "Phy-Reads Direct(LOB)",

round((1 - (sum(decode(name,'physical reads', value))

- sum(decode(name,'physical reads direct', value))

- sum(decode(name,'physical reads direct (lob)', value)))

/ sum(decode(name,'session logical reads', value))) * 100, 3) "Hit Ratio"

from     v$sysstat

/


clear columns;


prompt

prompt *******************************************************

prompt *             LRU Queue Average Reusable Buffer       *

prompt *******************************************************

prompt

select a.value "free buffer found", b.value "free buffer requests", round(decode(b.value, 0, 0, (a.value / b.value)),1) "Average Reusable Buffer"

from v$sysstat a, v$sysstat b

where a.name = 'DBWR free buffers found'

and b.name = 'DBWR make free requests'

/


prompt

prompt *******************************************************

prompt *            Average LRU Buffer Scan                  *

prompt *******************************************************

prompt

select round(decode(b.value, 0, 0, (a.value / b.value)),1) "Average LRU Buffer Scan"

from v$sysstat a, v$sysstat b

where a.name = 'DBWR buffers scanned'

and b.name = 'DBWR lru scans'

/


prompt

prompt *******************************************************

prompt *            Free Buffer Scan Ratio                   *

prompt *******************************************************

prompt

select round(decode(b.value, 0, -1, (a.value / b.value)*100),2) "Free Buffer Scan Ratio"

from v$sysstat a, v$sysstat b

where a.name = 'free buffer inspected'

and b.name = 'free buffer requested'

/


prompt

prompt *******************************************************

prompt *            Buffer Cache Advice                      *

prompt *******************************************************

prompt

select size_for_estimate "Cache Size (MB)", size_factor "Size Factor", buffers_for_estimate "Buffers",

estd_physical_read_factor "Estd Phys Read Factor", estd_physical_reads "Estd Phys Reads"

from v$db_cache_advice where advice_status = 'ON' and block_size = (select value from v$parameter where name = 'db_block_size') and name = 'DEFAULT'

order by 1,2

/


prompt

prompt *******************************************************

prompt *        INTERNAL SORT AND EXTERNAL SORT              *

prompt *******************************************************

prompt

select a.value "Sort(memory)",

       b.value "Sort(disk)",

       round(a.value/(a.value+b.value) * 100 ,2) "Memory Sort Hit Ratio"

from v$sysstat a, v$sysstat b

       where a.name = 'sorts (memory)'

       and b.name = 'sorts (disk)'

/

prompt

prompt *******************************************************

prompt *        Rows per Sort                                *

prompt *******************************************************

prompt


select round(a.value / (b.value + c.value),2) "Rows per Sort"

from v$sysstat a, v$sysstat b, v$sysstat c

where a.name = 'sorts (rows)'

and b.name = 'sorts (disk)'

and c.name = 'sorts (memory)'

/


prompt

prompt *******************************************************

prompt *        Sort Segment Usage                           *

prompt *******************************************************

prompt

SELECT tablespace_name "Tablespace Name",

       extent_size "Extent Size",

       current_users "Current Users",

       total_extents "Total Exts",

       used_extents "Used Exts",

       free_extents "Free Exts",

       max_used_size "Max Used Exts"

FROM v$sort_segment

/


prompt

prompt *******************************************************

prompt *        PGA Statistics                               *

prompt *******************************************************

prompt

col name for a40

col value for 999,999,999,999,999

select name, value, 'bytes' unit from v$sysstat

where name like 'session pga memory%'

union all

select name, value, unit from v$pgastat

/


prompt

prompt *******************************************************

prompt *        SQL Workarea Statistics                      *

prompt *******************************************************

prompt

select name "Profile", cnt "Count",

decode(total, 0, 0, round(cnt*100/total)) "Percentage"

from (select name, value cnt,

(sum(value) over ()) total

from v$sysstat

where name like 'workarea executions%')

/

prompt

prompt *******************************************************

prompt *        PGA Target Advice                            *

prompt *******************************************************

prompt

select round(pga_target_for_estimate/1024/1024) "Target Size(MB)", 

pga_target_factor "Target Factor", estd_pga_cache_hit_percentage "PGA Cache Hit(%%)", 

estd_overalloc_count "Over-allocation Count"

from v$pga_target_advice where advice_status = 'ON'

/


prompt

prompt *******************************************************

prompt *        ROLLBACK SEGMENT`S WAIT RATIO                *

prompt *******************************************************

prompt

col "Rollback Segment" for a20

col "Miss Ratio" for a15

col "Rsize" for 999,999,999,999

col "Writes" for 999,999,999,999

col "Gets" for 999,999,999,999

select name "Rollback Segment",

     rssize "Rsize", writes "Writes", xacts "Xacts", status "Status",

     waits "Waits", gets "Gets",

     trunc(waits/gets*100, 5)||'%' "Miss Ratio"

from v$rollstat a, v$rollname b

where a.usn = b.usn

order by waits/gets desc

/

clear columns;

prompt

prompt *******************************************************

prompt *            REDO LOG FILE`S WAIT RATIO               *

prompt *******************************************************

prompt

select round(sum(decode(name, 'redo buffer allocation retries', value))/sum(decode(name, 'redo entries', value)),5)

      "Redo Buffer Space Wait(%%)",

      sum(decode(name, 'redo log space requests', value)) "Redo Space Reqeusts"

from v$sysstat

/


col name for a30

col value for a40


select name, value from v$parameter

where name IN('log_buffer', 'log_checkpoint_interval', 'log_checkpoint_timeout','fast_start_mttr_target');


clear columns;


prompt

prompt *******************************************************

prompt *            Redo Entry Average Size                  *

prompt *******************************************************

prompt

select round(decode(b.value, 0, -1, a.value / b.value),1) "Redo Entry Average Size(bytes)"

from v$sysstat a, v$sysstat b

where a.name = 'redo size'

and b.name = 'redo entries'

/


prompt

prompt *******************************************************

prompt *            Log Buffer Retry Ratio                   *

prompt *******************************************************

prompt

select round(decode(b.value, 0, -1, a.value / b.value * 100),6) "Log Buffer Retry Ratio(%%)"

from v$sysstat a, v$sysstat b

where a.name = 'redo buffer allocation retries'

and b.name = 'redo entries'

/


prompt

prompt *******************************************************

prompt *            Redo Log Switch Count(Daily) 1 week      *

prompt *******************************************************

prompt

select thread#, to_char(first_time, 'yyyy/mm/dd') "Time", count(*) "Count"

from v$loghist

where first_time  > sysdate -7

group by thread#, to_char(first_time, 'yyyy/mm/dd')

order by 1, 2

/


select thread#,  count(*) "1 Week Count"

from v$loghist

where first_time  > sysdate -7

group by thread#

order by 1

/



prompt

prompt *******************************************************

prompt *               Latch Hit Ratio                       *

prompt *******************************************************

select * from (select name "Name",

decode(sign(gets-immediate_gets), 1, gets, immediate_gets) "(I)Gets",

decode(sign(gets-immediate_gets), 1, misses, immediate_misses) "(I)Misses",

sleeps "Sleeps",

decode(sign(gets-immediate_gets), 1, round(decode(gets,0,-1,(1-misses/gets) * 100),3),

round(decode(immediate_gets+immediate_misses,0,-1,

(1- immediate_misses/ (immediate_gets+immediate_misses)) * 100), 3 ))    "Hit Ratio"

from   v$latch

where decode(sign(gets-immediate_gets), 1, gets, immediate_gets) > 0

order by 5, 2 desc) where rownum <= 10

/


clear columns;


prompt

prompt *******************************************************

prompt *               Session Count                         *

prompt *******************************************************

col username for a15

col machine for a25


select username, program, machine, count(*) as session_count

from v$session

where username is not null

group by username, program, machine

/


select to_char(sysdate,'yyyy/mm/dd hh24:mi:ss') "Time",

 count(*) "Total Sessions",

 count(decode(status, 'ACTIVE',1) ) "Active Sessions"

from v$session

where username is not null

/


clear columns;


rem prompt

rem prompt *******************************************************

rem prompt *               Session Cursor Cache Hit Ratio        *

rem prompt *******************************************************

rem col "Cursor Cache Hits(%%)" for a21

rem select

rem        round(100 * (calls - sess - hard) / calls, 3)  "Soft Parses(%%)",

rem        round(100 * hard / calls, 3)  "Hard Parses(%%)",

rem        decode(round(100 * sess / calls, 3),0,decode(parm,0,to_char('N/A'),0),round(100 * sess / calls, 3))  

rem           "Cursor Cache Hits(%%)"

rem from

rem       ( select value calls from v$sysstat where name = 'parse count (total)' ),

rem       ( select value hard from v$sysstat where name = 'parse count (hard)' ),

rem       ( select value sess from v$sysstat where name = 'session cursor cache hits' ),

rem       ( select value parm from v$parameter where name = 'session_cached_cursors')

rem /

rem clear columns;


prompt

prompt *******************************************************

prompt *               Cursors opened per transaction        *

prompt *******************************************************

select decode(b.value, 0, -1, round(a.value/b.value)) "Cursors opened per transaction"

from v$sysstat a, v$sysstat b

where a.name = 'opened cursors cumulative'

and b.name = 'user commits'

/


prompt

prompt *******************************************************

prompt *               Recursive to User Call Ratio          *

prompt *******************************************************

select decode(b.value, 0, -1, round(a.value/b.value*100)) "Recur to User Call Ratio(%%)"

from v$sysstat a, v$sysstat b

where a.name = 'recursive calls'

and b.name = 'user calls'

/


prompt

prompt *******************************************************

prompt *               Transaction Rate (TPS)                *

prompt *******************************************************

select round((a.value+b.value) / ((sysdate - (select startup_time from v$instance)) * 24 * 3600),2) "Transaction Rate"

from v$sysstat a, v$sysstat b

where a.name = 'user commits'

and b.name = 'user rollbacks'

/


prompt

prompt *******************************************************

prompt *               Parse Count per User Calls            *

prompt *******************************************************

select decode(b.value, 0, -1, round(a.value/b.value)) "Parse Count per User Calls"

from v$sysstat a, v$sysstat b

where a.name = 'parse count (total)'

and b.name = 'user calls'

/


prompt

prompt *******************************************************

prompt *               Active Transaction                    *

prompt *******************************************************

col username for a10

col "Machine" for a15

col "Pgm" for a15

col "RBS" for a10

col status for a10

col sid for 9999

col "Pgm" for a15

select /*+ ordered */ s.username,

     s.sid sid ,

     substr(s.machine,1,15) "Machine" ,

     substr(s.program,1,15) "Pgm",

     t.status "Status",

     RECURSIVE "Recur",

     to_char(to_date(t.start_time, 'mm/dd/yy HH24:MI:SS'), 'yyyy/mm/dd hh24:mi:ss') "StartTime",

     r.name  "RBS",

     t.used_ublk  "UBLKS",

     t.used_urec "URECS",

     t.log_io "L_IO",

     t.PHY_IO  "P_IO"

from v$transaction t, v$session s, v$rollname r, v$process p

where s.saddr = t.ses_addr and t.xidusn = r.usn

     and s.paddr = p.addr

     order by used_ublk

/


clear columns;


prompt

prompt *******************************************************

prompt *               Pending Distributed Transaction       *

prompt *******************************************************

col host for a10

col global_tran_id for a30


select local_tran_id, global_tran_id, state, mixed, host, commit#

from dba_2pc_pending;


col database for a30

select local_tran_id, in_out, database, dbuser_owner, interface

from dba_2pc_neighbors;


prompt

prompt *******************************************************

prompt *               System Wait Event                     *

prompt *******************************************************

col event format a35

select * 

from (select event,

total_waits "Total Waits",

time_waited "Time Waited(cs)",

round(average_wait,5) "Avg Wait Time(cs)",

total_timeouts "Total Timeouts"

from v$system_event

where event not in ('SQL*Net message to client','SQL*Net more data to client','SQL*Net message from client',

'SQL*Net more data from client','SQL*Net break/reset to client','rdbms ipc message','rdbms ipc reply',

'SQL*Net message from dblink','SQL*Net more data from dblink','SQL*Net message to dblink',

'pipe get','pipe put','smon timer','pmon timer','dispatcher timer','PL/SQL lock timer','wakeup time manager',

'ges remote message','gcs remote message','i/o slave wait','jobq slave wait','slave wait','class slave wait',

'PX Idle Wait','PX Deque wait','PX Deq: Execution Msg','PX Deq: Table Q Normal','PX Deq Credit: need buffer','PX Deq Credit: send blkd',

'PX Deq: Par Recov Reply','PX Deq: Par Recov Execute','PX Deq: Par Recov Change Vector','PX Deq: Join ACK','PX Deq: Execute Reply','PX Deq: Parse Reply',

'PX Deq: reap credit','PX Deq: Signal ACK','PX Deq: Msg Fragment','PX Deq: Table Q Get Keys',

'Queue Monitor Slave Wait','Queue Monitor Wait','Queue Monitor Shutdown Wait','Queue Monitor IPC wait','single-task message',

'Streams AQ: waiting for messages in the queue','Streams AQ: waiting for time management or cleanup tasks',

'Streams AQ: qmn coordinator idle wait','Streams AQ: qmn slave idle wait','virtual circuit status','Null event')

and time_waited > 0

order by time_waited desc)

where rownum < 21

/


prompt

prompt *******************************************************

prompt *            Invalid Obecjt                           *

prompt *******************************************************

prompt

SELECT count(*) as "ALL Count"

FROM DBA_OBJECTS

WHERE STATUS = 'INVALID'

/


select

 owner, object_type,

 count(*) "Invalid Count"

 from dba_objects

 where status  = 'INVALID'

group by owner, object_type

order by 1, 2

/


prompt

prompt *******************************************************

prompt *            User Objects in SYSTEM Tablespace        *

prompt *******************************************************

prompt

select owner "Owner", segment_name "Segment Name", segment_type "Segment Type"

from dba_segments

where tablespace_name = 'SYSTEM'

 and owner not in ('SYSTEM', 'SYS', 'OUTLN', 'DBSNMP', 'MDSYS', 'ORDSYS','OLAPDBA', 'ORDPLUGINS', 

 'OLAPSVR', 'OSE$HTTP$ADMIN', 'AURORA$ORB$UNAUTHENTICATED', 'AURORA$JIS$UTILITY$','WMSYS')

/


prompt *******************************************************

prompt *           Index Scan Ratio                          *

prompt *******************************************************

prompt

select

round(sum(decode(name, 'table fetch by rowid', value)) /

(sum(decode(name, 'table scan rows gotten', value)) + sum(decode(name, 'table fetch by rowid', value)))*100,2) "Index Scan Ratio"

from v$sysstat

/


prompt *******************************************************

prompt *            Session Index Scan Ratio                 *

prompt *******************************************************

prompt

select /*+ ordered use_hash(c) swap_join_inputs(c) */ s.sid, s.program "Program",

     sum(decode(c.name, 'table fetch by rowid', a.value)) "Index Scan",

     sum(decode(c.name, 'table scan rows gotten',a.value)) "Full Scan",

     decode(sum(decode(c.name, 'table fetch by rowid', a.value))+sum(decode(c.name, 'table scan rows gotten',a.value)),0,

     -1, round(sum(decode(c.name, 'table fetch by rowid', a.value))/

     (sum(decode(c.name, 'table fetch by rowid', a.value))+sum(decode(c.name, 'table scan rows gotten',a.value)))*100,2)) "Index Scan Ratio"

from v$session s, v$sesstat a, v$statname c

where c.name in ( 'table scan rows gotten', 'table fetch by rowid' )

      and a.statistic# = c.statistic#

      and s.sid = a.sid

      and s.type != 'BACKGROUND'

      and s.module <> 'Orange for ORACLE'

group by s.sid, s.program

order by 5

/


prompt *******************************************************

prompt *            Chained Row Ratio                        *

prompt *******************************************************

prompt

SELECT sum(decode(name,'table fetch continued row',value,0)) "Chained row Access",

  sum(decode(name,'table fetch by rowid',value,0)) "Index Access",

  sum(decode(name,'table scan rows gotten',value,0)) "Table Scan Access",

  round(sum(decode(name,'table fetch continued row',value,0)) /

  (sum(decode(name,'table fetch by rowid',value,0)) + sum(decode(name,'table scan rows gotten',value,0))) * 100,5) "Ratio"

FROM v$sysstat

/


prompt *******************************************************

prompt *            TOP-20 SQL (by Buffer Gets)               *

prompt *******************************************************

prompt

col username for a12

col "HASH_VALUE" for a12

col executions for 99,999,999

col buffer_gets for 99,999,999,999

col disk_reads for 999,999,999

col "RowsPerExec" for 999,999,999

col parse_calls for 99,999,999

col "SQL_TEXT" for a120

select * from (

select u.username, sharable_mem, executions, parse_calls, disk_reads, buffer_gets, round(decode(executions,0,-1,rows_processed/executions)) "RowsPerExec",

round(elapsed_time/(decode(executions,0,-1000000,executions*1000000)),2) "Elap-Time(Sec)", optimizer_mode,  to_char(hash_value) "HASH_VALUE", --address, child_number, 

substr(sql_text,1,120) "SQL_TEXT"

from v$sql s, all_users u

where s.parsing_user_id = u.user_id

and u.username <> 'SYS'

and u.username <> 'SYSTEM'

and command_type <> 47

order by buffer_gets desc)

where rownum <= 20

/


prompt *******************************************************

prompt *            TOP-20 SQL (by Buffer Gets per Execution)*

prompt *******************************************************

prompt

select * from (

select u.username, sharable_mem, executions, parse_calls, disk_reads,

trunc(decode(executions, 0, -1, (buffer_gets/executions))) "BufferGets/Exec", round(decode(executions,0,-1,rows_processed/executions)) "RowsPerExec",

round(elapsed_time/(decode(executions,0,-1000000,executions*1000000)),2) "Ela-Time(Sec)",

optimizer_mode,  to_char(hash_value) "HASH_VALUE", --address, child_number, 

substr(sql_text,1,120) "SQL_TEXT"

from v$sql s, all_users u

where s.parsing_user_id = u.user_id

and u.username <> 'SYS'

and u.username <> 'SYSTEM'

and command_type <> 47

order by decode(executions, 0, -1, (buffer_gets/executions)) desc)

where rownum <= 20

/


prompt *******************************************************

prompt *            TOP-20 SQL (by Disk Reads)               *

prompt *******************************************************

prompt

select * from (

select u.username, sharable_mem, executions, parse_calls, disk_reads, buffer_gets, round(decode(executions,0,-1,rows_processed/executions)) "RowsPerExec",

round(elapsed_time/(decode(executions,0,-1000000,executions*1000000)),2) "Elap-Time(Sec)", optimizer_mode,  to_char(hash_value) "HASH_VALUE", --address, child_number, 

substr(sql_text,1,120) "SQL_TEXT"

from v$sql s, all_users u

where s.parsing_user_id = u.user_id

and u.username <> 'SYS'

and u.username <> 'SYSTEM'

and command_type <> 47

order by disk_reads desc)

where rownum <= 20

/


prompt *******************************************************

prompt *            TOP-20 SQL (by Elapsed Time)             *

prompt *******************************************************

prompt

select * from (

select u.username, sharable_mem, executions, parse_calls, disk_reads, buffer_gets, round(decode(executions,0,-1,rows_processed/executions)) "RowsPerExec",

round(elapsed_time/(decode(executions,0,-1000000,executions*1000000)),2) "Elap-Time(Sec)", optimizer_mode,  to_char(hash_value) "HASH_VALUE", --address, child_number

substr(sql_text,1,120) "SQL_TEXT"

from v$sql s, all_users u

where s.parsing_user_id = u.user_id

and u.username <> 'SYS'

and u.username <> 'SYSTEM'

and command_type <> 47

order by round(elapsed_time/(decode(executions,0,-1000000,executions*1000000)),2) desc)

where rownum <= 20

/


clear columns;


prompt *******************************************************

prompt *            Literal SQL                              *

prompt *******************************************************

prompt

col "SQL_TEXT" for a70

col "HASH_VALUE" for a12


select substr(sql_text, 1, 70) "SQL_TEXT",

count(*) "Count",

sum(executions) "TotExecs",

sum(sharable_mem) "Mem",

--to_char(to_date(min(first_load_time), 'yyyy-mm-dd/hh24:mi:ss'), 'YYYY/MM/DD hh24:mi:ss') "Start Time",

--to_char(to_date(max(first_load_time), 'yyyy-mm-dd/hh24:mi:ss'), 'YYYY/MM/DD hh24:mi:ss') "End TIme",

to_char(max(hash_value)) "HASH_VALUE"

from v$sql

where executions < 5

group by substr(sql_text, 1, 70)

having count(*) > 30

order by 2 desc

/

clear columns;


prompt

prompt *******************************************************

prompt *            Tablespace Fragments                     *

prompt *******************************************************

prompt

select tablespace_name

      ,total_extents

      ,percent_extents_coalesced || '% Coalesced'

  from dba_free_space_coalesced

 where percent_extents_coalesced <> 100

/


prompt

prompt *******************************************************

prompt *            Many Extent Allocation segment(100 > )   *

prompt *            Max_Extents < Extents + 10               *

prompt *******************************************************

prompt

set feedback on

set pagesize 150

set linesize 150

col owner for a10;

col segment for a25;

col type for a15;

col tablespace for a18;

select owner

      ,segment_name                      "Segment"

      ,segment_type                      "Type"

      ,tablespace_name                   "Tablespace"

      ,round(bytes/1024/1024,2)          "Size(MB)"

      ,extents                           "Extents"

      ,max_extents                       "MaxExtents"

      ,round(initial_extent/1024/1024,2) "Initial(MB)"

      ,round(next_extent/1024/1024,2)    "Next(MB)"

   from dba_segments

  where 

          (extents > 100

                or max_extents < extents + 10)

                and owner NOT IN ('SYS','SYSTEM')

/


prompt

prompt *******************************************************

prompt *   Unable to allocate next extent                    *

prompt *   Not Enough Free space in Tablespace               *

prompt *******************************************************

prompt

select s.owner

        ,s.segment_name         "Segment"

        ,s.segment_type         "Type"

        ,s.tablespace_name      "Tablespace"

        ,round(s.next_extent/1024/1024,2)       "Next(MB)"

from    dba_segments s

where   s.next_extent > (select MAX(f.bytes) 

                        from dba_free_space f

                        where f.tablespace_name = s.tablespace_name)

/


clear columns;


prompt

prompt *******************************************************

prompt *            TABLESPACE Usage                         *

prompt *******************************************************

prompt

set feedback off

SET PAGESIZE 100 

SET LINESIZE 100

COLUMN pct_free FORMAT 999.99 HEADING "% Free" 

COLUMN pct_used FORMAT 999.99 HEADING "% Used"

COLUMN name FORMAT A25 HEADING "Tablespace Name" 

COLUMN mbytes FORMAT 99,999,999 HEADING "Total MBytes" 

COLUMN used FORMAT 99,999,999 HEADING "Used Mbytes" 

COLUMN free FORMAT 99,999,999 HEADING "Free Mbytes" 


BREAK ON REPORT

COMPUTE SUM LABEL TOTAL OF mbytes free used ON REPORT 


SELECT df.tablespace_name name, ts.extent_management ext_mgt, df.totalspace mbytes,

(df.totalspace - NVL(fs.freespace,0)) used, NVL(fs.freespace,0) free,

100 * (NVL(fs.freespace,0) / df.totalspace) pct_free,

100 * ((df.totalspace - NVL(fs.freespace,0)) / df.totalspace) pct_used

FROM    (SELECT tablespace_name, ROUND(SUM(bytes) / 1048576) TotalSpace

FROM dba_data_files

GROUP BY tablespace_name) df, (SELECT tablespace_name,

ROUND(SUM(bytes) / 1048576) FreeSpace

FROM dba_free_space

GROUP BY tablespace_name ) fs, dba_tablespaces ts

WHERE df.tablespace_name = fs.tablespace_name(+)

AND df.tablespace_name = ts.tablespace_name

order by 1

/


rem select df.tablespace_name "Tablespace",

rem         round(df.TBS_byte /1048576,2) "Total(MB)",

rem         round((df.TBS_byte - fs.Free_byte)/1048576,2) "Used(MB)",

rem         round(fs.Free_byte /1048576,2) "Free(MB)",

rem         round((fs.Free_byte/df.TBS_byte) *100,0) "Free(%%)",

rem         fs.pieces "Pieces",

rem         round(fs.Max_free /1048576,2) "MaxFree(MB)"

rem from   ( select tablespace_name, sum(bytes) TBS_byte

rem          from dba_data_files group by tablespace_name ) df,

rem         ( select tablespace_name, max(bytes) Max_free, sum(bytes) Free_byte, count(*) pieces

rem          from dba_free_space group by tablespace_name ) fs,

rem         ( select tablespace_name, initial_extent, next_extent

rem          from dba_tablespaces ) db

rem where df.tablespace_name = db.tablespace_name

rem  and   df.tablespace_name = fs.tablespace_name(+)

rem order by 5

rem /


set feedback on


prompt

prompt *******************************************************

prompt *            datafile autoextensible                  *

prompt *******************************************************

prompt

set linesize 150

set pagesize 150

col file_name for a50;

col tablespace_name for a20;

select tablespace_name, file_name,bytes/1024/1024 as MB, maxbytes/1024/1024 as maxsize, autoextensible

from dba_data_files

order by 1

/


prompt

prompt *******************************************************

prompt *            File I/O INFO                            *

prompt *******************************************************

prompt


col name for a40;

select name "Name"

,phyrds "Phy Rds"

,phywrts "Phy Wrts"

,phyrds+phywrts "Total IO"

,trunc(phyrds/read_sum*100,2) "Read(%%)"

,trunc(phywrts/write_sum*100,2) "Write(%%)"

,trunc( (phyrds+phywrts) / (read_sum+write_sum) * 100 , 2) "Total IO(%%)"

,avgiotim "Avg IO Time"

from v$filestat a, v$datafile b,

(select sum(phyrds) read_sum, sum(phywrts) write_sum

from v$filestat ) c

where a.file# = b.file#

order by name desc

/


clear columns;


prompt

prompt *******************************************************

prompt *            Tablespace I/O INFO                      *

prompt *******************************************************

prompt

SELECT max(c.name) "Tablespace Name",

sum(phyrds) "Phy Rds",

sum(phywrts) "Phy Wrts",

sum(phyblkrd) "Phy Blk Rd",

sum(phyblkwrt) "Phy Blk Wrt",

sum(phyrds+phywrts) "Phy Rds+Wrts",

sum(phyblkrd+phyblkwrt) "Phy Blk Rd+Wrt",

trunc(decode(sum(phyrds),0,-1, sum(phyblkrd)/sum(phyrds)),1) "Blocks/Read"

FROM v$filestat a,

v$datafile b,

v$tablespace c

WHERE a.file# = b.file#

and b.ts# = c.ts#

group by b.ts#

order by "Blocks/Read" desc, "Phy Blk Rd" desc

/


prompt

prompt *******************************************************

prompt *            Table and Index Size Calculation        *

prompt *******************************************************

prompt


select ty as seg_type, sum(sz) as "Size(MB)"

from (select decode(substr(segment_type,1,5),'TABLE','Table Segments','INDEX','Index Segments','LOBSE','Table Segments','LOBIN','Index Segments','Etc Segments') as ty,

 trunc(sum(bytes/1024/1024),0) as sz

 from dba_segments

 where owner not in ('SYSTEM', 'SYS', 'SYSMAN', 'OUTLN', 'DBSNMP', 'MDSYS', 'ORDSYS','OLAPDBA', 'ORDPLUGINS',

  'OLAPSVR', 'OSE$HTTP$ADMIN', 'AURORA$ORB$UNAUTHENTICATED', 'AURORA$JIS$UTILITY$','WMSYS',

  'WMSYS', 'CTXSYS', 'XDB', 'ANONYMOUS', 'TRACESVR', 'REPADMIN', 'SCOTT', 'HR', 'SH')

 group by segment_type)

group by ty order by 1 desc;


spool off;


exit



Posted by pat98

사용법 : ./mon.sh mon.sql 3 (수행간격)

===============================

if [ $# -eq 1 ]

then

 arg2=2

elif [ $# -eq 2 ]

then

 arg2=$2

else

    echo "Usage : mon.sh sql term";

    exit;

fi


arg1=$1

while true

do

sqlplus -s '/ as sysdba' <<EOF

set linesize 200

set pause off

set pagesize 120

@$arg1

EOF

sleep $arg2

done


- mon.sql 화일내용


prompt ##################################################################################################################

!date

prompt ========================================================

prompt = Session Wait

prompt ========================================================

col DB      format 99

col sid     format 999999

col serial# format 99999

col spid    format a7

col cli_spid format a10

col process format a11

col event   format a30

col p       format a20

col W       format 999

col program format a15

col C       format a2

col blkSid  format 99999

col object_name format a20

set linesize 170 pagesize 100 trimspool on


select 

       a.inst_id "DB",

       a.sid, a.serial#, 

       (select p.spid from gv$process p where (a.inst_id = p.inst_id) and (a.paddr = p.addr))  spid, a.status,a.event,a.process as CLI_SPID,

       decode(a.event,'enqueue',

              decode(chr(bitand(a.p1,-16777216)/16777215)||chr(bitand(a.p1, 16711680)/65535),'TX',

              chr(bitand(a.p1,-16777216)/16777215)||chr(bitand(a.p1, 16711680)/65535)||to_char( bitand(a.p1, 65535) )||','||

              'usn.slot:'||bitand(a.p2, 4294901760)/65536||'.'||bitand(a.p2, 65535)||','||'wrap:'||a.p3,

              a.p1||','||a.p2||','||a.p3),a.p1||','||a.p2||','||a.p3) P,

       a.seconds_in_wait W, 

       substr(a.program,1,15) program, 

       decode(a.command,3,'S',2,'I',6,'U',7,'D',command) C,

       a.sql_id,

       substr((SELECT OBJECT_NAME FROM DBA_OBJECTS C WHERE C.OBJECT_ID = ROW_WAIT_OBJ# ),1,20) object_name,

       a.blocking_session blkSid, -- comment out for 10.2.0.2

       substr((SELECT NAME FROM V$LATCH WHERE LATCH# = p2 and event = 'latch free' ),1,10) LATCH_NAME

  from gv$session a

 where a.event not like 'SQL*Net message from client%'

   and a.event not like 'rdbms ipc%'

   and a.event not like 'smon timer'

   and a.event not like 'pmon timer'

   and a.event not like '%slave wait%'

   and a.event not like 'lock manager wait for remote message'

   and a.event not like 'PX Deq%'

   and a.event not like 'null event'

   and a.event not like 'gcs remote message'

   and a.event not like 'ges remote message'

   and a.event not like 'wakeup time manager'

   and a.event not like 'Queue Monitor%Wait'

   and a.event not like 'DIAG idle wait'

   and a.event not like 'Streams AQ:%'

   and a.sid <> (select sid from v$mystat where rownum = 1)

   and a.wait_class <> 'Idle'

order by a.inst_id, a.event, a.sid

/


prompt ========================================================

prompt =  v$latch_holder

prompt ========================================================

set linesize 150 pagesize 100 trimspool on

col name format a40

select 

'[latch]'||to_char(sysdate,'yyyy/mm/dd hh24:mi:ss') dt,

INST_ID,PID,SID,LADDR,NAME,GETS

from gv$latchholder

/


prompt ========================================================

prompt = 'Event summary'  having count(*) >= 3 

prompt ========================================================

col DB      format 99

col event   format a30

col count1   format 999,999

set linesize 150 pagesize 100 trimspool on


select '[event]'||to_char(sysdate,'yyyy/mm/dd hh24:mi:ss') dt,

        a.inst_id "DB", a.event,count(*) as count1

  from gv$session a

 where a.event not like 'SQL*Net message from client%'

   and a.event not like 'rdbms ipc%'

   and a.event not like 'smon timer'

   and a.event not like 'pmon timer'

   and a.event not like '%slave wait%'

   and a.event not like 'lock manager wait for remote message'

   and a.event not like 'PX Deq%'

   and a.event not like 'null event'

   and a.event not like 'gcs remote message'

   and a.event not like 'ges remote message'

   and a.event not like 'wakeup time manager'

   and a.event not like 'Queue Monitor%Wait'

   and a.event not like 'DIAG idle wait'

   and a.event not like 'Streams AQ:%'

   and a.sid <> (select sid from v$mystat where rownum = 1)

 group by a.inst_id, a.event

 having count(*) >= 3

 order by count(*) desc

/


--prompt ========================================================

--prompt = Program Info. having count(*) > 1

--prompt ========================================================

--col program format a40

--select '[program]'||to_char(sysdate,'yyyy/mm/dd hh24:mi:ss') dt,

--         program, count(*) as count1

--  from gv$session a

-- where a.event not like 'SQL*Net message from client%'

--   and a.event not like 'rdbms ipc%'

--   and a.event not like 'smon timer'

--   and a.event not like 'pmon timer'

--   and a.event not like '%slave wait%'

--   and a.event not like 'lock manager wait for remote message'

--   and a.event not like 'PX Deq%'

--   and a.event not like 'null event'

--   and a.event not like 'gcs remote message'

--   and a.event not like 'ges remote message'

--   and a.event not like 'wakeup time manager'

--   and a.event not like 'Queue Monitor%Wait'

--   and a.event not like 'DIAG idle wait'

--   and a.event not like 'Streams AQ:%'

--   and a.sid <> (select sid from v$mystat where rownum = 1)

-- group by program

-- having count(*) > 1

-- order by count(*) desc

--/

----

----prompt ========================================================

----prompt = 'gc buffer busy' - p1, p2 , count 

----prompt ========================================================

----select p1, p2, count(*) cnt

----  from gv$session

---- where event = 'gc buffer busy'

---- group by p1, p2

---- order by cnt desc

----/


--prompt ========================================================

--prompt = 'gv$resource ' - MAX_UTILIZATION > 0.8 * INITIAL_ALLOCATION

--prompt ========================================================

--set linesize 150 pagesize 100 trimspool on

--col RESOURCE_NAME format a17

--select 

--'[resource]'||to_char(sysdate,'yyyy/mm/dd hh24:mi:ss') dt, INST_ID,RESOURCE_NAME,CURRENT_UTILIZATION,MAX_UTILIZATION,INITIAL_ALLOCATION,LIMIT_VALUE

--from gv$resource_limit  

--where   MAX_UTILIZATION > 

--0.8*to_number( decode(INITIAL_ALLOCATION,' UNLIMITED','99999999999',INITIAL_ALLOCATION),'999999999999') 

--and RESOURCE_NAME not in ('ges_cache_ress','ges_big_msgs','gcs_shadows','gcs_resources')

--order by INST_ID asc 

--/



prompt ========================================================

prompt = Session Count.

prompt ========================================================

set linesize 150 pagesize 100 trimspool on

col dt format a29

select '[ses_cnt]'||to_char(sysdate,'yyyy/mm/dd hh24:mi:ss') dt,

       inst_id,

       sum(decode(status,'ACTIVE',1))-1 "Active",

       count(*) "Total"

  from gv$session

 where type <> 'BACKGROUND'

    or username is not null

 group by inst_id

 order by inst_id asc

/

--

--prompt ========================================================

--prompt = Insert Session Wait

--prompt ========================================================

--col DB      format 99

--col sid     format 999999

--col serial# format 99999

--col process format a11

--col event   format a30

--col p       format a20

--col W       format 999

--col program format a15

--col C       format a2

--col blkSid  format 99999

--col object_name format a20

--col spid format a6

--set linesize 170 pagesize 100 trimspool on

--

--select 

--       a.inst_id "DB",

--       a.sid, a.serial#, 

--       (select p.spid from gv$process p where (a.inst_id = p.inst_id) and (a.paddr = p.addr))  spid, a.status,a.event,a.process as CLI_SPID,

----       decode(a.event,'enqueue',

----              decode(chr(bitand(a.p1,-16777216)/16777215)||chr(bitand(a.p1, 16711680)/65535),'TX',

----              chr(bitand(a.p1,-16777216)/16777215)||chr(bitand(a.p1, 16711680)/65535)||to_char( bitand(a.p1, 65535) )||','||

----              'usn.slot:'||bitand(a.p2, 4294901760)/65536||'.'||bitand(a.p2, 65535)||','||'wrap:'||a.p3,

----              a.p1||','||a.p2||','||a.p3),a.p1||','||a.p2||','||a.p3) P,

--       a.seconds_in_wait W, 

--       substr(a.program,1,15) program, 

--       decode(a.command,3,'S',2,'I',6,'U',7,'D',command) C,

--       a.sql_id,

--       substr((SELECT OBJECT_NAME FROM DBA_OBJECTS C WHERE C.OBJECT_ID = ROW_WAIT_OBJ# ),1,20) object_name,

--       a.blocking_session blkSid,

--       substr((SELECT NAME FROM V$LATCH WHERE LATCH# = p2 and event = 'latch free' ),1,10) LATCH_NAME

--  from gv$session a

-- where a.event not like 'SQL*Net message from client%'

----   and a.event not like 'rdbms ipc%'

----   and a.event not like 'smon timer'

----   and a.event not like 'pmon timer'

----   and a.event not like '%slave wait%'

----   and a.event not like 'lock manager wait for remote message'

----   and a.event not like 'PX Deq%'

----   and a.event not like 'null event'

----   and a.event not like 'gcs remote message'

----   and a.event not like 'ges remote message'

----   and a.event not like 'wakeup time manager'

----   and a.event not like 'Queue Monitor%Wait'

----   and a.event not like 'DIAG idle wait'

----   and a.event not like 'Streams AQ:%'

--   and a.sid <> (select sid from v$mystat where rownum = 1)

--   and a.COMMAND = 2

--   and a.WAIT_TIME = 0 and a.SECONDS_IN_WAIT > 5

---- order by a.inst_id, a.event, a.sid

--/

--



--prompt ========================================================

--prompt =  DFS lock handle

--prompt ========================================================

--col DB      format 99

--col inst format 99

--col b_inst format 99

--col sid     format 999999

--col blk_sid     format 999999

--col serial# format 99999

--col blk_seri format 99999

--col process format a11

--col Mode   format a4

--col P2TEXT format a6

--col P3TEXT format a6

--col username format a9

--col W       format 999

--col program format a15

--col machine format a10

--col blkSid  format 99999

--col object_name format a20

--col spid format a6

--col dt format a29

--set linesize 170 pagesize 100 trimspool on

--

--select '[DFSlock]'||to_char(sysdate,'yyyy/mm/dd hh24:mi:ss') dt, inst_id as inst,chr(to_char(bitand(p1,-16777216))/16777215)||

--      chr(to_char(bitand(p1, 16711680))/65535) "Lock",

--      to_char( bitand(p1, 65535) )    "Mode",  P2TEXT,        P2,     P3TEXT, P3,

--sid,serial#,username,program,sql_id

--,BLOCKING_INSTANCE as b_inst,BLOCKING_SESSION as blk_sid

----,BLOCKING_SESSION_STATUS,PREV_SQL_ID, ROW_WAIT_OBJ#,ROW_WAIT_FILE#,ROW_WAIT_BLOCK#,ROW_WAIT_ROW#

--FROM gv$session

--WHERE event = 'DFS lock handle'

--/


--

--prompt ========================================================

--prompt = Global Enqueue 

--prompt ========================================================

--set numwidth 5

--col inst format 99

--column state format a8 tru;

--column event format a25 tru;

--select dl.inst_id as inst, s.sid, s.serial#,p.spid,s.username,s.program, dl.resource_name1, 

--decode(substr(dl.grant_level,1,8),'KJUSERNL','Null','KJUSERCR','Row-S (SS)',

--'KJUSERCW','Row-X (SX)','KJUSERPR','Share','KJUSERPW','S/Row-X (SSX)',

--'KJUSEREX','Exclusive',request_level) as grant_level,

--decode(substr(dl.request_level,1,8),'KJUSERNL','Null','KJUSERCR','Row-S (SS)',

--'KJUSERCW','Row-X (SX)','KJUSERPR','Share','KJUSERPW','S/Row-X (SSX)',

--'KJUSEREX','Exclusive',request_level) as request_level, 

--decode(substr(dl.state,1,8),'KJUSERGR','Granted','KJUSEROP','Opening',

--'KJUSERCA','Canceling','KJUSERCV','Converting') as state,

-- sw.event, sw.seconds_in_wait W

--from gv$ges_enqueue dl, gv$process p, gv$session s, gv$session_wait sw

--where blocker = 1

--and (dl.inst_id = p.inst_id and dl.pid = p.spid)

--and (p.inst_id = s.inst_id and p.addr = s.paddr)

--and (s.inst_id = sw.inst_id and s.sid = sw.sid)

--order by sw.seconds_in_wait desc

--/



--prompt ========================================================

--prompt = LOCK Blocking

--prompt ========================================================

--set verify off linesize 100

--col username format a10

--col sid format 999

--col lock_type format a18

--col mode_held format a11

--col mode_requested format a10

--col lock_id1 format a8

--col lock_id2 format a8

--select /*+ rule */ a.sid,

--decode(a.type,

--'MR', 'Media Recovery',

--'RT', 'Redo Thread',

--'UN', 'User Name',

--'TX', 'Transaction',

--'TM', 'DML',

--'UL', 'PL/SQL User Lock',

--'DX', 'Distributed Xact',

--'CF', 'Control File',

--'IS', 'Instance State',

--'FS', 'File Set',

--'IR', 'Instance Recovery',

--'ST', 'Disk Space TranX',

--'IR', 'Instance Recovery',

--'ST', 'Disk Space TranX',

--'TS', 'Temp Segment',

--'IV', 'Lib Cache Invalid',

--'LS', 'Log Start/Switch',

--'RW', 'Row Wait',

--'SQ', 'Sequence Number',

--'TE', 'Extend Table',

--'TT', 'Temp Table',

--a.type) lock_type,

--decode(a.lmode,

--0, 'None', /* Mon Lock equivalent */

--1, 'Null', /* N */

--2, 'Row-S (SS)', /* L */

--3, 'Row-X (SX)', /* R */

--4, 'Share', /* S */

--5, 'S/Row-X (SSX)', /* C */

--6, 'Exclusive', /* X */

--to_char(a.lmode)) mode_held,

--decode(a.request,

--0, 'None', /* Mon Lock equivalent */

--1, 'Null', /* N */

--2, 'Row-S (SS)', /* L */

--3, 'Row-X (SX)', /* R */

--4, 'Share', /* S */

--5, 'S/Row-X (SSX)', /* C */

--6, 'Exclusive', /* X */

--to_char(a.request)) mode_requested,

--to_char(a.id1) lock_id1, to_char(a.id2) lock_id2, BLOCK

--from v$lock a

--where a.type NOT IN ( 'MR','RT' )

--and (id1,id2) in

--( select b.id1, b.id2 from v$lock b

--where b.id1=a.id1

--and b.id2=a.id2

--and b.request > 0 )

--/



Posted by pat98

01-25 15:55
Flag Counter
Yesterday
Today
Total

글 보관함

최근에 올라온 글

달력

 « |  » 2025.1
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

최근에 달린 댓글