首页
解决方案
数据库专业技术服务全栈式PostgreSQL解决方案Oracle分布式存储化数据库云PolarDB一体化解决方案
产品
CLup:PostgreSQL高可用集群平台 CMiner: PostgreSQL中的CDC CData高性能数据库云一体机 CBackup数据库备份恢复云平台 CPDA高性能双子星数据库机 CSYun超融合虚拟机产品 ZQPool数据库连接池 ConshGuard数据保护产品 APCC: Greenplum管理平台
文档
文章
客户及伙伴
中启开源
关于我们
公司简介 联系我们
中启开源
修改标题
往前插入
往后插入
删除

查询指定时间点的表数据

通过快照点闪回数据库的方式受限于快照点的数量和间隔,无法精确闪回到某个指定的时间,于是ConshGuard还提供了查询某张表指定时间点的功能。

通过指定时间点来查询某张表的功能需要安装pg_dirtyread插件。

假设需要查询test表的2024-01-10 15:01:40+08时间点的数据。

首先运行下面的SQL获得误删除的表的各个列的定义:

  1. postgres=# select consh_gen_table_cols('test_fb');
  2. consh_gen_table_cols
  3. -----------------------------------------------------------------------------------------------------------------------
  4. tableoid oid, ctid tid, xmin xid, xmax xid, cmin cid, cmax cid, dead boolean, id integer, tm timestamp with time zone
  5. (1 row)

然后把上面的输出中的内容替换下面的SQL中的as t(X)中的X部分:

  1. select * from consh_query_table_by_time('test_fb'::regclass, '2024-01-10 15:01:40+08'::timestamptz) as t(X);

执行上面的SQL,查询出test表在2024-01-10 15:01:40+08时间点的数据:

  1. postgres=# select * from consh_query_table_by_time('test_fb'::regclass, '2024-01-10 15:01:40+08'::timestamptz) as t(tableoid oid, ctid tid, xmin xid, xmax xid, cmin cid, cmax cid, dead boolean, id int, tm timestamptz);
  2. tableoid | ctid | xmin | xmax | cmin | cmax | dead | id | tm
  3. ----------+--------+------+------+------+------+------+----+-------------------------------
  4. 18090562 | (0,1) | 8042 | 8043 | 0 | 0 | t | 75 | 2024-01-10 15:01:01.468669+08
  5. 18090562 | (0,66) | 8033 | 8043 | 0 | 0 | t | 66 | 2024-01-10 14:56:54.754206+08
  6. 18090562 | (0,67) | 8034 | 8043 | 0 | 0 | t | 67 | 2024-01-10 14:57:01.12277+08
  7. 18090562 | (0,68) | 8035 | 8043 | 0 | 0 | t | 68 | 2024-01-10 14:57:31.164265+08
  8. 18090562 | (0,69) | 8036 | 8043 | 0 | 0 | t | 69 | 2024-01-10 14:58:01.207221+08
  9. 18090562 | (0,70) | 8037 | 8043 | 0 | 0 | t | 70 | 2024-01-10 14:58:31.251475+08
  10. 18090562 | (0,71) | 8038 | 8043 | 0 | 0 | t | 71 | 2024-01-10 14:59:01.294713+08
  11. 18090562 | (0,72) | 8039 | 8043 | 0 | 0 | t | 72 | 2024-01-10 14:59:31.336454+08
  12. 18090562 | (0,73) | 8040 | 8043 | 0 | 0 | t | 73 | 2024-01-10 15:00:01.382129+08
  13. 18090562 | (0,74) | 8041 | 8043 | 0 | 0 | t | 74 | 2024-01-10 15:00:31.425634+08
  14. (10 rows)
目录
img