一些性能查询的SQL 备忘

--检查数据库的等待事件

from v$session_wait
where event not like ‘SQL%‘ and event not like ‘rdbms%‘

--找出系统中耗时的操作
select b.username username,a.disk_reads reads,
       a.executions exec,a.disk_reads/decode(a.executions,0,1,a.executions)
           rds_exec_ratio,
       a.sql_text statement
from v$sqlarea a,dba_users b
where a.parsing_user_id=b.user_id
and   a.disk_reads >100000
order by a.disk_reads desc;

--查看buffer中耗时的操作
select * from 
  (select address,rank() over( order by buffer_gets desc) as rank_bufgets,
   to_char(100*ratio_to_report(buffer_gets) over(),‘999.99‘) pct_bufgets
   from v$sql )
  where rank_bufgets <11;

-- 查看buffer中耗时的操作
select * from 
  (select sql_text,rank() over( order by buffer_gets desc) as rank_bufgets,
   to_char(100*ratio_to_report(buffer_gets) over(),‘999.99‘) pct_bufgets
   from v$sql )
  where rank_bufgets <11;

--查找前十条性能差的SQL
select * from (select parsing_user_id
executions,sorts,command_type,disk_reads,
sql_text from v$sqlarea order by disk_reads desc)
where rownum<10;

--等待时间最多的5和系统等待事件的获取
 select * from (select * 
 from v$system_event where event not like ‘sql%‘ order by
total_waits desc) where rownum<=5

--检查运行很久的SQL
column username format a12
column opname format a16
column progress format a8
SELECT USERNAME,SID,OPNAME,ROUND(SOFAR*100 / TOTALWORK,0) || ‘%‘ AS
PROGRESS,TIME_REMAINING,SQL_TEXT FROM V$SESSION_LONGOPS , V$SQL WHERE TIME_REMAINING <>
0 AND SQL_ADDRESS=ADDRESS AND SQL_HASH_VALUE = HASH_VALUE;

--检查消耗CPU最高的进程
SET LINE 240
SET VERIFY OFF
COLUMN SID FORMAT 999
COLUMN PID FORMAT 999
COLUMN S_# FORMAT 999
COLUMN USERNAME FORMAT A9 HEADING "ORA USER"
COLUMN PROGRAM FORMAT A29
COLUMN SQL FORMAT A60
COLUMN OSNAME FORMAT A9 HEADING "OS USER"
SELECT P.PID PID,S.SID SID,P.SPID SPID,S.USERNAME USERNAME,S.OSUSER OSNAME,P.SERIAL#
S_#,P.TERMINAL,P.PROGRAM PROGRAM,P.BACKGROUND,S.STATUS,RTRIM(SUBSTR(A.SQL_TEXT, 1, 80))
SQLFROM V$PROCESS P, V$SESSION S,V$SQLAREA A WHERE P.ADDR = S.PADDR AND S.SQL_ADDRESS
= A.ADDRESS (+) AND P.SPID LIKE ‘%&1%‘;

--检查碎片程度高的表
 select segment_name table_name,count(*) 
extents from dba_segments where owner not in (‘sys‘,‘system‘) 
group by segment_name having count(*)=(select max(count(*)) 
from dba_segments group by segment_name) ;

--检查表空间的1/O比例
 select df.tablespace_name name,df.file_name "FILE",
F.phyrds pyr,f.phyblkrd pbr,f.phywrts pyw,f.phyblkwrt pbw from v$filestat f,
dba_data_files df
where f.file#=df.file_id order by df.tablespace_name;

select df.tablespace_name name,df.file_name "File"
from v$filestat f,dba_data_files df
where f.file#=df.file_id
order by tablespace_name

--检测文件系统的I/O比例

