Monday, November 16, 2009

Speed your backup and recovery with new features in Oracle Database 10g



John, the lead DBA at Acme Bank, is at the IT center of attention in a high-level company acquisition. Recently Acme Bank acquired another bank, taking over its entire technology infrastructure. One special area of interest is the other bank's data warehouse database, which has been recently upgraded to Oracle Database 10g. After the takeover, the management of Acme has asked John for some major enhancements in the operation of the other bank's data warehouse database. In the high-availability area, John has been asked to substantially reduce the recovery time from a database failure, because the current recovery time is not acceptable. Of course, having to pay for the acquisition, Acme has asked John to improve the database recovery time without investing in new servers and software licenses.

With the many powerful new features that Recovery Manager (RMAN) provides in Oracle Database 10g, John has several enhancements in mind, the combined result of these enhancements being faster backup and recovery without investing in expensive new hardware or database licenses. This article shows John's thought process, objectives, and strategy for meeting the company's goal of faster recoveries, while discussing RMAN and other key Oracle Database 10g features available to him. This article is not an introduction to RMAN; refer to the link in Next Steps at the end of this article for information on RMAN basics.


Brainstorming Recovery

The current backup strategy for the acquired bank's data warehouse uses standard RMAN backup features: a full backup once a month and an incremental backup each week. The archived logs are backed up once a day. All backups are sent over the network to the server that hosts the tape drives. The backups go directly to tape; they do not get copied to the server's hard disks and therefore do not require any disk storage space on that server.

So, if a recovery is needed, the full backup set has to be restored first; then all the incremental backup sets have to be applied to it; and finally, the archived logs have to be applied to bring the database to the prefailure state. With the application of so many backup sets and archived logs, the recovery naturally takes considerable time.

Looking at the limitations of the current RMAN backup setup and the requirement from Acme Bank upper management to reduce recovery time, John decides on three main objectives to satisfy management's requirements:
  • Increase the frequency of incremental backups without affecting database performance, and do the backups in less time. This will require a change in the current use of RMAN for incremental backups.
  • Reduce recovery time using only RMAN—no additional servers and software—using a strategy of backing up to disk first and then to tape.
  • Reduce the size of the incremental backups and therefore reduce the database CPU cycles and the network traffic caused by RMAN incremental backups.

Use Block Change Tracking

The acquired bank's data warehouse runs on Oracle Database 10g, which offers a few tools John can use to achieve his objectives. For the first objective, he decides to use the Block Change Tracking feature, new in this version. Block change tracking causes the changed database blocks to be flagged in a special file.

All John needs to do is to enable block change tracking by issuing the following command:
 
ALTER DATABASE ENABLE 
BLOCK CHANGE TRACKING USING FILE 
'/oracle/admin/SMILEY/bct.dbf';

Now any time a block is changed in the database, the fact is recorded in this special file: /oracle/admin/SMILEY/ bct.dbf. 

During incremental backup, RMAN checks this file to see which blocks need to be backed up instead of checking all the blocks of a data file. It dramatically reduces CPU cycles and speeds up incremental backup in the process. The block change tracking file, if present, is used automatically by the incremental backup; no special RMAN syntax is required. Using a block change tracking file saves enough time and CPU cycles for John to take incremental backups every day (or night) instead of once a week.

How big will this block change tracking file be? The size of this file does not depend on the frequency or the size of updates to the database. For John's data warehouse database, a single instance with one old backup retained, the file will be approximately 10MB for 1TB of total database size, 20MB for 2TB, and so on.

John can ensure that block change tracking is turned on and check the location and name of the file used by querying a new dictionary view:
 
SELECT * FROM V$BLOCK_CHANGE_TRACKING;
The output is shown in vertical format:
STATUS  : ENABLED
FILENAME: /oracle/admin/SMILEY/bct.dbf
BYTES   : 11599872

Here the file size is about 11MB, for John's test database of about 1TB. John can also change the location of this file. One option is to do a normal data file rename when the database is in the MOUNTED state:
 
ALTER DATABASE RENAME FILE 
'/oracle/admin/SMILEY/bct.dbf' 
TO '/tmp/bct.dbf';

If a database shutdown is not an option, John can disable the tracking and re-enable it with a different filename as follows:
 
SQL> ALTER DATABASE 
DISABLE BLOCK CHANGE TRACKING;
Database altered.
 
SQL> ALTER DATABASE 
ENABLE BLOCK CHANGE TRACKING 
USING FILE '/tmp/bct.dbf';
 
