BEGIN TRANSACTION
INSERT INTO tblTest VALUES (1)
COMMIT TRANSACTION
接下来,将活动分解为简单的日志记录步骤,如下表所述。
Statement Actions performed
BEGIN TRANSACTION **Written to the log cache area.** However, it is
not necessary to flush to stable storage
because the SQL Server has not made any
physical changes.
INSERT INTO tblTest
1. Data page 150 is retrieved into SQL Server data
cache, if not already available.
2. The page is latched, pinned, and marked dirty,
and appropriate locks are obtained.
3. An Insert Log record is built and added to the
log cache.
4. A new row is added to the data page.
5. The latch is released.
6. The log records associated with the transaction
or page does not have to be flushed at this point
because all changes remain in volatile storage.
COMMIT TRANSACTION
1. A Commit Log record is formed and the log
records associated with the transaction must be
written to stable storage. The transaction is
not considered committed until the log records
are correctly assigned to stable storage.
2. Data page 150 remains in SQL Server data
cache and is not immediately flushed to stable
storage. When the log records are correctly
secured, recovery can redo the operation, if it
is necessary.
3. Transactional locks are released.
[1]: https://learn.microsoft.com/en-US/troubleshoot/sql/admin/logging-data-storage-algorithms
不,它不是“立即”硬化的,但是在日志记录实际刷新到磁盘之前事务要经过一系列步骤。只需阅读SQL Server 和 WAL阅读“SQL Server 和 WAL”部分。
对于每个数据库,您都会获得一个日志缓存一个连续的内存区域,该内存区域保存日志信息并在事务提交时刷新到磁盘。日志缓存可以包含有关多个事务的信息,并且每次提交都会触发刷新到磁盘以强化日志记录。AFAIK 大小为 60K(可能在新版本中发生了变化,不太确定大小)
如果日志缓存记录没有刷新到磁盘/没有硬化,是的,它将丢失
阅读我在上面分享的博客。我引用上面博客中的例子
接下来,将活动分解为简单的日志记录步骤,如下表所述。