Vous êtes sur la page 1sur 8

How to Check UNDO Tablespace Usage

Overall UNDO Tablespace Usage

SQL> column tablespace format a20;


SQL> column sum_in_mb format 999999.99;
SQL> select tablespace_name tablespace, status, sum(bytes)/1024/1024 sum_in_mb, count(*) counts
from dba_undo_extents group by tablespace_name, status order by 1,2;

TABLESPACE STATUS SUM_IN_MB COUNTS


-------------------- --------- ---------- ----------
UNDOTBS1 ACTIVE 1.00 1
UNDOTBS1 EXPIRED 1063.19 1015
UNDOTBS1 UNEXPIRED 241.94 152
UNDOTBS2 ACTIVE 2.00 2
UNDOTBS2 EXPIRED 12523.14 1456
UNDOTBS2 UNEXPIRED 357.10 265

6 rows selected.

User UNDO Tablespace Usage


SQL> select u.tablespace_name tablespace, s.username, u.status, sum(u.bytes)/1024/1024 sum_in_mb,
count(u.segment_name) seg_cnts from dba_undo_extents u left join v$transaction t on
u.segment_name = '_SYSSMU' || t.xidusn || '$' left join v$session s on t.addr = s.taddr group by
u.tablespace_name, s.username, u.status order by 1,2,3;

TABLESPACE USERNAME STATUS SUM_IN_MB SEG_CNTS


-------------------- --------------- --------- ---------- ----------
UNDOTBS1 SCOTT ACTIVE 8.00 1
UNDOTBS1 SCOTT EXPIRED 120.12 66
UNDOTBS1 EXPIRED 5476.18 1962
UNDOTBS1 UNEXPIRED 305.40 85
UNDOTBS2 EXPIRED 1743.67 3252
To show UndoRetention Value

Show parameter undo_retention;

To check retention guarantee for undo tablespace

select tablespace_name,status,contents,logging,retention from dba_tablespaces


where tablespace_name like '%UNDO%';

To find out which session is currently using the most UNDO

SQL>select s.sid, t.name, s.value from v$sesstat s, v$statname t where


s.statistic#=t.statistic# and t.name='undo change vector size' order by s.value
desc;

SQL>select sql.sql_text, t.used_urec records, t.used_ublk blocks,


(t.used_ublk*8192/1024) kb from v$transaction t,
v$session s, v$sql sql
where t.addr=s.taddr
and s.sql_id = sql.sql_id
and s.username ='&USERNAME';

Find out what user and which SQL statement is eating up all the UNDO space.

SQL> select s.sql_text from v$sql s, v$undostat u


where u.maxqueryid=s.sql_id;
You can also use following SQL to find out most undo used by a session for a currently

executing transaction.

SQL> select s.sid,s.username,t.used_urec,t.used_ublk


from v$session s, v$transaction t where s.saddr = t.ses_addr order by t.used_ublk desc;

TEMP

Temp segment usage per session


The below is a query which is very useful in knowing how much temp usage is being done by
each session connected to the database.

SELECT S.sid || ‘,’ || S.serial# sid_serial, S.username, S.osuser, P.spid, S.module,


P.program, SUM (T.blocks) * TBS.block_size / 1024 / 1024 mb_used, T.tablespace,
COUNT(*) statements
FROM v$sort_usage T, v$session S, dba_tablespaces TBS, v$process P
WHERE T.session_addr = S.saddr
AND S.paddr = P.addr
AND T.tablespace = TBS.tablespace_name
GROUP BY S.sid, S.serial#, S.username, S.osuser, P.spid, S.module,
P.program, TBS.block_size, T.tablespace
ORDER BY sid_serial;

To find Total Free space in Temp Tablespace :

select tablespace_name , (free_blocks*8)/1024/1024 FreeSpaceInGB,


(used_blocks*8)/1024/1024 UsedSpaceInGB,
(total_blocks*8)/1024/1024 TotalSpaceInGB
from v$sort_segment where tablespace_name like '%TEMP%'
To see top 10 consuming process :

select * from
(SELECT
d.tablespace_name,a.sid,a.serial#,a.program,a.module,a.action,a.username "DB
Username",a.osuser,ROUND((b.blocks*d.block_size)/1024/1024,2) "Used
MB",c.sql_text
FROM v$session a, v$tempseg_usage b, v$sqlarea c,dba_tablespaces d
WHERE a.saddr = b.session_addr AND c.address= a.sql_address AND c.hash_value
= a.sql_hash_value AND d.tablespace_name=b.tablespace ORDER BY
b.tablespace, b.blocks DESC)
where rownum <=10

To find Sort Segment Usage by a particular User

SELECT s.username,s.sid,s.serial#,u.tablespace, u.contents, u.extents, u.blocks


