Delete systemd journal logs

Hello,

Today on one of my server I saw that the disk space in /var is low, and the reason for that was in /var/log/journal.

In this post I will share how to delete systemd journal logs right, and how to make our server to do this alone.

root@mp-web06:/var/log# du -sh * |grep G
4.1G journal

Delete systemd journal logs older than X days

root@mp-web06:/var/log# journalctl --vacuum-time=5d
Deleted archived journal /var/log/journal/a20c526fbd1ffe2fe0fc6d5056053509/user-1003@55bfa9c91d5944b3a7a133fcec536fb8-000000000042a6ee-00057dd636182198.journal (8.0M).
.....
Vacuuming done, freed 3.8G of archived journals from /var/log/journal/a20c526fbd1ffe2fe0fc6d5056053509.

The idea here is the server will delete the logs older than 5 days.

Delete systemd journal logs bigger than X GB

root@mp-web06:/var/log# journalctl --vacuum-size=1G
Vacuuming done, freed 0B of archived journals from /var/log/journal/a20c526fbd1ffe2fe0fc6d5056053509.

So, if the log becomes bigger than 1GB, server will delete it, and will take care of the free space!

Now the disk space in /var/log/journal is much smaller!

root@mp-web06:/var/log# du -sh /var/log/journal/
257M /var/log/journal/

 

That’s it!