---
title: "Oracle发现所有用户锁 和锁等待或死锁"
author: "wxpwdm8461"
date: "2009-07-20T22:29:27Z"
tags: ["Oracle"]
slug: "oracle"
draft: false
lastmod: "2009-07-20T22:29:27Z"
id: 429673
url: "https://wxpwdm8461.iteye.com/blog/429673"
---

如果仅仅是lock，以下语句可以发现所有用户锁    
  select   s.username,    
  decode(l.type,'TM','TABLE   LOCK',    
                              'TX','ROW   LOCK',    
                              NULL)   LOCK\_LEVEL,    
  o.owner,o.object\_name,o.object\_type,s.terminal,s.machine,s.program,s.osuser    
  from   v$session   s,v$lock   l,dba\_objects   o    
  where   s.sid=l.sid    
  and   o.object\_id=l.id1    
  and   s.username   is   not   null    
     
  如果有锁等待或死锁，可以通过以下语句发现    
  select   lpad('   ',decode(l.xidusn,0,3,0))||l.oracle\_username   User\_name,    
                o.owner,o.object\_name,o.object\_type    
  from   v$locked\_object   l,dba\_objects   o    
  where   l.object\_id=o.object\_id    
  order   by   o.object\_id   desc