# 20.14. Error Handling
If on, any error will terminate the current session. By default, this is set to off, so that only FATAL errors will terminate the session.
When set to on, which is the default, PostgreSQL will automatically reinitialize after a backend crash. Leaving this value set to on is normally the best way to maximize the availability of the database. However, in some circumstances, such as when PostgreSQL is being invoked by clusterware, it may be useful to disable the restart so that the clusterware can gain control and take any actions it deems appropriate.
This parameter can only be set in thepostgresql.conf
file or on the server command line.
When set to off, which is the default, PostgreSQL will raise a PANIC-level error on failure to flush modified data files to the file system. This causes the database server to crash. This parameter can only be set at server start.
在某些操作系统上,在回写失败后,内核页面缓存中的数据状态是未知的。在某些情况下,它可能已被完全遗忘,因此重试不安全;第二次尝试可能会被报告为成功,而实际上数据已经丢失。在这些情况下,避免数据丢失的唯一方法是在报告任何故障后从 WAL 中恢复,最好是在调查故障的根本原因并更换任何故障硬件之后。
如果设置为 on,PostgreSQL 将改为报告错误但继续运行,以便可以在以后的检查点重试数据刷新操作。只有在调查了操作系统对缓冲数据的处理后才能将其设置为 on,以防写回失败。
当设置为同步
,这是默认设置,PostgreSQL 将在崩溃恢复开始之前递归地打开并同步数据目录中的所有文件。文件搜索将遵循 WAL 目录和每个配置的表空间的符号链接(但不是任何其他符号链接)。这是为了确保在重放更改之前,所有 WAL 和数据文件都持久地存储在磁盘上。这适用于启动未完全关闭的数据库集群,包括使用 pg 创建的副本_基本备份。
在 Linux 上,同步文件
可以改为使用,要求操作系统同步包含数据目录、WAL 文件和每个表空间的整个文件系统(但不能通过符号链接访问任何其他文件系统)。这可能比同步
设置,因为它不需要一个一个地打开每个文件。另一方面,如果文件系统由修改大量文件的其他应用程序共享,则可能会更慢,因为这些文件也将写入磁盘。此外,在 5.8 之前的 Linux 版本上,写入数据到磁盘时遇到的 I/O 错误可能不会报告给 PostgreSQL,并且相关的错误消息可能只出现在内核日志中。
该参数只能在postgresql.conf
文件或在服务器命令行上。