解 docker postgres 反复重启的问题

2024-12-16

背景

immich 使用 postgres 作为数据库,发现无法打开相关服务,仔细查看是无法连接数据库,数据库不断重启。docker log内容为

2024-12-16 20:54:26 2024-12-16 12:54:26.288 UTC [1] LOG:  redirecting log output to logging collector process
2024-12-16 20:54:26 2024-12-16 12:54:26.288 UTC [1] HINT:  Future log output will appear in directory "log".
2024-12-16 20:50:12 
2024-12-16 20:50:12 PostgreSQL Database directory appears to contain a database; Skipping initialization
2024-12-16 20:50:12 
2024-12-16 20:50:46

没有全部的日志内容,需要去查看 log 文件夹下对应时间的详细日志

[2024-12-16T12:54:39Z INFO  service::utils::clean] Find directory "pg_vectors/indexes/17332/segments/d5f94e4c-3dca-4426-91c8-e401381e72b3".
2024-12-16 12:54:42.201 UTC [46] FATAL:  the database system is starting up
2024-12-16 12:54:42.213 UTC [47] FATAL:  the database system is starting up
2024-12-16 12:54:45.206 UTC [48] FATAL:  the database system is starting up
2024-12-16 12:54:45.221 UTC [49] FATAL:  the database system is starting up
2024-12-16 12:54:47.859 UTC [28] LOG:  database system was not properly shut down; automatic recovery in progress
FATAL: could not create file "base/197420/989335": File exists

结果

分析上面日志,可以看到有文件占用,导致无法创建对应文件 重点见

FATAL: could not create file "base/197420/989335": File exists
  1. 如果将 989335 文件删除,重启 postgres 数据库。结果 无效果,数据库依然重启。
  2. 将文件按照文件名进行排列,可以看到 989335 以及 989335_init ,可以将类似 xx_init 一起删除。等待 postgresl 数据库运行。后续 数据库启动成功,服务正常。
copyright ©2019-2024 shenzhen
粤ICP备20041170号-1