6

Shared Memory files getting deleted some time (~15 hours) in Postgres 11

2019-07-09 08:46:41 CDT [] [6723]: [1-1] user=,db=,e=58P01 ERROR:  could not open shared memory segment "/PostgreSQL.291691635": No such file or directory
2019-07-09 08:46:41 CDT [] [6722]: [1-1] user=,db=,e=58P01 ERROR:  could not open shared memory segment "/PostgreSQL.291691635": No such file or directory
2019-07-09 08:46:41 CDT [10.40.0.204(60550)] [13880]: [1-1] user=user_name,db=db_name,e=58P01 ERROR:  could not open shared memory segment "/PostgreSQL.291691635": No such file or directory
2019-07-09 08:46:41 CDT [10.40.0.204(60550)] [13880]: [2-1] user=user_name,db=db_name,e=58P01 CONTEXT:  parallel worker
2019-07-09 08:46:41 CDT [10.40.0.204(60550)] [13880]: [3-1] user=user_name,db=db_name,e=58P01 STATEMENT:  WITH overall_reviewed AS (SQL Query)

GCP VM Config

CPU: 4
RAM: 16 GB
 OS: Ubuntu 18.04.1 LTS

kernel shared memory setting shared

kernel.shmmax=8589934592
kernel.shmall=2097152 

postgresql.config

max_connections = 500
shared_buffers = 4GB
effective_cache_size = 12GB
maintenance_work_mem = 1GB
checkpoint_completion_target = 0.7
wal_buffers = 16MB
default_statistics_target = 100
random_page_cost = 1.1
effective_io_concurrency = 200
work_mem = 4194kB
min_wal_size = 1GB
max_wal_size = 2GB
max_worker_processes = 4
max_parallel_workers_per_gather = 2
max_parallel_workers = 4

During startup: no errors/warnings After ~15 hours some of the shared memory files is getting deleted, I'm doubting is there any other process deleting files in "/dev/shm" ?

Not sure what is the root cause

3
  • Did you ever find the solution to this? I randomly run into this issue on my OpenBSD postgresql setup also. Every week or two it will randomly occur on one of the clients connected to the database. postgresql is still functional when this occurs, and just restarting the client is enough for things to resume working for another week or so.
    – n1000
    Sep 28, 2019 at 15:39
  • making dynamic_shared_memory_type = none in postgresql.conf did solve the issue.
    – Pruthviraj
    Sep 29, 2019 at 4:45
  • 1
    Any new solutions to this problem @n1000 ? It seems that "none" is no longer an option for dynamic_shared_memory_type.
    – chappjc
    Dec 3, 2020 at 14:30

4 Answers 4

3

making dynamic_shared_memory_type = none in postgresql.conf did solve the issue.

1
  • It works in postgres@10 but not at @12 anymore, I used mmap instead and now it's working Jan 13, 2022 at 11:57
3

Got the same problem on Ubuntu 18.04 and PostgreSQL 11 and after some more research i have found a solution for us. The error occured when the backup user, which ist he same user as the PG service user, logs into the system. The following Link describes that the storeage under /dev/shm where deleted when a user logs in to the system (same user). So our solution was to change the following:

/etc/systemd/logind.conf 

added the Line

RemoveIPC=no

and restart the service

systemctl restart systemd-logind.service

Sources:

https://www.postgresql-archive.org/systemd-deletes-shared-memory-segment-in-dev-shm-Postgresql-NNNNNN-td5883507.html

https://superuser.com/questions/1117764/why-are-the-contents-of-dev-shm-is-being-removed-automatically

1

We had the same issue and it turned out that someone set postgres user's UID bigger than 1000 (which means that postgres user was no longer a system account). And, as said here:

After hours of searching and reading, I found the culprit.
It's a setting for systemd. The /etc/systemd/logind.conf contains default configuration options, with each of them commented out.
The RemoveIPC option is set to yes by default. That option tells systemd to clean up interprocess communication (IPC) for "user accounts" who aren't logged in.

================================================
This does not affect "system accounts"
================================================

0

Met the same issue.....when I have opened two sqldeveloper with the same user account, one of them is my remote session which I completely forgot to close the session.

I was doing some aggregation operators like count(*) or max(...), and the error on both. And the error is similar:

ERROR: could not open shared memory segment "/PostgreSQL.798235387": No such file or directory Where: parallel worker

Solution? I killed the remote session.... XD And life is peaceful and happy again :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.