Can't increase db_shared_buffers (0.1% of total ram) and db_work_mem (0.03% of total ram)

AI-generated summary

A user is experiencing a PG::DiskFull error on a new Discourse instance running on a 128GB RAM server, despite having ample free space. The issue occurs when trying to increase db_shared_buffers and db_work_mem beyond default values, with the error indicating “No space left on device” when resizing shared memory. The problem appears to stem from a hardcoded --shm-size=512m in the Discourse launcher, which limits available shared memory. The user initially tried increasing the shm_size in the launcher file as a workaround but later discovered that enabling memory overcommit (vm.overcommit_memory=1) and disabling transparent huge pages resolved the issue permanently. The problem may be related to differences between Ubuntu 22.04 and 24.04, Docker versions, or kernel configurations.

This is a bit of a head scratcher :upside_down_face:

Have a freshly migrated Discourse instance on a new server.

Getting the error in logs: PG::DiskFull (ERROR: could not resize shared memory segment "/PostgreSQL.1759815625" to 8388608 bytes: No space left on device )

It’s strange because, the previous server (64gb ram) didn’t have this issue and I had these set:

db_shared_buffers: "25632MB"
db_work_mem: "160MB"

On the new server (128gb ram), I can’t increase above the baseline defaults (I tried tripling the values below and get the same PG DiskFull error):

db_shared_buffers: "128MB"
db_work_mem: "40MB"

Previous machine has docker 27.x on it (auto installed via the discourse installer). New machine installed docker.io as per instructions (so 26.x). I tried switching to docker 27.x to see if that was related - but it didn’t change anything. Both are on the Stable Discourse branch, version 3.3.2.

It seems shm_size might be the main culprit:

Though no idea why it wasn’t an issue on the previous server and it is on the new server. The only other main difference is the old server uses Ubuntu 22.04 LTS and the new server is on 24.04 LTS.

I tried this also, but the changes get overwritten when the container is started again

shm_size appears to be hardcoded into the launcher:

Any insights or help would be appreciated! :meow_heart:

Refers to the hard drive space, not the ram.

Thanks @pfaffman - I thought that too initially, but then I read this thread:

There is a lot of free space also :confused:

So a quick duct tape fix is to simply edit the launcher file like:

cd /var/discourse
vi launcher

Then replace all 3 occurances of
--shm-size=512m
with the desired ram amount (I went with 50% of system ram).

Then rebuild. Will need to edit it again every time the launcher updates.

Seems to be doing the job for the time being.

water leaking fix with flex tape

So to follow up in case someone else faces this issue - the above solved this for me. I do not need to edit shm-size in the launcher anymore.

This was found after noticing this warning during rebuild:
WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.