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 모델을 사용해 번역했습니다.