Skip to main content

Show which user sessions have locks against which tables and other objects and the users who are waiting for those locks

set serveroutput on size 10000
declare
cursor c1 is
select * from v$lock where request != 0
order by id1, id2;
wid1 number := -999999;
wid2 number := -999999;
wholder_detail varchar2(120);
v_err_msg varchar2(80);
wsid number(5);
wstep number(2);
wtype varchar2(10);
wobject_name varchar2(180);
wobject_name1 varchar2(80);
wlock_type varchar2(50);
begin
for c1_rec in c1 loop
if c1_rec.id1 = wid1 and c1_rec.id2 = wid2 then
null;
else
wstep := 10;
select sid , type into wsid , wtype
from v$lock
where id1 = c1_rec.id1
and id2 = c1_rec.id2
and request = 0
and lmode != 4;
dbms_output.put_line(' ');
wstep := 20;
select 'Holder DBU: '||s.username ||' OSU: '||s.osuser ||' DBP:'||p.spid||' APP: '|| s.process
||' SID: '|| s.sid||' Status: ' || s.status ||' ty:'||wtype
into wholder_detail
from v$session s, v$process p
where s.sid= wsid
and s.paddr = p.addr;
dbms_output.put_line(wholder_detail||' ID1='||to_char(c1_rec.id1)
||', ID2='|| to_char(c1_rec.id2));
begin
select decode(wtype,'TX', 'Transaction',
'DL', 'DDL Lock',
'MR', 'Media Recovery',
'RT', 'Redo Thread',
'UN', 'User Name',
'TX', 'Transaction',
'TM', 'DML',
'UL', 'PL/SQL User Lock',
'DX', 'Distributed Xaction',
'CF', 'Control File',
'IS', 'Instance State',
'FS', 'File Set',
'IR', 'Instance Recovery',
'ST', 'Disk Space Transaction',
'TS', 'Temp Segment',
'IV', 'Library Cache Invalida-tion',
'LS', 'Log Start or Switch',
'RW', 'Row Wait',
'SQ', 'Sequence Number',
'TE', 'Extend Table',
'TT', 'Temp Table',
'Un-Known Type of Lock')
into wlock_type
from dual;
declare
cursor c3 is
select object_id from v$locked_object
where session_id = wsid;
begin
wobject_name := '';
for c3_rec in c3 loop
select object_type||': '||owner||'.'||object_name
into wobject_name
from dba_objects
where object_id = c3_rec.object_id;
wobject_name := wobject_name ||' '||wobject_name1;
end loop;
exception
when others then
wobject_name := wobject_name ||' No Object Found';
end;
dbms_output.put_line('Lock Held: '||wlock_type||' for Object :'||wobject_name);
exception
when no_data_found then
dbms_output.put_line('Lock Held: '||wlock_type||' No object found in DBA Objects');
end;
end if;
wstep := 30;
select '.... Requestor DBU: '||s.username ||' OSU: '||s.osuser ||' DBP:'||p.spid||' APP: '|| s.process
||' SID: '|| s.sid||' Status: ' || s.status
into wholder_detail
from v$session s, v$process p
where s.sid= c1_rec.sid
and s.paddr = p.addr;
dbms_output.put_line(wholder_detail);
wid1 := c1_rec.id1;
wid2 := c1_rec.id2;
end loop;
if wid1 = -999999 then
wstep := 40;
dbms_output.put_line('No one requesting locks held by others');
end if;
exception
when others then
v_err_msg := (sqlerrm ||' '|| sqlcode||' step='||to_char(wstep));
DBMS_OUTPUT.PUT_LINE(v_err_msg);
end;
/

Comments

Popular posts from this blog

ORA-20200 Error while running AWR report from PDB level

Issue: In 19c database, while generating AWR report from PDB level, got the below error.  In 12cR1 - We can only generate statistics and run the Workload Repository (AWR) report from CDB level.  Since 12.2, if we want to generate statistics and run AWR report from PDB level, we have to change  awr_pdb_autoflush_enabled parameter to TRUE. Error: ERROR at line 1: ORA-20200: Database/Instance 2832289441/1 does not exist in AWR_PDB_DATABASE_INSTANCE ORA-06512: at line 27 Solution: alter session set container=ORCL; >>>>   Set the container Name alter system set awr_pdb_autoflush_enabled=true; conn system/<pwd>@orclcdb     >>>> Login into PDB database alter system set AWR_SNAPSHOT_TIME_OFFSET=1000000 scope=both;   >>> Set the arameter to avoid performance issue while generating snapshot at the same time in CDB and PDB level. exec dbms_workload_repository.create_snapshot(); SQL> @?/rdbms/admin/awrrpt.sql Console Log: SQL> show pdbs       CON_ID CON

EBS 12.2 - Script to monitor JVM Heap Memory for the weblogic managed servers

#!/bin/sh # Script to monitor JVM Heap Memory for the managed servers # Author : Ramasubbu Sunadaravel # Date   : 23-Aug-2016 # Usage  : sh jvm_heap_mem_mon.sh run  ## VARIABLES save_date=`date +%d_%b_%y` LOGFILE=/export/home/applmgr/oraprocs/logs HISTFILE=/export/home/applmgr/oraprocs/histfile threshold=10 MAIL_LIST=rsundaravel@yahoo.com SCRIPT=/export/home/applmgr/oraprocs/.jvm_check.py ## SCRIPTS STARTS HERE . /r11/app/FLRPRD/R12apps/EBSapps.env . $FMW_HOME/wlserver_10.3/server/bin/setWLSEnv.sh java weblogic.WLST $SCRIPT > $LOGFILE/jvm_heap_monitoring.log date '+Start Time: %m/%d/%y %H:%M:%S' >> $HISTFILE/jvm_heap_monitoring_$save_date.log cat $LOGFILE/jvm_heap_monitoring.log|grep "%" >> $HISTFILE/jvm_heap_monitoring_$save_date.log date '+End Time: %m/%d/%y %H:%M:%S' >> $HISTFILE/jvm_heap_monitoring_$save_date.log #Alert DBA's if any of the managed server heap size reached more than $threshold value current=`

EBS 12.2 - Script to monitor Weblogic Managed servers

#!/bin/sh # Script to monitor Weblogic managed server status # Author : Ramasubbu Sunadaravel # Date   : 23-Aug-2016 . /r11/app/FLRPRD/R12apps/EBSapps.env ## VARIABLES ### LOGFILE=/export/home/applmgr/oraprocs/logs MAIL_LIST=rsundaravel@yahoo.com ADMIN_URL=http://test.domain.int:7014/console PARFILE=/export/home/applmgr/oraprocs/mgd_server_list.par ## - place all the managed servers name. WEBLOGIC_PWD = /export/home/applmgr/oraprocs/.weblogicpwd ## SCRIPT STARTS cat $PARFILE |while read line do managed_server=`echo $line | awk '{print $1}'` LOGFILE=/export/home/applmgr/oraprocs/logs echo $managed_server echo `cat $WEBLOGIC_PWD`|$ADMIN_SCRIPTS_HOME/admanagedsrvctl.sh status $managed_server|grep $managed_server|grep -v logs > $LOGFILE/$managed_server.log status=`cat $LOGFILE/$managed_server.log|grep "is running"|wc -l` if test $status -eq 1 then echo "$managed_server is Running" else echo "$managed