Error
Error Code:
BGSAVE
Fix Redis Error BGSAVE: Save Already Running
Description
This error indicates that a background save operation (BGSAVE) is already in progress. Redis only allows one background save process to run at a time to avoid performance issues and data corruption.
Error Message
ERR Background save already in progress
Known Causes
3 known causesConcurrent BGSAVE Requests
Multiple BGSAVE commands were issued before the previous one completed.
Scheduled BGSAVE Overlap
A scheduled BGSAVE (e.g., through configuration) was triggered while another BGSAVE was still running.
Slow Disk I/O
The previous BGSAVE operation is taking a long time to complete due to slow disk I/O.
Solutions
3 solutions available1. Wait for the current BGSAVE to complete easy
The simplest solution is to wait for the ongoing background save operation to finish. Redis will automatically allow a new BGSAVE once the previous one is done.
1
Monitor Redis. You can check the status of Redis operations using the `INFO persistence` command. Look for the `rdb_bgsave_in_progress` field. It will be `1` if a BGSAVE is running and `0` otherwise.
redis-cli INFO persistence
2
Once `rdb_bgsave_in_progress` shows `0`, you can initiate a new BGSAVE command if needed.
redis-cli BGSAVE
2. Check and terminate the rogue BGSAVE process (Advanced) advanced
In rare cases, a BGSAVE might get stuck or hang. This solution involves identifying and forcefully terminating the underlying operating system process responsible for the BGSAVE.
1
Identify the Redis server's PID. You can usually find this in your Redis configuration file (`redis.conf`) under the `pidfile` directive, or by using system tools.
ps aux | grep redis-server
2
Check for child processes related to BGSAVE. Redis uses `fork()` to create a child process for BGSAVE. You can look for processes that are children of the main Redis server process.
pstree -p <redis_server_pid>
3
If you identify a persistent BGSAVE child process that is not terminating, you can try to kill it. Be cautious with this step as it might lead to minor data loss if the save was very close to completion.
kill <bgsave_child_pid>
4
Alternatively, if you are confident the Redis server is healthy but stuck, you can restart the Redis service. This will kill all associated processes and restart Redis cleanly.
sudo systemctl restart redis
3. Configure `stop-writes-on-bgsave-error` to prevent future issues (Medium) medium
While not a direct fix for an *already running* BGSAVE, this configuration option can help prevent situations where a failed BGSAVE might cause subsequent ones to be blocked. Setting `stop-writes-on-bgsave-error` to `yes` will make Redis stop accepting writes if a BGSAVE fails, which can help diagnose and resolve underlying issues that might be causing BGSAVE to hang.
1
Locate your `redis.conf` file. The default location varies by installation, but common paths include `/etc/redis/redis.conf` or `/usr/local/etc/redis/redis.conf`.
cat /etc/redis/redis.conf | grep stop-writes-on-bgsave-error
2
Edit the `redis.conf` file and uncomment or add the following line, ensuring it's set to `yes`:
stop-writes-on-bgsave-error yes
3
Restart your Redis server for the configuration change to take effect.
sudo systemctl restart redis
4
Monitor Redis logs for any BGSAVE failures after this change. If failures occur, investigate the root cause (e.g., disk space, memory issues).
tail -f /var/log/redis/redis-server.log