ITPub博客

首页 > 应用开发 > IT综合 > Explicit (Manual) Data Locking (364)

Explicit (Manual) Data Locking (364)

原创 IT综合 作者:tsinglee 时间:2007-12-13 10:27:57 0 删除 编辑

Oracle always performs locking automatically to ensure data concurrency, data
integrity, and statement-level read consistency. However, you can override the Oracle
default locking mechanisms. Overriding the default locking is useful in situations such
as these:
■ Applications require transaction-level read consistency or repeatable reads. In
other words, queries in them must produce consistent data for the duration of the
transaction, not reflecting changes by other transactions. You can achieve
transaction-level read consistency by using explicit locking, read-only transactions,
serializable transactions, or by overriding default locking.
■ Applications require that a transaction have exclusive access to a resource so that
the transaction does not have to wait for other transactions to complete.

Oracle’s automatic locking can be overridden at the transaction level or the session
level.

At the transaction level, transactions that include the following SQL statements
override Oracle’s default locking:
■ The SET TRANSACTION ISOLATION LEVEL statement
■ The LOCK TABLE statement (which locks either a table or, when used with views,
the underlying base tables)
■ The SELECT ... FOR UPDATE statement
Locks acquired by these statements are released after the transaction commits or rolls
back.
At the session level, a session can set the required transaction isolation level with the
ALTER SESSION statement.

Note: If Oracle’s default locking is overridden at any level, the
database administrator or application developer should ensure that
the overriding locking procedures operate correctly. The locking
procedures must satisfy the following criteria: data integrity is
guaranteed, data concurrency is acceptable, and deadlocks are not
possible or are appropriately handled.

显示(手工)加锁
在以下情况下手工加锁(覆盖Oracle默认的锁机制)非常有用
1. 应用需要事务级别的一致性读或者可重复读. 用户可以显示地对数据加锁,使用只读事务
或串行化事务,或覆盖默认的锁,从而实现事务级的读一致性
2. 应用要求事务必须以排他地访问某种资源,而不需要等待其他事务完成
3. 用户可以在事务级或会话级覆盖 Oracle 默认采用的锁
4. 在事务级别 , 可以使用下面的语句来覆盖Oracle默认的锁 ... , 这些锁在事务提交或回滚后
释放
5. 在会话级别,可以使用alter session 设置事务隔离级别
6. 手工加锁操作必须满足以下标准:保证数据完整性,提供足够的数据并发能力,
不会发生死锁或能够正确处理死锁

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10599713/viewspace-992629/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    740
  • 访问量
    1892392