As suggested in another question, we have added destination path as db and autosave_interval as 3000, but after few days memory is getting reducing automatically.

Please let me know if there is any other solution to store in only db file.

  • Even if you can persist messages on the hard drive, doing so indefinitely will at some point fill your disk. Have you considered letting those messages expire? (not sure if mosquitto provides such a thing).
    – bgusach
    Commented Jun 5, 2018 at 6:48

1 Answer 1


The mosquitto broker does not support offloading the persistence store to an external database and the db file is just a backup of the in memory database in case the broker crashes or is shutdown.

If you have large numbers of messages queued for offline clients or large numbers of large retained messages then memory will be consumed.

The best you can do is set the persistent_client_expiration option to remove queued messages for clients that have not logged on for a long time. Details of this option can be found in the mosquitto.conf man page.

Otherwise you will need to look at using a different broker that supports out of process storing of the persistence database. Something like mosca can be configured to use mongo or redis as a backing store.

  • Currently persitent_client_expiration is 1hour but still memory consumed.
    – bhuva nesh
    Commented Jun 7, 2018 at 6:26
  • Then the memory growth is probably not down to queued messages for offline clients.
    – hardillb
    Commented Jun 7, 2018 at 6:48
  • Is there any way to clean retained messages manually?
    – bhuva nesh
    Commented Jun 8, 2018 at 4:21
  • Not without stopping the broker, deleting the db file and restarting or publishing a null payload to the topic (with the retained flag set)
    – hardillb
    Commented Jun 8, 2018 at 7:09

Your Answer

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

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