云数据库 GAUSSDB-查看账本历史操作记录:操作步骤

时间:2024-11-13 10:05:08

操作步骤

  1. 查询全局区块表记录。

    1
    gaussdb=# SELECT * FROM gs_global_chain;
    
    查询结果如下:
     blocknum |  dbname  | username |           starttime           | relid |  relnsp   |  relname  |     relhash      |            globalhash            |
                    txcommand
    ----------+----------+----------+-------------------------------+-------+-----------+-----------+------------------+----------------------------------+------------------
    ------------------------------------------------------------
            0 | testdb | omm      | 2021-04-14 07:00:46.32757+08  | 16393 | ledgernsp | usertable | a41714001181a294 | 6b5624e039e8aee36bff3e8295c75b40 | insert into ledge
    rnsp.usertable values(1, 'alex'), (2, 'bob'), (3, 'peter');
            1 | testdb | omm      | 2021-04-14 07:01:19.767799+08 | 16393 | ledgernsp | usertable | b3a9ed0755131181 | 328b48c4370faed930937869783c23e0 | update ledgernsp.
    usertable set name = 'bob2' where id = 2;
            2 | testdb | omm      | 2021-04-14 07:01:29.896148+08 | 16393 | ledgernsp | usertable | 0ae4b4e4ed2fcab5 | aa8f0a236357cac4e5bc1648a739f2ef | delete from ledge
    rnsp.usertable where id = 3;

    该结果表明,用户omm连续执行了三条DML命令,包括INSERT、UPDATE和DELETE操作。

  2. 查询历史表记录。

    1
    gaussdb=# SELECT * FROM blockchain.ledgernsp_usertable_hist;
    

    查询结果如下:

     rec_num |     hash_ins     |     hash_del     |             pre_hash
    ---------+------------------+------------------+----------------------------------
           0 | 1f2e543c580cb8c5 |                  | e1b664970d925d09caa295abd38d9b35
           1 | 8fcd74a8a6a4b484 |                  | dad3ed8939a141bf3682043891776b67
           2 | f51b4b1b12d0354b |                  | 53eb887fc7c4302402343c8914e43c69
           3 | 437761affbb7c605 | 8fcd74a8a6a4b484 | c2868c5b49550801d0dbbbaa77a83a10
           4 |                  | f51b4b1b12d0354b | 9c512619f6ffef38c098477933499fe3
    (5 rows)

    查询结果显示,用户omm对ledgernsp.usertable表插入了3条数据,更新了1条数据,随后删除了1行数据,最后剩余2行数据,hash值分别为1f2e543c580cb8c5和437761affbb7c605。

  3. 查询用户表数据及校验列。

    1
    gaussdb=# SELECT *, hash_69dd43 FROM ledgernsp.usertable;
    

    查询结果如下:

     id | name |       hash_69dd43
    ----+------+------------------
      1 | alex | 1f2e543c580cb8c5
      2 | bob2 | 437761affbb7c605
    (2 rows)

    查询结果显示,用户表中剩余2条数据,与2中的记录一致。

support.huaweicloud.com/fg-gaussdb-dist-v8/gaussdb-18-0022.html