FROM v$session s, v$sort_usage u WHERE s.saddr=u.session_addr order by
u.blocks desc;

Get 10 sessions with largest temp usage

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;

Identifying WHO is currently using TEMP Segments

SELECT sysdate,a.username, a.sid, a.serial#, a.osuser, (b.blocks*d.block_size)/1048576


MB_used, c.sql_text
FROM v$session a, v$tempseg_usage b, v$sqlarea c,
(select block_size from dba_tablespaces where tablespace_name='TEMP') d
WHERE b.tablespace = 'TEMP'
and a.saddr = b.session_addr
AND c.address= a.sql_address
AND c.hash_value = a.sql_hash_value
AND (b.blocks*d.block_size)/1048576 > 1024
ORDER BY b.tablespace, 6 desc;

How to check default temporary and permanent tablespace


COLUMN property_name FORMAT A30
COLUMN property_value FORMAT A30
COLUMN description FORMAT A50
SET LINESIZE 200

SELECT *
FROM database_properties
WHERE property_name like '%TABLESPACE';
PROPERTY_NAME PROPERTY_VALUE DESCRIPTION
------------------------------ ------------------------------ --------------------------------------
DEFAULT_TEMP_TABLESPACE TEMP Name of default temporary tablespace
DEFAULT_PERMANENT_TABLESPACE USERS Name of default permanent
tablespace

Find a session which are generating more archive logs

SQL> SELECT s.sid, s.serial#, s.username, s.program,

i.block_changes

FROM v$session s, v$sess_io i

WHERE s.sid = i.sid

ORDER BY 5 desc, 1, 2, 3, 4;

SID SERIAL# USERNAME PROGRAM BLOCK_CHANGES

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

158 6 SCOTT sqlplus.exe 630295

159 3 SYS sqlplus.exe 97

161 1 ORACLE.EXE (MMON) 58

164 1 ORACLE.EXE (SMON) 34

148 5 ORACLE.EXE (q001) 0

........

19 rows selected.
Find numbers of archive generated per day
SELECT TO_CHAR(FIRST_TIME,'DD-MON-YYYY HH24'),
COUNT(*)
FROM V$LOGHIST
WHERE TO_CHAR(FIRST_TIME,'DD-MON-YY HH24') > '01-NOV-2013'
GROUP BY TO_CHAR(FIRST_TIME,'DD-MON-YYYY HH24')
ORDER BY TO_CHAR(FIRST_TIME,'DD-MON-YYYY HH24') ASC

find the size of the archivelog

select decode(grouping
(trunc(COMPLETION_TIME)),1,'TOTAL',TRUNC(COMPLETION_TIME)) TIME,
SUM(BLOCKS * BLOCK_SIZE)/1024/1024/1024 SIZE_MB
from V$ARCHIVED_LOG group by cube (trunc (COMPLETION_TIME)) order by 1

script to check tablespace free space for all db’s in server


Get file system details from V$datafile
select distinct file_name from (
select distinct substr(name,1,instr(name,'/',1,3)-1)
file_name from v$datafile
union all
select distinct substr(name,1,instr(name,'/',1,3)-1)
file_name from v$controlfile
union all
select distinct substr(member,1,instr(member,'/',1,3)-1)
file_name from v$logfile
union all
select distinct substr(name,1,instr(name,'/',1,3)-1)
file_name from v$tempfile
);

How to check RMAN backup status and timings


Login as sysdba and issue the following script:

This script will report on all currently running RMAN backups like full, incremental & archivelog backups:

SQL> col STATUS format a9


SQL> col hrs format 999.99
SQL> select SESSION_KEY, INPUT_TYPE, STATUS,
to_char(START_TIME,'mm/dd/yy hh24:mi') start_time,
to_char(END_TIME,'mm/dd/yy hh24:mi') end_time,
elapsed_seconds/3600 hrs from V$RMAN_BACKUP_JOB_DETAILS
order by session_key;
SQL> /

SESSION_KEY INPUT_TYPE STATUS START_TIME END_TIME HRS


----------- ------------- --------- -------------- -------------- -------
29 DB FULL RUNNING 01/07/14 10:28 01/07/14 10:28 .00
SQL> /
SESSION_KEY INPUT_TYPE STATUS START_TIME END_TIME HRS
----------- ------------- --------- -------------- -------------- -------
29 DB FULL RUNNING 01/07/14 10:28 01/07/14 10:28 .01
SQL> /
SESSION_KEY INPUT_TYPE STATUS START_TIME END_TIME HRS
----------- ------------- --------- -------------- -------------- -------
29 DB FULL COMPLETED 01/07/14 10:28 01/07/14 10:29 .03

V$rman_output

Vous aimerez peut-être aussi