当前位置:网站首页>A complete tutorial for getting started with redis: RDB persistence
A complete tutorial for getting started with redis: RDB persistence
2022-07-07 02:49:00 【Gu Ge academic】
RDB Persistence is the process of saving a snapshot of the current process data to the hard disk , Trigger RDB a
The aging process is divided into manual trigger and automatic trigger .
5.1.1 Trigger mechanism
Manual trigger corresponds to save and bgsave command :
·save command : Block the current Redis The server , until RDB Until the process is complete , For memory
Larger examples can create long-term blockages , Online environment is not recommended . function save Command corresponding to the
Of Redis The log is as follows :
* DB saved on disk
·bgsave command :Redis Process execution fork Action create subprocess ,RDB The persistence process is the result of
Process responsible , It will automatically end when it is finished . The blockage only happens in fork Stage , The average time is very short . function
bgsave The command corresponds to Redis The log is as follows :
* Background saving started by pid 3151
* DB saved on disk
* RDB: 0 MB of memory used by copy-on-write
* Background saving terminated with success
obviously bgsave The order is for save Optimization of blocking problem . therefore Redis All internal references
And RDB The operation of the bgsave The way , and save The order has been abandoned .
In addition to executing the command to trigger manually ,Redis There are also automatic triggers inside RDB The persistence of
Mechanism , For example, the following scenario :
1) Use save Related configuration , Such as “save m n”. Express m Data set exists in seconds n Time modification
when , Automatic triggering bgsave.
2) If full replication is performed from a node , Automatic execution of master node bgsave Generate RDB writing
And send it to the slave node , See... For more details 6.3 The principle of replication described in Section .
3) perform debug reload Command reload Redis when , It will also trigger automatically save operation .
4) Execute by default shutdown On command , If it's not on AOF The persistence function is
Automatic execution bgsave.
5.1.2 Process description
bgsave It's the mainstream trigger RDB Persistence mode , Now according to the picture 5-1 Understand its operation flow
cheng .
1) perform bgsave command ,Redis The parent process determines whether there is an executing child in progress
cheng , Such as RDB/AOF Subprocesses , If there is bgsave The command returns directly to .
2) Parent process execution fork Action create subprocess ,fork Parent process will block during operation , through
too info stats Command view latest_fork_usec Options , You can get the latest fork Operation cost
when , In microseconds .
3) The parent process fork After completion ,bgsave Command return “Background saving started” Information
And no longer block the parent process , You can continue to respond to other commands .
4) Subprocess creation RDB file , Generate a temporary snapshot file based on the memory of the parent process , After completion
Atomic replacement of the original file . perform lastsave Command to get the last build RDB Of
Time , Corresponding info The statistical rdb_last_save_time Options .
5) The process signals the parent process that it's done , Parent process update statistics , Specific view
info Persistence Under the rdb_* Related options .
5.1.3 RDB Handling of documents
preservation :RDB The file is kept in dir Configure the specified directory , File name passed dbfilename with
Set designation . Can be executed by config set dir{newDir} and config set
dbfilename{newFileName} Run time dynamic execution , When next run RDB The file will be saved to
New catalog .
Operation and maintenance tips
When a bad disk or disk is full , Can pass config set dir{newDir} On-line
Modify the file path to the available disk path , After performing bgsave Perform disk switching , The same applies
On AOF Persistent files .
Compress :Redis By default LZF Algorithm pair generated RDB File compression , Compressed
The file size is much smaller than the memory size , Default on , You can use the parameter config set
rdbcompression{yes|no} Dynamic modification .
Operation and maintenance tips
Although compressed RDB Will consume CPU, But it can greatly reduce the volume of the file , Easy to save to hard disk
Or send it to the slave node through the network , Therefore, it is suggested to open .
check : If Redis Load corrupted RDB File refused to start , And print the following log :
# Short read or OOM loading DB. Unrecoverable error, aborting now.
You can use Redis Provided redis-check-dump Tool detection RDB File and get the right
Should be reported .
5.1.4 RDB Advantages and disadvantages
RDB The advantages of :
·RDB Is a compact binary , representative Redis Data at a certain point in time
snapshot . Ideal for backup , Full scale replication and other scenarios . Like every 6 Hours to perform bgsave Backup ,
And put RDB Copy files to a remote machine or file system ( Such as hdfs), For disaster recovery .
·Redis load RDB Recover data much faster than AOF The way .
RDB The shortcomings of :
·RDB Modal data cannot be persisted in real time / Second persistence . because bgsave Every time
All trades must be carried out fork Action create subprocess , Is a heavyweight operation , Frequent execution cost is too high .
·RDB Files are saved in a specific binary format ,Redis There are multiple formats in the version evolution process
Of RDB edition , There is an old version Redis The service is not compatible with the new version RDB The problem of format .
in the light of RDB Problems that are not suitable for real-time persistence ,Redis Provides AOF Persistent way to solve
" .
边栏推荐
- 实施MES管理系统时,哪些管理点是需要注意的
- Use of fiddler
- 换个姿势做运维!GOPS 2022 · 深圳站精彩内容抢先看!
- MySQL is an optimization artifact to improve the efficiency of massive data query
- 3 -- Xintang nuc980 kernel supports JFFS2, JFFS2 file system production, kernel mount JFFS2, uboot network port settings, and uboot supports TFTP
- Qpushbutton- "function refinement"
- LeetCode 77:组合
- CSDN 夏令营课程 项目分析
- 哈希表及完整注释
- 记一次JAP查询导致OOM的问题分析
猜你喜欢
wireshark安装
Use of fiddler
PSINS中19维组合导航模块sinsgps详解(时间同步部分)
How to design interface test cases? Teach you a few tips to draft easily
Statistics of radar data in nuscenes data set
unity中跟随鼠标浮动的面板,并可以自适应文字内容的大小
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
Redis入门完整教程:复制原理
MySQL --- 常用函数 - 字符串函数
dotConnect for DB2数据提供者
随机推荐
牛客编程题--必刷101之双指针篇
MySQL
Oracle中日期的使用方法实例
Software testing -- common assertions of JMeter interface testing
1 -- Xintang nuc980 nuc980 porting uboot, starting from external mx25l
Fundamentals of process management
MySQL提升大量数据查询效率的优化神器
MMDetection3D加载毫米波雷达数据
一文读懂Faster RCNN
leetcode:736. LISP syntax parsing [flowery + stack + status enumaotu + slots]
Cloud Mail . NET Edition
Station B's June ranking list - feigua data up main growth ranking list (BiliBili platform) is released!
wzoi 1~200
Here comes a white paper to uncover the technology behind Clickhouse, a node with 10000 bytes!
巴比特 | 元宇宙每日必读:IP授权是NFT的破圈之路吗?它的难点在哪里?Holder该如何选择合作平台?...
PSINS中19维组合导航模块sinsgps详解(时间同步部分)
Wireshark installation
Andrews - multimedia programming
AWS learning notes (I)
The 8 element positioning methods of selenium that you have to know are simple and practical