查看: 8790|回复: 11

[原创] 探讨 DB2 的隔离级别,以及如何设置

[复制链接]
求职 : 数据库管理员
论坛徽章:
186
授权会员
日期:2008-07-27 22:25:202014年新春福章
日期:2014-02-18 16:42:02马上有房
日期:2014-02-18 16:42:02马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上加薪
日期:2014-02-19 11:55:14版主4段
日期:2015-02-26 02:21:03慢羊羊
日期:2015-03-04 14:51:35
跳转到指定楼层
1#
发表于 2007-1-11 17:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Oracle 中的锁可以是手动的,也可以是自动的。Oracle Lock Manager 可以在行级隐式地锁定表数据,此外也可以使用以下 SQL 语句在事务或会话级覆盖缺省的锁:
1. SET TRANSACTION ISOLATION LEVEL
2. LOCK TABLE
3. SELECT FOR UPDATE

Oracle 支持一种称为 Multi-Version Read Consistency 的机制,这是用 undo 段中的 undo 数据实现的。

DB2 实现 ANSI 标准隔离(Isolation)级别,例如未提交读(Uncommitted Read)、游标稳定性(Cursor stability)、读稳定性(Read stability)和可重复读(Repeatable Read)。除非使用未提交读隔离级别,否则用户只能看到已提交的数据。行锁是根据隔离级别隐式地获得的。可锁定的数据库对象有表空间、表和行,但是,只有表和表空间可以显式锁定。可使用 LOCK TABLE 命令来锁定一个表,而不是使用缺省的行锁定。

=====================
注: LOCK TABLE 语句命令格式如下:
>>-LOCK TABLE--+-table-name-+--IN--+-SHARE-----+--MODE---------><
               '-nickname---'      '-EXCLUSIVE-'

=====================
求职 : 数据库管理员
论坛徽章:
186
授权会员
日期:2008-07-27 22:25:202014年新春福章
日期:2014-02-18 16:42:02马上有房
日期:2014-02-18 16:42:02马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上加薪
日期:2014-02-19 11:55:14版主4段
日期:2015-02-26 02:21:03慢羊羊
日期:2015-03-04 14:51:35
2#
 楼主| 发表于 2007-1-11 17:27 | 只看该作者
现在,我的问题如下:
1. DB2 如何显示的设置其隔离级别呢?
2. 其默认的隔离级别是否是 CS?
3. 事务默认的隔离级别是什么?

欢迎大家探讨!

使用道具 举报

回复
论坛徽章:
0
3#
发表于 2007-1-11 21:12 | 只看该作者
1.At the statement level:
SELECT (INTO), DELETE, UPDATE ... WITH {RR, RS, CS, UR}
For dynamic SQL within the current session:
SET CURRENT ISOLATION = {RR, RS, CS, UR} or SET ISOLATION {RR, RS, CS, UR}
At precompile or bind time:
ISOLATION {RR, RS, CS, UR} option of the command line processor PREP or BIND commands
From the DB2 Call Level Interface (DB2 CLI):
For DB2 CLI, change the isolation level as part of the DB2 CLI configuration (db2cli.ini). This can be done either by:
UPDATE CLI CFG FOR SECTION sectionname USING TXNISOLATION {1, 2, 4, 8}
where:
1 = SQL_TXN_READ_UNCOMMITTED - Read Uncommitted (Uncommitted Read)
2 = SQL_TXN_READ_COMMITTED (default) - Read Committed (Cursor Stability)
4 = SQL_TXN_REPEATABLE_READ - Repeatable Read (Read Stability)
8 = SQL_TXN_SERIALIZABLE - Serializable (Repeatable Read)
editing db2cli.ini and setting applTxnIsolation = {1, 2, 4, 8}
From CLI or ODBC at run time:
Use the SQLSetConnectAttr function with the SQL_ATTR_TXN_ISOLATION attribute to set the transaction isolation level for the current connection referenced by the ConnectionHandle.
When working with JDBC or SQLJ at run time:
Use the setTransactionIsolation method in the java.sql interface connection, where:
TRANSACTION_SERIALIZABLE = Repeatable read
TRANSACTION_REPEATABLE_READ = Read stability
TRANSACTION_READ_COMMITTED = Cursor stability
TRANSACTION_READ_UNCOMMITTED = Uncommitted read
On a Command Line Processor (CLP) Connection:
CHANGE ISOLATION TO {RR, RS, CS, UR, NC} where NC stands for No Commit
On database servers that support REXX:
CHANGE SQLISL TO {RR|CS|UR|RS|NC} {RR, RS, CS, UR, NC}

