首页 > 开发 > 综合 > 正文

实用的数据库检查程序(3)

2024-07-21 02:08:34
字体:
来源:转载
供稿:网友

prompt

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt + 7.0 sort area size                                                     +

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt

 

ttitle left "*** sort area ***" skip 1

 

select substr(name,1,25)  "sort area name",

     substr(value,1,15) "value"

from v$sysstat

where name like 'sort%'

/

 

prompt

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt 7.0 invesigation

prompt the lower the value of the sorts to disk ,

prompt the better the sort is performing .

prompt sort_area_size can't be increase large enough to elimate sorts to disk

prompt the sorts on a database are low-maintenance items

prompt usually , sort_area_size and sort_area_retained_size should be set to the same value

prompt the optimal value of sort_area_size and sort_area_retained_size is 1m

prompt (for parallel query) . the larger value than 1m have not improved performance significantly

prompt check v$license and v$sort_usage

prompt from revealnet:

prompt initial/next parameter of temporary table should have minimum size sort_area_size + 1 block

prompt sort_area_retained_size set to half the sort_area_size

 

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt

ttitle off

 

prompt

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt + 7.1 sequence_cache_entries

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt

ttitle left "*** sequence_cache_entries ***" skip 1

select count(*) "number of sequence" , sum(cache_size) "cache size needed" from dba_sequences

/

 

prompt

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt 7.1 invesigation

prompt sequence_cache_entries should set to 1000

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt

ttitle off

 

prompt

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt + 9.0 rollback segment contention                                        +

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt

 

ttitle left "*** rollback segment contention ***" skip 1

 

column "rollback seg name" format a20

column "online?" format a10

column "gets" format 9,999,999,990

column "waits" format 9,999,999,990

column "% ratio" format 999.99

 

select r.name "rollback seg name" ,

       s.status "online?",

       s.gets "gets",

       s.waits "waits",

     (waits/gets ) * 100 "% ratio"

from v$rollstat s, v$rollname r

where s.usn = r.usn

/

 

prompt

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt 9.0 investigation

prompt if the radio is above 2% , create more rollback segment.

prompt the guideline is :

prompt transaction number  *    rollback seg. num

prompt  < 16           *    4

prompt  >= 16 & < 32       *    8

prompt  >= 32          *    min(50,transaction numbers/4)

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt

ttitle off

 

prompt

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt + 9.1 rollback segment contention                                        +

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt

ttitle left "*** rollback segment contention ***" skip 1

select class,count

from v$waitstat

where class like '%undo%'

union

select name,value

from v$sysstat

where name = 'consistent gets'

/

 

prompt

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt 9.1 investigation

prompt the ratio of waits for any class should be less than 1% of the

prompt total number of requests

prompt if the ratio is greater than 1% , consider creating more rollback seg

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt

prompt

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt how to estimate the transaction size

prompt before execute : select usn,writes from v$rollstat

prompt after execute  : select usn,writes from v$rollstat

prompt compare the result

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt

ttitle off

 

prompt

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt + 10.0 free space coalesced                                              +

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt

 

ttitle left "*** free space coalesced ***" skip 1

 

select tablespace_name , percent_blocks_coalesced

from dba_free_space_coalesced

order by percent_blocks_coalesced

/

 

prompt

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt 10.0 investigation

prompt the ideal percent blocks coalesced should be 100%

prompt use "alter tablespace <name> coalesce" to coalesce

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt

ttitle off

 

prompt

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt + 11.0 latch contention                                                  +

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt

 

ttitle left "******** latch information ******" skip 1

 

column "redo type" format a20

column gets format 9,999,990

column willing_to_wait format 9,999,990

column misses format 9,999,990

column "immediate" format 999.99

 

select name "redo type", gets , misses,

       decode(gets,0,0,(100*(misses/(gets + misses)))) willing_to_wait,

       sleeps,immediate_gets,immediate_misses,

       decode(immediate_gets,0,0,(100*(immediate_misses/(immediate_gets + immediate_misses)))) "immediate"

from v$latch

where name like 'redo%'

order by name

/

 

prompt

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt 11.0 investigation

prompt if willing_to_wait and immediate is greater than 1%,

prompt increase log_simultaneous_copies to twice # of cpus,

prompt and decrease log_small_entry_max_size in init.ora file

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt

ttitle off

 

prompt

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt + 11.1 latch contention (reveal net)                                     +

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt

 

ttitle left "******** latch information ******" skip 1

select a.name,

       100. * b.sleeps / b.gets ratio1,

       100. * b.immediate_misses / decode ( (b.immediate_misses + b.immediate_gets), 0, 1) ratio2

 from v$latchname a, v$latch b

 where a.latch# = b.latch#

 and b.sleeps > 0

/

prompt

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt 11.1 investigation

prompt

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt

ttitle off

 

prompt

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt + 12.0 tablespace usage                                                  +

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt

 

set pagesize 66

clear breaks

clear computes

 

column "total bytes" format 9,999,999,999,999

