pg_lightool基于basebackup的单表恢复和块恢复
原作者: 李传成 创作时间:2019-04-24 08:57:41+08 |
wangliyun 发布于2019-04-24 08:57:41
评论: 4
浏览: 5649
顶: 779
踩: 750
|
作者简介
李传成: 瀚高软件内核研发工程师,主要研究方向为数据库的备份和恢复,对wal日志的原理和应用有较深的理解。自研了wal日志解析工具walminer、pg块恢复工具pg_lightool。
背景
开源软件pg_lightool,实现了基于wal日志的块恢复。详情参见博客:https://my.oschina.net/lcc1990/blog/1931485。由于wal日志中FPW的不确定性,它不能作为一个数据库恢复的解决方案。目前对pg_lightool的代码做了升级,它可以基于一个basebackup和basebackup之后的wal日志完成某个数据表的恢复或者某些page的恢复。项目开源地址:https://gitee.com/movead/pg_lightool。
工具的安装方法在之前的博客里有详细说明,不再赘述。本文主要说明一下pg_lightool新功能的使用方法。新功能的主要应用场景:有基础备份的数据量级比较大的数据库,在发生表或者块数据损坏时,用于损坏数据的快速恢复。
一、实验数据准备
1.初始化数据库后设置归档目录

2.创建表插入测试数据

3.如下闭库后删除刚才产生的wal日志。用于保证数据是从basebackup获取的。

4.启动数据库做基础备份

5.测试数据修改(涂掉的地方是log输出有点串行,忽略即可)

二、基于basebackup和wal日志的单表完全恢复
1.关闭数据库,模拟表破坏


2.闭库,执行恢复命令后查看数据

说明:
使用-b 参数为-1即为全表恢复。
使用-r参数指定basebackup的路径。
命令执行成功后,在数据文件所在的目录生成wtrbk目录保存旧的数据


说明:表完全恢复的数据正确。
三、基于basebackup和wal日志的单表不完全恢复
在修改测试数据的时候,有一个delete语句,假设这个delete语句是误操作。我们想把数据恢复到这个delete语句之前,应该怎么办?如下是使用pg_lightool工具的不完全恢复演示过程。
1.使用pg_waldump到wal日志中查看这个delete语句的之前成功的一个事务提交,如下结果可以看出delete语句的xid是581,前一个提交的事务是580


2.闭库执行恢复,并查看结果

说明:
使用了-x参数指定停止wal日志redo的xid,还可以替换为使用-e参数指定时间。
假设delete为误操作,此时误操作数据已恢复,不完全恢复出的数据正确。
四、基于basebackup和wal日志的单block完全恢复
1.闭库删除t2的数据,并执行恢复命令

说明:-b参数指定要恢复的page为0,1,2
2.查看数据

说明:表完全恢复的数据正确。
五、基于basebackup和wal日志的单block不完全恢复
1.闭库删除t2的数据,并执行恢复命令

2.查看数据

说明:表不完全恢复的数据正确。
六、后记
1.此恢复操作没有计入wal日志,因此执行恢复后,需要立即备份。
2.目前代码只适用pg10以及之前的版本。
3.如有bug请issue或联系我(lchch1990@sina.cn)

