Postgresql 中文操作指南
pg_checksums
pg_checksums — 在 PostgreSQL 数据库集簇中启用、禁用或检查数据校验和
pg_checksums — enable, disable or check data checksums in a PostgreSQL database cluster
Description
pg_checksums 检查、启用或禁用 PostgreSQL 集簇中的数据校验和。在运行 pg_checksums 之前,必须干净地关闭服务器。验证校验和时,如果没有校验和错误,则退出状态为零;如果检测到至少一个校验和出现故障,则退出状态为非零。启用或禁用校验和时,如果操作失败,则退出状态为非零。
pg_checksums checks, enables or disables data checksums in a PostgreSQL cluster. The server must be shut down cleanly before running pg_checksums. When verifying checksums, the exit status is zero if there are no checksum errors, and nonzero if at least one checksum failure is detected. When enabling or disabling checksums, the exit status is nonzero if the operation failed.
在验证校验和时,将扫描集簇中的每个文件。在启用校验和时,将原位重写每个改变的校验和的关系文件块。禁用校验和只能更新文件 pg_control 。
When verifying checksums, every file in the cluster is scanned. When enabling checksums, each relation file block with a changed checksum is rewritten in-place. Disabling checksums only updates the file pg_control.
Options
以下命令行选项可用:
The following command-line options are available:
-
-D _directory—pgdata=_directory
-
Specifies the directory where the database cluster is stored.
-
-
-c_—check_
-
Checks checksums. This is the default mode if nothing else is specified.
-
-
-d_—disable_
-
Disables checksums.
-
-
-e_—enable_
-
Enables checksums.
-
-
-f _filenode—filenode=_filenode
-
Only validate checksums in the relation with filenode filenode.
-
-
-N_—no-sync_
-
By default, pg_checksums will wait for all files to be written safely to disk. This option causes pg_checksums to return without waiting, which is faster, but means that a subsequent operating system crash can leave the updated data directory corrupt. Generally, this option is useful for testing but should not be used on a production installation. This option has no effect when using —check.
-
-
-P_—progress_
-
Enable progress reporting. Turning this on will deliver a progress report while checking or enabling checksums.
-
-
-v_—verbose_
-
Enable verbose output. Lists all checked files.
-
-
-V_—version_
-
Print the pg_checksums version and exit.
-
-
-?_—help_
-
Show help about pg_checksums command line arguments, and exit.
-
Environment
-
PGDATA
-
Specifies the directory where the database cluster is stored; can be overridden using the -D option.
-
-
PG_COLOR
-
Specifies whether to use color in diagnostic messages. Possible values are always, auto and never.
-
Notes
启用大型集簇中的校验和可能需要很长时间。在此操作期间,必须不启动集簇或写入数据目录的其他程序,否则可能会发生数据丢失。
Enabling checksums in a large cluster can potentially take a long time. During this operation, the cluster or other programs that write to the data directory must not be started or else data loss may occur.
当使用直接复制关系文件块的工具(例如 pg_rewind )的复制设置时,如果操作未在所有节点上始终如一地完成,则启用或禁用校验和会导致页面损坏(以不正确的校验和形式出现)。因此,在复制设置中启用或禁用校验和时,建议先停止所有集群,然后再一致地切换所有集群。摧毁所有备用,对主集群执行操作,并最终从头开始重建备用也是安全的。
When using a replication setup with tools which perform direct copies of relation file blocks (for example pg_rewind), enabling or disabling checksums can lead to page corruptions in the shape of incorrect checksums if the operation is not done consistently across all nodes. When enabling or disabling checksums in a replication setup, it is thus recommended to stop all the clusters before switching them all consistently. Destroying all standbys, performing the operation on the primary and finally recreating the standbys from scratch is also safe.
如果在启用或禁用校验和时中止或终止 pg_checksums,则集群数据校验和配置保持不变,并且可以重新运行 pg_checksums 以执行相同操作。
If pg_checksums is aborted or killed while enabling or disabling checksums, the cluster’s data checksum configuration remains unchanged, and pg_checksums can be re-run to perform the same operation.