0% found this document useful (0 votes)
236 views3 pages

Performance Check DBA

This document contains SQL queries to analyze and monitor Oracle database sessions and performance. It includes queries to identify the top CPU consuming sessions, sessions blocking other sessions, database data file sizes and locations, RAM allocations, current CPU usage by active sessions, SQL statements consuming the most resources, total active sessions, inactive sessions, and how to kill inactive sessions.

Uploaded by

MaheshSai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
236 views3 pages

Performance Check DBA

This document contains SQL queries to analyze and monitor Oracle database sessions and performance. It includes queries to identify the top CPU consuming sessions, sessions blocking other sessions, database data file sizes and locations, RAM allocations, current CPU usage by active sessions, SQL statements consuming the most resources, total active sessions, inactive sessions, and how to kill inactive sessions.

Uploaded by

MaheshSai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Top 10 CPU consuming Session in Oracle ----

col program form a30 heading "Program"


col CPUMins form 99990 heading "CPU in Mins"
select rownum as rank, a.*
from (
SELECT v.sid,sess.Serial# ,program, v.value / (100 * 60) CPUMins
FROM v$statname s , v$sesstat v, v$session sess
WHERE s.name = 'CPU used by this session'
and sess.sid = v.sid
and v.statistic#=s.statistic#
and v.value>0
ORDER BY v.value DESC) a
where rownum < 11;

SQL id consuming more CPU in Oracle ----

col program form a30 heading "Program"


col cpu_usage_sec form 99990 heading "CPU in Seconds"
col MODULE for a18
col OSUSER for a10
col USERNAME for a15
col OSPID for a06 heading "OS PID"
col SID for 99999
col SERIAL# for 999999
col SQL_ID for a15
select * from (
select p.spid "ospid",
(se.SID),ss.serial#,ss.SQL_ID,ss.username,substr(ss.program,1,30) "program",
ss.module,ss.osuser,ss.MACHINE,ss.status,
se.VALUE/100 cpu_usage_sec
from v$session ss,v$sesstat se,
v$statname sn,v$process p
where
se.STATISTIC# = sn.STATISTIC#
and NAME like '%CPU used by this session%'
and se.SID = ss.SID
and ss.username !='SYS'
and ss.status='ACTIVE'
and ss.username is not null
and ss.paddr=p.addr and value > 0
order by se.VALUE desc);

Check any session blocking other session

select
blocking_session,
sid,
serial#,
wait_class,
seconds_in_wait
from
v$session
where
blocking_session is not NULL
order by
blocking_session;
datafiles size and percentage

select df.tablespace_name, df.file_name, round(df.bytes/1024/1024) totalSizeMB,


nvl(round(usedBytes/1024/1024), 0) usedMB, nvl(round(freeBytes/1024/1024), 0)
freeMB,
nvl(round(freeBytes/df.bytes * 100), 0) freePerc, df.autoextensible
from dba_data_files df
left join (
select file_id, sum(bytes) usedBytes
from dba_extents
group by file_id
) ext on df.file_id = ext.file_id
left join (
select file_id, sum(bytes) freeBytes
from dba_free_space
group by file_id
) free on df.file_id = free.file_id
order by df.tablespace_name, df.file_name;

list and paths of datafiles ---- select name from v$datafile;

archive logs path ---- archive log list;

Chaeck RAM allocations on ORACLE

set lines 80
col c1 heading 'STAT' format a25
col c2 heading 'Count' format 999,999,999,999
select distinct
stat_name c1,
value c2
from
dba_hist_osstat
where
stat_name in (
'NUM_CPU_CORES',
'NUM_CPU_SOCKETS',
'PHYSICAL_MEMORY_BYTES'
);

Show CPU Usage for active sessions

SET PAUSE ON
SET PAUSE 'Press Return to Continue'
SET PAGESIZE 60
SET LINESIZE 300

COLUMN username FORMAT A30


COLUMN sid FORMAT 999,999,999
COLUMN serial# FORMAT 999,999,999
COLUMN "cpu usage (seconds)" FORMAT 999,999,999.0000

SELECT
s.username,
t.sid,
s.serial#,
SUM(VALUE/100) as "cpu usage (seconds)"
FROM
v$session s,
v$sesstat t,
v$statname n
WHERE
t.STATISTIC# = n.STATISTIC#
AND
NAME like '%CPU used by this session%'
AND
t.SID = s.SID
AND
s.status='ACTIVE'
AND
s.username is not null
GROUP BY username,t.sid,s.serial#
/

sql text consuming more resources

col cpu_usage_sec form 99990 heading "CPU in Seconds"


select * from (
select
(se.SID),substr(q.sql_text,80),ss.module,ss.status,se.VALUE/100 cpu_usage_sec
from v$session ss,v$sesstat se,
v$statname sn, v$process p, v$sql q
where
se.STATISTIC# = sn.STATISTIC#
AND ss.sql_address = q.address
AND ss.sql_hash_value = q.hash_value
and NAME like '%CPU used by this session%'
and se.SID = ss.SID
and ss.username !='SYS'
and ss.status='ACTIVE'
and ss.username is not null
and ss.paddr=p.addr and value > 0
order by se.VALUE desc);

list total sessions running in database

SELECT sid, serial#, status, username FROM v$session;

list all inactive sessions in database

SELECT sid, serial#, status, username FROM v$session where status='INACTIVE';

kill inactive sessions

ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;

BEGIN
FOR r IN (select sid,serial# from v$session where status='INACTIVE')
LOOP
EXECUTE IMMEDIATE 'alter system kill session ''' || r.sid || ','
|| r.serial# || ''' immediate';
END LOOP;
END;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy