大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

oracle怎么锁表 oracle如何锁住表

查询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表在什么情况下会被锁住

在对指定表做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查询资源占用,锁表解锁

1. 先通过top命令查看产用资源较多的spid号

2.查询当前耗时的会话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查出当前正在使用的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.下面的语句用来杀死一个进程:

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

3.再一次查询目前锁定的对象,若发现以上方法不能解除锁定的表,则用以下方法:

3.1 执行下面的语句获得进程(线程)号:

select spid, osuser, s.program

from v$session s,v$process p

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

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如何锁住表
标题链接:http://dzwzjz.com/article/hghpjs.html
在线咨询
服务热线
服务热线:028-86922220
TOP