2.yes, the default isolation level is CS

3.sorry, i can not understand and answer your question, hope somebody can help on it

使用道具 举报

回复
求职 : 数据库管理员
论坛徽章:
186
授权会员
日期:2008-07-27 22:25:202014年新春福章
日期:2014-02-18 16:42:02马上有房
日期:2014-02-18 16:42:02马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上加薪
日期:2014-02-19 11:55:14版主4段
日期:2015-02-26 02:21:03慢羊羊
日期:2015-03-04 14:51:35
4#
 楼主| 发表于 2007-1-12 11:52 | 只看该作者
对于以下的实例,我看不明白,
能否请高手指点一下?
==========
In the following example, a user is in DB2 interactive mode following creation of the SAMPLE database:

   update command options using c off
   catalog db sample as sample2

   set client connect 2

   connect to sample
   connect to sample2

   change isolation to cs
   set connection sample
   declare c1 cursor for select * from org
   open c1                        // 1。这里是成功的吧?
   fetch c1 for 3 rows

   change isolation to rr    // 2。这里是失败的吧?
   fetch c1 for 2 rows  

An SQL0514N error occurs because c1 is not in a prepared state for this isolation level.
=====================
3。实际上,是在 sample2 上open的c1 吗?
=====================

   change isolation to cs
   set connection sample2
   fetch c1 for 2 rows

An SQL0514N error occurs because c1 is not in a prepared state for this database.

=====================
4。 为什么?
=====================

使用道具 举报

回复
论坛徽章:
22
ITPUB元老
日期:2006-12-13 17:04:38ITPUB十周年纪念徽章
日期:2011-11-01 16:19:41生肖徽章2007版:鼠
日期:2008-01-02 17:35:53生肖徽章2007版:虎
日期:2008-01-02 17:35:53生肖徽章2007版:兔
日期:2008-01-02 17:35:53生肖徽章2007版:猴
日期:2008-01-02 17:35:53生肖徽章2007版:鸡
日期:2008-01-02 17:35:53ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44会员2007贡献徽章
日期:2007-09-26 18:42:10授权会员
日期:2006-12-13 17:02:18
5#
发表于 2007-1-13 16:01 | 只看该作者
最初由 zhangzongjun 发布
[B]现在,我的问题如下:
1. DB2 如何显示的设置其隔离级别呢?
2. 其默认的隔离级别是否是 CS?
3. 事务默认的隔离级别是什么?

欢迎大家探讨! [/B]



默认的隔离级别是CS
事务默认的隔离级别也是CS

使用


[PHP]

C:\>db2 select * from org with cs

DEPTNUMB DEPTNAME       MANAGER DIVISION   LOCATION
-------- -------------- ------- ---------- -------------
      10 Head Office        160 Corporate  New York
      15 New England         50 Eastern    Boston
      20 Mid Atlantic        10 Eastern    Washington
      38 South Atlantic      30 Eastern    Atlanta
      42 Great Lakes        100 Midwest    Chicago
      51 Plains             140 Midwest    Dallas
      66 Pacific            270 Western    San Francisco
      84 Mountain           290 Western    Denver

  8 条记录已选择。

.
[/PHP]

使用道具 举报

回复
论坛徽章:
0
6#
发表于 2007-1-16 10:08 | 只看该作者
学习!

使用道具 举报

回复
求职 : 数据库管理员
论坛徽章:
186
授权会员
日期:2008-07-27 22:25:202014年新春福章
日期:2014-02-18 16:42:02马上有房
日期:2014-02-18 16:42:02马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上加薪
日期:2014-02-19 11:55:14版主4段
日期:2015-02-26 02:21:03慢羊羊
日期:2015-03-04 14:51:35
7#
 楼主| 发表于 2007-1-16 15:52 | 只看该作者
luckysea

select * from org with cs

只是静态SQL的用法,
但大多数情况下,还是使用 游标 的

在使用游标时(正如 第4楼 描述的那样),
本人存在很多疑问,
请大家帮忙说明一些,
谢谢~!

使用道具 举报

