1. Wait for the monitoring case:
Select Event,sum (Decode (wait_time,0,0,1)) prev, sum (decode (wait_time,0,1,0)) curr,count (*)
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. Monitor the I/O ratio of the 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
4. The I/O ratio of the system for monitoring the empty file:
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. Look up 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), 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. Find a user session with more CPU
12 is CPU used by this session
Select A.sid,spid,status,substr (a.program,1,40) prog,a.terminal,osuser,value/60/100 value
From V$session a,v$process B,v$sesstat C
where c.statistic#=12 and C.sid=a.sid and a.paddr=b.addr order by value Desc;
19. Monitor the use of Log_buffer: (the value is preferably less than 1%, otherwise increase the size of Log_buffer)
Select Rbar.name,rbar.value,re.name,re.value, (rbar.value*100)/re.value| | ' % ' "Radio"
From V$sysstat Rbar,v$sysstat re
where rbar.name= ' Redo buffer allocation retries '
and re.name= ' Redo entries ';
20. View the SQL statements that have been run:
SELECT Sql_text
From V$sql
21. Find all Table space usage:
SELECT D.tablespace_name,
Space | | ' m ' "Sum_space (m)",
Blocks "Sum_blocks",
SPACE-NVL (free_space, 0) | | ' m ' "Used_space (m)",
Round ((1-NVL (free_space, 0)/space) * 100, 2) | | '% ' "used_rate (%)",
Free_space | | ' m ' "Free_space (m)"
From (SELECT Tablespace_name,
Round (SUM (bytes)/(1024x768 * 1024x768), 2) space,
SUM (blocks) blocks
From Dba_data_files
GROUP by Tablespace_name) d,
(SELECT Tablespace_name,
Round (SUM (bytes)/(1024x768 * 1024x768), 2) free_space
From Dba_free_space
GROUP by Tablespace_name) F
WHERE D.tablespace_name = f.tablespace_name (+)
UNION All--if there is a temporary table space
SELECT D.tablespace_name,
Space | | ' m ' "Sum_space (m)",
Blocks Sum_blocks,
Used_space | | ' m ' "Used_space (m)",
Round (NVL (used_space, 0)/space * 100, 2) | | '% ' "used_rate (%)",
NVL (free_space, 0) | | ' m ' "Free_space (m)"
From (SELECT Tablespace_name,
Round (SUM (bytes)/(1024x768 * 1024x768), 2) space,
SUM (blocks) blocks
From Dba_temp_files
GROUP by Tablespace_name) d,
(SELECT Tablespace_name,
Round (SUM (bytes_used)/(1024x768 * 1024x768), 2) Used_space,
Round (SUM (bytes_free)/(1024x768 * 1024x768), 2) free_space
From V$temp_space_header
GROUP by Tablespace_name) F
WHERE D.tablespace_name = f.tablespace_name (+)
ORDER by 1;
22. Find the location of the trace file
SELECT D.value | | '/' | | Lower (RTrim (i.instance, Chr (0))) | | ' _ora_ ' | |
P.spid | | '. TRC ' as ' trace_file_name '
From (SELECT p.spid
From V$mystat m, v$session s, v$process p
WHERE m.statistic# = 1
and S.sid = M.sid
and p.addr = s.paddr) p,
(SELECT t.instance
From V$thread T, V$parameter v
WHERE v.name = ' thread '
and (v.value = 0 OR t.thread# = to_number (v.value))) I,
(SELECT VALUE from v$parameter WHERE NAME = ' user_dump_dest ') D;
Oracle Common Monitoring SQL statements