gpt4 book ai didi

Postgres container failed to start with initdb error. popen failure: Cannot allocate memory(Postgres容器启动失败,出现initdb错误。Popen失败:无法分配内存)

转载 作者:bug小助手 更新时间:2023-10-24 21:53:52 78 4
gpt4 key购买 nike



I'm using postgres:12 Docker image on AWS instance under Ubuntu 20.04.

我在Ubuntu 20.04下的AWS实例上使用postgres:12 Docker镜像。


  postgres-tests:
image: "postgres:12"
restart: always
command: postgres -c 'max_connections=200'
environment:
POSTGRES_DB: "${POSTGRES_DATABASE}"
POSTGRES_USER: "${POSTGRES_USER}"
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
ports:
- "8396:5432"


When running this container with docker-compose up -d it fails to start with the following error:

使用docker-compose up-d运行此容器时,它无法启动,并显示以下错误:


postgres-tests_1  | popen failure: Cannot allocate memory
postgres-tests_1 | initdb: error: The program "postgres" is needed by initdb but was not found in the
postgres-tests_1 | same directory as "/usr/lib/postgresql/12/bin/initdb".
postgres-tests_1 | Check your installation.


The error appeared suddenly after most-resent project deploy. The important thing is that the error happens only with this particular container. There is one more postgresql:12 container on the machine for another project, which works fine.

在最新的项目部署后,错误突然出现。重要的是,错误只发生在这个特定的容器中。机器上还有一个用于另一个项目的PostgreSQL:12容器,运行良好。


HERE IS WHAT I TRIED:

以下是我尝试过的:



  1. I've found several suggestions related to increasing the shmall/shmmax params controlling shared memory on the machine.


But these system params are already set to high value:

但这些系统参数已设置为高值:


ubuntu@ip-172-31-10-246:/var/www$ cat /proc/sys/kernel/shmall
18446744073692774399
ubuntu@ip-172-31-10-246:/var/www$ cat /proc/sys/kernel/shmmax
18446744073692774399
ubuntu@ip-172-31-10-246:/var/www$



  1. The second suggested option was to try a newer postgres image. Tested with postgres 13.0, 14.0 with no effect.
    UPDATE
    Tried with postgres:11 image and it runs OK, but I can not roll down postgres version in production, so it's not a solution in my case.



  2. I tried to stop/start and reboot the instance, also cleaning up docker cache with docker system prune and docker volumes prune.




Software:
Ubuntu 20.04.2
Docker version 20.10.8, build 3967b7d

Instance hardware:
Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz
RAM: 4/8GB Used by system and other services
Swap: 4.5/20GB Used by system and other services

更多回答
优秀答案推荐

Maintainers of the postgres docker images have updated the underlying OS image layer:

Postgres坞站映像的维护人员已经更新了底层操作系统映像层:


Previous: Debian 11 (bullseye)
New: Debian 12 (bookworm)

前作:Debian 11(牛眼)新:Debian 12(书呆子)


This was pushed up to hub.docker.com on 15 Jun 2023.
The move to this container is causing a lot of builds to throw errors and exceptions like the one noted in the question:

2023年6月15日,这篇文章被推到了hub.docker.com上。迁移到此容器会导致许多构建抛出错误和异常,如问题中所示:



  • initdb: error: The program "postgres" is needed by initdb but was not found in the same directory as "/usr/lib/postgresql/12/bin/initdb".


The mitigation route is to use the following conatiner:

缓解途径是使用以下Conatiner:



  • postgres:12-bullseye


The maintainers will keep providing bullseye variants until the Postgres version is EOL or Debian moves to their latest Trixie

在Postgres版本停产或Debian升级到他们最新的Trixie之前,维护人员将继续提供靶眼版本


Issues can be found here:

可以在以下位置找到问题:



  1. Postgres:12 container is not starting anymore #1103

  2. Postgres container failing with initdb error: program “postgres” is needed by initdb but was not found



Looks like it was some kind of version incompatibility between Docker 5:20.10.8~3-0~ubuntu-focal and one of recent updates of the official postgres:12 image.

看起来这是Docker 5:20.10.8~3-0~ubuntu-ocus和官方postgres:12的最新更新之一之间的某种版本不兼容。


Updating Docker to 5:23.0.6-1~ubuntu.20.04~focal solved the issue.

将Docker更新到5:23.0.6-1~ubuntu.20.04~ocus解决了这个问题。



In Circleci, upgrading the machine from

image: ubuntu-2004:202010-01
to
image: ubuntu-2004:2023.07.1 allowed me to use the latest bookworm postgres images.

在Circleci中,将机器从映像:ubuntu-2004:202010-01升级到映像:ubuntu-2004:2023.07.1允许我使用最新的书呆子postgres映像。


更多回答

78 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com