Updated on 2024-08-20 GMT+08:00

Ledger Database Functions

  • get_dn_hist_relhash(text, text)

    Description: Returns the hash value of table-level data in a specified tamper-proof user table. This function can be invoked only between distributed nodes. A message indicating insufficient permission is displayed when all users invoke this function.

    Parameter type: text

    Return type: hash16

  • ledger_hist_check(text, text)

    Description: Verifies the consistency between the hash value of table-level data in a specified tamper-proof user table and that in the corresponding history table.

    Parameter type: text

    Return type: Boolean

    Example:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    -- Create a schema.
    gaussdb=# CREATE SCHEMA ledgernsp WITH BLOCKCHAIN;
    -- Create a table.
    gaussdb=# CREATE TABLE ledgernsp.tab(a int, b text);
    -- Insert data.
    gaussdb=# INSERT INTO ledgernsp.tab values(generate_series(1, 10000), 'test');
    gaussdb=# SELECT ledger_hist_check('ledgernsp','tab');
     ledger_hist_check
    -------------------
     t
    (1 row)
    
  • ledger_hist_repair(text, text)

    Description: Restores the hash value of the history table corresponding to the specified tamper-proof user table to be the same as that of the user table, and returns the hash difference.

    Parameter type: text

    Return type: hash16

    Example:

    1
    2
    3
    4
    5
    gaussdb=# SELECT ledger_hist_repair('ledgernsp','tab');
     ledger_hist_repair
    --------------------
     0000000000000000
    (1 row)
    
  • ledger_hist_archive(text, text)

    Description: Archives the history table corresponding to a specified tamper-proof user table to the hist_back folder in the audit log directory.

    Parameter type: text

    Return type: Boolean

    Example:

    1
    2
    3
    4
    5
    gaussdb=# EXECUTE DIRECT ON (datanode1) 'select pg_catalog.ledger_hist_archive(''ledgernsp'', ''tab'');';
     ledger_hist_archive
    ---------------------
     t
    (1 row)
    
  • ledger_gchain_check(text, text)

    Description: Verifies the consistency between the history table hash corresponding to the specified tamper-proof user table and the relhash corresponding to the global history table.

    Parameter type: text

    Return type: Boolean

    Example:

    1
    2
    3
    4
    5
    gaussdb=# SELECT ledger_gchain_check('ledgernsp','tab'); 
     ledger_gchain_check
    ---------------------
     t
    (1 row)
    
  • ledger_gchain_repair(text, text)

    Description: Restores relhash of a specified tamper-proof user table in the global history table so that the hash is the same as that in the history table, and returns the total hash value of the specified table.

    Parameter type: text

    Return type: hash16

    Example:

    1
    2
    3
    4
    5
    gaussdb=# SELECT ledger_gchain_repair('ledgernsp','tab'); 
     ledger_gchain_repair
    ----------------------
     da30c1260af5be50
    (1 row)
    
  • ledger_gchain_archive(void)

    Description: Archives global history tables to the hist_back folder in the audit log directory.

    Parameter type: void

    Return type: Boolean

    Example:

    1
    2
    3
    4
    5
    gaussdb=# SELECT ledger_gchain_archive(); 
     ledger_gchain_archive
    -----------------------
     t
    (1 row)
    
  • hash16in(cstring)

    Description: Converts the input hexadecimal string into the internal hash16 format.

    Parameter type: cstring

    Return type: hash16

  • hash16out(hash16)

    Description: Converts internal hash16 data to hexadecimal cstring data.

    Parameter type: hash16

    Return type: cstring

  • hash32in(cstring)

    Description: Converts the input hexadecimal string (32 characters) into the internal type hash32.

    Parameter type: cstring

    Return type: hash32

  • hash32out(hash32)

    Description: Converts internal hash32 data to hexadecimal cstring data.

    Parameter type: hash32

    Return type: cstring