You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu系统PostgreSQL 13集群启动失败:无法恢复00000004.history文件

PostgreSQL 13集群启动失败排查与解决(Ubuntu环境)

核心错误提示

FATAL: could not restore file "00000004.history" from archive: command not found.

完整集群日志

● postgresql@13-mydb.service - PostgreSQL Cluster 13-mydb
     Loaded: loaded (/lib/systemd/system/postgresql@.service; enabled-runtime; vendor preset: enabled)
     Active: failed (Result: protocol) since Thu 2023-11-09 17:01:44 +03; 1min 32s ago
    Process: 767207 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 13-mydb start (code=exited, status=1/FAILURE)

Nov 09 17:01:44 master postgresql@13-mydb[767207]: sh: 1: pgbackrest: not found
Nov 09 17:01:44 master postgresql@13-mydb[767207]: 2023-11-09 17:01:44.700 +03 [767228] FATAL:  could not restore file "00000004.history" from archive: command not found
Nov 09 17:01:44 master postgresql@13-mydb[767207]: 2023-11-09 17:01:44.703 +03 [767227] LOG:  startup process (PID 767228) exited with exit code 1
Nov 09 17:01:44 master postgresql@13-mydb[767207]: 2023-11-09 17:01:44.703 +03 [767227] LOG:  aborting startup due to startup process failure
Nov 09 17:01:44 master postgresql@13-mydb[767207]: 2023-11-09 17:01:44.745 +03 [767227] LOG:  database system is shut down
Nov 09 17:01:44 master postgresql@13-mydb[767207]: pg_ctl: could not start server
Nov 09 17:01:44 master postgresql@13-mydb[767207]: Examine the log output.
Nov 09 17:01:44 master systemd[1]: postgresql@13-mydb.service: Can't open PID file /run/postgresql/13-mydb.pid (yet?) after start: Operation not permitted
Nov 09 17:01:44 master systemd[1]: postgresql@13-mydb.service: Failed with result 'protocol'.
Nov 09 17:01:44 master systemd[1]: Failed to start PostgreSQL Cluster 13-mydb.

问题根源

从日志里的sh: 1: pgbackrest: not found可以明确:当前集群配置的restore_command依赖pgbackrest归档工具,但该工具未在机器上安装,或者postgres用户的环境变量找不到它。你的推测没错,这个restore_command大概率是从主节点复制过来的归档恢复配置,但从节点没同步部署对应的工具。

解决步骤

1. 确认restore_command配置

先检查当前集群的postgresql.conf里的相关设置:

sudo -u postgres cat /etc/postgresql/13/mydb/postgresql.conf | grep restore_command

如果输出包含pgbackrest相关命令,就坐实了依赖问题。

2. 安装pgbackrest(保留归档恢复功能)

如果这个节点需要从归档恢复数据,直接在Ubuntu上安装pgbackrest:

sudo apt update
sudo apt install pgbackrest

安装完成后,验证postgres用户能否调用该命令:

sudo -u postgres pgbackrest --version

确认可用后重启集群:

sudo systemctl start postgresql@13-mydb

3. 注释restore_command(无需归档恢复)

如果这个节点只是作为只读副本,仅通过流复制同步数据,不需要归档恢复功能,直接注释掉该配置:
编辑postgresql.conf:

sudo -u postgres nano /etc/postgresql/13/mydb/postgresql.conf

找到restore_command行,添加#注释:

# restore_command = 'pgbackrest ...'

保存后重启集群:

sudo systemctl start postgresql@13-mydb

4. 修复PID文件权限问题(可选)

日志里还提到PID文件权限问题,检查并调整目录权限:

ls -ld /run/postgresql

确保postgres用户拥有读写权限,必要时执行:

sudo chown postgres:postgres /run/postgresql
sudo chmod 755 /run/postgresql

内容的提问来源于stack exchange,提问作者Abdullah Ergin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 20:22:53