pq:无法调整共享内存段的大小。设备上没有剩余空间
Posted
技术标签:
【中文标题】pq:无法调整共享内存段的大小。设备上没有剩余空间【英文标题】:pq: could not resize shared memory segment. No space left on device 【发布时间】:2019-11-07 03:29:49 【问题描述】:我在仪表板上有一些面板(大约 6 个)来显示数据点图表,这些图表对 PostgreSQL 数据库的 dockerised 实例进行查询。
面板直到最近都正常工作,有些停止工作并报告如下错误:
pq:无法将共享内存段“/PostgreSQL.2058389254”的大小调整为 12615680 字节:设备上没有剩余空间
知道为什么吗?如何解决这个问题。 Docker 容器在通过ssh
访问的远程主机上运行。
编辑
磁盘空间:
$df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 197G 140G 48G 75% /
devtmpfs 1.4G 0 1.4G 0% /dev
tmpfs 1.4G 4.0K 1.4G 1% /dev/shm
tmpfs 1.4G 138M 1.3G 10% /run
tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup
/dev/dm-16 10G 49M 10G 1% /var/lib/docker/devicemapper/mnt/a0f3c5ab84aa06d5b2db00c4324dd6bf7141500ff4c83e23e9aba7c7268bcad4
/dev/dm-1 10G 526M 9.5G 6% /var/lib/docker/devicemapper/mnt/8623a774d736ed3dc0d2db89b7d07cae85c3d1bcafc245180eec4ffd738f93a5
shm 64M 0 64M 0% /var/lib/docker/containers/260552ebcdf2bf0961329108d3d975110f8ada0a41325f5e7dd81b8ddad9d18b/mounts/shm
/dev/dm-4 10G 266M 9.8G 3% /var/lib/docker/devicemapper/mnt/6f873e62607e7cac4c4b658c72874c787b90290f74d1159eca81af61cb467cfb
shm 64M 50M 15M 78% /var/lib/docker/containers/84c66d9fb5b6ae023d051766f4d35ced87a519a1fee68ca5c89d61ff87cf1e5a/mounts/shm
/dev/dm-2 10G 383M 9.7G 4% /var/lib/docker/devicemapper/mnt/cb3df1ae654ed78802c2e5bd7a51a1b0bdd562855a7c7803750b80b33f5c206e
shm 64M 0 64M 0% /var/lib/docker/containers/22ba2ae2b6859c24623703dcb596527d64257d2d61de53f4d88e00a8e2335211/mounts/shm
/dev/dm-3 10G 99M 9.9G 1% /var/lib/docker/devicemapper/mnt/492a19fc8f3e254c4e5cc691c3300b5fee9d1a849422673bf0c19b4b2d1db571
shm 64M 0 64M 0% /var/lib/docker/containers/39abe855a9b107d4921807332309517697f024b2d169ebc5f409436208f766d0/mounts/shm
/dev/dm-7 10G 276M 9.8G 3% /var/lib/docker/devicemapper/mnt/55c6a6c17c892d149c1cc91fbf42b98f1340ffa30a1da508e3526af7060f3ce2
shm 64M 0 64M 0% /var/lib/docker/containers/bf2e7254cd7e2c6000da61875343580ec6ff5cbf40c017a398ba7479af5720ec/mounts/shm
/dev/dm-8 10G 803M 9.3G 8% /var/lib/docker/devicemapper/mnt/4e51f48d630041316edd925f1e20d3d575fce4bf19ef39a62756b768460d1a3a
shm 64M 0 64M 0% /var/lib/docker/containers/72d4ae743de490ed580ec9265ddf8e6b90e3a9d2c69bd74050e744c8e262b342/mounts/shm
/dev/dm-6 10G 10G 20K 100% /var/lib/docker/devicemapper/mnt/3dcddaee736017082fedb0996e42b4c7b00fe7b850d9a12c81ef1399fa00dfa5
shm 64M 0 64M 0% /var/lib/docker/containers/9f2bf4e2736d5128d6c240bb10da977183676c081ee07789bee60d978222b938/mounts/shm
/dev/dm-5 10G 325M 9.7G 4% /var/lib/docker/devicemapper/mnt/65a2bf48cbbfe42f0c235493981e62b90363b4be0a2f3aa0530bbc0b5b29dbe3
shm 64M 0 64M 0% /var/lib/docker/containers/e53d5ababfdefc5c8faf65a4b2d635e2543b5a807b65a4f3cd8553b4d7ef2d06/mounts/shm
/dev/dm-9 10G 1.2G 8.9G 12% /var/lib/docker/devicemapper/mnt/3216c48346c3702a5cd2f62a4737cc39666983b8079b481ab714cdb488400b08
shm 64M 0 64M 0% /var/lib/docker/containers/5cd0774a742f54c7c4fe3d4c1307fc93c3c097a861cde5f611a0fa9b454af3dd/mounts/shm
/dev/dm-10 10G 146M 9.9G 2% /var/lib/docker/devicemapper/mnt/6a98acd1428ae670e8f1da62cb8973653c8b11d1c98a8bf8be78f59d2ddba062
shm 64M 0 64M 0% /var/lib/docker/containers/a878042353f6a605167e7f9496683701fd2889f62ba1d6c0dc39c58bc03a8209/mounts/shm
tmpfs 285M 0 285M 0% /run/user/0
EDIT-2
$df -ih
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/vda1 13M 101K 13M 1% /
devtmpfs 354K 394 353K 1% /dev
tmpfs 356K 2 356K 1% /dev/shm
tmpfs 356K 693 356K 1% /run
tmpfs 356K 16 356K 1% /sys/fs/cgroup
/dev/dm-16 10M 2.3K 10M 1% /var/lib/docker/devicemapper/mnt/a0f3c5ab84aa06d5b2db00c4324dd6bf7141500ff4c83e23e9aba7c7268bcad4
/dev/dm-1 10M 19K 10M 1% /var/lib/docker/devicemapper/mnt/8623a774d736ed3dc0d2db89b7d07cae85c3d1bcafc245180eec4ffd738f93a5
shm 356K 1 356K 1% /var/lib/docker/containers/260552ebcdf2bf0961329108d3d975110f8ada0a41325f5e7dd81b8ddad9d18b/mounts/shm
/dev/dm-4 10M 11K 10M 1% /var/lib/docker/devicemapper/mnt/6f873e62607e7cac4c4b658c72874c787b90290f74d1159eca81af61cb467cfb
shm 356K 2 356K 1% /var/lib/docker/containers/84c66d9fb5b6ae023d051766f4d35ced87a519a1fee68ca5c89d61ff87cf1e5a/mounts/shm
/dev/dm-2 10M 5.6K 10M 1% /var/lib/docker/devicemapper/mnt/cb3df1ae654ed78802c2e5bd7a51a1b0bdd562855a7c7803750b80b33f5c206e
shm 356K 1 356K 1% /var/lib/docker/containers/22ba2ae2b6859c24623703dcb596527d64257d2d61de53f4d88e00a8e2335211/mounts/shm
/dev/dm-3 10M 4.6K 10M 1% /var/lib/docker/devicemapper/mnt/492a19fc8f3e254c4e5cc691c3300b5fee9d1a849422673bf0c19b4b2d1db571
shm 356K 1 356K 1% /var/lib/docker/containers/39abe855a9b107d4921807332309517697f024b2d169ebc5f409436208f766d0/mounts/shm
/dev/dm-7 10M 7.5K 10M 1% /var/lib/docker/devicemapper/mnt/55c6a6c17c892d149c1cc91fbf42b98f1340ffa30a1da508e3526af7060f3ce2
shm 356K 1 356K 1% /var/lib/docker/containers/bf2e7254cd7e2c6000da61875343580ec6ff5cbf40c017a398ba7479af5720ec/mounts/shm
/dev/dm-8 10M 12K 10M 1% /var/lib/docker/devicemapper/mnt/4e51f48d630041316edd925f1e20d3d575fce4bf19ef39a62756b768460d1a3a
shm 356K 1 356K 1% /var/lib/docker/containers/72d4ae743de490ed580ec9265ddf8e6b90e3a9d2c69bd74050e744c8e262b342/mounts/shm
/dev/dm-6 7.9K 7.3K 623 93% /var/lib/docker/devicemapper/mnt/3dcddaee736017082fedb0996e42b4c7b00fe7b850d9a12c81ef1399fa00dfa5
shm 356K 1 356K 1% /var/lib/docker/containers/9f2bf4e2736d5128d6c240bb10da977183676c081ee07789bee60d978222b938/mounts/shm
/dev/dm-5 10M 27K 10M 1% /var/lib/docker/devicemapper/mnt/65a2bf48cbbfe42f0c235493981e62b90363b4be0a2f3aa0530bbc0b5b29dbe3
shm 356K 1 356K 1% /var/lib/docker/containers/e53d5ababfdefc5c8faf65a4b2d635e2543b5a807b65a4f3cd8553b4d7ef2d06/mounts/shm
/dev/dm-9 10M 53K 10M 1% /var/lib/docker/devicemapper/mnt/3216c48346c3702a5cd2f62a4737cc39666983b8079b481ab714cdb488400b08
shm 356K 1 356K 1% /var/lib/docker/containers/5cd0774a742f54c7c4fe3d4c1307fc93c3c097a861cde5f611a0fa9b454af3dd/mounts/shm
/dev/dm-10 10M 5.2K 10M 1% /var/lib/docker/devicemapper/mnt/6a98acd1428ae670e8f1da62cb8973653c8b11d1c98a8bf8be78f59d2ddba062
shm 356K 1 356K 1% /var/lib/docker/containers/a878042353f6a605167e7f9496683701fd2889f62ba1d6c0dc39c58bc03a8209/mounts/shm
tmpfs 356K 1 356K 1% /run/user/0
EDIT-3
postgres
容器服务:
version: "3.5"
services:
#other containers 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: '4gb'
数据库大小:
postgres=# SELECT pg_size_pretty( pg_database_size('postgres'));
pg_size_pretty
----------------
42 GB
(1 row)
EDIT-4
抱歉,与此问题相关的解决方法均无效,包括this one
在仪表板上,我有 5 个面板用于显示数据点。这些查询是相似的,只是每个查询都为temperature
、relativeHumidity
、illuminance
、particles
和O3
显示不同的参数。这是查询:
SELECT to_timestamp(floor((extract('epoch' from recvtime)/ 1800 )) * 1800) as time,
avg(attrvalue::float) as illuminance
FROM urbansense.weather WHERE attrname='illuminance' AND attrvalue<>'null' GROUP BY time ORDER BY time asc;
区别在于WHERE attrname=#parameterValue
语句。我修改了postgresql.conf
文件以写入日志,但日志似乎没有提供有用的提示:日志如下:
$ vim postgres-data/log/postgresql-2019-06-26_150012.log
.
.
2019-06-26 15:03:39.298 UTC [45] LOG: statement: SELECT to_timestamp(floor((extract('epoch' from recvtime)/ 1800 )) * 1800) as time,
avg(attrvalue::float) as o3
FROM urbansense.airquality WHERE attrname='O3' AND attrvalue<>'null' GROUP BY time ORDER BY time asc;
2019-06-26 15:03:40.903 UTC [41] ERROR: could not resize shared memory segment "/PostgreSQL.1197429420" to 12615680 bytes: No space left on device
2019-06-26 15:03:40.903 UTC [41] STATEMENT: SELECT to_timestamp(floor((extract('epoch' from recvtime)/ 1800 )) * 1800) as time,
avg(attrvalue::float) as illuminance
FROM urbansense.weather WHERE attrname='illuminance' AND attrvalue<>'null' GROUP BY time ORDER BY time asc;
2019-06-26 15:03:40.905 UTC [42] FATAL: terminating connection due to administrator command
2019-06-26 15:03:40.905 UTC [42] STATEMENT: SELECT to_timestamp(floor((extract('epoch' from recvtime)/ 1800 )) * 1800) as time,
avg(attrvalue::float) as illuminance
FROM urbansense.weather WHERE attrname='illuminance' AND attrvalue<>'null' GROUP BY time ORDER BY time asc;
2019-06-26 15:03:40.909 UTC [43] FATAL: terminating connection due to administrator command
2019-06-26 15:03:40.909 UTC [43] STATEMENT: SELECT to_timestamp(floor((extract('epoch' from recvtime)/ 1800 )) * 1800) as time,
avg(attrvalue::float) as illuminance
FROM urbansense.weather WHERE attrname='illuminance' AND attrvalue<>'null' GROUP BY time ORDER BY time asc;
2019-06-26 15:03:40.921 UTC [1] LOG: worker process: parallel worker for PID 41 (PID 42) exited with exit code 1
2019-06-26 15:03:40.922 UTC [1] LOG: worker process: parallel worker for PID 41 (PID 43) exited with exit code 1
2019-06-26 15:07:04.058 UTC [39] LOG: temporary file: path "base/pgsql_tmp/pgsql_tmp39.0", size 83402752
2019-06-26 15:07:04.058 UTC [39] STATEMENT: SELECT to_timestamp(floor((extract('epoch' from recvtime)/ 1800 )) * 1800)as time,
avg(attrvalue::float) as relativeHumidity
FROM urbansense.weather WHERE attrname='relativeHumidity' AND attrvalue<>'null' GROUP BY time ORDER BY time asc;
2019-06-26 15:07:04.076 UTC [40] LOG: temporary file: path "base/pgsql_tmp/pgsql_tmp40.0", size 83681280
2019-06-26 15:07:04.076 UTC [40] STATEMENT: SELECT to_timestamp(floor((extract('epoch' from recvtime)/ 1800 )) * 1800)as time,
avg(attrvalue::float) as relativeHumidity
FROM urbansense.weather WHERE attrname='relativeHumidity' AND attrvalue<>'null' GROUP BY time ORDER BY time asc;
2019-06-26 15:07:04.196 UTC [38] LOG: temporary file: path "base/pgsql_tmp/pgsql_tmp38.0", size 84140032
有人知道如何解决这个问题吗?
【问题讨论】:
你检查过硬盘吗?你真的有空闲空间吗? @MostafaHussein 是的,我有足够的磁盘空间(大约 50GB 可用),可以在问题编辑中看到。 您需要检查您的 postgresql 配置中的共享内存设置以及您的 docker / 主机设置强加的任何共享内存限制。 你能检查inode消耗吗df -ih
@mchawre 我检查了这个问题edit-2。
【参考方案1】:
在增加 shm_size: 后没有帮助我,我转向 db optimization 并发现添加一些缺少的索引在我的特定情况下解决了这个错误。
具体来说,我有几个视图在没有索引的字段上使用连接,一旦数据库达到典型大小(连接的“多”端中的 1M 行),这些错误就开始了。
【讨论】:
【参考方案2】:抱歉回复晚了。没有必要建立新的形象。但是您必须确保容器已重新创建,并且您没有使用旧容器。
必须更改 Docker-compose 文件,在服务级别添加 shm_size
。不需要构建部分。
version: "3.5"
services:
#other containers go here..
postgres:
restart: always
image: postgres:10
#THIS MUST BE ADDED AT SERVICE LEVEL
shm_size: 1gb
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
那么你必须完全重新创建容器
docker-compose rm postgres
# alternatively you can docker-compose down to destroy all containers
docker-compose up -d
销毁旧容器并创建一个新容器。
您可以检查容器内的更改(输入docker-compose exec postgres bash
)并运行df -h | grep shm
参考:docker SHM_SIZE /dev/shm: resizing shared memory
【讨论】:
优秀。除了docker-compose down
,您还可以使用docker-compose rm postgres
来删除预先存在的Postgres 容器。
@Javier Dottori,解决方案没问题,但是 check shm 命令不行。应该是docker exec postgres df -h |grep shm
或docker exec -it postgres bash
,终端连接后,运行df -h |grep shm
。
您好安德烈,感谢您的建议。无论如何,如果容器是用docker-compose
创建的,最好使用它的包装器,这样您就不需要为其指定名称。如果您使用命名容器,则需要小心,以免多个 docker-compose 文件在您的所有机器上共享名称。 docker-compose exec
主要是docker exec -ti
的包装,如果你想使用docker
native 命令,你应该使用container_name
即fiware-postgres
(我保留它,因为它在原始问题中)跨度>
【参考方案3】:
您可以通过重新安装它来增加 shm 大小,而无需重新启动/重建容器
mount -o remount,size=256m -t tmpfs /var/lib/docker/containers/your-container-id/mounts/shm
更改您的容器 ID 和所需大小 (256m)
【讨论】:
效果不错!正在检查一个长时间运行的进程,我不想中断并用完共享内存。试一试,它奏效了。 在docker-compose.yml中加入shm_size: 256m
会更好。有时在重新启动容器后,我需要再次重新安装它。不知道为什么,但它发生了
但是我的任务还是崩溃了。目前这是一个快速的解决方案。【参考方案4】:
你需要构建一个增加 shm_size 的新镜像
Dockerfile
FROM postgres:10.7
docker-compose.release.yml
version: '3.7'
services:
postgres:
image: registry.my-site.com/postgres:latest
build:
shm_size: '4gb'
运行
docker-compose -f docker-compose.release.yml build
然后你可以使用你的镜像registry.my-site.com/postgres:latest
来部署容器,增加shm_size
【讨论】:
不需要构建自定义镜像,因为它是容器创建期间的设置 (docker run --rm -it --shm-size 2gb....
)。【参考方案5】:
这是因为 docker by-default 将共享内存的大小限制为 64MB
。
您可以使用docker run
中的--shm-size
选项覆盖此默认值。
docker run -itd --shm-size=1g postgres
或在 docker-compose 中:
db:
image: "postgres:11.3-alpine"
shm_size: 1g
检查this。更多信息here.
希望这会有所帮助。
【讨论】:
修改了撰写文件添加shm_size: '4gb'
但是,这并不能解决问题(问题编辑3)。这与容器容量或 docker 工作内存有关吗?因为在edit-3上可以看到我的数据库大小超过40GB。
但是在这个改变之后你得到了同样的pq: could not resize shared memory segment
错误吗?
是的,我还是明白了。甚至设置shm_size: '50gb'
没有变化,最近的:pq: could not resize shared memory segment "/PostgreSQL.1336373456" to 12615680 bytes: No space left on device
你有没有经历过这个类似的问题***.com/questions/55803015/…如果可能的话试试上面提到的解决方案。
@machawre 非常感谢,这真的很有帮助以上是关于pq:无法调整共享内存段的大小。设备上没有剩余空间的主要内容,如果未能解决你的问题,请参考以下文章
Gitlab runner:无法在 Ubuntu 上回收 Docker 空间 - 设备上没有剩余空间
错误:由于环境错误而无法安装软件包:[Errno 28] 设备上没有剩余空间
错误:无法写入临时文件的块 37583345:设备上没有剩余空间
如何解决postgresql中的“无法写入临时文件块:设备上没有剩余空间”?