Applicability
OceanBase Database Community Edition currently does not support transparent data encryption.
When you decrypt a table, you must first move it out of the encrypted tablespace and then process the existing encrypted data through major compaction. Decryption is asynchronous, so a successful tablespace change does not mean that all existing data has been decrypted.
Background information
This topic uses the example of moving table t1 from the encrypted tablespace sectest_ts1 to the unencrypted tablespace ts2. Before the operation, table t1 has undergone storage encryption and contains encrypted macroblocks.
You can execute the SHOW CREATE TABLE t1 statement to view the tablespace to which the table belongs, and query the following views to check the encryption status.
obclient> SELECT TABLE_NAME, ENCRYPTED, BLOCKS_ENCRYPTED, BLOCKS_DECRYPTED, STATUS FROM oceanbase.V$OB_ENCRYPTED_TABLES WHERE TABLE_NAME = 't1';
Here, BLOCKS_ENCRYPTED indicates the number of encrypted macroblocks, and BLOCKS_DECRYPTED indicates the number of unencrypted macroblocks. If tables with the same name exist in the tenant, you must also confirm the target table by checking the TABLE_ID in the view.
Move the table out of the encrypted tablespace and complete decryption
Log in to the MySQL-compatible tenant of the database as an administrator and go to the database where the table
t1is located.Create an unencrypted tablespace named
ts2.obclient> CREATE TABLESPACE ts2;Move table
t1from the encrypted tablespacesectest_ts1to the unencrypted tablespacets2.obclient> ALTER TABLE t1 TABLESPACE ts2;Execute the following statement to confirm that the tablespace specified in the CREATE TABLE statement has changed to
ts2. This step only confirms the tablespace change; it does not mean that the existing data has been decrypted.obclient> SHOW CREATE TABLE t1;Perform progressive compactions on the table after you move it out of the encrypted tablespace.
Set
progressive_merge_numto a value greater than1and execute theOPTIMIZEstatement to prepare for progressive compaction. The following example sets it to3.obclient> ALTER TABLE t1 SET progressive_merge_num = 3; obclient> OPTIMIZE TABLE t1;Manually initiate one round of major compaction.
obclient> ALTER SYSTEM MAJOR FREEZE;Query the major compaction status of the current tenant.
obclient> SELECT FROZEN_SCN, LAST_SCN, STATUS, IS_ERROR FROM oceanbase.DBA_OB_MAJOR_COMPACTION;Wait until
STATUSisIDLE,IS_ERRORisNO, andLAST_SCNmatchesFROZEN_SCNof the current round before you initiate the next round of major compaction. Repeat the above steps for each round of progressive compaction. Do not assume that decryption is complete just because you have submitted multiple major compaction requests in a row.Note
ALTER SYSTEM MAJOR FREEZEinitiates a tenant-level major compaction in the current user tenant. After the major compaction is completed, the decryption status may still beDECRYPTING. Do not assume that decryption is complete just because the command returns success or the specified number of rounds has been executed. Continue to check the encryption status of the table.
Query the
oceanbase.V$OB_ENCRYPTED_TABLESview to confirm the decryption status of the tables.obclient> SELECT TABLE_NAME, ENCRYPTED, BLOCKS_ENCRYPTED, BLOCKS_DECRYPTED, STATUS FROM oceanbase.V$OB_ENCRYPTED_TABLES WHERE TABLE_NAME = 't1';If decryption is not complete, the query result may be as follows. The number of macroblocks varies depending on the data volume and processing progress. The actual query result prevails.
+------------+-----------+------------------+------------------+------------+ | TABLE_NAME | ENCRYPTED | BLOCKS_ENCRYPTED | BLOCKS_DECRYPTED | STATUS | +------------+-----------+------------------+------------------+------------+ | t1 | NO | 1 | 3 | DECRYPTING | +------------+-----------+------------------+------------------+------------+ 1 row in setAt this point,
ENCRYPTEDisNO, but encrypted macroblocks still exist, so decryption is not complete. After the major compaction is completed, continue to wait and check the status. Decryption is complete when the target table meets all of the following conditions:ENCRYPTEDisNO.BLOCKS_ENCRYPTEDis0.STATUSisNORMAL.
The following is an example of the query result after decryption is complete:
+------------+-----------+------------------+------------------+--------+ | TABLE_NAME | ENCRYPTED | BLOCKS_ENCRYPTED | BLOCKS_DECRYPTED | STATUS | +------------+-----------+------------------+------------------+--------+ | t1 | NO | 0 | 3 | NORMAL | +------------+-----------+------------------+------------------+--------+ 1 row in setIf the status does not meet the above conditions, check the major compaction progress and error messages. For more information about the fields of the view, see V$OB_ENCRYPTED_TABLES.