Configuring Persistence with RDB
1. Understanding RDB Snapshots
| Property | Detail |
| Format | Compact binary point-in-time dump |
| Mechanism | fork() + write to temp + rename |
| Recovery | Fast bulk load on restart |
2. Configuring Save Points
save 3600 1
save 300 100
save 60 10000
save "" # disable RDB
| Pattern | Meaning |
save SECONDS CHANGES | Snapshot if N keys changed in M seconds |
3. Triggering Manual Save
| Command | Behavior |
SAVE | Synchronous; blocks server AVOID |
BGSAVE [SCHEDULE] | Background fork-based snapshot |
LASTSAVE | Unix ts of last successful save |
4. Setting RDB Filename
| Directive | Default |
dbfilename | dump.rdb |
5. Setting RDB Directory
| Directive | Notes |
dir /var/lib/redis | RDB + AOF written here |
6. Getting Last Save Time
| Command | Returns |
LASTSAVE | Unix timestamp |
INFO persistence | Status, last bgsave duration, error |
7. Configuring Compression
| Directive | Default | Effect |
rdbcompression yes | yes | LZF compression — small CPU cost |
8. Enabling Checksum
| Directive | Default |
rdbchecksum yes | CRC64 footer, detects corruption |
9. Handling RDB Failures
| Directive | Default |
stop-writes-on-bgsave-error yes | Reject writes if persistence fails |
Warning: Forking large datasets causes COW page faults — disable Transparent Huge Pages (THP).
| Mitigation | Detail |
| Disable THP | echo never > /sys/kernel/mm/transparent_hugepage/enabled |
| vm.overcommit_memory=1 | Required to prevent OOM during fork |
11. Using RDB for Backups
| Strategy | Detail |
| Hourly snapshot | Copy dump.rdb to S3 |
BGSAVE + copy | Trigger via cron |
12. Tuning Save Intervals
| Workload | Recommendation |
| High write | Larger thresholds to reduce fork frequency |
| Cache only | save "" (no persistence) |
| Critical | Combine RDB + AOF |