DBA Scripts
DBA Scripts
=============================================
Note:
This event signifies that the user process is reading buffers into the SGA buffer
cache and is waiting for a physical I/O call to return. A db file scattered read
issues a scatter-read to read the data into multiple discontinuous memory
locations. A scattered read is usually a multiblock read. It can occur for a fast
full scan (of an index) in addition to a full table scan.
The db file scattered read wait event identifies that a full table scan is
occurring. When performing a full table scan into the buffer cache, the blocks read
are read into memory locations that are not physically adjacent to each other. Such
reads are called scattered read calls, because the blocks are scattered throughout
memory. This is why the corresponding wait event is called 'db file scattered
read'. Multiblock (up to DB_FILE_MULTIBLOCK_READ_COUNT blocks) reads due to full
table scans into the buffer cache show up as waits for 'db file scattered read'.
DB_FILE_SCATTERED_READ_WAIT_DETAIL:
====================================
Note:
This wait indicates that there are some buffers in the buffer cache that multiple
processes are attempting to access concurrently. Query V$WAITSTAT for the wait
statistics for each class of buffer. Common buffer classes that have buffer busy
waits include data block, segment header, undo header, and undo block.
TYPE_OF_SEGMENT_CONTENDED_FOR
===============================
SELECT class, count FROM V$WAITSTAT WHERE count > 0 ORDER BY count DESC;
Wait event
===========
column seq# format 99999
column EVENT format a30
column p2 format 999999
column STATE format a10
column WAIT_T format 9999
select SID,SEQ#,EVENT,P1,P2,WAIT_TIME WAIT_T,SECONDS_IN_WAIT,STATE
from v$session_wait
where sid = '&sid' ;
SELECT count(*), event FROM v$session_wait WHERE wait_time = 0 AND event NOT IN
('smon
timer','pmon timer','rdbms ipc message','SQL*Net message from client') GROUP BY
event ORDER BY 1
DESC;
To find Wait event Most of the time the session waited for
============================================================
Wait events
Sessions having Wait Event "sql*net message from client" from more than 1Hour
select
s.sid,s.process,S.STATUS,s.program,s.module,s.sql_hash_value,s.last_call_et/3600
Last_Call_Et_HRS
from v$session s, v$session_Wait w
where w.sid=s.sid and w.event='SQL*Net message from client'
and s.module='&Module_name'
order by 6 desc;
Segment Statistics
=====================
select
object_name,
statistic_name,
value
from
V$SEGMENT_STATISTICS
where object_name ='SOURCE$';
V$SYSTEM_EVENT
Example
select SID, STATUS, LAST_CALL_ET, SERIAL# from v$session where SID in (select
SESSION_ID
from v$locked_object where OBJECT_ID in (select OBJECT_ID from dba_objects
where
OBJECT_NAME='MSC_ST_SALES_ORDERS'));
OR
If session Marked for kill, then identify and kill the associated Server Process of
the session using any of the session details script.
Kill -9 <SPID>
Note:
Library Cache contention is a serious issue. In most cases it would be good to
analyze what is holding the library cache lock and killing it will resolve the
issue. Library cache events can even bring the database to a hang state. It�s a
good idea to identify and kill appropriately as early as possible. But do not kill
any mandatory processes or sessions as it may lead to an outage. Contact Oracle
support for critical issues.
Library cache resource types waited for over the life of the instance
========================================================================
select sid,substr(event,1,30),wait_time
from v$session_wait
where sid in (select sid from x$kglpn , v$session
where KGLPNHDL in (select p1raw from v$session_wait
where wait_time=0 and event like 'library cache%')
and KGLPNMOD <> 0
and v$session.saddr=x$kglpn.kglpnuse );
Note:
Sometimes using the library query below to identify the holding sessions can cause
temp tablespace to run out of space�.
ReWritten SQL
select /*+ ordered */ w1.sid waiting_session,
h1.sid holding_session,
w.kgllktype lock_or_pin,
w.kgllkhdl address,
decode(h.kgllkmod, 0, 'None', 1, 'Null', 2, 'Share', 3, 'Exclusive',
'Unknown') mode_held,
decode(w.kgllkreq, 0, 'None', 1, 'Null', 2, 'Share', 3, 'Exclusive',
'Unknown') mode_requested
from dba_kgllock w, dba_kgllock h, v$session w1, v$session h1
where
(((h.kgllkmod != 0) and (h.kgllkmod != 1)
and ((h.kgllkreq = 0) or (h.kgllkreq = 1)))
and
(((w.kgllkmod = 0) or (w.kgllkmod= 1))
and ((w.kgllkreq != 0) and (w.kgllkreq != 1))))
and w.kgllktype = h.kgllktype
and w.kgllkhdl = h.kgllkhdl
and w.kgllkuse = w1.saddr
and h.kgllkuse = h1.saddr;
SELECT s.sid,
waiter.p1raw w_p1r,
holder.event h_wait,
holder.p1raw h_p1r,
holder.p2raw h_p2r,
holder.p3raw h_p2r,
count(s.sid) users_blocked,
sql.hash_value
FROM
v$sql sql,
v$session s,
x$kglpn p,
v$session_wait waiter,
v$session_wait holder
WHERE
s.sql_hash_value = sql.hash_value and
p.kglpnhdl=waiter.p1raw and
s.saddr=p.kglpnuse and
waiter.event like 'library cache pin' and
holder.sid=s.sid
GROUP BY
s.sid,
waiter.p1raw ,
holder.event ,
holder.p1raw ,
holder.p2raw ,
holder.p3raw ,
sql.hash_value;
set pagesize 80
undefine spid
col spid for a8
col INST_ID for 99
col sid for 99999
set linesize 140
col action format a20
col logon_time format a15
col module format a13
col cli_process format a7
col cli_mach for a15
col status format a10
col username format a10
col event for a20
col program for a20
col "Last SQL" for a30
col last_call_et_hrs for 999.99
col sql_hash_value for 9999999999999
select p.INST_ID,p.spid,s.sid, s.serial#, s.status,s.last_call_et/3600
last_call_et_hrs ,
s.process cli_process,s.machine cli_mach,sw.event,
s.action,s.module,s.program,s.sql_hash_value,t.disk_reads,lpad(t.sql_text,30) "Last
SQL"
from gv$session s, gv$sqlarea t,gv$process p,gv$session_wait sw
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.sid=sw.sid and
sw.event like '%library cache%'
order by p.spid;
select sid
from gv$session_wait where wait_time=0
and event like 'library cache%';
This script shows the Library cache resource types waited for over the life of the
instance
===================================================================================
========
set linesize 152
column average_wait format 9999990.00
col event for a30
col HANDLE for a20
col PIN_ADDR for a20
col TYPE for a20
col OBJECT_NAME for a35
col LOCK_ADDR for a30
Process ids/sid/pid
====================
Session details
=================
Last SQL
col username for a10
col "Last SQL" for a65
col process for a10
set pagesize 48
select s.username, s.sid,s.process, s.status,t.sql_text "Last SQL"
from gv$session s, gv$sqlarea t
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
s.sid = '&sid';
Wait event
===========
select username,s.sid,
t.used_ublk,t.used_urec
from v$transaction t,v$session s
where t.addr=s.taddr and
s.sid in (159,610);
undefine spid
col spid for a10
set linesize 150
col action format a10
col logon_time format a16
col module format a13
col cli_process format a7
col cli_mach for a15
col status format a10
col username format a10
col last_call_et for 9999.99
select p.spid,s.sid, s.serial#, s.status, s.username, s.action,
to_char(s.logon_time, 'DD-MON-YY, HH24:MI') logon_time,
s.module,s.last_call_et/3600 last_call_et,s.process cli_process,s.machine cli_mach
from gv$session s, gv$process p
where p.addr=s.paddr and p.spid= '&spid';
undefine spid
col spid for a6
col sid for 99999
set linesize 140
col action format a20
col logon_time format a15
col module format a13
col cli_process format a7
col cli_mach for a10
col status format a10
col username format a10
select p.spid,s.sid, s.serial#, s.status, s.username, s.action,
to_char(s.logon_time, 'DD-MON-YY, HH24:MI') logon_time,
s.module,s.last_call_et/3600,s.process cli_process,s.machine cli_mach
from gv$session s, gv$process p
where p.addr=s.paddr and s.process = '&cli_process';
This script points to the session that is holding a library cache lock for any
object. A typical session will wait on a library cache lock when when it is trying
to modify the object definition. The object may be a package/procedure or just a
table or index definition
0, 'None',
1, 'Null',
2, 'Row-S (SS)',
3, 'Row-X (SX)',
4, 'Share',
5, 'S/Row-X (SSX)',
6, 'Exclusive'
EXCLUSIVE (X) Lock allows queries but nothing else.
SHARE (S) Lock allows queries but not updates.
ROW SHARE (RS) Lock allows concurrent process access to table. Resource
may not be locked exclusively.
ROW EXCLUSIVE (RX) Same as row share but no share mode locking. Updates,
deletes and inserts use this lock mode.
SHARE ROW EXCLUSIVE (SRX) Lock used to do selective updates and to allow other
processes to look at rows in table but not lock table in
share mode or to update any rows. (Never used).
@$ORACLE_HOME/rdbms/admin/utllockt.sql
From v$lock
select * from v$lock where block>0;
From dba_locks
select distinct BLOCKING_OTHERS from dba_locks;
Blockers-Waiters Info
col SESS for a12
set lines 132
SELECT DECODE(request,0,'Holder: ','Waiter: ')||sid sess,
id1, id2, lmode, request, type
FROM V$LOCK
WHERE (id1, id2, type) IN
(SELECT id1, id2, type FROM V$LOCK WHERE request>0)
ORDER BY id1, request;
select distinct holding_session from dba_waiters where holding_session not in
(select
waiting_session from dba_waiters);
Blocking session
=================
Blocker-waiter
==============
set linesize 80
col sess for a15
SELECT DECODE(request,0,'Holder: ','Waiter: ')||trim(sid) sess,
id1, id2, lmode, request, type
FROM V$LOCK
WHERE (id1, id2, type) IN
(SELECT id1, id2, type FROM V$LOCK WHERE request>0)
ORDER BY id1, request;
select
INST_ID, SID, SERIAL#, MODULE, ACTION, status
from gv$session
where
(SID, inst_id) in (select sid, inst_id from gv$lock where block=1);
select sid,serial#,username,osuser,program,machine,status,to_char(logon_time,'DD-
MON-YYYY HH24:MI:SS') "LOGON_TIME",last_call_et/3600 " LAST_CALL_ET_HRS" from
v$session where status='ACTIVE' AND username is not null and last_call_et/3600 >1
order by 9 desc;
Active transaction
select username,s.sid,
t.used_ublk,t.used_urec
from v$transaction t,v$session s
where t.addr=s.taddr and
s.sid= '&sid' ;
DBMS_OUTPUT.PUT_LINE('-------------------------------------------------------------
----');
DBMS_OUTPUT.PUT_LINE(' Database session detail for the shadow process ');
DBMS_OUTPUT.PUT_LINE('-------------------------------------------------------------
----');
for m in cur1 loop
DBMS_OUTPUT.ENABLE(50000);
DBMS_OUTPUT.PUT_LINE(' ');
DBMS_OUTPUT.PUT_LINE('SID............ : ' || m.sid);
DBMS_OUTPUT.PUT_LINE('SERIAL#........ : ' || m.serial);
DBMS_OUTPUT.PUT_LINE('USERNAME....... : ' || m.username);
DBMS_OUTPUT.PUT_LINE('STATUS......... : ' || m.status);
DBMS_OUTPUT.PUT_LINE('Machine........ : ' || m.machine);
DBMS_OUTPUT.PUT_LINE('Terminal....... : ' || m.terminal);
DBMS_OUTPUT.PUT_LINE('Program........ : ' || m.program);
DBMS_OUTPUT.PUT_LINE('Module......... : ' || m.module);
DBMS_OUTPUT.PUT_LINE('Action......... : ' || m.action);
DBMS_OUTPUT.PUT_LINE('SQL Hash Value. : ' || m.sql_hash_value);
DBMS_OUTPUT.PUT_LINE('Logon Time..... : ' || m.logontime);
DBMS_OUTPUT.PUT_LINE('Last Call Et... : ' || m.last_call_et);
DBMS_OUTPUT.PUT_LINE('Process ID..... : ' || m.proc);
DBMS_OUTPUT.PUT_LINE('SPID........... : ' || m.spid);
DBMS_OUTPUT.PUT_LINE('Session Waiting for event:'||m.event);
DBMS_OUTPUT.PUT_LINE('Session state ...........:'||m.state);
for rec in ( select distinct(sql_text) sql_text from v$session s,v$sql v where
s.sql_hash_value=v.hash_value and s.sql_address=v.address and s.sid=m.sid)
loop
dbms_output.put_line(substr('SQL_TEXT is..........:'||rec.sql_text,1,255));
end loop;
DBMS_OUTPUT.PUT_LINE('-------------------------------------------------------------
-------');
DBMS_OUTPUT.PUT_LINE(' ');
end loop;
end;
/
-- dbms_output.put_line(SUBSTR('SQL_TEXT is..........:'||
rec.sql_text,1,255));
Another version
DBMS_OUTPUT.PUT_LINE('-------------------------------------------------------------
----');
DBMS_OUTPUT.PUT_LINE(' Database session detail for the shadow process ');
DBMS_OUTPUT.PUT_LINE('-------------------------------------------------------------
----');
for m in cur1 loop
DBMS_OUTPUT.ENABLE(50000);
DBMS_OUTPUT.PUT_LINE(' ');
DBMS_OUTPUT.PUT_LINE('SID............ : ' || m.sid);
DBMS_OUTPUT.PUT_LINE('SERIAL#........ : ' || m.serial);
DBMS_OUTPUT.PUT_LINE('USERNAME....... : ' || m.username);
DBMS_OUTPUT.PUT_LINE('STATUS......... : ' || m.status);
DBMS_OUTPUT.PUT_LINE('Machine........ : ' || m.machine);
DBMS_OUTPUT.PUT_LINE('Terminal....... : ' || m.terminal);
DBMS_OUTPUT.PUT_LINE('Program........ : ' || m.program);
DBMS_OUTPUT.PUT_LINE('Module......... : ' || m.module);
DBMS_OUTPUT.PUT_LINE('Action......... : ' || m.action);
DBMS_OUTPUT.PUT_LINE('SQL Hash Value. : ' || m.sql_hash_value);
DBMS_OUTPUT.PUT_LINE('Logon Time..... : ' || m.logontime);
DBMS_OUTPUT.PUT_LINE('Last Call Et... : ' || m.last_call_et);
DBMS_OUTPUT.PUT_LINE('Process ID..... : ' || m.proc);
DBMS_OUTPUT.PUT_LINE('SPID........... : ' || m.spid);
DBMS_OUTPUT.PUT_LINE('Session Waiting for event:'||m.event);
DBMS_OUTPUT.PUT_LINE('Session state ...........:'||m.state);
DBMS_OUTPUT.PUT_LINE('-------------------------------------------------------------
-------');
DBMS_OUTPUT.PUT_LINE(' ');
end loop;
end;
/
undefine spid
set pagesize 40
col INST_ID for 99
col spid for a10
set linesize 150
col action format a10
col logon_time format a16
col module format a13
col cli_process format a7
col cli_mach for a15
col status format a10
col username format a10
col last_call_et for 9999.99
col sql_hash_value for 9999999999999
select p.INST_ID,p.spid,s.sid, s.serial#, s.status, s.username, s.action,
to_char(s.logon_time, 'DD-MON-YY, HH24:MI') logon_time,
s.module,s.program,s.last_call_et/3600 last_call_et ,s.process
cli_process,s.machine
cli_mach,s.sql_hash_value
from gv$session s, gv$process p
where p.addr=s.paddr and p.spid in(&SPID);
undefine sid
col "Last SQL" for a70
select s.username, s.sid, s.serial#,t.sql_text "Last SQL"
from gv$session s, gv$sqlarea t
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
s.sid in (&SIDs);
select s.sid,
s.serial#,
'*'||s.process||'*' Client,
p.spid Server,
s.sql_address,
s.sql_hash_value,
s.username,
s.action,
s.program || s.module,
s.terminal,
s.machine,
s.status,
--s.last_call_et
s.last_call_et/3600
from gv$session s, gv$process p
where p.addr=s.paddr and
s.sid=nvl('&sid',s.sid) and
p.spid=nvl('&spid',p.spid) and
s.status='ACTIVE' and
--(s.last_call_et/3600)<1 and
nvl(s.process,-1) = nvl('&ClientPid',nvl(s.process,-1));
Active sessions
================
select (select count(*) from v$session) sessions, (select count(*) from v$process)
processes from dual;
SELECT count(*) FROM v$session where last_call_et > 43200 and username is not null
AND
STATUS='INACTIVE';
SELECT count(*) FROM v$session where last_call_et > 3600 and username is not null
AND
STATUS='INACTIVE';
select piece,sql_text from v$sqltext where HASH_VALUE = &hash and ADDRESS ='&addr'
order by piece;
select piece,sql_text from v$sqltext where ADDRESS ='&addr' order by piece;
***APPS 11i*****
undefine sid
col "Last SQL" for a70
select s.username, s.sid, t.sql_text "Last SQL"
from gv$session s, gv$sqlarea t
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
s.sid = '&sid';
end loop;
end;
select count(s.sid) from gv$session s where s.program || s.module like ('%JDBC Thin
Client%');
SELECT count(*),module FROM v$session where last_call_et > 43200 and username is
not null AND
STATUS='INACTIVE' group by module;
select count(status) Count, status, machine, program from v$session where program
like '%JDBC%'
group by status, machine,program having status = 'INACTIVE' order by 1;
Session distribution
========================
select s.sid,
s.serial#,
'*'||s.process||'*' Client,
p.spid Server,
s.sql_address,
s.sql_hash_value,
s.username,
s.action,
s.program || s.module,
s.terminal,
s.machine,
s.status,
--s.last_call_et
s.last_call_et/3600
from gv$session s, gv$process p
where p.addr=s.paddr
and s.osuser='&osuser';
select b.sql_text,a.sid,a.serial#,b.users_executing,
b.rows_processed,a.last_call_et/3600 Hrs from v$sqlarea b,v$session a where
b.sql_text like '&object_name' and a.sql_address=b.address;
select b.sql_text,a.sid,a.serial#,b.users_executing,
b.rows_processed,a.last_call_et/3600 Hrs from gv$sqlarea b,gv$session a where
sql_text like '%DTEA_PA_REPORTING_AGT_HISTO%' and a.sql_address=b.address;
Select
a.session_id, b.sql_text,
count(*)
from
v$active_session_history a,v$sql b
where
a.session_state= 'ON CPU' and
a.SAMPLE_TIME > sysdate - (120/(24*60)) and a.sql_id=b.sql_id and b.sql_text like
'%WF_ITEM_ATTRIBUTE_VALUES%'
group by a.session_id,b.sql_text
order by
count(*) desc;
Listing out details of program thru SQLID
================================================
Select
a.session_id, b.sql_text,a.program,a.module,a.action
from
v$active_session_history a,v$sql b
where
a.sql_id=b.sql_id and b.sql_id like '%fk9qzystpcazs%';
How to find apps user when you know the o/s pid in 11i for Forms users (f60webmx
100% CPU)
===================================================================================
================
select ' Sid, Serial#, Aud sid : '|| s.sid||' , '||s.serial#||' , '||
s.audsid||chr(10)|| ' DB User / OS User : '||s.username||
' / '||s.osuser||chr(10)|| ' Machine - Terminal : '||
s.machine||' - '|| s.terminal||chr(10)|| s.module||'-'||s.action ||
' OS Process Ids : '||
s.process||' (Client) '||p.spid||' - '||p.pid||' (Server)'|| chr(10)||
' Client Program Name : '||s.program "Session Info"
from v$process p,v$session s
where p.addr = s.paddr
and s.sid = '&sid';
###Actual Script#######
Sid.sql
undefine sid_number
undefine spid_number
rem accept sid_number number prompt "pl_enter_sid:"
select sql_text
from v$sqltext , v$session
where v$sqltext.address = v$session.sql_address
and sid = &sid_number
order by piece
/
PROMPT
PROMPT Event Wait Information
PROMPT ----------------------
select ' SID '|| &sid_number ||' is waiting on event : ' || x.event || chr(10)
||
' P1 Text : ' || x.p1text || chr(10) ||
' P1 Value : ' || x.p1 || chr(10) ||
' P2 Text : ' || x.p2text || chr(10) ||
' P2 Value : ' || x.p2 || chr(10) ||
' P3 Text : ' || x.p3text || chr(10) ||
' P3 Value : ' || x.p3
from v$session_wait x
where x.sid= &sid_number
/
PROMPT
PROMPT Session Statistics
PROMPT ------------------
PROMPT
PROMPT Sort Information
PROMPT ----------------
set heading on
set verify on
clear column
###############################Sql queries to check ACTIVE / INACTIVE Sessions
================================================================================
INACTIVE SESSIONS
INACTIVE
INACTIVE PROGRAMS
set pagesize 40
col INST_ID for 99
col spid for a10
set linesize 150
col PROGRAM for a10
col action format a10
col logon_time format a16
col module format a13
col cli_process format a7
col cli_mach for a15
col status format a10
col username format a10
col last_call_et_Hrs for 9999.99
col sql_hash_value for 9999999999999col username for a10
set linesize 152
set pagesize 80
col "Last SQL" for a60
col elapsed_time for 999999999999
select p.spid, s.sid,s.last_call_et/3600 last_call_et_Hrs
,s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
and s.last_call_et > (3600)
order by last_call_et;
set pagesize 40
col INST_ID for 99
col spid for a10
set linesize 150
col PROGRAM for a10
col action format a10
col logon_time format a16
col module format a13
col cli_process format a7
col cli_mach for a15
col status format a10
col username format a10
col last_call_et for 9999.99
col sql_hash_value for 9999999999999col username for a10
set linesize 152
set pagesize 80
col "Last SQL" for a60
col elapsed_time for 999999999999
select p.spid, s.sid,s.last_call_et/3600 last_call_et ,s.status,s.action,
s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
and s.program='JDBC Thin Client'
and s.last_call_et > 3600
order by last_call_et;
SELECT COUNT(P.SPID)
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
and s.program='JDBC Thin Client'
and s.last_call_et > 3600
order by last_call_et;
FORMS
TOTAL FORM SESSIONS
UNIQUE SPID
select unique(p.spid)
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
and s.action like 'FRM:%'
and s.last_call_et > 3600;
COUNT FORMS
select COUNT(p.spid)
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
and s.action like 'FRM:%'
and s.last_call_et > 3600;
select COUNT(p.spid)
from gv$session s,gv$process p
where
p.addr=s.paddr and
s.status='INACTIVE'
and s.action like 'FRM:%'
and s.last_call_et > 3600
AND S.SQL_HASH_VALUE=0;
GROUP BY ACTION
INACTIVE FORM
set pagesize 40
col INST_ID for 99
col spid for a10
set linesize 150
col PROGRAM for a10
col action format a10
col logon_time format a16
col module format a13
col cli_process format a7
col cli_mach for a15
col status format a10
col username format a10
col last_call_et for 9999.99
col sql_hash_value for 9999999999999col username for a10
set linesize 152
set pagesize 80
col "Last SQL" for a30
col elapsed_time for 999999999999
select p.spid, s.sid,s.process cli_process,s.last_call_et/3600 last_call_et ,
s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
and s.action like ('FRM%')
and s.last_call_et > (3600*3)
order by last_call_et;
ACTIVE
MODULE
set pagesize 40
col INST_ID for 99
col spid for a10
set linesize 150
col PROGRAM for a10
col action format a10
col logon_time format a16
col module format a13
col cli_process format a7
col cli_mach for a15
col status format a10
col username format a10
col last_call_et for 9999.99
col sql_hash_value for 9999999999999col username for a10
set linesize 152
set pagesize 80
col "Last SQL" for a30
col elapsed_time for 999999999999
select p.spid, s.sid,s.process cli_process,s.last_call_et/3600 last_call_et ,
s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr
and s.MODULE like ('&MODULE_NAME_1HR%')
and s.last_call_et > ('&TIME_HRS' * 3600)
order by last_call_et;
select p.spid, s.sid,s.process cli_process,s.last_call_et/3600 last_call_et ,
s.status,s.action,s.module,s.program
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
p.addr=s.paddr
and s.MODULE like ('%TOAD%')
Order by last_call_et;
TOAD SESSIONS
hash value=0
Unique Actions
GROUP BY program
Select
sysdate sample_time,
s.sid "SESSION_ID" ,
decode(w.WAIT_TIME, 0,'WAITING','ON CPU') "SESSION_STATE",
s.serial# "SESSION_SERIAL#",
s.user# "USER_ID",
s.sql_address "SQL_ADDRESS",
s.sql_hash_value "SQL_HASH" ,
s.command "SQL_OPCODE" ,
s.type "SESSION_TYPE" ,
w.event "EVENT",
w.p1 "P1" ,
w.p2 "P2" ,
w.p3 "P3" ,
s.ROW_WAIT_OBJ# "CURRENT_OBJ#",
s.ROW_WAIT_FILE# "CURRENT_FILE#",
s.ROW_WAIT_BLOCK# "CURRENT_BLOCK#",
s.program "PROGRAM",
s.module "MODULE",
s.action "ACTION"
from
v$session s ,
v$session_wait w
where
s.sid != ( select distinct sid from v$mystat where rownum < 2 ) and
w.sid = s.sid and
( (
/* status Active - seems inactive & "on cpu"=> not on CPU */
w.wait_time != 0 and /* on CPU */
s.status='ACTIVE' /* ACTIVE */
)
or
lower(w.event) not in /* waiting and the wait event is not idle */
(
'queue monitor wait',
'null event',
'pl/sql lock timer',
'px deq: execution msg',
'px deq: table q normal',
'px idle wait',
'sql*net message from client',
'sql*net message from dblink',
'dispatcher timer',
'lock manager wait for remote message',
'pipe get',
'pmon timer',
'queue messages',
'rdbms ipc message',
'slave wait',
'smon timer',
'virtual circuit status',
'wakeup time manager',
'i/o slave wait',
'jobq slave wait',
'queue monitor wait',
'SQL*Net message from client'
)
);
select
/* if sid not found in v$session then disconnected */
select decode(nvl(to_char(s.sid),-1),-1,'DISCONNECTED','CONNECTED')
"STATUS",
topsession.session_id "SESSION_ID",
u.name "NAME",
topsession.program "PROGRAM",
max(topsession.CPU) "CPU",
max(topsession.WAITING) "WAITING",
max(topsession.IO) "IO",
max(topsession.TOTAL) "TOTAL"
from (select
ash.session_id,
ash.session_serial#,
ash.user_id,
ash.program,
sum(decode(ash.session_state,'ON CPU',1,0)) "CPU",
sum(decode(ash.session_state,'WAITING',1,0)) -
sum(decode(ash.session_state,'WAITING',
decode(en.wait_class,'User I/O',1, 0 ), 0)) "WAITING" ,
sum(decode(ash.session_state,'WAITING',
decode(en.wait_class,'User I/O',1, 0 ), 0)) "IO" ,
sum(decode(session_state,'ON CPU',1,1)) "TOTAL"
from v$active_session_history ash,
v$event_name en
where en.event# = ash.event#
group by session_id,user_id,session_serial#,program
order by sum(decode(session_state,'ON CPU',1,1))) topsession,
v$session s,
user$ u
where
u.user# =topsession.user_id and
topsession.session_id = s.sid (+) and
topsession.session_serial# = s.serial# (+)
group by topsession.session_id, topsession.session_serial#, topsession.user_id,
topsession.program, s.username,s.sid,s.paddr,u.name
order by max(topsession.TOTAL) desc;
/* outer join to v$session because the session might be disconnected */
Select
session_id,
count(*)
from
v$active_session_history
where
session_state='WAITING' and
SAMPLE_TIME > SYSDATE - (60/(24*60)) and rownum<11
group by
session_id
order by
count(*) desc;
elect
session_id,
count(*)
from
v$active_session_history
where
session_state= 'ON CPU' and
SAMPLE_TIME > sysdate - (120/(24*60)) and rownum<11
group by session_id
order by
count(*) desc;
SELECT name, xacts "ACTIVE TRANSACTIONS" FROM v$rollname, v$rollstat WHERE status =
'PENDING OFFLINE' AND v$rollname.usn = v$rollstat.usn;
spool shrink_em.sql
select 'alter rollback segment '||segment_name||' shrink to 2;' from
dba_rollback_segs where tablespace_name='RBSTS';
spool off
@shrink_em.sql
set pagesize 0
set termout off
spool shrink_rollback_segs.tmp
select
'alter rollback segment ' || segment_name || ' shrink;'
from
sys.dba_rollback_segs
where
status = 'ONLINE'
/
spool off
@shrink_rollback_segs.tmp
select
n.name,
s.optsize,
( ceil(s.extents * (s.optsize + s.aveshrink)/(s.rssize + p.value))
* (s.rssize + p.value)
/ s.extents
) - p.value new_opt
from
( select
optsize,
avg(rssize) rssize,
avg(extents) extents,
max(wraps) wraps,
max(shrinks) shrinks,
avg(aveshrink) aveshrink
from
sys.v_$rollstat
where
optsize is not null and
status = 'ONLINE'
group by
optsize
) s,
( select
kvisval value
from
sys.x_$kvis
where
kvistag = 'kcbbkl' ) p,
sys.v_$rollstat r,
sys.v_$rollname n
where
s.shrinks > 1 and
s.shrinks > s.wraps / ceil(s.optsize / ((s.rssize + p.value) / s.extents)) and
r.optsize = s.optsize and
r.status = 'ONLINE' and
n.usn = r.usn
/
select
b.segment_name,b.tablespace_name,a.extents,a.rssize,a.xacts,a.optsize,a.shrinks,a.w
raps,a.status from v$rollstat a, dba_rollback_segs b where b.segment_id = a.usn;
SQL> select 'alter rollback segment ' || segment_name || ' shrink;' from
sys.dba_rollback_segs where status = 'ONLINE';
'ALTERROLLBACKSEGMENT'||SEGMENT_NAME||'SHRINK;'
-------------------------------------------------------------
alter rollback segment SYSTEM shrink;
alter rollback segment R01 shrink;
alter rollback segment R02 shrink;
alter rollback segment R03 shrink;
alter rollback segment R04 shrink;
SEGMENT_NAME
TABLESPACE_NAME (BYTES)/1024/1024 BLOCKS EXTENTS
---------------------------------------------------------------------------------
------------------------- ----------------- ---------- ----------
SYSTEM
SYSTEM 1.328125 170 17
R0
2 256 2
R01
RBS1 50 6400 10
R02
50 6400 10
R03
50 6400 10
R04
50 6400 10
6 rows selected.
SEGMENT_NAME
TABLESPACE_NAME (BYTES)/1024/1024 BLOCKS EXTENTS
---------------------------------------------------------------------------------
------------------------- ----------------- ---------- ----------
SYSTEM
SYSTEM 1.328125 170 17
R0
2 256 2
R01
RBS1 50 6400 10
R02
345 44160 69
R03
50 6400 10
R04
50 6400 10
6 rows selected.
SQL> SELECT name, xacts "ACTIVE TRANSACTIONS" FROM v$rollname, v$rollstat WHERE
status = 'PENDING OFFLINE' AND v$rollname.usn = v$rollstat.usn;
no rows selected
no rows selected
SQL> select
b.segment_name,b.tablespace_name,a.extents,a.rssize,a.xacts,a.optsize,a.shrinks,a.w
raps,a.status from v$rollstat a, dba_rollback_segs b where b.segment_id = a.usn;
Approaching Max extents different formula (less than 500 extents to extend)
Script to generate �alter table� and �alter index� statements to set maxextents to
unlimited
Checking for the segment which is approaching max extents (max extents reached)
To check instance-wise total allocated, total used TEMP for both rac and non-rac
Additional checks
Database altered.
cursor bigtemp_sids is
select * from (
select s.sid,
s.status,
s.sql_hash_value sesshash,
u.SQLHASH sorthash,
s.username,
u.tablespace,
sum(u.blocks*p.value/1024/1024) mbused ,
sum(u.extents) noexts,
nvl(s.module,s.program) proginfo,
floor(last_call_et/3600)||':'||
floor(mod(last_call_et,3600)/60)||':'||
mod(mod(last_call_et,3600),60) lastcallet
from v$sort_usage u,
v$session s,
v$parameter p
where u.session_addr = s.saddr
and p.name = 'db_block_size'
group by s.sid,s.status,s.sql_hash_value,u.sqlhash,s.username,u.tablespace,
nvl(s.module,s.program),
floor(last_call_et/3600)||':'||
floor(mod(last_call_et,3600)/60)||':'||
mod(mod(last_call_et,3600),60)
order by 7 desc,3)
where rownum < 11;
ls -ltr|tail
Now, the above query and the storage clause of the old 'create tablespace TEMP'
command seem to tell us the tablespace only allows temporary objects, so it should
be safe to assume that no one created any tables or other permanent objects in TEMP
by mistake, as I think Oracle would prevent that. However, just to be absolutely
certain, I decided to double-check. Checking for any tables in the tablespace is
very easy:
Checking for any other objects (views, indexes, triggers, pl/sql, etc.) is
trickier, but this query seems to work correctly - note that you'll probably need
to connect internal in order to see the sys_objects view:
-- Shows all objects which exist in the TEMP tablespace - should get
-- NO rows for this:
column owner format a20
column object_type format a30
column object_name format a40
select
o.owner ,o.object_name
,o.object_type
from sys_objects s
,dba_objects o
,dba_data_files df
where df.file_id = s.header_file
and o.object_id = s.object_id
and df.tablespace_name = 'TEMP' ;
10g onwards
select tablespace_name,
status,
count(extent_id) "Extent Count",
sum(blocks) "Total Blocks",
sum(blocks)*8/(1024*1024) total_space
from dba_undo_extents
group by tablespace_name, status;
select
sum(ssolderrcnt) "Total ORA-1555s",
round(max(maxquerylen)/60/60) "Max Query HRS",
sum(unxpstealcnt) "UNExpired STEALS",
sum(expstealcnt) "Expired STEALS"
from v$undostat
order by begin_time;
Date wise occurrence of ORA-1555
set head on
select usn,extents,round(rssize/1048576)
rssize,hwmsize,xacts,waits,optsize/1048576 optsize,shrinks,wraps
from v$rollstat where xacts>0
order by rssize;
select sid,username,
t.used_ublk ,t.used_urec
from v$transaction t,v$session s
where t.addr=s.taddr;
select tablespace_name,file_name,file_id,autoextensible,bytes/1048576
Mbytes, maxbytes/1048576 maxMbytes
from dba_data_files
where tablespace_name like '%UNDO%'
or tablespace_name like '%RBS%'
order by tablespace_name,file_name;
select tablespace_name,file_name,file_id,autoextensible,bytes/1048576
Mbytes, maxbytes/1048576 maxMbytes
from dba_data_files
where tablespace_name like '%UNDOTBS2%'
order by tablespace_name,file_name;
select file_name,tablespace_name,bytes/1024/1024,maxbytes/1024/1024,autoextensible
from dba_data_files where file_name like '%undo%' order by file_name;
select
OWNER,TABLE_NAME,TABLESPACE_NAME,STATUS,LAST_ANALYZED,PARTITIONED,DEPENDENCIES,DROP
PED from dba_tables where TABLE_NAME like 'MLC_PICK_LOCKS_DETAIL';
select
OWNER,TABLE_NAME,TABLESPACE_NAME,LAST_ANALYZED,PARTITIONED,DEPENDENCIES,DROPPED
from dba_tables where TABLE_NAME like 'APPS.XLA_AEL_GL_V';
Undo Tablespace
DBA_UNDO_EXTENTS
select s.sid,s.serial#,username,s.machine,
t.used_ublk ,t.used_urec,(rs.rssize)/1024/1024 MB,rn.name
from v$transaction t,v$session s,v$rollstat rs, v$rollname rn
where t.addr=s.taddr and rs.usn=rn.usn and rs.usn=t.xidusn and rs.xacts>0;
Total Undo Statistics
alter session set nls_date_format='dd-mon-yy hh24:mi';
set lines 120
set pages 2000
select BEGIN_TIME, END_TIME, UNDOBLKS, TXNCOUNT , MAXQUERYLEN , UNXPSTEALCNT ,
EXPSTEALCNT , SSOLDERRCNT , NOSPACEERRCNT
from v$undostat;
select 'TOTAL STATISTICS SINCE Jan 01, 2005 - STATSPACK' from dual;
set head on
set lines 152
column undotsn format 999 heading 'Undo|TS#';
column undob format 9,999,999,999 heading 'Undo|Blocks';
column txcnt format 9,999,999,999,999 heading 'Num|Trans';
column maxq format 999,999 heading 'Max Qry|Len (s)';
column maxc format 9,999,999 heading 'Max Tx|Concurcy';
column snol format 9,999 heading 'Snapshot|Too Old';
column nosp format 9,999 heading 'Out of|Space';
column blkst format a13 heading 'uS/uR/uU/|eS/eR/eU' wrap;
column unst format 9,999 heading 'Unexp|Stolen' newline;
column unrl format 9,999 heading 'Unexp|Relesd';
column unru format 9,999 heading 'Unexp|Reused';
column exst format 9,999 heading 'Exp|Stolen';
column exrl format 9,999 heading 'Exp|Releas';
column exru format 9,999 heading 'Exp|Reused';
select undotsn
, sum(undoblks) undob
, sum(txncount) txcnt
, max(maxquerylen) maxq
, max(maxconcurrency) maxc
, sum(ssolderrcnt) snol
, sum(nospaceerrcnt) nosp
, sum(unxpstealcnt)
||'/'|| sum(unxpblkrelcnt)
||'/'|| sum(unxpblkreucnt)
||'/'|| sum(expstealcnt)
||'/'|| sum(expblkrelcnt)
||'/'|| sum(expblkreucnt) blkst
from stats$undostat
where dbid in (select dbid from v$database)
and instance_number in (select instance_number from v$instance)
and end_time > to_date('01012005 00:00:00', 'DDMMYYYY HH24:MI:SS')
and begin_time < (select sysdate from dual)
group by undotsn;
Wraps
Wraps column as high values for the all segments size of rollback segments are
small for long running queries and transactions by increasing the rollback
segments size we can avoid the ORA-01555 errors
Undo Contention
prompt If any ratio is > .01 then more rollback segments are needed
Sample Output:
REM NAME WAITS GETS Ratio
REM ------------------------------ ---------- ---------- ---------
REM SYSTEM 0 269 .00000
REM R01 0 304 .00000
REM R02 0 2820 .00000
REM R03 0 629 .00000
REM R04 1 511 .00196
REM R05 0 513 .00000
REM R06 1 503 .00199
REM R07 0 301 .00000
REM R08 0 299 .00000
Looking at the tcl script to see what sql gets performed to determine rollback
segment contention
* select
tablespace_name,segment_name,initial_extent,next_extent,min_extents,max_extents,sta
tus
from dba_rollback_segs
where status='ONLINE';
* select
tablespace_name,file_name,bytes/1024/1024,maxbytes/1024/1024,autoextensible
from dba_data_files where file_name like '%&filename%';
UNDO_SIZE
----------
209715200
SELECT MAX(undoblks/((end_time-begin_time)*3600*24))
"UNDO_BLOCK_PER_SEC"
FROM v$undostat;
UNDO_BLOCK_PER_SEC
------------------
3.12166667
select tablespace_name,file_name,file_id,autoextensible,bytes/1048576
Mbytes, maxbytes/1048576 maxMbytes
from dba_data_files
where tablespace_name like '%UNDO%'
or tablespace_name like '%RBS%'
or tablespace_name like '%ROLLBACK%'
order by tablespace_name,file_name;
UNDO_SIZE
----------
209715200
SELECT MAX(undoblks/((end_time-begin_time)*3600*24))
"UNDO_BLOCK_PER_SEC"
FROM v$undostat;
UNDO_BLOCK_PER_SEC
------------------
3.12166667
DB Block Size
DB_BLOCK_SIZE [Byte]
--------------------
4096
If you are not limited by disk space, then it would be better to choose the
UNDO_RETENTION time that is best for you (for FLASHBACK, etc.). Allocate the
appropriate size to the UNDO tablespace according to the database activity:
DECLARE
v_table_space_name VARCHAR2(30);
v_table_space_size_in_MB NUMBER(9);
v_auto_extend BOOLEAN;
v_undo_retention NUMBER(9);
v_retention_guarantee BOOLEAN;
v_undo_info_return BOOLEAN;
BEGIN
v_undo_info_return := dbms_undo_adv.undo_info(v_table_space_name,
v_table_space_size_in_MB, v_auto_extend, v_undo_retention, v_retention_guarantee);
dbms_output.put_line(�UNDO Tablespace Name: � || v_table_space_name);
dbms_output.put_line(�UNDO Tablespace size (MB) : � ||
TO_CHAR(v_table_space_size_in_MB));
dbms_output.put_line(�If UNDO tablespace is auto extensible above size indicates
max possible size of the undo tablespace�);
dbms_output.put_line(�UNDO tablespace auto extensiable is : �|| CASE WHEN
v_auto_extend THEN �ON� ELSE �OFF� END);
dbms_output.put_line(�Undo Retention (Sec): � || v_undo_retention);
dbms_output.put_line(�Retention : �||CASE WHEN v_retention_guarantee THEN
�Guaranteed � ELSE �NOT Guaranteed� END);
END;
undo_autotune
This function is used to find auto tuning of undo retention is ENABLED or NOT.
Set serverout on
declare
v_autotune_return Boolean := null;
v_autotune_enabled boolean := null;
begin
v_autotune_return:= dbms_undo_adv.undo_autotune(v_autotune_enabled);
dbms_output.put_line(CASE WHEN v_autotune_return THEN 'Information is available :'
ELSE 'Information is NOT available :' END||
CASE WHEN v_autotune_enabled THEN 'Auto tuning of undo retention is ENABLED' ELSE
'Auto tuning of undo retention is NOT enabled' END);
end;
/
select dbms_undo_adv.longest_query from dual
DECLARE
v_undo_health_return number;
v_retention number;
v_utbsize number;
v_problem VARCHAR2(1024);
v_recommendation VARCHAR2(1024);
v_rationale VARCHAR2(1024);
BEGIN
v_undo_health_return := dbms_undo_adv.undo_health(problem => v_problem,
recommendation => v_recommendation,
rationale => v_rationale,
retention => v_retention,
utbsize => v_utbsize);
dbms_output.put_line(�Problem : �||v_problem);
dbms_output.put_line(�Recommendation= : �||v_recommendation);
dbms_output.put_line(�Rationale : �||v_retention);
dbms_output.put_line(�Retention : �||v_retention);
dbms_output.put_line(�UNDO tablespace size : �||v_utbsize);
END;
undo_advisor
It uses oracle�s advisor framework to find out problem and provide recommendations.
DECLARE
v_undo_advisor_return VARCHAR2(100);
BEGIN
v_undo_advisor_return := dbms_undo_adv.undo_advisor(instance => 1);
dbms_output.put_line(v_undo_advisor_return);
END;
select d.tablespace_name,
round((d.max - u.bytes)/1024/1024,2) as max_free_mbytes,
round(u.bytes*100/d.max,2) as used_pct
from sys.SM$TS_USED u,
(select tablespace_name,
sum(decode(MAXBYTES,0,bytes,maxbytes)) max
from sys.dba_data_files
group by tablespace_name) d
where u.tablespace_name = d.tablespace_name and
round(u.bytes*100/d.max,2)>70;
select
(BYTES/1024)/1024 "Used Space(MB)",
total "allocated size(MB)",
maxi "maximum allowable (MB)",
maxi-(BYTES/1024)/1024 "effectivefree(MB)",
--maxi-total "free(MB)",
round(((maxi-(BYTES/1024)/1024)/maxi)*100,2) "% FREE"
from
SM$TS_USED,(select sum((BYTES/1024)/1024)
total,sum((decode(MAXBYTES,0,bytes,maxbytes)/1024)/1024) maxi from
dba_data_files where tablespace_name in ('&tbs')) where
tablespace_name in ('&tbs');
Example
alter database datafile '/SID/oradata/data01/statsdata02.dbf' resize 1800M;
alter database datafile '/SID/oradata/data01/a_nolog01.dbf' autoextend on maxsize
120M;
alter database datafile '/SID/oradata/data03/ard198.dbf' autoextend off;
To enable autoextension
To find LOBs
select OWNER, TABLE_NAME, COLUMN_NAME from dba_lobs where segment_NAME in (select *
from
(select SEGMENT_NAME from dba_segments where TABLESPACE_NAME='SYSAUX' and
segment_type =
'LOB PARTITION' order by 1 desc) where rownum<45);
select file_name,status,FILE_ID,bytes/1024/1024,maxbytes/1024/1024,autoextensible
from dba_data_files where tablespace_name=upper('&tablespace_name') order by
FILE_ID;
FIND FREE,UTILIZED,ALLOCATED
SELECT
d.tablespace_name,
a.maxbytes/1024/1024 "maximum allowable (MB)",(a.maxbytes/1024/1024)*0.15 "15% of
Max Allowable",
(NVL(f.bytes,0) + (a.maxbytes - a.bytes))/1024/1024 "effective free(MB)",
(((a.maxbytes/1024/1024)*0.15)-((NVL(f.bytes,0) + (a.maxbytes -
a.bytes))/1024/1024)) "Mb to add to maintain 15% free",
100-round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2) "%FREE"
FROM
sys.dba_tablespaces d,
(select tablespace_name, sum(bytes) bytes,
sum(greatest(maxbytes,bytes)) maxbytes
from sys.dba_data_files group by tablespace_name) a,
(select tablespace_name,
sum(bytes) bytes
from sys.dba_free_space group by tablespace_name) f
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = f.tablespace_name(+)
AND NOT (d.extent_management = 'LOCAL' AND d.contents = 'TEMPORARY')
AND d.tablespace_name=upper('&TABLESPACE_NAME');
prompt Checking tablespace free space size less than 15% of total size
SELECT
d.tablespace_name,
(a.bytes - NVL(f.bytes,0))/1024/1024 "Used Space(MB)",
a.bytes/1024/1024 "allocated size(MB)",
a.maxbytes/1024/1024 "maximum allowable (MB)",
(NVL(f.bytes,0) + (a.maxbytes - a.bytes))/1024/1024 "effective free(MB)",
100-round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2) "%FREE"
FROM
sys.dba_tablespaces d,
(select tablespace_name, sum(bytes) bytes,
sum(greatest(maxbytes,bytes)) maxbytes
from sys.dba_data_files group by tablespace_name) a,
(select tablespace_name,
sum(bytes) bytes
from sys.dba_free_space group by tablespace_name) f
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = f.tablespace_name(+)
and (100-round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2)) <= 75
AND NOT (d.extent_management = 'LOCAL' AND d.contents = 'TEMPORARY');
SELECT
d.tablespace_name,
(a.bytes - NVL(f.bytes,0))/1024/1024 "Used Space(MB)",
a.bytes/1024/1024 "allocated size(MB)",
a.maxbytes/1024/1024 "maximum allowable (MB)",
(NVL(f.bytes,0) + (a.maxbytes - a.bytes))/1024/1024 "effective free(MB)",
100-round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2) "%FREE"
FROM
sys.dba_tablespaces d,
(select tablespace_name, sum(bytes) bytes,
sum(greatest(maxbytes,bytes)) maxbytes
from sys.dba_data_files group by tablespace_name) a,
(select tablespace_name,
sum(bytes) bytes
from sys.dba_free_space group by tablespace_name) f
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = f.tablespace_name(+)
AND NOT (d.extent_management = 'LOCAL' AND d.contents = 'TEMPORARY')
AND round(((NVL(f.bytes,0) + (a.maxbytes - a.bytes))/1048576),2) <2000
AND round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2) <75
order by 6 desc;
select file_name,bytes/1024/1024,maxbytes/1024/1024,autoextensible
from dba_data_files where tablespace_name=upper('&tbs') order by file_name;
Changing maxsize for all the files whose size is set more than maxsize
Changing bytes for all the files which have size less than 20MB
Freespace in tablespaces in MB
2)
set linesize 100 pagesize 30 feedback 1 echo off wrap on
column tblspace format a12 heading "Tablespace"
column totspace format 999999999 heading "Allocated MB"
column tfsspace format 999999999 heading "Free MB"
column extspace format 999999999 heading "AutoExt MB"
column pctfrees format 999.99 heading "% Free"
select
a.tsdf tblspace,
a.file_space totspace,
nvl(b.free_space,0) tfsspace,
a.extn_space extspace,
round(((a.extn_space - (a.file_space - nvl(b.free_space,0)))/a.extn_space)*100,2)
pctfrees
from
(select tablespace_name tsdf,sum(bytes)/1048576
file_space,sum(decode(maxbytes,0,bytes,maxbytes))/1048576 extn_space
from dba_data_files group by tablespace_name) a,
(select tablespace_name tsfs,sum(bytes)/1048576 free_space,max(bytes)/1048576
max_chunk from dba_free_space group by
tablespace_name) b
where
a.tsdf = b.tsfs (+) and
a.tsdf like upper('%&TableSpace%')
and round(((a.extn_space - (a.file_space -
nvl(b.free_space,0)))/a.extn_space)*100,2) < &PcFree
order by a.tsdf;
# lsnodes
Objects to be created:
----------------------
CREATE TABLE "SMF_APEXRPS"."DS_ERROR_TABLE"
( "COMNAME" VARCHAR2(200 BYTE),
"COMDDDL" LONG
);
Create or Replace
PROCEDURE DS_GET_DDL_STATEMENT(P_OBJECTTYPE VARCHAR2,PDIR VARCHAR2)
AS
V_DDL LONG;
V_ERRMSG VARCHAR2(500);
vInHandle utl_file.file_type;
CURSOR C1 IS
SELECT * FROM USER_OBJECTS WHERE object_type=P_OBJECTTYPE;
BEGIN
FOR I IN C1 LOOP
select
dbms_metadata.get_ddl(P_OBJECTTYPE,I.OBJECT_NAME) INTO V_DDL
from dual;
vInHandle := utl_file.fopen(PDIR, I.OBJECT_NAME||'.txt', 'W');
IF utl_file.is_open(vInHandle) THEN
utl_file.put_line(vInHandle, V_DDL, FALSE);
utl_file.fflush(vInHandle);
utl_file.fclose_all;
END IF;
END LOOP;
EXCEPTION WHEN OTHERS THEN
V_ERRMSG:=SQLERRM;
INSERT INTO DS_ERROR_TABLE VALUES('ERROR',V_ERRMSG);
END;
Posted by Suresh Kumar at 11:08 PM No comments: Links to this post
Labels: DB Scripts
Monday, January 2, 2012Provides a report on the top segments (in bytes) grouped by
Segment Type
-- +==================================================================+
-- PURPOSE: Provides a report on the top segments (in bytes) grouped by Segment
Type
-- +==================================================================+
SELECT
a.segment_type segment_type
, a.owner owner
, a.segment_name segment_name
, a.partition_name partition_name
, a.tablespace_name tablespace_name
, a.bytes bytes
, a.extents extents
FROM
(select
b.segment_type
, b.owner
, b.segment_name
, b.partition_name
, b.tablespace_name
, b.bytes
, b.extents
from
dba_segments b
order by
b.bytes desc
) a
WHERE
rownum < 101
ORDER BY
segment_type, bytes desc, owner, segment_name
/
Posted by Suresh Kumar at 5:32 PM No comments: Links to this post
Labels: DB Scripts
To check for index fragmentation
-- +------------------------------------------------------------------------------
+
-- | PURPOSE : To check for index fragmentation. As a rule of thumb if 10-15% |
-- | of the table data changes, then you should consider rebuilding the
index |
-- +-------------------------------------------------------------------------------
+
SELECT
name
, del_lf_rows
, lf_rows - del_lf_rows lf_rows_used
, TO_CHAR( del_lf_rows /(DECODE(lf_rows,0,0.01,lf_rows))*100,'999.99999')
ibadness
FROM index_stats
/
prompt
prompt Consider rebuilding any index if % of Deleted Leaf Rows is > 20%
prompt
undefine index_name
connect / as sysdba
CLEAR COLUMNS
SET LINESIZE 120
SET PAGESIZE 9999
SET FEEDBACK off
SET VERIFY off
SELECT
tablespace
, data_file
, pieces
, free_blocks
, largest_blks
, file_id
, total_blocks
FROM
free_space
/
prompt
prompt +----------------------------------------------------+
prompt | User Sessions Ordered by Current PGA Size |
prompt +----------------------------------------------------+
SELECT
s.sid sid
, s.serial# serial_id
, lpad(s.status,9) session_status
, lpad(s.username,12) oracle_username
, lpad(s.osuser,9) os_username
, lpad(p.spid,7) os_pid
, s.program session_program
, lpad(s.machine,8) session_machine
, sstat1.value session_pga_memory
, sstat2.value session_pga_memory_max
, sstat3.value session_uga_memory
, sstat4.value session_uga_memory_max
FROM
v$process p
, v$session s
, v$sesstat sstat1
, v$sesstat sstat2
, v$sesstat sstat3
, v$sesstat sstat4
, v$statname statname1
, v$statname statname2
, v$statname statname3
, v$statname statname4
WHERE
p.addr (+) = s.paddr
AND s.sid = sstat1.sid
AND s.sid = sstat2.sid
AND s.sid = sstat3.sid
AND s.sid = sstat4.sid
AND statname1.statistic# = sstat1.statistic#
AND statname2.statistic# = sstat2.statistic#
AND statname3.statistic# = sstat3.statistic#
AND statname4.statistic# = sstat4.statistic#
AND statname1.name = 'session pga memory'
AND statname2.name = 'session pga memory max'
AND statname3.name = 'session uga memory'
AND statname4.name = 'session uga memory max'
ORDER BY session_pga_memory DESC
/
Posted by Suresh Kumar at 4:42 PM No comments: Links to this post
Labels: DB Scripts
List all currently connected user sessions ordered by Logical I/O
--
+--------------------------------------------------------------------------------+
-- | PURPOSE : List all currently connected user sessions ordered by Logical - I/O
|
--
+--------------------------------------------------------------------------------+
prompt
prompt +----------------------------------------------------+
prompt | User Sessions Ordered by Logical I/O |
prompt +----------------------------------------------------+
SELECT
s.sid sid
, s.serial# serial_id
, lpad(s.status,9) session_status
, lpad(s.username,12) oracle_username
, lpad(s.osuser,9) os_username
, lpad(p.spid,7) os_pid
, s.program session_program
, lpad(s.machine,8) session_machine
, sstat1.value
+ sstat2.value logical_io
, sstat3.value physical_reads
, sstat4.value physical_writes
FROM
v$process p
, v$session s
, v$sesstat sstat1
, v$sesstat sstat2
, v$sesstat sstat3
, v$sesstat sstat4
, v$statname statname1
, v$statname statname2
, v$statname statname3
, v$statname statname4
WHERE
p.addr (+) = s.paddr
AND s.sid = sstat1.sid
AND s.sid = sstat2.sid
AND s.sid = sstat3.sid
AND s.sid = sstat4.sid
AND statname1.statistic# = sstat1.statistic#
AND statname2.statistic# = sstat2.statistic#
AND statname3.statistic# = sstat3.statistic#
AND statname4.statistic# = sstat4.statistic#
AND statname1.name = 'db block gets'
AND statname2.name = 'consistent gets'
AND statname3.name = 'physical reads'
AND statname4.name = 'physical writes'
ORDER BY logical_io DESC
/
Posted by Suresh Kumar at 4:38 PM No comments: Links to this post
Labels: DB Scripts
List all currently connected user sessions ordered by CPU time.
-- +----------------------------------------------------------------------------+
-- | DATABASE : Oracle |
-- | PURPOSE : List all currently connected user sessions ordered by CPU time. |
-- +----------------------------------------------------------------------------+
prompt
prompt +----------------------------------------------------+
prompt | User Sessions Ordered by CPU |
prompt +----------------------------------------------------+
SELECT
s.sid sid
, s.serial# serial_id
, lpad(s.status,9) session_status
, lpad(s.username,12) oracle_username
, lpad(s.osuser,9) os_username
, lpad(p.spid,7) os_pid
, s.program session_program
, lpad(s.machine,14) session_machine
, sstat.value cpu_value
FROM
v$process p
, v$session s
, v$sesstat sstat
, v$statname statname
WHERE
p.addr (+) = s.paddr
AND s.sid = sstat.sid
AND statname.statistic# = sstat.statistic#
AND statname.name = 'CPU used by this session'
ORDER BY cpu_value DESC
/