Automated backups not being triggered because cannot allocate memory

AI-generated summary

yanokwa reported that automated backups fail with a ‘Cannot allocate memory - fork(2)’ error, despite manual backups working. The server had 1GB RAM and was heavily swapping (1GB used). Falco and robbyoconnor suggested insufficient memory as the likely cause, though yanokwa questioned why manual backups succeeded. After upgrading to 2GB RAM, automated backups began working again, with memory usage now showing 1.2GB used and only 28M swap in use. yanokwa also noted a recent kernel upgrade and suggested rebooting as a possible fix. pfaffman advised running discourse-setup to optimize memory settings for the new RAM, which JagWaugh found surprising for an existing install. yanokwa initially hesitated due to concerns about app.yml changes, but later clarified that discourse-setup adjusts db_shared_buffers and UNICORN_WORKERS based on available RAM — e.g., 256MB for 2GB RAM and 2 workers per GB up to 8 total — as documented in the Discourse Docker repo.

Manual backups (local and to S3) work great, but automated backups don’t seem to work. Any ideas why?

Settings

Errors ~ 6 minutes after trigger

Job exception: Cannot allocate memory - fork(2)

/var/www/discourse/lib/backup_restore/backup_restore.rb:160:in `fork'
/var/www/discourse/lib/backup_restore/backup_restore.rb:160:in `start!'
/var/www/discourse/lib/backup_restore/backup_restore.rb:15:in `backup!'
/var/www/discourse/app/jobs/regular/create_backup.rb:8:in `execute'
/var/www/discourse/app/jobs/base.rb:154:in `block (2 levels) in perform'

Ram

root@discourse-app:/var/www/discourse# free -mh
              total        used        free      shared  buff/cache   available
Mem:           992M        664M         72M        137M        255M         50M
Swap:          2.0G        1.0G        1.0G

If you are constantly swapping 1GB, you need more memory on this server.

you probably are big enough that more memory is needed..1GB is enough.

If it’s a RAM issue, why do manual backups work then?

I’m not entirely sure but that error is due to insufficient memory available.

I upgraded from 1 GB to 2 GB box and backups seem to be working now.

              total        used        free      shared  buff/cache   available
Mem:           2.0G        1.2G        276M        141M        544M        498M
Swap:          2.0G         28M        2.0G

If anyone else has this problem, I’d try a reboot first because the Ubuntu box had also recently had kernel upgrades, so maybe that was the issue.

If you run discourse-setup it will tweak the memory settings to take advantage of the additional memory.

Interesting - I didn’t realise that running discourse-setup could be done on an install which was already up and running.

Hmm. Running the setup again sounds dangerous to my existing app.yml. Any idea what the tweaks are?

I answered my own question :joy:. According to discourse_docker/discourse-setup at master · discourse/discourse_docker · GitHub, the tweaks to app.yml are:

# db_shared_buffers: 128MB for 1GB, 256MB for 2GB, or 256MB * GB, max 4096MB
# UNICORN_WORKERS: 2 * GB for 2GB or less, or 2 * CPU, max 8