Home Database Mysql Tutorial oracle查询锁表与解锁情况提供解决方案

oracle查询锁表与解锁情况提供解决方案

Jun 07, 2016 pm 05:55 PM
Unlock

如果发生了锁等待,我们可能更想知道是谁锁了表而引起谁的等待,本文将详细问您介绍此等问题的解决方法,有这方面需求的朋友可适当参考

如果发生了锁等待,我们可能更想知道是谁锁了表而引起谁的等待
以下的语句可以查询到谁锁了表:
代码如下:
SELECT /*+ rule */ s.username,
decode(l.type,'TM','TABLE LOCK',
'TX','ROW LOCK',
NULL) LOCK_LEVEL,
o.owner,o.object_name,o.object_type,
s.sid,s.serial#,s.terminal,s.machine,s.program,s.osuser
FROM v$session s,v$lock l,dba_objects o
WHERE l.sid = s.sid
AND l.id1 = o.object_id(+)
AND s.username is NOT NULL

以下的语句可以查询到谁在等待:
代码如下:
SELECT /*+ rule */ lpad(' ',decode(l.xidusn ,0,3,0))||l.oracle_username User_name, o.owner,o.object_name,o.object_type,s.sid,s.serial#
FROM v$locked_object l,dba_objects o,v$session s
WHERE l.object_id=o.object_id
AND l.session_id=s.sid
ORDER BY o.object_id,xidusn DESC

解锁命令:
代码如下:
alter system kill session 'sid,serial#'

1).
代码如下:
select LOCK_INFO.OWNER || '.' || LOCK_INFO.OBJ_NAME as "已鎖物件名稱", --物件名稱(已經被鎖住)
LOCK_INFO.SUBOBJ_NAME as "已鎖子物件名稱", -- 子物件名稱(已經被鎖住)
SESS_INFO.MACHINE as "機器名稱", -- 機器名稱
LOCK_INFO.SESSION_ID as "會話ID", -- 會話SESSION_ID
SESS_INFO.SERIAL# as "會話SERIAL#", -- 會話SERIAL#
SESS_INFO.SPID as "OS系統的SPID", -- OS系統的SPID
(SELECT INSTANCE_NAME FROM V$INSTANCE) "實例名SID", --實例名SID
LOCK_INFO.ORA_USERNAME as "ORACLE用戶", -- ORACLE系統用戶名稱
LOCK_INFO.OS_USERNAME as "OS用戶", -- 作業系統用戶名稱
LOCK_INFO.PROCESS as "進程編號", -- 進程編號
LOCK_INFO.OBJ_ID as "對象ID", -- 對象ID
LOCK_INFO.OBJ_TYPE as "對象類型", -- 對象類型
SESS_INFO.LOGON_TIME as "登錄時間", -- 登錄時間
SESS_INFO.PROGRAM as "程式名稱", -- 程式名稱
SESS_INFO.STATUS as "會話狀態", -- 會話狀態
SESS_INFO.LOCKWAIT as "等待鎖", -- 等待鎖
SESS_INFO.ACTION as "動作", -- 動作
SESS_INFO.CLIENT_INFO as "客戶資訊" -- 客戶資訊
from (select obj.OWNER as OWNER,
obj.OBJECT_NAME as OBJ_NAME,
obj.SUBOBJECT_NAME as SUBOBJ_NAME,
obj.OBJECT_ID as OBJ_ID,
obj.OBJECT_TYPE as OBJ_TYPE,
lock_obj.SESSION_ID as SESSION_ID,
lock_obj.ORACLE_USERNAME as ORA_USERNAME,
lock_obj.OS_USER_NAME as OS_USERNAME,
lock_obj.PROCESS as PROCESS
from (select *
from all_objects
where object_id in (select object_id from v$locked_object)) obj,
v$locked_object lock_obj
where obj.object_id = lock_obj.object_id) LOCK_INFO,
(select SID,
SERIAL#,
LOCKWAIT,
STATUS,
(select spid from v$process where addr = a.paddr) spid,
PROGRAM,
ACTION,
CLIENT_INFO,
LOGON_TIME,
MACHINE
from v$session a) SESS_INFO
where LOCK_INFO.SESSION_ID = SESS_INFO.SID
order by LOCK_INFO.SESSION_ID;

2).
代码如下:
select sql_text
from v$sqltext
where address in (select sql_address from v$session where sid = &sid)
order by piece;

3).
代码如下:
ALTER SYSTEM KILL SESSION '會話ID,會話SERIAL#';

4).
kill -9 OS系統的SPID

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to lock and unlock the Function (Fn) key in Windows 11 How to lock and unlock the Function (Fn) key in Windows 11 May 01, 2023 pm 05:22 PM

The top row of the keyboard is populated with function (F1, F2, F3, etc.) keys, which often do double duty as both multimedia keys and designated keys. However, some users have been wondering how Windows 11 Function (Fn) Key Lock works. Function keys, or F-keys, are a great way to perform some quick actions, and with each key playing multiple roles, it makes things even easier. However, this does confuse a group of users who prefer simplicity and simplicity. The best part is that you can always choose whether to use the F keys to perform multimedia changes/modify settings or use them as standard roles. So, let’s understand the concept of function keys and how to lock the Fn key in Windows 11. How do function keys work?

