Search code examples
mongodbubuntusystemdlinode

mongodb.service dies after running some hours in Ubuntu


I have used mongodb(v3.6.8) for my server(Ubuntu 20.04), it works well for years. Recently,it be killed and failed to restart by systemd after running some days. I restart sysemd, it works for a few hours and dies again. Refer to systemd status:

$ systemctl status mongodb
● mongodb.service - An object/document-oriented database
     Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
     Active: failed (Result: signal) since Sat 2022-05-14 22:15:09 UTC; 5h 51min ago
       Docs: man:mongod(1)
    Process: 2463713 ExecStart=/usr/bin/mongod --unixSocketPrefix=${SOCKETPATH} --config ${CONF} $DAEMON_OPTS (code=killed, signal=KILL)
   Main PID: 2463713 (code=killed, signal=KILL)

Anyone know how to solve the problem?

Update log:

$ sudo journalctl -u mongodb.service
-- Logs begin at Wed 2022-05-11 06:03:08 UTC, end at Sun 2022-05-15 04:55:05 UTC. --
May 14 13:01:23 localhost systemd[1]: mongodb.service: Main process exited, code=killed, status=9/KILL
May 14 13:01:23 localhost systemd[1]: mongodb.service: Failed with result 'signal'.
May 14 17:29:35 localhost systemd[1]: Started An object/document-oriented database.
May 14 22:15:09 localhost systemd[1]: mongodb.service: Main process exited, code=killed, status=9/KILL
May 14 22:15:09 localhost systemd[1]: mongodb.service: Failed with result 'signal'.
May 15 04:10:53 localhost systemd[1]: Started An object/document-oriented database.

update: cmd "dmesg -T" show the reason is out of memory.

[Sat May 14 22:15:05 2022] Out of memory: Killed process 2463713 (mongod) total-vm:2486640kB, anon-rss:1133764kB, file-rss:0kB, shmem-rss:0kB, UID:112 pgtables:3240kB oom_score_adj:0

Solution

  • using dmesg -T show the reason why system kill mongodb(updated in question section), it's because "ot ouf memory". Mongodb consumes 2486640kB while my server is 16 GB, so mongodb does not consume too high memory.

    The failure is because other programs take too much memory, it's not mongodb problem