回复
论坛徽章:
12
开发板块每日发贴之星
日期:2005-05-15 01:02:09ERP板块每日发贴之星
日期:2010-05-29 01:01:01生肖徽章2007版:鼠
日期:2009-03-10 21:26:28生肖徽章2007版:虎
日期:2008-11-19 08:08:16ERP板块每日发贴之星
日期:2008-11-18 01:01:03生肖徽章2007版:狗
日期:2008-11-17 20:21:29ERP板块每日发贴之星
日期:2008-11-16 01:01:04奥运会纪念徽章:乒乓球
日期:2008-08-12 22:18:43授权会员
日期:2008-02-29 10:22:07生肖徽章2007版:虎
日期:2008-02-28 21:02:13
8#
发表于 2008-7-7 23:12 | 只看该作者
我顶顶
学习

使用道具 举报

回复
论坛徽章:
5
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44生肖徽章2007版:鸡
日期:2008-01-02 17:35:53生肖徽章2007版:鼠
日期:2008-01-02 17:35:532009新春纪念徽章
日期:2009-01-04 14:52:282011新春纪念徽章
日期:2011-02-18 11:43:33
9#
发表于 2008-7-8 01:10 | 只看该作者
原帖由 DB.Uncle 于 2007-1-11 21:12 发表
1.At the statement level:
SELECT (INTO), DELETE, UPDATE ... WITH {RR, RS, CS, UR}
For dynamic SQL within the current session:
SET CURRENT ISOLATION = {RR, RS, CS, UR} or SET ISOLATION {RR, RS, CS, UR}
At precompile or bind time:
ISOLATION {RR, RS, CS, UR} option of the command line processor PREP or BIND commands
From the DB2 Call Level Interface (DB2 CLI):
For DB2 CLI, change the isolation level as part of the DB2 CLI configuration (db2cli.ini). This can be done either by:
UPDATE CLI CFG FOR SECTION sectionname USING TXNISOLATION {1, 2, 4, 8}
where:
1 = SQL_TXN_READ_UNCOMMITTED - Read Uncommitted (Uncommitted Read)
2 = SQL_TXN_READ_COMMITTED (default) - Read Committed (Cursor Stability)
4 = SQL_TXN_REPEATABLE_READ - Repeatable Read (Read Stability)
8 = SQL_TXN_SERIALIZABLE - Serializable (Repeatable Read)
editing db2cli.ini and setting applTxnIsolation = {1, 2, 4, 8}
From CLI or ODBC at run time:
Use the SQLSetConnectAttr function with the SQL_ATTR_TXN_ISOLATION attribute to set the transaction isolation level for the current connection referenced by the ConnectionHandle.
When working with JDBC or SQLJ at run time:
Use the setTransactionIsolation method in the java.sql interface connection, where:
TRANSACTION_SERIALIZABLE = Repeatable read
TRANSACTION_REPEATABLE_READ = Read stability
TRANSACTION_READ_COMMITTED = Cursor stability
TRANSACTION_READ_UNCOMMITTED = Uncommitted read
On a Command Line Processor (CLP) Connection:
CHANGE ISOLATION TO {RR, RS, CS, UR, NC} where NC stands for No Commit
On database servers that support REXX:
CHANGE SQLISL TO {RR|CS|UR|RS|NC} {RR, RS, CS, UR, NC}

2.yes, the default isolation level is CS

3.sorry, i can not understand and answer your question, hope somebody can help on it

=======================
其实这个已经多是很清楚了哦,你仔细看看这个会有很大收获的(不知你看了没)

下面给你个链接,上面那段其中也有 ,希望对你有帮助
http://www.ibm.com/developerwork ... cle/dm-0509schuetz/

使用道具 举报

回复
论坛徽章:
12
开发板块每日发贴之星
日期:2005-05-15 01:02:09ERP板块每日发贴之星
日期:2010-05-29 01:01:01生肖徽章2007版:鼠
日期:2009-03-10 21:26:28生肖徽章2007版:虎
日期:2008-11-19 08:08:16ERP板块每日发贴之星
日期:2008-11-18 01:01:03生肖徽章2007版:狗
日期:2008-11-17 20:21:29ERP板块每日发贴之星
日期:2008-11-16 01:01:04奥运会纪念徽章:乒乓球
日期:2008-08-12 22:18:43授权会员
日期:2008-02-29 10:22:07生肖徽章2007版:虎
日期:2008-02-28 21:02:13
10#
发表于 2008-7-9 23:56 | 只看该作者
再顶两下

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表