Total Pageviews

Thursday, 25 June 2015

Create a view to check Locked objects.

------------DROP VIEW APPS.XXALL_LOCKED_OBJECTS;
/* Formatted on 6/25/2015 11:10:04 AM (QP5 v5.256.13226.35510) */
CREATE OR REPLACE FORCE VIEW APPS.XXALL_LOCKED_OBJECTS
(
   OWNER,
   OBJECT_NAME,
   OBJECT_TYPE,
   SID,
   SERIAL#,
   STATUS,
   OSUSER,
   MACHINE
)
   BEQUEATH DEFINER
AS
   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
    --TO ALTER AND KILL THE LOCKED OBJECTS
    ----  ALTER SYSTEM KILL SESSION 'SID,serial#' IMMEDIATE;
    ----  ALTER SYSTEM KILL SESSION '408,19512' IMMEDIATE;
    WHERE b.SID = a.session_id AND a.object_id = c.object_id;


===============================================================
How to find the locked objects and Kill the Session in Oracle
===========================================
Step-1 Run the following SQL query to find out the list of objects that has been locked

SELECT aob.object_name
,aob.object_id
,b.process
,b.session_id
FROM all_objects aob, v$locked_object b
WHERE aob.object_id = b.object_id

OR

SELECT aob.object_name
,aob.object_id
,b.process
,b.session_id
FROM all_objects aob, v$locked_object b
,V$session a
WHERE aob.object_id = b.object_id
and a.sid=b.session_id ;


Step-2 Now run the following SQL query with session id (from step-1)

SELECT SID, SERIAL#  FROM v$session WHERE SID = <SESSION_ID>
Note <SID> <SERIAL#>


Step-3 Run the following Query to kill the session with session_id and Serial no (from step-2)

ALTER SYSTEM KILL SESSION '<SID> ,<SERIAL#>';

Ref:--
http://appsdbaclass.blogspot.com/2011/05/how-to-find-locked-objects-and-kill_5619.html


Another eg:
=========
CREATE VIEW scott.empview
(
   ename,
   enumber
)
   BEQUEATH DEFINER
AS
   SELECT ename,enumber FROM scott.emp;

 now give grant to another user
======================
GRANT SELECT ON scott.empVIEW TO tom;

as tom user(fyi)
========
CREATE OR REPLACE SYNONYM tom.empVIEW  FOR scott.empview;

Query to check all application sessions along with their sid & pid:
================================================================
select /*+ ORDERED */
p.spid db_pid
, s.process mt_pid
, s.username||':'||SUBSTR(s.sid||','||s.serial#,1,15 ) sid_serial
, fl.start_time apps_logon_time
, fu.user_name apps_user
, s.machine||'.'||s.osuser mt_detail
--, logon_time mt_start_time
, substr(module,1,10) module, action
from fnd_logins fl
, fnd_user fu
, v$process p
, v$session s
where  decode('&&1','web',fl.spid,1)=decode('&&1','web',s .process,1)
and fl.pid=p.pid
and fl.process_spid=p.spid
and fl.serial#=p.serial#
and s.process is not null
and s.paddr = p.addr
and fl.user_id=fu.user_id
and fl.end_time is null


query to check locked objects
=====================
 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;


 ALTER SYSTEM KILL SESSION '428,4729'


No comments :

Post a Comment