评论:
请在
登录后发表评论,否则无法保存。
1# __
xcvxcvsdf 回答于 2024-11-22 08:56:02+08
http://ruanwen.xztcxxw.cn/shanghaishi/
http://gx.lztcxxw.cn/hljqqhr/
http://cf.lstcxxw.cn/jbjz/
https://dongminglu.tiancebbs.cn/
http://taiying.njtcbmw.cn/llpj/
http://huilong.sctcbmw.cn/jslyg/
http://km.lstcxxw.cn/huanggang/
http://huilong.sctcbmw.cn/ahmas/
http://nalei.zjtcbmw.cn/ghua/
http://cf.lstcxxw.cn/luoyang/
http://bjtcxxw.cn/nanchong/
https://bxqshi.tiancebbs.cn/
http://tuiguang.hntcxxw.cn/cqbp/
https://aihuishou.tiancebbs.cn/dxbj/
http://bjtcxxw.cn/suqian/
http://xinguang.sctcbmw.cn/lvliang/
http://ruanwen.xztcxxw.cn/zigong/
2# __
xcvxcvsdf 回答于 2024-11-20 22:28:30+08
https://su.tiancebbs.cn/hjzl/459530.html
https://su.tiancebbs.cn/hjzl/471116.html
https://www.tiancebbs.cn/ershoufang/471288.html
https://www.tiancebbs.cn/ershoufang/473660.html
https://aihuishou.tiancebbs.cn/sh/3194.html
https://www.tiancebbs.cn/ershouwang/474264.html
https://zulin.tiancebbs.cn/sh/57.html
https://zy.tiancebbs.cn/qths/471800.html
https://su.tiancebbs.cn/hjzl/460918.html
https://zulin.tiancebbs.cn/sh/2477.html
https://taicang.tiancebbs.cn/hjzl/463712.html
https://www.tiancebbs.cn/ershouwang/474289.html
https://aihuishou.tiancebbs.cn/sh/2231.html
https://zulin.tiancebbs.cn/sh/4935.html
https://aihuishou.tiancebbs.cn/sh/2357.html
https://aihuishou.tiancebbs.cn/sh/320.html
https://www.tiancebbs.cn/ershoufang/468917.html
3# __
xcvxcvsdf 回答于 2024-11-11 17:35:56+08
http://js.sytcxxw.cn/ershou/
https://fenlei.tiancebbs.cn/putuoqu/
http://nalei.zjtcbmw.cn/sxty/
https://jianning.tiancebbs.cn/
https://hjgongyeyuan.tiancebbs.cn/
http://ruanwen.xztcxxw.cn/hnxxn/
http://ty.cqtcxxw.cn/zhenjiang/
http://fs.shtcxxw.cn/hainanzhou/
http://fuyang.tjtcbmw.cn/nanchong/
https://fenlei.tiancebbs.cn/chenzhou/
http://huaguang.jxtcbmw.cn/huangpush/
https://fuzhouzhoubian.tiancebbs.cn/
http://taiying.njtcbmw.cn/cqjnp/
http://ruanwen.xztcxxw.cn/yanbian/
http://fs.shtcxxw.cn/rizhao/
http://fuyang.tjtcbmw.cn/ltxjhs/
http://tuiguang.hntcxxw.cn/lltl/
4# __
xiaowu 回答于 2024-04-23 14:48:42+08
同学聚会发朋友圈的句子:https://www.nanss.com/wenan/5017.html 分手之后想挽留:https://www.nanss.com/shenghuo/5383.html 致自己本命年的唯美句子:https://www.nanss.com/yulu/5016.html 最酷的游戏名字:https://www.nanss.com/mingcheng/5011.html 女王节文案:https://www.nanss.com/wenan/5006.html 陪孩子快乐时光朋友圈:https://www.nanss.com/wenan/5062.html 清账催款的句子发朋友圈:https://www.nanss.com/wenan/5072.html 女生唯美网名:https://www.nanss.com/mingcheng/5079.html 搞笑的群名:https://www.nanss.com/mingcheng/5329.html 走月亮第六自然段仿写小练笔:https://www.nanss.com/xuexi/5285.html 含蓄幽默表达自己生日:https://www.nanss.com/yulu/5355.html 高情商幽默万能句:https://www.nanss.com/yulu/5352.html 后悔的个性签名:https://www.nanss.com/wenan/5233.html 描写月下情景小练笔:https://www.nanss.com/xuexi/5032.html 我的读书格言:https://www.nanss.com/xuexi/5210.html 初三冲刺中考家长寄语:https://www.nanss.com/xuexi/5379.html 抖音最火的幽默句子:https://www.nanss.com/yulu/5356.html 最有素质的骂人语言:https://www.nanss.com/yulu/5080.html 班级座右铭:https://www.nanss.com/xuexi/5338.html LOL最欠揍的名字:https://www.nanss.com/mingcheng/5175.html 天冷了的简单暖心话语:https://www.nanss.com/wenan/5018.html 男人准备放弃你的表现:https://www.nanss.com/wenti/4876.html 典故取名:https://www.nanss.com/mingcheng/5028.html 周记400字:https://www.nanss.com/xuexi/4135.html 懒惰的近义词:https://www.nanss.com/xuexi/4609.html 时尚签名:https://www.nanss.com/wenan/5019.html 对老师的感言:https://www.nanss.com/xuexi/5405.html 简短的几句话:https://www.nanss.com/yulu/5212.html 家长简单的评语:https://www.nanss.com/xuexi/5406.html 学生自我评价15字:https://www.nanss.com/xuexi/5394.html
发表评论: 加入我们
QQ群1:5276420
QQ群2:3336901
QQ群3:254622631
文档群:150657323
© PostgreSQL中文社区 ... (自2010年起)