# Preventing Full Disk Issues

Running out of disk space in a Redis environment can lead to failed writes, snapshot errors, and service unavailability. Redis relies on disk storage for persistence (RDB and AOF files), temporary dumps, and logs especially when persistence is enabled. On platforms like Elestio, while the infrastructure is managed, users are responsible for monitoring disk usage, configuring retention policies, and managing backups. This guide covers how to monitor disk consumption, configure alerts, remove unused data, and follow best practices to prevent full disk scenarios in a Redis setup using Docker Compose.

### **Monitoring Disk Usage**

Disk usage monitoring is essential for spotting unusual growth before it leads to failures. In Docker Compose setups, you’ll need both host-level and container-level visibility.

#### **Inspect the host system storage**

Run this on the host machine to check which mount point is filling up:

```
df -h
```

This shows available and used space for each volume. Identify the mount point used by your Redis volume—usually mapped to something like <span class="s1">/var/lib/docker/volumes/redis\_data/\_data</span>.

#### **Check disk usage from inside the container**

Open a shell inside the Redis container:

```
docker-compose exec redis sh
```

Inside the container, check the data directory size:

```
du -sh /data
```

This reveals total usage by persistence files (<span class="s1">appendonly.aof</span>, <span class="s1">dump.rdb</span>, temporary files). You can inspect individual file sizes with:

```
ls -lh /data
```

### **Configuring Alerts and Cleaning Up Storage**

Monitoring alone isn’t enough—automated alerts and safe cleanup prevent downtime. You can inspect disk usage across Docker resources on the host with:

```
docker system df
```

#### **Identify unused Docker volumes**

```
docker volume ls
```

To remove a specific unused volume:

```
docker volume rm <volume-name>
```

> <span class="s1">**Warning**</span>: Never delete the volume mapped to your Redis data unless you’ve backed up its contents and confirmed it is not in use.

#### **Trigger AOF file compaction**

If AOF persistence is enabled, the append-only file can grow large over time. You can manually trigger a rewrite to compact the file:

```
docker-compose exec redis redis-cli BGREWRITEAOF
```

This creates a smaller AOF file containing the same dataset.

#### **Clean up old snapshots**

If you are using RDB snapshots, they’re stored in <span class="s2">/data</span> within the container (mapped to a host volume). To clean up, list them first:

```
docker-compose exec redis ls -lh /data
```

Remove unnecessary <span class="s1">.rdb</span> files with:

```
docker-compose exec redis rm /data/dump-<timestamp>.rdb
```

### **Managing &amp; Optimizing Temporary Files**

Redis creates temporary files during fork operations for AOF rewrites and RDB saves. These are stored in the container’s <span class="s2">/tmp</span> directory.

#### **Monitor temporary file usage:**

```
docker-compose exec redis du -sh /tmp
```

If <span class="s1">/tmp</span> fills up, writes and forks may fail. You can change the temporary directory by modifying the <span class="s1">dir</span> directive in <span class="s1">redis.conf</span> to point to <span class="s1">/data</span>, which is volume-backed:

```
dir /data
```

Restart the container to apply changes.

### **Best Practices for Disk Space Management**

Long-term disk space health in Redis requires proactive design and ongoing management.

- <span class="s1">**Avoid storing binary blobs**</span>: Store large files (images, PDFs, etc.) outside Redis and use Redis only for keys/metadata. Use object storage for large content.
- <span class="s1">**Disable persistence if not needed**</span>: For ephemeral cache use cases, you can disable persistence entirely to reduce disk usage:

```
appendonly no
save ""
```

- <span class="s1">**Limit AOF growth**</span>: Fine-tune AOF rewrite behavior in <span class="s2">redis.conf</span>:

```
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
```

- <span class="s1">**Rotate logs in containers**</span>: If logging to file (e.g., <span class="s2">/var/log/redis/redis-server.log</span>), configure <span class="s2">logrotate</span> on the host or use Docker log rotation options via <span class="s2">docker-compose.yml</span>:

```yaml
logging:
  driver: "json-file"
  options:
    max-size: "10m"
    max-file: "3"
```

- <span class="s1">**Evict old keys with TTLs**</span>: Set expiration on cache keys to prevent unbounded growth:

```
SET session:<id> "data" EX 3600
```

- <span class="s1">**Monitor data size**</span>: Use <span class="s2">INFO persistence</span> and <span class="s2">INFO memory</span> to track memory usage and AOF file size:

```
docker-compose exec redis redis-cli INFO memory
docker-compose exec redis redis-cli INFO persistence
```

- <span class="s1">**Offload backups**</span>: Backups stored in <span class="s2">/data</span> should be moved off the container host. Use Elestio backup tools or mount a remote backup volume in your <span class="s2">docker-compose.yml</span>.