无法使用损坏的Postgres运行pg_resetxlog

时间:2019-09-12 01:41:54

标签: postgresql docker

我在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.

我尝试了三件事:

  1. postmaster.pid下列出的PID与我的Postgres进程匹配,并使用kill <PID>手动杀死Postgres。这并没有关闭Postgres。

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

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

以上所有内容均无济于事。我想要做的基本上是为该容器提供一种恢复方式,而无需完全销毁它并强制其重新启动。我正在使用Postgres:9.5码头工人。

有什么想法吗?


编辑:添加容器日志

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

1 个答案:

答案 0 :(得分:0)

好消息,可能的状态!!!服务器已启动并正在运行:)

您可以连接到容器,使用

docker exec -ti postgres /bin/bash 

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

su postgres

然后开始

psql

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