Systemd could not open shared memory segment

Ellie Huxtable

systemdが共有メモリセグメントを開けない

しばらくEC2インスタンス上でPostgreSQLを運用していました。時折クエリが失敗するという奇妙な問題が発生し、次のようなエラーが表示されていました。

could not open shared memory segment "/PostgreSQL.271741757".

システムユーザー以外(UID < 1000)のユーザーでは、logindはデフォルトでログアウト時に共有メモリファイルを削除します。データベースのような用途では、これはまったく望ましくありません。なお、データベースユーザーとして一度もログインしなければ、この問題が発生する可能性は低いことも付け加えておきます。

RemoveIPC=no/etc/systemd/logind.confに設定することで、この問題は解消されるはずです。理論上はシステムの稼働中にlogindを再起動することも可能です。いくつかテストは行いましたが、やはりシステムを再起動するのが最も安全だと思います。

manページ

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」を使用して翻訳されました。