Database altered.

However, re-enabling block change tracking this way will reset the tracking, erasing all history of the earlier backups.


Using Incremental Merge

Now that John has a plan to address the first objective—to reduce the time required for incremental backup—he moves on to the next objective—to reduce the recovery time using only RMAN. Since incremental backups will be feasible every day thanks to the block change tracking file, John proposes a new backup strategy and schedule, shown in Table 1.

With the new strategy, every Sunday the Level 0 (full) backup will be taken and tagged WEEKLY. Every day the Level 1 (incremental) backups will be taken with tags that show the day of the week; for example, Monday's backup set is tagged MON. In this strategy, the RMAN command used for the Level 0 backup will be:
 
BACKUP INCREMENTAL 
LEVEL 0 TAG = WEEKLY DATABASE; 

This will create an RMAN backup set with the tag WEEKLY. The daily RMAN command for Monday will look like the following:

Backup Incremental LEVEL 1 TAG = MON DATABASE;

The daily command will be repeated for all other days, with appropriate tag values representing the weekday. After a week, if John queries the RMAN recovery catalog, he will see something similar to Listing 1.

Now let's examine a failure scenario with John's revised incremental backup schedule (which includes daily incremental backups). If the data file for tablespace USERS fails on Saturday, John has to restore the Level 0 backup taken (with tag WEEKLY) on Sunday and then apply all the incremental backups with keys from 36 through 46 from the output shown in Listing 1. After that he needs to apply the archived logs. The restore and recovery operations are shown in Listing 2. Note how all the incremental backups with tags MON, TUE, and so on are applied one after the other. After all of the incremental backups have been applied, the media recovery begins and applies the information in the archived logs.

If a full backup had been taken every day, the recovery would not have had to apply all the incremental backups, saving considerable time. But since that is not possible, what if John could apply the incremental backups taken on weekdays to the Level 0 backup taken earlier? This would make the Level 0 backup up-to-date with the latest day's changes and eliminate the need to apply all the subsequent incremental backups during recovery. In Oracle Database 10g, using a disk-based backup strategy, John can accomplish that using the Incremental Merge feature of the RMAN backup. With such an approach, the daily RMAN incremental backup script will look like this:
 
BACKUP INCREMENTAL LEVEL 1 
FOR RECOVER OF COPY 
WITH TAG WEEKLY DATABASE;
 
RECOVER COPY OF DATABASE 
WITH TAG WEEKLY;

When this command is executed every day, the incremental backups are applied to the Level 0 backup with the tag WEEKLY. Each incremental backup is merged with the current full backup, making it a complete up-to-date backup as of that day. For instance, this command executed on Monday will make the Level 0 backup taken on Sunday up-to-date as if it were a Level 0 (full) backup taken on Monday. In this situation, if the data file for tablespace USERS fails on Saturday, the RMAN restore operation will restore from the backup taken and merged with the Level 0 backup on Friday, since that will be most up-to-date, and then apply all the archived logs. Both the traditional RMAN operation (done by the old bank) and the Incremental Merge operation available in Oracle Database 10g are compared in Table 2.

The biggest time savings in Table 2 is in Step 2: the application of incremental backups is not necessary in John's proposed strategy, where the daily incremental backups are merged with the weekly full backup. This makes recovery very fast, satisfying his second objective and Acme Bank's main requirement.

Adding ASM

John's proposed use of disk-based backups and the addition of daily incremental backups requires a set of disks large enough to hold the full and at least one incremental backup temporarily. Since the old bank's backup solution wrote backups directly to tape and Acme's management wants to keep costs down, how does John justify a disk-based backup approach?

Enterprise-class disks in a storage area network (SAN), typically used with enterprise databases, are expensive. However, for the backup location, John proposes adding low-cost Serial ATA (SATA) disks to the data warehouse server to be the staging and merging location for backups.

SATA disks have a reputation of being slower and less reliable than enterprise-class disks, and John acknowledges that in his recommendations. He also mentions the fact that SATA disks cost much less than enterprise-class disks and that their reliability and performance can be significantly increased under Automatic Storage Management (ASM).

John is not asking for a new server or operating system; however, he is proposing that the SATA drives be located under ASM on the same server as the data warehouse database. Using ASM on a set of inexpensive disks like SATA makes the disk group mirrored, increasing its reliability, and striped, increasing the performance over that of a single disk. Other built-in features of ASM, such as kernelized asynchronous I/O and direct I/O, make the performance comparable to high-end disk systems. Best of all, ASM comes bundled with Oracle Database 10g with no extra cost—hence, no need to invest in an expensive file system.

