Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2783225
  • 博文数量: 423
  • 博客积分: 7770
  • 博客等级: 少将
  • 技术积分: 4766
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-09 11:58
个人简介

Oracle/DB2/Postgresql/Mysql/Hadoop/Greenplum/Postgres-xl/Mongodb

文章分类

全部博文(423)

文章存档

2019年(3)

2018年(6)

2017年(27)

2016年(23)

2015年(30)

2014年(16)

2013年(31)

2012年(73)

2011年(45)

2010年(14)

2009年(30)

2008年(30)

2007年(63)

2006年(32)

分类: Oracle

2011-05-23 10:11:24

  1. . 监控事例的等待

  2. select event,sum(decode(wait_Time,0,0,1)) "rev",
  3. sum(decode(wait_Time,0,1,0)) "Curr",count(*) "Tot"
  4. from v$session_Wait
  5. group by event order by 4;

  6. 2. 回滚段的争用情况

  7. select name, waits, gets, waits/gets "Ratio"
  8. from v$rollstat a, v$rollname b
  9. where a.usn = b.usn;

  10. 3. 监控表空间的 I/O 比例

  11. select df.tablespace_name name,df.file_name "file",f.phyrds pyr,
  12. f.phyblkrd pbr,f.phywrts pyw, f.phyblkwrt pbw
  13. from v$filestat f, dba_data_files df
  14. where f.file# = df.file_id
  15. order by df.tablespace_name;

  16. 4. 监控文件系统的 I/O 比例

  17. select substr(a.file#,1,2) "#", substr(a.name,1,30) "Name",
  18. a.status, a.bytes, b.phyrds, b.phywrts
  19. from v$datafile a, v$filestat b
  20. where a.file# = b.file#;

  21. 5.在某个用户下找所有的索引

  22. select user_indexes.table_name, user_indexes.index_name,uniqueness, column_name
  23. from user_ind_columns, user_indexes
  24. where user_ind_columns.index_name = user_indexes.index_name
  25. and user_ind_columns.table_name = user_indexes.table_name
  26. order by user_indexes.table_type, user_indexes.table_name,
  27. user_indexes.index_name, column_position;

  28. 6. 监控 SGA 的命中率

  29. select a.value + b.value "logical_reads", c.value "phys_reads",
  30. round(100 * ((a.value+b.value)-c.value) / (a.value+b.value)) "BUFFER HIT RATIO"
  31. from v$sysstat a, v$sysstat b, v$sysstat c
  32. where a.statistic# = 38 and b.statistic# = 39
  33. and c.statistic# = 40;

  34. 7. 监控 SGA 中字典缓冲区的命中率

  35. select parameter, gets,Getmisses , getmisses/(gets+getmisses)*100 "miss ratio",
  36. (1-(sum(getmisses)/ (sum(gets)+sum(getmisses))))*100 "Hit ratio"
  37. from v$rowcache
  38. where gets+getmisses <>;0
  39. group by parameter, gets, getmisses;

  40. 8. 监控 SGA 中共享缓存区的命中率,应该小于1%

  41. select sum(pins) "Total Pins", sum(reloads) "Total Reloads",
  42. sum(reloads)/sum(pins) *100 libcache
  43. from v$librarycache;

  44. select sum(pinhits-reloads)/sum(pins) "hit radio",sum(reloads)/sum(pins) "reload percent"
  45. from v$librarycache;

  46. 9. 显示所有数据库对象的类别和大小

  47. select count(name) num_instances ,type ,sum(source_size) source_size ,
  48. sum(parsed_size) parsed_size ,sum(code_size) code_size ,sum(error_size) error_size,
  49. sum(source_size) +sum(parsed_size) +sum(code_size) +sum(error_size) size_required
  50. from dba_object_size
  51. group by type order by 2;

  52. 10. 监控 SGA 中重做日志缓存区的命中率,应该小于1%

  53. SELECT name, gets, misses, immediate_gets, immediate_misses,
  54. Decode(gets,0,0,misses/gets*100) ratio1,
  55. Decode(immediate_gets+immediate_misses,0,0,
  56. immediate_misses/(immediate_gets+immediate_misses)*100) ratio2
  57. FROM v$latch WHERE name IN ('redo allocation', 'redo copy');

  58. 11. 监控内存和硬盘的排序比率,最好使它小于 .10,增加 sort_area_size

  59. SELECT name, value FROM v$sysstat WHERE name IN ('sorts (memory)', 'sorts (disk)');

  60. 12. 监控当前数据库谁在运行什么SQL语句

  61. SELECT osuser, username, sql_text from v$session a, v$sqltext b
  62. where a.sql_address =b.address order by address, piece;

  63. 13. 监控字典缓冲区

  64. SELECT (SUM(PINS - RELOADS)) / SUM(PINS) "LIB CACHE" FROM V$LIBRARYCACHE;
  65. SELECT (SUM(GETS - GETMISSES - USAGE - FIXED)) / SUM(GETS) "ROW CACHE" FROM V$ROWCACHE;
  66. SELECT SUM(PINS) "EXECUTIONS", SUM(RELOADS) "CACHE MISSES WHILE EXECUTING" FROM V$LIBRARYCACHE;

  67. 后者除以前者,此比率小于1%,接近0%为好。

  68. SELECT SUM(GETS) "DICTIONARY GETS",SUM(GETMISSES) "DICTIONARY CACHE GET MISSES"
  69. FROM V$ROWCACHE

  70. 14. 找ORACLE字符集

  71. select * from sys.props$ where name='NLS_CHARACTERSET';

  72. 15. 监控 MTS

  73. select busy/(busy+idle) "shared servers busy" from v$dispatcher;

  74. 此值大于0.5时,参数需加大

  75. select sum(wait)/sum(totalq) "dispatcher waits" from v$queue where type='dispatcher';
  76. select count(*) from v$dispatcher;
  77. select servers_highwater from v$mts;

  78. servers_highwater接近mts_max_servers时,参数需加大

  79. 16. 碎片程度

  80. select tablespace_name,count(tablespace_name) from dba_free_space group by tablespace_name
  81. having count(tablespace_name)>;10;

  82. alter tablespace name coalesce;
  83. alter table name deallocate unused;

  84. create or replace view ts_blocks_v as
  85. select tablespace_name,block_id,bytes,blocks,'free space' segment_name from dba_free_space
  86. union all
  87. select tablespace_name,block_id,bytes,blocks,segment_name from dba_extents;

  88. select * from ts_blocks_v;

  89. select tablespace_name,sum(bytes),max(bytes),count(block_id) from dba_free_space
  90. group by tablespace_name;

  91. 查看碎片程度高的表

  92. SELECT segment_name table_name , COUNT(*) extents
  93. FROM dba_segments WHERE owner NOT IN ('SYS', 'SYSTEM') GROUP BY segment_name
  94. HAVING COUNT(*) = (SELECT MAX( COUNT(*) ) FROM dba_segments GROUP BY segment_name);

  95. 17. 表、索引的存储情况检查

  96. select segment_name,sum(bytes),count(*) ext_quan from dba_extents where
  97. tablespace_name='&tablespace_name' and segment_type='TABLE' group by tablespace_name,segment_name;

  98. select segment_name,count(*) from dba_extents where segment_type='INDEX' and wner='&owner'
  99. group by segment_name;

  100. 18、找使用CPU多的用户session

  101. select a.sid,spid,status,substr(a.program,1,40) prog,a.terminal,osuser,value/60/100 value
  102. from v$session a,v$process b,v$sesstat c
  103. where c.statistic#=12 and c.sid=a.sid and a.paddr=b.addr order by value desc;

  104. 监控数据库状态的目的就是找到相关的瓶颈点,但也许有时你的监控语句就会是你的瓶颈点,包括您后台的一些自动的监控。Jason就遇到这样的囧事,不是dbconsole占资源(响应时间>2s)就是监控lock语句占资源,包括oracle的某些maintain功能,需要很好的时间schedual。

  105. 插播就到这里,下篇会继续负载均衡,我们的重点是比较流行的lvs heartbeat。

  106. ———EOF———

  107. 作者: 吴颖敏 |www.futurehandw.com
  108. Email: wuyingminhui@gmail.com
  109. 转载请注明来源:吴颖敏 -www.futurehandw.com
阅读(1504) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~