1、在做Oracle監(jiān)聽程序測試時(shí),發(fā)現(xiàn)帳戶已經(jīng)被鎖定。
創(chuàng)新互聯(lián)建站專注于企業(yè)全網(wǎng)整合營銷推廣、網(wǎng)站重做改版、澠池網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5頁面制作、成都商城網(wǎng)站開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為澠池等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
2、在數(shù)據(jù)庫安裝電腦上,點(diǎn)擊開始打開運(yùn)行窗口。
3、在運(yùn)行窗口輸入CMD,調(diào)出命令提示符界面。
3、在命令提示符下面,用管理員身份登入到數(shù)據(jù)庫sqlplus / as sysdba。
4、輸入解鎖命令alter user Scott account unlock后回車。
5、看見用戶已更改的字樣,表示命令已成功執(zhí)行。
6、再切換到監(jiān)聽程序驗(yàn)證,原來的ora-28000帳戶被鎖定的提示已經(jīng)不存在了。用戶解鎖成功。
1. 先通過top命令查看產(chǎn)用資源較多的spid號
2.查詢當(dāng)前耗時(shí)的會話ID,用戶名,sqlID等:
select sid,serial#,machine,username,program,sql_hash_value,sql_id,
? to_char(logon_time,'yyyy/mm/dd hh24:mi:ss') as login_time from v$session
where paddr in (select addr from v$process where spid in ('5648612','256523'));
3. 如果上一步sql_id或者 hash_value不為空,則可用v$sqlarea查出當(dāng)前正在使用的sql
select sql_text
from v$sqltext_with_newlines
where hash_value = hash_value
order by piece;
也可直接使用:
select a.*,b.SQL_TEXT from (
select sid,serial#,machine,username,program,sql_hash_value,sql_id,
? to_char(logon_time,'yyyy/mm/dd hh24:mi:ss') as login_time from v$session
where paddr in (select addr from v$process where spid in ('23226'))
) a,v$sql b
where a.sql_id? = b.SQL_ID(+)
4.kill占用大資源的session
Alter system kill session 'SID,SERIAL#'
解鎖:
1.查詢哪些對象被鎖:
select object_name,machine,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;
2.下面的語句用來殺死一個(gè)進(jìn)程:
alter system kill session '524,1095'; (其中24,111分別是上面查詢出的sid,serial#)
3.再一次查詢目前鎖定的對象,若發(fā)現(xiàn)以上方法不能解除鎖定的表,則用以下方法:
3.1 執(zhí)行下面的語句獲得進(jìn)程(線程)號:
select spid, osuser, s.program
from v$session s,v$process p
where s.paddr=p.addr and s.sid=524 (524是上面的sid)
查詢鎖表
select object_name, machine, 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;
解表
ALTER system kill session 'sid, serial#';
ALTER system kill session '256, 34034';
1.創(chuàng)建測試表,如下圖。
createtabletest_lock(idnumber,valuevarchar2(200));
2.執(zhí)行append語句;并且不做提交,insert/*+append*/intotest_lockvalues(1,1)如下圖。
3.再次執(zhí)行清表語句,truncatetabletest_lock;報(bào)鎖表錯(cuò)誤,如下圖。
4.查看鎖表語句,發(fā)現(xiàn)被鎖表
selectb.object_name,t.*
fromv$locked_objectt,user_objectsb
wheret.object_id=b.object_id
注意事項(xiàng):
簡化數(shù)據(jù):可以將復(fù)雜的查詢創(chuàng)建為其他人可以使用的視圖,而不必了解復(fù)雜的業(yè)務(wù)或邏輯關(guān)系。這簡化并掩蓋了視圖用戶數(shù)據(jù)的復(fù)雜性。
表結(jié)構(gòu)設(shè)計(jì)的補(bǔ)充:在設(shè)計(jì)的系統(tǒng)才剛剛開始,大部分的程序直接訪問數(shù)據(jù)表結(jié)構(gòu),但是隨著業(yè)務(wù)的變化,系統(tǒng)更新,等等,引起了一些表結(jié)構(gòu)不適用,這次修改系統(tǒng)的表結(jié)構(gòu)太大,開發(fā)成本較高的影響。
這個(gè)時(shí)候可以創(chuàng)建一個(gè)視圖來補(bǔ)充表結(jié)構(gòu)設(shè)計(jì),降低開發(fā)成本。程序可以通過查詢視圖直接獲得它想要的數(shù)據(jù)。
添加安全性:視圖可以向用戶顯示表中的指定字段,而不是向用戶顯示表中的所有字段。在實(shí)際開發(fā)中,視圖通常作為提供數(shù)據(jù)的一種方式提供,并將只讀權(quán)限提供給第三方以供查詢使用。
select LOCK_INFO.OWNER || '.' || LOCK_INFO.OBJ_NAME as "已鎖物件名稱", --物件名稱(已經(jīng)被鎖住)
LOCK_INFO.SUBOBJ_NAME as "已鎖子物件名稱", -- 子物件名稱(已經(jīng)被鎖住)
SESS_INFO.MACHINE as "機(jī)器名稱", -- 機(jī)器名稱
LOCK_INFO.SESSION_ID as "會話ID", -- 會話SESSION_ID
SESS_INFO.SERIAL# as "會話SERIAL#", -- 會話SERIAL#
SESS_INFO.SPID as "OS系統(tǒng)的SPID", -- OS系統(tǒng)的SPID
(SELECT INSTANCE_NAME FROM V$INSTANCE) "實(shí)例名SID", --實(shí)例名SID
LOCK_INFO.ORA_USERNAME as "ORACLE用戶", -- ORACLE系統(tǒng)用戶名稱
LOCK_INFO.OS_USERNAME as "OS用戶", -- 作業(yè)系統(tǒng)用戶名稱
LOCK_INFO.PROCESS as "進(jìn)程編號", -- 進(jìn)程編號
LOCK_INFO.OBJ_ID as "對象ID", -- 對象ID
LOCK_INFO.OBJ_TYPE as "對象類型", -- 對象類型
SESS_INFO.LOGON_TIME as "登錄時(shí)間", -- 登錄時(shí)間
SESS_INFO.PROGRAM as "程式名稱", -- 程式名稱
SESS_INFO.STATUS as "會話狀態(tài)", -- 會話狀態(tài)
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;
在對指定表做append操作,其他再做truncate時(shí)候,會產(chǎn)生鎖表,如下驗(yàn)證步驟,
1、創(chuàng)建測試表,
create table test_lock(id number, value varchar2(200));
2、執(zhí)行append語句;并且不做提交,insert /*+append*/ into test_lock values(1,1);
3、再次執(zhí)行清表語句,truncate table test_lock;報(bào)鎖表錯(cuò)誤,
4、查看鎖表語句,發(fā)現(xiàn)被鎖表,
select b.object_name, t.*
from v$locked_object t, user_objects b
where t.object_id = b.object_id