暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

亚信安慧AntDB数据库DDL数据闪回基础介绍(2)

北陌 2023-12-06
78

4.2 闪回drop使用示例

1、创建表,插入测试数据

antdb =# create table t(f1 int);

CREATE TABLE

antdb =# insert into t values(1),(2),(3);

INSERT 0 3

-- 确认数据已插入

antdb =# select * from t;

 f1

----

  1

  2

  3

(3 rows)

-- 确认表结构,供后续闪回表之后做对比

antdb =# \d+ t

                                     Table "public.t"

 Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description

--------+---------+-----------+----------+---------+---------+--------------+-------------

 f1     | integer |           |          |         | plain   |              |

Access method: heap

 

2、误删除表

antdb =# drop table t;

DROP TABLE

-- 确认表被删除

antdb =# select count(*) from pg_class where oid='public.t'::regclass;

ERROR:  relation "public.t" does not exist

LINE 1: select count(*) from pg_class where oid='public.t'::regclass...

                                                ^

 

3、使用闪回功能闪回表,且恢复后的表数据和表结构与原表是否相同。

antdb =# select flashbackddl('t');

     flashbackddl

----------------------

 flashbackddl success

(1 row)

-- 查看表数据

antdb =# select * from t;

 f1

----

  1

  2

  3

(3 rows)

-- 查看表结构

antdb =# \d+ t

                                     Table "public.t"

 Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description

--------+---------+-----------+----------+---------+---------+--------------+-------------

 f1     | integer |           |          |         | plain   |              |

Access method: heap

 

4.3 闪回truncate使用示例

1、创建表,插入测试数据

antdb =# create table t(f1 int);

CREATE TABLE

antdb =# insert into t values(1),(2),(3);

INSERT 0 3

antdb =# select * from t;

 f1

----

  1

  2

  3

(3 rows)

 

2、误删除表数据,此时表数据为空

antdb =# truncate table t;

TRUNCATE TABLE

antdb =# select * from t;

 f1

----

(0 rows)

 

3、使用闪回功能恢复表中数据。

antdb =# select flashbackddl('t');

     flashbackddl

----------------------

 flashbackddl success

(1 row)

 

antdb =# select * from t;

 f1

----

  1

  2

  3

(3 rows)

 

5. 总结

本文主要介绍了AntDB数据库DDL数据闪回的基本原理和使用方法。AntDB通过这一功能,确保数据的完整性和可用性、降低了因误操作或数据损坏而导致的风险、提高了组织的数据管理效率。因此,了解和掌握AntDB数据库数据闪回的使用方法对于数据库管理员来说至关重要。

如果数据库专业人员对数据闪回的内部实现感到好奇,后续章节将为大家带来AntDB数据库DDL数据闪回的实现,敬请期待~


关于AntDB数据库

AntDB数据库始于2008年,在运营商的核心系统上,为全国24个省份的10亿多用户提供在线服务,具备高性能、弹性扩展、高可靠等产品特性,峰值每秒可处理百万笔通信核心交易,保障系统持续稳定运行近十年,并在通信、金融、交通、能源、物联网等行业成功商用落地。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论