189 8069 5689

oracle怎么锁表,oracle为什么锁表

oracle表在什么情况下会被锁住

在对指定表做append操作,其他再做truncate时候,会产生锁表,如下验证步骤,

裕华网站建设公司成都创新互联公司,裕华网站设计制作,有大型网站制作公司丰富经验。已为裕华上千余家提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的裕华做网站的公司定做!

1、创建测试表,

create table test_lock(id number, value varchar2(200));

2、执行append语句;并且不做提交,insert /*+append*/ into test_lock values(1,1);

3、再次执行清表语句,truncate table test_lock;报锁表错误,

4、查看锁表语句,发现被锁表,

select b.object_name, t.*

from v$locked_object t, user_objects b

where t.object_id = b.object_id

查询Oracle锁表语句以及解锁语句

查询锁表:SELECT l.session_id sid,

  s.serial#,

  l.locked_mode,

  l.oracle_username,

  l.os_user_name,

  s.machine,

  s.terminal,

  o.object_name,

  s.logon_time FROM  v$locked_object l,

  all_objects      o,

  v$session        s WHERE l.object_id = o.object_id ANd l.session_id = s.sid ORDER BY sid,

  s.serial#;

解锁:ALTER system KILL session 'sid,serial#';

查询锁住原因:SELECT b.sid oracleID,b.username 登录Oracle用户名,b.serial#,spid 操作系统ID,paddr, 

sql_text 正在执行的SQL,b.machine 计算机名 FROM v$process a, v$session b, v$sqlarea c 

WHERE a.addr = b.paddr AND b.sql_hash_value = c.hash_value  and b.USERNAME='FKPHIS24';

oracle 锁表的语句

锁表:LOCK TABLE tablename IN 锁模式 MODE;

解锁:commit或rollback;

锁模式有以下几种:

ROW SHARE

ROW SHARE permits concurrent access to the locked table but prohibits users from locking the entire table for exclusive access. ROW SHARE is synonymous with SHARE UPDATE, which is included for compatibility with earlier versions of Oracle Database.

ROW EXCLUSIVE

ROW EXCLUSIVE is the same as ROW SHARE, but it also prohibits locking in SHARE mode. ROW EXCLUSIVE locks are automatically obtained when updating, inserting, or deleting.

SHARE UPDATE

See ROW SHARE.

SHARE

SHARE permits concurrent queries but prohibits updates to the locked table.

SHARE ROW EXCLUSIVE

SHARE ROW EXCLUSIVE is used to look at a whole table and to allow others to look at rows in the table but to prohibit others from locking the table in SHARE mode or from updating rows.

EXCLUSIVE

EXCLUSIVE permits queries on the locked table but prohibits any other activity on it.

oracle 锁表、解锁的语句

一些ORACLE中的进程被杀掉后,状态被置为"killed",但是锁定的资源很长时间不释放,有时实在没办法,只好重启数据库。现在提供一种方法解决这种问题,那就是在ORACLE中杀不掉的,在OS一级再杀。

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.下面的语句用来杀死一个进程:

alter system kill session '24,111'; (其中24,111分别是上面查询出的sid,serial#)

【注】以上两步,可以通过Oracle的管理控制台来执行。

3.如果利用上面的命令杀死一个进程后,进程状态被置为"killed",但是锁定的资源很长时间没有被释放,那么可以在os一级再杀死相应的进程(线程),首先执行下面的语句获得进程(线程)号:

select spid, osuser, s.program

from v$session s,v$process p

where s.paddr=p.addr and s.sid=24 (24是上面的sid)

4.在OS上杀死这个进程(线程):

1)在unix上,用root身份执行命令:

#kill -9 12345(即第3步查询出的spid)

2)在windows(unix也适用)用orakill杀死线程,orakill是oracle提供的一个可执行命令,语法为:

orakill sid thread

其中:

sid:表示要杀死的进程属于的实例名

thread:是要杀掉的线程号,即第3步查询出的spid。

例:c:orakill orcl 12345

Oracle 锁表查询 和解锁表

查询锁表

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';


分享题目:oracle怎么锁表,oracle为什么锁表
当前地址:http://jkwzsj.com/article/hsscch.html

其他资讯