brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: MaxRetentionSec in journald.conf caps how old journalctl history gets

Journalctl
~/tips/tip-journalctl-max-retention

sudo mkdir -p /etc/systemd/journald.conf.d

Make journald delete old log files after a fixed age, whatever the disk size.

The usual journald limits are about size. If you care about age, for privacy rules or just because older lines are noise, there is a time based setting.

Put it in a drop-in so a package update does not overwrite it:

sudo mkdir -p /etc/systemd/journald.conf.d
sudo tee /etc/systemd/journald.conf.d/50-retention.conf <<'EOF'
[Journal]
MaxRetentionSec=1month
EOF
sudo systemctl restart systemd-journald

journald then removes archived journal files whose entries are all older than a month. The default is 0, which turns this feature off, so out of the box only the size limits decide. I like a month on small servers: long enough to look back at the last update, short enough that old noise goes away.

To see that the setting is live:

systemd-analyze cat-config systemd/journald.conf | grep Retention

Retention works per file, so lines can live a bit longer than the limit while the file they are in also holds newer entries. If you want tighter steps, also set MaxFileSec= so files get rotated more often; it defaults to one month. The size limits still apply on top, so on a small disk old logs may disappear sooner anyway.

Further reading: journald.conf man page

More Journalctl tips journalctl -k -g 'killed process' --since "2 days ago" journalctl _PID=1 -b ls -lh /var/log/journal/*/*.journal~ Storage=volatile sudo journalctl --setup-keys All Journalctl tips (81) All topics

Link