journalctl - remove logs of a specific unit

Systemd

Systemd Problem Overview


With journalctl, it is possible to remove the old logs, by specifying either the maximum disk space they can use, or the maximum age they can have, or the maximum number of separate journal files (using the options --vacuum-size, --vacuum-time or --vacuum-files).

Is there a way to restrain this deletion to a specific systemd unit ?

journalctl -u <unit> --vacuum-time=2d seems not to work as desired: according to the documentation, -u only works when displaying logs.

Systemd Solutions


Solution 1 - Systemd

After some research I found that you can't delete logs for a specific systemd unit, because the logs are interlaced and if you delete only one unit you'll corrupt the logs, so journalctl doesn't let you.

Solution 2 - Systemd

The self maintenance method is to vacuum the logs by size or time.

Retain only the past two days:

journalctl --vacuum-time=2d

Retain only the past 500 MB:

journalctl --vacuum-size=500M

Source: https://unix.stackexchange.com/questions/139513/how-to-clear-journalctl

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionaudeoudhView Question on Stackoverflow
Solution 1 - Systemduser3144605View Answer on Stackoverflow
Solution 2 - SystemdNail Khaled BeneloualidView Answer on Stackoverflow