Monday, June 1, 2020

Encrypting / Decrypting Tablespaces Online / Offline

Oracle database allow the ability to encrypt (or decrypt) tablespace online (or offline). Online method requires twice the space as the tablespace been worked on as work (encryption or decryption) happens out of place. In the offline method the work happens inplace as such in case of failure would need to recover from a backup. This post shows the online and offline encryption and decryption of an existing tablespace. It is assumed master key is already created for the database. The options could be interchanged, i.e. online encrypted tablespace could be decrypted offline and vice versa.

Online Encryption
The tablespace name stbs was chosen for encryption. Currently it's not encrypted (only the tablespace in question is shown).
SQL> select t.name,e.ENCRYPTIONALG,e.ENCRYPTEDTS,e.STATUS from V$ENCRYPTED_TABLESPACES e, v$tablespace t where t.ts#=e.ts#(+);

NAME                           ENCRYPT ENC STATUS
------------------------------ ------- --- ----------
STBS
Enable the encryption for the tablespace with encryption online encrypt.
SQL> ALTER TABLESPACE stbs ENCRYPTION ONLINE USING 'AES256' ENCRYPT;
Tablespace's encryption status will change to encryption.
SQL> select t.name,e.ENCRYPTIONALG,e.ENCRYPTEDTS,e.STATUS from V$ENCRYPTED_TABLESPACES e, v$tablespace t where t.ts#=e.ts#(+);

NAME                           ENCRYPT ENC STATUS
------------------------------ ------- --- ----------
STBS                           AES256  YES ENCRYPTING
Once the encryption is done status will change to normal
NAME                           ENCRYPT ENC STATUS
------------------------------ ------- --- ----------
STBS                           AES256  YES NORMAL
The alert log will show a intermediate data file being created for encryption and switching to it in the end.
2020-04-22T22:20:44.920971+10:00
ALTER TABLESPACE STBS ENCRYPTION ONLINE USING 'AES256' ENCRYPT
2020-04-22T22:20:44.953241+10:00
About to encrypt tablespace stbs (tsn 0/6)
Rekeying datafile +DATA/TESTDB1/DATAFILE/stbs.273.1035989447 (6) to +DATA
2020-04-22T22:22:22.315005+10:00
Rekey operation committed for file +DATA/TESTDB1/DATAFILE/stbs.297.1038435645
2020-04-22T22:22:24.436978+10:00
About to zero out original file "+DATA/TESTDB1/DATAFILE/stbs.273.1035989447"
2020-04-22T22:22:34.359115+10:00
Successfully zero'ed out original file "+DATA/TESTDB1/DATAFILE/stbs.273.1035989447"
Successfully deleted original file "+DATA/TESTDB1/DATAFILE/stbs.273.1035989447"
Completed rekey for tablespace stbs (tsn 0/6) from key version 0 to 1.
Completed: ALTER TABLESPACE STBS ENCRYPTION ONLINE USING 'AES256' ENCRYPT

Online Decryption
The same tablespace is used for decrypting. Being the decryption by specifying encryption online and decrypt.
SQL>  ALTER TABLESPACE stbs ENCRYPTION online DECRYPT;
The tablespace status change to decrypting during this process.
NAME                           ENCRYPT ENC STATUS
------------------------------ ------- --- ----------
stbs                         NONE    NO  DECRYPTING
Alert log shows new datafile created and switched to at the end.
2020-04-22T22:36:42.446452+10:00
 ALTER TABLESPACE stbs ENCRYPTION online DECRYPT
2020-04-22T22:36:42.485372+10:00
About to decrypt tablespace stbs (tsn 0/6)
Rekeying datafile +DATA/TESTDB1/DATAFILE/stbs.297.1038435645 (6) to +DATA
2020-04-22T22:38:14.303037+10:00
Rekey operation committed for file +DATA/TESTDB1/DATAFILE/stbs.273.1038436603
2020-04-22T22:38:16.437063+10:00
About to zero out original file "+DATA/TESTDB1/DATAFILE/stbs.297.1038435645"
2020-04-22T22:38:26.331705+10:00
Successfully zero'ed out original file "+DATA/TESTDB1/DATAFILE/stbs.297.1038435645"
Successfully deleted original file "+DATA/TESTDB1/DATAFILE/stbs.297.1038435645"
Completed rekey for tablespace stbs (tsn 0/6) from key version 3 to 4.
Completed:  ALTER TABLESPACE stbs ENCRYPTION online DECRYPT


Offline Encryption
Offline encryption requires taking the tablespace offline and encrypting and brining it back online. As said earlier it doesn't require double the space as work happens inline.
SQL> alter tablespace stbs offline normal;

SQL>  ALTER TABLESPACE stbs ENCRYPTION OFFLINE  USING 'AES256' ENCRYPT;

SQL> alter tablespace stbs online;

SQL> select t.name,e.ENCRYPTIONALG,e.ENCRYPTEDTS,e.STATUS from V$ENCRYPTED_TABLESPACES e, v$tablespace t where t.ts#=e.ts#(+);
NAME                           ENCRYPT ENC STATUS
------------------------------ ------- --- ----------
stbs                           AES256  YES NORMAL
Alert log shows work happening inline.
2020-04-22T22:32:17.799065+10:00
alter tablespace stbs offline normal
Completed: alter tablespace stbs offline normal
2020-04-22T22:33:05.102693+10:00
 ALTER TABLESPACE stbs ENCRYPTION OFFLINE  USING 'AES256' ENCRYPT
2020-04-22T22:33:05.182112+10:00
About to offline encrypt tablespace 6 ..
2020-04-22T22:34:37.019647+10:00
Successfully encrypted tablespace 6 with database key.
Completed:  ALTER TABLESPACE stbs ENCRYPTION OFFLINE  USING 'AES256' ENCRYPT
2020-04-22T22:34:44.844771+10:00
alter tablespace stbs online
Completed: alter tablespace stbs online

Offline Decryption
Same as encryption to decrypt take the tablespace offline and decrypt.
SQL> alter tablespace stbs offline normal;

SQL> ALTER TABLESPACE stbs ENCRYPTION OFFLINE DECRYPT;

SQL> alter tablespace stbs online;

SQL> select t.name,e.ENCRYPTIONALG,e.ENCRYPTEDTS,e.STATUS from V$ENCRYPTED_TABLESPACES e, v$tablespace t where t.ts#=e.ts#(+);

NAME                           ENCRYPT ENC STATUS
------------------------------ ------- --- ----------
stbs
Alert log output for offline decryption.
2020-04-22T22:27:20.225977+10:00
alter tablespace STBS offline normal
Completed: alter tablespace stbs offline normal
2020-04-22T22:28:19.782418+10:00
ALTER TABLESPACE stbs ENCRYPTION OFFLINE DECRYPT
2020-04-22T22:28:19.860285+10:00
About to offline decrypt tablespace 6 ..
2020-04-22T22:29:47.629045+10:00
Successfully decrypted tablespace 6 with database key.
Completed: ALTER TABLESPACE stbs ENCRYPTION OFFLINE DECRYPT

Related Posts
19c Encryption
12c Encryption
Rekeying Master Key in a Data Guard Setup
Encrypting / Decrypting Tablespaces Online / Offline in a Data Guard Configuration

Tuesday, May 26, 2020

Reread resulted in same corrupt block on file 'spfil.ora' blockno=1

Active database duplication for standby fails with an error specific to 4k sector size. The primary database is Oracle restart with ASM where disks are on 4k emulation mode (512 logical sector and 4k physical sector). The spfile of the primary reside in the ASM disk (19c DB). During the active database duplicate command the primary would copy the spfile (with relavent changes specified by the duplication command) to the standby instance. But this location is not the ASM but $ORACLE_HOME/dbs. However, when the 4k emulation mode is involved this copying spfile from ASM to file system location results in following error on the primary DB rman session.
RMAN> duplicate target database for standby from active database
2> spfile
3> parameter_value_convert 'masterdb','masterdr','MASTERDB','MASTERDR'
set db_name='masterdb'
4> 5> set db_unique_name='masterdr'
6> set fal_server='masterdbtns'
7> set log_archive_dest_1='location=use_db_recovery_file_dest valid_for=(all_logfiles,all_roles) db_unique_name=masterdr NOREOPEN ALTERNATE=log_archive_dest_2'
8> set log_archive_dest_3='service=masterdbtns LGWR ASYNC NOAFFIRM max_failure=10 reopen=60 valid_for=(online_logfiles,primary_role) db_unique_name=masterdb'
9> set local_listener='LISTENER_MASTERDR';

Starting Duplicate Db at 28-JUN-19
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=268 device type=DISK

contents of Memory Script:
{
   backup as copy reuse
   passwordfile auxiliary format  '/opt/app/oracle/product/19.x.0/dbhome_1/dbs/orapwmasterdr'   targetfile
 '+DATA/masterdb/parameterfile/spfile.293.1012128045' auxiliary format
 '/opt/app/oracle/product/19.x.0/dbhome_1/dbs/spfilemasterdr.ora'   ;
   sql clone "alter system set spfile= ''/opt/app/oracle/product/19.x.0/dbhome_1/dbs/spfilemasterdr.ora''";
}
executing Memory Script

Starting backup at 28-JUN-19
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=575 device type=DISK
Finished backup at 28-JUN-19

sql statement: alter system set spfile= ''/opt/app/oracle/product/19.x.0/dbhome_1/dbs/spfilemasterdr.ora''


Reread resulted in same corrupt block on file '/opt/app/oracle/product/19.x.0/dbhome_1/dbs/spfilemasterdr.ora' blockno=1
Reread resulted in same corrupt block on file '/opt/app/oracle/product/19.x.0/dbhome_1/dbs/spfilemasterdr.ora' blockno=1
Reread resulted in same corrupt block on file '/opt/app/oracle/product/19.x.0/dbhome_1/dbs/spfilemasterdr.ora' blockno=1
Reread resulted in same corrupt block on file '/opt/app/oracle/product/19.x.0/dbhome_1/dbs/spfilemasterdr.ora' blockno=1

The error keeps repeating and no going forward from this point.

The solution was to move the DB spfile out of ASM into local disk ($ORACLE_HOME/dbs) and re-run the duplicate command. There were no issue in the subsequent execution.

Related Post
4K Sector, compatible.rdbms and Redo Log File Block Size

Thursday, May 21, 2020

DBCA Reports ORA-46385 When Oracle Home Has Unified Auditing Enabled

Running dbca in silent mode reports ORA-46385 if the Oracle home has unified auditing is enabled. Below is the output on the shell prompt (only relevant section of the output is shown). This was on 19c.
Creating data dictionary views
33% complete
38% complete
39% complete
40% complete
[WARNING] ORA-46385: DML and DDL operations are not allowed on table

41% complete
46% complete
49% complete
52% complete
57% complete
Oracle Text
Trace files shows the same.
[Thread-242] [ 2020-02-06 12:23:53.087 UTC ] [BasicStep.handleNonIgnorableError:541]  oracle.sysman.assistants.util.SilentMessageHandler@3a6532cd:messageHandler
[Thread-242] [ 2020-02-06 12:23:53.087 UTC ] [BasicStep.handleNonIgnorableError:542]  ORA-46385: DML and DDL operations are not allowed on table
:msg
WARNING: Feb 06, 2020 12:23:53 PM oracle.assistants.common.base.util.AssistantAdvisor logMessage
WARNING: [ 2020-02-06 12:23:53.088 UTC ] [WARNING] ORA-46385: DML and DDL operations are not allowed on table


The dbca can run till the end despite the error. However, if a clean error free installation is preferred then turn off the unified auditing on the Oracle home before running dbca. There's no error in this case (output shown around same % mark where error happened before). Enable unified auditing once database is created.
Creating data dictionary views
33% complete
38% complete
39% complete
40% complete
41% complete
46% complete
49% complete
52% complete
57% complete
Oracle Text