postgresql - docker SHM_SIZE/dev/shm : resizing shared memory

标签 postgresql docker docker-compose

我想将 postgres 容器的共享内存从默认的 64M 调整大小。所以我补充说:

build:
      context: .
      shm_size: '2gb'

我正在使用 3.6 版的撰写文件,postgres 服务定义。

version: "3.6"

services:

 #other services go here..
 postgres:
    restart: always
    image: postgres:10
    hostname: postgres
    container_name: fiware-postgres
    expose:
      - "5432"
    ports:
      - "5432:5432"
    networks:
      - default
    environment:
      - "POSTGRES_PASSWORD=password"
      - "POSTGRES_USER=postgres"
      - "POSTGRES_DB=postgres"
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
    build:
      context: .
      shm_size: '2gb'

但是,即使我重新启动服务 docker-compose down 然后 up,此更改也不会生效。因此,当我开始与 postgres 交互以在仪表板上显示一些数据时,我立即遇到了共享内存问题。

在使用仪表板之前:

$docker exec -it fiware-postgres df -h
Filesystem                                                                                        Size  Used Avail Use% Mounted on
/dev/mapper/docker-253:1-107615-1541c55e4c3d5e03a7716d5418eea4c520b6556a6fd179c6ab769afd0ce64d9f   10G  266M  9.8G   3% /
tmpfs                                                                                              64M     0   64M   0% /dev
tmpfs                                                                                             1.4G     0  1.4G   0% /sys/fs/cgroup
/dev/vda1                                                                                         197G   52G  136G  28% /etc/hosts
shm                                                                                                64M  8.0K   64M   1% /dev/shm
tmpfs                                                                                             1.4G     0  1.4G   0% /proc/acpi
tmpfs                                                                                             1.4G     0  1.4G   0% /proc/scsi
tmpfs                                                                                             1.4G     0  1.4G   0% /sys/firmware

午餐后仪表板:

$docker exec -it fiware-postgres df -h
Filesystem                                                                                        Size  Used Avail Use% Mounted on
/dev/mapper/docker-253:1-107615-1541c55e4c3d5e03a7716d5418eea4c520b6556a6fd179c6ab769afd0ce64d9f   10G  266M  9.8G   3% /
tmpfs                                                                                              64M     0   64M   0% /dev
tmpfs                                                                                             1.4G     0  1.4G   0% /sys/fs/cgroup
/dev/vda1                                                                                         197G   52G  136G  28% /etc/hosts
shm                                                                                                64M   50M   15M  78% /dev/shm
tmpfs                                                                                             1.4G     0  1.4G   0% /proc/acpi
tmpfs                                                                                             1.4G     0  1.4G   0% /proc/scsi
tmpfs                                                                                             1.4G     0  1.4G   0% /sys/firmware

postgres 错误日志:

2019-07-01 17:27:58.802 UTC [47] ERROR:  could not resize shared memory segment "/PostgreSQL.1145887853" to 12615680 bytes: No space left on device

这是怎么回事?

最佳答案

你在build中设置了shm_size,这只会影响build,你需要在service level中设置它,如下:

docker-compose.yaml:

version: "3.6"

services:

 #other services go here..
 postgres:
    restart: always
    image: postgres:10
    hostname: postgres
    container_name: fiware-postgres
    expose:
      - "5432"
    ports:
      - "5432:5432"
    networks:
      - default
    environment:
      - "POSTGRES_PASSWORD=password"
      - "POSTGRES_USER=postgres"
      - "POSTGRES_DB=postgres"
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
    build:
      context: .
      shm_size: 256mb
    shm_size: 512mb

Docker 文件:

FROM postgres:10

RUN df -h | grep shm

然后,docker-compose up -d --build 启动它并检查:

shubuntu1@shubuntu1:~/66$ docker-compose --version
docker-compose version 1.24.0, build 0aa59064
shubuntu1@shubuntu1:~/66$ docker-compose up -d --build
Building postgres
Step 1/2 : FROM postgres:10
 ---> 0959974989f8
Step 2/2 : RUN df -h | grep shm
 ---> Running in 25d341cfde9c
shm             256M     0  256M   0% /dev/shm
Removing intermediate container 25d341cfde9c
 ---> 1637f1afcb81

Successfully built 1637f1afcb81
Successfully tagged postgres:10
Recreating fiware-postgres ... done
shubuntu1@shubuntu1:~/66$ docker exec -it fiware-postgres df -h | grep shm
shm             512M  8.0K  512M   1% /dev/shm

您可以看到在构建时它显示 256m,但在运行时容器它显示 512m

关于postgresql - docker SHM_SIZE/dev/shm : resizing shared memory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56839975/

相关文章:

mysql - 数据未添加到 MySQL 服务

python - Dockerfile指定API的路径

postgresql - WHERE子句中的函数返回表,如何使用查询结果作为参数?

php - SQL 命令的类型强制转换警告

sql - 如何获取 PostgreSQL 中两个日期之间的完整日历月份

linux - Sqlite DB 锁定在 Azure Dotnet Core Entity Framework 上

elasticsearch - docker elasticsearch容器不转发端口(macOs)

sql - Explain Analyze 上嵌套反循环的成本

macos - Docker错误拨号unix/var/run/docker.sock : no such file or directory

docker - 在 docker 中调试 spring-boot 应用程序不起作用