Article directory
①. Overview and functions of RDB
- ①. RDB overview: At a specified time interval, execute a point-in-time snapshot of the data set
- The way to achieve a photo-like recording effect is to write the data and status at a certain moment to the disk in the form of a file, which is a
snapshot. In this way, even if there is a failure, the snapshot file will not be lost, and the reliability of the data is guaranteed. - This snapshot file is called an RDB file (dump.rdb). RDB is the abbreviation of Redis DataBase.
- RDB official website
- ②. The role of RBD files
- Write the snapshot of the data set in the memory to the disk within the specified time interval, which is the Snapshot memory snapshot in the jargon. When it is restored, the hard disk and the snapshot file are directly read back to the memory.
- Redis data is all in memory. When saving a backup, it performs a full snapshot , that is, it records all the data in the memory to the disk.
- The file RDB saves to disk is called dump.rdb
②. RDB - automatic trigger
-
①. The configuration files below Redis6.0.16 are as follows:
-
②. This case was modified twice in 5 seconds.
-
③. Modify the dump file saving path and dump file name. Customize the
modified path and you can enter redis and use CONFIG GET dir to obtain the directory.
-
④. The first trigger situation:
-
⑤. The second trigger situation:
-
⑥. After the backup is successful, deliberately use flushdb to clear redis to see if the data can be restored.
Executing the flushall/flushdb command will also generate a dump.rdb file, but it is empty and meaningless.
③. Manual trigger - save, bgsave
-
①. Redis provides two commands to generate RDB files (manually triggered), namely save and bgsave
-
②. Save - Not recommended. Execution
in the main program will block the current redis server until the persistence work is completed. During the execution of the save command, Redis cannot process other commands, and online use is prohibited.
-
③. BGSAVE (default): Redis will perform snapshot operations asynchronously in the background. It does not block snapshots and can also respond to client requests. This trigger method will fork a child process and copy the persistence process by the child process.
-
④. You can obtain the time of the last successful snapshot execution through the lastsave command.
# redis侧获得时间戳
127.0.0.1:6369>LASTSAVE
(integer) 1668604512
# linux侧
# date -d @1668604512
2022年 11月 6日 星期三 21:15:12 CST
④. RDB - Advantages reflected
-
①.Official website description
-
②. Suitable for large-scale data recovery
-
③. Low requirements for data integrity and consistency
-
④. RDB files are loaded into memory much faster than AOF.
⑤. RDB - Disadvantages
-
①. Official website description:
-
②. Make a backup at a certain interval, so if redis accidentally goes down, the data from the current to the latest snapshot will be lost, and the data between snapshots will be lost.
-
③. Full synchronization of memory data. If the amount of data is too large, I/0 will seriously affect server performance.
-
④. Data loss cases
⑥. What situations will trigger RDB snapshots?
-
①. Default snapshot configuration in configuration file
-
②. Executing the flushall/flushdb command will also generate the dump.rdb file, but it is empty and meaningless.
-
③. Manual save/bgsave command
-
④. Execute shutdown without setting to enable AOF persistence.
-
⑤. During master-slave replication, the master node automatically triggers
⑦. Detailed explanation of RDB optimization configuration items
-
①. Method to dynamically stop all RDB saving rules: redis-cli config set save "", the configuration file is as follows:
-
②. Commonly used RDB configurations are as follows:
save <seconds> <changes>
- dbfilename: file name
- dir: file directory
-
③. stop-writes-on-bgsave-error: The default is yes.
If configured to no, it means that you do not care about data inconsistency or have other means to discover and control such inconsistencies. This will ensure that redis continues to accept new data when the snapshot writing fails. write request
-
④. rdbcompression: The default is yes.
For snapshots stored on disk, you can set whether to compress and store them. If so, redis will use the LZF algorithm for compression. If you don't want to consume CPU for compression, you can set it to turn off this function.
-
⑤. rdbchecksum: The default is yes.
After storing the snapshot, you can also let redis use the CRC64 algorithm for data verification, but doing so will increase performance consumption by about 10%. If you want to get the maximum performance improvement, you can turn off this function.
-
⑥. rdb-del-sync-files: Enable deleting RDB files used in replication without persistence. By default no, this option is disabled