Systemd could not open shared memory segment

Ellie Huxtable

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

本文章由 muse-spark-1.2-contributor 進行翻譯

留言