Locking and blocking information and solution

1. To see the details about the specified sid
 
set linesize 200 select blocking_session, sid, serial#, wait_class, seconds_in_wait from gv$session where blocking_session is not null order by blocking_session ; blocking_sessionsid serial# wait_classseconds_in_wait ---------------- ---------- ---------- -------------------- -------- 148 135 61521 idle 64

Note: We found that session 148 is blocking session 135 and has been for 64 seconds.

2. Run the script provided by oracle.
 
@?/rdbms/admin/utllockt.sql

3. Simple query to find the blocking session information.

 
select object_id,session_id,process,locked_mode from gv$locked_object where session_id in (&session_id);

  a. This will give easy readable output for locking objects.

  
set lines 100
set pages 500
col "lock particulars" format a100
select
(select username from gv$session where sid=a.sid) || '('||a.sid||')'||
' is blocking to '||
(select username from gv$session where sid=b.sid) || '('||b.sid||')' "lock particulars"
from gv$lock a, gv$lock b where a.block = 1 and b.request> 0 and a.id1 = b.id1 and a.id2 = b.id2
;
lock particulars
----------------------------------------------------------------------------------------------------
qsitbba(9) is blocking to vitvcd(7)
qsitbba(72) is blocking to vitvcd(7)
qsitbba(9) is blocking to qtnsdp(72)
4. Use below to find kill details.

Note: need to provide the sid from above query.

setlinesize 200 col username format a15 colschemaname format a15 col program format a15 select sid,serial#,username,status,schemaname,program,to_char(logon_time,'dd/mm/yyyy hh24:ss:mm') logon_time from v$session where sid in(&sid); 

5. >kill -3/9 can be run on spid provided by below query.

set linesize 100 
column spid format a10
column username format a10
column program format a45
selects.inst_id,
s.sid,
s.serial#,
p.spid,
s.username,
s.program
from gv$session s
join gv$process p on p.addr = s.paddr and p.inst_id = s.inst_id
where s.sid=1950 ;
6. >To see queries running from more than 5 sec.

Note: new feature of 11g.

 
set linesize 200
select s.sid, serial#, s.sql_id, (sysdate-sql_exec_start)*24*60*60 secs, sql_text from v$session s, v$sqltext t
wheres.sql_id = t.sql_id
and sql_exec_start is not null and piece = 0
and (sysdate-sql_exec_start)*24*60*60 > 5 ;

7. To find the details of locking objects.

 
set lines 180
set pages 500
col owner format a15
col object_name format a20
col object_type format a20
col sid a8
col serial# format a50
col status format a 10
col osuser format a10
col machine format a60



select c.owner, c.object_name, c.object_type, b.sid, b.serial#, b.status, b.osuser, b.machine from v$locked_object a , v$session b, dba_objects c where b.sid = a.session_id and a.object_id = c.object_id ;

8. To find the sql being run by blocking sid

 
select s.sid, s.serial#, t.sql_fulltext,t.sql_id,s.sql_hash_value,t.hash_value from v$session s, v$sql t where s.sql_address = t.address and s.sql_hash_value = t.hash_value and s.sid=1950 ;

9. To find out the query information against the process which you take from unix.

 
select sql_text, optimizer_mode, module, action from v$sqlarea where hash_value in ( select sql_hash_value from v$session wherepaddr=( select addr from v$process where spid=&process_id ) );

10. To see the queries running from more than 5 sec

 
set linesize 200 select s.sid, serial#, s.sql_id, (sysdate-sql_exec_start)*24*60*60 secs, sql_text from v$session s, v$sqltext t where s.sql_id = t.sql_id and sql_exec_start is not null and piece = 0 and (sysdate-sql_exec_start)*24*60*60 > 5 ; sid serial# sql_idsecssql_text ---------- ---------- ------------- ---------- ---------------------------------------------------------------- 492 46694 a0f74y2n959cbt 12 select /*+ first_rows(1) use_nl (p t) */ path_name,path_doci

Weblogic: Scripts to start/stop Weblogic

1. Node Manager:
Start

 
$WLS_HOME/server/bin/startNodeManager.sh

Stop
Note: There is no specific command to stop node manager, you have to kill the process manually to stop the node manager.

 
kill -9 `ps -ef | grep -i nodemanager.javahome | grep -v grep | awk {'print $2'} | head -1`

2. Weblogic:
Start

 $DOMAIN_HOME/bin/startWebLogic.sh 

Stop

 
$DOMAIN_HOME/bin/stopWebLogic.sh

3. Managed Server:
Start

 
$DOMAIN_HOME/bin/startManagedWebLogic.sh

