Unable connecting to locally installed MongoDB if custom cacheSizeGB is specified

Ubuntu 22.04.1
MongoDB 6.0.1

With default mongod.conf the connection is okay.

storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true

With custom cacheSizeGB it is not possible to connect.

storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
  wiredTiger:
    engineConfig:
      cacheSizeGB: 48

Compass output:
connect ECONNREFUSED [127.0.0.1:27017](http://127.0.0.1:27017)

PyMongo output:

pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno
111] Connection refused, Timeout: 30s, Topology Description:
<TopologyDescription id: 631a26da7c16647798b4ac71, topology_type:
Unknown, servers: [<ServerDescription ('localhost', 27017)
server_type: Unknown, rtt: None, error=AutoReconnect('localhost:27017:
[Errno 111] Connection refused')>]>

ECONNREFUSED means mongod is not running.

You probably got errors when you restarted with the new configuration. Share those errors. You should use a log file as it simplifies trouble shooting.

Do you have at least 48GB of RAM?

No, there are 64 GB. According to htop it is 62.6 GB. My goal is to allow MongoDB to use 56 GB. The inability to connect is observed with different cacheSizeGB values.

The error was observed both immediately after saving the changes in mongod.conf, and after rebooting the OS.

1 Like

The mongod.log stops filling up with new lines after adding the cacheSizeGB parameter to the config.

Depending on how you installed mongod, rebooting the OS might be insufficient to restart mongod.

Make sure it is running.

To disable MongoDB I apply sudo systemctl stop mongod or reboot OS, to enable - sudo systemctl enable mongod. None of these things work.

Try

sudo systemctl start mongod

And provide output of

sudo systemctl status mongod

Note that it is possible that the service is named mongodb rather than mongod.

sudo systemctl start mongod
sudo systemctl status mongod

× mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled;
vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2022-09-10 22:47:59
MSK; 16s ago
       Docs: https://docs.mongodb.org/manual
    Process: 5069 ExecStart=/usr/bin/mongod --config /etc/mongod.conf
(code=exited, status=2)
   Main PID: 5069 (code=exited, status=2)
        CPU: 20ms

сен 10 22:47:59 platon-MS-7D42 systemd[1]: Started MongoDB Database Server.
сен 10 22:47:59 platon-MS-7D42 mongod[5069]: Unrecognized option:
storage.wiredTiger
сен 10 22:47:59 platon-MS-7D42 mongod[5069]: try '/usr/bin/mongod
--help' for more information
сен 10 22:47:59 platon-MS-7D42 systemd[1]: mongod.service: Main
process exited, code=exited, status=2/INVALIDARGUMENT
сен 10 22:47:59 platon-MS-7D42 systemd[1]: mongod.service: Failed with
result 'exit-code'.

This confirms mongod is not running. It also indicates that the configuration you specified is wrong.

Check https://www.mongodb.com/docs/v5.0/reference/configuration-options/#storage-options for proper options. May be you have tabs rather than spaces.

Following the pattern of default mongod.conf, I use a multiple of two spaces for indentation.

Could you please clarify in which exact place of the code below there is an error?

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
  wiredTiger:
    engineConfig:
      cacheSizeGB: 56

May be you have tabs or spaces after the :.

Try removing the # engine

I just tested locally with this in my config file and mongod starts up just fine with MongoDB 6.0.1. This config even works with version 3.4.23, so storage.wiredTiger is a valid key.

I know you said that you’re running MongoDB 6.0.1, but can you post the results of mongod --version just for sanity. It’s almost like you have a really old version of mongod running.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.