Find locked objects

If a table used by an user A is locked by User B then A needs to wait until B unlocks it. By issuing this query, User A can find which tables in his schema are locked and which session has locked it. It has been tested on versions 8 and up.

SQL>select a.sid,a.serial#,c.object_name 
 from V$session a, 
 V$locked_object b, 
 user_objects c 
 where a.sid=b.session_id 
 and b.object_id=c.object_id; 
 

Output:

 SID SERIAL# OBJECT_NAME 
 ---- ------- ------------ 
 7 36 emp 
 9 58 dept 
 
 2 rows selected. 

Now you can release the lock:

 
 SQL>alter system kill session '7,36'; 
 
 System Altered. 
 
 SQL>alter system kill session '9,58'; 
 
 System Altered. 
 
Note: Make sure you know what the sessions are doing before killing them!

For More Information

    Requires Free Membership to View

  • Feedback:
    E-mail the editor with your thoughts about this tip.
  • More tips: Hundreds of free Oracle tips and scripts.
  • Tip contest: Have an Oracle tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize -- submit your tip today!
  • Ask the Experts: Our applications, SQL, database administration, and data warehousing gurus are waiting to answer your toughest questions.
  • Forums: Ask your technical Oracle questions--or help out your peers by answering them--in our active forums.
  • Best Web Links: Oracle tips, tutorials, and scripts from around the Web.

This was first published in February 2004

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.