PostgreSQL 13: 新增ignore_invalid_pages参数

PostgreSQL 13 新增ignore_invalid_pages参数用于控制数据库恢复过程中遇到坏块时是否绕过这个坏块继续进行数据库恢复,此参数默认值为off

早在 PostgreSQL 13 版本前 Developer Options已提供了zero_damaged_pages参数,用于控制PostgreSQL数据库运行过程中遇到坏块数据时是否绕过这个坏块。

详见以下手册解说。

手册说明

Allow WAL recovery to continue even if invalid pages are referenced (Fujii Masao)
This is enabled using ignore_invalid_pages.

关于zero_damaged_pages

zero_damaged_pages参数手册解说如下:

1
2
3
4
5
6
7
8
zero_damaged_pages (boolean)
Detection of a damaged page header normally causes PostgreSQL to report an error, aborting the current transaction. Setting
zero_damaged_pages to on causes the system to instead report a warning, zero out the damaged page in memory, and continue processing.
This behavior will destroy data, namely all the rows on the damaged page. However, it does allow you to get past the error and retrieve
rows from any undamaged pages that might be present in the table. It is useful for recovering data if corruption has occurred due to
a hardware or software error. You should generally not set this on until you have given up hope of recovering data from the damaged
pages of a table. Zeroed-out pages are not forced to disk so it is recommended to recreate the table or the index before turning
this parameter off again. The default setting is off, and it can only be changed by a superuser.

PostgreSQL当检测到受损的页面首部时会报错,并中止当前事务。将参数zero_damaged_pages设置为on,数据库将报WARNING错误,并将内存中的页面抹为零。然而该操作会带来数据丢失,也就是说受损页上的所有数据全都丢失。不过,这样做确实能绕过错误并从未损坏的页面中获取表中未受损的行。当出现软件或硬件故障导致数据损坏时,该选项可用于恢复数据。通常情况下只有当放弃从受损的页面中恢复数据时,才应当使用该选项。本选项默认是关闭的,且只有超级用户才能修改。

关于此参数的应用案例,可参考 PostgreSQL数据页面损坏修复

关于ignore_invalid_pages

ignore_invalid_pages参数手册解说如下:

1
2
3
4
5
6
7
ignore_invalid_pages (boolean)
If set to off (the default), detection of WAL records having references to invalid pages during recovery causes PostgreSQL
to raise a PANIC-level error, aborting the recovery. Setting ignore_invalid_pages to on causes the system to ignore invalid
page references in WAL records (but still report a warning), and continue the recovery. This behavior may cause crashes,
data loss, propagate or hide corruption, or other serious problems. However, it may allow you to get past the PANIC-level error,
to finish the recovery, and to cause the server to start up. The parameter can only be set at server start. It only has effect
during recovery or in standby mode.

如果设置为off,当在恢复过程中发现WAL记录引用了无效页面时,PostgreSQL引发严重错误,中止恢复。

如果设置为on,当在恢复过程中发现WAL记录引用了无效页面时,PostgreSQL忽略这个严重错误(但仍然告警),并继续进行恢复,这种行为可能会导致崩溃、数据丢失、隐藏损坏或其他严重问题。当遇到这种情况时,应首先尽量尝试恢复已损坏的数据文件。

两个参数的异同

ignore_invalid_pagesignore_invalid_pages参数共同之处为以下:

  • 都属于Developer Options参数,这种类型的参数是用来处理PostgreSQL源代码的,在postgresql.conf文件中已剔除,并且在某些情况下可以用于恢复严重受损的数据库,生产库原则上不应该使用这些参数,除非是紧急情况。
  • 都是用于控制数据库遇到坏块场景时的处理方式。

两个参数的不同点为以下:

  • ignore_invalid_pages参数用于数据库恢复过程中遇到坏块的场景,zero_damaged_pages参数用于当数据库运行过程中遇到数据坏块的场景。
  • 只有当数据库处于recovery modestandby mode时,ignore_invalid_pages参数才有效。

参考

最后推荐和张文升共同编写的《PostgreSQL实战》,本书基于PostgreSQL 10 编写,共18章,重点介绍SQL高级特性、并行查询、分区表、物理复制、逻辑复制、备份恢复、高可用、性能优化、PostGIS等,涵盖大量实战用例!

购买链接:https://item.jd.com/12405774.html

PostgreSQL实战
感谢支持!
0%