-- viewing waits system wide
col event format a46
col seconds format 999,999,990.00
col calls format 999,999,990
select a.event,
a.time_waited,
a.total_waits calls,
a.time_waited/a.total_waits average_wait,
sysdate - b.startup_time days_old
from v$system_event a, v$instance b
where rownum < 6
order by a.time_waited desc;
-- viewing waits on a session
select
e.event, e.time_waited
from
v$session_event e
where
e.sid = 12
union all
select
n.name,
s.value
from
v$statname n,
v$sesstat s
where
s.sid = 12
and n.statistic# = s.statistic#
and n.name = 'CPU used by this session'
order by
2 desc
/
-- sesstat
select a.sid, b.name, a.value
from v$sesstat a, v$statname b
where a.statistic# = b.statistic#
and a.value > 0
and a.sid = 12;
-- kill sessions
-- select /* usercheck */ 'alter system disconnect session '''||s.sid||','||s.serial#||''''||' post_transaction;'
select /* usercheck */ 'alter system disconnect session '''||s.sid||','||s.serial#||''''||' immediate;'
from v$process p, v$session s, v$sqlarea sa
where p.addr=s.paddr
and s.username is not null
and s.sql_address=sa.address(+)
and s.sql_hash_value=sa.hash_value(+)
and sa.sql_text NOT LIKE '%usercheck%'
-- and upper(sa.sql_text) LIKE '%CP_IINFO_DAILY_RECON_PKG.USP_DAILYCHANGEFUND%'
-- and s.sid = 178
and s.sql_id = '&sql_id'
-- and sid in (1404,1023,520,389,645)
-- and s.username = 'APAC'
-- and sa.plan_hash_value = 3152625234
order by status desc;
-- quicker kill sessions
select /* usercheck */ 'alter system disconnect session '''||s.sid||','||s.serial#||''''||' immediate;'
from v$session s
where s.sql_id = '&sql_id';
-- purge SQL_ID on shared pool
var name varchar2(50)
BEGIN
select /* usercheck */ sa.address||','||sa.hash_value into :name
from v$process p, v$session s, v$sqlarea sa
where p.addr=s.paddr
and s.username is not null
and s.sql_address=sa.address(+)
and s.sql_hash_value=sa.hash_value(+)
and sa.sql_text NOT LIKE '%usercheck%'
-- and upper(sa.sql_text) LIKE '%CP_IINFO_DAILY_RECON_PKG.USP_DAILYCHANGEFUND%'
and s.sid = 176
-- and s.username = 'APAC'
order by status desc;
dbms_shared_pool.purge(:name,'C',1);
END;
/
-- show all users
-- on windows to kill do.. orakill<instance_name> <spid>
set lines 32767
col terminal format a4
col machine format a4
col os_login format a4
col oracle_login format a4
col osuser format a4
col module format a5
col program format a8
col schemaname format a5
-- col state format a8
col client_info format a5
col status format a4
col sid format 99999
col serial# format 99999
col unix_pid format a8
col txt format a50
col action format a8
select /* usercheck */ s.INST_ID, s.terminal terminal, s.machine machine, p.username os_login, s.username oracle_login, s.osuser osuser, s.module, s.action, s.program, s.schemaname,
s.state,
s.client_info, s.status status, s.sid sid, s.serial# serial#, lpad(p.spid,7) unix_pid, -- s.sql_hash_value,
sa.plan_hash_value, -- remove in 817, 9i
s.sql_id, -- remove in 817, 9i
substr(sa.sql_text,1,1000) txt
from gv$process p, gv$session s, gv$sqlarea sa
where p.addr=s.paddr
and s.username is not null
and s.sql_address=sa.address(+)
and s.sql_hash_value=sa.hash_value(+)
and sa.sql_text NOT LIKE '%usercheck%'
-- and lower(sa.sql_text) LIKE '%grant%'
-- and s.username = 'APAC'
-- and s.schemaname = 'SYSADM'
-- and lower(s.program) like '%uscdcmta21%'
-- and s.sid=12
-- and p.spid = 14967
-- and s.sql_hash_value = 3963449097
-- and s.sql_id = '5p6a4cpc38qg3'
-- and lower(s.client_info) like '%10036368%'
-- and s.module like 'PSNVS%'
-- and s.program like 'PSNVS%'
order by status desc;
-- find running jobs
set linesize 250
col sid for 9999 head 'Session|ID'
col spid head 'O/S|Process|ID'
col serial# for 9999999 head 'Session|Serial#'
col log_user for a10
col job for 9999999 head 'Job'
col broken for a1 head 'B'
col failures for 99 head "fail"
col last_date for a18 head 'Last|Date'
col this_date for a18 head 'This|Date'
col next_date for a18 head 'Next|Date'
col interval for 9999.000 head 'Run|Interval'
col what for a60
select j.sid,
s.spid,
s.serial#,
j.log_user,
j.job,
j.broken,
j.failures,
j.last_date||':'||j.last_sec last_date,
j.this_date||':'||j.this_sec this_date,
j.next_date||':'||j.next_sec next_date,
j.next_date - j.last_date interval,
j.what
from (select djr.SID,
dj.LOG_USER, dj.JOB, dj.BROKEN, dj.FAILURES,
dj.LAST_DATE, dj.LAST_SEC, dj.THIS_DATE, dj.THIS_SEC,
dj.NEXT_DATE, dj.NEXT_SEC, dj.INTERVAL, dj.WHAT
from dba_jobs dj, dba_jobs_running djr
where dj.job = djr.job ) j,
(select p.spid, s.sid, s.serial#
from v$process p, v$session s
where p.addr = s.paddr ) s
where j.sid = s.sid;
-- find where a system is stuck
break on report
compute sum of sessions on report
select event, count(*) sessions from v$session_wait
where state='WAITING'
group by event
order by 2 desc;
-- find the session state
select event, state, count(*) from v$session_wait group by event, state order by 3 desc;
-- when user calls up, describe wait events per session since the session has started up
select max(total_waits), event, sid from v$session_event
where sid = 12
group by sid, event
order by 1 desc;
-- You can easily discover which session has high TIME_WAITED on the db file sequential read or other waits
select a.sid,
a.event,
a.time_waited,
a.time_waited / c.sum_time_waited * 100 pct_wait_time,
round((sysdate - b.logon_time) * 24) hours_connected
from v$session_event a, v$session b,
(select sid, sum(time_waited) sum_time_waited
from v$session_event
where event not in (
'Null event',
'client message',
'KXFX: Execution Message Dequeue - Slave',
'PX Deq: Execution Msg',
'KXFQ: kxfqdeq - normal deqeue',
'PX Deq: Table Q Normal',
'Wait for credit - send blocked',
'PX Deq Credit: send blkd',
'Wait for credit - need buffer to send',
'PX Deq Credit: need buffer',
'Wait for credit - free buffer',
'PX Deq Credit: free buffer',
'parallel query dequeue wait',
'PX Deque wait',
'Parallel Query Idle Wait - Slaves',
'PX Idle Wait',
'slave wait',
'dispatcher timer',
'virtual circuit status',
'pipe get',
'rdbms ipc message',
'rdbms ipc reply',
'pmon timer',
'smon timer',
'PL/SQL lock timer',
'SQL*Net message from client',
'WMON goes to sleep')
having sum(time_waited) > 0 group by sid) c
where a.sid = b.sid
and a.sid = c.sid
and a.time_waited > 0
-- and a.event = 'db file sequential read'
order by hours_connected desc, pct_wait_time;
-- show all users RAC
select s.inst_id instance_id,
s.failover_type failover_type,
s.FAILOVER_METHOD failover_method,
s.FAILED_OVER failed_over,
p.username os_login,
s.username oracle_login,
s.status status,
s.sid oracle_session_id,
s.serial# oracle_serial_no,
lpad(p.spid,7) unix_process_id,
s.machine, s.terminal, s.osuser,
substr(sa.sql_text,1,540) txt
from gv$process p, gv$session s, gv$sqlarea sa
where p.addr=s.paddr
and s.username is not null
and s.sql_address=sa.address(+)
and s.sql_hash_value=sa.hash_value(+)
--and s.sid=48
--and p.spid
order by 3;
-- this is for RAC TAF, fewer columns
col oracle_login format a10
col instance_id format 99
col sidserial format a8
select s.inst_id instance_id,
s.failover_type failover_type,
s.FAILOVER_METHOD failover_method,
s.FAILED_OVER failed_over,
s.username oracle_login,
s.status status,
concat (s.sid,s.serial#) sidserial,
substr(sa.sql_text,1,15) txt
from gv$process p, gv$session s, gv$sqlarea sa
where p.addr=s.paddr
and s.username is not null
and s.type = 'USER'
and s.username = 'ORACLE'
and s.sql_address=sa.address(+)
and s.sql_hash_value=sa.hash_value(+)
--and s.sid=48
--and p.spid
order by 6;
-- show open cursors
col txt format a100
select sid, hash_value, substr(sql_text,1,1000) txt from v$open_cursor where sid = 12;
-- show running cursors
select nvl(USERNAME,'ORACLE PROC'), s.SID, s.sql_hash_value, SQL_TEXT
from sys.v_$open_cursor oc, sys.v_$session s
where s.SQL_ADDRESS = oc.ADDRESS
and s.SQL_HASH_VALUE = oc.HASH_VALUE
and s.sid = 12
order by USERNAME, s.SID;
-- Get recent snapshot
select instance_number, to_char(startup_time, 'DD-MON-YY HH24:MI:SS') startup_time, to_char(begin_interval_time, 'DD-MON-YY HH24:MI:SS') begin_interval_tim, snap_id
from DBA_HIST_SNAPSHOT
order by snap_id;
-- Finding top expensive SQL in the workload repository, get snap_ids first
select * from (
select a.sql_id as sql_id, sum(elapsed_time_delta)/1000000 as elapsed_time_in_sec,
(select x.sql_text
from dba_hist_sqltext x
where x.dbid = a.dbid and x.sql_id = a.sql_id) as sql_text
from dba_hist_sqlstat a, dba_hist_sqltext b
where a.sql_id = b.sql_id and
a.dbid = b.dbid
and a.snap_id between 710 and 728
group by a.dbid, a.sql_id
order by elapsed_time_in_sec desc
) where ROWNUM < 2
/
-- Only valid for 10g Release 2, Finding top 10 expensive SQL in the cursor cache by elapsed time
select * from (
select sql_id, elapsed_time/1000000 as elapsed_time_in_sec, substr(sql_text,1,80) as sql_text
from v$sqlstats
order by elapsed_time_in_sec desc
) where rownum < 11
/
-- get hash value statistics, The query sorts its output by the number of LIO calls executed per row returned. This is a rough measure of statement efficiency. For example, the following output should bring to mind the question, "Why should an application require more than 174 million memory accesses to compute 5 rows?"
col stmtid heading 'Stmt Id' format 9999999999
col dr heading 'PIO blks' format 999,999,999
col bg heading 'LIOs' format 999,999,999,999
col sr heading 'Sorts' format 999,999
col exe heading 'Runs' format 999,999,999,999
col rp heading 'Rows' format 9,999,999,999
col rpr heading 'LIOs|per Row' format 999,999,999,999
col rpe heading 'LIOs|per Run' format 999,999,999,999
select hash_value stmtid
,sum(disk_reads) dr
,sum(buffer_gets) bg
,sum(rows_processed) rp
,sum(buffer_gets)/greatest(sum(rows_processed),1) rpr
,sum(executions) exe
,sum(buffer_gets)/greatest(sum(executions),1) rpe
from v$sql
where command_type in ( 2,3,6,7 )
and hash_value in (2023740151)
-- and rownum < 20
group by hash_value
order by 5 desc;
-- check block gets of a session
col block_gets format 999,999,999,990
col consistent_gets format 999,999,999,990
select to_char(sysdate, 'hh:mi:ss') "time", physical_reads, block_gets, consistent_gets, block_changes, consistent_changes
from v$sess_io
where sid=681;
-- show SQL in shared SQL area, get hash value
SELECT /* example */ substr(sql_text, 1, 80) sql_text,
sql_id,
hash_value, address, child_number, plan_hash_value, FIRST_LOAD_TIME
FROM v$sql
WHERE
--sql_id = '6wps6tju5b8tq'
-- hash_value = 1481129178
upper(sql_text) LIKE '%INSERT INTO PS_CBLA_RET_TMP SELECT CB_BUS_UN%'
AND sql_text NOT LIKE '%example%'
order by first_load_time;
-- show SQL hash
col txt format a1000
select
sa.hash_value, sa.sql_id,
substr(sa.sql_text,1,1000) txt
from v$sqlarea sa
where
sa.hash_value = 517092776
--ADDRESS = '2EBC7854'
--sql_id = 'gz5bfrcjq060u';
-- show full sql text of the transaction
col sql_text format a1000
set heading off
select sql_text from v$sqltext
where HASH_VALUE = 1481129178
-- where sql_id = 'a5xnahpb62cvq'
order by piece;
set heading on
/*
The trace doesn't contain the SQLID as such but the hash value.
In this case Hash=61d72ac6.
Translate this to decimal and query v$sqlarea where hash_value=#
( if the hash value is still in the v$sqlarea )
/u01/app/oracle/diag/rdbms/biprddal/biprd1/incident/incdir_65625/biprd1_dia0_19054_i65625.trc
~~~~~~~~~~
....
LibraryHandle: Address=0x1ff1434c8 Hash=61d72ac6 LockMode=N PinMode=0 LoadLockMode=0 Status=VALD
ObjectName: Name=UPDATE WC_BUDGET_BALANCE_A_TMP A SET
*/
select sql_text from dba_hist_sqltext where sql_id in (select sql_id from DBA_HIST_SQLSTAT where plan_hash_value = 1641491142);
-- get sql id and hash value, convert hash to, sqlid to hash, sql_id to hash, h2s
col sql_text format a1000
select substr(sql_text, 1,30), sql_id, hash_value from v$sqltext
where
HASH_VALUE = 1312665718
-- sql_id = '048znjmq3uvs9'
and rownum < 2;
-- show full sql text of the transaction, of the top sqls in awr
col sql_text format a1000
set heading off
select ''|| sql_id || ' '|| hash_value || ' ' || sql_text || '' from v$sqltext
-- where HASH_VALUE = 1481129178
where sql_id in (select distinct a.sql_id as sql_id
from dba_hist_sqlstat a, dba_hist_sqltext b
where a.sql_id = b.sql_id and
a.dbid = b.dbid
and a.snap_id between 710 and 728)
order by sql_id, piece;
set heading on
-- query SQL in ASH
set lines 3000
select substr(sa.sql_text,1,500) txt, a.sample_id, a.sample_time, a.session_id, a.session_serial#, a.user_id, a.sql_id,
a.sql_child_number, a.sql_plan_hash_value,
a.sql_opcode, a.plsql_object_id, a.service_hash, a.session_type,
a.session_state, a.qc_session_id, a.blocking_session,
a.blocking_session_status, a.blocking_session_serial#, a.event, a.event_id,
a.seq#, a.p1, a.p2, a.p3, a.wait_class,
a.wait_time, a.time_waited, a.program, a.module, a.action, a.client_id
from gv$active_session_history a, gv$sqltext sa
where a.sql_id = sa.sql_id
-- and session_id = 126
/* -- weird scenario, when I'm looking for TRUNCATE statement, I can see it in V$SQLTEXT
-- and I can't see it on V$SQLAREA and V$SQL
select * from v$sqltext where upper(sql_text) like '%TRUNCATE%TEST3%';
select * from v$sqlarea
where sql_id = 'dfwz4grz83d6a'
where upper(sql_text) like '%TRUNCATE%';
select * from v$sql
where sql_id = 'dfwz4grz83d6a'
where upper(sql_text) like '%TRUNCATE%';
from oracle-l:
Checking V$FIXED_VIEW_DEFINITION, you can see that V$SQLAREA is based off of
x$kglcursor_child_sqlid, V$SQL is off x$kglcursor_child, and V$SQLTEXT is off
x$kglna. I may be way off on this, but I believe pure DDL is not a cursor,
which is why it won't be found in X$ cursor tables. Check with a CTAS vs. a
plain CREATE TABLE ... (field ...). CTAS uses a cursor and would be found in
all the X$ sql tables. A plan CREATE TABLE won't.
*/
-- query long operations
set lines 200
col opname format a35
col target format a10
col units format a10
select * from (
select
sid, serial#, sql_id,
opname, target, sofar, totalwork, round(sofar/totalwork, 4)*100 pct, units, elapsed_seconds, time_remaining time_remaining_sec, round(time_remaining/60,2) min
,sql_hash_value
-- ,message
from v$session_longops
WHERE sofar < totalwork
order by start_time desc);
-- query session waits
set lines 300
col program format a23
col event format a18
col seconds format 99,999,990
col state format a17
select w.sid, s.sql_hash_value, s.program, w.event, w.wait_time/100 t, w.seconds_in_wait seconds_in_wait, w.state, w.p1, w.p2, w.p3
from v$session s, v$session_wait w
where s.sid = w.sid and s.type = 'USER'
and s.sid = 37
-- and s.sql_hash_value = 1789726554
-- and s.sid = w.sid and s.type = 'BACKGROUND'
and w.state = 'WAITING'
order by 6 asc;
-- show actual transaction start time, and exact object
SELECT s.saddr, s.SQL_ADDRESS, s.sql_hash_value, t.START_TIME, t.STATUS, s.lockwait, s.row_wait_obj#, row_wait_file#, s.row_wait_block#, s.row_wait_row#
--, s.blocking_session
FROM v$session s, v$transaction t
WHERE s.saddr = t.ses_addr
and s.sid = 12;
-- search for the object
select owner, object_name, object_type
from dba_objects
where object_id = 73524;
SELECT owner,segment_name,segment_type
FROM dba_extents
WHERE file_id = 32
AND 238305
BETWEEN block_id AND block_id + blocks - 1;
-- open transactions
set lines 199 pages 100
col object_name for a30
COL iid for 999
col usn for 9999
col slot for 9999
col ublk for 99999
col uname for a15
col sid for 9999
col ser# for 9999999
col start_scn for 99999999999999
col osuser for a20
select * from (
select v.inst_id iid, v.XIDUSN usn, v.XIDSLOT slot, v.XIDSQN ,v. START_TIME, v.start_scn, v.USED_UBLK ublk, o.oracle_username uname,s.sid sid,s.serial# ser#, s.osuser, o.object_id oid ,d.object_name
from gv$transaction v, gv$locked_object o, dba_objects d, gv$session s
where v.XIDUSN = o.XIDUSN and v.xidslot=o.xidslot and v.xidsqn=o.xidsqn and o.object_id = d.object_id and v.addr = s.taddr order by 6,1,11,12,13) where rownum < 26;
-- search for the object in the buffer cache
select b.sid,
nvl(substr(a.object_name,1,30),
'P1='||b.p1||' P2='||b.p2||' P3='||b.p3) object_name,
a.subobject_name,
a.object_type
from dba_objects a, v$session_wait b, x$bh c
where c.obj = a.object_id(+)
and b.p1 = c.file#(+)
and b.p2 = c.dbablk(+)
-- and b.event = 'db file sequential read'
union
select b.sid,
nvl(substr(a.object_name,1,30),
'P1='||b.p1||' P2='||b.p2||' P3='||b.p3) object_name,
a.subobject_name,
a.object_type
from dba_objects a, v$session_wait b, x$bh c
where c.obj = a.data_object_id(+)
and b.p1 = c.file#(+)
and b.p2 = c.dbablk(+)
-- and b.event = 'db file sequential read'
order by 1;
-- if there are locks, show the locks thats are waited in the system
select sid, type, id1, id2, lmode, request, ctime, block
from v$lock
where request>0;
-- per session pga
BREAK ON REPORT
COMPUTE SUM OF alme ON REPORT
COMPUTE SUM OF mame ON REPORT
COLUMN alme HEADING "Allocated MB" FORMAT 99999D9
COLUMN usme HEADING "Used MB" FORMAT 99999D9
COLUMN frme HEADING "Freeable MB" FORMAT 99999D9
COLUMN mame HEADING "Max MB" FORMAT 99999D9
COLUMN username FORMAT a15
COLUMN program FORMAT a22
COLUMN sid FORMAT a5
COLUMN spid FORMAT a8
set pages 3000
SET LINESIZE 3000
set echo off
set feedback off
alter session set nls_date_format='yy-mm-dd hh24:mi:ss';
SELECT sysdate, s.username, SUBSTR(s.sid,1,5) sid, p.spid, logon_time,
SUBSTR(s.program,1,22) program , s.process pid_remote,
ROUND(pga_used_mem/1024/1024) usme,
ROUND(pga_alloc_mem/1024/1024) alme,
ROUND(pga_freeable_mem/1024/1024) frme,
ROUND(pga_max_mem/1024/1024) mame,
decode(a.IO_CELL_OFFLOAD_ELIGIBLE_BYTES,0,'No','Yes') Offload,
s.sql_id
FROM v$session s,v$process p, v$sql a
WHERE s.paddr=p.addr
and s.sql_id=a.sql_id
ORDER BY pga_max_mem, logon_time;
-- pga breakdown
SELECT pid, category, allocated, used, max_allocated
FROM v$process_memory
WHERE pid = (SELECT pid
FROM v$process
WHERE addr= (select paddr
FROM v$session
WHERE sid = &sid))
-- UNDO
/* Shows active (in progress) transactions -- feed the db_block_size to multiply with t.used_ublk */
/* select value from v$parameter where name = 'db_block_size'; */
select sid, serial#,s.status,username, terminal, osuser,
t.start_time, r.name, (t.used_ublk*8192)/1024 USED_kb, t.used_ublk "ROLLB BLKS",
decode(t.space, 'YES', 'SPACE TX',
decode(t.recursive, 'YES', 'RECURSIVE TX',
decode(t.noundo, 'YES', 'NO UNDO TX', t.status)
)) status
from sys.v_$transaction t, sys.v_$rollname r, sys.v_$session s
where t.xidusn = r.usn
and t.ses_addr = s.saddr;
-- TEMP, show user currently using space in temp space
select se.username
,se.sid
,se.serial#
,su.extents
,su.blocks * to_number(rtrim(p.value))/1024/1024 as Space
,tablespace
,segtype
from v$sort_usage su
,v$parameter p
,v$session se
where p.name = 'db_block_size'
and su.session_addr = se.saddr
order by se.username, se.sid;
-- To report the info on temp usage used...
select swa.sid, vs.process, vs.osuser, vs.machine,vst.sql_text, vs.sql_id "Session SQL_ID",
swa.sql_id "Active SQL_ID", trunc(swa.tempseg_size/1024/1024)"TEMP TOTAL MB"
from v$sql_workarea_active swa, v$session vs, v$sqltext vst
where swa.sid=vs.sid
and vs.sql_id=vst.sql_id
and piece=0
and swa.tempseg_size is not null
order by "TEMP TOTAL MB" desc;
-- a quick TEMP script for threshold
echo "TEMP_Threshold: $TMP_THRSHLD"
sqlplus -s << EOF | read GET_TMP
/ as sysdba
set head off
set pagesize 0
select sum(trunc(swa.tempseg_size/1024/1024))"TEMP TOTAL MB"
from v\$sql_workarea_active swa;
EOF
-- Oracle also provides single-block read statistics for every database file in the V$FILESTAT view. The file-level single-block average wait time can be calculated by dividing the SINGLEBLKRDTIM with the SINGLEBLKRDS, as shown next. (The SINGLEBLKRDTIM is in centiseconds.) You can quickly discover which files have unacceptable average wait times and begin to investigate the mount points or devices and ensure that they are exclusive to the database
select a.file#,
b.file_name,
a.singleblkrds,
a.singleblkrdtim,
a.singleblkrdtim/a.singleblkrds average_wait
from v$filestat a, dba_data_files b
where a.file# = b.file_id
and a.singleblkrds > 0
order by average_wait;
--------------------
-- BUFFER CACHE
--------------------
/*This dynamic view has an entry for each block in the database buffer cache. The status are:
free : Available ram block. It might contain data but it is not currently in use.
xcur :Block held exclusively by this instance
scur :Block held in cache, shared with other instance
cr :Block for consistent read
read :Block being read from disk
mrec :Block in media recovery mode
irec :Block in instance (crash) recovery mode
If it is needed to investigate the buffer cache you can use the following script:*/
SELECT count(*), db.object_name, tb.name
FROM v$bh bh, dba_objects db, v$tablespace tb
WHERE bh.objd = db.object_id
AND bh.TS# = TB.TS#
AND db.owner NOT IN ('SYS', 'SYSTEM')
GROUP BY db.object_name, bh.TS#, tb.name
ORDER BY 1 ASC;
-- get block
select block#,file#,status from v$bh where objd = 46186
-- get touch count
select tch, file#, dbablk,
case when obj = 4294967295
then 'rbs/compat segment'
else (select max( '('||object_type||') ' ||
owner || '.' || object_name ) ||
decode( count(*), 1, '', ' maybe!' )
from dba_objects
where data_object_id = X.OBJ )
end what
from (
select tch, file#, dbablk, obj
from x$bh
where state <> 0
order by tch desc
) x
where rownum <= 5
/
--shows touch count for tables/indexes. Use to determine tables/indexes to keep
select decode(s.buffer_pool_id,0,'DEFAULT',1,'KEEP',2,'RECYCLE') buffer_pool,
s.owner, s.segment_name, s.segment_type,count(bh.obj) blocks, round(avg(bh.tch),2) avg_use, max(bh.tch) max_use
from sys_dba_segs s, X$BH bh where s.segment_objd = bh.obj
group by decode(s.buffer_pool_id,0,'DEFAULT',1,'KEEP',2,'RECYCLE'), s.segment_name, s.segment_type, s.owner
order by decode(s.buffer_pool_id,0,'DEFAULT',1,'KEEP',2,'RECYCLE'), count(bh.obj) desc,
round(avg(bh.tch),2) desc, max(bh.tch) desc;