db check references

4
-- Tablespace used/available space prompt prompt prompt prompt Tablespace Information prompt This will show how much used and available space prompt is in each tablespace. prompt prompt This will take a few moments to run. prompt clear columns set pagesize 80 linesize 90 feedback off column tablespace_name heading Tablespace format a19 column object_count heading 'Objects|(#)' format 999,990 column mb heading Mb format 999,990 column sum(frags) heading 'Frags|(#)' format 999,990 column avail heading 'Max|(Mb)' format 9999.990 column free heading 'Free|(%)' format 999.990 column bytesize heading 'Size|(Mb)' format 999,999 column byteused heading 'Used|(Mb)' format 999,990 column bytefree heading 'Free|(Mb)' format 999,990 break on report compute sum of object_count bytesize byteused bytefree on report select tablespace_name, sum(obj_cnt) object_count, sum(byte)/1048576 bytesize, (sum(byte)/1048576)- (sum(fbyte)/1048576) byteused, sum(fbyte)/1048576 bytefree, sum(frags), sum(largest)/1048576 avail, (sum(fbyte)/sum(byte))*100 free from (select tablespace_name, 0 obj_cnt, 0 ini_ext, 0 nex_ext, 0 byte, sum(bytes) fbyte, count(*) frags, max(bytes) largest from dba_free_space group by tablespace_name union select tablespace_name, 0, 0, 0, sum(bytes), 0, 0, 0 from dba_data_files group by tablespace_name

Upload: lunwen

Post on 20-Feb-2016

217 views

Category:

Documents


3 download

DESCRIPTION

scripts

TRANSCRIPT

Page 1: DB Check References

-- Tablespace used/available space

promptpromptpromptprompt Tablespace Informationprompt This will show how much used and available spaceprompt is in each tablespace.prompt prompt This will take a few moments to run.prompt

clear columnsset pagesize 80 linesize 90 feedback off column tablespace_name heading Tablespace format a19column object_count heading 'Objects|(#)' format 999,990column mb heading Mb format 999,990column sum(frags) heading 'Frags|(#)' format 999,990column avail heading 'Max|(Mb)' format 9999.990column free heading 'Free|(%)' format 999.990column bytesize heading 'Size|(Mb)' format 999,999column byteused heading 'Used|(Mb)' format 999,990column bytefree heading 'Free|(Mb)' format 999,990break on reportcompute sum of object_count bytesize byteused bytefree on report

select tablespace_name,sum(obj_cnt) object_count,sum(byte)/1048576 bytesize, (sum(byte)/1048576)- (sum(fbyte)/1048576) byteused,sum(fbyte)/1048576 bytefree, sum(frags), sum(largest)/1048576 avail,(sum(fbyte)/sum(byte))*100 free

from(select tablespace_name,

0 obj_cnt,0 ini_ext,0 nex_ext, 0 byte, sum(bytes) fbyte, count(*) frags, max(bytes) largest

from dba_free_space group by tablespace_name

unionselect tablespace_name,

0, 0, 0, sum(bytes), 0, 0, 0 from dba_data_files group by tablespace_nameunionselect tablespace_name, 0,

initial_extent/1024 ini_ext,next_extent/1024 nex_ext,0,0,0,0

from dba_tablespacesunionselect tablespace_name,

count(*) obj_cnt,0, 0, 0, 0, 0, 0

Page 2: DB Check References

from dba_segments group by tablespace_name) group by tablespace_name;set pagesize 24 feedback on verify on

--Fragment Check

col "Tbs Name" format a10col file_name format a40col Freespace(Mb) format 999,999.990col Extcnt format 999.990col bytes format 99,999.990col larges format 99,999.90col smallest format 99,999.90select a.tablespace_name "Tbs Name", b.file_name, sum(a.bytes)/1048576 "Freespace(Mb)",

count(*) Extcnt, b.bytes/1048576 "Bytes(Mb)", max(a.Bytes)/1048576 larges, min(a.bytes)/1048576 smallest

from dba_free_space a, dba_data_files bwhere a.tablespace_name=b.tablespace_name and a.file_id=b.file_idgroup by a.tablespace_name, b.file_name, b.bytes

--CPU Usage

SELECTto_number(p.spid) "ID_THREAD",p.background "BACKGROUND",b.name "NAME",s.sid "SID",s.serial# "SERIAL#",s.username "USERNAME",s.status "STATUS",s.osuser "OSUSER",s.program "PROGRAM"FROMv$process p,v$bgprocess b,v$session sWHEREs.paddr = p.addr andb.paddr(+) = p.addrorder by 1

--Chunk Check

set pagesize 70set feedback offset numwidth 12compute sum of bytes on reportcompute sum of bytes on tablespace_namebreak on Tablespace_Name skip 2

Page 3: DB Check References

column One noprintcolumn Two heading 'Space type' format a20column Bytes format 9,999,999,990column Tablespace_Name format a18set termout offset echo offspool c:\temp\ts_space.txtselect 1 One, Tablespace_Name, 'Max available: ' Two, sum(Bytes) Bytes from dba_data_files group by Tablespace_Name unionselect 2 Two, Tablespace_name, 'Allocated: ', nvl(((sum(Bytes) + decode(Tablespace_Name, 'SYSTEM',2048,1024)) * -1),0) from dba_extents group by Tablespace_Nameorder by2, 1;clear computesclear breakscolumn Tb heading 'Frag' format 9,990column Sm heading 'Small' format 9,999,999,990column Lg heading 'Large' format 9,999,999,990remselect

Tablespace_Name, sum(Bytes) Bytes, count(Blocks) Tb, min(Bytes) Sm,max(Bytes) Lg

fromDBA_FREE_SPACE

group byTablespace_Name;

spool off

--Coalesce check

select Tablespace_Name, Total_Extents, Extents_Coalescedfrom DBA_FREE_SPACE_COALESCED