首页 > 解决方案 > Postgres 10.3 无法绑定 IPv6 地址,数据库系统未正确关闭

问题描述

我正在通过 Docker(特别是 docker-compose)运行 Postgres v10.3。它没有重新打开。当我尝试打开它时,我收到以下错误消息:

postgres           | pg_ctl: another server might be running; trying to start server anyway
postgres           | waiting for server to start....2018-05-15 12:37:07.552 UTC [22] LOG:  listening on IPv4 address "127.0.0.1", port 5432
postgres           | 2018-05-15 12:37:07.552 UTC [22] LOG:  could not bind IPv6 address "::1": Address not available
postgres           | 2018-05-15 12:37:07.552 UTC [22] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
postgres           | 2018-05-15 12:37:07.558 UTC [22] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres           | 2018-05-15 12:37:07.804 UTC [23] LOG:  database system was interrupted while in recovery at 2018-05-15 12:35:58 UTC
postgres           | 2018-05-15 12:37:07.804 UTC [23] HINT:  This probably means that some data is corrupted and you will have to use the last backup for recovery.
postgres           | .........2018-05-15 12:37:17.735 UTC [23] LOG:  database system was not properly shut down; automatic recovery in progress
postgres           | .2018-05-15 12:37:17.935 UTC [23] LOG:  redo starts at 1/5E964BA8
postgres           | pg_ctl: server did not start in time
postgres           | ................................................. stopped waiting

我可能在写入数据库时​​关闭了数据库,这是我能想到的唯一会导致这种情况的事情。我没有备份,这就是为什么我想恢复我已经完成的工作(除了我在关闭时写入的表)。

我尝试过的事情:

当运行single_user_mode更多日志时,我得到

/ $ postgres --single -D /var/lib/postgresql/data/pgdata -P -d 5
2018-05-15 15:16:09.978 UTC [12] DEBUG:  invoking IpcMemoryCreate(size=148537344)
2018-05-15 15:16:09.978 UTC [12] DEBUG:  mmap(148897792) with MAP_HUGETLB failed, huge pages disabled: Out of memory
2018-05-15 15:16:09.999 UTC [12] DEBUG:  SlruScanDirectory invoking callback on pg_notify/0000
2018-05-15 15:16:09.999 UTC [12] DEBUG:  removing file "pg_notify/0000"
2018-05-15 15:16:10.005 UTC [12] DEBUG:  dynamic shared memory system will support 288 segments
2018-05-15 15:16:10.005 UTC [12] DEBUG:  created dynamic shared memory control segment 262836907 (6928 bytes)
2018-05-15 15:16:10.005 UTC [12] DEBUG:  InitPostgres
2018-05-15 15:16:10.005 UTC [12] DEBUG:  my backend ID is 1
2018-05-15 15:16:10.010 UTC [12] LOG:  database system was shut down in recovery at 2018-05-15 15:16:04 UTC
2018-05-15 15:16:10.014 UTC [12] DEBUG:  checkpoint record is at 1/64CA6F18
2018-05-15 15:16:10.025 UTC [12] DEBUG:  redo record is at 1/5E964BA8; shutdown FALSE
2018-05-15 15:16:10.025 UTC [12] DEBUG:  next transaction ID: 0:681710; next OID: 311511
2018-05-15 15:16:10.025 UTC [12] DEBUG:  next MultiXactId: 155; next MultiXactOffset: 312
2018-05-15 15:16:10.025 UTC [12] DEBUG:  oldest unfrozen transaction ID: 547, in database 1
2018-05-15 15:16:10.025 UTC [12] DEBUG:  oldest MultiXactId: 1, in database 1
2018-05-15 15:16:10.025 UTC [12] DEBUG:  commit timestamp Xid oldest/newest: 0/0
2018-05-15 15:16:10.025 UTC [12] DEBUG:  transaction ID wrap limit is 2147484194, limited by database with OID 1
2018-05-15 15:16:10.025 UTC [12] DEBUG:  MultiXactId wrap limit is 2147483648, limited by database with OID 1
2018-05-15 15:16:10.025 UTC [12] DEBUG:  starting up replication slots
2018-05-15 15:16:10.028 UTC [12] DEBUG:  starting up replication origin progress state
2018-05-15 15:16:10.031 UTC [12] LOG:  database system was not properly shut down; automatic recovery in progress
2018-05-15 15:16:10.037 UTC [12] DEBUG:  resetting unlogged relations: cleanup 1 init 0
2018-05-15 15:16:10.334 UTC [12] LOG:  redo starts at 1/5E964BA8

我的 dockerfile 扩展了这个:https ://github.com/docker-library/postgres/blob/fe8c9a4a309a889dc057d53bf3769c25c1522c65/10/alpine/Dockerfile

入口点更改为:https ://github.com/docker-library/postgres/blob/fe8c9a4a309a889dc057d53bf3769c25c1522c65/10/alpine/docker-entrypoint.sh

这是ifconfig

MacBook-Pro:backend zebrainatree$ docker-compose demo run postgres ifconfig -a
eth0      Link encap:Ethernet  HWaddr 02:42:AC:12:00:03  
          inet addr:172.18.0.3  Bcast:172.18.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:90 (90.0 B)  TX bytes:0 (0.0 B)
ip6tnl0   Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          NOARP  MTU:1452  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
tunl0     Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-10-8B-00-00-00-00-00-00-00-00  
          NOARP  MTU:1480  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

标签: postgresqldockerdocker-compose

解决方案


我认为没有什么可担心的:

  • could not bind IPv6 address "::1": Address not available

    这意味着作为 的 IP 地址getaddrinfo返回,但 IPv6 不起作用。::1localhost

    您的 DNS 设置配置错误,但这不是什么大问题——您只是无法使用 IPv6 连接到环回接口。

  • waiting for server to start.....stopped waiting

    启动花费的时间比pg_ctl等待的时间长。烦人,但本身没有问题。看下一点。

    在这种情况下,您应该始终查阅 PostgreSQL 日志。

  • LOG:  database system was interrupted while in recovery at 2018-05-15 12:35:58 UTC  
    HINT:  This probably means that some data is corrupted and you will have to use the last backup for recovery.
    

    这只是意味着您不耐烦并打断了之前的启动尝试,不是吗?

    提示就在那里,因为如果在没有惊慌失措的系统管理员中断启动过程的情况下发生这种情况,则可能意味着恢复崩溃,可能是因为数据库文件中的数据不正确。

崩溃恢复的 15 分钟并不短。

也许自上次检查点以来有很多活动(并且max_wal_size设置得非常高),也许您的磁盘非常慢,也许您的限制性 cgroups 设置给您的资源太少......


推荐阅读