【发布时间】:2020-02-04 11:39:18
【问题描述】:
我正在使用 pg_basebackup 从我的 postgresql 数据库 (v11) 进行备份,如下所示:
pg_basebackup -h localhost -p 5432 -U postgres -D /tmp/backup -Ft -z -Xs -P
备份过程完成得很好,没有任何错误。然后作为测试,我想从备份中恢复,为此我执行以下步骤:
- 关闭 postgres 实例。
-
从
/var/lib/postgresql/data文件夹中删除所有内容rm -rf /var/lib/postgresl/data/* -
在那里解压基础存档:
tar xvf /tmp/backup/base.tar.gz -C /var/lib/postgresql/data -
将wal存档解压到一个临时目录
tar xvf /tmp/backup/pg_wal.tar.gz -C /tmp/archived_wals -
在
/var/lib/postgresql/data文件夹中创建一个文件recovery.conf:touch /var/lib/postgresql/data/recovery.conf chown postgres:postgres /var/lib/postgresql/data/recovery.conf -
在 recovery.conf 文件中指定恢复命令:
restore_command = 'cp /path/archived_wals/%f "%p" ' 重启 postgres 实例,等待恢复完成。
但是,当 postgres 启动时,我在日志中收到以下错误:
2020-02-04 11:34:52.599 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2020-02-04 11:34:52.599 UTC [1] LOG: listening on IPv6 address "::", port 5432
2020-02-04 11:34:52.613 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-02-04 11:34:52.709 UTC [18] LOG: database system was interrupted; last known up at 2020-02-04 08:39:54 UTC
cp: can't stat '/tmp/archived_wals/00000002.history': No such file or directory
2020-02-04 11:34:52.735 UTC [18] LOG: starting archive recovery
2020-02-04 11:34:52.752 UTC [18] LOG: invalid checkpoint record
2020-02-04 11:34:52.752 UTC [18] FATAL: could not locate required checkpoint record
2020-02-04 11:34:52.752 UTC [18] HINT: If you are not restoring from a backup, try removing the file "/var/lib/postgresql/data/backup_label".
2020-02-04 11:34:52.753 UTC [1] LOG: startup process (PID 18) exited with exit code 1
2020-02-04 11:34:52.753 UTC [1] LOG: aborting startup due to startup process failure
2020-02-04 11:34:52.769 UTC [1] LOG: database system is shut down
我想我遗漏了一些东西,也许我需要对 postgres 进行额外配置才能恢复 pg_basebackup 备份?
【问题讨论】:
-
这应该可以。至少,它适用于我没有 timescaledb。您可以在启动之前将
/tmp/archived_wals/中的 wal 文件直接复制到/var/lib/postgresql/data/pg_wal中,但这不是必需的。 -
@jjanes 确实如此。我在
recovery.conf文件上有一个类型。我有"%p%而不是"%p",它搞砸了,但是错误消息并没有真正很好地描述问题的根源。
标签: postgresql database-backups database-restore timescaledb