Oracle Daily Monitoring statements

Source: Internet
Author: User
Tags sorts what sql

Oracle's common performance monitoring SQL statements

First, query the history of sql:

---The SQL statement being executed:
Select A.username, A.sid,b.sql_text, B.sql_fulltext
From V$session A, V$sqlarea b where a.sql_address = b.address;

---Query the SQL statement that Oracle is executing and the user who executes the statement:
SELECT b.sid Oracleid, b.username Log in to the Oracle user name, b.serial#,
SPID operating system ID, PADDR, sql_text executing SQL, b.machine computer name
From V$process A, v$session B, V$sqlarea c
WHERE a.addr = b.paddr and b.sql_hash_value = C.hash_value;

---to view the issuer's release program for executing SQL
SELECT osuser Computer login status, program initiated the request, USERNAME login system username,
SCHEMANAME, B.cpu_time spends Cpu time, STATUS, B.sql_text executed SQL
From V$session A left JOIN v$sql B on a.sql_address = b.address and A.sql_hash_value = B.hash_value
ORDER by B.cpu_time DESC;


---executed SQL statement:
Select B.sql_text,b.first_load_time,b.sql_fulltext
From V$sqlarea b where b.first_load_time between ' 2017-06-06/18:00:47 ' and ' 2017-06-06/20:00:47 '
Order BY B.first_load_time;

---Query the most recently executed SQL statement:
Select Sql_text,last_load_time from V$sql order by last_load_time Desc;
SELECT Sql_text, last_load_time from V$sql WHERE last_load_time are not NULL and sql_text like ' select% ' ORDER by last_load _time DESC;
SELECT Sql_text, last_load_time from V$sql WHERE last_load_time are not NULL and sql_text like ' update% ' ORDER by last_load _time DESC;
SELECT Sql_text, last_load_time from V$sql WHERE last_load_time are not NULL and last_load_time like ' 14-06-09% ' ORDER by L Ast_load_time DESC;

---Find the first 10 poor performance SQL statements:
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;

---View the running session with the larger IO:
SELECT SE.SID,SE.SERIAL#,PR. Spid,se.username,se.status,
Se.terminal,se.program,se. Module,se.sql_address,st.event,st.
P1text,si.physical_reads,
Si.block_changes from V$session Se,v$session_wait St,
V$sess_io si,v$process PR WHERE St.sid=se.sid and St.
Sid=si.sid and SE. Paddr=pr. ADDR and Se.sid>6 and St.
Wait_time=0 and st.event not like '%sql% ' ORDER by Physical_reads DESC;


--View the current number of session connections
Select COUNT (*) from v$session;
--View the details of the session
Select Sid,serial#,username,program,machine,status from V$session;


Lock table Query sql
SELECT object_name, Machine, S.sid, s.serial#
From Gv$locked_object L, dba_objects O, gv$session s
WHERE l.object_id = o.object_id
and l.session_id = S.sid;

--Release session SQL:
--alter system kill session ' Sid, Serial# ';
ALTER system kill session ' 23, 1647 ';


--Identify Oracle's current locked object
SELECT l.session_id Sid, S.serial#, L.locked_mode lock mode, l.oracle_username login user,
L.os_user_name Login Machine user name, S.machine machine name, s.terminal end user name, O.object_name locked object name, S.logon_time logon database time
From V$locked_object L, all_objects O, v$session s
WHERE l.object_id = o.object_id and l.session_id = S.sid
ORDER by Sid, S.serial#;

--kill drop the current lock object can be
Alter system kill session ' Sid, S.serial# ';

Second, daily performance monitoring statements:

1. Waiting for the monitoring case

Select Event,sum (Decode (wait_time,0,0,1)) "Prev",
SUM (decode (wait_time,0,1,0)) "Curr", COUNT (*) "Tot"
From v$session_wait
Group BY event order by 4;

2. Race Conditions for rollback segments

Select name, waits, gets, waits/gets "Ratio"
From V$rollstat A, v$rollname b
where A.usn = B.usn;

3. Monitoring the I/O ratio of table spaces

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;

4. Monitor 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#;

5. Find all the indexes under one user

