【问题标题】:Can't run pg_resetxlog with corrupted Postgres无法使用损坏的 Postgres 运行 pg_resetxlog
【发布时间】:2020-01-13 20:37:50
【问题描述】:

我在 docker 容器中运行的 Postgres 数据库可能已损坏。这个容器挂载了一个数据卷到/var/lib/postgresql/data

我执行到 docker 容器中并运行命令 gosu postgres pg_resetxlog /var/lib/postgresql/data。我收到的错误如下:

pg_resetxlog: lock file "postmaster.pid" exists
Is a server running?  If not, delete the lock file and try again.

我尝试了 3 件事:

  1. postmaster.pid 下列出的 PID 与我的 Postgres 进程匹配,并使用 kill <PID> 手动终止 Postgres。这对关闭 Postgres 没有任何作用。

  2. 删除位于/var/lib/postgresql/data 下的postmaster.pid。这迫使容器重新启动,但同样的问题仍然存在。

  3. 我运行docker restart <POSTGRES> 重新启动postgres。

以上都没有任何帮助。我想要做的基本上是让这个容器恢复而不完全破坏它并迫使它重新开始。我正在使用Postgres:9.5 docker。

有什么想法吗?


编辑:添加容器日志

Sep 11 18:23:34 VM postgres-container[1045]: LOG:  incomplete startup packet
Sep 11 18:24:36 VM postgres-container[1045]: LOG:  incomplete startup packet
Sep 11 18:24:46 VM postgres-container[1045]: LOG:  received smart shutdown request
Sep 11 18:24:46 VM postgres-container[1045]: LOG:  autovacuum launcher shutting down
Sep 11 18:24:58 VM postgres-container[1045]: FATAL:  the database system is shutting down
Sep 11 18:25:01 VM postgres-container[1045]: FATAL:  the database system is shutting down
Sep 11 18:25:39 VM postgres-container[1045]: LOG:  incomplete startup packet
Sep 11 18:25:39 VM postgres-container[1045]: FATAL:  the database system is shutting down
Sep 11 18:25:59 VM postgres-container[1045]: FATAL:  the database system is shutting down
Sep 11 18:26:02 VM postgres-container[1045]: FATAL:  the database system is shutting down
Sep 11 18:26:40 VM postgres-container[1045]: LOG:  incomplete startup packet
Sep 11 18:26:40 VM postgres-container[1045]: FATAL:  the database system is shutting down
Sep 11 18:27:00 VM postgres-container[1045]: FATAL:  the database system is shutting down
Sep 11 18:27:03 VM postgres-container[1045]: FATAL:  the database system is shutting down
Sep 11 18:27:41 VM postgres-container[1045]: LOG:  incomplete startup packet
Sep 11 18:27:41 VM postgres-container[1045]: FATAL:  the database system is shutting down
Sep 11 18:28:01 VM postgres-container[1045]: FATAL:  the database system is shutting down
Sep 11 18:28:04 VM postgres-container[1045]: FATAL:  the database system is shutting down
Sep 11 18:28:41 VM postgres-container[1045]: LOG:  could not open file "postmaster.pid": No such file or directory
Sep 11 18:28:41 VM postgres-container[1045]: LOG:  performing immediate shutdown because data directory lock file is invalid
Sep 11 18:28:41 VM postgres-container[1045]: LOG:  received immediate shutdown request
Sep 11 18:28:41 VM postgres-container[1045]: WARNING:  terminating connection because of crash of another server process
Sep 11 18:28:41 VM postgres-container[1045]: DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
Sep 11 18:28:41 VM postgres-container[1045]: HINT:  In a moment you should be able to reconnect to the database and repeat your command.
Sep 11 18:28:41 VM postgres-container[1045]: LOG:  incomplete startup packet
Sep 11 18:28:43 VM postgres-container[1045]: LOG:  database system was interrupted; last known up at 2019-09-12 01:24:31 UTC
Sep 11 18:28:56 VM postgres-container[1045]: LOG:  database system was not properly shut down; automatic recovery in progress
Sep 11 18:28:56 VM postgres-container[1045]: LOG:  redo starts at 0/1C384970
Sep 11 18:28:56 VM postgres-container[1045]: LOG:  invalid record length at 0/1C44DAC8
Sep 11 18:28:56 VM postgres-container[1045]: LOG:  redo done at 0/1C44DAA0
Sep 11 18:28:56 VM postgres-container[1045]: LOG:  last completed transaction was at log time 2019-09-12 01:24:42.2848+00
Sep 11 18:28:57 VM postgres-container[1045]: LOG:  MultiXact member wraparound protections are now enabled
Sep 11 18:28:57 VM postgres-container[1045]: LOG:  database system is ready to accept connections
Sep 11 18:28:57 VM postgres-container[1045]: LOG:  autovacuum launcher started
Sep 11 18:29:42 VM postgres-container[1045]: LOG:  incomplete startup packet
Sep 11 18:30:45 VM postgres-container[1045]: LOG:  incomplete startup packet
Sep 11 18:31:47 VM postgres-container[1045]: LOG:  incomplete startup packet

【问题讨论】:

  • 请检查日志并将错误写在这里
  • 警告:pg_resetxlog 会损坏您的数据库。
  • @Laurenz Albe 我知道,这个post 建议你可以使用pg_dumpall 来恢复状态。
  • @Adiii 我试过了,但它不起作用。主要是我在 docker 容器中运行它,而 brew 服务并不是促进 Postgres 进程的原因。我尝试重新启动 docker 容器,但什么也没发生。

标签: postgresql docker


【解决方案1】:

五月的好消息!!!服务器已启动并正在运行:)

你可以连接到容器,使用

docker exec -ti postgres /bin/bash 

你应该是root用户,切换到postgres

su postgres

然后开始

psql

并检查数据是否存在于服务器中

【讨论】:

  • 服务器中不存在数据,我已确认。连接到此 Postgres 容器的客户端也失败了,原因是数据库状态不佳。
  • 在这里复制客户端得到的错误,以及他是如何尝试连接的。也试试我写的步骤
猜你喜欢
  • 2021-06-02
  • 2023-03-12
  • 1970-01-01
  • 1970-01-01
  • 2022-07-29
  • 2016-03-23
  • 1970-01-01
  • 2021-05-31
  • 1970-01-01
相关资源
最近更新 更多