Sql Scripts

1.Tablespace Used/Free space

set lin 300
COLUMN TABLESPACE FORMAT A15

select t.tablespace, t.totalspace as ” Totalspace(MB)”,
round((t.totalspace-nvl(fs.freespace,0)),2) as “Used Space(MB)”,
nvl(fs.freespace,0) as “Freespace(MB)”,
round(((t.totalspace-nvl(fs.freespace,0))/t.totalspace)*100,2) as “%Used”,
round((nvl(fs.freespace,0)/t.totalspace)*100,2) as “% Free”
from
(select round(sum(d.bytes)/(1024*1024)) as totalspace,d.tablespace_name
tablespace
from dba_data_files d
group by d.tablespace_name) t,
(select round(sum(f.bytes)/(1024*1024)) as freespace,f.tablespace_name
tablespace
from dba_free_space f
group by f.tablespace_name) fs
where t.tablespace=fs.tablespace (+)
order by t.tablespace
/

2.Temp Tablespace Usage

SET PAUSE ON
SET PAUSE ‘Press Return to Continue’
SET PAGESIZE 60
SET LINESIZE 300

SELECT
A.tablespace_name tablespace,
D.mb_total,
SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_used,
D.mb_total – SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_free
FROM
v$sort_segment A,
(
SELECT
B.name,
C.block_size,
SUM (C.bytes) / 1024 / 1024 mb_total
FROM
v$tablespace B,
v$tempfile C
WHERE
B.ts#= C.ts#
GROUP BY
B.name,
C.block_size
) D
WHERE
A.tablespace_name = D.name
GROUP by
A.tablespace_name,
D.mb_total
/

3.Undo Tablespace usage 

select a.tablespace_name, sizemb, usagemb, (sizemb-usagemb) freemb
from (select sum(bytes/1024/1024) sizemb, b.tablespace_name
from dba_data_files a,
dba_tablespaces b
where a.tablespace_name = b.tablespace_name
and b.contents = ‘UNDO’
group by b.tablespace_name) a,
(select c.tablespace_name, sum(bytes/1024/1024) usagemb
from dba_undo_extents c
where status <> ‘EXPIRED’
group by c.tablespace_name) b
where a.tablespace_name = b.tablespace_name;

4.Sqlid that changes their execution or hash plan

set lines 155
col execs for 999,999,999
col avg_etime for 999,999.999
col avg_lio for 999,999,999.9
col begin_interval_time for a30
col node for 99999
break on plan_hash_value on startup_time skip 1
select ss.snap_id, ss.instance_number node, begin_interval_time, sql_id, plan_hash_value,
nvl(executions_delta,0) execs,
(elapsed_time_delta/decode(nvl(executions_delta,0),0,1,executions_delta))/1000000 avg_etime,
(buffer_gets_delta/decode(nvl(buffer_gets_delta,0),0,1,executions_delta)) avg_lio
from DBA_HIST_SQLSTAT S, DBA_HIST_SNAPSHOT SS
where ss.snap_id = S.snap_id
and ss.instance_number = S.instance_number
and executions_delta > 10
–order by 4,3,1
order by 7,6
/

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s