Locks Script in ORACLE

LOCKS:

Locks are mechanisms that prevent destructive interaction between transactions accessing the same resource.
Oracle has several views for showing lock status, some of which show the username:
  • DBA_BLOCKERS – Shows non-waiting sessions holding locks being waited-on
  • DBA_DDL_LOCKS – Shows all DDL locks held or being requested
  • DBA_DML_LOCKS  - Shows all DML locks held or being requested
  • DBA_LOCK_INTERNAL – Displays 1 row for every lock or latch held or being requested with the username of who is holding the lock 
  • DBA_LOCKS  - Shows all locks or latches held or being requested
  • DBA_WAITERS  - Shows all sessions waiting on, but not holding waited for locks
The following script is commonly used by Oracle professionals who need to quickly find out all database objects that are locked within their system.
Most Oracle professionals use of the v$locked_object view in order to gather information about objects that are locked within the Oracle database.  The v$locked_object view can also be joined into the v$session view in order to gather session level information (SID, PID, status, machine) , and also joined into the dba_objects view in order to get the owner, the object name, and the type of objects that is currently being locked within the database.
The following script can be used in order quickly identify all lock objects within your Oracle system.

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;


DEADLOCK:

Oracle automatically detects deadlock situations and resolves them by rolling back one of the statements involved in the deadlock.  This releases one set of the conflicting row locks. A corresponding message also is returned to the transaction that undergoes the rollback.

Below the script is useful for identify  – “ Who is blocking to whom ”

select s1.username || '@' || s1.machine
 || ' ( SID=' || s1.sid || ' )  is blocking '
 || s2.username || '@' || s2.machine || ' ( SID=' || s2.sid || ' ) ' AS blocking_status
  from v$lock l1, v$session s1, v$lock l2, v$session s2
where s1.sid=l1.sid and s2.sid=l2.sid
   and l1.BLOCK=1 and l2.request > 0
 and l1.id1 = l2.id1
  and l2.id2 = l2.id2 ;

below script is useful  for  “who’s Holder and Who’s Waiter” to query.

SELECT  /*+ FIRST_ROWS ORDERED */ DECODE(request,0,'Holder: ','Waiter: ')||sid sess,
         id1, id2, lmode, request, type
    FROM V$LOCK
   WHERE (id1, id2, type) IN
             (SELECT id1, id2, type FROM V$LOCK WHERE request>0)
   ORDER BY id1, request;


Below the scriprt is Useful for identify Database level locks.

select    nvl(S.USERNAME,'Internal') username,
                nvl(S.TERMINAL,'None') terminal,
                L.SID||','||S.SERIAL# Kill, b.spid,
                U1.NAME||'.'||substr(T1.NAME,1,20) tab,
                decode(L.LMODE,1,'No Lock',
                                2,'Row Share',
                                3,'Row Exclusive',
                                4,'Share',
                                5,'Share Row Exclusive',
                                6,'Exclusive',null) lmode,
                decode(L.REQUEST,1,'No Lock',
                                2,'Row Share',
                                3,'Row Exclusive',
                                4,'Share',
                                5,'Share Row Exclusive',
                                6,'Exclusive',null) request
from      V$LOCK L, 
                V$SESSION S,
                SYS.USER$ U1,
                SYS.OBJ$ T1 ,
                v$process b
where   L.SID = S.SID 
and        T1.OBJ# = decode(L.ID2,0,L.ID1,L.ID2) 
and        U1.USER# = T1.OWNER#
and        S.TYPE != 'BACKGROUND'
and        s.paddr = b.addr    order by 1,2,5 ;