Can't change core voltage in MSI Afterburner: 3 ways to fix it Can't change core voltage in MSI Afterburner: 3 ways to fix it Apr 14, 2023 am 09:31 AM

After installing MSI Afterburner, you may notice that it does not have GPU voltage control. Some unsupported desktop GPU models require temporary fixes for voltage control and work in MSI Afterburner. Find below a way to unlock the MSI Afterburner lock voltage on your laptop GPU. How to unlock voltage control in MSI Afterburner? Unlocking voltage control on MSI Afterburner is limited to +100 modified boost allowed value. Try using a modified bios with a high base voltage to allow voltage control using MSI Afterb

How to unlock SteelSeries keyboard if it is locked? How to unlock SteelSeries keyboard if it is locked? Mar 04, 2024 am 09:30 AM

If the SteelSeries keyboard is locked, it may be because we connected an external keyboard to the computer and then pressed numlock to unlock it. We can also press fn+numlock. Let’s take a look. How to unlock the SteelSeries keyboard if it is locked: 1. It may be that the keyboard is connected externally. We can press numlock to lock it. We can connect the keyboard and press numlock again to return to normal. 2. If you haven’t connected the external keyboard, we can find the fn keyboard in the keyboard. This button is called the second function button. When we press this button and then press the other two function buttons, the second function will appear. Then find the f8 button. The second function of fn is the function corresponding to numlock. Press f

Different ways to lock and unlock the Fn key in Windows 10 and 11 Different ways to lock and unlock the Fn key in Windows 10 and 11 Apr 14, 2023 pm 12:49 PM

How the Fn Key Works with Function Keys The Fn key on your keyboard is basically similar to the Shift and CapsLock buttons. If you create documents frequently, you know how they work: Hold down Shift to capitalize a letter or two, then release it to quickly return to lowercase, while clicking CapsLock lets you write the entire letter in uppercase sentence without holding down another key. This is how Fn works with the standard function keys F1 through F12. When not using Fn

Kirin 9000S unlocked benchmarks exposed: Stunning performance exceeds expectations Kirin 9000S unlocked benchmarks exposed: Stunning performance exceeds expectations Sep 05, 2023 pm 12:45 PM

Huawei's latest Mate60Pro mobile phone has attracted widespread attention after it went on sale in the domestic market. However, recently there has been some controversy on the benchmark platform about the performance of the Kirin 9000S processor equipped on the machine. According to the test results of the platform, the running scores of Kirin 9000S are incomplete, and the GPU running scores are missing, resulting in the inability of some benchmarking software to adapt. According to information exposed online, Kirin 9000S has achieved astonishing results in the unlocked running score test. The total score is 950935 points. Specifically, the CPU score is as high as 279,677 points, while the previously missing GPU score is 251,152 points. Compared with the total score of 699783 points in the previous AnTuTu official test, this shows the performance improvement of Kirin 9000S.

How to unlock iPhone without passcode How to unlock iPhone without passcode Aug 18, 2023 pm 09:49 PM

1. Use Computer The first way to unlock iPhone without passcode or Face ID is to use computer. You must restore your iPhone in recovery mode. Once done, you can set up your iPhone and set up a new passcode, Touch ID, Face ID, or choose to use your device without any of these. You can use a Mac or even a Windows PC for this process. Please note: This method will delete all content and restore your iPhone to factory settings. If you have backed up your data, you can restore it while setting up your iPhone. 1. First, you need to turn off your iPhone. 2. Next, perform a force restart to put your iPhone into recovery mode. For iPhone8 or higher

Here's how to dual-boot Windows 11 on Microsoft Surface Duo Here's how to dual-boot Windows 11 on Microsoft Surface Duo Apr 29, 2023 pm 09:37 PM

Install Windows 11 on Microsoft Surface Duo Remember, the steps described below apply to unlocked and AT&T models of Surface Duo. Surface Duo2 powered by Qualcomm Snapdragon 888 processor is completely incompatible with this module. Warning: Before we learn how to dual-boot Windows 11 on Microsoft Surface Duo, remember to take an off-device backup. This is because the process requires erasing all data on the phone, including files in the internal storage. You might brick your device permanently, so only try this if you know what you're doing

How to unlock an iPhone if you forgot the password How to unlock an iPhone if you forgot the password Feb 19, 2024 am 09:33 AM

How to unlock iPhone if you forget password In modern society, mobile phones have become an indispensable part of our lives. Among mobile phones, Apple mobile phones are chosen and trusted by the majority of users due to their stability and security. However, sometimes we also encounter some problems, such as forgetting the iPhone password we set. How to unlock your iPhone if you forget your password? Below we will discuss several common unlocking methods. The first method is to unlock it through the "Retrieve Phone Password" function. First, we want to make sure the phone is connected to the Internet. Then,

See all articles