---
title: "Manage log rotation"
description: "Guide on configuring and testing Linux logrotate for Aerospike database logs."
---

# Manage log rotation

> For the complete documentation index see: [llms.txt](https://aerospike.com/docs/llms.txt)
> 
> All documentation pages available in markdown.

Aerospike manages log rotation with the Linux `logrotate` tool, which is installed by default on most versions of Linux. If your OS does not include `logrotate`, this page describes how to install it.

::: note
With `journald`, you don’t need to configure log rotation as it is handled implicitly by the journaling subsystem when the logs are configured to be output to the console. Refer to the [systemd](https://aerospike.com/docs/database/8.0.0/manage/logging/systemd) page for more details.
:::
::: caution
When configured to log to multiple files, it is necessary to use the logrotate **sharedscripts** directive in order to preserve the content of all the file and prevent a race condition between the different SIGHUP signals. Such race may improperly close log sink file descriptors, which could lead to potential reuse of those file descriptors for client transactions.
:::

## Install the logrotate binary

Install on CentOS

```bash
sudo yum install logrotate
```

Install on Debian and Ubuntu

```bash
sudo apt-get install logrotate
```

## Configure logrotate policy for Aerospike

If your system is configured with `logrotate.d` to manage log rotation, use `<logrotate.d>/aerospike` as the filename. On Aerospike installation, a log rotation policy file is set up at `/etc/logrotate.d/aerospike` that specifies:

-   The log should be rotated every day
-   Compress the old log files
-   Retain files for 90 days
-   Use date as the suffix
-   Use sharedscripts when rotating multiple files.

## Logrotate policy

If there are no pid files (on systemd based installations, if logrotate is preferred over journald), the postrotate `kill -HUP` command should use either `pidof asd` or `pgrep -x asd`.

Terminal window

```bash
/var/log/aerospike/aerospike.log {

    daily

    rotate 90

    dateext

    compress

    olddir /var/log/aerospike/

    sharedscripts

    postrotate

        /bin/kill -HUP `pgrep -x asd`

    endscript

}
```

## Logrotate policy with multiple files

Multiple log sync files can be configured to be rotated and use the same logrotate configuration and postrotate script.

Terminal window

```bash
/var/log/aerospike/aerospike.log /var/log/aerospike/xdr.log {

    daily

    rotate 90

    dateext

    compress

    olddir /var/log/aerospike/

    sharedscripts

    postrotate

        /bin/kill -HUP `pgrep -x asd`

    endscript

}
```

::: note
When typing the configuration lines above, there is a `<tab>` before **/bin/kill** preceded by 4 spaces of indentation.
:::

## Force run a logrotate to test

```plaintext
sudo logrotate -f -v /etc/logrotate.d/aerospike
```

Example output:

```plaintext
logrotate -f -v /etc/logrotate.d/aerospike

reading config file /etc/logrotate.d/aerospike

olddir is now /var/log/aerospike/

Allocating hash table for state file, size 15360 B

Handling 1 logs

rotating pattern: /var/log/aerospike/aerospike.log  forced from command line (90 rotations)

olddir is /var/log/aerospike/, empty log files are rotated, old logs are removed

considering log /var/log/aerospike/aerospike.log

  log needs rotating

rotating log /var/log/aerospike/aerospike.log, log->rotateCount is 90

dateext suffix '-20171101'

glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'

glob finding old rotated logs failed

renaming /var/log/aerospike/aerospike.log to /var/log/aerospike//aerospike.log-20171101

running postrotate script

compressing log with: /bin/gzip
```