column "sql blocks" format 9,999,999,999

column "bytes free" format 9,999,999,999,999

column "bytes used" format 9,999,999,999,999

column "% free" format 9999.999

column "% used" format 9999.999

break on report

compute sum of "total bytes" on report

compute sum of "sql blocks" on report

compute sum of "bytes free" on report

compute sum of "bytes used" on report

compute sum of "% free" on report

compute sum of "% used" on report

 

ttitle left "*** database: "xdbname", current tablespace usage (as of: "xdate") ***" skip 1

select substr(fs.file_id,1,3) "id#",

    fs.tablespace_name,

    df.bytes "total bytes",

    df.blocks "sql blocks",

    sum(fs.bytes) "bytes free",

    (100*((sum(fs.bytes))/df.bytes)) "% free",

    df.bytes-sum(fs.bytes) "bytes used",

    100*((df.bytes-sum(fs.bytes))/df.bytes) "% used"

from sys.dba_data_files df,sys.dba_free_space fs

where df.file_id(+) = fs.file_id

group by fs.file_id,fs.tablespace_name,df.bytes,df.blocks

order by fs.tablespace_name

/

 

prompt

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt 12.0 invesigation

prompt if a tablespace has all datafiles with % used greater

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt

ttitle off

 

prompt

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt + 13.0 disk activity                                                     +

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt

 

column "file name" format a35

column "file total" format 999,999,999,990

set pagesize 33

ttitle "*** database: "xdbname", datafile disk activity (as of : "xdate") ***"

 

select substr(df.file#,1,2) "id",

    rpad(name,35,'.') "file name",

    rpad(substr(phyrds,1,10),10,'.') "phy reads",

    rpad(substr(phywrts,1,10),10,'.') "phy writes",

    rpad(substr(phyblkrd,1,10),10,'.') "blk reads",

    rpad(substr(phyblkwrt,1,10),10,'.') "blk writes",

    rpad(substr(readtim,1,9),9,'.') "read time",

    rpad(substr(writetim,1,10),10,'.') "write time",

    sum(phyrds+phywrts+phyblkrd+phyblkwrt+readtim) "file total"

from v$filestat fs,v$datafile df

where fs.file# = df.file#

group by df.file#,df.name,phyrds,phywrts,phyblkrd,

    phyblkwrt,readtim, writetim

order by sum(phyrds+phywrts+phyblkrd+phyblkwrt+readtim) desc , df.name

/

 

 

prompt

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt 13.0 investigation

prompt to reduce disk contention , insure that datafiles

prompt with the greatest activity are not on the same disk .

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt

ttitle off

prompt

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt + 14.0 fragmentation need                                                +

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt

set heading on

set termout on

set pagesize 66

 

ttitle left "*** database: "xdbname", defragmentation need as of: "xdate" ***"

 

select substr(de.owner,1,8) "owner",

       substr(de.segment_type,1,8) "seg type",

    substr(de.segment_name,1,35) "table name (segment)",

    substr(de.tablespace_name,1,20) "tablespace name",

    count(*) "frag need",

    substr(df.name,1,40) "datafile name"

from sys.dba_extents de,v$datafile df

where de.owner <> 'sys'

and de.file_id = df.file#

and de.segment_type = 'table'

group by de.owner,de.segment_name,de.segment_type,de.tablespace_name,df.name

having count(*) > 1

order by count(*) desc

/

 

prompt

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt 14.0 investigation

prompt the more fragmented a segment is , the more i/o needed to read

prompt that info . defragments this table regularly to insure extents

prompt ('frag need') do not get much above 2.

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt

ttitle off

prompt

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt + 15.0 prompt high water mark (hwm)                                      +

prompt + perform "analyze table <table name> compute statistics;" first         +

prompt + this transcation is taken more resources <be carefully to use it!>     +

prompt + (to analyze tables , you can use                                       +

prompt + dbms_utility.analyze_schema('<user>','compute') )                      +

prompt ++++++++++++++++++++++++++++++++++ item ++++++++++++++++++++++++++++++++++

prompt

 

ttitle left skip 1 -

left "************ high water mark *****************" skip 1

 

column owner format a10

column segment_name format a40

 

select a.owner ,

     a.segment_name ,

     a.blocks ,

     b.empty_blocks ,

     a.blocks - b.empty_blocks -1 "high water mark"

from   dba_segments a, dba_tables b

where  a.owner = b.owner

and    a.segment_name = b.table_name

order by a.owner , a.segment_name

/

 

 

prompt

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

prompt 15.0 investigation

prompt to analyze the table statistics , you can also use

prompt dbms_space.unused_space(<'owner'>,<'object_name'>,<'object_type'>

prompt      ,<total blocks>,<total bytes>,<unused blocks>,<unused bytes>

prompt            ,<number varible5>,<number varible6>,<number varible7>)

prompt <<<<<<<<<<<<<<<<<<< note: >>>>>>>>>>>>>>>>>>>>>>

ttitle off

spool off
菜鸟学堂:
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表