SQL memo for some performance queries

Source: Internet
Author: User

--Check the database for wait events

From v$session_wait
Where event is not a like ' sql% ' and an event not a like ' rdbms% '

--Find time-consuming operations in the system
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;

--View the time-consuming operation in 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;

--View the time-consuming operation in 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;


--Find the Top 10 poor performance 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 of the waiting time and the acquisition of the system wait event
SELECT * FROM (SELECT *
From V$system_event where event is not a like ' sql% ' ORDER by
Total_waits desc) where rownum<=5

--Check for long-running 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;

--Check the process that consumes the highest 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% ';


--Check the table with high degree of fragmentation
Select Segment_name Table_name,count (*)
Extents from Dba_segments where owner isn't in (' sys ', ' system ')
GROUP BY Segment_name have count (*) = (select Max (COUNT (*))
From Dba_segments Group by segment_name);

--Check the 1/o ratio of table space
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


--Detecting the I/O ratio of the file system

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#

--Check for deadlocks and handling
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;

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

SQL memo for some performance queries

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.