我有一个带有本地 Linux 卷映射的 Docker PostgreSQL (TimescaleDB) 开发人员实例。
version: '3'
services:
dex-timeseriesdb:
image: timescale/timescaledb:latest-pg12
# https://stackoverflow.com/a/56754077/315168
shm_size: 1g
container_name: dex-timeseriesdb
environment:
POSTGRES_USER: postgres
volumes:
- $PWD/data/postgresql:/var/lib/postgresql/data
非正常关闭后,实例不再以FATAL: xlog flush request 0/2CEFA910 is not satisfied --- flushed only to 0/1B48258
错误启动:
dex-timeseriesdb |
dex-timeseriesdb | PostgreSQL Database directory appears to contain a database; Skipping initialization
dex-timeseriesdb |
dex-timeseriesdb | 2021-06-13 18:50:47.330 UTC [1] LOG: starting PostgreSQL 12.6 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.2.1_pre1) 10.2.1 20201203, 64-bit
dex-timeseriesdb | 2021-06-13 18:50:47.330 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
dex-timeseriesdb | 2021-06-13 18:50:47.330 UTC [1] LOG: listening on IPv6 address "::", port 5432
dex-timeseriesdb | 2021-06-13 18:50:47.336 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
dex-timeseriesdb | 2021-06-13 18:50:47.486 UTC [21] LOG: database system shutdown was interrupted; last known up at 2021-06-13 18:47:35 UTC
dex-timeseriesdb | 2021-06-13 18:50:49.629 UTC [21] LOG: database system was not properly shut down; automatic recovery in progress
dex-timeseriesdb | 2021-06-13 18:50:49.645 UTC [21] LOG: redo starts at 0/1B46C68
dex-timeseriesdb | 2021-06-13 18:50:49.648 UTC [21] LOG: invalid record length at 0/1B48258: wanted 24, got 0
dex-timeseriesdb | 2021-06-13 18:50:49.648 UTC [21] LOG: redo done at 0/1B48220
dex-timeseriesdb | 2021-06-13 18:50:49.697 UTC [21] LOG: request to flush past end of generated WAL; request 0/2CEFA910, currpos 0/1B48258
dex-timeseriesdb | 2021-06-13 18:50:49.697 UTC [21] CONTEXT: writing block 0 of relation base/13455/16573_vm
dex-timeseriesdb | 2021-06-13 18:50:49.697 UTC [21] FATAL: xlog flush request 0/2CEFA910 is not satisfied --- flushed only to 0/1B48258
dex-timeseriesdb | 2021-06-13 18:50:49.697 UTC [21] CONTEXT: writing block 0 of relation base/13455/16573_vm
dex-timeseriesdb | 2021-06-13 18:50:49.701 UTC [1] LOG: startup process (PID 21) exited with exit code 1
dex-timeseriesdb | 2021-06-13 18:50:49.701 UTC [1] LOG: aborting startup due to startup process failure
dex-timeseriesdb | 2021-06-13 18:50:49.744 UTC [1] LOG: database system is shut down
这可能是由于不干净的 Docker 关闭造成的数据损坏。
数据库中没有什么重要的东西。但是,我仍然想了解在这种情况下是否可以恢复数据库,而不是从头开始重建它或从备份中恢复。
我使用 shell 测试了卷映射在 Docker 实例中是可写的,所以这应该不是问题。
根据提供的日志,该问题与数据文件损坏有关 - 这可能是由不正确的关机引起的。数据文件之一已损坏。
文件位置应该是
$PGDATA/base/13455/16573_vm
建议操作:
首先,重要的是要记住这个错误是关于写入数据目录的页面,而不是关于 WAL 流。这意味着,如果表的数据确实丢失了,这里的主要目标是从 WAL 流中获取数据的副本。
在我们详细介绍如何做到这一点之前,让我们首先找出受影响的表或索引。
在日志消息
invalid page in block 0 of relation base/13455/16573_vm
中,我们得到以下信息:这意味着我们可以通过首先执行以下操作来定位正确的数据库来找到受影响的表:
然后连接到该数据库并运行以下命令,这为我们提供了受影响的表或索引:
如果受影响的数据库对象是一个索引,那对你来说是幸运的——你可以重建索引来修复所有问题。
如果受影响的数据库对象是一个表 - 运气不好 - 可用的选项是: