Clear systemd journal

Mattias Geniar, Monday, February 26, 2018

On any server, the logs can start to add up and take considerable amount of disk space. Systemd conveniently stores these in /var/log/journal and has a systemctl command to help clear them.

Take this example:

$ du -hs /var/log/journal/
4.1G	/var/log/journal/

4.1GB worth of journal files, with the oldest dating back over 2 months.

$ ls -lath /var/log/journal/*/ | tail -n 2
-rw-r-x---+ 1 root systemd-journal 8.0M Dec 24 05:15 user-xxx.journal

On this server, I really don't need that many logs, so let's clean them out. There are generally 2 ways to do this.

Clear systemd journals older than X days

The first one is time-based, clearing everything holder than say 10 days.

$ journalctl --vacuum-time=10d
...
Vacuuming done, freed 2.3G of archived journals on disk.

Alternatively, you can limit its total size.

Clear systemd journals if they exceed X storage

This example will keep 2GB worth of logs, clearing everything that exceeds this.

$ journalctl --vacuum-size=2G
...
Vacuuming done, freed 720.0M of archived journals on disk.

Afterwards, your /var/log/journal should be much smaller.

$ du -hs /var/log/journal
1.1G	/var/log/journal

Saves you some GBs on disk!



Hi! My name is Mattias Geniar. I'm a Support Manager at Nucleus Hosting in Belgium, a general web geek & public speaker. Currently working on DNS Spy & Oh Dear!. Follow me on Twitter as @mattiasgeniar.

Share this post

Did you like this post? Will you help me share it on social media? Thanks!

Comments

Cornelius Friday, March 23, 2018 at 12:32 - Reply

There is a possibility to limit the total size too: SystemMaxUse=1G
https://www.freedesktop.org/software/systemd/man/journald.conf.html


Leave a Reply

Your email address will not be published. Required fields are marked *