[root@redhatos ~]# pgcreate_pg_control.sh ======================================== PostgreSQL 控制文件生成脚本 ======================================== 数据目录: /var/lib/pgsql/18/data PostgreSQL 二进制目录: /usr/pgsql-18/bin ======================================== 1. 计算 -l 参数(下一个 WAL 文件位置)...最新 WAL 文件: 000000010000000000000076下一个 WAL 文件: 000000010000000000000077 2. 计算 -x 参数(下一个事务 ID)...找到 pg_xact/0000 文件,使用默认值: 1048576 3. 计算 -m 参数(多事务 ID)...最大 pg_multixact/offsets 文件名: 0002计算得到的 next-multixact-id: 196608计算得到的 oldest-multixact-id: 131072 4. 计算 -O 参数(多事务偏移量)...找到 pg_multixact/members/0000 文件,使用默认值: 52352 5. 计算 -c 参数(可查询提交时间的事务ID)...未找到提交时间文件,使用默认值: 0,0 6. 设置 -e 参数(下一个事务ID的纪元)...下一个事务ID的纪元: 1 ======================================== 收集到的参数:-l (next-wal-file): 000000010000000000000077-x (next-transaction-id): 1048576-m (multixact-ids): 196608-O (multixact-offset): 52352-c (commit-timestamp-ids): 0,0-e (epoch): 1 ======================================== ======================================== 生成的 pg_resetwal 命令: ======================================== sudo -u postgres /usr/pgsql-18/bin/pg_resetwal -f -l "000000010000000000000077" -x "1048576" -m "196608,131072" -O "52352" -c "0,0" -e "1" "/var/lib/pgsql/18/data"======================================== 使用说明: ======================================== 1. 确保 PostgreSQL 服务已停止: sudo -u postgres /usr/pgsql-18/bin/pg_ctl stop 2. 如果 pg_control 文件不存在,创建空文件: sudo -u postgres touch /var/lib/pgsql/18/data/global/pg_control 3. 执行上面生成的命令 4. 启动 PostgreSQL 服务: sudo -u postgres /usr/pgsql-18/bin/pg_ctl start 5. 运行一致性检查: sudo -u postgres /usr/pgsql-18/bin/vacuumdb --all --analyze-in-stages 6. 备份数据库: sudo -u postgres /usr/pgsql-18/bin/pg_dumpall > backup.sql注意: 此命令会重置 WAL 日志,可能导致数据丢失,请谨慎执行! [root@redhatos ~]#
