postgres Write-Ahead Log DOUBLE RE-APPLY 有可能吗?
Would it possible that postgres Write-Ahead Log DOUBLE RE-APPLY?
我在这里找到引用
PostgreSQL is one of the databases relying on write-ahead log (WAL) –
all changes are written to a log (a stream of changes) first, and only
then to the data files. That provides durability, because in case of a
crash the database may use WAL to perform recovery – read the changes
from WAL and re-apply them on data files.
来自这篇文章https://blog.2ndquadrant.com/basics-of-tuning-checkpoints/
假设有 WAL 文件继续跟随查询
UPDATE page SET view_count = view_count + 1;
我可以想象这样的情况,postgres 已经将这个 WAL 应用到 DB
但它在应用后立即崩溃。
DB 尚未更新最新的 WAL 位置或删除 WAL 日志文件。
当 DB 启动时,它会进行恢复并再次重新应用此 WAL,不是吗?
数据库中的这个最终值会变成 view_count + 2
吗?
请指教
这种情况称为部分页面写入。 PostgreSQL 有配置选项来防止这个问题 full_page_writes
。默认启用:
When this parameter is on, the PostgreSQL server writes the entire content of each disk page to WAL during the first modification of that page after a checkpoint. This is needed because a page write that is in process during an operating system crash might be only partially completed, leading to an on-disk page that contains a mix of old and new data.
通过恢复页面副本而不是重做更新来重播更改。
我在这里找到引用
PostgreSQL is one of the databases relying on write-ahead log (WAL) – all changes are written to a log (a stream of changes) first, and only then to the data files. That provides durability, because in case of a crash the database may use WAL to perform recovery – read the changes from WAL and re-apply them on data files.
来自这篇文章https://blog.2ndquadrant.com/basics-of-tuning-checkpoints/
假设有 WAL 文件继续跟随查询
UPDATE page SET view_count = view_count + 1;
我可以想象这样的情况,postgres 已经将这个 WAL 应用到 DB 但它在应用后立即崩溃。
DB 尚未更新最新的 WAL 位置或删除 WAL 日志文件。
当 DB 启动时,它会进行恢复并再次重新应用此 WAL,不是吗?
数据库中的这个最终值会变成 view_count + 2
吗?
请指教
这种情况称为部分页面写入。 PostgreSQL 有配置选项来防止这个问题 full_page_writes
。默认启用:
When this parameter is on, the PostgreSQL server writes the entire content of each disk page to WAL during the first modification of that page after a checkpoint. This is needed because a page write that is in process during an operating system crash might be only partially completed, leading to an on-disk page that contains a mix of old and new data.
通过恢复页面副本而不是重做更新来重播更改。