BGREWRITE
Fix Redis BGREWRITE Error
Description
Error Message
ERR Background append only file rewriting already in progress
Known Causes
3 known causesSolutions
3 solutions available1. Wait for the Current AOF Rewrite to Complete easy
The error message explicitly states that a BGREWRITE is already in progress. The simplest solution is to wait for the current process to finish naturally. Redis will automatically start a new BGREWRITE when it's triggered again, provided no other rewrite is running.
redis-cli BGREWRITEAOF
2. Check and Kill the Existing BGREWRITE Process (Advanced) advanced
If the BGREWRITE process seems stuck or is taking an excessively long time, you might consider forcefully terminating it. This should be done with extreme caution as it could lead to data inconsistencies if not managed properly. It's generally recommended to avoid this unless absolutely necessary and after understanding the risks.
ps aux | grep redis-server
kill <PID_of_redis_server>
# If SIGTERM doesn't work, use SIGKILL (use with caution):
kill -9 <PID_of_redis_server>
3. Adjust BGREWRITE Triggers and Configuration medium
This error can occur if the conditions for automatic AOF rewrites are met too frequently, leading to overlapping processes. Reviewing and adjusting the `auto-aof-rewrite-percentage` and `auto-aof-rewrite-min-size` configuration parameters can help prevent this by making the triggers less sensitive.
redis-cli
CONFIG GET auto-aof-rewrite-percentage
CONFIG GET auto-aof-rewrite-min-size
CONFIG SET auto-aof-rewrite-percentage 100
CONFIG SET auto-aof-rewrite-min-size 1gb
vim /etc/redis/redis.conf
# Add or modify the following lines:
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 1gb
# Then reload or restart Redis:
redis-cli CONFIG REWRITE
# or restart the Redis service