数据库期末复习 数据恢复
一、事务
1.1 基本概念
- 事务是用户定义的一个数据库操作序列,要么全做,要么都不做
- 操作:
BEGIN TRANSACTION 事务开始
COMMIT/ROLLBACK 事务结束
1.2 ACID特性
-
原子性
-
一致性
-
隔离性
-
持续性
1.3 事务状态
二、Schedule
2.1 Serial
一个事务接一个事务,无交叉
2.2 conflict Serializable
A schedule is conflict serializable if and only if its precedence graph is acyclic(无环的).
If a schedule S can be transformed into a schedule S´ by a series of swaps of non-conflicting instructions, we say that S and S´ are conflict equivalent.
We say that a schedule S is conflict serializable if it is conflict equivalent to a serial schedule.
- li = read(Q), lj = read(Q). li and lj don’t conflict.
- li = read(Q), lj = write(Q). They conflict.
- li = write(Q), lj = read(Q). They conflict
- li = write(Q), lj = write(Q). They conflict
三、恢复
利用日志文件
日志文件基础操作:
3.1 故障
- 事务内部的故障 用UNDO
- 系统故障 用REDO
- 介质故障
- 计算机病毒
3.2 Redo
3.3 Undo
- checkpoint
在日志中加入< CKPT >
标记的事务表示已提交或完成
3.4 Redo/Undo
四、锁
4.1 状态
- Unlocked
- Shared (Read)
- Exclusive (Write)
4.2 共用
s-读锁
x-写锁
4.3 2PL Lock
- two phase lock
- Strict 2PL
All locks held by a transaction are released only when the transaction completes.