Stop

 
$DOMAIN_HOME/bin/stopManagedWebLogic.sh

Workflow Mailer Script to start notification mailer

 
sqlplus apps/apps_pwd
 
declare
p_retcode number;
p_errbuf varchar2(100);
m_mailerid fnd_svc_components.component_id%TYPE;
begin
-- Find mailer Id
-----------------
select component_id
into m_mailerid
from fnd_svc_components
where component_name = 'Workflow Notification Mailer';
--------------
-- Start Mailer
--------------
fnd_svc_component.start_component(m_mailerid, p_retcode, p_errbuf);
commit;
end;
/

Workflow Mailer Script to stop notification mailer

 
sqlplus apps/apps_wpd
 
declare
p_retcode number;
p_errbuf varchar2(100);
m_mailerid fnd_svc_components.component_id%TYPE;
begin
-- Find mailer Id
-----------------
select component_id
into m_mailerid
from fnd_svc_components
where component_name = 'Workflow Notification Mailer';
--------------
-- Stop Mailer
--------------
fnd_svc_component.stop_component(m_mailerid, p_retcode, p_errbuf);
commit;
end;
/

HA: Scripts to check if archive logs are being shipped and applied to standby

1. Steps to check archive logs are being shipped and applied to standby.

AT PRIMARY:

A.  Check the status.

Note: Status should return valid for standby destination

 
set lines 500
column destination format a35 wrap
column process format a7
column archiver format a8
column ID format 99
select dest_id "ID",destination,status,target,archiver,schedule,process,mountid from v$archive_dest ;

Sample Output:

B. Check if any error is reported for archive dest.

 Note: Should not return any error messages

 
column error format a55 tru
select dest_id,status,error from v$archive_dest;

Sample Output:

C. Check the errors from dataguard status.
Note: Should not return any row.

 
column message format a80
select message, timestamp from v$dataguard_status where severity in ('Error','Fatal') order by timestamp;

AT STANBDY:

A. Check MRP status and which block is being applied at standby database.

 
set linesize 230
select process,status,client_process,sequence#,block#,active_agents,known_agents from v$managed_standby ;

Sample Output:

B. Check the error for dataguard status
Note: Should not return any rows.

 
column message format a80
select message, timestamp from v$dataguard_status where severity in ('Error','Fatal') order by timestamp;

RAC: List info of all long operations in whole RAC

 
SET LINESIZE 230
COLUMN sid FORMAT 9999
COLUMN serial# FORMAT 9999999
COLUMN machine FORMAT A25
COLUMN progress_pct FORMAT 99999999.00
COLUMN elapsed FORMAT A20
COLUMN remaining FORMAT A20
SELECT s.inst_id,
s.sid,
s.serial#,
s.username,
s.module,
ROUND(sl.elapsed_seconds/60) || ':' || MOD(sl.elapsed_seconds,60) elapsed,
ROUND(sl.time_remaining/60) || ':' || MOD(sl.time_remaining,60) remaining,
ROUND(sl.sofar/sl.totalwork*100, 2) progress_pct
FROM gv$session s,
gv$session_longops sl
WHERE s.sid = sl.sid
AND s.inst_id = sl.inst_id
AND s.serial# = sl.serial#;

RAC: List all current sessions in whole RAC

 
SET LINESIZE 230
SET PAGESIZE 2300
COLUMN username FORMAT A25
COLUMN machine FORMAT A25
COLUMN logon_time FORMAT A25
SELECT NVL(s.username, '(oracle)') AS username,
s.inst_id,
s.osuser,
s.sid,
s.serial#,
p.spid,
s.lockwait,
s.status,
s.module,
s.machine,
s.program,
TO_CHAR(s.logon_Time,'DD-MON-YYYY HH24:MI:SS') AS logon_time
FROM gv$session s,
gv$process p
WHERE s.paddr = p.addr
AND s.inst_id = p.inst_id
ORDER BY s.username, s.osuser ;

Sample Output:

RAC: Displays memory allocations for all current sessions in whole RAC

 
SET LINESIZE 230
COLUMN username FORMAT A30
COLUMN module FORMAT A25
SELECT a.inst_id,
NVL(a.username,'(oracle)') AS username,
a.module,
a.program,
Trunc(b.value/1024) AS memory_kb
FROM gv$session a,
gv$sesstat b,
gv$statname c
WHERE a.sid = b.sid
AND a.inst_id = b.inst_id
AND b.statistic# = c.statistic#
AND b.inst_id = c.inst_id
AND c.name = 'session pga memory'
AND a.program IS NOT NULL
ORDER BY b.value DESC ;