39 Response to "Locks Script in ORACLE"

  1. Unknown says:

    Hi There,


    Your writing shines! There is no room for gibberish here clearly you have explained about Tutorials. Keep writing!

    Though the basic Unix-like systems unit of a Unix and include at least some BSD code, and some systems also include GNU utilities in their distributions. I've came across forums it says you can create your own mini OS using C/C++ compiler.
    Is that entirely true? How much time it takes to replicate an OS like Chrome OS

    But nice Article Mate! Great Information! Keep up the good work!


    MuchasGracias,
    Abhiram

    gowsalya says:

    Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.
    full stack developer training in pune


    full stack developer training in annanagar

    full stack developer training in tambaram

    Mounika says:

    After reading your post I understood that last week was with full of surprises and happiness for you. Congratz! Even though the website is work related, you can update small events in your life and share your happiness with us too.
    AWS Training in chennai

    AWS Training in bangalore

    nivatha says:

    This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.

    Data Science Training in Chennai
    Data science training in bangalore
    Data science online training
    Data science training in pune

    Unknown says:

    I am definitely enjoying your website. You definitely have some great insight and great stories. 
    java online training | java training in pune

    java training in chennai | java training in bangalore

    Unknown says:

    Really great post, Thank you for sharing This knowledge.Excellently written article, if only all bloggers offered the same level of content as you, the internet would be a much better place. Please keep it up!

    angularjs Training in chennai
    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    sai says:

    This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    python interview questions and answers | python tutorialspython training institute in electronic city

    Suba says:

    I feel happy to find your post, excellent way of writing and also I would like to share with my colleagues so that they also get the opportunity to read such an informative blog.
    Selenium Training in Chennai
    selenium testing training in chennai
    iOS Training in Chennai
    Digital Marketing Training in Chennai
    Salesforce Developer 501 Training in Chennai
    Salesforce Developer 502 Training in Chennai

    jefrin says:

    Good to read thanks for sharing
    blue prism training institute in chennai

    priya says:

    Really great post, I simply unearthed your site and needed to say that I have truly appreciated perusing your blog entries. I want to say thanks for great sharing.

    Microsoft Azure online training
    Selenium online training
    Java online training
    Java Script online training
    Share Point online training

    Tuhin says:

    keep up the good work. this is an Assam post. this to helpful, i have reading here all post. i am impressed. thank you. this is our digital marketing training center. This is an online certificate course
    digital marketing training in bangalore / https://www.excelr.com/digital-marketing-training-in-bangalore

    subha says:

    Informative post indeed, I’ve being in and out reading posts regularly and I see alot of engaging people sharing things and majority of the shared information is very valuable and so, here’s my fine read.thanks
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

    Revathi says:

    I have completely read your post and the content is crisp and clear. Thank you for posting such an informative article, I have decided to follow your blog so that I can myself updated.Tanks lot!!

    android training in chennai

    android online training in chennai

    android training in bangalore

    android training in hyderabad

    android Training in coimbatore

    android training

    android online training



    devi says:


    Excellent blog with lots of information, keep sharing. I am waiting for your more posts like this or related to any other informative topic. Amazing web journal I visit this blog it's extremely marvellous. Interestingly, in this blog content composed plainly and reasonable. The substance of data is educational
    Data Science Training In Chennai

    Data Science Online Training In Chennai

    Data Science Training In Bangalore

    Data Science Training In Hyderabad

    Data Science Training In Coimbatore

    Data Science Training

    Data Science Online Training

    Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome. I will instantly grab your rss feed to stay informed of any updates you make and as well take the advantage to share some latest information about

    CREDIT CARD HACK SOFTWARE which many are not yet informed of, the recent technology.

    Thank so much for the great job.

    jenani says:

    Amazing Article ! I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Java Training in Chennai

    Java Training in Velachery

    Java Training in Tambaram

    Java Training in Porur

    Java Training in Omr

    Java Training in Annanagar

    subathara says:
    This comment has been removed by the author.
    kalish says:
    This comment has been removed by the author.
    subathara says:
    This comment has been removed by the author.
    kalish says:

    Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.

    Python Training in Chennai

    Python Training in Velachery

    Python Training in Tambaram

    Python Training in Porur

    Python Training in Omr

    Python Training in Annanagar

    hi thanku so much this information

    cs executive
    freecseetvideolectures/

    Automated Forex Trading With ETORO REVIEW Metatrader 4 - Download .

    Read More About The Latest XM REVIEW Review In This Article. Learn How The Broker Operates And If You Should Avoid Trading With It Or Not.

    Excellent effort to make this blog more wonderful and attractive.
    data scientist training in hyderabad

    Success Write content success. Thanks.
    kıbrıs bahis siteleri
    betturkey
    canlı poker siteleri
    betpark
    kralbet
    deneme bonusu
    betmatik

    sportsbet says:

    Good content. You write beautiful things.
    mrbahis
    korsan taksi
    vbet
    hacklink
    hacklink
    sportsbet
    taksi
    vbet
    mrbahis

    Very Informative blog
    Jewellery Software
    Jewellery Software

    delfin says:

    ağrı
    muş
    mersin
    afyon
    uşak

    J71

    Osman says:

    salt likit
    salt likit
    dr mood likit
    big boss likit
    dl likit
    dark likit
    3D22

Post a Comment

Powered by Blogger