Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, abdul wahid.

Asked: November 17, 2016 - 6:39 am UTC

Last updated: November 18, 2016 - 6:35 am UTC

Version: 10.2.0.1.0

Viewed 10K+ times! This question is

You Asked

Hi Tom,

I would like to know which queries currently running is consuming host memory

From OS level i came to know that the below process is consuming memory -

$ ps aux | head -1; ps aux | sort -rn +3 | head

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
oracle 14734 0.0 14.2 7362260 4698604 ? Ss Nov15 0:58 oracleABHMOKA01 (LOCAL=NO)

From SQL plus i came to know the user -

SQL> SELECT s.sid, s.serial#, p.spid, s.username, s.program FROM v$session s JOIN v$process p ON p.addr = s.paddr and SPID = '&spid';
Enter value for spid: 14734

SID SERIAL# SPID USERNAME PROGRAM
---------- ---------- ------------ ------------------------------ ------------------------------------------------
667 11506 14734 PHARMACY w3wp.exe

Now i would like to know -

1. which queries are currently running by the above user

2. which of them is consuming memory

Thanks
Abdul

and Connor said...

Firstly, often the OS will give misleading information about memory, because Oracle uses shared memory. For example, if the SGA is 500M, then a 10 processes might show (say) 520M each, because they are attached to 500M of shared memory, and are using 20M of their own.

Probably the best way to see process level memory is by looking at v$sesstat

select
  st.sid,
  s.name, 
  st.value
from v$statname s, v$sesstat st
where st.STATISTIC# = s.STATISTIC#
and s.name like '%pga%'


From each session, you can drill into v$active_session_history to what sql's they have been running, and use the SQL_ID to look in v$sqlstats

Dont forget - it might not be SQL that chews memory - it could be PLSQL programs etc.

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

Performance

Get all the information about database performance in the Database Performance guide.