GBase 8s
适配迁移
文章

GBase 8s常见锁错误原因及处理办法

发表于2021-06-22 18:35:004919次浏览3个评论

错误原因:不能在表的数据行上加锁,该行数据已被锁 示例: session1

dbaccess testdb -					
drop table if exists t;
create table t(col1 int,col2 char(100));
insert into t select tabid,tabname from systables;		
begin;
delete from t where col1=1;		

session2

dbaccess testdb -					
begin;
delete from t where col1=1;		
-243: Could not position within a table (gbasedbt.t).
-107: ISAM error:  record is locked.

解决办法: 1、设置锁等待时间,等待被锁定的数据行锁释放(set lock mode to wait 10;)

-244 Could not do a physical-order read to fetch next row.

错误原因:表顺序扫描到某一个已被其他会话锁定的数据行出现该错误 示例: session1

dbaccess testdb -					
drop table if exists t;
create table t(col1 int,col2 char(100));
insert into t select tabid,tabname from systables;		
begin;
delete from t where col1=1;		

session2

dbaccess testdb -					
begin;
select * from t where col1=10;
-244    Could not do a physical-order read to fetch next row.
-107    ISAM error: record is locked.

解决办法: 1、创建合理索引,避免顺序扫描 2、设置锁等待时间,等待被锁定的数据行锁释放(set lock mode to wait 10;)

-245 Could not position within a file via an index.

错误原因:索引key被锁 示例: session1

dbaccess testdb -					
drop table if exists t;
create table t(col1 int,col2 char(100));
insert into t select tabid,tabname from systables;	
create index idx_t on t(col1);	
begin;
delete from t where col1=1;		

session2

dbaccess testdb -					
begin;
select * from t where col1=1;
-245: Could not position within a file via an index.
-144: ISAM error: key value locked.

解决办法: 1、设置锁等待时间,等待被锁定的key释放(set lock mode to wait 10;)

-246 Could not do an indexed read to get the next row.

错误原因:通过索引扫描定位到的数据行被锁 示例: session1

dbaccess testdb -					
drop table if exists t;
create table t(col1 int,col2 char(100));
insert into t select tabid,tabname from systables;	
create index idx_t on t(col1);	
begin;
update t set col2='aaa' where col1=1;

session2

dbaccess testdb -					
begin;
select * from t where col1=1;
-246    Could not do an indexed read to get the next row.
-107    ISAM error: record is locked.

解决办法: 1、设置锁等待时间,等待被锁定的数据行释放(set lock mode to wait 10;)

总结:

要避免数据库出现频繁的锁冲突,需要尽量避免表的全表扫描以及设置锁等待时间,创建合理的索引及设置合理的锁等待时间。 对于JDBC,可在URL添加环境变量设置锁等待:IFX_LOCK_MODE_WAIT=10; 对于其他应用程序,如不方便添加set lock mode to wait 10;设置会话级别锁等待,可考虑创建sysdbopen函数,设置全库有效的锁等待: dbaccess testdb <<! create procedure public.sysdbopen() set lock mode to wait 10; end procedure; !

评论

登录后才可以发表评论
用户头像
路路路发表于 10个月前
崔哥发表于 10个月前
中秋一轮月,只和旧青冥。都缘人意,须道今夕别般明。是处登临开宴,争看吴歌楚舞,沈醉倒金尊。各自心中事,悲乐几般情。烛摧花,鹤惊露,忽三更。舞茵未卷,玉绳低转便西倾。认取眼前流景,试看月归何处,因甚有亏盈。我自阖门睡,高枕笑浮生。
崔哥发表于 7个月前
梅花不肯傍春光,自向深冬著艳阳。龙笛远吹胡地月,燕钗初试汉宫妆。风虽强暴翻添思,雪欲侵凌更助香。应笑暂时桃李树,盗天和气作年芳。