John proposes these three steps:
1.     Create an ASM instance on the data warehouse server.
You do this by creating a parameter file with a special parameter named INSTANCE_TYPE=ASM and bringing up the instance. Note that there are no control files, redo log files, or data files for ASM instances.
2.     Once the ASM instance is started, create a disk group RMANDG as follows:
3.  CREATE DISKGROUP rmandg
4.  NORMAL REDUNDANCY
5.  FAILGROUP failgrp1 DISK
6.  '/dev/d1',
7.  '/dev/d2',
8.  FAILGROUP failgrp2 DISK
9.  '/dev/d3',
10.'/dev/d4';
 This assumes that John has four disks with which he wants to make an ASM group. He can expand it to as many disks as he likes. The above disk group is analogous to mirrored disks with the creation of failure groups, and each failure group is striped across two disks.
11.   Change the flash recovery area of the database to point to the disk group:
12.ALTER SYSTEM SET DB_RECOVERY_FILE_DEST = '+RMANDG'
Note the plus (+) sign before the disk group name, which indicates an ASM disk group.

RMAN backups by default go to the location specified by the parameter DB_RECOVERY_FILE_DEST, which is the disk group rmandg. In addition to the backups, the disk group can hold archived logs and control file backups. If the database has flashback enabled, the flashback logs are stored here as well.

Files inside an ASM location are not accessible as operating system files. To get the backups and archived logs from the ASM disk group to regular disks and tapes, John will use RMAN to back up the recovery area from ASM to tape (at the network backup server) through the following command:
 
BACKUP RECOVERY AREA;

This backs up the entire recovery area, including data file backups, archived logs, and control file backups from the ASM disk group to the tape.

There is no need to keep multiple copies of the backups on tape. The following RMAN command deletes the old backup sets:
 
DELETE OBSOLETE DEVICE TYPE sbt;

John proposes to back up the ASM disks to tape every week, so the tapes will contain a week's worth of data. In case of a data warehouse database failure, the recovery can be quick from the SATA disks. If the disks fail, the database can also be recovered from the tape.

Reducing Traffic with Compression

John's last objective is to reduce the size of the incremental backups significantly so that they do not overwhelm the network. John addresses this issue by proposing to enable the compression feature of RMAN, which uses a proprietary algorithm to compress the backup sets. John's proposed backup scripts change a little to add the compression feature:
 
BACKUP AS COMPRESSED INCREMENTAL 
LEVEL 1 TAG = WEEKLY DATABASE;

The clause AS COMPRESSED compresses data in the backup sets before sending them to the backup location. A compressed backup set means fewer bytes are transferred across the network, allowing incremental backups to be taken everyday without interfering with the regular network traffic. When the time comes to restore the backup sets, RMAN can read the compressed backup sets directly without having to first uncompress them. RMAN compression is also compatible with the Incremental Merge.


Conclusion

Reducing costs and time have been the goals of many projects at Acme Bank. John summarizes his proposed backup strategy in Table 3, presenting his plan in terms of the resources it saves. With a significantly reduced backup and recovery time, minimal disk costs, and reduced network bandwidth requirements, John's proposals are accepted with much appreciation.

REFERENCES

Faster Backup, Faster Recovery By Arup Nanda, Oracle Corporation

Build a flexible infrastructure to protect sensitive data



John, the lead DBA at Acme Bank, is involved in a very important initiative regarding security and privacy. Jane, the chief information security officer of the company, has outlined Acme's security strategy, and John has identified his team's responsibilities.

Enterprise security, Jane explains at a meeting with IT managers at Acme, can be thought of as a series of protective layers. To illustrate her point, Jane uses a nesting doll—a doll with a hollow body inside which another hollow doll is kept, which, in turn, contains another hollow doll, and so on. The last of four or five of these hollow dolls contains some type of prize. Getting to the prize means removing the layers of the dolls one by one, and if the layers can't be removed for some reason, the prize becomes increasingly difficult to get to. To get to corporate information assets, Jane explains, an intruder must also defeat many layers of security.

The first layer of defense is the firewall around the whole information infrastructure of the organization, which keeps outsiders from accessing any of the information sources inside the company. However, no organization is an island and firewalls are far from airtight; "holes" or ports are necessary to let legitimate traffic from outside flow in.

If an intruder gets past the external firewall, that person will be required to supply a password to access the server or perhaps be asked to provide other authentication credentials such as security certificates. This is the next layer of security. After being authenticated, the legitimate user must be allowed to access only those assets that person is supposed to access. If a user gets into the database but has no authority to see any table, view, or any other data source, the information is still protected. This mechanism is the next layer of security.

Jane stresses that it is possible for an intruder to somehow defeat all of the protective measures and get to the enterprise data. From a planning perspective, this possibility must be accepted, analyzed, and accounted for. The only option left for defending against an intruder at this point, the last layer of security, is to alter the data, via a process known as encryption, in such a way that the intruder will not find it useful. Encryption alters data to make it unreadable to all except those who know how to decipher the information.

Database Encryption

When John leaves the IT managers' meeting, he immediately calls together his direct reports to talk about his team's encryption strategy and implementation.

He presents his take on the encryption strategy to his team, beginning with a brief overview of the encryption process. He presents a simple example in which the account balance value is altered by the addition of a secret one-digit number. If the secret number is 2, for example, and the real balance value is 3467, the encrypted value will be 3469. The real value can be deciphered from the encrypted value by the deduction of the number 2, a process known as decryption, John explains. This logic of adding a specific number to the real data is called the encryption algorithm. Here, the value 2, which is added by the algorithm, is known as the encryption key. Encrypting a value involves passing the original data and the encryption key to the encryption algorithm to create encrypted data.

During decryption, the logic is reversed, producing the original value. Because the same key is used to encrypt and decrypt, this scheme is also known as symmetric encryption.

Encryption algorithms are most often in the public domain; hence, the security lies in choosing a difficult-to-guess key. If hackers were to guess the 1-digit key, in this example, they would have to take only as many as 10 guesses—a number from 0 to 9. However, if the key were two digits, they would have to take as many as 100 guesses—a number from 0 to 99. The longer the key, John explains, the more difficult it is to guess it.

Oracle-Supplied Packages

In Oracle Database 10g, John continues, users can implement these encryption techniques by using functions and procedures available in a built-in package named DBMS_CRYPTO. Another package, DBMS_OBFUSCATION_TOOLKIT, also available in Oracle Database 10g and earlier releases, offers a subset of the functionality provided by DBMS_CRYPTO. But because Acme Bank's systems are built on Oracle Database 10g, the newer package offers more functionality, and Oracle recommends it over the older toolkit, John decides to use the DBMS_CRYPTO package, and no one in the room disagrees.

Key Generation. Because the security of the encrypted value depends on how hard it is to guess the key, using an appropriate key is a major step in the encryption process. A key can be any value of data type RAW, but unless it is random enough, an intruder will be able to guess the key. For instance, John warns, the key can't be something such as your pet's name or your date of birth; it must be truly random. "How do you generate such a random key?" asks one junior DBA. John answers that random values can be generated with the built-in package DBMS_RANDOM, but true cryptographically acceptable randomness means using the function RANDOMBYTES in the package DBMS_CRYPTO. This function accepts one parameter of data type BINARY_INTEGER and produces a RAW value of that length. This value can then be used as a key. John demonstrates the usage with a simple PL/SQL routine, shown in Listing 1.

Code Listing 1: Encrypting a value
  1  declare
  2     enc_val   raw (2000);
  3     l_key     raw (2000);
  4     l_key_len number := 128;
  5     l_mod     number := dbms_crypto.ENCRYPT_AES128
  6                       + dbms_crypto.CHAIN_CBC
  7                       + dbms_crypto.PAD_PKCS5;
  8  begin
  9     l_key   := dbms_crypto.randombytes (l_key_len);
10     enc_val := dbms_crypto.encrypt
11        (
12           UTL_I18N.STRING_TO_RAW ('SECRET', 'AL32UTF8'),
13           l_mod,
14           l_key
15        );
16      -- The encrypted value enc_val can be used here
17  end;   

Explaining the code, John points out that the DBMS_CRYPTO package offers several types of algorithms and associated 
key lengths for Acme's encryption project.

The first column in Table —Constant Name—shows the constant defined in the package to specify the different algorithms and the key length. For instance, to specify a 128-bit key according to the Advanced Encryption Standard (AES), you use the constant DBMS_CRYPTO.ENCRYPT_AES128, John explains (see line 5 of Listing 1). The longer the key, the less the chance that an intruder will be able to guess it but the more work the server has to do during encryption and decryption. To strike a balance between security and stress on the server, John chooses the middle ground—a 128-bit-key AES algorithm.

Next, the type of chaining, which divides the data into chunks to prepare for encryption in block ciphering, is defined, as shown in Listing 1, line 6. The most common format is Cipher Block Chaining (CBC), specified by a constant defined in the DBMS_CRYPTO package as CHAIN_CBC. Other chaining options include Electronic Code Book format (CHAIN_ECB), Cyber Feedback (CHAIN_CFB), and Output Feedback (CHAIN_OFB).

Finally, in block ciphering, John explains, the data is usually encrypted in blocks of eight characters. If the length of the input data is not a multiple of eight, you add a character or characters, in a process known as padding. A simple option is to use zeroes as padding. John points out that the constant PAD_ZERO defined in the DBMS_CRYPTO package pads with zeroes but that padding with zeroes is not considered very secure, because a potential intruder might be able to guess that. More-secure padding is based on Public-Key Cryptography Standards # 5 (PCKS#5), specified by the constant PKCS5 in the DBMS_CRYPTO package and demonstrated in Listing 1, line 7. If you're sure, John comments, that the length of the data is already a multiple of the block size, there is no need to pad, and you can specify that by using the constant PAD_NONE.

 These three parameters—the algorithm with the key length, the chaining method, and the padding method—are all combined and passed to the built-in function ENCRYPT in DBMS_CRYPTO. The ENCRYPT function needs this input value to be a RAW data type. Listing 1, line 12 converts the input value to a RAW value, which is then passed to the ENCRYPT function.

As a means of standardization, John continues, Acme has made a decision to adopt the AES algorithm with 128-bit keys, CBC chaining, and PCKS #5 padding across all applications. Using these values, John builds a simpler function GET_ENC_VAL, shown in Listing 2, that accepts only two parameters—the input value and the key—and returns the encrypted value.

Code Listing 2: A simple encryption function
  1  create or replace function get_enc_val
  2  (
  3     p_in    in varchar2,
  4     p_key   in raw
  5  )
  6  return raw is
  7     l_enc_val raw (2000);
  8     l_mod     number := dbms_crypto.ENCRYPT_AES128
  9                      + dbms_crypto.CHAIN_CBC
10                      + dbms_crypto.PAD_PKCS5;
11  begin
12     l_enc_val := dbms_crypto.encrypt
13        (
14           UTL_I18N.STRING_TO_RAW
15              (p_in, 'AL32UTF8'),
16           l_mod,
17           p_key
18        );
19     return l_enc_val;
20* end;


Decryption

"When the time comes to decipher the encoded data, how do we do it?" asks Jill, one of John's developers.
John explains that DBMS_CRYPTO has a function for that too: DECRYPT. It accepts the source data to be decrypted; the key used during encryption; and the combined parameter of algorithm, key length, chaining, and padding schemes. The same key and the modifiers used during encryption must be passed along with the value to be decrypted. Because Acme Bank uses a standard algorithm, key length, and padding, John creates a simple function to decrypt encrypted values, as shown in Listing 3. This function accepts only two parameters—the encrypted value and the key—and returns the decrypted value as a VARCHAR2 data type. The conversion from the RAW data type is done in line 20 of Listing 3.

Code Listing 3: A simple decryption function
  1  create or replace function get_dec_val
  2  (
  3     p_in    in raw,
  4     p_key   in raw
  5  )
  6  return varchar2
  7  is
  8     l_ret     varchar2 (2000);
  9     l_dec_val raw (2000);
10     l_mod     number := dbms_crypto.ENCRYPT_AES128
11                       + dbms_crypto.CHAIN_CBC
12                       + dbms_crypto.PAD_PKCS5;
13  begin
14     l_dec_val := dbms_crypto.decrypt
15        (
16           p_in,
17           l_mod,
18           p_key
19        );
20        l_ret:= UTL_I18N.RAW_TO_CHAR
21                     (l_dec_val, 'AL32UTF8');
22             return l_ret;
23* end;


Key Management

With the building blocks in place, John's team is looking for a complete encryption solution built on the DBMS_CRYPTO package. The biggest challenge in encryption, John explains, is not generating keys or using the functions but managing the keys used in the encryption process. Because the same key is used to encrypt and decrypt a value, it must be reliably guarded to protect the data. At the same time, however, the applications and users must have access to the keys to decrypt the values for normal use. The challenge is figuring out where to store the keys and how to make sure they are available to legitimate users only, John explains. He lays out two options for managing keys:

1.     Use the same key for all records
2.     Use a different key for each record

With option 1, John continues, a single key is used to encrypt the value in all the rows. In this case, there are several options for storing the key:
  • In the database—A key table owned by a special non-application owner can be used to store the key. John writes a simple function that merely returns the key as an output parameter. The users receive execute privileges in this procedure, and no user has any privileges on the key table. The function contains several checks and balances to make sure users have the proper privileges to get the key. Because the function is the only source for getting the key, users can be authenticated easily and given access to the key.
  • In the filesystem—Keeping the key in the database protects from most intruders but not from DBAs who may have access to any table. In addition, making sure users making requests are indeed legitimate can be very difficult. Storing the key in a filesystem DBAs don't have access to, even on a different server such as an application server, may be a better idea. However, this also means that if the key is somehow lost because filesystems are damaged, the encrypted data is lost as well, forever.
  • With the user—A third option, John shows, can be to let users keep the key somewhere, such as on a memory stick or a client machine. This way, no one other than legitimate users can access the sensitive data. This is particularly useful in situations such as in data warehouses where encrypted data is sent regularly to users who have the key already. If the data is stolen along the way, the sensitive information is still protected. However, the risk of data loss is highest here, because users are more likely to lose the key.

John proposes the "With the user" single-key solution for a small number of cases, such as publishing summarized content to various users who have received the keys earlier.

The biggest drawback of this approach is the vulnerability of the key to theft. If the key is stolen, all the data in the database is compromised. Therefore, John suggests a different approach to protecting sensitive data in OLTP databases. The database has a table named ACCOUNT_MASTER, where a sensitive data element, the account holder's name, is stored. The column containing the name, ACC_NAME, needs to be encrypted. The primary key of the table is ACCOUNT_NO. Here is what the ACCOUNT_MASTER table looks like:
 
SQL> desc account_master
 
Name        Null?     Type
----------  --------  ------------
ACCOUNT_NO  NOT NULL  NUMBER
ACC_NAME              VARCHAR2(200)
ACC_TYPE              CHAR(1)

John suggests using a different key for each row of the ACCOUNT_MASTER table, which eliminates the risk of databasewide exposure in case of a key theft. He creates a table called ACCOUNT_MASTER_ENC to store the encrypted values of the account name and creates another table to hold the keys used to encrypt the values. These tables—ACCOUNT_MASTER_ENC and ACCOUNT_MASTER_KEYS—look like this:
 
SQL> desc account_master_enc
 
Name           Null?     Type
------------   --------  --------    
ACCOUNT_NO     NOT NULL  NUMBER
ACC_NAME_ENC             RAW(2000)
SQL> desc account_master_keys
 
Name       Null?     Type
----------  --------  ---------  
ACCOUNT_NO  NOT NULL  NUMBER
KEY         NOT NULL  RAW(2000)

Next John creates the view VW_ACCOUNT_MASTER, shown in Listing 4, to join these three tables to get the decrypted value. He points out line 8 in Listing 4, where the value is decrypted with the function GET_DEC_VAL mentioned earlier. Because the function returns a value as a VARCHAR2 data type, it will be shown as a VARCHAR2(2000) column; hence, line 7 has a CAST function to make it a VARCHAR2(20) type.

This view, not the table, is what is granted to the other users. John creates a public synonym ACCOUNT_MASTER pointing to the view VW_ACCCOUNT_MASTER, not to the table of the same name.

Code Listing 4: View for account master
  1  create or replace view
  2     vw_account_master
  3  as
  4  select
  5     m.account_no as account_no,
  6     m.acc_type as acc_type,
  7     cast (
  8             get_dec_val (e.acc_name_enc, k.key)
  9     as varchar2(20)) as acc_name
10  from
11     account_master m,
12     account_master_enc e,
13     account_master_keys k
14  where
15     k.account_no = e.account_no
16*    and m.account_no = e.account_no; 

Because the public synonym ACCOUNT_MASTER points to the view, users can select from the view, but Jill the developer asks how the users will manipulate the data in the table. By using an INSTEAD OF trigger (shown in Listing 5), explains John. This trigger manipulates the data in the table whenever a user inserts or updates the view. The INSTEAD OF trigger fires when the data is either inserted or updated in the view, which, in turn, does an INSERT or UPDATE on the actual tables. While updating, it makes sure the encrypted values are also updated.

Code Listing 5: INSTEAD OF trigger on the view
  1  create or replace trigger io_vw_acc_master
  2  instead of insert or update on
  3  vw_account_master
  4  for each row
  5  declare
  6     l_key    raw(2000);
  7  begin
  8     if (inserting) then
  9        l_key := dbms_crypto.randombytes (128);
10        insert into account_master
11        (account_no, acc_type, acc_name)
12        values
13        (
14           :new.account_no,
15           :new.acc_type,
16           :new.acc_name
17        );
18        insert into account_master_enc
19        (account_no, acc_name_enc)
20        values
21        (
22           :new.account_no,
23           get_enc_val (
24              :new.acc_name,
25              l_key )
26        );
27        insert into account_master_keys
28        (account_no, key)
29        values
30        (
31           :new.account_no,
32           l_key
33        );
34     else
35        select key
36        into l_key
37        from account_master_keys
38        where account_no = :new.account_no;
39        update account_master
40        set acc_name = :new.acc_name,
41           acc_type = :new.acc_type
42        where account_no = :new.account_no;
43        update account_master_enc
44        set acc_name_enc =
45           get_enc_val (:new.acc_name, l_key)
46        where account_no = :new.account_no;
47     end if;
48* end;

Because the users can't see the data in the table but only through the view, the information is protected. A different view can be built on the base table to show only encrypted values, protecting the original contents.

Further Security

John then leads a discussion on refining the encryption key storage and access process even further. The group spends time discussing secure application contexts and how they will allow use of just one view that will behave differently for users of different authorization levels.
The meeting ends; John sends a quick e-mail to Jane, letting her know that the encryption plan is in place, and he offers to demonstrate it to her at her earliest convenience.

REFERENCES

Encrypt Your Data Assets By Arup Nanda, Oracle Corporation


Concepts of and sample questions on space usage


Oracle Database 10g provides a variety of features for managing the space usage of a tablespace. These features include the monitoring of tablespace usage, the ability to suspend transactions that require more space and successfully resume them when the space is available, and a database advisor that lets you determine whether an object has space available for reclamation.

This column presents sample questions on managing tablespace usage. The questions are of the type you may encounter when taking the Oracle Database 10g Administration Workshop II exam. The Oracle Database 10g Administration Workshop II exam is one of the two exams you must take to achieve the Oracle Certified Professional (OCP) level of certification. Note that the sample question format has been adjusted for presentation in this column.

Monitoring Tablespace Space Usage

Oracle Database 10g provides proactive help for managing the disk space usage of a tablespace. It alerts you when tablespaces run low on available space. Two space-used alert thresholds are defined by default: warning and critical. The warning threshold is the limit at which space starts to run low. The critical threshold is a serious limit that warrants your immediate attention. The database issues alerts at both thresholds.

You can modify the default threshold values and also disable the space-used threshold alerts for a tablespace.

You do not want to use the default threshold values for space used for the EXAMPLE tablespace. Which package would you use to explicitly set the space-used threshold values for a tablespace?

A. DBMS_SERVICE
B.
DBMS_SERVER_ALERT
C.
DBMS_STORAGE_MAP
D.
DBMS_TRACE

The correct answer is B. You can use the SET_THRESHOLD procedure in the DBMS_SERVER_ALERT package to set the space-used threshold values for a particular tablespace. Alternatively, you can use Oracle Enterprise Manager 10g to set the space-used threshold values.

The USERS_TBS tablespace does not include autoextensible datafiles. Identify the situation in which server-managed threshold alerts for tablespace space usage will not be generated for the USERS_TBS tablespace.

A. If USERS_TBS is a bigfile tablespace
B. If
USERS_TBS is the default permanent tablespace
C. If
USERS_TBS is a temporary tablespace
D. If
USERS_TBS is a dictionary-managed tablespace
E. If
USERS_TBS is an UNDO tablespace

The correct answer is D. Server-managed threshold alerts for tablespace space usage are supported only for locally managed tablespaces, not for dictionary-managed tablespaces. Answers A, B, and C are incorrect because server-managed threshold alerts are supported for bigfile tablespaces, default permanent tablespaces, and temporary tablespaces. Answer E is incorrect because server-managed threshold alerts are supported for UNDO tablespaces.

You created a locally managed tablespace by using the following SQL statement:
 
CREATE TABLESPACE TEST_TBS
DATAFILE 'test.dat' SIZE 1M 
AUTOEXTEND ON MAXSIZE 100M;

You set the warning threshold limit to 60 percent for the TEST_TBS tablespace. Which statement is correct regarding the server-managed tablespace space usage threshold alerts in this scenario?

A. A warning alert will be generated when 60K of space is used.
B. No alerts will be generated, because it is not a bigfile tablespace.
C. No alerts will be generated, because the tablespace includes an autoextensible datafile.
D. A warning alert will be generated when 60MB of space is used.
E. A warning alert will be generated when 60MB of space is left as free space.


The correct answer is D. Answer A is incorrect because for tablespaces with autoextensible files, the thresholds are computed according to the maximum file size you specified or the maximum file size of the operating system. Answers B and C are incorrect because the alerts are generated for smallfile tablespaces as well as for tablespaces with autoextensible datafiles. Answer E is incorrect because the alerts are based on the space used and not on the free space left in a tablespace.


Resumable Space Allocation

In the event of space allocation failures, rather than returning the error to the user and stopping the operation, the transaction can be temporarily suspended and corrective action taken. After the error condition is corrected, the suspended operation automatically resumes. This feature is called resumable space allocation. The affected statements are called resumable statements.

Which two statements are correct regarding the resumable space allocation feature?

A. Resumable space allocation can be enabled only at the system level and not at the session level.
B. When a resumable statement is suspended, an error is reported in the alert log.
C. Every resumable operation has a "time out" period associated with it.
D. A resumable statement can be suspended and resumed only once during execution.


The correct answers are B and C. When the execution of a resumable statement is suspended, the system issues a Resumable Session Suspended alert. A suspended operation is automatically aborted if the error condition is not fixed within the time-out period. By default, the time-out period is two hours. Answer A is incorrect because you can enable resumable space allocation either at the system level, by setting the RESUMABLE_TIMEOUT initialization parameter to a nonzero value, or at the session level, by issuing the ALTER SESSION ENABLE RESUMABLE statement. Answer D is incorrect because a resumable statement can be suspended and resumed multiple times during execution.

Which statements are resumable? (Choose all that apply.)

A. INSERT INTO ... SELECT from external tables statement
B.
CREATE TABLE ... AS SELECT statement
C.
CREATE TABLESPACE statement
D.
SELECT statement
E.
CREATE USER statement

The correct answers are A, B, and D. DML statements, including INSERT INTO ... SELECT from external tables, are resumable. The interface used to execute the DML statements does not matter. DDL statements, including CREATE TABLE ... AS SELECT, are resumable. SELECT statements that run out of temporary space are also candidates for resumable execution.

Under which three error conditions can the resumable space allocation feature be used?

A. The user has exceeded his or her assigned space quota in the tablespace.
B. The number of extents in a table or index equals the number of maximum extents defined on the object.
C. The operation cannot acquire any more extents for an index in a tablespace.
D. The user application tries to access a table for which the user does not have necessary privileges.
E. The user-specified datafile size exceeded the maximum operating system file size.


The correct answers are A, B, and C. A resumable statement can be suspended under any of these conditions: space quota exceeded, maximum extents reached, and out of space.


Database Advisors

Oracle Database 10g provides a set of component advisors that provide useful feedback about resource utilization and performance. These advisors enable you to analyze the performance of your database, identify potential problems and bottlenecks, and tune the various components of your database.

DML operations on the objects within the USER_TBS tablespace have created pockets of empty space that individually are not big enough to be reused. This is leading to a large amount of wasted space in the USER_TBS tablespace. You plan to reclaim the wasted space through a shrink operation. Which advisor would you use to determine the objects in the USER_TBS tablespace that contain wasted space and are good candidates for the shrink operation?

A. SQL Tuning Advisor
B. Segment Advisor
C. Undo Advisor
D. SQL Access Advisor


The correct answer is B. You can use the Segment Advisor to determine whether an object has space available for reclamation on the basis of the level of space fragmentation within the object. The Segment Advisor can generate advice at three levels: object level (such as table), tablespace level, and segment level.
You can use the SQL Tuning Advisor for tuning SQL statements. The Undo Advisor improves transaction management, especially for automatic-undo management. The SQL Access Advisor provides recommendations for creating indexes and materialized views for a given workload.

Conclusion

You can use space-used threshold values to proactively manage the space in tablespaces. Space usage exceeding the threshold values raises alerts, allowing you to take action to ensure that there is space available. Resumable space allocation lets you suspend a statement temporarily, so that when more space is available, the transaction can resume and complete. The Segment Advisor—one of many database advisors—lets you identify unused space so that you can reclaim it.

REFERENCES
Efficient Space Management By Aradhana Puri , Oracle Corporation