lock是锁定数据库中的对象的 latch(锁存)进行操作的对象是数据库内部加锁
当事务需向缓冲区写入信息时,为了使用此块内存区域, ORACLE首先必须取得这块内存区域的锁存,才能向此块内存写入信息。
相关文档如下:
Latches are different from locks (enqueues) in several ways, although both are locking mechanisms.
Latches vs. Locks
Purpose
Serve a single purpose: to provide exclusive access to memory structures. (Starting in Oracle9i Database, the cache buffers chains latches are shareable for read-only.)
Serve two purposes: to allow multiple processes to share the same resource when the lock modes are compatible and to enforce exclusive access to the resource when the lock modes are incompatible.
Jurisdiction
Apply only to data structures in the SGA.
Protect memory objects, which are temporary.
Control access to a memory structure for a single operation.
Not transactional.
Protect database objects such as tables, data blocks, and state objects.
Application driven and control access to data or metadata in the database.
Transactional.
Acquisition
Can be requested in two modes: willing-to-wait or no-wait.
Can be requested in six different modes: null, row share, row exclusive, share, share row exclusive, or exclusive.
Scope
Information is kept in the memory and is only visible to the local instance—latches operate at instance level.
Information is kept in the database and is visible to all instances accessing the database—locks operate at database-level.
Complexity
Implemented using simple instructions, typically, test-and-set, compare-and-swap, or simple CPU instructions. Implementation is port specific because the CPU instructions are machine dependent.
Lightweight.
Implemented using a series of instructions with context switches.
Heavyweight.
Duration
Held briefly (in microseconds).
Normally held for an extended period of time (transactional duration).
Queue
When a process goes to sleep after failing to acquire a latch, its request is not queued and serviced in order (with a few exceptions—for example, the latch wait list latch has a queue). Latches are fair game and up for grabs.
When a process fails to get a lock, its request is queued and serviced in order, unless the NOWAIT option is specified.
Deadlock
Latches are implemented in such a way that they are not subject to deadlocks.
Locks support queuing and are subject to deadlocks. A trace file is generated each time a deadlock occurs.