Archiving a Ledger Database
Prerequisites
- You are an audit administrator or a role that has the AUDITADMIN permission.
- The database is running properly, and a series of addition, deletion, and modification operations are performed on the tamper-proof database to ensure that operation records are generated in the ledger for query.
- The storage path audit_directory of audit files has been correctly configured in the database.
Context
- Currently, the ledger database provides two archiving APIs: ledger_hist_archive(text, text) and ledger_gchain_archive(text, text). Only audit administrators can call the ledger database APIs.
- The API for archiving the user history table is pg_catalog.ledger_hist_archive. To archive the table, run the following command:
SELECT pg_catalog.ledger_hist_archive(schema_name text,table_name text);
If the archiving is successful, the function returns t. Otherwise, the function returns f and the cause of failure.
-
The API for archiving the global blockchain table is pg_catalog.ledger_gchain_archive. To archive the table, run the following command:
SELECT pg_catalog.ledger_gchain_archive();
If the archiving is successful, the function returns t. Otherwise, the function returns f and the cause of failure.
Procedure
- Archive a specified user history table.
1
gaussdb=# SELECT pg_catalog.ledger_hist_archive('ledgernsp', 'usertable');
The command output is as follows:ledger_hist_archive --------------------- t (1 row)
The user history table is archived as a record:gaussdb=# SELECT * FROM blockchain.ledgernsp_usertable_hist; rec_num | hash_ins | hash_del | pre_hash ---------+------------------+------------------+---------------------------------- 3 | e78e75b00d396899 | 8fcd74a8a6a4b484 | fd61cb772033da297d10c4e658e898d7 (1 row)
The command output indicates that the user history table of the current node is exported successfully.
- Export the global blockchain table.
1
gaussdb=# SELECT pg_catalog.ledger_gchain_archive();
The command output is as follows:
ledger_gchain_archive ----------------------- t (1 row)
The global history table will be archived to n (number of user tables) data records by user table:
gaussdb=# SELECT * FROM gs_global_chain; blocknum | dbname | username | starttime | relid | relnsp | relname | relhash | globalhash | txcommand ----------+----------+----------+-------------------------------+-------+-----------+-----------+------------------+----------------------------------+----------- 1 | testdb | libc | 2021-05-10 19:59:38.619472+08 | 16388 | ledgernsp | usertable | 57c101076694b415 | be82f98ee68b2bc4e375f69209345406 | Archived. (1 row)
The command output indicates that the global blockchain table of the current node is successfully exported.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot