知识大全 分析数据库性能的SQL

Posted 语句

篇首语:亦余心之所善兮,虽九死其犹未悔。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 分析数据库性能的SQL相关的知识,希望对你有一定的参考价值。

分析数据库性能的SQL  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

   用于查看哪些实例的哪些操作使用了大量的临时段    SELECT to_number(decode(SID NULL SID)) sid   operation_type OPERATION trunc(EXPECTED_SIZE/ ) ESIZE   trunc(ACTUAL_MEM_USED/ ) MEM trunc(MAX_MEM_USED/ ) MAX MEM   NUMBER_PASSES PASS trunc(TEMPSEG_SIZE/ ) TSIZE  FROM V$SQL_WORKAREA_ACTIVE  ORDER BY ;     查询有热块查询的SQL语句    select hash_value  from v$sqltext a   (select distinct a owner a segment_name a segment_type from  dba_extents a   (select dbarfil dbablk  from (select dbarfil dbablk  from x$bh order by tch desc) where rownum < ) b  where a RELATIVE_FNO = b dbarfil  and a BLOCK_ID <= b dbablk and a block_id + a blocks > b dbablk) b  where a sql_text like % ||b segment_name|| % and b segment_type = TABLE   order by a hash_value a address a piece;     全表扫描    select opname target b num_rows b tablespace_name count(target) from v$session_longops a all_all_tables b  where a TARGET=b owner|| ||b table_name  having count(target)> group by  opname target b num_rows b tablespace_name     查看磁盘排序和缓存排序次数    select to_char(sn snap_time yyyy mm dd hh ) time_   avg(newmen value oldmen value) sorts_memeory   avg(newdsk value olddsk value) disk_sort  from  stats$sysstat oldmen   stats$sysstat newmen   stats$sysstat newdsk   stats$sysstat olddsk   stats$snapshot sn  where  newdsk snap_id=sn snap_id  and   olddsk snap_id=sn snap_id   and   newmen snap_id=sn snap_id  and   newdsk snap_id=sn snap_id   and   oldmen name= sorts (memory)   and   newmen name= sorts (memory)   and   olddsk name= sorts (disk)   and   newdsk name= sorts (disk)   group by to_char(sn snap_time yyyy mm dd hh )     执行最慢的前 个SQL???    select * from (  select  to_char(snap_time dd Mon HH :mi:ss ) mydate   executions               exec   loads                 loads   parse_calls              parse   disk_reads               reads   buffer_gets              gets   rows_processed             rows_proc   sorts                 sorts   sql_text   hash_value  from  perfstat stats$sql_summary sql   perfstat stats$snapshot   sn  where  sql snap_id >  (select min(snap_id) min_snap  from stats$snapshot where snap_time > sysdate $days_back)  and  sql snap_id = sn snap_id  order by $sortskey desc) tt where rownum< ;     SQL缓存池的命中率查询(pinhitratio gethitratio应该大于 %以上)    select namespace gethitratio pinhitratio reloads invalidations  from v$librarycache  where namespace in ( SQL AREA TABLE/PROCEDURE BODY TRIGGER )     数据库的常规参数我就不说了 除了V$parameter中的常规参数外 ORACLE还有大量的隐含参数 下面的语句就可以查询到数据库的所有隐含参数以及其值与参数的描述     SELECT NAME   VALUE   decode(isdefault TRUE Y N ) as Default    decode(ISEM TRUE Y N ) as SesMod   decode(ISYM IMMEDIATE I    DEFERRED D    FALSE N ) as SysMod   decode(IMOD MODIFIED U    SYS_MODIFIED S N ) as Modified   decode(IADJ TRUE Y N ) as Adjusted   description  FROM ( GV$SYSTEM_PARAMETER  SELECT x inst_id as instance   x indx+    ksppinm as NAME   ksppity   ksppstvl as VALUE   ksppstdf as isdefault   decode(bitand(ksppiflg/ ) TRUE FALSE ) as ISEM   decode(bitand(ksppiflg/ )    IMMEDIATE DEFERRED FALSE ) as ISYM   decode(bitand(ksppstvf ) MODIFIED FALSE ) as IMOD   decode(bitand(ksppstvf ) TRUE FALSE ) as IADJ   ksppdesc as DESCRIPTION  FROM x$ksppi x   x$ksppsv y  WHERE x indx = y indx  AND substr(ksppinm ) = _   AND x inst_id = USERENV( Instance )  )  ORDER BY NAME     想知道现在哪个用户正在利用临时段吗?这个语句将告诉你哪个用户正在利用临时段     SELECT b tablespace b segfile# b segblk# b blocks a sid a serial#   a username a osuser a status c sql_text  FROM v$session a v$sort_usage b v$sql c  WHERE a saddr = b session_addr  AND a sql_address = c address(+)  ORDER BY b tablespace b segfile# b segblk# b blocks;     查看磁盘碎片    select tablespace_name sqrt(max(blocks)/sum(blocks))*  ( /sqrt(sqrt(count(blocks)))) FSFI  from dba_free_space  group by tablespace_name order by      查看表空间的名称及大小    select t tablespace_name round(sum(bytes/( * )) ) ts_size  from dba_tablespaces t dba_data_files d  where t tablespace_name = d tablespace_name  group by t tablespace_name;     查看表空间物理文件的名称及大小    select tablespace_name file_id file_name   round(bytes/( * ) ) total_space  from dba_data_files  order by tablespace_name;     查看回滚段名称及大小    select segment_name tablespace_name r status   (initial_extent/ ) InitialExtent (next_extent/ ) NextExtent   max_extents v curext CurExtent  From dba_rollback_segs r v$rollstat v  Where r segment_id = v usn(+)  order by segment_name     耗资源的进程(top session)    select s schemaname schema_name   decode(sign( mand)   to_char(mand) Action Code # || to_char(mand) ) action   status  session_status   s osuser os_user_name   s sid      p spid      s serial# serial_num   nvl(s username [Oracle process] ) user_name   s terminal terminal   s program program   st value criteria_value from v$sesstat st   v$session s  v$process p  where st sid = s sid and  st statistic# = to_number( ) and  ( ALL = ALL   or s status = ALL ) and p addr = s paddr order by st value desc  p spid asc s username asc s osuser asc     查看锁(lock)情况    select /*+ RULE */ ls osuser os_user_name   ls username user_name   decode(ls type RW Row wait enqueue lock TM DML enqueue lock TX    Transaction enqueue lock UL User supplied lock ) lock_type   o object_name object   decode(ls lmode null Row Share    Row Exclusive Share Share Row Exclusive Exclusive null)  lock_mode   o owner   ls sid   ls serial# serial_num   ls id   ls id   from sys dba_objects o (  select s osuser   s username   l type   l lmode   s sid   s serial#   l id   l id   from v$session s   v$lock l  where s sid = l sid ) ls where o object_id = ls id and  o owner  <> SYS   order by o owner o object_name     查看低效率的SQL语句    SELECT EXECUTIONS DISK_READS BUFFER_GETS   ROUND((BUFFER_GETS DISK_READS)/BUFFER_GETS ) Hit_radio   ROUND(DISK_READS/EXECUTIONS ) Reads_per_run   SQL_TEXT  FROM  V$SQLAREA  WHERE EXECUTIONS>   AND   BUFFER_GETS >   AND (BUFFER_GETS DISK_READS)/BUFFER_GETS <   ORDER BY DESC cha138/Article/program/Oracle/201311/17408

