Linux command
pg_rewind 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Rewind target against a running source server
pg_rewind -D [target_dir] --source-server="host=[host] user=[rewind_user] dbname=[postgres]"
Rewind against a locally shut-down source
pg_rewind -D [target_dir] --source-pgdata=[source_dir]
Dry run
pg_rewind -n -D [target_dir] --source-server="[conninfo]"
Rewind and write recovery configuration
pg_rewind -R -D [target_dir] --source-server="[conninfo]"
Show progress
pg_rewind -P -D [target_dir] --source-pgdata=[source_dir]
Restore missing WAL files
pg_rewind -c -D [target_dir] --source-server="[conninfo]"
说明
pg_rewind resynchronizes a PostgreSQL data directory with another copy of the same cluster after their timelines have diverged. Typical use is to re-attach a former primary as a standby after a failover without taking a full base backup. It identifies the point where the timelines diverged, then copies from the source only the blocks that changed in the target after that point, along with all current configuration, WAL, and other required files. The source must have `wal_log_hints` enabled or be initialized with data checksums, and `full_page_writes` must be on.
参数
- -D, --target-pgdata _dir_
- Target data directory to be modified. Must have been cleanly shut down.
- --source-pgdata _dir_
- File-system path of a cleanly shut-down source cluster.
- --source-server _connstr_
- libpq connection string for a running source server.
- -n, --dry-run
- Perform all work without modifying the target directory.
- -N, --no-sync
- Return without waiting for changes to be flushed to disk.
- -P, --progress
- Show progress while copying files.
- -R, --write-recovery-conf
- Create `standby.signal` and append connection settings to `postgresql.auto.conf`.
- -c, --restore-target-wal
- Use `restore_command` to fetch WAL files missing from `pg_wal`.
- --config-file _file_
- Main server configuration file for the target cluster.
- --no-ensure-shutdown
- Do not run single-user recovery; fail if the target is not cleanly shut down.
- --sync-method _method_
- Method used to flush changes: `fsync` (default) or `syncfs`.
- --debug
- Print verbose debugging output.
- -V, --version
- Print version information.
- -?, --help
- Show help.
FAQ
What is the pg_rewind command used for?
pg_rewind resynchronizes a PostgreSQL data directory with another copy of the same cluster after their timelines have diverged. Typical use is to re-attach a former primary as a standby after a failover without taking a full base backup. It identifies the point where the timelines diverged, then copies from the source only the blocks that changed in the target after that point, along with all current configuration, WAL, and other required files. The source must have `wal_log_hints` enabled or be initialized with data checksums, and `full_page_writes` must be on.
How do I run a basic pg_rewind example?
Run `pg_rewind -D [target_dir] --source-server="host=[host] user=[rewind_user] dbname=[postgres]"` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -D, --target-pgdata _dir_ do in pg_rewind?
Target data directory to be modified. Must have been cleanly shut down.