⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oracle基本操作-13.htm

📁 微软数据库开发梦工场多媒体教学-oracle篇.rar,是多媒体教学的
💻 HTM
字号:
<body bgcolor="#000000">
<font color="#FFFFFF"> <font color="#009900">监控数据库性能的SQL </font> 
<p>1. 监控事例的等待</p>
<p> select event,sum(decode(wait_Time,0,0,1)) &quot;Prev&quot;, <br>
  sum(decode(wait_Time,0,1,0)) &quot;Curr&quot;,count(*) &quot;Tot&quot; <br>
  from v$session_Wait <br>
  group by event order by 4;</p>
<p>2. 回滚段的争用情况</p>
<p> select name, waits, gets, waits/gets &quot;Ratio&quot; <br>
  from v$rollstat a, v$rollname b <br>
  where a.usn = b.usn; </p>
<p>3. 监控表空间的 I/O 比例</p>
<p> select df.tablespace_name name,df.file_name &quot;file&quot;,f.phyrds pyr,<br>
  f.phyblkrd pbr,f.phywrts pyw, f.phyblkwrt pbw<br>
  from v$filestat f, dba_data_files df<br>
  where f.file# = df.file_id<br>
  order by df.tablespace_name;</p>
<p>4. 监控文件系统的 I/O 比例</p>
<p> select substr(a.file#,1,2) &quot;#&quot;, substr(a.name,1,30) &quot;Name&quot;, 
  <br>
  a.status, a.bytes, b.phyrds, b.phywrts <br>
  from v$datafile a, v$filestat b <br>
  where a.file# = b.file#; </p>
<p>5.在某个用户下找所有的索引</p>
<p> select user_indexes.table_name, user_indexes.index_name,uniqueness, column_name<br>
  from user_ind_columns, user_indexes<br>
  where user_ind_columns.index_name = user_indexes.index_name<br>
  and user_ind_columns.table_name = user_indexes.table_name <br>
  order by user_indexes.table_type, user_indexes.table_name,<br>
  user_indexes.index_name, column_position;</p>
<p>6. 监控 SGA 的命中率</p>
<p> select a.value + b.value &quot;logical_reads&quot;, c.value &quot;phys_reads&quot;,<br>
  round(100 * ((a.value+b.value)-c.value) / (a.value+b.value)) &quot;BUFFER HIT 
  RATIO&quot; <br>
  from v$sysstat a, v$sysstat b, v$sysstat c<br>
  where a.statistic# = 38 and b.statistic# = 39 <br>
  and c.statistic# = 40; </p>
<p>7. 监控 SGA 中字典缓冲区的命中率</p>
<p> select parameter, gets,Getmisses , getmisses/(gets+getmisses)*100 &quot;miss 
  ratio&quot;,<br>
  (1-(sum(getmisses)/ (sum(gets)+sum(getmisses))))*100 &quot;Hit ratio&quot;<br>
  from v$rowcache <br>
  where gets+getmisses &lt;&gt;0<br>
  group by parameter, gets, getmisses; </p>
<p>8. 监控 SGA 中共享缓存区的命中率,应该小于1%</p>
<p> select sum(pins) &quot;Total Pins&quot;, sum(reloads) &quot;Total Reloads&quot;,<br>
  sum(reloads)/sum(pins) *100 libcache<br>
  from v$librarycache;</p>
<p> select sum(pinhits-reloads)/sum(pins) &quot;hit radio&quot;,sum(reloads)/sum(pins) 
  &quot;reload percent&quot; <br>
  from v$librarycache;</p>
<p>9. 显示所有数据库对象的类别和大小</p>
<p> select count(name) num_instances ,type ,sum(source_size) source_size ,<br>
  sum(parsed_size) parsed_size ,sum(code_size) code_size ,sum(error_size) error_size,<br>
  sum(source_size) +sum(parsed_size) +sum(code_size) +sum(error_size) size_required 
  <br>
  from dba_object_size <br>
  group by type order by 2;</p>
<p>10. 监控 SGA 中重做日志缓存区的命中率,应该小于1%</p>
<p> SELECT name, gets, misses, immediate_gets, immediate_misses,<br>
  Decode(gets,0,0,misses/gets*100) ratio1,<br>
  Decode(immediate_gets+immediate_misses,0,0,<br>
  immediate_misses/(immediate_gets+immediate_misses)*100) ratio2<br>
  FROM v$latch WHERE name IN ('redo allocation', 'redo copy'); </p>
<p>11. 监控内存和硬盘的排序比率,最好使它小于 .10,增加 sort_area_size </p>
<p> SELECT name, value FROM v$sysstat WHERE name IN ('sorts (memory)', 'sorts 
  (disk)'); </p>
<p><br>
  12. 监控当前数据库谁在运行什么SQL语句</p>
<p> SELECT osuser, username, sql_text from v$session a, v$sqltext b<br>
  where a.sql_address =b.address order by address, piece;</p>
<p>13. 监控字典缓冲区</p>
<p> SELECT (SUM(PINS - RELOADS)) / SUM(PINS) &quot;LIB CACHE&quot; FROM V$LIBRARYCACHE;<br>
  SELECT (SUM(GETS - GETMISSES - USAGE - FIXED)) / SUM(GETS) &quot;ROW CACHE&quot; 
  FROM V$ROWCACHE;<br>
  SELECT SUM(PINS) &quot;EXECUTIONS&quot;, SUM(RELOADS) &quot;CACHE MISSES WHILE 
  EXECUTING&quot; FROM V$LIBRARYCACHE; </p>
<p> 后者除以前者,此比率小于1%,接近0%为好。</p>
<p> SELECT SUM(GETS) &quot;DICTIONARY GETS&quot;,SUM(GETMISSES) &quot;DICTIONARY 
  CACHE GET MISSES&quot;<br>
  FROM V$ROWCACHE</p>
<p>14. 找ORACLE字符集</p>
<p> select * from sys.props$ where name='NLS_CHARACTERSET'; </p>
<p>15. 监控 MTS</p>
<p> select busy/(busy+idle) &quot;shared servers busy&quot; from v$dispatcher;</p>
<p> 此值大于0.5时,参数需加大</p>
<p> select sum(wait)/sum(totalq) &quot;dispatcher waits&quot; from v$queue where 
  type='dispatcher';<br>
  select count(*) from v$dispatcher;<br>
  select servers_highwater from v$mts;</p>
<p> servers_highwater接近mts_max_servers时,参数需加大</p>
<p>16. 碎片程度</p>
<p> select tablespace_name,count(tablespace_name) from dba_free_space group by 
  tablespace_name <br>
  having count(tablespace_name)&gt;10;</p>
<p> alter tablespace name coalesce;<br>
  alter table name deallocate unused;</p>
<p> create or replace view ts_blocks_v as<br>
  select tablespace_name,block_id,bytes,blocks,'free space' segment_name from 
  dba_free_space<br>
  union all<br>
  select tablespace_name,block_id,bytes,blocks,segment_name from dba_extents;</p>
<p> select * from ts_blocks_v;</p>
<p> select tablespace_name,sum(bytes),max(bytes),count(block_id) from dba_free_space 
  <br>
  group by tablespace_name;</p>
<p> 查看碎片程度高的表</p>
<p> SELECT segment_name table_name , COUNT(*) extents<br>
  FROM dba_segments WHERE owner NOT IN ('SYS', 'SYSTEM') GROUP BY segment_name<br>
  HAVING COUNT(*) = (SELECT MAX( COUNT(*) ) FROM dba_segments GROUP BY segment_name);</p>
<p>17. 表、索引的存储情况检查</p>
<p> select segment_name,sum(bytes),count(*) ext_quan from dba_extents where <br>
  tablespace_name='&amp;tablespace_name' and segment_type='TABLE' group by tablespace_name,segment_name;</p>
<p> select segment_name,count(*) from dba_extents where segment_type='INDEX' and 
  owner='&amp;owner'<br>
  group by segment_name;</p>
<p>18、找使用CPU多的用户session</p>
<p> 12是cpu used by this session</p>
<p> select a.sid,spid,status,substr(a.program,1,40) prog,a.terminal,osuser,value/60/100 
  value<br>
  from v$session a,v$process b,v$sesstat c<br>
  where c.statistic#=12 and c.sid=a.sid and a.paddr=b.addr order by value desc;<br>
</p>
</font>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -