登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
我知道了
查看详情
登录
注册
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
28
Star
18
Fork
236
openGauss
/
blog
代码
Issues
9
Pull Requests
23
Wiki
统计
流水线
服务
Gitee Pages
JavaDoc
PHPDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
我知道了,不再自动展开
703
【openGauss技术文章征集】-openGauss 3.0:闪回恢复.md
已关闭
用户已删除:master
openGauss:master
杨凯
创建于 2022-10-17 21:03
克隆/下载
HTTPS
SSH
复制
下载 Email Patch
下载 Diff 文件
**openGauss 3.0:闪回恢复** 闪回概念是Oracle最先提出来的,其本质是为了回退错误操作产生的,避免人为的“灾难”,并且要能够快速回退。 闪回恢复功能是数据库恢复技术的一环,可以有选择性的撤销一个已提交事务的影响,将数据从人为不正确的操作中进行恢复。在采用闪回技术之前,只能通过备份恢复、PITR等手段找回已提交的数据库修改,恢复时长需要数分钟甚至数小时。采用闪回技术后,恢复已提交的数据库修改前的数据,只需要秒级,而且恢复时间和数据库大小无关。 openGauss的闪回分为一下两类: 闪回查询 闪回表 **一、闪回查询** 基于MVCC多版本的数据恢复:适用于误删除、误更新、误插入数据的查询和恢复,用户通过配置旧版本保留时间,并执行相应的查询或恢复命令,查询或恢复到指定的时间点或CSN点。 前提条件(下面三个缺一不可) undo_retention_time:参数用于设置undo旧版本的保留时间。 undo_zone_count=16384 ---代表的时候undo log的一种资源个数 enable_default_ustore_table=on --默认指定用户创建表时使用USTORE存储引擎。 存储引擎:Ustore Ustore存储引擎将最新版本的“有效数据”和历史版本的“垃圾数据”分离存储。将最新版本的“有效数据”存储在数据页面上,并单独开辟一段UNDO空间,用于统一管理历史版本的“垃圾数据”,因此数据空间不会由于频繁更新而膨胀,“垃圾数据”集中回收效率更高。 设置参数命令如下: gs_guc set -N all -I all -c "undo_retention_time=2000s" gs_guc set -N all -I all -c "undo_zone_count=16384" gs_guc set -N all -I all -c "enable_default_ustore_table=on" 设置完重启数据库: gs_om -t restart 重启后验证参数: openGauss=# show undo_retention_time; undo_retention_time --------------------- 2000s (1 row) openGauss=# show undo_zone_count; undo_zone_count ----------------- 16384 (1 row) openGauss=# show enable_default_ustore_table; enable_default_ustore_table ----------------------------- on (1 row) openGauss=# 下面开始演示: 创建表: openGauss=# CREATE TABLE flashback_tab( id int not null, name text not null); openGauss-# CREATE TABLE 查看表存储引擎: openGauss=# \d+ flashback_tab; Table "public.flashback_tab" Column | Type | Modifiers | Storage | Stats target | Description --------+---------+-----------+----------+--------------+------------- id | integer | not null | plain | | name | text | not null | extended | | Has OIDs: no Options: orientation=row, compression=no, storage_type=USTORE, toast.storage_type=USTORE 插入数据: insert into flashback_tab values (1,'ybj'); 查询当前日期; openGauss=# select current_timestamp; pg_systimestamp ------------------------------- 2022-09-29 01:13:32.691158+08 (1 row) 查询数据: openGauss=# select * from flashback_tab; id | name ----+------ 1 | ybj (1 row) 插入数据: openGauss=# insert into flashback_tab values (2,'yangkai'); INSERT 0 1 查询结果: openGauss=# select * from flashback_tab; id | name ----+--------- 1 | ybj 2 | yangkai (2 rows) ---基于timestamp的闪回查询: openGauss=# SELECT * FROM flashback_tab TIMECAPSULE TIMESTAMP to_timestamp ('2022-09-29 01:13:32.691158', 'YYYY-MM-DD HH24:MI:SS.FF'); id | name ----+------ 1 | ybj (1 row) ---查询timestamp对应的CSN openGauss=# select snptime,snpcsn from gs_txn_snapshot where snptime between '2022-09-29 01:13:32.691158' and ' 2022-09-29 01:15:24.921426' openGauss-# ; snptime | snpcsn -------------------------------+-------- 2022-09-29 01:13:32.841985+08 | 2112 2022-09-29 01:13:35.87922+08 | 2114 2022-09-29 01:13:38.924031+08 | 2116 2022-09-29 01:13:41.966247+08 | 2118 2022-09-29 01:13:45.013022+08 | 2120 2022-09-29 01:13:48.04741+08 | 2122 2022-09-29 01:13:51.078498+08 | 2124 2022-09-29 01:13:54.101686+08 | 2126 2022-09-29 01:13:57.123891+08 | 2128 2022-09-29 01:14:00.147156+08 | 2130 2022-09-29 01:14:03.169433+08 | 2132 2022-09-29 01:14:06.192879+08 | 2134 2022-09-29 01:14:09.216963+08 | 2136 2022-09-29 01:14:12.240249+08 | 2138 2022-09-29 01:14:15.26606+08 | 2140 2022-09-29 01:14:18.288409+08 | 2142 2022-09-29 01:14:21.309986+08 | 2144 2022-09-29 01:14:24.332801+08 | 2146 2022-09-29 01:14:27.378095+08 | 2148 2022-09-29 01:14:30.416234+08 | 2151 2022-09-29 01:14:33.460251+08 | 2153 2022-09-29 01:14:36.508431+08 | 2155 ---基于CSN的闪回查询 openGauss=# SELECT * FROM flashback_tab TIMECAPSULE CSN 2116; id | name ----+------ 1 | ybj (1 row) **二、闪回表** 基于类似windows系统回收站的恢复:适用于误DROP、误TRUNCATE的表的恢复。用户通过配置回收站开关,并执行相应的恢复命令,可以将误DROP、误TRUNCATE的表找回。 前置条件:开启回收站、设置回收站对象保留时间 enable_recyclebin=on 启用回收站。 recyclebin_retention_time=30min 参数用于设置回收站对象保留时间,超过该时间的回收站对象将被自动清理。 命令如下: gs_guc set -N all -I all -c "enable_recyclebin=on" gs_guc set -N all -I all -c "recyclebin_retention_time=30min" 设置完重启数据库: gs_om -t restart [omm@huaweidb ~]$ gsql -d postgres -p 15400 gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:34 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. openGauss=# show recyclebin_retention_time; recyclebin_retention_time --------------------------- 30min (1 row) openGauss=# show enable_recyclebin; enable_recyclebin ------------------- on (1 row) openGauss=# 下面开始操作演示: [omm@huaweidb ~]$ gsql -d postgres -p 15400 gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:34 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. --查询当前表 openGauss=# select * from flashback_tab ; id | name ----+--------- 1 | ybj 2 | yangkai (2 rows) --truncate表 openGauss=# truncate flashback_tab; TRUNCATE TABLE openGauss=# select * from flashback_tab ; id | name ----+------ (0 rows) ---闪回表 openGauss=# timecapsule table flashback_tab to before truncate; TimeCapsule Table --查询结果 openGauss=# select * from flashback_tab ; id | name ----+--------- 1 | ybj 2 | yangkai (2 rows) --drop 表 openGauss=# drop table flashback_tab; DROP TABLE openGauss=# select * from flashback_tab; ERROR: relation "flashback_tab" does not exist on dn_6001 LINE 1: select * from flashback_tab; ^ --查看回收站: openGauss=# sELECT rcyname,rcyoriginname,rcytablespace FROM GS_RECYCLEBIN; rcyname | rcyoriginname | rcytablespace ------------------------------+----------------------+--------------- BIN$3C7C4EB8014$30BE34C8==$0 | pg_toast_32783_index | 0 BIN$3C7C4EB8012$30BE3AA0==$0 | pg_toast_32783 | 0 BIN$3C7C4EB800F$30BE40B0==$0 | flashback_tab | 0 BIN$3C7C4EB800F$30BEA658==$0 | flashback_tab | 0 BIN$3C7C4EB8014$30BEAF78==$0 | pg_toast_32783_index | 0 BIN$3C7C4EB8012$30BEB560==$0 | pg_toast_32783 | 0 (6 rows) --通过回收站闪回表并命名flashback_yangkai; openGauss=# timecapsule table flashback_tab to before drop rename to flashback_yangkai; TimeCapsule Table openGauss=# select * from flashback_yangkai; id | name ----+--------- 1 | ybj 2 | yangkai (2 rows) **三、总结** openGauss 闪回非常强大,可以秒杀国产大部分数据库,基本可以满足日常运维需求,希望后期可以推出类似oracle数据库级别闪回、snapshot standby就完美了。
所有 PR 依赖均已合并(1个已合并)
!701
【openGauss技术文章征集】一种可能是目前最快的从ORACLE同步数据到MogDB(openGauss)的方式
怎样手动合并此 Pull Request
git checkout master
git pull https://gitee.com/opengauss/blog.git master
git push origin master
评论
10
提交
7
文件
2
检查
代码问题
0
批量操作
展开设置
折叠设置
审查
Code Owner
审查人员
tongdabao
tongdabao
guohuan
spaceoddity91719
zhang cuiping
zcp100_zcp100
Kamus
kamusis
liuxu-enmo
mogliu
jiangxiaoying
jiangxiaoying1
sky-stars
sky-stars
cchen676
struggle_hw
刘贵宾
vipl
胡正超
gentle_hu
周聪
congzhou2603
舛扬
zijianli16
lestertt
lestertt
mentoswang
mentoswang
胡君
hujunjune
吴冬儿
wu-donger
樊雅清
fyqlpl
Freyaqqianjin
freyaqqianjin
kangyang
ylfan96
liyang
liyang0608
zhengxue
shirley_zhengx
邦邦邦邦
gzbang
未设置
最少人数
0
测试
tongdabao
tongdabao
guohuan
spaceoddity91719
zhang cuiping
zcp100_zcp100
Kamus
kamusis
liuxu-enmo
mogliu
jiangxiaoying
jiangxiaoying1
sky-stars
sky-stars
cchen676
struggle_hw
刘贵宾
vipl
胡正超
gentle_hu
周聪
congzhou2603
舛扬
zijianli16
lestertt
lestertt
mentoswang
mentoswang
胡君
hujunjune
吴冬儿
wu-donger
樊雅清
fyqlpl
Freyaqqianjin
freyaqqianjin
kangyang
ylfan96
liyang
liyang0608
zhengxue
shirley_zhengx
邦邦邦邦
gzbang
未设置
最少人数
0
优先级
不指定
严重
主要
次要
不重要
标签
opengauss-cla/no
sig/docs
ci-pipeline-running
needs-issue
关联 Issue
未关联
Pull Request 合并后将关闭上述关联 Issue
里程碑
未关联里程碑
参与者
(2)
Cherry-pick 提交
Cherry-pick 可以将
特定提交(Commit)
从某个分支挑选并应用到另一个分支,实现快速集成特定更改,而无需合并整个分支。
请选择应用 Cherry-pick 提交 (Commit) 的目标分支
新建分支
当前账号不存在 Fork 仓库,建议 cherry-pick 到 Fork 仓库。
Fork 仓库
提交列表
Commit SHA
Commit Message
基于 Cherry-pick 后的分支发起 Pull Request
取消
Cherry-pick
1
https://gitee.com/opengauss/blog.git
git@gitee.com:opengauss/blog.git
opengauss
blog
blog
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册