2026-07-0720:00:46 CST[13082]:user=,db=,app=,client=LOG: database system was interrupted;last known up at2026-07-0719:53:31 CST cp: cannotstat‘/var/lib/pgsql/15/archive/00000011.history’: No suchfileor directory2026-07-0720:00:46 CST[13082]:user=,db=,app=,client=FATAL: recovery target timeline17does not exist
二、根据日志报错先排查修复主库报错
主库日志报错:
2026-07-0717:38:57 CST[17670]:user=,db=,app=,client=DETAIL: The database subdirectory"pg_tblspc/24610/PG_15_202209061/24847"is missing.
2026-07-0720:00:46 CST[13082]:user=,db=,app=,client=LOG: database system was interrupted;last known up at2026-07-0719:53:31 CST cp: cannotstat‘/var/lib/pgsql/15/archive/00000011.history’: No suchfileor directory2026-07-0720:00:46 CST[13082]:user=,db=,app=,client=FATAL: recovery target timeline17does not exist
6、排查过程
1. 查看主库当前的 timeline
# 在从库执行# 1. 查看 postgresql.auto.conf 内容[postgres@pg05 data]$catpostgresql.auto.conf l# Do not edit this file manually!# It will be overwritten by the ALTER SYSTEM command.checkpoint_completion_target='0.9'primary_conninfo='user=rep password=123456 channel_binding=prefer host=192.168.6.9 port=5432 sslmode=prefer sslcompression=0 sslsni=1 ssl_min_protocol_version=TLSv1.2 gssencmode=prefer krbsrvname=postgres target_session_attrs=any'# 2. .conf 里是否有 restore_commandgrep"restore_command"postgresql.confgrep"recovery_target_timeline"postgresql.conf# 3. 查看 standby.signal 是否存在[postgres@pg05 data]$ls-lastandby.signal -rw-r-----1postgres postgres0Jul719:54 standby.signal# 4. 查看 recovery.signal(PG12+ 如果有的话)[postgres@pg05 data]$ls-larecovery.signal ls: cannot access recovery.signal: No suchfileor directory# 5. 检查 postgresql.conf 里是否有 restore_command[postgres@pg05 data]$grep"restore_command"postgresql.conf restore_command=''# command to use to restore an archived logfile segment[postgres@pg05 data]$grep"recovery_target_timeline"postgresql.conf#recovery_target_timeline = 'latest' # 'current', 'latest', or timeline ID
# 1. 查找所有包含 restore_command 的配置文件[postgres@pg05 data]$grep-r"restore_command"/var/lib/pgsql/15/data/2>/dev/null postgresql.conf 中 restore_command 的实际生效值 psql-Upostgres-c"SHOW restore_command;"2>/dev/null||echo"无法连接"/var/lib/pgsql/15/data/pg_rman_recovery.conf:restore_command='cp /var/lib/pgsql/15/archive/%f %p'/var/lib/pgsql/15/data/postgresql.conf-bak20260706:#restore_command = '' # command to use to restore an archived logfile segment/var/lib/pgsql/15/data/postgresql.conf-bak20251025:#restore_command = '' # command to use to restore an archived logfile segment/var/lib/pgsql/15/data/postgresql.conf: restore_command=''# command to use to restore an archived logfile segment# 2. 检查是否使用了 include 指令引入了外部配置[postgres@pg05 data]$grep"^include"postgresql.conf include='pg_rman_recovery.conf'# added by pg_rman 1.3.15# 3. 查看 postgresql.conf 中 restore_command 的实际生效值[postgres@pg05 data]$ psql-Upostgres-c"SHOW restore_command;"2>/dev/null||echo"无法连接"结果:无法连接
根本原因:
# postgresql.conf 里有一行:include='pg_rman_recovery.conf'# added by pg_rman 1.3.15# 而这个 pg_rman_recovery.conf 文件里设置了:restore_command='cp /var/lib/pgsql/15/archive/%f %p'这就是问题所在! 虽然你在 postgresql.conf 里设置了 restore_command='',但 include 指令在后面引用了 pg_rman_recovery.conf,覆盖了你前面的设置。# PostgreSQL 的配置加载顺序是:postgresql.conf → include 的文件 → postgresql.auto.conf。所以 pg_rman_recovery.conf 里的 restore_command 最终生效了。
7、修复步骤:
cd/var/lib/pgsql/15/data# 备份 postgresql.confcppostgresql.conf postgresql.conf.bak# 注释掉 include 行sed-i's/^include/#include/g'postgresql.conf# 或者直接编辑vipostgresql.conf# 找到下面这行,在前面加 # 注释掉# include = 'pg_rman_recovery.conf' # added by pg_rman 1.3.15# 重命名或删除 pg_rman_recovery.conf(可选)## 重命名,让 PostgreSQL 找不到它mvpg_rman_recovery.conf pg_rman_recovery.conf.disabled# 重置 postgresql.auto.confcat>postgresql.auto.conf<<'EOF' primary_conninfo = 'user=rep password=123456 host=192.168.6.9 port=5432 sslmode=prefer' recovery_target_timeline = 'latest' EOF# 删除所有 .history 文件cd/var/lib/pgsql/15/datafind.-name"*.history"-typef-deleterm-fpg_wal/*.history# 清空 archive 目录rm-rf/var/lib/pgsql/15/archive/*# 启动从库systemctl start postgresql-15# 查看日志,验证修复是否成功tail-100/var/lib/pgsql/15/data/log/*.log# 启动成功后,应该看到类似这样的日志:LOG: database system was shut down at... LOG: entering standby mode LOG: started streaming WAL from primary at... LOG: consistent recovery state reached at...
如何在openEuler上快速部署Marvell QLogic FC HBA驱动:qla2xxx安装教程 【免费下载链接】qla2xxx provide Marvell QLogic FC HBA adapter qla2xxx driver for openEuler LTS version. 项目地址: https://gitcode.com/openeuler/qla2xxx
前往项目官网免费下载…