首页 > 开发 > 综合 > 正文

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

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

 

功能:

1.     数据库的基本信息显示(建库时间,模式等)

2.     数据库结构信息-database map(control file, redo log file, datafile, rollback segment)

3.     数据库所有状态信息

4.     数据库级的db block buffer hit ratio

5.     session级的db block buffer hit ratio

6.     前一天的log switch情况

7.     redo log 空间需求查询

8.     log buffer 性能查询

9.     log file switch性能查询

10.  检查不完全的checkpoint

11.  library cache 的 性能查询

12.  dictionary cache的 性能查询

13.  查找最资源的sql语句

14.  session级的cpu使用度

15.  sort_area_size的性能查询

16.  sequence_cache_entries的性能查询

17.  chained row的查询

18.  rollback segment contention 检查

19.  表空间碎片检查

20.  latch contention 检查

21.  tablespace 用量检查

22.  数据文件i/o检查

23.  表和索引的碎片检查

24.  表的hwm检查

 

使用方法举例:

 

目前,作为一个dba,可以有很多工具来管理,维护和症查数据库.这只是我平时搜集的一些脚本,可以作为dba随身携带的小工具程序

在没有其他可视化的工具时,它可以用来对数据库做一些基本的诊断.

 

1.打开sqlplus , connect system

2.@a:/check_db.sql   (a:/是本文件的路径)

3.执行完毕,结果储存在c:/local.txt

4.local.txt 不但有每个数据的说明,同时介绍一些解决相关问题的方法以供参考

 

check_db.sql的内容:

 

set echo off

spool c:/local.txt

ttitle off

break on today

column today noprint new_value xdate

select substr(to_char(sysdate,'fmmonth dd, yyyy hh:mi:ss p.m.'),1,35) today

from dual

/

column name noprint new_value xdbname

select name from v$database

/

 

set heading on

set feedback off

set linesize  250

set pagesize 200

 

rem ######################################################################################

rem             **** check_db_v2.1: performance tuning****

rem ######################################################################################

 

prompt *******************************************************************************

prompt          database check information

prompt *******************************************************************************

ttitle left "database: "xdbname" (as of: "xdate")" skip 2

select name , created , log_mode from v$database

/

prompt

prompt *******************************************************************************

ttitle off

 

prompt

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

prompt + 0.0 database map                                                       +

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

prompt

 

ttitle left "*** database map - control file ***"

column "control file" format a40

select status , name "control file" from v$controlfile

/

ttitle off

ttitle left "*** database map - redolog file ***"

column "log file" format a40

select f.member "log file",l.group# ,l.thread# ,l.bytes ,l.status from v$log l, v$logfile f

where l.group# = f.group#

/

 ttitle off

ttitle left "*** database map - data file ***"

column file_name format a40                       

                                                                                             

select file_name ,tablespace_name,bytes,blocks,status from dba_data_files order by tablespace_name , bytes desc                                                                                                                        

/

ttitle off

ttitle left "*** database map - rollback seg ***"

 

select n.name "rollback seg name" , r.extents , r.rssize , r.optsize , hwmsize ,status

from v$rollstat r,v$rollname n

where  r.usn = n.usn

/

 

ttitle off

 

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

prompt + 1.0 database statistic                                                 +

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

set heading on

set termout on

 

ttitle left "*** database: "xdbname", database statistic(as of : "xdate" ) ***" skip 1

 

column "statistic name" format a55

column value format 9,999,999,999,999,990

 

select n.statistic# , n.name "statistic name", s.value

from v$statname n , v$sysstat s

where n.statistic# = s.statistic#

and value > 0

order by value desc

/

ttitle off

 

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

prompt + 2.0 db block buffer - hit ratio (database wise)                        +

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

set heading on

set termout on

 

column "physical reads" format 9,999,999,999,999

column "consistent gets" format 9,999,999,999,999

column "db block gets" format 9,999,999,999,999

column "hit ratio" format 999.99

 

ttitle left "*** database: "xdbname", db block buffers hit ratio (as of : "xdate" ) ***" skip 1-

left  "percent = ((100*(1-(physical reads/(consistent gets + db block gets))))"  skip 2

 

select pr.value "physical reads",

       cg.value "consistent gets",

       bg.value "db block gets",

       round((1-(pr.value/(bg.value+cg.value)))*100,2) "hit ratio"

from   v$sysstat pr, v$sysstat bg, v$sysstat cg

where pr.name = 'physical reads'

and   bg.name = 'db block gets'

and   cg.name = 'consistent gets'

/

 

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

prompt 2.0 investigation if percent is less than 70% , increase db_block_buffers

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

ttitle off

 

prompt

prompt

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

prompt + 2.1  db block buffer - hit ratio (session wise)                        +

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

 

 

clear breaks

clear computes

break on report

compute sum of consistent_gets on report

compute sum of block_gets on report

compute sum of physical_reads on report

 

column "hit ratio %" format 999.99

column username format a10

 

ttitle left "*** database: "xdbname", hit ratio for user sessions(as of : "xdate" ) ***" skip 1

 

select username,

     osuser,

     consistent_gets,

     block_gets,

     physical_reads,

     100*( consistent_gets + block_gets - physical_reads)/

         ( consistent_gets + block_gets ) "hit ratio %"

from  v$session,v$sess_io

where v$session.sid = v$sess_io.sid

and   ( consistent_gets + block_gets )>0

and   username is not null

order by username,"hit ratio %";

 

prompt

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

prompt 2.0/2.1 investigation

prompt if you have 20 or more users and batch users cause less than 50%

prompt logical reads within your database , you should aim for a hit ratio

prompt of between 94% ~ 97%.

prompt if you have fewer than 20 users , the sharing of data among users depends

prompt heavily on the application , so you should aim for a hit ratio in the 89%~94%

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

prompt

prompt


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表