select substr(a.file#,1,2) "#",substr(a.name,1,30) "NAME",
a.status,a.bytes,b.phyrds,b.phywrts 
from v$datafile a,
v$filestat b
where a.file# = b.file#

--检查死锁及处理
select sid,serial#,username,schemaname,osuser,machine,
terminal,program,owner,object_name,object_type,o.object_id
from dba_objects o,v$locked_object l,v$session s
where o.object_id=l.object_id and s.sid=l.session_id;

转:http://www.cnblogs.com/jerryxing/archive/2013/02/19/2916471.html

时间: 2024-12-23 09:49:47

一些性能查询的SQL 备忘的相关文章

Postgresql,常用sql备忘

1.查看所有表的名称 Postgresql,greeplum,如果数据库在几千里以外,数据量巨大,网速不好,使用pgadmin客户端,那么你大部分时间都要浪费在等在中... 使用pgadmin的query是个不错的选择,但是,怎么才能知道表名呢,这丫真没mysql好用—— SELECT tablename FROM pg_tables where tablename not like 'gp%' and tablename not like 'gp%' and tablename not lik

数据统计SQL备忘

1.统计9月注册角色首次充值时的游戏时长分布(分钟,人数),单位:分钟 SELECT sub.minutes,        Count(roleId) AS count FROM   (SELECT pr.roleId,                Timestampdiff(MINUTE, Max(player_login.logTime), pr.logTime)                + Ifnull(Max(player_logout.totalOnlineMins), 0)

Mysql又一次整理笔记--woods备忘

==============================SQL备忘 CRUD 查询 多表 事件等=============================== -------------------------------------------------------------------------------------------------- 一.数据库 1.创建数据库 create database [if not exists] db_name [character set

Mysql重新整理笔记--woods备忘

==============================SQL备忘 CRUD 查询 多表 事件等=============================== -------------------------------------------------------------------------------------------------- 一.数据库 1.创建数据库 create database [if not exists] db_name [character set

工作中常用SQL 查询语句备忘

--当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列.select (case when a>b then a else b end ), (case when b>c then b esle c end) from table_name --求和查询 create table #tmp(rq varchar(10), shengfu nchar(1)) insert into #tmp values('2005-05-09','胜') insert into #tm

SQL Server -- 自定义函数(学习总结,备忘)

SQL Server自定义函数,以前只在书上看过,没有动手去敲一敲,今天刚好接触到,看了几篇博文学习了下.做好备忘很重要!! (@[email protected])Y Learn from:http://www.cnblogs.com/lideng/archive/2013/04/15/3022418.html 自定义函数分为:标量值函数或表值函数两种. 标量值函数:如果 RETURNS 子句指定一种标量数据类型,则函数为标量值函数. 表值函数:如果 RETURNS 子句指定 TABLE,则函

SQL注入备忘单

Find and exploit SQL Injections with free Netsparker SQL Injection Scanner SQL Injection Cheat Sheet, Document Version 1.4 About SQL Injection Cheat Sheet Currently only for MySQL and Microsoft SQL Server, some ORACLE and some PostgreSQL. Most of sam

Visual Studio Entity Framework (EF) 生成SQL 代码 性能查询

Visual Studio Entity Framework (EF) 生成SQL 代码 性能查询 SQL 中,有SQL Server Profiler可以用来查询性能以及查看外部调用的SQL代码. 但是,EF 连接MYSQL 之后,部分代码没法查询EF生成的SQL 代码,如下代码: db.BaseDept.Remove(basedept)的时候, db.BaseDept打断点,查询到的是select 语句, Remove之后,就变成执行结果了,具体生成的DELETE 的SQL 代码无法查看.

Sphinx 配置文件的说明【备忘】

## 数据源src1 source src1 { ## 说明数据源的类型.数据源的类型可以是:mysql,pgsql,mssql,xmlpipe,odbc,python ## 有人会奇怪,python是一种语言怎么可以成为数据源呢? ## python作为一种语言,可以操作任意其他的数据来源来获取数据,更多数据请看:(http://www.coreseek.cn/products-install/python/) type = mysql ## 下面是sql数据库特有的端口,用户名,密码,数据库