Systemd could not open shared memory segment

Ellie Huxtable

systemd 無法開啟共享記憶體區段

我花了一段時間在 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

原文由 Ellie Huxtable 發布

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