如何查看某张表被锁住了
时间: 2023-12-21 17:03:31 浏览: 63
在Oracle数据库中,可以使用以下的方法来查看某张表是否被锁住了:
1. 使用V$LOCKED_OBJECT视图查询被锁住的对象:
```sql
SELECT OBJECT_NAME, OBJECT_TYPE, SESSION_ID, ORACLE_USERNAME, OS_USER_NAME
FROM V$LOCKED_OBJECT
WHERE OBJECT_ID = (SELECT OBJECT_ID FROM DBA_OBJECTS WHERE OBJECT_NAME = 'table_name');
```
其中,`OBJECT_NAME`为被锁住的表名,`OBJECT_TYPE`为被锁住的对象类型,`SESSION_ID`为持有锁定的会话ID,`ORACLE_USERNAME`为持有锁定的用户,`OS_USER_NAME`为持有锁定的操作系统用户。
2. 使用DBA_BLOCKERS和DBA_WAITERS视图查询阻塞和等待锁的会话信息:
```sql
SELECT *
FROM DBA_BLOCKERS
WHERE SESSION_ID IN (SELECT SESSION_ID FROM V$LOCKED_OBJECT WHERE OBJECT_ID = (SELECT OBJECT_ID FROM DBA_OBJECTS WHERE OBJECT_NAME = 'table_name'));
SELECT *
FROM DBA_WAITERS
WHERE SESSION_ID IN (SELECT SESSION_ID FROM V$LOCKED_OBJECT WHERE OBJECT_ID = (SELECT OBJECT_ID FROM DBA_OBJECTS WHERE OBJECT_NAME = 'table_name'));
```
其中,`DBA_BLOCKERS`视图显示当前阻塞其他会话的会话信息,`DBA_WAITERS`视图显示正在等待锁的会话信息。
通过以上方法,可以查看到某张表是否被锁住了,以及持有锁定和等待锁定的会话信息。
阅读全文