Postgres容器启动失败,出现initdb错误。popen失败:无法分配内存。

huangapple go评论143阅读模式
英文:

Postgres container failed to start with initdb error. popen failure: Cannot allocate memory

问题

我在AWS实例上使用了postgres:12 Docker镜像,操作系统是Ubuntu 20.04。

当我使用以下命令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.

这个错误突然出现在最近的项目部署后。重要的是,这个错误只发生在特定的容器中。在同一台机器上还有一个用于另一个项目的postgresql:12容器,它运行正常。

我尝试过以下方法:

  1. 我发现了一些关于增加控制机器上共享内存的shmall/shmmax参数的建议。

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

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. 第二个建议是尝试使用更新的postgres镜像。我尝试了postgres 13.0和14.0,但没有效果。
    更新
    尝试使用postgres:11镜像,它可以正常运行,但我无法在生产环境中降级postgres版本,所以这对我来说不是解决方案。

  2. 我尝试了停止/启动和重启实例,还使用了docker system prunedocker volumes prune清理了Docker缓存。

软件信息:

  • Ubuntu 20.04.2
  • Docker版本 20.10.8,构建版本 3967b7d

实例硬件信息:

  • Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz
  • RAM: 4/8GB 被系统和其他服务使用
  • 交换空间: 4.5/20GB 被系统和其他服务使用
英文:

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

  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:

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.

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

答案1

得分: 4

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

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

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:

  • 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:

  • postgres:12-bullseye

The maintainers will keep providing bullseye variants until the Postgres version is EOL or Debian moves to their latest 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
英文:

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

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

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:

  • 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:

  • postgres:12-bullseye

The maintainers will keep providing bullseye variants until the Postgres version is EOL or Debian moves to their latest 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

答案2

得分: 1

看起来是Docker 5:20.10.8~3-0~ubuntu-focal和官方postgres:12镜像的最近更新之间存在某种版本不兼容性。

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

英文:

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.

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

答案3

得分: 0

在CircleCI中,将机器从
image: ubuntu-2004:202010-01
升级到
image: ubuntu-2004:2023.07.1
允许我使用最新的Bookworm PostgreSQL镜像。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月26日 17:20:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76555305.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定