Question : Shell / sql script to check Oracle current number of processes used : ORA-00020 00018 exceeded

I recently ran into the following 2 issues :
ORA-00020: maximum number of processes (%s) exceeded
ORA-00018: maximum number of sessions (%s) exceeded

Following link described the problem :
http://ora-00020.ora-code.com/msg/40800.html

I can't recall what one of my DBA colleague taught me to do over the phone (I'm no DBA) :
alter ... spfile=500  ( to increase from current 300 processes to 500 )  & then followed by
command below (perhaps I'm missing one more command)  to verify the value have been
changed :
    show parameter session

My management asks : how can I monitor if we'll run close to exceeding these resource/parameters again;  so I'll need a way to monitor if the number of SGA
processes and sessions came close to being exceeded again.

So I'll need a script that I can put into crontab (to run every minute) to do the following :
select count(*) from v$process;
if the above hits 80% of the current set max limit, email to notify me
select count(*) from v$session;
if the above hits 80% of the current set max limit, email to notify me

I can't figure out how to embed  the above sql commands in a Shell
script.  I'm running on HP-UX B11.13 on PA-RISC

Answer : Shell / sql script to check Oracle current number of processes used : ORA-00020 00018 exceeded

You can use this script to get the processes grouped by username...

select qcsid SID, username, totl_par_procs_in_use, reqstd_degree, obtaind_degree, par_proc_cnt_for_sessn,
       currtime, sqltext
from (
select qcsid, username, totl_par_procs_in_use, reqstd_degree, obtaind_degree, par_proc_cnt_for_sessn,
       currtime, num_active,qnum_active, sqltext
from (
select s.qcsid,ses.username,sys.value totl_par_procs_in_use,s.req_degree reqstd_degree,s.degree Obtaind_degree,
       count(*) par_proc_cnt_for_sessn,sum(decode(ses.status,'ACTIVE',1,0)) num_active,
sum(decode(qses.status,'ACTIVE',1,0)) qnum_active,
       to_char(sysdate,'HH24:MI:SS') currtime,coalesce(sql.sql_text,sqlt.sql_text,ses.action) sqltext
from v$px_session s
  inner join v$px_process_sysstat sys
      on s.qcsid <> s.sid
      and sys.statistic like 'Servers In Use%'
  inner join v$session ses
      on s.sid=ses.sid
      and s.serial#=ses.serial#
  inner join v$px_process p
      on p.sid = ses.sid
      and p.serial# = ses.serial#
  left outer join v$sql sql
      on ses.sql_address = sql.address
      and ses.sql_hash_value = sql.hash_value
      and sql.child_number=0
  left outer join v$session qses
      on s.qcsid=qses.sid
      and s.qcserial#=qses.serial#
  left outer join v$sqltext sqlt
      on qses.sql_address = sqlt.address
      and qses.sql_hash_value = sqlt.hash_value
      and sqlt.piece=0
group by s.qcsid,s.degree,s.req_degree,coalesce(sql.sql_text,sqlt.sql_text,ses.action),sys.value,
ses.username
) AA
union all
select a.SID,a.username,null,null,null,0,to_char(sysdate,'HH24:MI:SS'),null,null,
  coalesce(b.sql_text, a.action, a.module) SQL_TEXT
from v$session a,v$sql b
where a.status='ACTIVE' and a.sql_address=b.address and a.sql_hash_value=b.hash_value
and a.sid not in (select sid from v$px_session)
--and b.piece=0
) BB order by qcsid

Random Solutions  
 
programming4us programming4us