341

I don't understand why the /var/log/journal/ folder is so big.

For example, by executing the command systemctl -f, i see the fill. If I click on an email on Thunderbird, it generates dozens of lines that I consider useless.

Currently, I have more than 1.5GB (du -h /var/log/journal/) generated in 1 day!

Is there a method to reduce this log considerably without stopping logging?

TooTone
  • 185
Bristow
  • 3,460

5 Answers5

382

You can diminish the size of the journal by means of these commands:

sudo journalctl --vacuum-size=100M

This will retain the most recent 100M of data.

sudo journalctl --vacuum-time=10d

will delete everything but the last 10 days.

From man journalctl:

--vacuum-size=, --vacuum-time=, --vacuum-files=
    Removes the oldest archived journal files until the disk space they use
    falls below the specified size (specified with the usual "K", "M", "G" and
    "T" suffixes), or all archived journal files contain no data older than
    the specified timespan (specified with the usual "s", "m", "h", "days",
    "months", "weeks" and "years" suffixes), or no more than the specified
    number of separate journal files remain. Note that running --vacuum-size=
    has only an indirect effect on the output shown by --disk-usage, as the
    latter includes active journal files, while the vacuuming operation only
    operates on archived journal files. Similarly, --vacuum-files= might not
    actually reduce the number of journal files to below the specified number,
    as it will not remove active journal files.
<b>--vacuum-size=, --vacuum-time= and --vacuum-files=</b> may be combined in a
single invocation to enforce any combination of a size, a time and a
number of files limit on the archived journal files. Specifying any of
these three parameters as zero is equivalent to not enforcing the specific
limit, and is thus redundant.

These three switches may also be combined with --rotate into one command.
If so, all active files are rotated first, and the requested vacuuming
operation is executed right after. The rotation has the effect that all
currently active files are archived (and potentially new, empty journal
files opened as replacement), and hence the vacuuming operation has the
greatest effect as it can take all log data written so far into account.

Jos
  • 30,529
  • 8
  • 89
  • 96
260

As @kurt-fitzner wrote:

Teach them to edit /etc/systemd/journald.conf and you teach them how to solve the problem permanently.

More specifically: Activate the SystemMaxUse= option there, e.g. as SystemMaxUse=100M to only use 100 MB.

After editing, use service systemd-journald restart to activate the changed configuration. This will remove the excess logs.

journald.conf also has other options that might be useful.

22

You also need to set this in /etc/systemd/journald.conf:

SystemMaxFileSize=100M

See: https://got-tty.org/journalctl-via-journald-conf-die-loggroesse-definieren (in German)

Per Lundberg
  • 163
  • 8
Chillio
  • 221
  • 2
  • 2
9

Reading this was confused about SystemMaxFileSize vs SystemMaxUse options for journald.conf. This clears it up:

SystemMaxUse= and RuntimeMaxUse= control how much disk space the journal may use up at most. SystemKeepFree= and RuntimeKeepFree= control how much disk space systemd-journald shall leave free for other uses. systemd-journald will respect both limits and use the smaller of the two values.

The first pair defaults to 10% and the second to 15% of the size of the respective file system, but each value is capped to 4G. If the file system is nearly full and either SystemKeepFree= or RuntimeKeepFree= are violated when systemd-journald is started, the limit will be raised to the percentage that is actually free. This means that if there was enough free space before and journal files were created, and subsequently something else causes the file system to fill up, journald will stop using more space, but it will not be removing existing files to reduce the footprint again, either. Also note that only archived files are deleted to reduce the space occupied by journal files. This means that, in effect, there might still be more space used than SystemMaxUse= or RuntimeMaxUse= limit after a vacuuming operation is complete.

SystemMaxFileSize= and RuntimeMaxFileSize= control how large individual journal files may grow at most. This influences the granularity in which disk space is made available through rotation, i.e. deletion of historic data. Defaults to one eighth of the values configured with SystemMaxUse= and RuntimeMaxUse=, so that usually seven rotated journal files are kept as history.

Marc
  • 91
  • 1
  • 1
1

If this is on a btrfs volume, you can drastically decrease the space without removing data using transparent folder compression.

btrfs property set /var/log/journal force-compress zstd

Though I prefer to set it on the entire log folder:

btrfs property set /var/log force-compress zstd