相关参考

知识大全 怎样保持Oracle数据库SQL性能的稳定性

怎样保持Oracle数据库SQL性能的稳定性  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  有客

知识大全 oracle数据库性能监控的SQL的几种情况

oracle数据库性能监控的SQL的几种情况  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  监控

知识大全 从外到内提高SQL Server数据库性能

从外到内提高SQLServer数据库性能  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  如何提高

知识大全 sql server 2008亿万数据性能优化

  根据设计惯例查询的时候主子表通过关键词字段关联查询查询语句如下  selecttopawordaqueryurlairankatitleabaiduurlaitrafficaitrafficbib

知识大全 利用typeperf工具收集SQL Server性能数据[3]

利用typeperf工具收集SQLServer性能数据[3]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看

知识大全 利用typeperf工具收集SQL Server性能数据[1]

利用typeperf工具收集SQLServer性能数据[1]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看

知识大全 利用typeperf工具收集SQL Server性能数据[2]

利用typeperf工具收集SQLServer性能数据[2]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看

知识大全 MS SQL Server数据库事务锁机制分析

MSSQLServer数据库事务锁机制分析  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  锁是网

知识大全 在SQL Server 2000查询分析器里面收缩数据库日志

在SQLServer2000查询分析器里面收缩数据库日志  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下

知识大全 SQL语句性能调整之性能调整综述

SQL语句性能调整之性能调整综述  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  Oracle数据