简体   繁体   English

在数据库中批量写入 WAL 文件不会否定 WAL 文件的目的吗?

[英]Doesn't batch writing WAL files in databases negate the purporse of WAL files?

I am reading about databases and I can't understand one thing about WAL files.我正在阅读有关数据库的信息,但我无法理解有关 WAL 文件的一件事。 They exist in order to make sure transactions are reliable and recoverable, however, apparently, to improve performance, WAL files are written in batches instead of immediately.它们的存在是为了确保事务的可靠性和可恢复性,然而,显然,为了提高性能,WAL 文件是批量写入而不是立即写入。 This looks to me quite contradictory and negates the purpose of WAL files.这在我看来很矛盾并且否定了 WAL 文件的目的。 What happens if there's a crash between WAL commits?如果 WAL 提交之间发生崩溃会发生什么? How does this differ from not having the WAL at all and simply fsync'ing the database itself periodically?这与根本没有 WAL 而只是定期同步数据库本身有什么不同?

I've no much idea and just seeked for information about this as it seems interesting to me.我没有太多想法,只是寻找有关这方面的信息,因为我觉得这很有趣。

If some ninja find my explanation incorrect please, correct me.如果有忍者发现我的解释不正确,请纠正我。 What I understand at this point is that WAL files are written before the commit, then once confirmed that the transaction data is on the WAL, it confirms the transaction.这一点我的理解是WAL文件是在commit之前写的,然后一旦确认事务数据在WAL上,就确认事务。

What is done in batch is to move this WAL data to heap and index, real tables.批量做的就是把这个WAL数据移动到堆和索引,真正的表。


Write-Ahead Logging (WAL) is a standard method for ensuring data integrity.预写日志 (WAL) 是确保数据完整性的标准方法。 A detailed description can be found in most (if not all) books about transaction processing.在大多数(如果不是全部)关于事务处理的书籍中都可以找到详细的描述。 Briefly, WAL's central concept is that changes to data files (where tables and indexes reside) must be written only after those changes have been logged, that is, after log records describing the changes have been flushed to permanent storage.简而言之,WAL 的中心概念是对数据文件(表和索引所在的位置)的更改必须仅在这些更改被记录后写入,即在描述更改的日志记录已刷新到永久存储之后。 If we follow this procedure, we do not need to flush data pages to disk on every transaction commit, because we know that in the event of a crash we will be able to recover the database using the log: any changes that have not been applied to the data pages can be redone from the log records.如果我们遵循这个过程,我们不需要在每次事务提交时将数据页刷新到磁盘,因为我们知道在发生崩溃的情况下,我们将能够使用日志恢复数据库:任何尚未应用的更改可以从日志记录中重做数据页。 (This is roll-forward recovery, also known as REDO.) (这是前滚恢复,也称为 REDO。)

https://www.postgresql.org/docs/current/wal-intro.html https://www.postgresql.org/docs/current/wal-intro.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM