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, storage encryption is enabled for table t1 and encrypted macroblocks exist in the table.
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 SYS.V$OB_ENCRYPTED_TABLES WHERE TABLE_NAME = 'T1';
In these views, 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 check the TABLE_ID column in the V$OB_ENCRYPTED_TABLES view to identify the target table.
Remove the table from the encrypted tablespace and complete decryption
Log in to an Oracle tenant of a cluster as an administrator, and execute the following statements in the schema to which table
t1belongs.Create an unencrypted tablespace named
ts2.obclient> CREATE TABLESPACE ts2;Move the
t1table from 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 theSHRINK SPACEstatement to prepare for progressive compaction. The following example sets it to3.obclient> ALTER TABLE t1 SET progressive_merge_num = 3; obclient> ALTER TABLE t1 SHRINK SPACE;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 SYS.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
The
ALTER SYSTEM MAJOR FREEZEstatement initiates 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
SYS.V$OB_ENCRYPTED_TABLESview to check the decryption status of the table.obclient> SELECT TABLE_NAME, ENCRYPTED, BLOCKS_ENCRYPTED, BLOCKS_DECRYPTED, STATUS FROM SYS.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 | 25 | 0 | DECRYPTING | +------------+-----------+------------------+------------------+------------+ 1 row in setIn this case, the
ENCRYPTEDcolumn is set toNO, 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 the following conditions:- The
ENCRYPTEDcolumn is set toNO. - The
BLOCKS_ENCRYPTEDcolumn is set to0. - The
STATUScolumn is set toNORMAL.
The following is an example of the query result after decryption is complete:
+------------+-----------+------------------+------------------+--------+ | TABLE_NAME | ENCRYPTED | BLOCKS_ENCRYPTED | BLOCKS_DECRYPTED | STATUS | +------------+-----------+------------------+------------------+--------+ | T1 | NO | 0 | 5 | 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.
- The