查询指定时间点的表数据
通过快照点闪回数据库的方式受限于快照点的数量和间隔,无法精确闪回到某个指定的时间,于是ConshGuard还提供了查询某张表指定时间点的功能。
通过指定时间点来查询某张表的功能需要安装pg_dirtyread插件。
假设需要查询test
表的2024-01-10 15:01:40+08时间点的数据。
首先运行下面的SQL获得误删除的表的各个列的定义:
postgres=# select consh_gen_table_cols('test_fb');
consh_gen_table_cols
-----------------------------------------------------------------------------------------------------------------------
tableoid oid, ctid tid, xmin xid, xmax xid, cmin cid, cmax cid, dead boolean, id integer, tm timestamp with time zone
(1 row)
然后把上面的输出中的内容替换下面的SQL中的as t(X)
中的X部分:
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时间点的数据:
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);
tableoid | ctid | xmin | xmax | cmin | cmax | dead | id | tm
----------+--------+------+------+------+------+------+----+-------------------------------
18090562 | (0,1) | 8042 | 8043 | 0 | 0 | t | 75 | 2024-01-10 15:01:01.468669+08
18090562 | (0,66) | 8033 | 8043 | 0 | 0 | t | 66 | 2024-01-10 14:56:54.754206+08
18090562 | (0,67) | 8034 | 8043 | 0 | 0 | t | 67 | 2024-01-10 14:57:01.12277+08
18090562 | (0,68) | 8035 | 8043 | 0 | 0 | t | 68 | 2024-01-10 14:57:31.164265+08
18090562 | (0,69) | 8036 | 8043 | 0 | 0 | t | 69 | 2024-01-10 14:58:01.207221+08
18090562 | (0,70) | 8037 | 8043 | 0 | 0 | t | 70 | 2024-01-10 14:58:31.251475+08
18090562 | (0,71) | 8038 | 8043 | 0 | 0 | t | 71 | 2024-01-10 14:59:01.294713+08
18090562 | (0,72) | 8039 | 8043 | 0 | 0 | t | 72 | 2024-01-10 14:59:31.336454+08
18090562 | (0,73) | 8040 | 8043 | 0 | 0 | t | 73 | 2024-01-10 15:00:01.382129+08
18090562 | (0,74) | 8041 | 8043 | 0 | 0 | t | 74 | 2024-01-10 15:00:31.425634+08
(10 rows)
目录