Raspi > DietPi > Mosquitto: Increase SD card lifetime

Hello,
I have successfully installed DietPi on my Raspi.
In order to increase SD card lifetime I installed DietPi-RAMlog.
This is working as expected.

Now I installed Mosquitto message broker with dietpi-software.

With regards to SD card lifetime the question is:
Where is Mosquitto storing its data?

I found a file in /var/lib/mosquitto/mosquitto.db that could be identified as a database file of Mosquitto.
If this is true, this would shorten the lifetime of a (consumer class) SD card.

Can you please advise how to increase SD card lifetime running Mosquitto on Raspi?

THX

You would need another medium where you can store the data. You can not store the database in RAM, after a reboot everything would be gone.
You could connect an USB Stick and symlink the database to it

Just having a database file, doesn’t mean you are going to reduce your SD card live time already. It depends on r/w operation in total.

Ramlog should be default setting. Usually nothing to be installed.

Look, this is not a generic question but related to Mosquitto.

In the meantime I have found the solution in Mosquitto’s manpage:

persistence [ true | false ]

If true, connection, subscription and message data will be written to the disk in mosquitto.db at the location dictated by persistence_location. When mosquitto is restarted, it will reload the information stored in mosquitto.db. The data will be written to disk when mosquitto closes and also at periodic intervals as defined by autosave_interval. Writing of the persistence database may also be forced by sending mosquitto the SIGUSR1 signal. If false, the data will be stored in memory only. Defaults to false.

The persistence file may change its format in a new version. The broker can currently read all old formats, but will only save in the latest format. It should always be safe to upgrade, but cautious users may wish to take a copy of the persistence file before installing a new version so that they can roll back to an earlier version if necessary.

This option applies globally.

Reloaded on reload signal.

This means if persistence is not enabled (default), there’s no disk IO on the SD card.

1 Like