作者
Greg Sabino Mullane
译者
张⽂升
$ pg_checksums --helppg_checksums enables, disables, or verifies data checksums in a PostgreSQLdatabase cluster.Usage:pg_checksums [OPTION]... [DATADIR]Options:[-D, --pgdata=]DATADIR data directory-c, --check check data checksums (default)-d, --disable disable data checksums-e, --enable enable data checksums-f, --filenode=FILENODE check only relation with specified filenode-N, --no-sync do not wait for changes to be written safely todisk-P, --progress show progress information-v, --verbose output verbose messages-V, --version output version information, then exit-?, --help show this help, then exit
$ export PGDATA=data$ initdb --no-instructions --auth=trustThe files belonging to this database system will be owned by user "greg".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.creating directory data ... okcreating subdirectories ... okselecting dynamic shared memory implementation ... posixselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting default time zone ... Livingstone/Zambiacreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... oksyncing data to disk ... ok
$ echo -e "logging_collector=on\nlisten_addresses='' " >>data/postgresql.conf$ pg_ctl startwaiting for server to start....2020-09-05 00:00:47.914 EDT [8499] LOG: redirecting log output to loggingcollector process2020-09-05 00:00:47.914 EDT [8499] HINT: Future log output will appear indirectory "log".doneserver started
$ export PGDATABASE=testdb$ createdb$ pgbench --initialize --scale=300dropping old tables...creating tables...generating data (client-side)...30000000 of 30000000 tuples (100%) done (elapsed 22.60 s, remaining 0.00s)vacuuming...creating primary keys...done in 39.61 s (drop tables 0.21 s, create tables 0.01 s, client-sidegenerate 22.89 s, vacuum 3.29 s, primary keys 13.21 s).
$ psql -Axtc 'show data_checksums'data_checksums|off$ pg_controldata | grep -E 'state|checksum'Database cluster state: in productionData page checksum version: 0
$ pg_checksums --pgdata data --enablepg_checksums: error: cluster must be shut down$ pg_ctl stop --mode=fastwaiting for server to shut down.... doneserver stopped$ pg_controldata | grep -E 'state|checksum'Database cluster state: shut downData page checksum version: 0
$ time bin/pg_checksums --enable --progress4518/4518 MB (100%) computedChecksum operation completedFiles scanned: 1239Blocks scanned: 578376pg_checksums: syncing data directorypg_checksums: updating control fileChecksums enabled in clusterreal 0m4.719suser 0m1.157ssys 0m1.669s
$ pg_ctl stop --mode=immediatewaiting for server to shut down.... doneserver stopped$ pg_controldata | grep -E 'state|checksum'Database cluster state: in productionData page checksum version: 0$ pg_checksums --pgdata data --enablepg_checksums: error: cluster must be shut down$ psql -Axtc 'show data_checksums'psql: error: could not connect to server: could not connect to server: Nosuch file or directoryIs the server running locally and acceptingconnections on Unix domain socket "/tmp/.s.PGSQL.5432"?
$ pg_ctl start; pg_ctl stop --mode=fastwaiting for server to start....2020-09-05 00:38:26.866 EDT [7547] LOG: starting PostgreSQL 14.02020-09-05 00:38:26.866 EDT [7547] LOG: redirecting log output to loggingcollector process2020-09-05 00:38:26.866 EDT [7547] HINT: Future log output will appear indirectory "log".doneserver startedwaiting for server to shut down.... doneserver stopped$ pg_controldata | grep stateDatabase cluster state: shut down
$ pg_checksums --checkChecksum operation completedFiles scanned: 1239Blocks scanned: 578376Bad checksums: 0Data checksum version: 1$ time pg_checksums --disablepg_checksums: syncing data directorypg_checksums: updating control fileChecksums disabled in clusterreal 0m0.180suser 0m0.013ssys 0m0.025s
$ pg_ctl stop$ mv data/pg_twophase data/pg_twophase.DO_NOT_START_THIS_DATABASE$ pg_checksums --enable --progress$ mv data/pg_twophase.DO_NOT_START_THIS_DATABASE data/pg_twophase$ pg_ctl start
PostgreSQL中文社区欢迎广大技术人员投稿
投稿邮箱:press@postgres.cn
最后修改时间:2021-08-27 10:25:23
文章转载自PostgreSQL中文社区,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




