Writing logs to RAM instead of the microSD card on RPi?

Is there a tweak that can force Pihole to write logs to RAM and flush them after x MB has reached or before a reboot to the microSD of RPi?

I know of log2ram but I encountered an issue where: 40M 40M 0 100% /var/log and log2ram didn't flush the logs on the microSD, so when I ran pihole tail no logs where generated.
Is there an alternative to log2ram that achieves the same thing but that actually works?

Looking for the same...I tried to use log2ram and had it fail on me. So I removed it. But if there is a way to optimize it correctly, I would probably reinstall it.

My opinion, its not necessary.
The SD speed is more than sufficient for the logs.
log2ram only complicates things.

1 Like

As I don't need permanent logs, I use this approach

sudo nano /etc/fstab

tmpfs   /var/log    tmpfs   rw,nosuid,nodev,noexec,noatime,size=64m,mode=755    0 0

It's not about the speed of writing, it's about wearing the sd card too quickly with all the writing going on.

I'm not savvy with the bash commands. Can you please explain what does this command do?

Search Discourse here for more log2ram and wear related discussions.
And you should change the title for this thread to reflect on wear instead of speed.

If not efficient with bash etc, dont do it!
Meddling with fstab can brick your system if dont know how to revert.

duly noted, but speed is a component in it. I find that my RPi is slow to respond at times and I can attribute it to the log writing.

Can you explain ?
Many thousands of users are using Pi-hole.
This is the first time (that I know of) someone relates log speed with a slow responding Pi.

I only assume that based on the amount of logging I see (pihole tail) and browsing the pihole.net/admin menus, or the time it takes web pages to load that my RPi is slow to respond (RPi 3B+). I thought it's the microSD card.
But I was more concerned with the 'quick' wear and tear I read about by the logging.

I have a little test for you.
You can disable logging entirely via the web GUI if changing privacy level into "Anonymous mode: This disables basically everything except the live anonymous statistics".
And see if improves.

1 Like

Alternatively, you may leave your privacy level untouched and switch off logging via Pi-hole's command line:

-l, logging [on|off|off noflush]

        Specify whether the Pi-hole log should be used

        (Logging options):
         on                Enable the Pi-hole log at /var/log/pihole.log
         off               Disable and flush the Pi-hole log at
                           /var/log/pihole.log
         off noflush       Disable the Pi-hole log at /var/log/pihole.log

EDIT: While avoiding log writes, I very much doubt that it has any perceivable impact on DNS resolution speeds.

1 Like

From Pi-hole's perspective, there is little to gain by logging to ram.

Pi-hole itself doesn't rely on the logs, it uses its own in-memory structures to populate the dashboard for its current queries (rolling at 24 hours), and it pulls information from its database for long-term data display.

If you are just worried about SD card wear, buying a good quality SD card already goes a long way.

As mentioned above, you may also switch off logging completely, but that will also force you to use SQL commands against the database instead of e.g. tail and grep for plain text files to extract data.
Depending on your personal skills, that may not be a big deal, but you can't use SQL without knowing how the data is structured in views, tables and columns. Command line tools tend to be easier to handle, and more generic.

In general, I wouldn't worry about Pi-hole's contribution to wearing your SD card too much.
A single uncontrolled shutdown by pulling the plug on an RPi may do more damage to your SD card than a year of running Pi-hole.

1 Like

There is not as much writing going on as you may think. My advice would be to get a good quality SD card of 32 GB or higher. That provides quite a bit of free space on the card for the wear leveling algorithm to use. A good 32 GB card is less than $10 US, and a 64 GB is probably about $15 US.

Adding the complication of a RAM log is unwarranted in my opinion.

1 Like

you are correct about the wear leveling with the 32GB card. my microSD card that came bundled with RPi was fudged. I'm using a temporary 16GB card and it's much faster. I'm waiting for the 32GB replacement and it will be my daily driver.
Thanks.

Most cards that ship with Pi kits are the cheapest junk the bundler can find. Get a good name brand card, and buy a spare that you can clone to for a backup. Rotate them every year and they'll last much longer than the Pi will be useful.

Cheers!
Is Samsung cards OK? Class 10?

p.s. - I'm having issues which I cannot resolve and would really appreciate your help: Cannot access WebUI

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