Systemd 无法打开共享内存段
原文由 Ellie Huxtable 于 发布,订阅该博客
我曾在 EC2 实例上运维 PostgreSQL 一段时间。我们遇到了一个奇怪的问题:有时查询会失败,报错如下
could not open shared memory segment "/PostgreSQL.271741757".
对于非系统用户(UID < 1000),logind 默认会在用户注销时清除共享内存文件。对于数据库这类应用来说,这完全不是我们想要的行为。需要注意的是,如果你从未以数据库用户的身份登录过,就不太可能遇到这个问题。
在 /etc/systemd/logind.conf 中设置 RemoveIPC=no 应该就能解决这个问题。理论上,你可以在系统运行时重启 logind。我做了一些测试,但我觉得最稳妥的做法仍然是重启系统。
手册页
RemoveIPC=
Controls whether System V and POSIX IPC objects belonging to
the user shall be removed when the user fully logs out. Takes
a boolean argument. If enabled, the user may not consume IPC
resources after the last of the user's sessions terminated.
This covers System V semaphores, shared memory and message
queues, as well as POSIX shared memory and message queues.
Note that IPC objects of the root user and other system users
are excluded from the effect of this setting. Defaults to
"yes".修改后,完整重启可以确保配置生效。或者,重启 logind 应该也能解决此问题:systemctl restart systemd-logind.service
相关链接:
- https://github.com/systemd/systemd/issues/4532
- https://github.com/systemd/systemd/issues/2039
- https://stackoverflow.com/questions/49065733/redhat-or-centos7-systemd-may-remove-user-ipc-resources-unexpectedly
- https://stackoverflow.com/questions/73368759/why-systemd-remove-my-shm-file-but-not-postgresqls
随机一篇博客
评论
登录后参与讨论