成都网站建设设计

将想法与焦点和您一起共享

锁表怎么解决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如何解锁表

一些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数据库update锁表现象及处理办法

Session1创建测试表:

SQL create table test (id number (10) not null , name varchar(20), primary key(id));

Table created.

SQL desc test;

Name Null? Type

----------------------------------------- -------- ----------------------------

ID NOT NULL NUMBER(10)

NAME VARCHAR2(20)

SQL insert into test values(001,'tom');

1 row created.

SQL insert into test values(002,'lisa');

1 row created.

SQL insert into test values(003,'joy');

1 row created.

SQL insert into test values(004,'jia');

1 row created.

查看test表信息

SQL update test set name='xue' where name='joy';

1 row updated.

SQL commit;

Commit complete.

SQL select * from test updata;

ID NAME

---------- --------------------

1 tom

2 lisa

3 xue

4 jia

重新打开session 2:

SQL select * from test;

ID NAME

---------- --------------------

1 tom

2 lisa

3 xue

4 jia

update模拟锁表

SQL update test set name='da' where name='tom';

1 row updated.

注:不提交

Session2查询:

SQL select * from test;

ID NAME

---------- --------------------

1 tom

2 lisa

3 xue

4 jia

查看哪个表被锁

SQL select b.owner,b.object_name,a.session_id,a.locked_mode from v$locked_object a,dba_objects b where b.object_id = a.object_id;

OWNER

------------------------------

OBJECT_NAME

--------------------------------------------------------------------------------

SESSION_ID LOCKED_MODE

---------- -----------

SYS

TEST

23 3

查看是哪个session引起的

SQL select b.username,b.sid,b.serial#,logon_time from v$locked_object a,v$session b where a.session_id = b.sid order by b.logon_time;

USERNAME SID SERIAL# LOGON_TIM

------------------------------ ---------- ---------- ---------

SYS 23 23 02-JAN-20

杀掉对应进程

SQL alter system kill session'23,23';

System altered.

其中23为sid,23为serial#.

SQL select b.owner,b.object_name,a.session_id,a.locked_mode from v$locked_object a,dba_objects b where b.object_id = a.object_id;

no rows selected

SQL select b.username,b.sid,b.serial#,logon_time from v$locked_object a,v$session b where a.session_id = b.sid order by b.logon_time;

no rows selected

session 1查询:

SQL select * from test;

select * from test

*

ERROR at line 1:

ORA-00028: your session has been killed

SQL select * from test;

select * from test

*

ERROR at line 1:

ORA-01012: not logged on

Process ID: 5366

Session ID: 23 Serial number: 23

重新连接SQL

[oracle@localhost ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Thu Jan 2 11:39:53 2020

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL select * from test updata;

ID NAME

---------- --------------------

1 tom

2 lisa

3 xue

4 jia


新闻名称:锁表怎么解决oracle,锁表怎么解决oracle 代码层
文章位置:http://chengdu.cdxwcx.cn/article/hchpds.html