云数据库 GAUSSDB-闪回查询:使用示例

时间:2024-11-01 17:07:52

使用示例

  • 示例(需将undo_retention_time参数设置为大于0的值):
    gaussdb=# DROP TABLE IF EXISTS "public".flashtest;
    NOTICE:  table "flashtest" does not exist, skipping
    DROP TABLE
    --创建表flashtest
    gaussdb=# CREATE TABLE "public".flashtest (col1 INT,col2 TEXT) WITH(storage_type=ustore);
    CREATE TABLE
    --查询csn
    gaussdb=# SELECT int8in(xidout(next_csn)) FROM gs_get_next_xid_csn();
      int8in  
    ----------
     79351682
    (1 rows)
    --查询当前时间戳
    gaussdb=# select now();
                  now              
    -------------------------------
     2023-09-13 19:35:26.011986+08
    (1 row)
    --插入数据
    gaussdb=# INSERT INTO flashtest VALUES(1,'INSERT1'),(2,'INSERT2'),(3,'INSERT3'),(4,'INSERT4'),(5,'INSERT5'),(6,'INSERT6');
    INSERT 0 6
    gaussdb=# SELECT * FROM flashtest;
     col1 |  col2   
    ------+---------
        3 | INSERT3
        1 | INSERT1
        2 | INSERT2
        4 | INSERT4
        5 | INSERT5
        6 | INSERT6
    (6 rows)
    --闪回查询某个csn处的表
    gaussdb=# SELECT * FROM flashtest TIMECAPSULE  CS N 79351682;
     col1 | col2 
    ------+------
    (0 rows)
    gaussdb=# SELECT * FROM flashtest;
     col1 |  col2   
    ------+---------
        1 | INSERT1
        2 | INSERT2
        4 | INSERT4
        5 | INSERT5
        3 | INSERT3
        6 | INSERT6
    (6 rows)
    --闪回查询某个时间戳处的表
    gaussdb=# SELECT * FROM flashtest TIMECAPSULE TIMESTAMP '2023-09-13 19:35:26.011986';
     col1 | col2 
    ------+------
    (0 rows)
    gaussdb=# SELECT * FROM flashtest;
     col1 |  col2   
    ------+---------
        1 | INSERT1
        2 | INSERT2
        4 | INSERT4
        5 | INSERT5
        3 | INSERT3
        6 | INSERT6
    (6 rows)
    --闪回查询某个时间戳处的表
    gaussdb=# SELECT * FROM flashtest TIMECAPSULE TIMESTAMP to_timestamp ('2023-09-13 19:35:26.011986', 'YYYY-MM-DD HH24:MI:SS.FF');
     col1 | col2 
    ------+------
    (0 rows)
    --闪回查询某个csn处的表,并对表进行重命名
    gaussdb=# SELECT * FROM flashtest AS ft TIMECAPSULE CSN 79351682;
     col1 | col2 
    ------+------
    (0 rows)
    gaussdb=# DROP TABLE IF EXISTS "public".flashtest;
    DROP TABLE
support.huaweicloud.com/fg-gaussdb-cent-v8/gaussdb-48-0202.html