Select User_indexes.table_name, User_indexes.index_name,uniqueness, column_name
From User_ind_columns, user_indexes
where user_ind_columns.index_name = User_indexes.index_name
and user_ind_columns.table_name = User_indexes.table_name
Order by User_indexes.table_type, User_indexes.table_name,
User_indexes.index_name, column_position;

6. Monitor the ratio of the SGA

Select A.value + b.value "logical_reads", C.value "Phys_reads",
Round ((a.value+b.value)-c.value)/(A.value+b.value)) "BUFFER hit RATIO"
From V$sysstat A, V$sysstat B, V$sysstat c
where a.statistic# = b.statistic# = 39
and c.statistic# = 40;

7. Monitor the dictionary buffer hit ratio in the SGA

Select parameter, gets,getmisses, getmisses/(gets+getmisses) *100 "Miss Ratio",
(SUM (getmisses)/(SUM (gets) +sum (getmisses))) *100 "hit ratio"
From V$rowcache
where Gets+getmisses <>0
Group BY parameter, gets, getmisses;

8. Monitor the hit rate of shared buffers in the SGA, which should be less than 1%

Select SUM (Pins) "Total pins", sum (reloads) "Total reloads",
SUM (reloads)/sum (pins) *100 Libcache
From V$librarycache;

Select SUM (pinhits-reloads)/sum (Pins) "Hit Radio", SUM (reloads)/sum (Pins) "Reload percent"
From V$librarycache;

9. Display the category and size of all database objects

Select count (name) num_instances, type, sum (source_size) source_size,
SUM (parsed_size) parsed_size, sum (code_size) code_size, sum (error_size) error_size,
SUM (source_size) +sum (parsed_size) +sum (code_size) +sum (error_size) size_required
From Dba_object_size
Group By type Order by 2;

10. Monitor the hit rate of redo log buffers in SGA, should be less than 1%

SELECT name, gets, misses, immediate_gets, immediate_misses,
Decode (gets,0,0,misses/gets*100) Ratio1,
Decode (immediate_gets+immediate_misses,0,0,
Immediate_misses/(immediate_gets+immediate_misses) *100) Ratio2
From V$latch WHERE name in (' Redo allocation ', ' redo copy ');

11. Monitor the memory and hard disk sequencing ratios, preferably less than. 10, increase sort_area_size

SELECT name, value from V$sysstat WHERE name in (' Sorts (memory) ', ' sorts (disk) ');


12. Monitor the current database who is running what SQL statement

SELECT Osuser, username, sql_text from v$session A, V$sqltext b
where a.sql_address =b.address order by address, piece;

13. Monitoring the dictionary buffers

Select (sum (pins-reloads))/sum (PINS) "LIB CACHE" from V$librarycache;
Select (sum (gets-getmisses-usage-fixed))/sum (GETS) "ROW CACHE" from V$rowcache;
Select SUM (PINS) "Executions", sum (reloads) "CACHE MISSES while executing" from V$librarycache;

The latter divided by the former, this ratio is less than 1%, close to 0% is good.

Select sum (gets) "DICTIONARY GETS", Sum (getmisses) "DICTIONARY CACHE GET MISSES"
From V$rowcache

14. Find the Oracle Character set

SELECT * from sys.props$ where name= ' nls_characterset ';

15. Monitoring MTS

Select busy/(Busy+idle) "Shared servers Busy" from V$dispatcher;

When this value is greater than 0.5, the parameters need to be increased

Select sum (Wait)/sum (TOTALQ) "Dispatcher waits" from V$queue where type= ' dispatcher ';
Select COUNT (*) from V$dispatcher;
Select Servers_highwater from V$mts;

Servers_highwater when approaching mts_max_servers, the parameters need to be increased

16. Fragmentation Level

Select Tablespace_name,count (tablespace_name) from Dba_free_space GROUP by Tablespace_name
Having count (Tablespace_name) >10;

Alter tablespace name COALESCE;
ALTER TABLE name DEALLOCATE unused;

Create or replace view Ts_blocks_v as
Select Tablespace_name,block_id,bytes,blocks, ' free space ' segment_name from Dba_free_space
UNION ALL
Select Tablespace_name,block_id,bytes,blocks,segment_name from Dba_extents;

SELECT * from Ts_blocks_v;

Select Tablespace_name,sum (bytes), max (bytes), COUNT (block_id) from Dba_free_space
Group BY Tablespace_name;

View a table with a 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);

17. Checking the storage of tables and indexes

Select Segment_name,sum (bytes) space,count (*) Ext_quan from dba_extents where
Tablespace_name= ' &tablespace_name ' and segment_type= ' TABLE ' GROUP by Tablespace_name,segment_name;

Select Segment_name,count (*) from dba_extents where segment_type= ' INDEX ' and owner= ' &owner '
Group BY Segment_name;

18. Monitor User

SELECT DISTINCT
P.spid unix_process,
S.terminal,
To_char (S.logon_time, ' yyyy/mon/dd hh24:mi ') Logon_time,
S.username
From V$process p, v$session s
where P.addr=s.paddr ORDER by 2

19. Generate reports for Tablespace usage status

Select T.tablespace_name tb_name, d.tot_size/1024/1024 tot,
(d.tot_size-f.free_size)/1024/1024 used,
free_size/1024/1024 free,
f.max_free_extent/1024/1024 Max_free_extent,
n.max_next_extent/1024/1024 Max_next_extent,
Round (free_size/tot_size * 100,0) pct
From Dba_tablespaces T,
(select Tablespace_name, sum (bytes) tot_size from Dba_data_files
where status = ' AVAILABLE '
Group by Tablespace_name) d,
(select Tablespace_name, sum (bytes) free_size, max (bytes) max_free_extent
From Dba_free_space
GROUP by Tablespace_name) F,
(Select Tablespace_name, max (next_extent) max_next_extent--assume pcs_increase=0
From Dba_segments
Group by Tablespace_name) n
where t.tablespace_name = D.tablespace_name
and d.tablespace_name = F.tablespace_name
and f.tablespace_name = N.tablespace_name
and status = ' ONLINE '
--and d.tablespace_name like Upper (' 1% ')
ORDER BY 7,1

Third, CPU and memory usage monitoring statement:

1. Check the machine performance top isolate several PID numbers that occupy memory or CPU. Then use the Sys/oracle login database to view: "Check the SQL-related information that consumes the most memory SGA"
Check Memory:
Select Server, Osuser, Name, value/1024/1024 Mb, s.sql_id, Spid, s.*
From V$session S, V$sesstat St, V$statname Sn, v$process p
Where St.sid = S.sid
and st.statistic# = sn.statistic#
and Sn.name like ' session PGA memory '
and p.addr = S.paddr
---The following spid is the PID number on the server, if you do not add the following and conditions, find out all.
and p.spid= ' 18988 '
Order by Value Desc;


Check the CPU:
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)) SQL from V$process p,v$session S,v$sqlarea a where
P.addr=s.paddr and s.sql_address=a.address (+)
and p.spid like ' 3148 ';


2. View the top 10 CPU-intensive sql:
SELECT * FROM (select Sql_text,sql_id,cpu_time to V$sql ORDER by cpu_time Desc) where rownum<=10 ORDER by rownum ASC ;
SELECT * FROM (select Sql_text,sql_id,cpu_time to V$sqlarea ORDER by cpu_time Desc) where rownum<=10 order by rownum ASC;
These 2 statements effect basically the same, one from the V$sql view query from the V$sqlarea view.


3. List the 5 most frequently used queries:
Select Sql_text,executions
From (select Sql_text,executions,
Rank () over
(Order BY executions Desc) Exec_rank
From V$sql)
where Exec_rank <=5;

4. The SQL TOP5 that consumes the most disk reads:
Select Disk_reads,sql_text
From (select Sql_text,disk_reads,
Dense_rank () over
(Order BY disk_reads Desc) Disk_reads_rank
From V$sql)
where Disk_reads_rank <=5;

5. Find the query that requires a large buffer read (logical read) operation:
Select Buffer_gets,sql_text
From (select Sql_text,buffer_gets,
Dense_rank () over
(Order BY buffer_gets Desc) Buffer_gets_rank
From V$sql)
where buffer_gets_rank<=5;

Oracle Daily Monitoring statements

Related Article

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.