oca ocp - oracle10g new features for administrators exam guide

618
1 Installation, Server Configuration, and Database Upgrades CERTIFICATION OBJECTIVES 1.01 Installation New Features Support 1.02 Performance Enhancements to the Installation Processs 1.03 Simplified Instance Configuration 1.04 Viewing Database Feature Usage Statistics 1.05 Supported Upgrade Paths to Oracle Database 10g 1.06 Using New Utility to Perform Pre-Upgrade Validation Checks 1.07 Using the Simplified Upgrade Process 1.08 Starting Up the Database Using a New Mode When Upgrading Two-Minute Drill Q&A Self Test

Upload: phungdan

Post on 08-Dec-2016

283 views

Category:

Documents


14 download

TRANSCRIPT

Page 1: OCA OCP - Oracle10G New Features For Administrators Exam Guide

1Installation, ServerConfiguration, and

Database Upgrades

CERTIFICATION OBJECTIVES

1.01 Installation New Features Support

1.02 Performance Enhancementsto the Installation Processs

1.03 Simplified Instance Configuration

1.04 Viewing Database Feature Usage Statistics

1.05 Supported Upgrade Paths to OracleDatabase 10g

1.06 Using New Utility to PerformPre-Upgrade Validation Checks

1.07 Using the Simplified Upgrade Process

1.08 Starting Up the Database Usinga New Mode When Upgrading

✓ Two-Minute Drill

Q&A Self Test

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1Blind Folio 1:1

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1Blind Folio 1:1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:43 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 2: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Oracle Corporation has ambitiously positioned Oracle Database 10g as asophisticated self-managing database. Note that you don’t refer to the new10g database as Oracle10g, as in Oracle9i. The correct name of our new

database is Oracle Database 10g. Throughout this text, I refer to the database as OracleDatabase 10g, although I may occasionally refer to it as simply Oracle 10g, for convenience.

The database server I use in this book is the Oracle Database 10g EnterpriseEdition Release 10.1.0.2.0. I use both a UNIX platform and a Windows platformfor most of the examples in this book. You can probably replicate several examplesin this book using a different version of the Oracle software, but you can get theEnterprise Edition software free from Oracle, so there isn’t any reason for not usingthat version. Practicing using the new features is essential not only for passing thetest, but also for learning the features well enough to implement them in yourdatabases. So, if you haven’t already downloaded the software, please do so now(from www.oracle.com).

The g in Oracle 10g, stands for grid computing. Grid computing is all the rage now,with IBM promoting “on-demand” computing, and Sun, HP, and other companiestalking about their own visions of grid computing. Regardless of what a particularcompany might name it, grid computing really means treating computing as a utility,somewhat like an electrical company’s power grid. When you want more or lesscomputing power, the grid will supply it to you automatically in a flexible manner.The following three attributes lie at the heart of grid computing:

■ Virtualization between the layers of the computing stack and the users

■ Dynamic provisioning of work among the available resources, based onchanging needs

■ Pooling of resources to maximize availability and utilization

Several new manageability-enhancing features, along with revamped older features,promise Oracle database administrators (DBAs) a very new way of managing theirpowerful Oracle databases. The main goals of this new approach are to reduceadministrative effort and capital expenditures, while simultaneously keeping failurecosts to a minimum. The changes start, as they should, right with the installation ofthe database software itself.

This first chapter discusses in detail features related to installation, configuration,and upgrading.

2 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:43 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 3: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Please refer to the Oracle Database 10g documentation for complete detailson a given feature. This book is intended to provide the information youneed for upgrading your Oracle OCP certification from Oracle9i to OracleDatabase 10g. (The complete name of the test required for upgrading yourcertification is Oracle Database 10g: New Features for Administrators (Exam#1Z0-040) Therefore, unless the feature is completely new to Oracle 10g,I don’t attempt to fully explain it in this book.

Let’s start our review of the new Oracle 10g installation features by looking atsome interesting changes in the installation process.

CERTIFICATION OBJECTIVE 1.01

Installation New Features SupportWhile the essential database software installation is through the familiar OracleUniversal Installer, there are several appealing changes in the Oracle Database 10ginstallation process itself. The entire installation process is simpler now, and thetypical server installation takes less than a half an hour to complete. Client installationscan now be done in less than a minute, and they require less than 70MB of disk space.

The following are some new features related to the Oracle Enterprise Serversoftware installation process:

■ Database management choices

■ Automatic pre-install checks

■ New file storage options

■ Backup and recovery options

■ Database user password specification

■ Cluster Ready Services

■ Enterprise Configuration Management Tool

■ OracleMetaLink integration

■ Oracle software cloning

■ Database cloning

Installation New Features Support 3

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:43 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 4: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Let’s look at each of these installation new features, starting with enhancementsin database management choices.

Database Management ChoicesAs part of the Oracle Database 10g software installation, Oracle offers you the choiceto create a “starter” database, as was the case in previous versions. However, now, youhave more management choices to make when you decide to let Oracle create thestarter database.

In Oracle9i, you could create the Oracle Enterprise Manager (OEM) centralmanagement setup (including database management, as well as host andnetwork management) as part of the normal database installation. In Oracle 10g,if you wish to configure a centralized (or grid-based) OEM capability, you mustconfigure this feature separately.

In Oracle9i, you needed to choose between an OEM console in the stand-alonemode or log in to the Oracle Management Server. In the stand-alone mode, youcould manage only your databases. In order to manage HTTP servers, events, andjobs, you needed to use the Oracle Management Server. You can now use the OEMin two fundamentally different ways:

■ You can manage your databases locally using the OEM Database Control,which is part of the Oracle 10g server software.

■ You can manage your databases centrally, through the OEM Grid Control,which is available on separate CDs.

The OEM Database Control comes with the Oracle Database 10gserver software.

The OEM Database Control is a web-based application that you can use to managea single Oracle 10g database. The Database Control simply lets you monitor andmanage a single database. You can access the Database Control by using a webbrowser; no configuration is necessary to start using the Database Control. Oracleautomatically installs the OEM Database Control in the same Oracle Home as yourOracle database.

Alternatively, you can install the OEM Grid Control tool, which lets youmonitor and manage several databases and servers at once. In order to use the OEMGrid Control, you need to configure and start the Oracle Management Agent oneach of the nodes you wish to monitor.

4 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:43 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 5: OCA OCP - Oracle10G New Features For Administrators Exam Guide

If you are managing a single database, the simple stand-alone OEM DatabaseControl is adequate. On the other hand, if you are in charge of several databaseson several hosts, you’ll need to install and use the OEM Grid Control. TheGrid Control includes the Oracle Management Agent, Oracle ManagementService, the Oracle Management Repository, and the Grid Control console.It is through the console that you perform all monitoring, configuration, andmanagement tasks for not only databases, but also for the various hostsand other services.

In Oracle9i databases, there was only one kind of OEM, and you had theoption of configuring it with or without Management Agents and the ManagementRepository. Now, Oracle is making a formal distinction between a local and centrallymanaged OEM.

The OEM Database Control runs with the help of a HTTP server, and you use aregular Internet browser to see the OEM interface. The default URL for the OEMDatabase Control is as follows:

http://host.domain:5500/em/

In order to manage your database, log in as the user SYS and connect as SYSDBA.

The default port number for the OEM is 5500. You can determine the correctport number for your database by looking at the portlist.ini file, which youcan find in the $ORACLE_HOME/install directory.

In order to run the OEM Database Control, you must first start the databasefrom which the Database Control is running. Let’s say your database nameis nina. You then need to make sure that the service (on a Windows server)OracleServiceDBConsoleNina is running, before you try to access the OEM DatabaseControl interface through your web browser.

When you choose local management using the Database Control, the installeralso gives you the choice of configuring default backup strategies administered bythe Recovery Manager (RMAN). In addition, choosing the Database Control alsoenables you to configure the sending of automatic e-mail alerts to warn you aboutspace concerns and other problems.

The Apache HTTP Server isn’t a part of the Oracle Database 10g software,unlike in the previous versions. Oracle continues to provide the Apache HTTPServer, but as part of the supplemental product CD-ROM.

Installation New Features Support 5

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:43 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 6: OCA OCP - Oracle10G New Features For Administrators Exam Guide

6 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

The Database Configuration Assistant (DBCA) can automatically configure theOEM Database Control interface during database creation. However, if you createa database manually, you must configure and install the OEM Database Control,using the Oracle-supplied build script: $ORACLE_HOME/bin/emca for UNIX andLINUX systems and $ORACLE_HOME\bin\emca.bat for Windows. This scriptwill configure the OEM repository and start up the Database Control console.

In order to access the OEM Database Control from your browser, you must firsthave the dbconsole process running on your system. The dbconsole processis automatically started during the installation process when you create a databaseusing the DBCA. When you create a database manually, the emca (UNIX) or theemca.bat (Windows) script will start the dbconsole process. You can start, stop,and check the status of the dbconsole process by using the following threecommands, respectively:

$ emctl start dbconsole$ emctl stop dbconsole$ emctl status dbconsole

Automatic Pre-Install ChecksIn order to install Oracle 10g, you must meet several operating system hardware andsoftware requirements. In previous Oracle software versions, it wasn’t uncommon forDBAs to start the installation process, only to stop it midway because they overlookedone or two factors. The DBA was responsible for making sure that there were enoughsystem resources, that the correct set of initialization parameters were chosen, andso on. To make the requirements phase go smoothly, the Oracle Universal Installer(OUI) now manages the entire pre-install requirements check automatically. Oraclewrites the results of the prerequisite checking process to a results file.

Comprehensive hardware and software prerequisite checks ensure the detectionof resource and compatibility issues before your installation process gets underway.Oracle even allows for the updating of the prerequisites directly via OracleMetaLink,to reflect new operating system patches on your system. You may also add customprerequisite checks through XML files, in order to customize the installation process.

Pre-Installation Checks PerformedThe following are some of the main pre-installation checks that the prerequisite checkerof the OUI automatically performs before you install the Oracle 10g server software:

■ Correct operating system version and compatibility level The first thingthat Oracle checks before you start the installation process is whether you

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:43 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 7: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Installation New Features Support 7

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

are running the current operating system version. For example, on a HP-UXsystem, Oracle will verify that you have at least the HP 11.11 version.Similarly, for Linux-based systems, Oracle will make sure you have one ofUnitedLinux 1.0, Red Hat 2.1, or Red Hat 3.0 versions before you canproceed further with the installation. In addition, if you have a 32-bitoperating system, you cannot install the 64-bit version. Oracle will alsoensure that you have set the database compatibility level to 9.2.0 or higher.

■ Operating system patches Oracle automatically checks to make sure youhave installed all the necessary operating system patches.

■ Kernel parameters Oracle checks to make sure that operating system kernelparameters like SHMMAX and SHMMIN are set appropriately.

■ Sufficient memory and file space Oracle checks the amount of swap spaceand the minimum space in the temporary tablespace that are required duringthe installation process. Oracle will also ensure that your redo logs are sizedsufficiently.

■ Oracle Home Your Oracle Home must be either empty or belong to asupported release that permits the installation of Oracle 10g server software.

Methods for Performing Pre-Installation ChecksYou can instruct the OUI to perform the prerequisite checks in three different ways:

■ As part of an actual installation process

■ As a stand-alone check without any installation

■ From the command line, in the silent mode (without using the OUI GUI)

Only after you pass all the preinstall validations will the OUI proceed with theinstallation of the Oracle software.

New File Storage OptionsThe OUI now offers three choices for configuring the file systems for any new starterdatabase that you may create:

■ Automatic Storage Management (ASM) This option offers a way to easilymanage your datafiles using logical file management techniques. You canthink of ASM as an integration of a traditional file system with a built-inLogical Volume Manager (LVM), which is separate from any LVM your

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:43 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 8: OCA OCP - Oracle10G New Features For Administrators Exam Guide

8 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

system may already have, like Veritas, for example. This means that you nolonger need to use a third-party LVM to stripe and mirror your hard drives.Under ASM, all you need to do is create disk groups, and the databaseautomatically stripes and mirrors your data across the available disks inthe disk groups. You can also add or remove disks while the database isup and running.

■ Raw Devices You need to think about using raw devices only if you areconsidering using Oracle Real Application Clusters. If you use RAC, and aClustered File System (CFS) is available on your operating system, Oraclerecommends using either CFS or ASM for your file storage. If a CFS isunavailable, Oracle recommends that you use raw, or “uncooked,” filesystems or ASM.

■ File Systems Choosing this option will mean that you are using the traditionaloperating system files and directories for your database storage. Of course,you should organize your directories and files according to the well-knownOptimal Flexible Architecture (OFA) guidelines.

Backup and Recovery OptionsThe next major management option involves the choice of backup and recovery optionsfor the starter database, during the Oracle server software installation process. You have achoice of two options:

■ Do not enable automatic backups

■ Enable automatic backups

If you choose to enable automatic backups, you must also specify the location inwhich you want the backups to reside. In addition, you need to provide thecredentials—name and password—for the user who will be performing the backups.

You can enable the automated backups after you’ve finished the serversoftware installation.

Database User Password SpecificationThe starter database will have several schemas for database management and post-installation functions: SYS, SYSTEM, DBSNMP, and SYSMAN schemas. Oracle

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:44 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 9: OCA OCP - Oracle10G New Features For Administrators Exam Guide

will leave the passwords for these four usernames unlocked and unexpired. Duringinstallation, you’ll be asked to furnish passwords for these four accounts, and you canuse the same password for all of them if you wish.

All other preloaded Oracle schemas will have passwords that are expired andlocked when you create any new database. It’s your job to unlock these standard useraccounts and set new passwords for them.

In Oracle9i, you had to change the SYS and SYSTEM passwords twice: onceduring the installation of the software and once during database creation. InOracle 10g, you need to provide this information only once, during the installationof the software.

Cluster Ready ServicesThe Oracle 10g installation supports several Real Application Clusters (RAC) features,including the installation of the Cluster Ready Services (CRS) feature. CRS facilitatethe management of RAC and replace third-party cluster management software onmost operating system platforms. CRS provide a platform for services on RAC. Forexample, when an RAC component database goes down, CRS will automaticallyredirect the processing to an alternate available instance.

You can invoke the OUI from any node on a cluster that is part of aninstallation. You can not only install new software, but also performupgrades and apply patches from any node in a cluster

Enterprise Configuration Management ToolThe Enterprise Configuration Management Tool is available through the OEM GridControl. As enterprises grow larger, so do the number and complexity of the hostsand databases you need to manage the enterprise. You can use the new OEM GridControl tool to simplify the configuration and management of the enterprise. TheGrid Control offers a management console for your entire system, and it enables youto monitor and configure complex enterprises by performing the following two tasks:

■ Collect necessary host and database configuration information.

■ Perform configuration changes.

Let’s briefly look at how you can perform these tasks in your enterprise.

Installation New Features Support 9

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:44 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 10: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Collecting Host and Database Configuration InformationThe Oracle 10g OEM contains powerful new configuration management features tohelp enforce best practice configuration parameter settings and track configurationchanges. These features apply to Oracle databases, as well as to the host servers andthe network. Continuous configuration monitoring helps you to adhere to best practiceconfiguration management and promotes availability, performance, and security.

The OEM Grid Control manages hosts and databases with the help of ManagementAgents that run on various hosts. These Management Agents collect informationabout the hosts, databases, listeners, web servers, and other services that run on thehost. By default, the Management Agents collects and sends information every 24hours. The hosts send this information to the Oracle Management Repository. Thefollowing is a list of some of the host and database configuration information thatthe Management Agents send to OEM:

■ Memory, CPU, and I/O configuration on the host

■ Operating system details such as vendor, version, installed software components,patches, and database patch information

■ Database and instance properties, including information about initializationparameters

■ Tablespace and datafile information

■ Control file and redo log information

The OEM maintains a detailed configuration inventory of all the databases andservers in its domain.

Monitoring and Managing Enterprise ConfigurationOnce the Grid Control collects the configuration information, you can use the sametool to monitor and manage the configuration. Here’s a brief list of the various thingsyou can do to manage enterprise configuration with the OEM Grid Control:

■ View and compare the hardware and software configurations of individualhosts and databases.

■ Track changes to host configurations.

■ See a summary view of your enterprise configuration.

■ Search the enterprise configuration to find configurations that meet a setof search criteria that you specify.

10 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:44 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 11: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ Clone Oracle Homes and database instances.

■ View host and database policy violations.

■ Simplify the process of patching Oracle products and manage Oracle criticalpatch advisories.

MetaLink IntegrationProbably every Oracle DBA knows and relies on the OracleMetaLink service to someextent during the performance of his or her duties. In Oracle 10g, you can directly linkthe OEM to the OracleMetaLink service. Through this built-in MetaLink integration,OEM can then automatically track any new software patches for you. You can arrangeto receive alerts whenever the OEM spots new patches. The OEM can even tell youwhich systems need the new patches. Using the OEM OracleMetaLink link, you cansearch for appropriate patches and download them, receive critical patch alerts, andstage and apply patches on your system.

How does Oracle keep track of the exact software version that you are using, ifyou are constantly downloading and uploading patches? Whenever you apply apatch, Oracle immediately updates the OUI’s inventory, so it has the correct recordof your latest patch level. Exercise 1-1 shows how to use the OEM Database Controlto download Oracle software patches.

EXERCISE 1-1

Using OEM Database Control toDownload Oracle Software Patches

The OEM uses OracleMetaLink credentials to search for and download OracleMetaLinkpatches. If you did not specify your OracleMetaLink credentials during installation, youcan follow the steps in this exercise.

1. On the OEM Database Control home page, click Setup.

2. On the Setup page, click Patching Setup.

3. Specify your OracleMetaLink username and password in the fields provided.

4. The URL to access the OracleMetaLink web site to search for and downloadpatches is displayed in the Patch Search URL field on this page, as shown here:

Patch Search URL : http://updates.oracle.com

Installation New Features Support 11

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:44 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 12: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You may access OracleMetaLink directly by going to the following web site:

http://oracle.com/support/metalink/index.html

5. From this page, Oracle licensees can register for an account or log in withan existing account. Once logged in, you can search for patches, downloadpatches, and so on.

The OEM automatically alerts you to any new crtical patches that becomeavailable. In addition, you can use the OEM Patch Wizard to find out what interimpatches are available for your system. You can now study patch details and READMEnotes directly from your OEM interface. Using the Patch Wizard, you can downloadavailable patches from Metalink into the OEM patch cache, so you can propagatethese patches across your system at your convenience.

Oracle Software CloningThe OEM Grid Control enables you to easily duplicate Oracle Database 10g softwareinstallations (Oracle Homes) from a master installation to one more servers. Using anOEM Wizard, you can specify the source and the destination host to which you wantto clone that Oracle Home. The cloning process will automatically adjust host names,IP addresses, listener settings, and so on.

You can create multiple new installations in a single operation from the OEMGrid Control framework. You can also create a library of master installations,which you can use repeatedly in cloning operations.

Database CloningUsing the OEM, you can now easily clone databases. OEM performs database cloningby using RMAN. You use the OEM Clone Database wizard, also known as the CloneDatabase Tool, to perform the various steps in a database cloning operation. To createa duplicate of an existing database, from the home page of the OEM Database Control,choose Maintenance | Deployments | Clone Database. OEM will back up the sourcedatabase’s datafiles as well as archive logs, and automatically restore and recover thesein the target location. The OEM also creates the necessary password files, initializationfiles, and networking files.

When you use the OEM to clone a database, you can leave the database open.You can clone databases that are release 8.1.7 and higher. The new database will

12 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:44 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 13: OCA OCP - Oracle10G New Features For Administrators Exam Guide

be up-to-date with the old one until the time the archived logs of the originaldatabases were backed up by the OEM.

CERTIFICATION OBJECTIVE 1.02

Performance Enhancementsto the Installation Process

Oracle has implemented several changes to make the installation process more streamlinedand faster than in previous versions. You can literally install the entire Oracle 10gsoftware in less than half an hour, using just one CD. Moreover, during the installationprocess, you can now automatically set up several features, such as database monitoring.The important installation process enhancements are discussed in the following sections.

Single CD InstallationAlthough the Oracle Database 10g server software comes in a pack of CD-ROMs, youneed only a single 650MB CD to complete your Oracle 10g server installation. It takesonly about 20 minutes to complete the entire installation. The label on this maindatabase server software CD is Oracle Database 10g CD. Several older components arenow available on separate CDs. Along with the Oracle Database 10g CD, the followingCDs are supplied with the Oracle 10g package:

■ Companion CD

■ Oracle Database 10g Products CD

■ Oracle Database 10g Client CD

■ Oracle Documentation 10g CD

■ Oracle Database 10g Demos CD

■ Oracle Enterprise Manager CD

You install other tools, such as the HTTP Server, from the Oracle Database 10gCompanion CD. The Companion CD includes two products: the HTTP Server andthe new HTML DB feature.

Performance Enhancements to the Installation Process 13

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:44 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 14: OCA OCP - Oracle10G New Features For Administrators Exam Guide

14 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

The Database 10g Products CD includes the Oracle database examples, the OracleWorkflow Server, and the Legato Single Server Version (LSSV).

The original installation includes only the new OEM Database Control, whichenables you to monitor just the database itself. The OEM Grid Control, which enablesthe monitoring of your entire system, is available on the Oracle Enterprise Manager CD.

Minimal Hardware RequirementsYou can use the Oracle Database 10g software with less stringent hardware requirementsthan those in previous versions. The following are the basic hardware requirements forOracle Database 10g:

■ Memory You need 256MB for the basic database, and 512MB if you areusing the stand-alone version of the OEM (the OEM Database Control).If you need to, you can run both the database and Database Control with256MB or even less memory, say, for testing purposes. However, the morememory you have, the easier it is to use the memory-hungry, Java-basedOEM tool.

■ Disk space You need a maximum of about 2.5GB of disk space for theOracle software. In addition, you need 1GB of swap space and about 400MBof disk space in the /tmp directory. The OUI uses a more sophisticatedalgorithm to estimate your disk space needs now, so there is less chance ofrunning out of disk space during the installation process.

Easier and Cleaner DeinstallationPrior to Oracle Database 10g, you couldn’t always count on a clean Oracle serverdeinstallation if you needed to remove the server software for some reason. Well,this isn’t true anymore. With Oracle 10g, you can perform an easy and cleandeinstallation, marked by the following new features:

■ All files, including files that belong to configuration assistants and patch sets,are automatically removed during the deinstallation process.

■ The installer automatically cleans up all the Windows Registry entries.

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:44 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 15: OCA OCP - Oracle10G New Features For Administrators Exam Guide

To deinstall your Oracle 10g software, follow these steps:

1. First, shut down all databases and ASM instances running under the OracleHome you want to remove, and then remove the databases (remove alldirectories with database files).

2. Stop all the relevant processes running under this Oracle Home, by runningthe following commands:

$ORACLE_HOME/bin/emctl stop dbconsole – shuts down the OEM.

$ORACLE_HOME/bin/lsnrctl stop – brings down the Oracle listener

$ORACLE_HOME/bin/isqlplusctl stop – brings down the iSQL*Plus server.

3. Start the OUI.

4. Click Deinstall Products in the Welcome window.

5. In the Inventory window, select the correct Oracle Home that contains thesoftware you want to deinstall, and then click Remove.

6. Manually remove the Home directory that you just deinstalled.

Don’t remove any Oracle Home directories without first using the OUIto remove the Oracle software.

Automatic Launching of SoftwareIn Oracle 10g, several Oracle products will launch automatically immediately after youcomplete the server installation. Examples include the Oracle Management Agent,the OEM Database Control, and the iSQL*Plus server. Oracle automatically sets upan out-of-the-box monitoring and administration environment for you after theinstallation is complete.

Response File ImprovementsThe response file is a file you can use to perform silent installations, which are installationswhere the user doesn’t need to provide any interactive input. The response file containsall the information that you normally provide during an interactive installation session.If you have several off-site Oracle installations to perform, you could send an installationresponse file to these locations, rather than going to each place to perform a manualinstallation.

Performance Enhancements to the Installation Process 15

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:44 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 16: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The following are the new Oracle 10g improvements in the response file, whichhelp you perform a truly “silent” Oracle installation:

■ The file has a new header format, which makes the response file easier to edit.

■ You don’t need to specify an X server when performing installations in acharacter mode console.

■ You don’t need to set the DISPLAY variable on UNIX systems.

■ No GUI classes are instantiated, making this a truly silent method ofinstalling software.

CERTIFICATION OBJECTIVE 1.03

Simplified Instance ConfigurationIn Oracle Database 10g, several enhancements make instance creation a lot simplerthan before. These enhancements include a more sophisticated DBCA, adoption ofa set of simplified database initialization parameters, and the ability to view databasefeature usage statistics. The following are the main new features related to simplifiedinstance configuration:

■ DBCA enhancements

■ Policy-based database configuration framework

■ Simplified initialization parameters

■ Irreversible datafile compatibility

Let’s start with a discussion of the enhancements in the DBCA tool.

Database Configuration Assistant (DBCA) EnhancementsYou can create new databases manually by using the standard create databasestatement. You can also create databases with the help of Oracle’s DBCA. The DBCAreally makes the Oracle DBA’s database-creation tasks tremendously lighter whencreating complex Oracle 10g databases. Oracle 10g contains several enhancementsin routine database administration, and the DBCA helps you implement all thesenew automatic management tasks. Using the DBCA ensures that you’re reminded

16 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:44 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 17: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Simplified Instance Configuration 17

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

about all the important options, rather than needing to remember them and performthem all manually.

EXERCISE 1-2

Creating a New Database ManuallyYou can create a new database with the simple statement create databaseabcd, where abcd stands for your database instance name.

1. Create the instance before you try creating the database. On a Windowssystem, first run the command oradim –new –sid my_sid. Make sureyou create a simple init.ora file with just one parameter: the instance name.

2. Log in as SYSDBA.

3. Use the command create database my_sid. Do not specify anydatafiles, tablespaces, or any other information.

4. Answer the following questions:

■ What tablespaces does Oracle create? Where are the datafiles?

■ What are key features of the initialization parameter file (init.ora or inthe SPFILE)?

■ How much SGA and other PGA memory is allocated?

■ What mode of undo management does your new database use?

■ What are the default passwords for the various system accounts?

■ What database features are currently configured?

Please make sure you create the instance before you try creating thedatabase. On a Windows system, first run the command oradim –new–sid my_sid. Make sure you create a simple init.ora file with just oneparameter—the instance name. Next, log in as sysdba and use the command‘create database my_sid. Now, you can answer the exercise questions.

There are several important DBCA enhancements in Oracle Database 10g,including the creation of the mandatory SYSAUX tablespace, a flash recovery area,and new database storage options. Let’s start with a discussion of the new mandatorySYSAUX tablespace.

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:45 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 18: OCA OCP - Oracle10G New Features For Administrators Exam Guide

18 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

The SYSAUX TablespaceYou are aware that the OEM, the RMAN, and several other Oracle tools needrepositories—locations where these tools store all the database metadata. TheSYSTEM tablespace stores a lot of metadata, such as the data dictionary, but it doesnot store the metadata relating to tools like the OEM. Traditionally, Oracle requiredyou to create separate tablespaces for the various repositories in your database. Now,in Oracle 10g, Oracle introduces the SYSAUX tablespace, which is auxiliary to theSYSTEM tablespace. This new tablespace is a central location for the metadata of alltools like the OEM and RMAN. The SYSAUX tablespace consolidates the data thatvarious database features and products used to store in multiple tablespaces (or in theSYSTEM tablespace). Thus, you need to create fewer tablespaces to store all therepository data for the various utilities like the RMAN.

The DBCA automatically creates the SYSAUX tablespace for you, with a defaultsize of 500MB. Of course, you can customize the storage and file parameters forSYSAUX, if you wish. Toward the end of this chapter, in the section detailing themanual upgrading of a database to the Oracle 10g version, I’ll show you the syntaxfor manually creating the SYSAUX tablespace.

Flash Recovery AreaThe flash recovery area is a unified storage location on your server that Oracle reservesexclusively for all database recovery-related files and activities. The main purposebehind the creation of the flash recovery area is to automate the storage managementfor many backup and recovery-related activities. The database will store all the filesthat it needs during a database recovery in this flash recovery area.

Note that the flash recovery area is separate from the space you allocate to thenormal database files—datafile, redo log files, and the control files. You must allocateseparate physical space for the flash recovery area. When you use the DBCA to createa new database, it automatically creates the flash recovery area for you.

The flash recovery area is mandatory if you wish to configure automaticbackups using the OEM.

How do you determine what size your database flash recovery area should be?Oracle recommends that you allocate at least enough space to hold a copy of thefollowing files:

■ All datafiles

■ All redo log files

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:45 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 19: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ All control files

■ All archived redo logs necessary for recovery that haven’t been migratedto tape

■ Any incremental backups, if they exist

If you want to manually define a flash recovery area, you can do so using the newflash recovery initialization parameters, DBA_FLASH_RECOVERY_DEST and DB_FLASH_RECOVERY_DEST_SIZE, as follows:

SQL> ALTER SYSTEM SET db_recovery_file_dest_size = 500G;SQL> ALTER SYSTEM SET db_recovery_file_dest ='/u22/oradata/finance/recovery';

You can dynamically alter or disable both of the flash recovery initializationparameters. You can find out details about the flash recovery area’s contents by usingthe V$FLASH_RECOVERY_FILE_DEST view, as shown here:

SQL> SELECT name, space_limit, space_used,space_reclaimable, number_of_filesFROM v$recovery_file_dest;

Automatic Storage Management (ASM)ASM is an exciting new Oracle Database 10g feature. In essence, an ASM-basedstorage system contains its own LVM for Oracle files. ASM makes it easier to managelarge databases. Chapter 10 is devoted to a detailed discussion of the ASM feature.

Management OptionsAs in the case of the starter database described earlier in this chapter, the DBCA givesyou a choice between two kinds of database management: local and central. If youwant to just manage a single database instance, simply choose the Database Control,which Oracle automatically installs with your new database. If, on the other hand, youneed to manage several databases and several nodes, use the new Grid Control. TheGrid Control doesn’t come automatically with the database; you need to install thistool from a separate CD.

As mentioned earlier in this chapter, Oracle automatically sets up an out-of-the-box monitoring and administration environment for you after the installation iscomplete. You don’t need to perform any configuration to start using the DBConsole (Database Control) to start managing a single database, including alertnotification, job scheduling, and software management.

Simplified Instance Configuration 19

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:45 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 20: OCA OCP - Oracle10G New Features For Administrators Exam Guide

20 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

You can access the OEM Database Control or the Grid Control from any clientbrowser. For example, to access the OEM Database Control, just open InternetExplorer or Netscape and type in the following URL:

http://myhostname:default_port_number/em

where myhostname stands for the IP address or symbolic name of your machine, anddefault_port_number is the port number that Oracle allocated to the Database Controlduring installation. The default Database Control HTTP port number is 5500.

Once you get to the Database Control login page, log in as the SYS user (withthe SYSDBA password). This will take you to the home page of the OEM DatabaseControl utility.

Note that you’ll need Oracle licensing for the following three premium componentsof OEM Database Control (technically speaking, you’ll be in violation of yourOracle licensing requirements, if you use these options without paying for them!):

■ Database Diagnostics Pack

■ Database Tuning Pack

■ Configuration Management Pack

Here’s a brief listing of the components of each of these OEM premium packs:

Database Diagnostics PackDatabaseTuning Pack Configuration Management Pack

Performance Monitoring (databaseand host)

SQL Access Advisor Database and Host Configuration

Automated Database DiagnosticMonitor (ADDM)

SQL Tuning Advisor Deployments

Automatic Workload Repository SQL Tuning Sets Patch Database and Patch Staging

Event Notifications: NotificationMethods, Rules, and Schedules;Notification Blackouts

Object Reorganization Clone Database and Clone Oracle Home

Event history/metric history(database and host)

Search and Compare Configuration Policies

Policy-Based Database Configuration FrameworkOracle provides a set of established configuration recommendations, which are a setof Oracle’s best practice recommendations, to ensure that your database performs atan optimal level. Oracle 10g enables you to monitor all of your databases to see if there

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:45 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 21: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Simplified Instance Configuration 21

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

are any violations of the predetermined configuration policies. Oracle collects theseconfiguration metrics for databases, host machines, and listener services.

The OEM Database Control provides an easy way to monitor the adherence of yoursystem to the predetermined policies. On the Database Control home page, thereis a section called Diagnostic Summary, which shows you if there are any policyviolations anywhere. If you drill down, using the All Policy Violations button, youcan get to the Policy Violations page, which summarizes all policy violations inyour databases and hosts. If you wish, you can disable a policy by going to theManage Policy Library page.

Here are a few examples of some typical policy rules:

■ The policy rule “critical patch advisories for Oracle Homes” checks formissing Oracle patches.

■ The policy rule “insufficient number of control files” checks for the use ofa single control file.

■ The “listener password policy rule” checks for password-protected listeners.

Simplified Initialization ParametersInstance configuration includes the all-important choice of initialization parameters.Oracle 10g informally divides the available set of initialization parameters into a basicand an advanced set of parameters, as follows:

■ Basic initialization parameters This set consists of about 25 to 30 of themost common parameters that you need for an Oracle database. Oracledefines the basic initialization parameters as those that are adequate to keepyour database running well. Examples include parameters like PROCESSES,SESSIONS, UNDO_MANAGEMENT, DB_BLOCK_SIZE, CONTROL_FILES,and DB_NAME.

■ Advanced initialization parameters These are parameters you’ll need todeploy only rarely, to improve your database’s performance or to overcomesome special performance problems. Some examples of the initializationparameters in the advanced set are the CURSOR_SHARING and CURSOR_SPACE_FOR_TIME parameters. Oracle recommends that only experiencedOracle DBAs configure the advanced initialization parameters.

Initialization Parameter ViewsYou can view the database initialization parameters, as in Oracle9i, by querying theV$PARAMETER view or the V$SPPARAMETER view, depending on whether youare using the init.ora file or the SPFILE to store your initialization parameters.

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:45 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 22: OCA OCP - Oracle10G New Features For Administrators Exam Guide

22 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

EXERCISE 1-3

Using the OEM Database Controlto View Initialization Parameters

You can also use the OEM Database Control to view your initialization parameters.To view the parameters using the Database Control, follow these steps:

1. Go the Database Control home page.

2. Click the All Initialization Parameters tab on the Administration page.

3. If you wish to change any parameters, you can do so from here and clickSave to File.

4. If you wish configuration changes to come into force immediately, click theSPFILE tab first, and then check the Apply Changes in SPFile mode tothe current running instance box.

Changes in the Initialization ParametersIn Oracle Database 10g, several traditional initialization parameters have becomeobsolete or deprecated. You also have access to several new parameters. Here’s a listof some of the important deprecated, obsolete, and new initialization parameters inOracle Database 10g:

Deprecated Parameters Obsolete Parameters New Parameters

MTS_DISPATCHERS DISTRIBUTED_TRANSACTIONS RESUMABLE_TIMEOUT

UNDO_SUPPRESS_ERRORS JOB_QUEUE_INTERVAL SGA_TARGET

PARALLEL_AUTOMATIC_TUNING

ORACLE_TRACE_COLLECTION_NAME

PLSQL_OPTIMIZE_LEVEL

MAX_ENABLED_ROLES

Irreversible Datafile CompatibilityIn prior Oracle database versions, you could revert to a previous compatibilitysetting by using the alter database reset compatibility command.This command is now obsolete. Once you start the database, you cannot go backto a compatibility value that’s less than the current value of the COMPATIBLE

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:46 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 23: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Viewing Database Feature Usage Statistics 23

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

initialization parameter in your init.ora (or SPFILE) file. Thus, the COMPATIBILEinitialization parameter is now irreversible. This section provides the new details onthe compatibility feature.

The minimum value of the compatibility setting is now 9.2.0. That is, if you setthe COMPATIBLE initialization parameter to 9.2.0., your datafile formats will becompatible with the Oracle9i Release 2 version. This means that if you wish, youcan always downgrade your new Oracle 10g database to a 9.2.0 version, as long asyou have installed the Oracle9i Release 2 (9.2.0.3) or later executables on yoursystem along with the Oracle 10g server software. If you set the COMPATIBILEinitialization parameter to 9.2, however, you can take advantage of only a subset ofthe new Oracle 10g features. Therefore, use the 9.2 compatibility setting only if youthink you may need to revert to the Oracle9i version for some reason.

By default, Oracle sets the file format compatibility to 10.0.0. If you don’t set theCOMPATIBLE parameter in your init.ora file, or if you set it explicitly to 10.0.0,the compatibility level will be set to the Oracle 10g file format compatibility. Thismeans that you won’t be able to downgrade the Oracle 10g database to a priorrelease. In that case, in order to start you database with a lower compatibility setting,you would need to perform a point-in-time database recovery and recover to a pointin time that was before you advanced the compatibility level.

To check the current compatibility level of your database, which is set by the valueyou chose for the COMPATIBLE initialization parameter, use the following statement.

SQL> SELECT name, value, description FROM v$parameterWHERE name = 'compatible';

The minimum value of the COMPATIBILE initialization parameter is 9.2.0.The default value, however, is 10.0.0.

CERTIFICATION OBJECTIVE 1.04

Viewing Database Feature Usage StatisticsIn Oracle 10g, you can track database usage metrics, which enable you to understandtwo important aspects:

■ How you are using the various features of your Oracle database, includingwhether the database is currently using a given feature, as well as the firstand last times it used a given feature.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:46 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 24: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ The high-water mark (HWM) statistics for important database attributes. TheHWM is simply the highest usage point a feature has attained up to now.

The database features that you can track include features like Advanced Replication,Oracle Streams, Virtual Private Database (VPD), and various auditing features.

Oracle Database 10g collects HWM statistics for items like the following:

■ Maximum size of tables

■ Maximum number of datafiles

■ Maximum number of sessions

■ Size of the largest data and index segment

Let’s briefly look at how the Oracle database collects these statistics.

The Statistics Collection ProcessHow exactly does Oracle collect these new kinds of statistics? Oracle Database 10gintroduces a new database process called Manageability Monitor Process (MMON),which records both the database usage statistics and the HWM statistics for variousobjects. MMON is a new Oracle 10g background process, and it is primarilyresponsible for various manageability-related background tasks, including takingsnapshots of data, issuing database alerts, and collecting statistics.

MMON records the various statistics inside the Automatic Workload Repository(AWR), which, as you’ll see in later chapters, is a new Oracle Database 10g innovationthat stores database performance data. By default, MMON samples the data dictionaryonce a week, to collect both database feature usage and HWM statistics.

You can query the new DBA_FEATURE_USAGE_STATISTICS data dictionaryview to find out the usage statistics of various features that MMON has stored in theAWR. Here’s the structure of this view:

SQL> desc dba_feature_usage_statisticsName Null? Type––––––––––––––––––––––––––DBID NOT NULL NUMBERNAME NOT NULL VARCHAR2(64)VERSION NOT NULL VARCHAR2(17)DETECTED_USAGES NOT NULL NUMBERTOTAL_SAMPLES NOT NULL NUMBERCURRENTLY_USED VARCHAR2(5)FIRST_USAGE_DATE DATE

24 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:46 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 25: OCA OCP - Oracle10G New Features For Administrators Exam Guide

LAST_USAGE_DATE DATEAUX_COUNT NUMBERFEATURE_INFO CLOBLAST_SAMPLE_DATE DATELAST_SAMPLE_PERIOD NUMBERSAMPLE_INTERVAL NUMBERDESCRIPTION VARCHAR2(128)

You can also use the procedures REGISTER_DB_FEATURE and REGISTER_HIGH_WATER_MARK in the new DBMS_FEATURE_USAGE package to trackfeature usage and HWM statistics.

You can query the DBA_HIGH_WATER_MARK_STATISTICS data dictionaryview to see the HWM statistics and a description of all the database attributes thatthe database is currently monitoring. Here’s a simple example:

SQL> select name, highwater, description2* from dba_high_water_mark_statistics;

USER_TABLES Number of User Tables 760SEGMENT_SIZE Size of Largest Segment (Bytes) 159383552PART_TABLES Max Number of Partitions belonging to a Table 0PART_INDEXES Max Number of Partitions belonging to a Index 0USER_INDEXES Number of User Indexes 1353SESSIONS Max No of Concurrent Sessions seen in database 28DB_SIZE Maximum Size of the Database (Bytes) 901775360DATAFILES Maximum Number of Datafiles 5TABLESPACES Maximum Number of Tablespaces 6CPU_COUNT Maximum Number of CPUs 1QUERY_LENGTH Maximum Query Length 2122Maximum Number of Services 412 rows selected.SQL>

In this section, I have shown how you can query various data dictionary views totrack the database feature usage and HWM statistics. However, there’s an easier wayto monitor these statistics: just use the OEM Database Control to quickly checkthe statistics. The next section describes how to use the OEM Database Control tomonitor database usage statistics.

Database Usage Statistics in the OEMThere are times when you would like to see whether and how the database is makinguse of important features. A feature is simply a specific area of functionality for thedatabase. You can use the OEM Database Control to examine a list of the database

Viewing Database Feature Usage Statistics 25

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:46 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 26: OCA OCP - Oracle10G New Features For Administrators Exam Guide

features and how the database is using those features. These usage patterns includethe frequency of usage, the first time the database used a certain feature, and the mostrecent time the database used a certain feature. Following are the steps to viewingdatabase usage statistics in the OEM Database Control:

1. Go the Database Control home page. Click the Administration link andgo to the Configuration Management group. Click the Database UsageStatistics link.

2. You’ll now be in the Database Usage Statistics property sheet. This propertysheet leads to two pages: the High Water Mark page and the Feature Usagepage. The Feature Usage page lists all the available database features byname. You can also see if the database is currently using a certain feature, aswell as the first usage and last usage timings. To view details about the usagestatistics of any feature, just click the associated link on this page. Figure 1-1shows the Feature Usage page of the Database Usage Statistics property sheet.

3. If you want to view the database HWMs, click the High Water Marks tab inthe Database Usage Statistics property sheet. This will take you to the HighWater Marks page. Here, you can see the HWM attained for each databaseobject, as well as the last sampled value for each feature and the version ofthe database feature. Figure 1-2 shows the High Water Marks page of theDatabase Usage Statistics property sheet.

26 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

FIGURE 1-1

The FeatureUsage page ofthe DatabaseUsage Statisticsproperty sheet

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:46 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 27: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CERTIFICATION OBJECTIVE 1.05

Supported Upgrade Paths to Oracle Database 10gSeveral of you currently use Oracle8i or Oracle9i databases. You’ll most likely beupgrading all these databases to the new Oracle Database 10g version in the nearfuture. I have good news for all DBAs who are embarking on an Oracle Database 10gupgrade project: Oracle has made the upgrade process remarkably simpler by automatingmost of the upgrade process.

The following are the upgrade paths available to you to move up to OracleDatabase 10g:

■ If you have Oracle 7.3.3 or lower, or Oracle 7.3.4, 8.0.3, 8.0.4, 8.0.5, 8.1.5, or8.1.6, you can’t directly upgrade to Oracle Database 10g. You’ll need to firstupgrade to an intermediate release database.

■ If you are using an Oracle 8.0.6, 8.1.7, 9.0.1, or 9.2 database, you can directlyupgrade to Oracle Database 10g.

You can migrate directly to the Oracle Database 10g version only if yourdatabase is one of the following versions: 8.0.6, 8.1.7, 9.0.1, or 9.2.

Supported Upgrade Paths to Oracle Database 10g 27

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

FIGURE 1-2

The High WaterMarks page ofthe DatabaseUsage Statisticsproperty sheet

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:46 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 28: OCA OCP - Oracle10G New Features For Administrators Exam Guide

28 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

You can upgrade to Oracle Database 10g in two ways: the traditional manual mode orby using the Database Upgrade Assistant (DBUA), a tool that automates the upgradeprocess. The DBUA is a refined version of the old Oracle Data Migration Assistant usedin previous versions. Note that you can also use the traditional export and importutilities to perform your database upgrade, especially if you have a very small database.

Unlike in prior versions, the Oracle 10g upgrade process, even when you use themanual method, is somewhat automatic. As you’ll see in the following sections,the manual process invokes the startup upgrade command, after which you needto run the main upgrade script, which performs all the necessary upgrades in the correctdependency order. Oracle will determine the upgrade order of the various components,by querying the new DBA_SERVER_REGISTRY data dictionary view. Oracle uses thisview to check for the existence of the various components that it needs to upgrade.Oracle also queries the view to check the upgrade status of each component after themain upgrade script finishes running. The DBMS_SERVER_REGISTRY is also the basisfor the new Post-Upgrade Status Tool, which you’ll learn about in a later section.

You can use either the DBA_REGISTRY or the DBA_SERVER_REGISTRYview to ascertain the upgrade status of individual database componentsloaded into the database. The two dictionary views are identical, except thatthat the DBA_REGISTRY has an extra column: namespace. If you query thisview with the namespace set to SERVER, the results are identical to theresults you’ll obtain by using the DBA_REGISTRY data dictionary view.

Traditionally, Oracle DBAs have needed to run a number of scripts during thedatabase upgrade process, which made the whole process very strenuous and error-prone. In Oracle Database 10g, you can now run the entire upgrade process with asingle upgrade script provided by Oracle. For example, to migrate from an Oracle8.1.7.4 version database to the Oracle Database 10g version, you’ll need to run theu0801070.sql script. You’ll see a detailed example of the execution of this script inthe “Steps in the Manual Upgrade Process” section later in this chapter.

In the following sections, I’ll briefly explain the upgrade process using both theavailable methods.

The Manual Upgrade ProcessThe manual upgrade process means you do all the due diligence work: make sureyou remove or change all obsolete initialization parameters and run all the Oracle-provided database upgrade scripts. During a manual upgrade process, you, the DBA,must run SQL scripts from the command line to drive the upgrade process.

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:47 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 29: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

The advantage in using this method is that you control every part of the entireupgrade process. Of course, the drawbacks of a manual method are that you mustperform a backup of the database yourself before the upgrade, remove or add allnecessary initialization parameters, and ensure that the SYSTEM tablespace hasadequate free space.

The Database Upgrade Assistant (DBUA)When you use the DBUA, the tool performs all the preinstallation checks for you toensure that your database meets all the upgrade requirements, and then manages theupgrade process automatically. Here is a summary of what the DBUA does for youduring a database upgrade:

■ Perform all pre-upgrade tasks, including checking for invalid datatypes, desupportedcharacter sets, invalid user accounts, and sufficient free space in the tablespaces.

■ Back up the database.

■ Create any necessary objects.

■ Invoke the correct upgrade script.

■ Show the upgrade progress during the upgrade.

■ Create new parameter and listener files in the new Oracle Home.

The DBUA is a GUI tool, but you can also run it in the silent mode, byusing the following command at the operating system level: dbua.

To begin with, you need to analyze your existing system to see what changes maybe necessary. Fortunately, Oracle provides an excellent script called the UpgradeInformation Tool, which will ferret out this information for you automatically. We’lllook at this new tool in the following section.

CERTIFICATION OBJECTIVE 1.06

Using New Utility to Perform Pre-UpgradeValidation Checks

Oracle now includes a brand-new tool, called the Upgrade Information Tool, to helpyou collect various pieces of critical information before you start the upgrade process.

Using New Utility to Perform Pre-Upgrade Validation Checks 29

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:47 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 30: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Too often, as you are aware, you might need to restart an upgrade process, owing toincompatible initialization features or inadequate tablespace sizes.

The Upgrade Information ToolThe Upgrade Information Tool provides the following important information:

■ The SYSAUX tablespace You need to create a brand new tablespacecalled the SYSAUX tablespace before you can run the Oracle Database 10gupgrade script. The Upgrade Information Tool will tell you about this andrecommend the correct size for this tablespace.

■ Information about log files Oracle Database 10g requires the redo log filesto be at least 4MB in size. If your current log files in the database you aregoing to upgrade are smaller than 4MB, the script will tell you to increase thesize of the redo log files before the upgrade.

■ Tablespace sizes If the current tablespaces don’t have enough free space,the information will be logged, so you can increase the size of the tablespaces.

■ Initialization parameters The pre-upgrade script will save you a lot ofheadaches by telling you which of your initialization parameters should beremoved (deprecated and obsolete parameters) and which new parametersshould be added before you can upgrade.

■ Database versions and compatibility level The Upgrade Information Toollets you know if you need to change your database compatibility level, usingthe COMPATIBLE initialization parameter.

■ Time estimates The Upgrade Information Tool also provides you anapproximate estimate of the time it will take for you to complete your upgrade.

As you can see, running the Upgrade Information Tool prior to your manualupgrade process does a lot of the manual work for you! As long as you read the logfile of the Upgrade Information Tool carefully and implement the recommendedchanges, you are well set to upgrade to Oracle Database 10g.

Both the manual upgrade process and the DBUA can use the UpgradeInformation Tool. If you are performing a manual upgrade, you needto invoke the tool by running the SQL script utlu101i.sql. The DBCAautomatically runs it as part of the pre-upgrade check.

30 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:47 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 31: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The Upgrade Information Tool is really nothing but a simple Oracle-providedSQL script, called utlu101i.sql (located in the usual $ORACLE_HOME/rdbms/admin directory), which helps you find out how your database stacks up for theupgrade process. Here’s how you start the Upgrade Information Tool in yourpre-upgrade database:

SQL> @$ORACLE_HOME\rdbms\admin\utlu101i.sqlOracle Database 10.1 Upgrade Information Tool 04-14-2004 10:07:08Database:––––-–> name: FINANCE–> version: 8.1.7.0.0–> compatibility: 8.1.0WARNING: Database compatibility must be set to 9.2.0 prior to upgrade.Oracle Database 10.1 Upgrade Information Tool 04-14-2004 10:07:08. …

The Post-Upgrade Status ToolOracle Database 10g also provides a new Post-Upgrade Status Tool, which gives youan accurate summary of the upgrade process and any necessary corrective steps to betaken. In the past, you had to determine the success of an upgrade by looking for anyerror messages. However, the absence of error messages during the upgrade doesn’tguarantee that your upgrade was successful. The Post-Upgrade Status Tool looks inthe component registry called DBA_SERVER_REGISTRY to check the status of eachdatabase component. If one or more components don’t have a valid status or carrythe wrong version number, the Post-Upgrade Status Tool will list the componentinformation for you.

You can restart a failed database upgrade job from the point where you failed.

The Post-Upgrade Status Tool provides the following information:

■ The name and status, either VALID or INVALID, of each database component

■ The component’s version compatibility with the current database version

■ Suggestions for corrective action to take if there are any invalid componentsafter the upgrade process is completed (such as the appropriate script namesto run)

Using New Utility to Perform Pre-Upgrade Validation Checks 31

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:47 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 32: OCA OCP - Oracle10G New Features For Administrators Exam Guide

32 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

As in the case of the Upgrade Information Tool, you use an Oracle-supplied scriptto invoke the Post-Upgrade Status Tool. This script is the utlu101s.sql script, locatedin the $ORACLE_HOME/rdbms/admin directory on your server.

if you use the DBUA to upgrade, the utlu101s.script runs automatically. If youare performing a manual upgrade, you need to run the script yourself, afterthe upgrade process is finished.

CERTIFICATION OBJECTIVE 1.07

Using the Simplified Upgrade ProcessAlthough it is easy to perform a manual upgrade to Oracle Database 10g, the factremains that you need to do all the due diligence, and a critical mistake like omittinga key step could cost you dearly in terms of time. Oracle recommends that you usethe DBUA to facilitate the database upgrade process. The DBUA takes care of thefollowing tasks for you:

■ Deletes all obsolete initialization parameters

■ Changes the ORACLE_HOME settings automatically

■ Runs the appropriate upgrade scripts for your current release

■ Configures your listener.ora file

Both the manual upgrade and the DBUA upgrade process perform the same setof steps: performing pre-upgrade checks to ensure that the database meets all therequirements, running the Oracle-supplied upgrade script, and so on. However, theDBUA performs additional chores like configuring the listener.ora file.

Which one of the two methods is superior? I think either one is good enough,with the DBUA being easier on your nerves if you are relatively new to thedatabase upgrading business. If you are a veteran Oracle DBA, going throughthe manual process may be the best way to go, in my opinion.

Note that some of the material regarding the database upgrade process in thefollowing sections may be more detailed than what’s necessary to merely pass thecertification exam. However, the review would come in handy when you areupgrading your databases to Oracle Database 10g.

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:47 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 33: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using the Simplified Upgrade Process 33

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

How Does the DBUA Work?The DBUA performs several steps before and during the database upgrade process.In effect, the DBUA combines the work of the Upgrade Information Tool and themanual upgrade process, which you have seen in the previous sections. The DBUAperforms all the necessary pre-upgrade steps for you automatically, including thefollowing:

■ Change the ORACLE_HOME settings to the new Oracle Database 10gsoftware locations.

■ Change the /etc/oratab entries to reflect the new location.

■ Copy the existing init.ora file from its old location to the new OracleDatabase 10g default init.ora location ($ORACLE-HOME/dbs under UNIX).

■ Check for adequate space in your tablespaces, including the undo tablespaceor the rollback segments, before the upgrade process begins.

■ Check for desupported character sets, invalid data types, invalid usernames,and so on.

■ Perform a backup of the database, if you choose.

As you have seen, the upgrade process isn’t really a horrendous process, evenwhen you do it using the manual method. With the DBUA, upgrading becomeseven easier. As you know by now, the DBUA incorporates all three steps of theupgrade process: the pre-install checks, the actual upgrade process, and the post-upgrade checks. You can use the DBUA to upgrade any database configuration,including RAC and standby databases.

DBUA StartupYou can start the DBUA by selecting Programs | Oracle | Configuration and MigrationTools | Database Upgrade Assistant. Figure 1-3 shows the Welcome screen of theDBUA. If you are on a UNIX system, simply type dbua (after logging in as the Oracleuser) at the operating system prompt to start up the DBUA GUI.

If you don’t want to deal with the GUI, you have the wonderful option of simplydoing a silent upgrade using the DBUA. This means you won’t be prompted foranything—you simply wait for a couple of hours, and if there are no major problems,your database will be automatically upgraded for you. Use the following commandfor the silent invocation of the DBUA (assuming your database name is nina):

$ dbua -silent –dbName nina

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:47 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 34: OCA OCP - Oracle10G New Features For Administrators Exam Guide

34 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

This command is all you need to migrate your current database to Oracle Database 10g.

The Upgrade Process with the DBUAThe following are the steps to performing a database upgrade using the DBUA in theinteractive GUI mode (you click Next to continue after each step):

■ Select the database instance to upgrade. In the Selecting a DatabaseInstance screen, first ensure the chosen database has already been started.Then select the database instance to be upgraded.

■ Create the SYSAUX tablespace. Next is the Sysaux Tablespace screen. LetOracle create the new SYSAUX tablespace for you.

The SYSAUX tablespace is a mandatory new tablespace in Oracle Database 10g.Oracle uses the SYSAUX tablespace to store the data for several Oraclefeatures, including the RMAN. If you use the DBUA to upgrade, Oracle willautomatically create the SYSAUX tablespace for you. On the other hand, ifyou manually upgrade, you must create the SYSAUX tablespace, as describedin the “Steps in the Manual Upgrade Process” section later in this chapter.

FIGURE 1-3

The WelcomeScreen of theDatabaseUpgradeAssistant

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:47 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 35: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using the Simplified Upgrade Process 35

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

■ Choose the option to recompile invalid objects. The next screen gives youthe option of automatically recompiling any invalid database objects after thedatabase upgrade is completed. Let Oracle recompile objects that are invalid.

Letting Oracle recompile all invalid objects at the end of the upgrade isequivalent to manually running the utlrp.sql script during a manual upgrade.

■ Back up your database. The next screen gives you a last chance to do a coldbackup of your database, if you haven’t already done so. If you (as any saneDBA would) have already done your backups, choose the I Have AlreadyBacked Up My Database option.

■ Choose the OEM configuration. The next screen is the ManagementOptions screen, which provides options to configure the OEM, as well asbackups. You can choose either the Grid Control or Database Controlversion of the OEM to manage your upgraded database. As noted previouslyin this chapter, the Database Control component comes with your databaseinstallation software, and Oracle automatically installs it when you installOracle Database 10g, but you must install the Grid Control from separatesoftware. Grid Control assumes that you have already created a ManagementService on one of the servers in your grid. If you haven’t already installedthe Grid Control software, it may be best to choose the Database Controlat this early stage in the game.

■ Define the Flash Recovery Area. The DBUA then asks you to choose aflash recovery area, which, as described earlier in this chapter, is used asthe default area for your backup and recovery-related operations.

■ Choose database passwords. In the Database Credentials screen, the DBUAasks you to choose passwords for users like SYSMAN and DBSNMP, whichare default users of all Oracle databases.

■ Verify the details of the upgrade The Upgrade Summary screen comes next.The summary includes the source and target database names and databaseversions. You should verify the following important details at this stage:

■ Database name

■ Oracle Homes for the source and target databases

■ Source and target database versions

The Upgrade Summary screen also shows an estimate of the database upgradetime. Click Finish to start the upgrade process. Figure 1-4 shows the upgradeprogress screen of the DBUA.

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 36: OCA OCP - Oracle10G New Features For Administrators Exam Guide

36 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

■ Accept upgrade results or restore from backup. Finally, after the upgradeis completed, the DBUA shows you the results in the Upgrade Resultsscreen, as shown in Figure 1-5. You can do three tasks using the UpgradeResults screen:

■ Check the upgrade details.

■ Manage passwords in the database.

■ If you wish, restore the pre-upgrade database.

How to Restore to the Pre-Upgrade VersionAmazingly, you can now choose to go back to the pre-upgrade version of your database,if you so choose. You can do this by simply clicking the Restore button. This willrestore the database to the pre-upgrade version, if you have chosen the option to havethe RMAN perform a cold backup during the DBUA process. If you didn’t use theDBUA to perform the backup (through the RMAN), it will tell you that it cannotperform a restore.

FIGURE 1-4

The DBUAupgrade progressscreen

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 37: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using the Simplified Upgrade Process 37

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

You can automatically revert to an older version of your database afterthe 10g upgrade completes only if you’ve used the DBUA to back up yourdatabase first.

What if you chose not to restore the database to the pre-upgrade status, and laterfound that you had made a terrible mistake in turning down the kind offer of theDBUA to undo the upgrade process? Not to worry—you can just run an Oracle-provided script to restore back to the pre-upgrade database. This script is created byOracle when you choose to back up the database during the beginning part of theupgrade process. Here’s how I ran the script on my Windows machine to undo anOracle Database 10g upgrade (Note that finance is the name of my recently upgradeddatabase.)

SQL> @C:\oracle\product\10.1.0\admin\finance\backup\FINANCE_restore.bat

FIGURE 1-5

The DBUAUpgrade ResultsScreen

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 38: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CERTIFICATION OBJECTIVE 1.08

Starting Up the Database Usinga New Mode When Upgrading

Although Oracle strongly recommends that you use the DBUA tool to upgrade yourdatabase, we’ll step through the manual database process in this section, so youunderstand the various activities that a database upgrade involves. This will also giveyou the chance to see how to start up a database using a new mode—startup upgrade—when you are upgrading it to Oracle Database 10g.

Remember that the DBUA automatically performs virtually all the same steps foryou behind the scenes. After you run your Upgrade Information Tool, as describedearlier in this chapter, make sure you’ve made all the recommended changes, so youdon’t run into unnecessary error messages during the upgrade process.

Steps in the Manual Upgrade ProcessHere are the steps in the manual upgrade process:

1. Start a spool file.

2. Start the Upgrade Information Tool.

3. Back up your current database.

4. Copy your present init.ora file to the new Oracle Database 10g default location.

5. If you are using a Windows-based version of Oracle, remove the old instance.

6. Start up the database.

7. Create the SYSAUX tablespace.

8. Run the upgrade script.

9. Verify the existence of invalid objects.

10. Run the utlrp.sql script to automatically recompile and validate all theinvalidated PL/SQL and Java code in your database.

11. Run the utlu101s.sql script (the Post-Upgrade Status Tool).

These steps are detailed in the following sections:

38 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 39: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Start a Spool FileStart a spool file, so you can easily review the upgrade process.

SQL> spool upgrade.log

Run the Upgrade Information ToolRun the Upgrade Information Tool while connected to the database that you areupgrading. The Upgrade Information Tool is run by executing the utlu101i.sql script,which is located in the new Oracle Database 10g software’s ORACLE_HOME/rdbms/admin directory.

SQL> @$ORACLE_HOME/rdbms/admin/utlu101i.sql

To review the results of this pre-upgrade check, turn spooling off using thefollowing command:

SQL> spool off

Here’s the partial output from a test I ran on my Windows server. Note that I amupgrading an Oracle 8.17 database to the Oracle Database 10g version.

*************************************************************************Database:–> name: FINANCE–> version: 8.1.7.0.0–> compatibility: 8.1.0WARNING: Database compatibility must be set to 9.2.0 prior to upgrade.***********************************************************************Update Parameters: [Update Oracle Database 10.1 init.ora or spfile]WARNING: –> "shared_pool_size" needs to be increased to at least "150944944"*************************************************************************Obsolete Parameters: [Update Oracle Database 10.1 init.ora or spfile]–> "job_queue_interval"–> "max_enabled_roles”*************************************************************************Components: [The following database components will be upgraded or installed]–> Oracle Catalog Views [upgrade]–> Oracle Packages and Types [upgrade]...*************************************************************************SYSAUX Tablespace: [Create tablespace in Oracle Database 10.1 environment]–> New "SYSAUX" tablespace.... minimum required size for database upgrade: 500 MBPlease create the new SYSAUX Tablespace AFTER the Oracle Database10.1 server is started and BEFORE you invoke the upgrade script.

Starting Up the Database Using a New Mode When Upgrading 39

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 40: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Back Up Your DatabaseAt this point, shut down and back up your current database, by using either theRMAN or by using user-managed backup techniques.

Copy Your init.ora FileCopy your present init.ora file to the new Oracle Database 10g default location (forexample, $ORACLE_HOME/dbs under UNIX). Make all the necessary changes inyour init.ora parameter file, as per the Upgrade Information Tool’s recommendations.

Completely Remove Any Windows-Based Oracle InstancesIf you are using a Windows-based Oracle version, you need to do the following, tomake sure that you completely remove the old instance before creating the new OracleDatabase 10g instance.

C:\> net stop oracleservicefinanceThe OracleServiceFINANCE service is stoppingThe OracleServiceFINANCE service was stopped successfully.C:\> oradim -delete -sid financeInstance deleted.C:\>C:\>oradim -new -sid finance -intpwd finance1 -startmode auto –pfile c:\oracle\product\10.1.0\Db_1\database\initfinance.oraInstance created.C:\>

Start Up the New DatabaseStart up the database under the new Oracle Database 10g Home, after making surethat the updated init.ora parameter file is in its default location.

Make sure you start up the Oracle Database 10g in the following manner, to startthe upgrade process. Note the use of the new startup upgrade command. Youmust use this command, or the upgrade won’t start. Using the startup upgradecommand tells Oracle to automatically modify certain parameters, includinginitialization parameters that cause errors otherwise (for example, it sets the job_que_processes parameter to zero).

C:\> sqlplus /nologSQL*Plus: Release 10.1.0.2.0 - Production on Wed Apr 14 11:13:25 2004Copyright (c) 1982, 2004, Oracle. All rights reserved.SQL> connect / as sysdba

40 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 41: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Connected to an idle instance.SQL> startup upgradeORACLE instance started.Total System Global Area 310378496 bytesFixed Size 788268 bytesVariable Size 309328084 bytesDatabase Buffers 0 bytesRedo Buffers 262144 bytesDatabase mounted.Database opened.SQL>

Create the SYSAUX TablespaceAfter you start up the database with the startup upgrade command, first createthe new mandatory SYSAUX tablespace, as recommended by the Upgrade InformationTool. Here’s an example:

SQL> CREATE TABLESPACE sysaux DATAFILE 'sysaux01.dbf'SIZE 500M REUSEEXTENT MANAGEMENT LOCALSEGMENT SPACE MANAGEMENT AUTOONLINE;

At this point, the database is technically converted into a Oracle 10g version,although you yet have to run the main upgrade script.The following querydemonstrates this:

SQL> select * from v$version;BANNER––––––––––––––––––––––––––––––––Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 – ProdPL/SQL Release 10.1.0.2.0 – ProductionCORE 10.1.0.2.0 ProductionTNS for 32-bit Windows: Version 10.1.0.2.0 – ProductionNLSRTL Version 10.1.0.2.0 – ProductionSQL>

Run the Upgrade ScriptAlthough the database is opened, and although the query on V$VERSION shows thatyour database in now an Oracle 10g version, you still need to run the actual upgradescript, which is your next task. Each version of Oracle has a separate upgrade script.Here are the various versions of Oracle you can directly upgrade to Oracle 10g, andthe corresponding upgrade script for each.

Starting Up the Database Using a New Mode When Upgrading 41

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 42: OCA OCP - Oracle10G New Features For Administrators Exam Guide

42 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

■ 8.0.6: u0800060.sql

■ 8.1.7: u0801070.sql

■ 9.0.1: u0900010.sql

■ 9.2: u0902000.sql

Since I am upgrading a 8.1.7 database, I choose the u08010870.sql upgrade script,which is located in the $ORACLE_HOME/rdbms/admin directory.

SQL> @c:\oracle\product\10.1.0\Db_1\rdbms\admin\u0801070.sql

The u0801070.sql upgrade script calls several other scripts to manage the upgradeprocess. The upgrade script will call various Oracle SQL scripts, as shown here:

call i0801070.sql:This loads all tables that are necessary to perform basic sql commands.call utlip.sql to invalidate views, procedures, packagescall c0801070.sql:This performs all necessary dictionary upgrades to bring the db from 8.1.7 tothe new release.call a0801070.sql:This performs all necessary upgrade using anonymous blocks.call cmpdbmig.sql

This calls the upgrade scripts for all of the components that have been loadedinto the database. The script uses procedures from the DBMS_REGISTRY packageto execute various component upgrades.

Verify the Existence of Invalid ObjectsDuring the upgrade process, Oracle will create, drop, and alter several database tablesand other objects. Thus, it’s only natural that several internal Oracle packages andprocedures will become invalidated during the course of the upgrade. Once theupgrade script finishes, you can verify the existence of invalid objects by running thefollowing script:

SQL> select count(*) from dba_objects2 where status = 'INVALID';

COUNT(*)–––––––16742

1 row selected.SQL>

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 43: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Recompile and Validate the Invalidated PL/SQL and Java CodeWow! A large number of procedures and packages have been invalidated, but not toworry! Just run the Oracle utlrp.sql script, which will automatically recompile andvalidate all the invalidated PL/SQL and Java code in your database. Of course, evenif you don’t recompile all the invalidated packages and procedures in this way, Oraclewill validate each object at run time, when a user accesses the object. However, thismight lead to a deterioration in run-time performance, so you’re better off recompilingall the objects during the upgrade process itself. Note that the utlrp.sql script actuallycalls another script—the utlprp.sql script, which is a wrapper based on the UTL_RECOMP package.

SQL> @C:\oracle\product\10.1.0\Db_1\rdbms\admin\utlrp.sqlTIMESTAMP–––––––––––––––––––––––––––––-COMP_TIMESTAMP UTLRP_BGN 2004-04-14 19:03:371 row selected.PL/SQL procedure successfully completed.TIMESTAMP–––––––––––––––––––––––––––––-COMP_TIMESTAMP UTLRP_END 2004-04-14 19:39:361 row selected.PL/SQL procedure successfully completed.PL/SQL procedure successfully completed.SQL>

Just to make sure that there aren’t any more invalid objects left, run the followingquery again:

SQL> select count(*) from dba_objects2 where status = 'INVALID';COUNT(*)

–––––0

1 row selected.SQL>

Besides validating all remaining invalidated database objects, the utlrp.sql scriptalso checks for the validity of each individual component in the database. As youhave seen earlier in this chapter, the DBA_SERVER_REGISTRY view will containinformation about all the component entries. The utlrp.sql script will update DBMS_SERVER_REGISTRY after it runs, to let Oracle know that it has validated all objects.

Starting Up the Database Using a New Mode When Upgrading 43

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 44: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You can also revert back manually to the older database by using the DB_Name_restore.bat file (under Windows). To restore your old database usingeither of the two methods mentioned here requires that you enabled theDBUA to perform a backup of your database (with the RMAN). If you chosenot to have the DBUA perform a pre-upgrade backup, you can still revert toyour old pre-Oracle 10g version database by simply restoring from your ownbackups. The key here is to ensure that you have a backup, either made byyou or created by the DBCA, before you start the upgrade process.

Run the Post-Upgrade Status ToolOnce you complete the upgrade process, run the following script, which works as thePost-Upgrade Status Tool.

SQL> @utlu101s.sql TEXT

The Post-Upgrade Status Tool provides a summary of the upgrade process, asshown in the following listing from my upgrade process (Note that the utlu101s.sqlscript is followed by the word TEXT, to enable the printing of the following output):

SQL> @c:\oracle\product\10.1.0\Db_1\rdbms\admin\utlu101s.sql TEXTPL/SQL procedure successfully completed.Oracle Database 10.1 Upgrade Status Tool 13-APR-2004 03:21:22–> Oracle Database Catalog Views Normal successful completion–> Oracle Database Packages and Types Normal successful completion–> JServer JAVA Virtual Machine Normal successful completion–> Oracle XDK Normal successful completion–> Oracle Database Java Packages Normal successful completion–> Oracle interMedia Normal successful completion–> Spatial Normal successful completion–> Oracle Text Normal successful completionNo problems detected during upgradePL/SQL procedure successfully completed.SQL>

Where does the Upgrade Status Tool get its information about the variouscomponents? The tool simply queries the DBA_SERVER_REGISTRY table todetermine the upgrade status of each individual component. You can get the sameoutput as that produced by the utlu101s.sql script, by running the following query:

SQL> select comp_id, comp_name, version, statusfrom dba_server_registry;

44 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:49 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 45: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Based on the outcome of your database upgrade, the Upgrade Status Tool willtell you one of the following: all the database components have been successfullyupgraded (Normal Successful Completion), or some of the components haven’t beencleanly upgraded. If a component hasn’t been cleanly upgraded, the Upgrade StatusTool will tell you the corrective action to take to fix the problem, as shown in thefollowing example.

SQL> @C:\oracle\product\10.1.0\Db_1\rdbms\admin\utlu101s.sql TEXTPL/SQL procedure successfully completed.Oracle Database 10.1 Upgrade Status Tool 14-APR-2004 04:59:46–> Oracle Database Catalog Views Normal successful completion–> Oracle Database Packages and Types Problem(s) detectedWARNING: ––> component status is not valid––> version is correct––> check upgrade log file for errors––> script="re-run base update "u" script"–> JServer JAVA Virtual Machine Normal successful completion–> Oracle XDK Normal successful completion–> Oracle Database Java Packages Normal successful completion–> Oracle interMedia Normal successful completion–> Spatial Normal successful completion–> Oracle Text Normal successful completionPL/SQL procedure successfully completed.SQL>

Don’t try to start your newly upgraded database under your old Oracle Homefor any reason—this will corrupt your database.

After the UpgradeYou have now successfully upgraded your database to the Oracle Database 10g(10.1.0.2.0) version. Of course, at this point, all your old application code, as welldatabase features, are strictly at the Oracle8i or Oracle9i level, depending on whatyour pre-upgrade database version was. Now, you can check out the various newfeatures of Oracle Database 10g, as well as most of the Oracle database features, seewhich ones are useful to you. The rest of this book focuses on explaining all the newdatabase administration features in Oracle Database 10g.

Starting Up the Database Using a New Mode When Upgrading 45

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:49 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 46: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CERTIFICATION SUMMARYThis chapter provided you with a summary of Oracle 10g’s innovations in the softwareinstallation and database upgrade areas. First, you looked at the support of new installationfeatures in Oracle 10g. These included the changes to the Oracle Enterprise Manager(OEM) tool. You learned the difference between local and central installation of theOEM. Other installation new features include the file storage options and backup andrecovery options. You also learned about the changes in the response file installation,as well as the new irreversibility factor relating to the COMPATIBLE initializationparameter.

You saw how you now perform an Oracle database installation from a single CD,with minimal hardware requirements. You then looked at how Oracle 10g providesyou both pre-installation and post-installation support tools to ensure easy softwareinstallation. Next, you learned about the new easier and cleaner Oracle softwaredeinstallation process.

46 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

The exam contains questions about trackingOracle Database 10g feature usage. Payparticular attention to tracking feature usagethrough OEM as well as the DBA_FEATURE_USAGE_STATISTICS view. Something elsethat the test might focus on are the high-watermark statistics for various database objects.Which database objects does Oracle collecthigh-water mark statistics for?

The test expects you to know the newOracle Policy Framework. How do youprioritize policy violations along variouscategories? The test may include a questionabout the new Database Cloning Tool(OEM Database Cloning wizard). What arethe various features of the source and targetdatabases during a cloning operation?

You must understand the COMPATIBLEinitialization parameter accurately for the test.The exam tests your knowledge of the DBCAtool in creating a new database. Please look atthe various DBCA screens carefully. Whatmanagement options does the DBCA enableyou to configure?

The exam will include a question ortwo about the upgrade process. You mustunderstand how to use the Pre-UpgradeInformation Tool and the Post_UpgradeStatus Tool. What scripts start these tools?You must also understand the role of theDBA_SERVER_REGISTRY during adatabase upgrade. How do you recompileinvalid objects?

INSIDE THE EXAMINSIDE THE EXAM

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:49 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 47: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The Database Creation Assistant (DBCA) has many changes, and this chapterreviewed all of them. These include the mandatory creation of the SYSAUXtablespace, the creation of the flash recovery area, and the Automatic StorageManagement (ASM) storage option. Management options include a choice betweenthe OEM Database Control and the OEM Grid Control. You also saw how the OEMcan now be used to link with OracleMetaLink service, perform database cloning, andenforce a predetermined policy-based configuration framework.

An interesting new feature is how you can track database feature usage and high-water mark (HWM) statistics. This chapter demonstrated how to use this featureboth manually as well as through the OEM Database Control.

In the database upgrade section, you first reviewed the supported upgrade pathsto the new Oracle Database 10g version. I then took you step-by-step through botha manual and a DBUA database upgrade. You learned about the Oracle pre-upgradechecks and the post-upgrade validation as well.

Starting Up the Database Using a New Mode When Upgrading 47

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:49 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 48: OCA OCP - Oracle10G New Features For Administrators Exam Guide

✓TWO-MINUTE DRILL

Installation New Features Support❑ You have more management choices than with previous versions if you decide

to let Oracle create the starter database.

❑ The Oracle Universal Installer (OUI) now performs a series of pre-installationchecks before the installation process can start.

❑ You have a choice between two types of Oracle Enterprise Manager (OEM):local management using the OEM Database Control or central managementusing the OEM Grid Control. With the Database Control, you can manageonly a single database. With the Grid Control, you can manage several nodesat once.

❑ The OEM Database Control comes with the Oracle 10g software installation.You need to install the OEM Grid Control separately, using a separate CD.

❑ The default port number for the OEM Database Control is 5500.

❑ The installer enables you to configure default backup strategies.

❑ The installer gives you three storage choices: traditional UNIX/Windows filesystems, Automatic Storage Management (ASM), and raw devices.

❑ You need to specify database user (SYS and SYSTEM, for example) passwordsduring database creation time.

❑ You can invoke the OUI from any node on a cluster that is part of aninstallation.

❑ The Oracle 10g installer supports the installation of Cluster Ready Services(CRS).

❑ You can use the OEM Grid Control to perform enterprise-wide configurationchanges.

❑ There are several changes in the response file creation, enabling a truly“silent” installation. These changes include the following:

❑ New header formats

❑ No need to specify X server

❑ No need to specify the DISPLAY variable

❑ No instantiation of GUI classes

48 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:49 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 49: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Performance Enhancements to the Installation Process❑ Performance enhancements include a single CD Oracle software installation.

Companion CDs contain documentation, client software, demos, and theOEM Grid Control components.

❑ Minimal hardware requirements are now necessary for Oracle 10g installation.

❑ The OUI performs most of the automatic pre-installation checks. It checksfor the correct operating system version, kernel parameters, patches, diskspace, and so on.

❑ Oracle also provides a new post-installation tool called the Upgrade StatusTool. You can invoke the Upgrade Status Tool by running the script$ORACLE_HOME/rdbms/admin/utlu101s.sql.

❑ Oracle 10g enables a cleaner software deinstallation process, wherein itremoves all the necessary files automatically as well as performing thenecessary Registry changes in Windows systems.

❑ Due to the new irreversible file compatibility feature, you cannot revert toa lower compatibility value after you create a new Oracle 10g database.

❑ The minimum value of the compatibility setting is 9.2.0.

❑ The default setting of the compatibility setting is 10.0.0. This is also themaximum value for the COMPATIBLE initialization parameter under OracleDatabase 10g Release 10.1.

❑ You now need a new mandatory tablespace, called the SYSAUX tablespace,to store database metadata relating to various tools like the LOGMNR. Thisbrings the number of minimum tablespaces in an Oracle database to two;SYSTEM is the other mandatory tablespace.

❑ The Database Configuration Assistant (DBCA) automatically creates theSYSAUX tablespace for you.

❑ The flash recovery area is space that is dedicated to all backup and recovery-related activities and files. The DBCA automatically creates this for you.

❑ You can now link OEM directly to the OracleMetaLink service. This enablesthe automatic tracking of new software patches.

❑ You can now use the OEM to clone databases, provided you use RMAN toback up the source databases. You can do this by selecting Maintenance |Deployments | Clone Database from the OEM home page.

Two-Minute Drill 49

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:49 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 50: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Simplified Instance Configuration❑ To simplify basic instance configuration, Oracle now divides initialization

parameters into two groups: basic and advanced.

❑ There are about 25 to 30 basic initialization parameters (I saw the precisefigure of 28 initialization parameters in one Oracle Corporation white paper).

❑ There are several enhancements in the DBCA, which enables you toconfigure the following:

❑ SYSAUX tablespace

❑ Flash recovery area

❑ Automatic Storage Management (ASM)

❑ You can now link the OEM directly to the OracleMetaLink service.

❑ You can automatically download patches through OracleMetaLink now.

❑ Using the OEM, it is easy to clone databases now.

Viewing Database Feature Usage Statistics❑ You can now view database feature usage statistics for various Oracle features

like auditing through the OEM Database Control. You can also view thefeature usage by querying the view DBA_FEATURE_USAGE_STATISTICS.

❑ You can view high-water mark (HWM) statistics for objects like tables,indexes, and datafiles. The new view that you can use to check HWMstatistics is called DBA_HIGH_WATER_MARK_STATISTICS.

❑ You can now track whether your database is following predetermineddatabase configuration policies, and record all policy violations. Again, youcan use the OEM to perform this task.

Supported Upgrade Paths to Oracle Database 10g❑ You can directly upgrade to the Oracle 10g (10.1.0) version only if you are

currently using the 8.0.6, 8.1.7, 9.0.1, or a 9.0.2 version database.

❑ You can upgrade to Oracle 10g by using the Database Upgrade Assistant(DBUA) or by using a manual method.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

50 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:50 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 51: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using New Utility to Perform Pre-Upgrade Validation Checks❑ Use the new Upgrade Information Tool to gather pre-upgrade information.

You invoke this tool by running the utl101i.sql script located in the$ORACLE_HOME/rdbms/admin directory.

Using the Simplified Upgrade Process❑ During a database upgrade, Oracle will now consult a new internal table

called the DBA_SERVER_REGISTRY. This table contains names of all thecomponents you are going to be upgrading, as well as their post-upgrade status.

❑ Oracle recommends that you use the DBUA to perform all database upgrades,in order to reduce mistakes and make the process a lot simpler.

❑ The DBUA performs pre-upgrade checks including the following:

❑ Changes the ORACLE_HOME settings

❑ Changes the /etc/oratab entries

❑ Automatically deletes all obsolete initialization parameters

❑ Checks for adequate physical space for the upgrade

❑ Checks for any desupported character sets, invalid data types, and so on

❑ The DBUA will also provide you with a choice to back up your old database.

❑ Following are the upgrade steps using the DBUA:

❑ Start the DBUA by typing the command dbua in UNIX/Linux systems.In Windows systems, click the Database Upgrade Assistant button underthe Oracle Programs list.

❑ Select the database to be upgraded from the list provided by the DBUA.

❑ Allow the DBUA to create the mandatory SYSAUX tablespace.

❑ Choose automatic recompiling of all objects after the upgrade process.

❑ Choose either the OEM Database Control or Grid Control undermanagement options.

❑ Choose a flash recovery area, where Oracle will store all backup andrecovery-related files.

❑ Approve the upgrade process after looking at the summary provided bythe DBUA.

Two-Minute Drill 51

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:50 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 52: OCA OCP - Oracle10G New Features For Administrators Exam Guide

❑ If you choose to revert to the pre-upgrade version after the upgradeprocess, you can do so by clicking the Restore button in the final DBUAUpgrade Results screen.

Starting Up the Database Using a New Mode When Upgrading❑ Following is a summary of the steps in a manual upgrade process:

❑ Adjust the tablespace and redo log sizes if necessary.

❑ Remove any deprecated or obsolete parameters and add any necessarynew parameters.

❑ Back up your current database.

❑ Copy the present init.ora file after you modify it, to the new Oracle 10gdefault init.ora location.

❑ Under a Windows system, make sure the existing instance is stoppedand deleted using the oradim utility. Create a new instance using thesame utility.

❑ Start the database from the new Oracle 10g Home.

❑ Begin the upgrade process by issuing the command startup upgrade.

❑ Create the SYSAUX tablespace.

❑ Run the appropriate upgrade script for your database version (for example,u0801070.sql for an 8.1.7 version database).

❑ Once the upgrade script finishes running, compile any invalid objects byrunning the utlrp.sql script.

❑ Check to make sure there aren’t any invalid objects.

❑ Invoke the Upgrade Status Tool by running the utlu101s.sql script fromthe $ORACLE_HOME/rdbms/admin directory. Remember that you canget this information by querying the DBA_SERVER_REGISTRY tabledirectly.

❑ If the Upgrade Status Tool indicates “Normal Successful Completion” forall the database components, your upgrade is successful.

❑ For a successful upgrade, the query on the DBA_SERVER_REGISTRYview should indicate “valid” under the status column for all the databasecomponents in the new Oracle Database 10g.

52 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:50 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 53: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test 53

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

SELF TESTThe following questions will help you measure your understanding of the material presented in thischapter. Read all the choices carefully because there might be more than one correct answer. Chooseall correct answers for each question.

Installation New Features Support

1. Which of the following sets of tablespaces is mandatory for any Oracle 10g database?

A. SYSTEM, SYSAUX, and UNDOTBSB. SYSTEM and UNDOTBSC. SYSAUX and UNDOTBSD. SYSTEM and SYSAUX

2. What does a DBA need to do for Oracle to perform the automatic pre-installationrequirements check, when you start installing the Oracle Database 10g Server software?

A. Run the Upgrade Information Tool manually.B. Do nothing—Oracle will automatically perform the pre-installation checks.C. Use the upgrade database command to open the database.D. Execute the utls10x.sql script.

3. What does the Enterprise Configuration Management Tool do?

A. Helps you configure enterprise-wide configuration through the OEM Grid ControlB. Helps you configure enterprise-wide configuration through the OEM Database ControlC. Helps you configure the Oracle Database Control toolD. Collects only database information, not host information

Performance Enhancements to the Installation Process

4. During a response file-based “silent” Oracle installation, what do you need to do?

A. Specify an X server while performing installations in a character mode console.B. You don’t need to specify an X server while performing database installation in a character

mode console.C. Set a DISPLAY variable on UNIX systems.D. Use no header formats in the response file.

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:50 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 54: OCA OCP - Oracle10G New Features For Administrators Exam Guide

5. When you deinstall a Windows Oracle server installation, which of the following is true?

A. Oracle will automatically clean up the Windows Registry for you.B. You must manually clean up the Windows Registry.C. The Windows Registry doesn’t need to be changed.D. The Windows operating system automatically cleans up the Windows Registry for you.

6. When you complete the Oracle software installation, which of the following products doesOracle launch for you?

A. OEM Management AgentB. OEM Database ControlC. OEM Grid ControlD. OEM Management Agent and OEM Database Control

Simplified Instance Configuration

7. Which one of the following initialization parameters would belong to the basic groupof parameters?

A. SHARED_POOL

B. CURSOR_SPACE_FOR_TIME

C. DB_NAME

D. CURSOR_SHARING

8. If you use the DBCA to create your new database, when is the creation of the new flashrecovery area mandatory?

A. AlwaysB. Only if you configure automatic backup using the OEMC. Only if you configure user-managed backupsD. Only if you run your database in the archive log mode

9. Which of the following is a new initialization parameter for Oracle Database 10g?

A. UNDO_SUPPRESS_ERRORS

B. PARALLEL_AUTOMATIC_TUNING

C. RESUMABLE_TIMEOUT

D. SHARED_SERVER

54 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:50 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 55: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test 55

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

Viewing Database Feature Usage Statistics

10. Where are database usage and high-water mark statistics stored?

A. Flash recovery areaB. Automatic Workload RepositoryC. RMAN RepositoryD. In the bit map area of the datafiles

11. Which two of the following are examples of an Oracle database high-water mark statistic?

A. SGA sizeB. Number of named usersC. Size of the largest data segmentD. Maximum number of concurrent sessions

12. You have just upgraded your 8.1.7 release Oracle database to the new 10.1.0 version. Youdid not specify a value for the COMPATIBLE initialization parameter. After using the newdatabase for a while, you decide you need to revert to your 8.1.7 database. Which one of thefollowing is true under these circumstances?

A. You cannot return to the 8.1.7 version.B. Just add COMPATIBLE=8.1.7 to your initialization parameters. You should then be able

to go back to the 8.1.7 version.C. Use the ALTER DATABASE RESET COMPATIBILITY command to go back to the

8.1.7 version.D. You cannot go back to a time before the upgrade, unless you do a point-in-time recovery.

Supported Upgrade Paths to Oracle Database 10g

13. Which of the following Oracle versions is not an approved version for a direct upgrade toOracle 10g (10.1.0)?

A. 8.0.6B. 8.1.7C. 9.0.1D. 8.1.6

14. In which of the following modes can you upgrade your current database to the OracleDatabase 10g version?

A. Database Upgrade AssistantB. Oracle Data Migration Assistant

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:50 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 56: OCA OCP - Oracle10G New Features For Administrators Exam Guide

C. Export and importD. Manual upgrade

Using New Utility to Perform Pre-Upgrade Validation Checks

15. What is the name of the Oracle-supplied script that runs the pre-upgrade validation checks?

A. utlu101i.sqlB. utl101i.sqlC. utlu101x.sqlD. utlu101s.sql

16. If you are using the DBCA to upgrade your database to the Oracle Database 10g version, whichof the following is true in relation to the Upgrade Information Tool?

A. You don’t need to run the utlu101u.sql script.B. You must run the utl101u.sql script.C. You must run the utlu101s.sql script.D. You must choose the Pre-Upgrade Information Tool option while using the DBCA.

17. The Upgrade Information Tool provides information about which of the following?

A. Optimal SGA allocation to the various components of SGA, for example, the shared poolB. Optimal performance features of Oracle Database 10gC. Recommendations for additional space for tablespacesD. A time estimate for the upgrade

Using the Simplified Upgrade Process

18. You are using the DBUA to upgrade your database. One of the steps during the use of theDBUA is a choice regarding the recompilation of invalid objects. Telling the DBUA torecompile all invalid database objects after the upgrade is the same as running which script?

A. utlrpt.sqlB. utlu101i.sqlC. utlu101x.sqlD. utlrp.sql

19. You have just finished an Oracle Database 10g upgrade using the DBUA tool. You have chosenmost of the default settings, including letting the DBUA perform a pre-upgrade backup foryou. You are at the very end of the process, when the Upgrade Summary screen shows you the

56 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:50 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 57: OCA OCP - Oracle10G New Features For Administrators Exam Guide

upgrade details. You suddenly realize that you made a mistake, and you would like to revert tothe previous software version, which is an Oracle 8.1.7.3 database. What can you do?

A. Just start up the new database from the old Oracle 8.1.7.3 Home.B. Just click the Restore button on the update summary screen of the DBUA.C. You need to start fresh by manually restoring your 8.1.7.3 database.D. There is no way to restore to 8.1.7.3 at this point.

Starting Up the Database Using a New Mode When Upgrading

20. When you start up your database just prior to running the upgrade script, you need to usewhich of the following commands?

A. startup mount

B. startup nomount

C. startup open

D. startup upgrade

21. Once you upgrade your database to the Oracle Database 10g version, which of the followingis true?

A. You can always start it either under the old Oracle Home or the new Oracle Home.B. You will corrupt the database if you try to start it under the old Oracle Home.C. You can start it under the old Oracle Home, as long as your compatibility is set to the old

database version level.D. You can start it in either Oracle Home, as long as the compatibility level is set to 10.0.0.

LAB QUESTIONS

Lab 1

Using the OEM Database Control, find the locations of the following:

■ Tablespaces

■ Flash recovery area

Lab 2

Using the OEM Database Control, how do you find out the initialization parameters for the instance?

Lab Questions 57

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:50 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 58: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Lab 3

Manually create a SYSAUX tablespace with a size of 1GB.

Lab 4

Show all the command-line steps necessary to access the OEM Database Control (assume that noOEM-related process is currently running on your server).

Lab 5

Show the steps necessary to clone a database, and explain the cloning process in detail.

58 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:50 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 59: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test Answers 59

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

SELF TEST ANSWERS

Installation New Features Support

1. � D. SYSTEM and SYSAUX are the two mandatory tablespaces, without which you cannotcreate an Oracle Database 10g database.� A, B, and C are incorrect, since they include UNDOTBS, which isn’t a mandatorytablespace in Oracle Database 10g. Remember that you still can use manually configuredrollback segments, in which case you won’t need an undo tablespace.

2. � B. Oracle will automatically perform the pre-installation checks for you when you startinstalling the software. There are no scripts to run.� A is wrong because the Upgrade Information Tool is used only for upgrades, not forinstallations. It is the same case with option C as well. D is wrong since the utls101x.sql scriptperforms a post-upgrade check, not a pre-installation check.

3. � A. The Enterprise Configuration Management Tool, as its name indicates, helps you makeenterprise-wide configuration changes, using the OEM Grid Control.� B is wrong since, by definition, you cannot perform enterprise-wide changes using theOEM Database Control. C is wrong because the Oracle Database Control tool is configuredwhen you install the database software. D is wrong since the Enterprise Configuration Toolcollects database and host information across the enterprise.

Performance Enhancements to the Installation Process

4. � B. Oracle Database 10g makes the response file-based “silent” installations easier, and oneof the ways is by not forcing you to specify an X server in a character mode console.� A and C are incorrect because they are not true in the Oracle 10g version. D is wrong, asyou still need header formats in the response file, although the newer header formats are a loteasier to edit.

5. � A. The Oracle Universal Installer will automatically clean up the Windows Registry foryou as part of the software deinstallation process.� B is wrong because you don’t need to perform a manual cleanup of the Windows Registryanymore in the Oracle 10g database. C is incorrect since the Registry changes are necessaryafter a software deinstallation. D is wrong since the Windows operating system doesn’tautomatically clean up the Registry after an Oracle deinstallation.

6. � A, B, and D. Oracle launches both the OEM Management Agent and the OEM DatabaseControl automatically after installation.� C is wrong because the Oracle Universal Installer never launches the OEM Grid Controlis as part of Oracle server installation.

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:51 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 60: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Simplified Instance Configuration

7. � A and C. Both SHARED_POOL and DB_NAME belong to the basic set of initializationparameters, which should be sufficient in most cases. The parameters in the advanced list arenecessary only under some special conditions.� You can easily see that B and D refer to initialization parameters that belong to theadvanced group, not the basic group of parameters.

8. � B. The creation of the flash recovery area is mandatory only if you configure automaticbackups using the OEM.� A is clearly wrong, since the flash recovery area is not mandatory under all circumstances.C is wrong because configuring user-managed backups doesn’t have anything to with the flashrecovery area. D is wrong as well, since the archive log mode in which the database is runninghas no bearing on the flash recovery area.

9. � C. RESUMABLE_TIMEOUT is a new Oracle Database 10g initialization parameter.� A, B, and D refer to initialization parameters that have become obsolete in OracleDatabase 10g.

Viewing Database Feature Usage Statistics

10. � B. The MMON process periodically collects database usage and high-water mark statisticsand stores them in the Automatic Workload Repository.� A is wrong since the flash recovery area is free space reserved for recovery-relatedactivities. C is wrong since the RMAN repository is used to store backup-related data. D isclearly wrong, as bit maps in datafiles are used mostly for storage-related purposes.

11. � C and D. The size of the largest data segment shows the “high point” of resource usagefor that data segment, and thus it captures a high-water mark statistic. The same is true of themaximum number of concurrent sessions statistics.� A and B refer to statistics that aren’t part of the high-water mark statistics attributes.

12. � D. This is a tough question. Once you used the database for a while, you cannot set thecompatibility back to a lower version. The compatibility level can be set only higher, notlower. You just can’t start the new database with a lower level of compatibility. If you areprepared to lose all the changes made since the upgrade, of course, you can always performa point-in-time recovery to a time that precedes the upgrade.� A is wrong since it implies there is no way you can go back to the previous version ofthe software. B is wrong since you cannot set compatibility to a lower level compared to theexisting level. C is wrong since the alter database reset compatibilitycommand is obsolete in Oracle Database 10g.

60 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:51 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 61: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test Answers 61

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

Supported Upgrade Paths to Oracle Database 10g

13. � A, B, and C. These answers all represent database versions that permit a direct upgradeto Oracle Database 10g.� D. 8.1.6 belongs in the group of database versions that you cannot directly upgrade toOracle Database 10g.

14. � A, C, and D. You can use either the DBUA or manual upgrade procedure to performan identical upgrade. Export and import also enable an upgrade to Oracle Database 10g.� B. The Oracle Data Migration Assistant is the predecessor to the DBUA in previousversions of Oracle databases.

Using New Utility to Perform Pre-Upgrade Validation Checks

15. � A. The utlu101i.sql script located in the $ORACLE_HOME/rdbms/admin directory is thecorrect script to run the Upgrade Information Tool.� B misspells the correct script name. C refers to the wrong script. D is wrong because youuse this script for post-upgrade verification.

16. � A. It is true that if you use the DBCA, you don’t need to run the utlu101is.ql manually.The DBCA runs this for you, so it can provide you with vital upgrade-related information.� B is wrong, since you don’t need to run any scripts yourself, if you are using the DBCA.The same reasoning applies to choice C. D is wrong because the Upgrade Information Toolisn’t presented as an option to you by the DBCA; it automatically uses the tool before eachdatabase upgrade, by invoking the utlu101i.sql script.

17. � C and D. Both recommendations about additional space for tablespaces and upgrade timeestimates are part of the Upgrade Information Tool information.� A and B are invalid answers since the Upgrade Information Tool doesn’t give you anyperformance-related information. Its goal is to ensure that you can perform the upgradesuccessfully.

Using the Simplified Upgrade Process

18. � D. The utlrp.sql script will recompile all invalid objects in your database.� A misspells the correct answer. B and C both refer to pre-upgrade information scripts,not scripts that you run after an upgrade.

19. � B. As long as you have backed up the database using the DBUA, you can easily revertto the pre-upgrade version of the database by clicking the Restore button after the upgradeis completed.� A is wrong because you’ll end up corrupting your database if you start the upgradeddatabase from its old Oracle Home location. C is wrong because you don’t need to manually

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:51 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 62: OCA OCP - Oracle10G New Features For Administrators Exam Guide

62 Chapter 1: Installation, Server Configuration, and Database Upgrades

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

restore the database—as long as you let it perform a backup beforehand, the DBUA willperform the restore for you. D is incorrect because you can restore to 8.1.7 either throughthe DBA or through a manual restore, if necessary.

Starting Up the Database Using a New Mode When Upgrading

20. � D. You start a database with the new startup upgrade command prior to runningyour upgrade scripts. Oracle will issue an error otherwise!� A, B, and C are incorrect, since they don’t use the keyword upgrade.

21. � B. Once you upgrade your database to the Oracle Database 10g version, you must start itunder the new Oracle Database 10g Home. If you start it up under the old Oracle Home, youmay corrupt the database.� A and D are incorrect, since you cannot start the upgraded database from its old OracleHome. C is wrong since there is now no way (in Oracle 10g) to go to a lower level of databasecompatibility.

LAB ANSWERS

Lab 1

To find out which tablespaces exist in your database:

1. From the Database Control home page, click the Administration link.

2. From the Administration page, click Tablespaces.

To find out the size and location of the flash recovery area:

1. From the Database Control home page, click the Maintenance link.

2. From the Maintenance page, click Configure Recovery Settings.

3. Go to the flash recovery area settings.

Lab 2

To find the initialization parameters for the instance:

1. Go to the Database Control home page.

2. Click the Administration link.

3. Click the Initialization Parameters link in the Instance section.

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:51 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 63: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Lab Answers 63

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1

Lab 3

To manually create a SYSAUX tablespace with a size of 1GB:

SQL> CREATE TABLESPACE sysaux DATAFILE 'sysaux01.dbf'SIZE 1000M REUSEEXTENT MANAGEMENT LOCALSEGMENT SPACE MANAGEMENT AUTOONLINE;

Lab 4The command-line steps to access the OEM Database Control are as follows:

1. Check whether the dbconsole process is running. (Make sure your database is up as well.If it isn’t, there isn’t anything to manage!)

2. If the dbconsole process isn’t running, start it up by using the following command:

$> emctl start dbconsole

3. Once the dbconsole process starts up, you can access the Database Control using thefollowing URL in your web browser:

http://hostname:5500/em

5500 is the default HTTP port number, and it may be different in your case. Make sure youlog in as the SYS user or some other user with SYSDBA privileges.

Lab 5You must use RMAN to perform backups. You can use the Clone Database wizard (also referred toas the Clone Database Tool) to create a clone of an existing database. Following is a brief summaryof the cloning process:

■ The source database must be kept open.

■ The source database must belong to an Oracle 8.1.7 or higher version.

■ The Clone Database Tool (Clone Database wizard) will back up the source database files andcopy them to the target location.

■ The backup files are used to start up the new instance (in the OPEN mode), which has thesame initialization files as the source database.

Using the OEM, this is how you clone a database:

1. From the Database Control home page, click the Maintenance link.

2. Click the Clone Database link under the Deployments section.

P:\010Comp\CertPrs8\862-4\ch01.vpThursday, September 02, 2004 12:50:51 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 64: OCA OCP - Oracle10G New Features For Administrators Exam Guide

2Loading and

Unloading Data

CERTIFICATION OBJECTIVES

2.01 Introduction to the Data PumpArchitecture

2.02 Using Data Pump Export and Import

2.03 Monitoring a Data Pump Job

2.04 Creating External Tables forData Population

2.05 Defining Your External Table Properties

2.06 Transporting Tablespaces AcrossDifferent Platforms

✓ Two-Minute Drill

Q&A Self Test

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2Blind Folio 2:1

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2Blind Folio 2:1

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 65: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Almost every Oracle DBA is familiar with the traditional Oracle data-loading utilities:export and import. In Oracle Database10g, you now have a newer and morerefined version of the old export and import utilities, called the Data Pump export

and import utilities. The old export and import utilities continue to be available under OracleDatabase 10g, but Oracle would prefer you to use the Data Pump technology, because it offersyou more sophisticated features than the old export/import technology.

While the Data Pump export and import utilities look quite similar to the traditionalexport and import utilities, the new technology is vastly superior in many ways. Forexample, you can now interrupt export/import jobs in the middle, and then resumethem. You can even restart failed export and import jobs. You can also remap objectattributes to modify the objects. You can easily monitor your Data Pump jobs from adifferent session, and you can even modify job attributes on the fly, during the courseof a job. It is easy now to move massive amounts of data quickly, using parallelizationtechniques. Because Oracle provides you the Application Programming Interfaces(APIs) for the Data Pump technology, you can now easily incorporate export/importjobs within PL/SQL programs.

The Data Pump export and import jobs need more startup time than theold export and import utilities. Therefore, you may still want to use the oldexport and import utilities for small jobs.

In this chapter, you’ll also look at the new features related to transportable tables,as well as enhancements in the external tables feature, which was first introduced inOracle9i. In Oracle Database 10g, you can now write to external tables, instead of beingmerely be able to read from them.

■ Introduction to the Data Pump architecture

■ Using Data Pump export and import

■ Monitoring a Data Pump job

■ Creating external tables for data population

■ Defining external table properties

■ Transporting tablespaces across different platforms

Let’s start this very important chapter with a brief introduction to the new DataPump technology.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

2 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 66: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CERTIFICATION OBJECTIVE 2.01

Introduction to the Data Pump ArchitectureThe new Oracle Data Pump facility enables DBAs to transfer large amounts of dataand metadata at very high speeds compared to the older export/import technology.Data Pump manages multiple, parallel streams of data to achieve maximum throughput.Oracle claims that Data Pump enables you to decrease total export time by more thantwo orders of magnitude in most data-intensive export jobs. Imports are supposed torun 15 to 30 times faster than with the original import utility. Both of the above estimatesare for single-thread operations; parallel threads will make the operations even faster.

Oracle Data Pump is a complete superset of the original export and import utilities.In addition to all the old capabilities of the export and import utilities, Data Pumpalso lets you estimate job times, perform fine-grained object selection, monitor jobseffectively, and directly load one database from a remote instance.

For compatibility purposes, Oracle still includes the old export and import utilitiesin Oracle Database 10g. Thus, you can continue to use your export and import scriptsas usual, without any changes. Oracle Corporation recommends that you use theOracle Database10g Data Pump export and import, even though the older exportand import utilities are still available to you, because of the superior performanceprovided by the newer tools. Oracle will support the original import utility forever.This means that you’ll always have a way of importing dump files from earlier versionsof Oracle. However, Oracle will eventually deprecate the original export utility.

The new Data Pump technology lets you export data only to disk. You cannotuse a tape drive when performing a Data Pump export.

Oracle Data Pump technology consists of two components: the Data Pump exportutility, to unload data objects from a database, and the Data Pump import utility, toload data objects into a database. You access the two Data Pump utilities through apair of clients called expdp and impdp. As their names indicate, the first of thesecorresponds to the traditional export utility and the latter to the import utility. Youcan control both Data Pump export and import with the help of several parameters.Here’s how you invoke the two utilities:

$ expdp username/password (various parameters here)$ impdp username/password (various parameters here)

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Introduction to the Data Pump Architecture 3

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 67: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

4 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

I’m sure you are quite familiar with the interactive mode of using the traditionalexport and import utilities. In this mode, you enter your choices in response to variousprompts. The parameters are the same for the interactive and command-line modes,although you can use only a limited set of export and import parameters during aninteractive operation. Unlike in the old export and import utilities, Data Pumputilities have a set of parameters you can use at the command line and a set of specialcommands you can use only in an interactive mode. I’ll explain the main parameters,commands, and the important features of the Data Pump toolset in the followingsections. You can also get a quick summary of all Data Pump parameters and commandsby simply typing expdp help=y or impdp help=y at the command line.

The Data Pump export utility will unload data into operating system files knownas dump files. It writes to these files in a proprietary format, which only the Data Pumpimport utility can understand while loading the data in the dump files into the sameor another Oracle database. You can take Data Pump export dump files from anoperating system and import them into a database running on a different type ofplatform, as is the case with the older export/import utilities.

The original export and Data Pump dump files aren’t compatible. You can’tread export dump files with Data Pump and vice versa. The new features ofOracle Database 10g aren’t supported in the original export utility, whichyou’ll still have access to in Oracle Database 10g.

In addition to expdp and impdp, you can have other clients perform Data Pumpexport and import as well, by using the Data Pump API. The database uses the Oracle-supplied package DBMS_DATA PUMP to implement the Data Pump API. Throughthis package, you can programmatically access the Data Pump export and importutilities. This means that you can create powerful custom data-movement utilitiesusing the Data Pump technology.

The traditional export utility is a normal user process that writes data to its localdisks. The old export utility fetches this data from a server process as part of a regularsession. By contrast, the Data Pump expdp user process launches a server-side processthat writes data to disks on the server node, and this process runs independently ofthe session established by the expdp client.

The Data Pump technology is remarkably different from the traditional exportand import utilities. In the following sections, you’ll learn about those differencesas we cover the following topics:

■ Benefits of Data Pump technology

■ Data Pump components

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 68: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Introduction to the Data Pump Architecture 5

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

■ Data-access methods

■ Data Pump files

■ The mechanics of a Data Pump job

Benefits of Data Pump TechnologyData Pump technology offers several benefits over the traditional exportand import data utilities. The following are the main benefits of the DataPump technology:

■ Ability to restart data pump jobs You can now easily restart jobs that eitherhave stalled due to lack of space or have failed for various reasons. You mayalso voluntarily stop and restart jobs.

■ Parallel execution capabilities By simply specifying a value for thePARALLEL parameter, you can now choose the number of active executionservers for each export job.

■ Ability to attach to running jobs You now have the amazing capability toattach to a running Data Pump job from a different screen or location. Thisenables you to monitor jobs, as well as to modify certain parameters interactively.The jobs continue to run while you are attaching to and detaching from them.Data Pump is an integral part of the Oracle Database server, and as such, itdoesn’t need a client to run once it starts a job.

■ Network mode of operation Once you create database links between twodatabases, you can perform exports from a remote database straight to a dumpfile set. You can also perform direct imports via the network using databaselinks, without using any dump files. The network mode is a means of transferringdata from one database directly into another database via SQLNET with thehelp of database links, without needing to stage it on disk at all.

■ Fine-grained data import capability Oracle9i offered only one parameterthat gave you the ability to perform data loads at a fine-grained level. Thisparameter was QUERY, which enabled you to specify that the export utilityextract only a specified portion of a table’s rows. Now with Data Pump, youhave access to a vastly improved fine-grained options arsenal, thanks to newparameters like INCLUDE and EXCLUDE.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 69: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

6 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

■ Remapping capabilities During a data pump import, you now have theability to remap schemas and tablespaces, as well as filenames, by using thenew REMAP_ * parameters. Remapping capabilities enable you to modifyobjects during the process of importing data, by changing old attributes tonew values. For example, the REMAP_SCHEMA parameter enables you tomap all of user HR’s schema to a new user, OE. The REMAP_SCHEMAparameter is similar to the TOUSER parameter in the old import utility.

■ Ability to estimate space requirements In a Data Pump job, you can nowestimate the space requirements of a job by using either the ESTIMATE orthe ESTIMATE_ONLY parameter.

Data Pump ComponentsOn the surface, expdp and impdp, the clients for the Data Pump export and DataPump import utilities, respectively, are quite similar to the exp and imp commands.However, while they are syntactically similar to the Data Pump clients, exp and impare absolutely ordinary user processes that use SQL SELECT, CREATE, and INSERTcommands. In contrast, the new utilities are more like control processes that initiate jobs.

The new Data Pump technology is based entirely on the server; all data movementoccurs on the server. The older export and import utilities acted as clients throughwhich all the data movement took place. In Data Pump export and import, thedatabase instance handles the Data Pump utilities.

You can look at the Data Pump technology as consisting of three major components:

■ The DBMS_DATA PUMP package

■ The DBMS_METADATA package

■ The command-line clients, expdp and impdp

The DBMS_DATAPUMP package contains the guts of the Data Pump technology,in the form of procedures that actually drive the data loading and unloading jobs.The contents of this package perform the work of both the Data Pump export andimport utilities. In traditional export/import, Oracle uses normal SQL to take thedata in the export dump files and inserts it sequentially into the database tablesduring the import process. In the Data Pump technology, the DBMS_DATA PUMPpackage performs the export and import of data.

The DBMS_DATA PUMP is the main engine for driving data loading and unloading.To extract and modify data dictionary metadata, Oracle provides the DBMS_METADATApackage, which has been available since the Oracle9i version. In traditional export

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 70: OCA OCP - Oracle10G New Features For Administrators Exam Guide

and import utilities, the metadata of the objects is included in the export dump file.In Data Pump technology, you need to use the DBMS_METADATA package to extractthe appropriate metadata.

Note that both the packages—DBMS_DATA PUMP and DBMS_METADATA—act as APIs, in the sense that you can use either of them directly in your programsto load and unload data, without accessing the expdp and impdp clients.

Data-Access MethodsA Data Pump import or export job can access table data in either of two ways,depending on which one is faster for the specific case:

■ Direct path This access uses the Direct Path API. Direct path exports andimports lead to improved performance, since the direct path internal streamformat is the same format as the data stored in Oracle dump files. This leadsto a reduced need for data conversions.

■ External tables The external tables feature lets Oracle read data from andwrite data to operating system files that lie outside the database.

Since direct-path access doesn’t support intra-partition parallelism,external tables are used for very large data loading or unloading jobs.

It is up to Oracle to decide which access method it will employ for a given job.Oracle always tries to first use the direct-path method to load or unload data. Undersome conditions, such as the following, it may not able to use the direct method:

■ Clustered tables

■ Presence of active triggers in the tables

■ Export of a single partition in a table with a global index

■ Presence of referential integrity constraints

■ Presence of domain indexes on LOB columns

■ Tables with fine-grained access control enabled in the insert mode

■ Tables with BFILE or opaque type columns

In all these cases, the structure of the table and/or the indexes precludes the useof direct-path access, so Data Pump will use external tables. On the other hand, ifyour table has any LONG data, you must use the direct-path access.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Introduction to the Data Pump Architecture 7

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 71: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

8 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Data Pump FilesAs in the case of the traditional export and import utilities, Data Pump uses dump filesand other log files, but there are significant differences. You’ll use three types of filesfor Data Pump operations:

■ Dump files These hold the data for the Data Pump job.

■ Log files These are the standard files for logging the results of Data Pumpoperations.

■ SQL files Data Pump import uses a special parameter called SQLFILE,which will write all the Data Definition Language (DDL) statements it willexecute during the import job to a file. Data Pump doesn’t actually executethe SQL, but merely writes the DDL statements to the file specified by theSQLFILE parameter. You use SQL files only to hold the output of the SQLFILEcommand during a Data Pump import job. This parameter is discussed in the“Data Pump Import Parameters” section later in this chapter.

In Data Pump, you use directories and directory objects, unlike in the export andimport utilities. The following sections explain how to use directory objects.

Using Directory ObjectsRecall that the Data Pump technology is server-based, not client-based. This meansthat a Data Pump job creates all its dump files on the server, not on the client machinewhere a job may have originated. Oracle background processes are responsible for alldump file set I/O, on behalf of the privileged user ORACLE. This means that for securityreasons, you can’t let any user be able to specify an absolute file path on the server. Inaddition to a possible violation of security, there is the matter of safety, as you canunwittingly overwrite a server file if you are given the power to write dump files anywhereon the system. To avoid these problems, Data Pump uses directory objects.

Directory objects are named objects that Data Pump maps to a specific operatingsystem directory. For example, a directory object named dpump_dir1 can point to

The datafile format isidentical in external tables and thedirect-access method. Therefore, you

can easily export data with one methodand import it with the other method,if you wish.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:42 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 72: OCA OCP - Oracle10G New Features For Administrators Exam Guide

the /u01/app/oracle/admin/export directory on the server. You can then access theexport directory by simply using the dpump_dir1 directory object name. Here’s howyou create a directory object:

SQL> CREATE DIRECTORY dpump_dir1 as 'c:/oracle/product/10.1.0/oradata/export';Directory created.

To create a directory, a user must have the DBA role or have the CREATE ANYDIRECTORY privilege.

In order for a user to use a specific directory, the user must have access privilegesto the directory object. For example, in order to grant user SALAPATI privileges onthe new directory dpump_dir1, you need to grant the following privileges:

SQL> grant read, write on directory dpump_dir1 to salapatiGrant succeeded.SQL>

You’ll need the write privilege on all files for Data Pump export. During animport, you’ll need read access to the export dump file. You’ll also need writeprivileges on the directory for import, so that you can write to the log file.

Once you create a directory and grant the necessary rights, all Data Pump exportand import jobs can use the DIRECTORY parameter to specify the name of thedirectory object (DIRECTORY=dpump_dir1). This way, the DIRECTORYparameter will indirectly point to the actual operating system directories and files.Here’s an example:

$ expdp salapati/password dumpfile=dpump_dir1.testexp01.dmp

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Introduction to the Data Pump Architecture 9

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

You can create adefault directory with the nameDATA_PUMP_DIR, and then not needto specify the DIRECTORY parameter inyour export and import commands. Oraclewill automatically look for the directory

specified as the value for DATA_PUMP_DIR. Data Pump will write all dump files,SQL files, and log files to the directoryspecified for DATA_DUMP_DIR.Nonprivileged users cannot use thisdefault DATA_PUMP_DIR directory.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:42 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 73: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Specifying Directory ObjectsIn order for the Data Pump utilities to know where to place or get data for their exportand import jobs, you need to specify location information when you use the expdp andimpdp clients. As you know by now, you can’t use absolute directory path location forData Pump jobs; you must always use a directory object. However, there is more thanone way to specify this directory object name during an actual job, as explained in thefollowing sections.

Using the DIRECTORY Parameter Earlier in this section, you learned how tocreate a directory object. During a Data Pump export job, you can specify the directoryobject by using the DIRECTORY parameter, as shown in the following example.

$ expdp hr/hr DIRECTORY=dpump_dir1 …

Using the DIRECTORY:FILE Notation You may also specify the directoryobject without using the DIRECTORY parameter. You can do this by specifying thedirectory object’s name as part of the value for a specific Data Pump file (the dumpfile, log file, or SQL file). You may then use the specific directory object for a log filein the following manner:

$ expdp LOGFILE=dpump_dir2:salapati.log …

Note that the colon (:) separates the directory and filenames in the log filespecification. In this example, dpump_dir2 is the name of the directory object.The Data Pump filename is salapati.log.

Using the DATA_DUMP_DIR Environment Variable You can also usethe environment variable DATA_DUMP_DIR to point to a file location. In order touse the DATA_DUMP_DIR environment, you must have first created a specific directoryobject on the server. In this example, it is the dpump_dir1 directory describedearlier. Once you have this directory, you can then use the DATA_DUMP_DIRenvironment variable on the client to point to the directory object on the server.

In the following example, I first create a new directory object on the server, using thevariable DATA_DUMP_DIR. I then use the export command to save the value of theDATA_DUMP_DIR variable in the operating system environment. Once I do that, I canjust specify a dump file for my export job, without specifically stating the directory location.

SQL> create_directory dump_dir2 AS '/usr/apps/dumpfiles2';$export DATA_PUMP_DIR dump_dir2$expdp salapati/password TABLES=employees DUMPFILE=employees.dmp

10 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:42 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 74: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Introduction to the Data Pump Architecture 11

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Once you have made the DATA_DUMP_DIR variable part of your operating systemenvironment, you don’t need to specify the actual directory name (dump_dir2)explicitly (by using the DIRECTORY parameter) when you invoke a Data Pumpexport, as shown in the previous example. You merely need to specify the name, notthe location, for the DUMPFILE parameter.

Understanding the Order of Precedence for File LocationsNow that we have reviewed the various ways you can specify a directory objectfor a Data Pump job, you may wonder how Oracle knows which location to use incase there is a conflict. You can have a situation where you muight have specified aDATA_DUMP_DIR environment variable, but you then also specify a DIRECTORYparameter for the export job. Which directory will Oracle choose to use? Here’s theorder of precedence for directory objects:

1. Oracle will look to see if a directory name is used as part of a file parameter(for example, the LOGFILE parameter). Remember that in these cases, thedirectory object is separated from the filename by a colon (:).

2. Oracle’s second choice would be to use the directory objects assigned to theDIRECTORY parameter during the export or import job. If you explicitlyspecify the DIRECTORY parameter, you don’t need to use the directoryname as part of the file parameter.

3. Finally, Oracle looks to see if there is a default server-based directory objectnamed DATA_PUMP_DIR. You must have explicitly created this directoryobject beforehand. Note that the default DATA_DUMP_DIR object isavailable only to DBAs and other privileged users.

The directory object name resolution simply means that Oracle knows whichdirectory it should be using to read or write datafiles. However, you must havealready granted the database read/write privileges at the operating system level,in order to enable the database to actually use the operating system files.

The Mechanics of a Data Pump JobThe Data Pump export and import utilities use several processes to perform their jobs,including the key master and worker processes, as well as the shadow process and clientprocesses. Let’s look at these important Data Pump processes in detail.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:42 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 75: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The Master ProcessThe master process, or more accurately, the Master Control Process (MCP),has a process name of DMnn. The full master process name is of the format<instance>_DMnn_<pid>.

There is only one MCP for each job, and this process controls the executionand sequencing of the entire Data Pump job. More specifically, the master processperforms the following tasks:

■ Creates jobs and controls them

■ Creates and manages the worker processes

■ Monitors the jobs and logs the progress

■ Maintains the job state and restart information in the master table

■ Manages the necessary files, including the dump file set

The master process uses a special table called the master table to log the locationof the various database objects in the export dump file. The master table is at theheart of every Data Pump export and import job. The master process maintains thejob state and restart information in the master table. Oracle creates the master tablein the schema of the user who is running the Data Pump job at the beginning of everyexport job. The master table contains various types of information pertaining to thecurrent job, such as the state of the objects in the export/import job, the locationof the objects in the dump file set, the parameters of the job, and the status of allworker processes.

The master table has the same name as the export job, such as SYS_EXPORT_SCHEMA_01.

The master process uses the master table only for the duration of the export. Atthe very end of the export, as the last step in the export job, it writes the contentsof the master table to the export dump file and automatically deletes the mastertable from the database. The deletion of the master table will occur automatically,as long as the export completed successfully (or if you issue the KILL_JOB command).However, if you use the STOP_JOB command to stop a job or the export fails forsome reason, the master table isn’t deleted from the database. (Data Pump jobcommands are described in the “Data Pump Export Parameters” section later inthis chapter.) When you restart the export job, it will then use the same mastertable. Since the master table tracks the status of all the objects, Data Pump caneasily tell which objects are in the middle of an export and which have beensuccessfully exported to the dump files.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

12 Chapter 2: Loading and Unloading Data

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:42 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 76: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The master process will re-create the master table saved by the export utility in thedump file, in the schema of the user who is performing the import. This is the first stepin any Data Pump import job. (Note that you don’t need to create any tables, becausethe import utility will automatically do this for you.) The Data Pump import utilityreads the contents of the mastertable to verify the correctsequence in which it shouldimport the various exporteddatabase objects. As in the caseof Data Pump export, if theimport job finishes successfully,Oracle will automaticallydelete the master table.

The Worker ProcessThe worker process is the process that actually performs the heavy-duty work of loadingand unloading data, and has the name DWnn (<instance>_DWnn_<pid>). TheMCP (DMnn) creates the worker process. The number of worker processes that themaster process will create depends on the degree of parallelism of the job. If you choosethe PARALLEL option for a load, Oracle splits up the worker processes into severalparallel execution coordinators.

The worker processes maintain the object rows of the master table. As the workerprocesses export or import various objects, they update the master table with informationabout the status of the various jobs: completed, pending, or failed.

Shadow ProcessWhen a client logs in to an Oracle server, the database creates an Oracle foregroundprocess to service Data Pump API requests. This shadow process creates the job consistingof the master table as well as the master process. Once a client detaches, the shadowprocess automatically disappears.

Client ProcessesThe client processes call the Data Pump’s API. You perform export and import with thetwo clients, expdp and impdp. Later in this chapter, you’ll learn about the variousparameters you can specify when you invoke these clients.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Introduction to the Data Pump Architecture 13

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

The master table containsall the necessary information to restarta stopped job. It is thus the key to DataPump’s job restart capability, whether thejob stoppage is planned or unplanned.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:42 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 77: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

14 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

CERTIFICATION OBJECTIVE 2.02

Using Data Pump Export and ImportThe Data Pump export utility corresponds to the traditional export utility, and youinvoke it with the client expdp. The Data Pump import utility corresponds to the oldimport utility, and you invoke it with the client impdp. In this section, you will learnhow to use both Data Pump utilities.

Data Pump export will load row data from database tables as well as object metadatainto dump file sets in a proprietary format that only the Data Pump import utility canread. The dump file sets, which are operating system files, will contain data, metadata,and control information. Dump file sets usually refer to a single file, such as the defaultexport dump file expdat.dmp.

Quite a few of the Data Pump import utility’s features are mirror images of theData Pump export utility. However, there are some features that are exclusive tothe new Data Pump Import utility.

In the following sections, we’ll look at Dump Pump export and import types,modes, and parameters, as well as some examples.

Data Pump Export TypesBy Data Pump export types, I simply mean the various ways in which you can run theData Pump utility. You can interface with the Data Pump export and import utilitiesthrough the command line, using a parameter file, or interactively.

Using the Command LineYou can use the Data Pump export utility from the command line in a manner similarto the traditional export utility. Here’s a simple example:

$ expdp system/manager directory=dpump_dir1 dumpfile=expdat1.dmp

As you can see, the command-line option would quickly get tiring if you weredoing anything but the simplest type of exports.

Using a Parameter FileRather than specifying the export parameters on the command line, you can put themin a parameter file. You then simply invoke the parameter file during the actual export.When you use parameter files, you don’t need to retype the same parameters.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:43 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 78: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

For example, you could create a small file called myfile.txt, with the followingexport parameters:

userid=system/managerdirectory=dpump_dir1dumpfile=system1.dmp

The file myfile.txt will be your export parameter file. Now, all you need to do inorder to export the system schema is invoke expdp with just the PARFILEparameter, as follows:

$ expdp parfile=myfile.txt

Using Interactive Data Pump ExportSince this is a certification upgrade book, I assume you have experience with previousversions of the export and import utilities. You also must be quite familiar with theinteractive feature of the export and import utilities. All you need to do during aninteractive export or import is merely type exp or imp at the command line, andOracle will prompt you for the rest of the information. Interactive Data Pump exportis quite different from the interactive mode of the older utilities. As you’ll see in thefollowing sections, Data Pump interactive mode isn’t meant to be used in the sameway as the exp/imp interactive mode.

In Data Pump export, you use the interactive method for one purpose only:when you decide you need to change some export parameters midstream, while thejob is still running. The way to get into the interactive mode is by pressing theCONTROL-C combination on your keyboard, which interrupts the running job andlets you participate in the export job in an interactive fashion. When you pressCONTROL-C during an export job, the running job will pause, and you’ll see theexport prompt (Export>) displayed on your screen. At this point, you can dealinteractively with the export utility, with the help of a special set of interestingcommands, which I’ll explain later in this chapter, in the “Interactive Mode ExportParameters” section. As you’ll see, you can also enter the interactive mode of operationby using the ATTACH command.

Using Data Pump Export and Import 15

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

You can use all command-line export parameters in an export

parameter file. The only exception isthe parameter PARFILE itself!

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:43 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 79: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You can also perform Data Pump export and import operations easily throughthe OEM Database Control interface. To use this feature, start the Database Controland go to the Maintenance | Utilities page. On that page, you can see the variouschoices for performing export and import of data.

You cannot start an interactive job using Data Pump export (or import).You can use the interactive mode only to intervene during a running job.

Data Pump Export ModesAs in the case of the regular export utilities, you can perform Data Pump export inseveral modes. The following four modes in which you can perform an export do notdiffer from the traditional modes of operation using the older export utility:

■ Full export mode You use the FULL parameter when you want to exportthe entire database in one export session. You need the EXPORT_FULL_DATABASE role to use this mode.

■ Schema mode If you want to export a single user’s data and/or objects only,you must use the SCHEMA parameter.

■ Tablespace mode By using the TABLESPACES parameter, you can exportall the tables in one or more tablespaces. If you use the TRANSPORT_TABLESPACES parameter, you can export just the metadata of the objectscontained in one or more tablespaces. You may recall that you can exporttablespaces between databases by first exporting the metadata, copying thefiles of the tablespace to the target server, and then importing the metadatainto the target database.

■ Table mode By using the TABLES parameter, you can export one or tables.The TABLES parameter is identical to the TABLES parameter in previousversions of Oracle.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

16 Chapter 2: Loading and Unloading Data

In Data Pump, theinteractive mode means that the exportor import job stops logging its progresson the screen and displays the export (or

import) prompt. You can enter the specialinteractive commands at this point. Notethat the export or import job keeps runningthroughout, without any interruption.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:43 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 80: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Data Pump Export ParametersSome of the Data Pump export commands are familiar to you from the traditionalexport utility. Others are quite new. Here, I’ll briefly run through the set of DataPump export parameters, providing detailed explanations for only the new andunfamiliar parameters. For this discussion, the parameters are grouped into thefollowing categories:

■ File- and directory-related parameters

■ Export mode-related parameters

■ Export filtering parameters

■ Estimation parameters

■ The network link parameter

■ Interactive mode export parameters

■ Job-related parameters

You can use all the following parameters at the command line or in parameterfiles, except those listed in the “Interactive Mode Export Parameters” section.

File- and Directory-Related ParametersYou can specify several file- and directory-related parameters during a Data Pumpexport job. Let’s look at these parameters in the following sections.

DIRECTORY The DIRECTORY parameter specifies the location of thedump and other files. A detailed discussion of how you can use this parameterwas presented in the “Using Directory Objects” section earlier in this chapter.

DUMPFILE The DUMPFILE parameter provides the name of the dump file towhich the export dump should be written. The DUMPFILE parameter replaces theFILE parameter in the old export utility. You can provide multiple dump filenamesin several ways:

■ You can create multiple dump files by specifying the %U substitution variable.

■ You can provide multiple files in a comma-separated list.

■ You can specify the DUMPFILE parameter multiple times for a singleexport job.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Using Data Pump Export and Import 17

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:43 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 81: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

If you specify the %U notation to indicate multiple dump files, the numberof files you can create is equal to the value of the PARALLEL parameter.

If you don’t specify the DUMPFILE parameter, Oracle will use the default nameexpdat.dmp for the export dump file, just as it does when you use the traditionalexport utility.

FILESIZE The FILESIZE parameter is purely optional, and it specifies the sizeof the dump file. If you don’t specify this parameter, the dump file has no limits onits size. If you use the FILESIZE parameter by specifying, say 10MB as the maximumdump file size, your export will stop if your dump file reaches its size limit, and youcan restart it after correcting the problem.

PARFILE The PARFILE parameter stands for the same thing it did intraditional export utility: the parameter file, wherein you can specify exportparameters in a file, instead of entering them directly from the command line.

LOGFILE and NOLOGFILE You can use the LOGFLE parameter to specifya log file for your export jobs. Here’s what you need to remember regarding thisparameter:

If you just specify the parameter without the directory parameter, Oracle willautomatically create the log file in the location you specified for the DIRECTORYparameter.

■ If you don’t specify this parameter, Oracle will create a log file namedexport.log. A subsequent export job will overwrite this file, because Oraclealways names the default log file simply export.log.

■ If you specify the parameter NOLOGFILE, Oracle will not create its log file(export.log). You’ll still see the progress of the export job on the screen, butOracle suppresses the writing of a separate log file for the job.

Export Mode-Related ParametersThe export mode-related parameters are the FULL, SCHEMAS, TABLES,TABLESPACES, TRANSPORT_TABLESPACES, and TRANSPORT_FULL_CHECKparameters. You’ve already seen all these parameters except the last one, in the “Data

18 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:43 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 82: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Pump Export Modes” section. The TRANSPORT_FULL_CHECK parameter simplychecks to make sure that the tablespaces you are trying to transport meet all theconditions to qualify for the job.

Export Filtering ParametersThere are several new parameters related to export filtering. Some of them aresubstitutes for old export parameters, and others offer new functionality. Let’s lookat these important parameters in detail.

CONTENT By using the CONTENT parameter, you can filter what goes into theexport dump file. The CONTENT parameter can take three values:

■ ALL exports both table data and table and other object definitions(metadata).

■ DATA_ONLY exports only table rows.

■ METADATA_ONLY exports only metadata.

Here’s an example:

$ expdp system/manager dumpfile=expdat1.dmp content=data_only

Note that the CONTENT=METADATA_ONLY option is equivalent to the rows=noption in the original export utility. However, there is no equivalent to the CONTENT=DATA_ONLY option in Data Pump.

EXCLUDE and INCLUDE The EXCLUDE and INCLUDE parameters aretwo mutually exclusive parameters that you can use to filter various kinds of objects.Remember how in the old export utility you used the CONSTRAINTS, INDEXES,GRANTS, and INDEXES parameters to specify whether you wanted to exportthose objects? Using the EXCLUDE and INCLUDE parameters, you now caninclude or exclude many other kinds of objects besides the four objects youcould previously.

Using Data Pump Export and Import 19

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:44 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 83: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Simply put, the EXCLUDE parameter helps you omit specific database object typesfrom an export or import operation. The INCLUDE parameter, on the other hand,enables you to include only a specific set of objects. Following is the format of theEXCLUDE and INCLUDE parameters:

EXCLUDE=object_type[:name_clause]INCLUDE=object_type[:name_clause]

For both the EXCLUDE and INCLUDE parameters, the name clause is optional.As you know, several objects in a database—such as tables, indexes, packages,and procedures—have names. Other objects, such as grants, don’t have names.The name clause in an EXCLUDE or an INCLUDE parameter lets you apply aSQL function to filter named objects.

Here’s a simple example that excludes all tables that start with EMP:

EXCLUDE=TABLE:"LIKE 'EMP%'"

In this example, "LIKE 'EMP%'" is the name clause.The name clause in an EXCLUDE or INCLUDE parameter is optional. It’s purely

a filtering device, allowing you finer selectivity within an object type (index, table,and so on). If you leave out the name clause component, all objects of the specifiedtype will be excluded or included.

In the following example, Oracle excludes all indexes from the export job, sincethere is no name clause to filter out only some of the indexes.

EXCLUDE=INDEX

You can also use the EXCLUDE parameter to exclude an entire schema, as shownin the following example.

EXCLUDE=SCHEMA:"='HR'"

The INCLUDE parameter is the precise opposite of the EXCLUDE parameter: itforces the inclusion of only a set of specified objects in an export. As in the case ofthe EXCLUDE parameter, you can use a name clause to qualify exactly which objectsyou want to export. Thus, you have the ability to selectively choose objects at a fine-grained level.

The following three examples show how you can use the name clause to limit theselection of objects.

INCLUDE=TABLE:"IN ('EMPLOYEES', 'DEPARTMENTS')"INCLUDE=PROCEDUREINCLUDE=INDEX:"LIKE 'EMP%'"

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

20 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:44 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 84: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The first example is telling the Data Pump job to only include two tables: employeesand departments. In the second example, the INCLUDE parameter specifies thatonly procedures should beincluded in this export job.The third example showshow you can specify thatonly those indexes thatstart with EMP should bepart of the export job.

QUERY The QUERY parameter stands for the same thing as it does in traditionalexport: it lets you selectively export table row data with the help of a SQL statement.However, the parameter is enhanced for Oracle Database 10g by permitting you toqualify the SQL statement with a table name, so that it applies only to a particulartable. Here’s an example:

QUERY=OE.ORDERS: "WHERE order_id > 100000"

In this example, only those rows in the orders table where the order_id is greater than100000 are exported.

Estimation ParametersTwo interesting parameters enable you to estimate how much physical space yourexport job will consume. Let’s look at both these parameters in detail.

ESTIMATE The ESTIMATE parameter will tell you how much space your newexport job is going to consume. The space estimate is always in terms of bytes. Bydefault, Oracle will always estimate the space requirements in terms of blocks. Itsimply takes your database block size and multiplies it with the amount of blocks allthe objects together will need. Here is an example of what you’ll see in your log file(and on the screen):

Estimate in progress using BLOCKS method...Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATATotal estimation using BLOCKS method: 654 KB

Since the space estimation in terms of blocks is the default behavior, you don’tneed to specify the ESTIMATE parameter during the export. However, if you haveanalyzed all your tables recently, you can ask the Data Pump export utility to

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Using Data Pump Export and Import 21

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

The EXCLUDE andINCLUDE parameters are mutuallyexclusive. You can use one or the other,not both simultaneuously in the same job.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:44 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 85: OCA OCP - Oracle10G New Features For Administrators Exam Guide

estimate the space requirements by using the statistics the database has alreadycalculated for each of the tables. In order to tell the database to use the databasestatistics (rather than use the default BLOCKS method), you need to specify theESTIMATE parameter in the following manner:

ESTIMATE=statistics

Here’s what you’ll see in your log file when you use the ESTIMATE=statisticsparameter:

Estimate in progress using STATISTICS method...Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA. estimated "SYSTEM"."HELP" 35.32 KBTotal estimation using STATISTICS method: 65.72 KB

ESTIMATE_ONLY While the ESTIMATE parameter is operative onlyduring an actual export job, you can use the ESTIMATE_ONLY parameterwithout starting an actual export job. Here’s an example:

C:\>expdp system/manager estimate_only=yExport: Release 10.1.0.2.0 - Production on Saturday, 17 April, 2004 14:30…Total estimation using BLOCKS method: 288 KBJob "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at 14:30

Although the log indicates that the export job “completed successfully,” all thejob really did was to estimate the space that you will need for the export job.

The Network Link ParameterThe expdp utility provides you with a way to initiate a network export. Using theNETWORK_LINK parameter, you can initiate an export job from your server and haveData Pump export data from a remote database to dump files located on the instancefrom which you initiate the Data Pump export job.

Here’s an example that shows you how to perform a network export:

expdp hr/hr DIRECTORY=dpump_dir1 NETWORK_LINK=finance@prod1DUMPFILE=network_export.dmp LOGFILE=network_export.log

In the example, the NETWORK_LINK parameter must have a valid database link as itsvalue. This means that you must have created the database link ahead of time. You areexporting data from the finance database on the prod1 server.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

22 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:44 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 86: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

You can’t use Data Pump in the normal way to export data from a read-onlydatabase. This is because Data Pump can’t create the necessary master tableor create external tables on a read-only tablespace. Using the network mode,however, you can export data from a read-only database on server A to dumpfiles on server B, where Data Pump is running.

Interactive Mode Export ParametersAs I mentioned earlier in this chapter, the interactive mode of Data Pump is quitedifferent from the interactive export and import mode that you know. Traditionally, theinteractive mode gave you the chance to enter a limited set of export/import parametersat the command line in response to the queries made by the export or import utility.You use the interactive mode in the new Data Pump technology only to intervene inthe middle of a running job, to either suspend the job or modify some aspects of it.You can enter the interactive mode of Data Pump export in either of two ways:

■ You can use the CONTROL-C keyboard combination during a Data Pumpexport job, if you want to enter the interactive mode from the same sessionwhere you are running the Data Pump job.

■ You can either use a separate session or even a separate server to “attach”yourself to a running session by using—what else?—the ATTACH command.(You can also attach to a stopped job.) When you successfully attach yourselfto a job, you’ll be able to use specific export parameters in an interactive mode.

Let’s examine when you might use the interactive mode in Data Pump export.Suppose that you started a job in the evening at work and left for home. At midnight,you check the status of the job and find that it’s barely moving. You can easily startanother session, and then “connect” to the running job and monitor it by simplyusing the ATTACH command. When you do this, the running job does not pause.

Using Data Pump Export and Import 23

In the Data Pump export(and import), the only way to get intoan interactive mode of operation is byusing the CONTROL-C sequence or by

opening another session and “attaching”yourself to that session. You cannot startan interactive Data Pump session from thecommand line.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:44 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 87: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Instead, it opens an interactive window into the running session, so you can changesome parameters to hasten the crawling export job by running one of a special setof interactive Data Pump export commands. Here’s an example of the usage of theATTACH parameter:

C:\>expdp salapati/sammyy1 attach=SALAPATI.SYS_EXPORT_SCHEMA_01Export: Release 10.1.0.2.0 - Production on Saturday, 17 April, 2004 11:47…State: EXECUTING…Export>

You may attach multiple clients to a single job.

Once you attach yourself to a running job by using the ATTACH command orby using the CONTROL-C sequence on the server where the job is actually running,you get the interactive export prompt (Export>), indicating that Data Pump isawaiting your interactive commands. From the interactive prompt, you can useseveral interesting parameters to influence the progress of the currently executingData Pump job. Here are some examples of interactive commands:

Export> parallel=4Export> kill_jobExport> stop_jobExport> continue_client

I’ll explain these and other interactiveData Pump parameters in the followingsections, grouped in the categories ofclient-related parameters, job-relatedparameters, and other parameters.

Client-Related Interactive Parameters The CONTINUE_CLIENTparameter will take you out of the interactive mode and resume the runningexport job. Your client connection will still be intact, and you’ll continue tosee the export messages on your screen. However, the EXIT_CLIENT parameterwill stop the interactive session, as well as terminate the client session. In both ofthese cases, the actual Data Pump export job will continue to run unhindered.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

24 Chapter 2: Loading and Unloading Data

You must be a DBA, ormust have EXP_FULL_DATABASE or IMP_FULL_DATABASE roles, in order to attachand control Data Pump jobs of other users.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:45 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 88: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Job-Related Interactive Parameters You can use several job-related parametersfrom any interactive session you open with an export session using the ATTACHcommand. You can use the STOP_JOB command to stop the export job in an orderlyfashion. To stop it at once, use the STOP_JOB=immediate command. You canchoose to resume any export jobs you’ve stopped in this manner, with the help ofthe START_JOB parameter.

If you decide that you don’t really want to continue the job you’ve just attachedto, you can terminate it by using the KILL_JOB parameter. Unlike the EXIT_CLIENT parameter, the KILL_JOB parameter terminates the client as well as theexport job itself for good.

To summarize, the job-related interactive parameters work as follows:

■ STOP_JOB stops running Data Pump jobs.

■ START_JOB resumes stopped jobs.

■ KILL_JOB kills both the client and the Data Pump job.

Other Interactive Parameters From the interactive prompt, you can usethe ADD_FILE parameter to add a dump file to your job. You can also use the HELPand STATUS parameters interactively, and both of these parameters function thesame way as their command-line counterparts.

Job-Related ParametersSeveral Data Pump export parameters can be classified as job-related parameters.I’ll briefly discuss the important ones here.

JOBNAME You can use the JOBNAME parameter to provide your own jobname for a given Data Pump export/import job (for example, JOBNAME=myjob1).The JOBNAME parameter is purely optional, however. If you don’t use it, DataPump will generate a unique system name, of the format <USER>_<OPERATION>_<MODE>_%N. For example, if the user SYSTEM is performing an export of the

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Using Data Pump Export and Import 25

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

You can restart any jobthat is stopped, whether it’s stoppedbecause you issued a STOP_JOB command

or due to a system crash, as long as youhave access to the master table and anuncorrupted dump file set.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:45 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 89: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

26 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

database (FULL mode), the automatically generated job name will be SYSTEM_EXPORT_FULL_01. In this job name, SYSTEM is the user that is performing theData Pump job. EXPORT tells you it’s an export, not an import job. FULL indicatesthat this is full database export. The last part of the job name is a number, indicatingthe sequence number of the job. This was my first job in a new database, so my jobnumber happens to end with 01.

Remember that Oracle gives the master table, which holds critical informationabout your export job, the same name as the name of the job.

STATUS The STATUS parameter is useful while you’re running long jobs, as itprovides you with an updated status at intervals that you can specify. The parametertakes integer values that stand for seconds. For example, an anxious DBA (like me)might want to get an update every minute regarding an ongoing Data Pump exportjob. Here’s what you need to do to get your reassuring minutely updates:

$ expdp system/manager status=60 ……Worker 1 Status:State: EXECUTINGObject Schema: SYSTEMObject Name: SYS_EXPORT_SCHEMA_01Object Type: SCHEMA_EXPORT/TABLE/TABLE_DATACompleted Objects: 1Total Objects: 65

. . exported "SYSTEM"."REPCAT$_SITES_NEW"Job: SYS_EXPORT_SCHEMA_01Operation: EXPORTMode: SCHEMAState: EXECUTINGBytes Processed: 69,312Percent Done: 99Current Parallelism: 1Job Error Count: 0Dump File: C:\ORACLE\PRODUCT\10.1.0\ADMIN\EXPORT\EXPDAT6.DMPbytes written: 1,748,992

The STATUS parameter shows the overall percentage of the job that iscompleted, the status of the worker processes, and the status of the currentdata objects being processed.

PARALLEL PARALLEL is the mighty parameter that lets you specify morethan a single active execution thread for your export job. Note that the Data Pump

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:45 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 90: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Using Data Pump Export and Import 27

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

PARALLEL parameter has nothing to do with the other Oracle parallel features,but they can work together. The default value of the PARALLEL parameter is 1,meaning a single thread export operation writing to a single dump file. If you specifyanything more than 1 as the value for the PARALLEL parameter, you also shouldremember to specify the same number of dump files, so the multiple execution threadscan simultaneously write to the multiple dump files. Here’s an example that showshow you can set the level of parallelism to 3, forcing the export job to write inparallel to three dump files:

expdp system/manager DIRECTORY=dpump_dir1 DUMPFILE=par_exp%u.dmp PARALLEL=3

If you specify the PARALLEL parameter, make sure you allocate the samenumber of dump files as the degree of parallelism. The higher the degreeof parallelism, the higher will be the memory, CPU, and network bandwithusage as well.

In the previous example, the DUMPFILE parameter uses the substittion varable %uto indicate that multiple files should be generated, of the format par_expNN.dmp,where NN is a two-character integer starting with 01. Since the PARALLEL parameteris set to 3, the substitution variable will create three files with the following names:par_exp01.dmp, par_exp02.dmp, and par_exp03.dmp.

Note that you don’t need to use the %u substition variable to generate multipledump files when you choose a value of greater than 1 for the PARALLEL parameter.You could simply use a comma-separated list of values, as follows:

expdp system/manager DIRECTORY=dpump_dir1 PARALLEL 3DUMPFILE=(par_exp01.dmp,par_exp02.dmp,par_exp03.dmp)

If you don’t have sufficient I/O bandwidth, you may actually experience adegradation in Data Pump performance with the PARALLEL parameter.

Data Pump Export ExamplesLet’s look at some simple Data Pump export job specifications that demonstrate someof the new concepts you’ve learned in this chapter. The next example creates anexport dump file of just two tables: employees and jobs.

expdp hr/hr TABLES=employees,jobs DUMPFILE=dpump_dir1:table.dmp NOLOGFILE=y

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:45 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 91: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

28 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

The following example shows how to use a parameter file, as well as how touse the CONTENT and EXCLUDE parameters. The CONTENT=DATA_ONLYspecification means you are exporting just rows of data and excluding all objectdefinitions (metadata). The EXCLUDE parameter requries that the countries,locations, and regions tables be omitted from the export. The QUERY parameterstipulates that all the data in the employees table, except that belonging tolocation_id 20, be exported. The parameter file, exp.par, has the followinginformation:

DIRECTORY=dpump_dir1DUMPFILE=dataonly.dmpCONTENT=DATA_ONLYEXCLUDE=TABLE:"IN ('COUNTRIES', 'LOCATIONS', 'REGIONS')"QUERY=employees:"WHERE department_id !=20 ORDER BY employee_id"

You can then issue the following command to execute the exp.par parameter file:

$ expdp hr/hr PARFILE=exp.par

The following example illustrates a schema mode export. You don’t see anymention of the SCHEMA parameter; that’s because Data Pump will export a schema(of the exporting user) by default.

$ expdp hr/hr DUMPFILE=dpump_dir1:expschema.dmpLOGFILE=dpump_dir1:expschema.log

By default, Data Pump export will run the export in the schema mode.

Here’s an interesting Data Pump export example, showing how to use thePARALLEL, FILESIZE, and JOB_NAME parameters. It also illustrates the useof the DUMPFILE parameter when there are multiple dump files.

$ expdp hr/hr FULL=y DUMPFILE=dpump_dir1:full1%U.dmp, dpump_dir2:full2%U.dmpFILESIZE=2G PARALLEL=3 LOGFILE=dpump_dir1:expfull.log JOB_NAME=expfull

Now that you’ve seen how the Data Pump export utility works, you’re ready tolook at the Data Pump import features.

Data Pump Import Types and ModesAs in the case of exporting data, you can perform a Data Pump import job from thecommand line or use a parameter file. Interactive access to the import utility isavailable, but it is different from what you are used to when working with the

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:46 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 92: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Using Data Pump Export and Import 29

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

traditional export/import utilities. The interactive framework is analogous to theinteractive access to the Data Pump export utility, as you’ll see shortly.

You can use Data Pump import in the same modes as Data Pump export:table, schema, tablespace, and full modes. In addition, you can also employ theTRANSPORTABLE_TABLESPACES parameter to import the metadata necessaryfor implementing the transportable tablespaces feature.

You must have the IMPORT_FULL_DATABASE role in order to perform one ofthe following:

■ Full database import

■ Import of a schemaother than your own

■ Import of a table thatyou don’t own

Data Pump Import ParametersAs in the case of the Data Pump export utility, you control a Data Pump importjob with the help of several parameters when you invoke the impdp utility. Forthis discussion, the import parameters are grouped as follows:

■ File- and directory-related parameters

■ Filtering parameters

■ Job-related parameters

■ Import mode-related parameters

■ Remapping parameters

■ The network link parameter

■ The transform parameter

■ The flashback time parameter

File- and Directory-Related ParametersThe Data Pump import utility uses the PARFILE, DIRECTORY, DUMPFILE,LOGFILE, and NOLOGFILE commands in the same way as the Data Pump exportutility. However, SQLFILE is a file-related parameter unique to the import utility.

The SQLFILE parameter is similar to the old import utility’s INDEXFILEparameter. When you perform a Data Pump import, you may sometimes wish to

You’ll need the IMPORT_FULL_DATABASE role to perform animport if the dump file for the importwas created using the EXPORT_FULL_DATABASE role.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:46 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 93: OCA OCP - Oracle10G New Features For Administrators Exam Guide

extract the DDL from the export dump file. The SQLFILE parameter enablesyou to do this easily, as shown in the following example.

$ impdp salapati/sammyy1 DIRECTORY=dpump_dir1 DUMPFILE=finance.dmpSQLFILE=dpump_dir2:finance.sql

In this example, the SQLFILE parameter instructs the Data Pump import job to writethe DDL to the finance.sql file, located in the directory dpump_dir2. Of course, youmust have created dpump_dir2 prior to this, using the CREATE DIRECTORY AScommand. The DIRECTORY=dpump_dir1 parameter value tells Data Pump importwhere to find the dump file finance.dmp. This example also shows how you can usemultiple directories in a single Data Pump job.

It’s important to remember that the SQLFILE parameter just extracts the SQLDDL to the specified file—no actual data import whatsoever takes place. By usingthis parameter, you can extract a SQL script with all the DDL from your exportdump file. The DDL in SQLFILE lets you peek at what the import job will execute.

The other import file-related parameter is the new REUSE_DATAFILESparameter. This parameter tells Data Pump whether it should use existing datafilesfor creating tablespaces during an import. If you specify REUSE_DATAFILES=y,the import utility will write over your existing datafiles.

Filtering ParametersYou use the CONTENT parameter, as in the case of a Data Pump export, to determinewhether you’ll load just rows (CONTENT=DATA_ONLY), rows and metadata(CONTENT=ALL), or just metadata (CONTENT=METADATA_ONLY).

The EXCLUDE and INCLUDE parameters have the same meaning as in an export,and they are mutually exclusive. If you use the CONTENT=DATA_ONLY option, youcannot use either the EXCLUDE or INCLUDE parameter during an import.

You can use the QUERY parameter during import as well, in order to filter dataduring an import. In the older export/import utilities, you could use the QUERYparameter only during an export. You can use the QUERY parameter to specify anentire schema or a single table. Note that if you use the QUERY parameter duringimport, Data Pump will use only the external table data method, rather than thedirect-path method, to access the data.

What will Data Pump import do if there is a table creation script in the exportdump file, but the table already exists in the target database? You can use theTABLE_EXISTS_ACTION parameter to tell Data Pump what to do when a table

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

30 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:46 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 94: OCA OCP - Oracle10G New Features For Administrators Exam Guide

already exists. You can provide four different values to the TABLE_EXISTS_ACTION parameter:

■ With SKIP (the default), Data Pump will skip a table if it exists.

■ The APPEND value appends rows to the table.

■ The TRUNCATE value truncates the table and reloads the data from theexport dump file.

■ The REPLACE value drops the table if it exists, re-creates, and reloads it.

Job-Related ParametersThe JOB_NAME, STATUS, and PARALLEL parameters carry identical meaningsas their Data Pump export counterparts. Note that if you have multiple dump files,you should specify them either explicitly or by using the %u notation, as shown inthe Data Pump import section.

Import Mode-Related ParametersYou can perform a Data Pump import in various modes, using the TABLE, SCHEMAS,TABLESPACES, and FULL parameters, just as in the case of the Data Pump exportutility. You can use the TRANSPORTABLE_TABLESPACES parameter when youwish to transport tablespaces between databases.

Remapping ParametersThe remapping parameters are brand-new features in the Oracle Database 10g DataPump import utility, and they clearly mark the superiority of this utility over thetraditional import utility. Let’s briefly discuss each of these three parameters: REMAP_SCHEMA, REMAP_DATAFILE, and REMAP_TABLESPACE.

REMAP_SCHEMA Using the REMAP_SCHEMA parameter, you can moveobjects from one schema to another. You need to specify this parameter in thefollowing manner:

$ impdp system/manager dumpfile=newdump.dmp REMAP_SCHEMA=hr:oe

In this example, HR is the source schema, and Data Pump import will import all ofuser HR’s objects into the target schema OE. The import utility can even create theOE schema, if it doesn’t already exist in the target database. Of course, if you want to

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Using Data Pump Export and Import 31

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:46 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 95: OCA OCP - Oracle10G New Features For Administrators Exam Guide

just import one or more tables from the HR schema and import them into the OEschema, you can do that as well, by using the TABLES parameter.

The REMAP_SCHEMA parameter provides the same functionality as theFROMUSER/TOUSER capability in the old export and import utilities.

REMAP_DATAFILE When you are moving databases between two differentplatforms, each with a separate filenaming convention, the REMAP_DATAFILEparameter comes in handy to change file system names. The following is an examplethat shows how you can change the file system from the old Windows platform tothe new UNIX platform. Whenever there is any reference to the Windows file systemin the export dump file, the import utility will automatically remap the filename tothe UNIX file system.

$ impdp hr/hr FULL=y DIRECTORY=dpump_dir1 DUMPFILE=db_full.dmpREMAP_DATAFILE='DB1$:[HRDATA.PAYROLL]tbs6.f':'/db1/hrdata/payroll/tbs6.f'

REMAP_TABLESPACE Sometimes, you may want the tablespace into whichyou are importing data to be different from the tablespace in the source database.The REMAP_TABLESPACE parameter enables you to move objects from onetablespace into a different tablespace during an import, as shown in the followingexample. Here, Data Pump import is transferring all objects from the tablespaceexample_tbs to the tablespace new_tbs.

$ impdp hr/hr REMAP_TABLESPACE='example_tbs':'new_tbs'DIRECTORY=dpump_dir1PARALLEL=2 JOB_NAME=cf1n02 DUMPFILE=employees.dmp NOLOGFILE=Y

The Network Link ParameterUsing the new NETWORK_LINK parameter, you can perform an import across thenetwork, without using dump files. The NETWORK_LINK parameter enables import toconnect directly to the source database and transfer data to the target database. Here’san example:

$ impdp hr/hr TABLES=employees DIRECTORY=dpump_dir1NETWORK_LINK=finance@prod1 EXCLUDE=CONSTRAINT

In this example, finance@prod1 is the network link. It is a valid database link, createdby you beforehand using the CREATE DATABASE LINK command. Thus, the databaseshown in the database link is your source for the import job. Data Pump will import

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

32 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:47 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 96: OCA OCP - Oracle10G New Features For Administrators Exam Guide

the table employees from the remote database finance to your instance where yourun the Data Pump import job. In a network import, the Metadata API executes onthe remote instance, and extracts object definitions and re-creates necessary objectsin your local instance. It then fetches data from the remote database tables and loadsthem in your local instance, using the INSERT AS SELECT command, as follows:

insert into employees(emp_name,emp_id) … select (emp_name,emp_id) fromfinance@remote_service_name

Note that a Data Pump network import doesn’t involve a dump file, as Data Pumpwill import the table from the source to the target database directly.

EXERCISE 2-1

Using the NETWORK_LINK ParameterUsing the following information as your guidelines, perform an an import using theNETWORK_LINK parameter.

SQL> create database link L1connect to system identified by oracleusing 'db_name';

SQL> create directory d1 as 'e:\tmp';E:\> impdp userid=system/oracle tables=hr.regions network_link=L1remap_schema=HR:OE directory=D1

The TRANSFORM ParameterSuppose you are importing a table from a different schema or even a different database.Let’s say you want to make sure that you don’t also import the objects’ storage attrributesduring the import—you just want to bring in the data that the table contains. Whatcan you do? The new TRANSFORM parameter lets you specify that your Data Pumpimport job should not import certain storage and other attributes. Using the TRANSFORMparameter, you can exclude the STORAGE and TABLESPACE clauses, or just thestorage clause, from a table or an index.

During a Data Pump (or traditional) import, Oracle creates objects using the DDLthat it finds in the export dump files. The TRANSFORM parameter instructs the DataPump import job to modify the DDL that creates the objects during the import job.

Using Data Pump Export and Import 33

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:47 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 97: OCA OCP - Oracle10G New Features For Administrators Exam Guide

34 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

The TRANSFORM parameter has the following syntax:

TRANSFORM = transform_name:value[:object_type]

Here’s an example to help you understand the TRANSFORM parameter:

impdp hr/hr TABLES=hr.employees \DIRECTORY=dpump_dir1 DUMPFILE=hr_emp.dmp \TRANSFORM=SEGMENT_ATTRIBUTES:n:table

The TRANSFORM parameter syntax elements correspond to the following itemsin the example:

■ Transform name You can modify two basic types of an object’scharacteristics using TRANSFORM: segment attributes and storage. Segmentattributes include physical atttributes, storage attributes, tablespaces, andlogging. The transform name represents exactly which of these two objectattributes you want to modify during the import job. In the example, theTRANSFORM=SEGMENT_ATTRIBUTES specification indicates that youwant the import job to modify all the segment (the employees table in theHR schema) attributes.

■ Value The value of the TRANSFORM parameter can be Y (yes) or N (no).By default, the value is set to Y. This means that, by default, Data Pumpimports an object’s segment attributes and storage features. If you assign avalue of N as your choice, you specify not to import the original segmentattributes and/or the storage attributes.

■ Object type The object type specifies which types of objects should betransformed. Your choices are limited to TABLE and INDEX. You may omitthis part of the TRANSFORM parameter specification, in which case DataPump import will transform both tables and indexes.

The Flashback Time ParameterThe FLASHBACK_TIME parameter enables you to import data consistent as of theflashback time you specify in your import job. For example, look at the followingimport statement:

$ impdp system/manager flashback_time=2004-06-01 07:00

The import job will ensure that the data is consistent as of the time you specified.Note that the FLASHBACK_TIME parameter does the same thing as the oldCONSISTENT parameter in the traditional import utility.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:47 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 98: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Monitoring a Data Pump Job 35

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

CERTIFICATION OBJECTIVE 2.03

Monitoring a Data Pump JobThere are two new views—DBA_DATA PUMP_JOBS and DBA_DATA PUMP_SESSIONS—which are crucial for monitoring Data Pump jobs. In addition, youcan also use the V$SESSION_ LONGOPS view and the old standby V$SESSION,to obtain session information. In most cases, you can join two or more of theseviews to gain the necessary information about job progress. Let’s look at someof the important data dictionary views that help you manage Data Pump jobs.

Viewing Data Pump JobsThe DBA_DATA PUMP_JOBS view shows summary information of all currentlyrunning Data Pump jobs. It has the following structure:

SQL> desc dba_data pump_jobsName Null? Type---------------------------------------------OWNER_NAME VARCHAR2(30)JOB_NAME VARCHAR2(30)OPERATION VARCHAR2(30)JOB_MODE VARCHAR2(30)STATE VARCHAR2(30)DEGREE NUMBERATTACHED_SESSIONS NUMBER

Since the dynamic DBA_DATA PUMP_JOBS view shows only the active jobs, youcan easily find the JOB_NAME value for any job that is running right now. As youknow, you’ll need to know the job name for a job if you want to attach to a runningjob in midstream.

Because the name of the master table is the same as the JOB_NAME value, youcan thus determine the name of the master table through this view.

The JOB_MODE column can take the values FULL, TABLE, SCHEMA, orTABLESPACE, reflecting the mode of the curently executing export or the import job.

The STATE column can take the values UNDEFINED, DEFINING, EXECUTING,and NOT RUNNING, depending on which stage of the export or import you executeyour query. The Data Pump job enters the NOT RUNNING state immediately beforeit completes the import or export. Of course, when there aren’t any active jobs running,the view DBA_DATA PUMP_JOBS returns no rows whatsoever.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:47 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 99: OCA OCP - Oracle10G New Features For Administrators Exam Guide

36 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Viewing Data Pump SessionsThe DBA_DATA PUMP_SESSIONS view identifies the user sessions currentlyattached to a Data Pump export or import job. You can join the SADDR columnin this view with the SADDR column in the V$SESSION view to gain usefulinformation about user sessions that are currently attached to a job. The followingquery shows this:

SQL> select sid, serial#from v$session s, dba_data pump_sessions dwhere s.saddr = d.saddr;

Viewing Data Pump Job ProgressThe V$SESSION_LONGOPS dynamic performance view is not new to Oracle Database10g. In Oracle 9i, you could use use this view to monitor long-running sessions.

In the V$SESSION_LONGOPS view, you can use the columns TOTALWORK,SOFAR, UNITS, and OPNAME to monitor the progress of an export/import job.This is what these four key columns represent:

■ TOTALWORK shows the total estimated number of megabytes in the job.

■ SOFAR shows the megabytes transferred thus far in the job,

■ UNITS stands for megabytes.

■ OPNAME shows the Data Pump job name.

Here’s a typical SQL script that you can run to show how much longer it will takefor your Data Pump job to finish:

SQL> select sid, serial#, sofar, totalworkfrom v$session_longopswhere opname = 'MY_EXPORTJOB1'

CERTIFICATION OBJECTIVE 2.04

Creating External Tables for Data PopulationExternal tables are tables that do not reside in the database itself, and they can haveany format defined by an access driver. An external table is merely a representation ofexternal data in a file—data that’s never actually loaded into an Oracle table. In some

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 100: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

ways, external tables are like a view, but the data physically exists in a flat file outsidethe database.

External tables aren’t a new feature of Oracle Database 10g. Oracle9i first introducedthe concept of external tables. However, in Oracle9i, you could only read fromexternal tables. Now, in Oracle Database 10g, you can also to write to external tables.

We’ll look at the following areas regarding external table creation in the followingsections:

■ An overview of external table population features

■ The process for creating external tables

■ How to load and unload data

■ Parallel population of external tables

Features of External Table Population OperationsIn reality, an external table isn’t really a table, but rather an interface to an externaldatafile. However, you may query this external table like a virtual table, just as you wouldquery any regular Oracle table, which makes it a very powerful tool for data warehouseextraction, transformation, and loading (ETL) activities. You can query external tablesor join them with regular tables, without ever loading the external data into yourdatabase. In addition, you may create other regular tables or views from the externaltables, so this feature comes in very handy during the population of data warehouses.

You can’t perform all the normal table Data Manipulation Language (DML)actions on an external table. You can query the external table data, but you can’tperform an update, delete, or an insert on an external table. You also can’t buildan index on external tables.

Prior to Oracle Database 10g, you could use external tables to load data intoa database from external flat files. Now, for the first time, you can unload datafrom an Oracle database into an external table. That is, whereas you could onlyread from an external table before, now you can write to an external table aswell. The technique simplyuses the CREATE TABLE ASSELECT (CTAS) command topopulate external tables withdata that actually resides inoperating system text files andnot in regular datafiles.

Creating External Tables for Data Population 37

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

The same limitationsin earlier versions—inability to createindexes and perform DML on the externaltables—still apply to all external tables.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 101: OCA OCP - Oracle10G New Features For Administrators Exam Guide

38 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

When you create an external table, you can use the TYPE attribute to selectbetween two types of external tables: the ORACLE_LOADER type and theORACLE_DATAPUMP type. Each of these external tables comes with its ownaccess driver. In Oracle9i, you used the ORACLE_LOADER access driver to createexternal tables; however, the ORACLE_LOADER access driver can load data onlyinto an external table; that is, it can extract data from external flat files to load anOracle (external) table. The ORACLE_LOADER access driver is the default accessdriver in Oracle Database 10g.

The ORACLE_DATAPUMP access driver is new to Oracle Database 10g. TheORACLE_DATA PUMP access driver can load aswell extract data; that is, it can both load anexternal table from a flat file and extract datafrom a regular database table to an external flatfile. This external flat file data is written in aproprietary format, which only the ORACLE_DATA PUMP access driver can read. You can thenuse this newly created file to create an externaltable in the same database or a different database.

Here’s a summary of the main features of external table population operations:

■ You can use the ORACLE_LOADER or ORACLE_DATA PUMP access driversto perform data loads. You can use only the new ORACLE_DATA PUMPaccess driver for unloading data (populating external tables).

■ No DML or indexes are possible for external tables.■ You can use the datafiles created for an external table in the same database

or a different database.

Creating External TablesIn this section, I’ll briefly describe the mechanics of creating an external table. Thisbasic background will help you to understand the enhancements in this area in OracleDatabase 10g. The three main steps—create the datafile, create the directory object,and then create the external table—are demonstrated in the following sections.

If you want to createindexes on a staging table, you are betteroff using the SQL*Loader utility to loaddata into the table. You cannot index anexternal table!

The new OracleDatabase10g ORACLE_DATA PUMP accessdriver can perform a data load as well as an

unload. The older ORACLE_LOADER accessdriver can only load an external table usingdata in operating system text files.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 102: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Creating External Tables for Data Population 39

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Create the DatafileCreate a flat file with some data that you’ll load into your external table. Let’s call thisdatafile dept.dmp. Later, you’ll be defining this flat file as an external table. The filewill always remain in the operating system directories, and you may edit it as you wish.Here’s the datafile structure:

10000001,nina,FINANCE,04-APR-200010000002,nicholas,FINANCE,04-APR-200010000007,shannon,HR,02-FEB-199010000008,valerie,HR,01-JUN-1998

Create the Directory ObjectCreate a directory object to hold the external datafiles, as shown here:

SQL> CREATE OR REPLACE DIRECTORY employee_data AS 'C:\employee_data';Directory created.

Create the External TableUse the CREATE TABLE … ORGANIZATION EXTERNAL statement to create yourexternal table, as follows:

SQL> CREATE TABLE employee_ext(empid NUMBER(8),emp_name VARCHAR2(30),dept_name VARCHAR2(20),hire_date date)

ORGANIZATION EXTERNAL(TYPE ORACLE_LOADERDEFAULT DIRECTORY employee_dataACCESS PARAMETERS(RECORDS DELIMITED BY NEWLINEFIELDS TERMINATED BY ','MISSING FIELD VALUES ARE NULL)

LOCATION ('emp.dat'))

REJECT LIMIT UNLIMITED;Table created.SQL>

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 103: OCA OCP - Oracle10G New Features For Administrators Exam Guide

There are several important components of this CREATE TABLE statement thatyou need to be aware of:

■ ORGANIZATION EXTERNAL Indicates to Oracle that the table you arecreating is an external table, not a regular database table.

■ TYPE Specifies the type of access loader: ORACLE_LOADER or ORACLE_DATA PUMP. The default type is ORACLE_LOADER. However, only theORACLE_DATA PUMP access loader can perform a data unload. Both accessdrivers can perform a data load. The records delimited by newlineclause indicates that each line in the datafile is a new row in the externaltable. The fields terminated by ',' clause tells Oracle that eachcolumn is seperated by a comma in the datafile. If there are missing values,the clause missing field values are null instructs Oracle to treatthem as null.

■ DEFAULT DIRECTORY Allows you to specify a file system as the directory,by first using the CREATE DEFAULT DIRECTORY AS statement.

■ ACCESS PARAMETERS Describes the structure of the external data. Theaccess parameters ensure that the data from the data source is processedcorrectly to match the definition of the external table.

■ LOCATION Refers to the actual dump file location. You must specify adump filename at least. In addition, you may specify an optional directoryname as well. If you furnish just a dump filename and no directory name,Oracle will automatically place the dump file in the default dump directory.Note that both of the following location specifications are valid:

LOCATION(‘dept_xt.dmp')LOCATION(dept_xt_dir.dep_xt.dmp)

■ REJECT LIMIT UNLIMITED Specifies that there is no limit on thenumber of errors that occur during the querying of the external tables.

Loading and Unloading DataThe terms loading and unloading in the context of external tables can be confusing, solet’s pause and make sure you undertand these terms without any ambiguity. Whenyou deal with external tables, this is what these terms mean:

■ Loading data means reading data from an external table and loading it intoa regular Oracle table. Oracle first reads the data stream from the files you

40 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 104: OCA OCP - Oracle10G New Features For Administrators Exam Guide

specify. Oracle will then convert the data from its external representation toan Oracle internal datatype and pass it along to the external table interface.

■ Unloading data means reading data from a regular Oracle table and putting itinto an external table. You couldn’t do this in the Oracle9i database.

As I explained earlier, only the ORACLE_DATA PUMP access driver can perform anexternal table population (unloading data). Why is the new functionality (unloadingdata into external tables) important? Following are some of the benefits of this newOracle Database 10g feature:

■ Loading table data into flat files means that you can now store data or moveit to different databases easily. If you want to move large volumes of dataacross platforms, external tables provide a means of doing so, since theexternal files are platform-independent.

■ During the population of data warehouses, there are many situations whereyou need to perform complex ETL jobs. You can use SQL transformations tomanipulate the data in the external tables before reloading them into thesame or other databases.

■ Once you create an external table and populate it using the CTASstatement, you can move the text files containing data and create newexternal tables in the same or a different database.

Note that when you talk about to writing to external tables, you are really referringto writing to an external file. You use a SELECT statement to extract table data tothis operating sytem file. The ORACLE_DATA PUMP access driver writes data to thisfile in a binary Oracle-internal Data Pump format. You can then use this file to loadanother external table on a different database.

The following example shows how you can create an external table and populate itwith data from an external flat file. The only difference between this example and thepreceding external table creation statement is that it uses the ORACLE_DATAPUMPaccess driver rather than the ORACLE_LOADER driver.

SQL> CREATE TABLE inventories_xt22 (3 product_id NUMBER(6),4 warehouse_id NUMBER(3),5 quantity_on_hand NUMBER(8)6 )7 ORGANIZATION EXTERNAL

Creating External Tables for Data Population 41

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 105: OCA OCP - Oracle10G New Features For Administrators Exam Guide

8 (9 TYPE ORACLE_DATA PUMP10 DEFAULT DIRECTORY def_dir111 LOCATION ('inv_xt.dmp')12 );Table created.SQL>

The CREATE TABLE … ORGANIZATION EXTERNAL statement creates an externaltable. There is no data in this table at this point. The external table inventories_xt2is then populated using the flat file inv_xt.dmp, located in the directory def_dir1.You could do all this in Oracle9i. The feature shown in the next example—writingto an external table—is a brand-new Oracle Database 10g external tables enhancement.

SQL> CREATE TABLE dept_xt2 ORGANIZATION EXTERNAL3 (4 TYPE ORACLE_DATA PUMP5 DEFAULT DIRECTORY ext_tab_dir16 LOCATION ('dept_xt.dmp')7 )8* AS SELECT * FROM scott.DEPT

SQL> /Table created.

If you now go look in the location specified for the default directory (ext_tab_dir1), you’ll see a dump file named dept_xt.dmp, which contains the data from theDEPT table. You can then use this dump file in the same database or a differentdatabase to load other tables. Note that you must create the default directory ext_tab_dir1 beforehand for this external table creation statement to succeed. You arecreating the external table dept_xt as an external table. The table structure anddata both come from the regular Oracle DEPT table. The CTAS method of tablecreation will load the data from the DEPT table into the new external table dept_xt.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

42 Chapter 2: Loading and Unloading Data

Remember that when youload an Oracle table from an external table(data loading), you use the INSERT INTO

…SELECT clause. When you populate anexternal table using Oracle table data, youuse the CREATE TABLE AS SELECT clause.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:48 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 106: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Where will the data for the dept_xt be located? You’ll be wrong if you answersomething like “in a table segment”! Since the dept_xt table is defined as an externaltable, the CTAS command simply stores the table data in the external file calleddept_xt_dmp. Thus, the external table is really composed of proprietary format,operating system-independent flat files.

Parallel Population of External TablesSince external tables can be quite frequently very large, it’s nice to know that you canload external tables in a parallel fashion, simply by using the keyword PARALLELwhen creating the external table. Here’s the catch with the PARALLEL commandwhile creating an external table: your use of the PARALLEL parameter will makesense only if you have more than one file specified as values for the LOCATIONvariable. Otherwise, the PARALLEL command really can’t do anything in parallel(the degree of parallelism defaults to 1)! The reason for this is that Oracle will allocateexactly only one parallel execution server for each file. If you specify PARALLEL=4and specify two datafiles for Oracle to write to, your degree of parallelism is automaticallylowered to 2. Thus, the degree of parallelism is constrained by the number of dumpfiles you specify under the LOCATION parameter.

Here’s an example of how to use the PARALLEL command while creatingexternal tables:

SQL> CREATE TABLE inventories_xt2 ORGANIZATION EXTERNAL3 (4 TYPE ORACLE_DATA PUMP5 DEFAULT DIRECTORY def_dir16 LOCATION ('inv_xt.dmp1',’inv_xt.dmp2’,inv_xt.dmp3’)

)7 PARALLEL8 AS SELECT * FROM inventories;

Creating External Tables for Data Population 43

When you use the externaltables feature to extract table data to a file,you export only the data. You can’t export

metadata using external tables. If you wishto extract the metadata for any object, justuse DBMS_METADATA, as shown here:

SET LONG 2000SELECT DBMS_METADATA.GET_DDL('TABLE','EXTRACT_CUST') FROM DUAL;

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:49 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 107: OCA OCP - Oracle10G New Features For Administrators Exam Guide

44 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

CERTIFICATION OBJECTIVE 2.05

Defining External Table PropertiesThe data dictionary view DBA_EXTERNAL_TABLES describes features of all externaltables in your database:

SQL> desc dba_external_tablesName Null? Type----------------------------------------- -------- ---------------OWNER NOT NULL VARCHAR2(30)TABLE_NAME NOT NULL VARCHAR2(30)TYPE_OWNER CHAR(3)TYPE_NAME NOT NULL VARCHAR2(30)DEFAULT_DIRECTORY_OWNER CHAR(3)DEFAULT_DIRECTORY_NAME NOT NULL VARCHAR2(30)REJECT_LIMIT VARCHAR2(40)ACCESS_TYPE VARCHAR2(7)ACCESS_PARAMETERS VARCHAR2(4000)PROPERTY VARCHAR2(10)

Pay particular attention the last three columns in the DBA_EXTERNAL_TABLES view:

■ The ACCESS_TYPE column refers to whether you have BLOB or CLOBtype of access parameters for your external table.

■ The ACCESS_PARAMETERS column shows all the access parametersyou used in creating the external table.

■ The PROPERTY column, which refers to the property of the projectedcolumns, could take two values: REFERENCED or ALL.

The default value for the PROPERTY column for all external tables is ALL. Thistells the access driver to always process all the columns of an external table, not justsome. This means that, regardless of which columns you select in a query, the accessdriver will process all column values. The access driver will validate only those columnswithout data errors. The access driver will also eliminate any rows that have erroneouscolumn values, even if those columns aren’t a part of the SELECT query.

If the PROPERTY column shows the value REFERENCED, this means that onlythose columns referenced by a SQL statement are processed (parsed and converted)by the Oracle access driver. When would you want to specify the REFERENCED

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:49 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 108: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

property? You do this when you are quite sure about the quality of your data fieldsand expect no data rejections due to data format errors. For example, you may havea column called emp_id, which you define as a number(5) column. When Oracleencounters a row in the datafile where the emp_id has six digits, it would normallyreject this row, since the default value for the property is ALL. This means that evenif you issue a query that selects a different column, say social_security_num from theemployee table, Oracle will reject all rows that have bad data in the emp_id column.

How do you change the default ALL property value for an external table toREFERENCED? Say that you want to change this property for your external tabledept_xt, which now has the default ALL property.

SQL> select table_name,property from dba_external_tables;TABLE_NAME PROPERTY------------------------------ ----------DEPT_XT ALL

To do this, you use the ALTER TABLE command in the following manner.

SQL> alter table dept_xt2 project column referenced;

Table altered.SQL> select table_name,property from dba_external_tables;TABLE_NAME PROPERTY------------------------------ ----------DEPT_XT REFERENCEDSQL>

Changing the PROPERTY column to REFERENCED is a good idea if you knowyour data is clean, because it provides better performance, since only the projectedcolumns are parsed and converted. If your data is clean, flagging an external table asREFERENCED will provide better performance when you query only a subset of thecolumns.The default ALL property projects all columns and will guarantee consistentresults, but all of the data is queried for every type of query, thus hindering performance.

CERTIFICATION OBJECTIVE 2.06

Transporting Tablespaces Across Different PlatformsSuppose you need to move a large amount of data between two databases. What’s thefastest way to do this? You can use the Data Pump export and import utilities, of

Transporting Tablespaces Across Different Platforms 45

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:49 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 109: OCA OCP - Oracle10G New Features For Administrators Exam Guide

course, to perform the job. However, there is a much faster way to perform the datatransfer: use transportable tablespaces. Transportable tablespaces simply involve movingtablespaces from one database to another. All you really need to do is to copy thedatafiles (containing tables, indexes, and other Oracle database objects) that comprisethe tablespace, from the target to the source server (if the two databases reside ondifferent servers) and just import the metadata of the objects in the tablespace to thetarget database.

Transportable tablespaces are ideal for moving large amounts of data quicklybetween two databases. The transportable tablespaces feature, of course, has beenavailable for a while now, but both the source and target databases needed belongto the same operating system platform. In Oracle Database 10g, for the first time,you can transport tablespaces between different platforms. Now the onerous requirementof identical operating system platforms is gone, and you can easily transport atablespace from pretty much any platform to any other. This is a great feature, asit enables you to take tablespaces from a data warehouse and plug them into datamarts, even though your data warehouse runs on an UNIX platform and the datamarts are located on smaller Windows servers. As you have probably already figuredout, the key here is Oracle Database 10g’s ability to convert one set of datafiles fromone operating system format to another, so the target database can read the sourcedatabase files.

Transportable tablespaces are a good way to migrate a database betweendifferent platforms.

Transporting a Tablespace Between Identical PlatformsAlthough the procedure of transporting tablespaces hsn’t really changed in OracleDatabase 10g, let’s recap the steps involved in transporting tablespaces, so you canunderstand the new changes better. Transporting a tablespace from one database toanother when both databases belong to the same platform consists of the following steps:

1. Ensure that the tablespaces are self-contained.

2. Make the tablespaces read-only.

3. Export the metadata using Data Pump export.

4. Copy the datafiles over to the target system.

5. Use Data Pump import to import the metadata.

46 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:49 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 110: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Following are the general requriements for transporting tablespaces between twodatabases:

■ Both platforms should use the same character sets.

■ Both databases must be using Oracle8i or a higher version, but the databaseversion does not need to be identical.

■ You cannot transport the SYSTEM tablespaces or any objects owned by theuser SYS.

■ If you want to transport a partitioned table, all the partitions must beincluded in the transportable table set. If you are transporting indexes, youalso need to transport the tablespaces containing the respective tables as well.

■ You can transport tablespaces to a target database only if it has the same orhigher compatiblity setting than the source database.

Determining the Supported PlatformsNote that you can’t transport tablespaces between all operating system platformsautomatically, even in Oracle Database 10g. How do you know which platforms aresupported for cross-platform tablespace transport? All you need to do to get thisinformation is to query the new V$TRANSPORTABLE_PLATFORM view:

SQL> col platform_name format a30SQL> select * from v$transportable_platform;PLATFORM_ID PLATFORM_NAME ENDIAN FORMAT----------- ------------------------------ --------------

1 Solaris[tm] OE (32-bit) Big2 Solaris[tm] OE (64-bit) Big7 Microsoft Windows IA (32-bit) Little10 Linux IA (32-bit) Little6 AIX-Based Systems (64-bit) Big3 HP-UX (64-bit) Big5 HP Tru64 UNIX Little

Transporting Tablespaces Across Different Platforms 47

If either the source or thetarget database compatibility level is less than

10.0.0, you cannot transform a tablespaceacross different operating sytem platforms.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:49 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 111: OCA OCP - Oracle10G New Features For Administrators Exam Guide

48 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

4 HP-UX IA (64-bit) Big11 Linux IA (64-bit) Little15 HP Open VMS Little8 Microsoft Windows IA (64-bit) Little9 IBM zSeries Based Linux Big13 Linux 64-bit for AMD Little16 Apple Mac OS Big12 Microsoft Windows 64-bit for A Little

MD15 rows selected.SQL>

The V$TRANSPORTABLE_PLATFORM view shows allplatforms supported fortransporting tablespaces. ThePLATFORM_NAME columnshows all the platforms that areeligible for transporting acrossplatforms. If both your sourceand target platforms are in this list, you can conduct the transportable tablespacesoperation between the databases running on those platforms.

You can find out your own platform name, in case you aren’t sure, by running thefollowing simple query:

SQL> select platform_name from v$database;PLATFORM_NAME----------------------------------------Microsoft Windows IA (32-bit)SQL>

If you need to transport read-only tablespaces to ensure that your datafile headerscan identify the operating system platform, you must first make the datafile read/write at least once (after setting the database compatibility level at 10.0.0 or higher).If your source database is operating at a 9.2.0 compatibility level, for example, youneed to first advance the compatibility level to 10.0.0 before you can transport anytablespaces for this database.

In order to transporttablespaces across different platforms,the character sets in both databasesshould be identical.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:49 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 112: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Converting to Match Datafile Endian FormatsEven if your source and target operating system platforms are identical, you maystill not be able to perform a tablespace transport directly. Remember that the mosttime-consuming job during a tablespace transport is the copying of the files thatbelong to the tablespace. If the endian format of two operating system platforms isdifferent, you need to perform a conversion of the datafiles, either before or afteryou copy the files to the target system.

What does the ENDIAN FORMAT column, which you can see in the followingquery, stand for?

SQL> select * from v$transportable_platform;PLATFORM_ID PLATFORM_NAME ENDIAN FORMAT----------- ------------------------------ --------------------------

1 Solaris[tm] OE (32-bit) Big2 Solaris[tm] OE (64-bit) Big7 Microsoft Windows IA (32-bit) Little10 Linux IA (32-bit) Little

SQL>

Endian format refers to byte ordering in the datafiles of a given platform. Byteordering affects the way data is written and read in different platforms. There areonly two types of endian formats: little or big. In order for the datafiles betweentwo compatible platforms to be transported directly from one another, their endianformat (also known as endianness) should be the same. Both the source and targetplatforms should have an identical endian format—either both are in the big formator both are in the little format.

If you have two platforms that are in the compatible list for transporting tablespaces,but their endian formats are different, you need to convert the datafiles belongingto the tablespaces that you are exporting, using the RMAN utility.

Transporting Tablespaces Across Different Platforms 49

Being compatible forthe purpose of transporting tablespaces

isn’t the same thing as having identicalendian formats.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:49 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 113: OCA OCP - Oracle10G New Features For Administrators Exam Guide

50 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Transporting a Tablespace Across PlatformsThe steps for transporting tablespaces across platforms are the same as for transportingtablespaces across identical platforms, with an additional step if the source and targetdatabase file endian format are different. The following sections provide an example ofthese steps.

Ensure the Tablespaces Are Self-ContainedEnsure that the tables you want to transport all are placed in their own separatetablespaces. To ensure that your tablespaces are self-contained, you need to use theTRANSPORT_SET_PROCEDURE in the Oracle-supplied package DBMS_TTS.

Make the Tablespaces Read-OnlyAlter the tablespace to make it read-only. Once you complete the export of themetadata in the next step, you can make the tablespace read/write again.

Export the Metadata Using Data Pump ExportExport the metadata describing the objects in the tablespace(s), by using theTRANSPORTABLE_TABLESPACES parameter.

Convert the Datafiles to Match Endian FormatIf your platforms are compatible, but the endian formats are different, you need toconvert the datafiles. You may perform the conversion before transporting the tablespaceset or after finishing the transport. You can convert the datafiles before transportingthe tablespaces, using the following CONVERT TABLESPACE command in the RMAN:

RMAN> convert tablespace finance_tbs012> to platform 'HP-UX (64-bit)'3> format '/temp/%U';Starting backup at 09-MAY-04using channel ORA_DISK_1channel ORA_DISK_1: starting datafile conversioninput datafile fno=00011 name=C:\ORACLE\TEST02.DBFconverted datafile=C:\TEMP\DATA_D-FINANCE_I-2343065311_TS-TODAY_FNO-11_05FLAUM6channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:17

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:50 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 114: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Transporting Tablespaces Across Different Platforms 51

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Finished backup at 09-MAY-04RMAN> exitRecovery Manager complete.

In this example, I show how you can use the FORMAT parameter to tell Oraclewhat format the newly converted file should be and in which directory to put it. Butas you can see, Oracle gives the file a name. If you want to specify the datafile nameyouself, perform the conversion using the DB_FILE_NAME_CONVERT clause, asfollows. (Remember that you use the following command when you convert the filesdirectly on the source system, before transporting them.)

RMAN> convert tablespace today2> to platform 'HP-UX (64-bit)'3> db_file_name_convert = 'c:\oracle\test02.dbf','c:\temp\test02.dbf';Starting backup at 10-MAY-04using target database controlfile instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: sid=151 devtype=DISKchannel ORA_DISK_1: starting datafile conversioninput datafile fno=00011 name=C:\ORACLE\TEST02.DBFconverted datafile=C:\TEMP\TEST02.DBFchannel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:16Finished backup at 10-MAY-04RMAN>

The DB_FILE_NAME_CONVERT clause performs the following functions for you:

■ Takes a given filename and converts it to any filename you specify

■ Places the converted file in the location you specify

Copy the Files to the Target SystemAt this point, you need to copy both the converted datafile that is part of the tablespace(finance_tbs01 in this example) as well as the expdp dump file, sales2003.dmp, overto the target server where your target database is running.

If you chose to transport the tablespaces (the datafiles that constitute the tablespaces)first, you must convert the datafiles on the target platform at this point, before tryingto perform the import of the metadata in the tablespace. Here’s an example that

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:50 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 115: OCA OCP - Oracle10G New Features For Administrators Exam Guide

52 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

shows how you can take a datafile that belongs to the HP-UX operating systemplatform and convert it into a Windows platform:

RMAN> convert datafile2> 'c:\audit_d01_01.dbf'3> to platform 'Microsoft Windows IA (32-bit)'4> from platform='HP-UX (64-bit)'5> FORMAT '\export';

As in the previous case where you performed the file conversion on the sourcesytem, you may use the DB_FILE_NAME_CONVERT clause when performing thedata file conversion on the target system. Your datafile conversion statement wouldthen have the format CONVERT DATAFILE …FROM PLATFORM …DB_FILE_NAME_CONVERT = ….

By default, Oracle places the converted files in the Flash Recovery Area,without changing the datafile names.

Use Data Pump Import to Import the MetadataOnce you move the converted files files over to the target system (or move the filesover first and convert them later), use the Data Pump import utility as follows toimport the metadata into the target database—that is, just plug in the tablespaces anduse the Data Pump import to integrate the datafiles and their metadata (found in thetest.dmp file):

impdp system/manager TRANSPORT_TABLESPACE=yDATAFILES='/u01/app/oracle/data01.dbf'TABLESPACES=test FILE=test.dmp

Understanding Exceptions to File ConversionsThere is an important exception to the file conversions that the RMAN performs foryou in order to enable the transporting of tablespaces between two platforms withdifferent endian formats. RMAN doesn’t automatically convert CLOB data for youduring file conversion. Here’s what you need to know about CLOBs and file conversionfor transportable tablespaces:

■ If your CLOBs were created in an operating system with the big-endianformat, you don’t need to convert the CLOB data.

■ If you are transporting little-endian CLOB data to a big-endian system, aconversion must be done. But even here, Oracle can automatically convert

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:50 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 116: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Transporting Tablespaces Across Different Platforms 53

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

the CLOB data to the big-endian format dynamically, whenever a useraccesses the data. However, if you wish to do all the conversion yourself,you may do so by re-creating the table on the target database.

Here’s the reasoning for the variation in the treatment of CLOB data in big-endian and little-endian systems: prior to Oracle Database 10g, CLOBs were storedin the UCS2 format, which is endian-dependent, but Oracle Database 10g storesthem as AL16UTF16, which is endian-independent. However, big-endian UCS2is the same as AL16UTF16. So if your source system was big-endian, there isn’t anydifference. If it wasn’t, Oracle will convert the datafiles on demand.

The exam will test your knowledge of the newData Pump import and export parameters. Youmust understand the new parameters like theremapping parameters of Data Pump import.What are the different levels at which you canperform transformations during an import? Payparticular attention to the new parameters likeESTIMATE, ESTIMATE_ONLY, NETWORK_LINK, INCLUDE, and EXCLUDE. You mustknow the levels at which you can performData Pump import and export.

You can expect questions on the interactiveimport and export commands. How do youattach to a running job? What happens to ajob and a client session when you stop a job?Review the Data Pump dictionary views likeDBA_DATAPUMP_JOB_STATISTICS andDBA_DATAPUMP_JOBS.

There will be a question on the Data Pumparchitecture. You must know the differencebetween the External Table API and Direct

Path API. You can expect some questionson the DBMS_DATAPUMP and the DBMS_METADATA packages. You must understandthe importance of the master table.

There will be questions on the externaltable population feature. You must rememberthe syntax for performing an external tablepopulation (CREATE TABLE AS SELECT).Review the parallel feature, putting specialemphasis on the relationship between the degreeof parallelism and the number of dump files.

The test will contain questions on the newfeatures related to transportable tablespaces.What is an endian format, and what role doesit play in transporting tablespaces acrossplatforms? You must remember the RMANcommands to convert the endian formats offiles. What is the difference in the fileconversion commands when you convert fileson the target platform and when you convertthem on the source platform?

INSIDE THE EXAMINSIDE THE EXAM

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:50 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 117: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CERTIFICATION SUMMARYThis chapter introduced you to the new Data Pump technology in Oracle Database 10g.You saw how Data Pump offers sophisticated new features to run large export and importjobs faster, while offering exceptional data-filtering techniques. You also learned aboutthe powerful interactive Data Pump features. You learned how to monitor your DataPump jobs.

You learned how to populate external tables. You also saw how the new optionsyou have in Oracle Database10g regarding external table properties. You learnedhow to transport tablespaces across server platforms, even when the file semanticsare different between two operating sytem platforms.

54 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:50 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 118: OCA OCP - Oracle10G New Features For Administrators Exam Guide

✓TWO-MINUTE DRILL

Introduction to the Data Pump Architecture❑ The new Data Pump technology is a much more efficient way of moving large

amounts of data than the old export/import utilities.

❑ You can still continue to use the traditional export and import utilties inOracle Database 10g.

❑ Data Pump technology is entirely server-based; all work takes place on the server.

❑ The Data Pump export utility exports data out of the database, and the DataPump import utility imports data into a database.

❑ There are two kinds of parameters: a set of command-line parameters and aspecial set of interactive commands in both the Data Pump import andexport utilities.

❑ The Oracle-supplied package DBMS_DATA PUMP is used to implement theData Pump API.

❑ The clients for the Data Pump export and import utilities are expdp andimpdp, respectively.

❑ DBMS_METADATA, an older Oracle-provided package, is used to extract andmodify data dictionary metadata.

❑ Data Pump export can access data in two ways: direct-path access using theDirect Path API or through external tables. Data Pump itself makes thedecision as to the access choice, based on which will be faster in a given case.

❑ Direct-path access is the first method Oracle will try to use. Under someconditions, Oracle cannot use the direct-path method, and it must use theexternal tables access method.

❑ You can export data using either direct path or external tables and import thedata back with either of the two methods.

❑ There are three types of Data Pump files: dump files, log files, and SQL files.

❑ Data Pump export dump files are created on the server, using directory objects.

❑ Directory objects are named objects that are mapped to an operating systemdirectory.

❑ Once you create a directory, you can access that file system by simplyreferring to the dirctory name.

Two-Minute Drill 55

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:51 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 119: OCA OCP - Oracle10G New Features For Administrators Exam Guide

56 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

❑ In order to create a directory, you must have the DBA role. In order to use adirectory, you must have the appropriate read and/or write privileges on thedirectory.

❑ DATA_PUMP_DIR is the default directory object for Data Pump jobs. Onlyprivileged users can use this default directory object.

❑ The order of precedence for file locations is the following: the directory nameas part of a file parameter name, the value assigned to the DIRECTORYparameter, the directory name specified by DATA_PUMP_DIR environemntvariable, and finally, the default value for the DATA_PUMP_DIR object.

❑ All Data Pump jobs consist of a master and several worker processes. Themaster process controls jobs and the worker processes as well. The masterprocess is also responsible for monitoring the progress of jobs.

❑ The master process uses the master table to store the database object location.The master table is created during the export process. If the job completessuccessfully, the master table is automatically deleted from the database.

❑ During Data Pump import, the master table is consulted to verify the correctsequencing of objects during import.

❑ If you choose the PARALLEL option, the worker processes become parallelexecution coordinators.

❑ The benefits of the Data Pump technology include the ability to restart jobs,parallel execution capabilities, ability to attach to a running job, ability toestimate space requirements, fine-grained export and import capabilities, andremapping capabilities.

❑ You can perform both network mode exports and imports.

❑ You can perform Data Pump export/import from the command line or withthe help of parameter files.

❑ In Data Pump export/import, you use the interactive mode to interveneduring a running job. There are several special commands you can use inthis interactive mode.

❑ You can start the interactive mode either by using the CONTROL-C

combination or by using the ATTACH command from a different session.

Using Data Pump Export and Import❑ You can perform Data Pump export and import in full, tablespace, table, or

schema modes. You can also perform Data Pump jobs in the transportabletablespaces mode.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:51 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 120: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Two-Minute Drill 57

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

❑ The CONTENT parameter can take the values ALL, DATA_ONLY, orMETADATA_ONLY. The ALL parameter enables the export of both data andmetadata. The DATA_ONLY parameter lets you export data only. TheMETADATA_ONLY option enables the export of only the object definitions.

❑ The EXCLUDE parameter forces the exclusion of specific objects, and theINCLUDE parameter requries the inclusion of specified objects.

❑ The EXCLUDE and INCLUDE parameters are mutually exclusive.

❑ You use the QUERY parameter to filter table row data with the help of aSQL statement.

❑ The ESTIMATE parameter provides an estimate of the size of the export job. Ituses BLOCKS by default. You can specify ESTIMATE=STATISTICS to makethe parameter use database statistics instead of the default blocks method.

❑ The ESTIMATE_ONLY parameter just gives you a size estimate, withoutperforming an export.

❑ You can connect to a running export or import job by using the ATTACHcommand.

❑ The CONTINUE_CLIENT parameter takes you out of the interactive modebut keeps the job running. The EXIT_CLIENT command will terminate theinteractive session and the client session. The KILL_JOB command willterminate the export or import job in addition. The STOP_JOB commandstops running Data Pump jobs.

❑ The STATUS parameter will provide you with periodic job progress updates.

❑ The default value of the PARALLEL parameter is 1. In practice, it is limitedby the number of dump files you provide for the export job.

❑ By default, a Data Pump export job will export the entire schema of the userrunning it.

❑ The SQLFILE parameter is used during a Data Pump Import to extract DDLto a specified file, without conducting an import of the data in the exportdump file.

❑ If you specify REUSE_DATAFILES=Y, Data Pump will overwrite yourexisting datafiles.

❑ Remapping parameters are used during a Data Pump import job to remapdatabase objects. You can remap datafiles, tablespaces, and entire schemas.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:51 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 121: OCA OCP - Oracle10G New Features For Administrators Exam Guide

❑ The NETWORK_LINK parameter enables you to import data directly from astarget database, without using any dump files. You must first create a databaselink before performing a network import.

❑ The TRANSFORM parameter enables you to modify storage andtablespace clauses during an import.

Monitoring a Data Pump Job❑ You can monitor Data Pump jobs with the help of the views DBA_DATA

PUMP_JOBS, DBA_DATA PUMP_SESSIONS, and V$SESSION_LONGOPS.

❑ The DBA_DATAPUMP_JOBS view shows all active Data Pump jobs.

❑ The DBA_DATAPUMP_SESSIONS view shows all the user sessions attachedto an import or export job.

❑ The V$SESSION_LONGOPS view tells you how far a Data Pump job hasprogressed.

Creating External Tables for Data Population❑ You can now populate external tables by using the ORACLE_DATA PUMP

access loader.

❑ The main parameters you need to specify in the creation of external tables aretype, default_directory, location, and access_parameters.

❑ Loading data refers to reading data from external tables. Unloading data refersto populating external tables.

❑ You use the CREATE TABLE AS SELECT (CTAS) statement to populateexternal tables.

❑ The ORACLE_LOADER access driver permits only the loading of externaltables.

❑ The ORACLE_DATAPUMP access loader will permit both the loading andthe unloading of data (reading as well as writing to external tables).

❑ You can load external table creation faster by using the PARALLELparameter. If you use the PARALLEL parameter, you must specify more thanone datafile for writing the data. The degree of parallelism is limited by thenumber of datafiles you provide.

58 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:51 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 122: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Defining External Table Properties❑ External tables could have either of two values for the PROPERTY column:

ALL or REFERENCED.

❑ The default value fo the PROPERTY column is ALL.

❑ If your data is known to be clean (no data formatting errors), you should usethe REFERENCED value for the PROPERTY column, for better performance.

❑ You can use the ALTER TABLE command to change the PROPERTYcolumn of an external table.

Transporting Tablespaces Across Different Platforms❑ You can now transport tablespaces across different operating system

platforms.

❑ In order to qualify for a cross-platform tablespace transport, both platformsshould set to the compatibility equal to 10.0.0, use an identical character set,and be in the compatible platforms list.

❑ The view V$TRANSPORTABLE_PLATFORM will let you know if a pair ofoperating system platforms are compatible.

❑ The endian format of an operating system platform refers to the byte-orderingformat of the files on that platform.

❑ If the endian format of two compatible platforms is the same, you don’t needto convert the datafiles for transporting them across different platforms.

❑ If the endian format of two compatible platforms is different, you mustconvert the datafiles either before or after you physically transport thetablespaces.

❑ You use the DB_FILE_NAME_CONVERT option to convert file formats fromone endian format to another.

❑ If your CLOBs were created in an operating sytem with the big-endianformat, you don’t need to convert the CLOB data.

❑ If you are transporting little-endian CLOB data to a big-endian system, youmust convert the data.

Two-Minute Drill 59

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:51 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 123: OCA OCP - Oracle10G New Features For Administrators Exam Guide

60 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

SELF TESTThe following questions will help you measure your understanding of the material presented inthis chapter. Read all the choices carefully because there might be more than one correct answer.Choose all correct answers for each question.

Introduction to the Data Pump Architecture

1. Which of the following are part of the new Data Pump technology?

A. DBMS_METADATA, DBMS_DATA PUMP, Direct Path APIB. DBMS_METADATA, DBMS_DATA PUMP, Indirect Path APIC. DBMS_METADATA, DBMS_DATA PUMP, SQL Loader APID. DBMS_METADATA, DBMS_DATA PUMP, Export API

2. What is the DBMS_METADATA package used for?

A. Transport tablespaces between two databasesB. Load and unload metadataC. Perform a cross-platform transport of tablespacesD. Load external tables

3. Assume the following is the first import job you are performing in your database:

$ impdp system/manager parfile=imp.par

What would be the default name of your master table?

A. IMPORT_FULL_01B. SYS_IMPORT_FULL_01C. SYSTEM_IMPORT_FULL_01D. DATA PUMP_JOB_FULL_01

4. Which of the following statements is correct?

A. The master table is created during a Data Pump export job and written to the dump file atthe very beginning of the export job.

B. The master table is created during a Data Pump export job and written to the dump file atthe very end of the export job.

C. The master table is created during a Data Pump import job and written to the dump file atthe very beginning of the import job.

D. The master table is created during a Data Pump import job and written to the dump file atthe very end of the import job.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:51 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 124: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test 61

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Using Data Pump Export and Import

5. The DBA has just performed a full database Data Pump export. She must now perform a fulldatabase import using the dump file set created by the export job. Which one of the followingstatements would be correct under the circumstances?

A. impdp system/manager dumpfile=expdata.dmp FULL=Y

B. impdp system/manager dumpfile=expdata.dmpC. impdp system/manager FULL=YD. impdp system/manager dumpfile=expdata.dmp FROMUSER=TOUSER

6. Which of the following parameters enables you to perform a data-only unloading of data?

A. EXCLUDE

B. INCLUDE

C. CONTENT

D. DATA_ONLY

7. Which of the following statements is correct?

A. If you stop a job using the STOP_JOB command, the master table is retained for use inrestarting the job.

B. If you stop a job using the KILL_JOB command, the master table is dropped and the jobcannot be restarted.

C. If you stop a job using the KILL_JOB command, the master table is retained and you canrestart the job later.

D. If a job terminates unexpectedly, the master table is dropped automatically.

8. Which of the following occurs when you start an interactive session with Data Pump?

A. The currently running export job is interrupted briefly.B. The current job continues normally.C. The current job is stopped and you need to restart it later.D. You cannot start an interactive session when a Data Pump job is running.

Monitor a Data Pump Job

9. How can you see the amount of work performed so far by your Data Pump import job?

A. Query the V$JOB_STATUS viewB. Query the V$SOFAR viewC. Query the V$SESSION_LONGOPS viewD. Query the DBA_DATAPUMP_JOBS view

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:52 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 125: OCA OCP - Oracle10G New Features For Administrators Exam Guide

10. Which is the sequence of commands you must use if you want to suspend and then resume yourData Pump job?

A. START_JOB, ATTACH, CONTINUE_CLIENT

B. ATTACH, KILL_SESSION, CONTINUE_CLIENT

C. ATTACH, STOP_JOB, START_JOB

D. STOP_JOB, ATTACH, CONTINUE_CLIENT

11. What information do you need to supply to attach to a running job from a different session?

A. The location of the dump fileB. Username and password, job nameC. Username and password onlD. Username and password, master table name

12. What does the column SOFAR in the monitoring view V$SESSION_LONGOPS tell you?

A. How many megabytes have been transferred thus far in the jobB. What percentage of the job has been completed thus farC. What percentage of the job remains to be doneD. The estimated number of megabytes left to be transferred

Creating External Tables for Data Population

13. Which two of the following statements is true?

A. You use the ORGANIZATION EXTERNAL clause during an external table unloadingoperation.

B. You use a CREATE TABLE AS SELECT statement during an external table loadingoperation.

C. You use a CREATE TABLE AS SELECT from statement during an external tableunloading operation.

D. You use the ORGANIZATION EXTERNAL clause only for reading data into an externaltable from an operating system file.

14. What does unloading of data refer to?

A. The reading of data from external datafiles into external tables.B. The writing of data from Oracle tables to external datafiles.C. The writing of data from external datafiles into external tables.D. The reading of data from Oracle tables into external datafiles.

62 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:52 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 126: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test 63

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

15. Why should you use the NETWORK_LINK export parameter when you perform a Data Pumpexport of a read-only database?

A. You can’t write to a read-only database.B. The export is faster if you use the NETWORK_LINK parameter.C. You don’t need to use export dump files when you use the NETWORK_LINK parameter

during exportD. You can’t use the traditional export utility to export a read-only database.

16. If the number of files in the LOCATION clause is different from the degree of parallelism thatyou specify, which two statements below would be correct?

A. Oracle will ignore the PARALLEL parameter.B. Oracle will perform the table population with the same degree of parallelism as the number

of files.C. Oracle ignores any extra files (files greater than the degree of parallelism) that you may

specify.D. You can instruct the parallel execution server to write to multiple files simultaneously.

Defining External Table Properties

17. The DBA knows that the database may reject certain columns in an external table, due to dataformat errors. In this case, what should the DBA do to get consistent query results?

A. Clean up the data so the rows with data format errors are taken out of the table.B. Alter the external table to set the PROJECT COLUMN attribute to ANY.C. Alter the external table to set the PROJECT COLUMN attribute to ALL.D. Alter the external table to set the PROJECT COLUMN attribute to REFERENCED.

18. Which of the following is true in Oracle Database 10g?

A. The default value for an external table PROJECT COLUMN attribute projects all columns.B. The default value for an external table PROJECT COLUMN attribute projects no

columns.C. The default value for an external table PROJECT COLUMN attribute projects only

columns with no data errors.D. The default value for an external table PROJECT COLUMN attribute projects only

columns with data errors.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:52 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 127: OCA OCP - Oracle10G New Features For Administrators Exam Guide

64 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

19. Which of the following is true if your data is clean (without any formatting errors)?

A. Using the ALL value for the PROJECT COLUMN attribute always provides the sameresults.

B. Using the REFERENCED value for the PROJECT COLUMN attribute always provides thesame results.

C. Using the default value for the PROJECT COLUMN attribute always provides the sameresults.

D. Using the ALL value for the PROJECT COLUMN attribute always provides differentresults.

20. Of the following, which statement is true of the external table properties?

A. REFERENCED is better because you need to parse and convert only some columns.B. ALL is better because you need to parse and convert only some columns.C. ALL is better because you need to parse and convert all columns.D. REFERENCED is better because you need to parse and convert all columns.

Transporting Tablespaces Across Different Platforms

21. Which of the following interfaces can you use to convert your database files when the endianformats are incompatible between a source and a target database?

A. SQL*PlusB. RMANC. OEM Database ControlD. Oracle PL/SQL procedures and packages

22. Which of the following do you need to do when the endian formats of the target and sourcedatabase files are different?

A. Convert the source files on the source system, copy them to the target system, and importthe metadata.

B. Convert the source files on the source system, copy them to the target system, and exportthe metadata.

C. Copy the source files to the target system, convert the datafiles, and export the metadata.D. Copy the source files to the target system, convert the datafiles, and import the metadata.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:52 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 128: OCA OCP - Oracle10G New Features For Administrators Exam Guide

23. To find out if two databases are cross-transportable compliant, which data dictionary view doyou need to use?

A. V$TRANSPORTABLE_PLATFORM

B. V$ENDIAN FORMAT

C. V$PLATFORM

D. V$COMPATIBILITY_LEVEL

24. Which of the following can you do if you find both the target and source operating systemplatforms in the V$TRANSPORTABLE_TABLESPACES view?

A. Automatically transport tablespaces between the two platformsB. Transport tablespaces only after you perform a mandatory file conversion firstC. Transport tablespaces between the two platforms only if their endian format is differentD. Transport tablespaces between the two platforms, provided you always perform a file

conversion first if the file endian formats are different

LAB QUESTIONStart a Data Pump export job as the user SYSTEM. Export the entire database. Show the commandsyou would enter to perform the following actions:

■ Start an interactive session by using the ATTACH command.

■ Find out the name of the master table.

■ Parallelize the export (four streams).

■ Resume the export job.

Lab Question 65

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:52 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 129: OCA OCP - Oracle10G New Features For Administrators Exam Guide

66 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

SELF TEST ANSWERS

Introduction to the Data Pump Architecture

1. � A. The DBMS_METADATA and DBMS_DATAPUMP packages are the main OraclePL/SQL packages that the Data Pump technology uses. The Direct Path API is a part ofData Pump as well.� B, C, and D all contain the name of an invalid API.

2. � B. As the name of the package indicates, DBMS_METADATA is used to load and unloadmetadata.� A and C are not correct because the package doesn’t play a role in transportingtablespaces. D is wrong because the package isn’t related to external tables.

3. � C. The default name of the master table is of the format: USERNAME_OPERATION_TYPE_N. In this case, since you know user SYSTEM is performing a full import, it shouldn’tbe that hard to pick this answer.� A and D are wrong since they don’t have either user’s name. B is wrong since it containsthe username SYS instead of SYSTEM.

4. � B. The master table is created during an export job. The creation of the master table is thelast thing that the Data Pump export utility does, before finishing the job.� A is wrong since it says that the master table is created at the beginning of the export job.C and D are incorrect since they state that the master table is created during the import job.

Using Data Pump Export and Import

5. � A. This answer provides all the necessary parameters: username, dump filename, and theFULL parameter to perform the full import.� B is wrong because it is missing the FULL parameter—the default mode for import is theschema level, not a full database import. C is wrong because it is missing the dump filename.D is incorrect because there isn’t a FROMUSER/TOUSER option in Data Pump.

6. � C. This is a slightly tricky question. The CONTENT parameter offers the option ofexporting just the data in the tables, by using DATA_ONLY as the value for the parameter.� A and B are incorrect since these parameters enable you to specify only the type of objectsyou want to include or exclude. D is wrong since DATA_ONLY is not an export parameter—it’s an option for the CONTENT parameter.

7. � A and B. A is correct because using the STOP_JOB command doesn’t drop the mastertable. B is correct because using the KILL_JOB command terminates the job and drops themaster table.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:52 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 130: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test Answers 67

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

� C is incorrect since the use of the KILL_JOB command removes the master table. D isincorrect since an unexpected termination of a job doesn’t automatically drop the master table.

8. � B. You can start an interactive session in Data Pump only when an export job is alreadyrunning. Thus, when you log interactively in to a Data Pump job using either the CONTROL-C

sequence or the ATTACH command, the job is already running.� A and C are wrong since the export job is neither interrupted nor stopped when you log ininteractively. D is wrong since the Data Pump job must be running for you to log in interactively.

Monitor a Data Pump Job

9. � C. The SOFAR column in the V$SESSION_LONGOPS view tells you how much of DataPump job (in megabytes) has been completed thus far.� A, B, and D cannot tell you anything about the progress of your Data Pump jobs.

10. � C. First, you need to use the ATTACH command to attach to the interactive session. Tosuspend the job, you should use the STOP_JOB command. The START_JOB command willresume the job.� A, B, and D provide various wrong sequences of commands.

11. � B. You need to provide both the username/password and the job name before you canattach to a running job.� A is wrong because you don’t need to specify the dump file location. C is wrong becausethe username/password is inadequate to attach to a session. D is wrong because you don’t needthe master table’s name to attach to a Data Pump session.

12. � A. The SOFAR column tells you how many megabytes have been transferred thus far.� B and C are incorrect because the SOFAR column doesn’t deal with the percentage ofwork—it deals with the work in terms of megabytes. D is wrong because it talks about workstill to be done, not work already completed by the job.

Creating External Tables for Data Population

13. � A and C. A is correct because you must use the ORGANIZATION EXTERNAL clausewhether you are loading or unloading data. C is correct because you have to use the CREATETABLE AS SELECT (CTAS) clause when you populate an external table.� B is incorrect because you don’t need to use the CTAS statement during external tableloading. D is incorrect since you need the ORGANIZATION EXTERNAL clause for bothreading from and writing to external tables.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:52 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 131: OCA OCP - Oracle10G New Features For Administrators Exam Guide

68 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

14. � B. Unloading of data is the writing of Oracle table data to external datafiles, in theform of external tables.� A and D are clearly wrong since unloading of data involves writing of data, not readingof data. C is wrong since it states the opposite of what’s true.

15. � A is correct because you can’t use Data Pump export if you are exporting a read-onlydatabase, since you can’t create the master table in a read-only database. The NETWORK_LINK parameter provides a way to solve this problem.� B is wrong because this isn’t the reason why you need to use the NETWORK_LINKparameter. C is incorrect because you do need to create an export dump file, no matter whatparameters you specify. D is wrong because you can export a read-only database using thetraditional export utility.

16. � B and C. B is correct because Oracle will set the degree of parallelism to the number offiles. C is correct because when the number of datafiles is more than the degree of parallelism,Oracle will ignore the extra files.� A is incorrect since Oracle doesn’t ignore the PARALLEL parameter if the number of filesis different from the degree of parallelism. B is incorrect since Oracle doesn’t adjust the degreeof parallelism to match the number of datafiles. D is wrong since the parallel execution serverwill not write to multiple files simultaneously.

Defining External Table Properties

17. � C. The DBA should make sure that the PROJECT COLUMN attribute value is set toALL, which is the default value for the column as well.� A is incorrect since the DBA isn’t responsible for cleaning up the data format errors inthe data. B is wrong since there isn’t a value of ANY for the PROJECT COLUMN. D iswrong since setting the column value to REFERENCED will give you inconsistent queryresults, depending on the columns you specify in each query.

18. � A. The default value for the PROJECT COLUMN attribute is ALL, which means Oraclewill project all columns out.� B is wrong since the default behavior, as answer A shows, is to project out all columns.C and D are wrong since the projection of the columns has nothing to do with whether thecolumns have data errors or not.

19. � A, B, and C. If your data is clean, it doesn’t make a difference if the PROJECT COLUMNattribute has the value ALL or REFERENCED, since the results are going to be consistent witheither value.� D is incorrect since the use of the ALL column will produce the same results for any query,if your data doesn’t have any formatting errors.

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:53 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 132: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

Lab Answer 69

20. � A. REFERENCED is better because you need to parse and convert only the selectedcolumns in the query, not all the columns in the table.� B is incorrect because you need to parse and convert all columns, not just some, if youchoose the ALL value for the PROPERTY column. C is incorrect since ALL forces the parsingand conversion of all columns; it isn’t better than using the REFERENCED value for thePROPERTY column. D is incorrect since REFERENCED means that Oracle doesn’t parseand convert all columns.

Transporting Tablespaces Across Different Platforms

21. � B. You need to use the RMAN interface to convert database files when the endianformats are different between platforms.� A, C, and D are wrong since you can’t use any of these interfaces or tools to convertyour datafiles.

22. � A and D. You may convert the datafiles either on the source or on the target system,and perform a Data Pump import afterwards.� B and C are incorrect since they mention exporting of the metadata instead of importing.

23. � A. The V$TRANSPORTABLE_PLATFORM view shows you all the platforms that arecompatible with each other. You join this view with the V$DATABASE view to determineplatform compatibility.� B, C, and D are incorrect since there are no such views.

24. � D. You can transport tablespaces across platforms even if the endian formats are different,as long as you convert the datafiles during the transport process.� A is wrong since you can’t automatically transport tablespaces between two platforms ifthey both are in the V$TRANSPORTABLE_TABLESPACES view. If the endian formats ofthe two platforms vary, you need to perform a file conversion first. B is incorrect because fileconversions aren’t mandatory for transporting tablespaces—you need to convert datafiles onlyif the file semantics (endian formats) are different between the two platforms, since the endianformats cannot be different for implementing transportable tablespaces. C is incorrect becausethe opposite is true—you can automatically transport tablespaces across platforms if the endianformats are identical.

LAB ANSWER■ You can start an interactive session and attach to a running export job by using the following

command at the expdp prompt:

$ expdp salapati/sammyy1 attach=SALAPATI.SYS_EXPORT_SCHEMA_01

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:53 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 133: OCA OCP - Oracle10G New Features For Administrators Exam Guide

To stop the running job, you issue the following command at the expdp prompt (if you wantan immediate rather than an orderly stoppage of the export job, you can use the commandSTOP_JOB=IMMEDIATE):

expdp> STOP_JOB

■ The name of the master table is always the same as the job name. In this case, it isSYS_EXPORT_SCHEMA.

■ Once you attach to the running export session, you can issue various comamnds at theoperating system prompt. To make your export session perform an export to four dumpfiles simultaneously, you issue the following command:

expdp> PARALLEL=4

■ To resume your export job after making the changes, you issue the following command:

expdp> START_JOB

The START_JOB command doesn’t “start” a new job—it resumes a job you stopped by attachingto it first. If you have both the dump file and the master table (which is in the export dump file),you can always resume a stopped export job without any data loss or corruption of data.

70 Chapter 2: Loading and Unloading Data

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2

P:\010Comp\CertPrs8\862-4\ch02.vpMonday, August 30, 2004 2:09:53 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 134: OCA OCP - Oracle10G New Features For Administrators Exam Guide

3AutomaticDatabase

Management

CERTIFICATION OBJECTIVES

3.01 Use Automatic Database DiagnosticMonitor

3.02 Use Automatic Shared MemoryManagement

3.03 Use Automatic Optimizer StatisticsCollection

3.04 Use Automatic Undo Retention Tuning

✓ Two-Minute Drill

Q&A Self Test

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3Blind Folio 3:1

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:08 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 135: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You have probably heard a lot of talk about Oracle Database 10g being a self-managingdatabase. Far from being hype, Oracle Database 10g offers you a dazzling array ofself-managing features that will help you perform difficult tuning chores effortlessly.

Not only that, the database now provides you with ways to implement your performance fixes.As practicing Oracle DBAs, we all know how difficult it can be to figure out what is causinga performance problem. Accurate and quick diagnosis of performance issues is critical to thesuccess of any Oracle database professional. Oracle DBAs routinely undertake tuning exercisesthat involve running SQL scripts, poring over extended trace results, using the EXPLAIN PLANstatement, using the TKPROF utility, and/or employing other tuning aids.

For the first time, Oracle Database 10g helps you automatically diagnose performanceproblems. Diagnosing and fixing performance problems may be as simple as goingto the OEM Database Control and selecting one or more of the recommendations.Often, it is hard for you to reproduce a performance problem after it has alreadyoccurred. Do you recall how often the OracleMetaLink service asks you to see if youcan “reproduce” a performance problem? In Oracle Database 10g, the database collectsand saves all the statistical data you need for a performance diagnosis in the AutomaticWorkload Repository (AWR).

A new diagnosis tool, the Automatic Database Diagnostic Monitor (ADDM) analyzesthis data regularly, to provide you with detailed information about the root cause ofperformance problems, as well as recommendations for how to fix the problem. TheADDM relies on years of Oracle Corporation’s performance methods, thus makingit a sort of an expert system or a self-diagnostic engine that is built right into OracleDatabase 10g. Since the performance statistics collection mechanism relies on theOracle System Global Area (SGA), it is very accurate and efficient. The ADDMuses a new statistics collection method, where statistics are read directly from theSGA structures by a new background process called the Manageability Monitorprocess (MMON). Hence, there is none of the performance overhead of a sessionpopulating a V$ view.

Previous versions of Oracle provided you with ways to manage the critical SGAon a dynamic basis. The ability to dynamically modify SGA component sizes meansthat you don’t need to restart an instance after you make the changes. Now, Oraclehas gone a step further and provides you with the option of using Automatic SharedMemory Management. With automatic SGA management, you can realize the twintasks of conserving memory while improving database performance by automaticallyprovisioning SGA memory based on database workload, not tedious guesswork.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

2 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:08 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 136: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

Practicing Oracle DBAs know how critical it is to collect timely database statisticsso the Oracle optimizer performs efficiently. In Oracle Database 10g, there is a newfeature, the automatic optimizer statistics collection, in which Oracle itself automaticallyschedules the statistics collection, using the new database Scheduler feature. DBAshave always been beset with the problem of which tables to analyze and how often.Now, in Oracle Database 10g, you simply trust Oracle to decide for you.

In Oracle9i, you first encountered Automatic Undo Management (AUM). In OracleDatabase 10g, there are enhancements to this feature, including the interesting newoption of guaranteed undo retention. Using this new undo feature, you can virtuallyrule out any ORA-1555 (snapshot too old) errors.

In this chapter, our focus is on the exciting automatic management featuresintroduced in the Oracle Database 10g Server. Let’s start our discussion of OracleDatabase 10g’s automatic management features with a description of the ADDMfeature.

■ Using the Automatic Database Diagnostic Monitor (ADDM)

■ Using Automatic Shared Memory Management

■ Using automatic optimizer statistics collection

■ Using automatic undo retention tuning

CERTIFICATION OBJECTIVE 3.01

Using the Automatic DatabaseDiagnostic Monitor (ADDM)

As an Oracle DBA, you know how difficult it is sometimes to figure out why your databaseperformance isn’t up to par. You may need to hunt down the causes, but too often, youare likely to mistake the symptoms for the causes. Correctly diagnosing performanceproblems is the key to efficient performance tuning.

Traditionally, organizations have spent considerable amounts of effort on performancetuning, which usually tends to be quite laborious and not an exact science. OracleDatabase 10g changes all that. It provides you with very powerful and accurate automatic

Using the Automatic Database Diagnostic Monitor (ADDM) 3

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:08 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 137: OCA OCP - Oracle10G New Features For Administrators Exam Guide

performance-tuning capabilities. The heart of the new automatic performance tuningis the new statistics collection facility, the Automatic Workload Repository (AWR),which automatically saves crucial performance information in the new mandatorySYSAUX tablespace.

By default, the AWR collects new performance statistics in the form of a snapshoton an hourly basis and saves the snapshots for seven days before purging them. Thesesnapshots of database activity include resource-intensive SQL statements. TheAutomatic Database Diagnostic Monitor (ADDM) runs automatically every hour,after the AWR takes a new snapshot. The ADDM uses the AWR performancesnapshots to locate the root causes for poor performance and provides recommendationsfor improving performance.

The AWR saves all historical performance data, so you don’t need to worry aboutbeing able to reproduce a performance problem. Every time the AWR takes a snapshotof the database, which is hourly by default, the ADDM runs automatically and analyzesthe key data gathered by the AWR. You can then go to the OEM Database Controlto view the results, or even view them from a SQL*Plus session with the help of an

Oracle-supplied SQL script.The ADDM runs automatically, although you

can also manually invoke the tool to investigateproblems that occur in between the scheduledsnapshots. As the DBA, you are relieved ofthe responsibility of catching a problem at theright time to collect statistic, since the ADDMautomatically analyzes performance data for you.

The Goal of the ADDMThe entire rationale behind the work of the ADDM is to reduce a key database metriccalled DB time, which stands for database time (in microseconds) spent actually processinguser’s requests. DB time is the total time the database is spending on processing userrequests.

The DB Time VariableThe DB time variable includes only the cumulative amount of time spent on actualdatabase calls (at the user level) and doesn’t include time spent on background processes.DB time includes both the wait time and processing time (CPU time). DB time doesn’tinclude the idle time incurred by your processes. For example, if you spend 30 minutes

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

4 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

The results of the AWRstatistics collection, including the snapshots,are stored in the SYSAUX tablespace. Oraclestores the ADDM analyses in the sametablespace as well.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:08 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 138: OCA OCP - Oracle10G New Features For Administrators Exam Guide

connected to the database and you’re idle for 28 of those minutes, then DB time isonly 2 minutes.

If a problem is contributing to inappropriate or excessive DB time, the ADDMautomatically flags it as an issue that needs your attention. If there is a problemin your system, but it doesn’t contribute significantly to the DB time variable, theADDM will simply ignore the problem. Thus, the entire functioning of the ADDMrevolves around the single mantra: reduce DB time. By relentlessly focusing on thereduction of database time (DB time), the ADDM’s aim is to increase the throughputof your database, thus serving more users with the same amount of resources.

Problems That the ADDM DiagnosesThe ADDM analyzes the AWR snapshots periodically and comes up with performancerecommendations, usually quantified in terms of expected benefit of various actions.Following are some of the key problems that the ADDM diagnoses:

■ Configuration issues

■ Improper application usage

■ Expensive SQL statements

■ I/O performance issues

■ Locking issues

■ Excessive parsing

■ CPU bottlenecks

■ Undersized memory allocation

■ Connection management issues, such as excessive logon/logoff statistics

You may be wondering why you shouldn’t just use the well-known STATSPACKutility to gather performance-related data. For one thing, STATSPACK has toomuch information, not all of which is critically important to fixing critical performanceproblems that are occurring right now. The ADDM uses a sophisticated, new timestatistics model in Oracle Database 10g, which is highly effective in determiningwhere time is spent in the database. This new time statistics model enables Oracle tofocus on only the most critical performance problem areas. DB time is the key metricagainst which the ADDM judges all performance problems. If a problem exceeds thethreshold for DB time, the ADDM tags it as a top performance issue; otherwise, itleaves it alone as nonproblem area.

Using the Automatic Database Diagnostic Monitor (ADDM) 5

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:08 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 139: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

The New Time ModelThe ADDM bases most of its performance recommendations on the basis of time modelstatistics, the most important of which is the new DB time statistic. The DB time statistic,as I explained in the previous section, represents the true workload of your database,because it shows the total time spent in making database calls. In addition to DB time,time model statistics also provide timings relating to logon statistics and parse activity.Using decades of its performance-tuning expertise, Oracle has come up with a new andmore accurate time model to accurately diagnose performance issues.

Two new database views, V$SESS_TIME_MODEL and V$SYS_TIME_MODEL,help you to manage these new time-based performance statistics.

The V$SYS_TIME_MODEL view provides the accumulated time statistics for variousoperations in the entire database. This view shows time in terms of the number ofmicroseconds the database has spent on a specific operation. The following querydemonstrates the kind of operations for which the V$SYS_TIME_MODEL viewholds statstics.

SQL> select stat_name ,value from V$SYS_TIME_MODELSTAT_NAME VALUE---------------------------------------------------------------- ----------DB time 3175312459DB CPU 473486465background elapsed time 7152613400background cpu time 445371822sequence load elapsed time 2780225parse time elapsed 1003246942hard parse elapsed time 969141891sql execute elapsed time 2921215454connection management call elapsed time 49093303failed parse elapsed time 278729failed parse (out of shared memory) elapsed time 0hard parse (sharing criteria) elapsed time 7446158hard parse (bind mismatch) elapsed time 3152674PL/SQL execution elapsed time 327980460inbound PL/SQL rpc elapsed time 0PL/SQL compilation elapsed time 267986126Java execution elapsed time 017 rows selected.SQL>

The V$SESS_TIME_MODEL view is similar to the V$SYS_TIME_MODEL viewand provides the same types of time statistics, but at a session level, instead of thesystem level.

6 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:08 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 140: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Benefits Provided by the ADDMThe ADDM bases its recommendations on a holistic approach, with time spent ondatabase activities as its main focus. Here are some of the important benefits of usingthe ADDM:

■ It identifies the root causes of performance problems, instead of merelyfocusing on the symptoms. The ADDM will automatically capture highlyresource-intensive SQL statements.

■ It produces automatic performance diagnostic reports at periodic intervals.

■ You’ll experience very little performance overhead when using the tool.A typical ADDM analysis takes only three or four seconds.

■ The ADDM points out nonproblem areas, so you don’t waste your effortspoking around in areas with little bang for the buck.

■ Performance diagnosis is based on decades’ worth of Oracle’s expert tuningknowledge.

Types of ADDM RecommendationsThe ADDM may propose several recommendations for the same performanceproblem. The recommendations may include the following:

■ Hardware changes ADDM may recommend that you add more CPUs toyour system. It may also recommend that you change the way you configureyour I/O subsystem.

■ Database and application changes The ADDM may find, for example, thatyour database is performing an excessive amount of parses due to the failureto use bind variables. In a case like this, it may recommend that you changeyour initialization parameter CURSOR_SHARING to a setting of FORCE,rather than rewrite your application code. In some other cases, the ADDMmay recommend that you go ahead and rewrite the application code so youuse bind variables.

■ Space configuration changes The ADDM may sometimes makerecommendations like switching to the new Automatic Storage Management(ASM) to fix certain performance problems.

■ Using management advisors The ADDM may recommend several changesthat you can implement immediately to improve database performance.

Using the Automatic Database Diagnostic Monitor (ADDM) 7

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:08 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 141: OCA OCP - Oracle10G New Features For Administrators Exam Guide

However, in some cases, it may recommend that you use a managementadvisor—like the SQL Tuning Advisor, Undo Advisor, or Segment Advisor—to gain an in-depth knowledge of the performance problems. For example,the ADDM may tag certain high-load SQL statements as candidates forautomatic SQL tuning, using the Automatic Tuning Optimizer (I’ll explainthis in Chapter 5).

Automatic Management of the ADDMOracle manages the ADDM with the help of a brand-new background process in OracleDatabase 10g databases: the MMON. The MMON process schedules the automaticrunning of the ADDM. Each time the AWR takes a snapshot (every 60 minutes, bydefault), the MMON process asks the ADDM to analyze the interval between the lasttwo snapshots it gathered. This is the default behavior of the ADDM performance analysis.

Where does the ADDM store its analysis results? Not surprisingly, the ADDMstores the results in the AWR itself. You can use the OEM Database Control toview the ADDM’s performance analysis and action recommendations.

Configuring the ADDMIt might surprise you to find out that you don’t need to go through an arduous setup orconfiguration exercise for using the amazingly powerful ADDM feature. Oracle enablesthe ADDM feature by default. Your only task is to make sure that the initializationparameter STATISTICS_LEVEL is set to TYPICAL or ALL, in order for the AWRto gather its cache of performance statistics. If you set STATISTICS_LEVEL to

8 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

You must set theinitialization parameter STATISTICS_LEVEL to TYPICAL or ALL in order to usethe ADDM. If you set STATISTICS_LEVELto BASIC, you cannot use the ADDM. Inaddition, you won’t be able to use severalother important Oracle diagnostic features.For example, if STATISTICS_LEVEL is setto BASIC, you must explicitly set the

TIMED_STATISTICS parameter to TRUEin order to collect timed performancestatistics. Oracle strongly recommends theuse of the TYPICAL setting, which it deemssufficient for all your day-to-day needs.BASIC cripples your tuning efforts, whileALL will have a performance impact onyour system.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:08 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 142: OCA OCP - Oracle10G New Features For Administrators Exam Guide

BASIC, you can still manually use the AWR to collect statistics by using the DBMS_WORKLOAD_REPOSITORY package. However, you will not be able to collect severalimportant types of performance statistics.

You can control the amount of statistics collected by the AWR by adjusting eitheror both of two variables:

■ Snapshot interval The default snapshot interval is 60 minutes, and Oraclerecommends that you use the default interval for your everyday needs. Rememberthat flushing statistics involves a performance hit, however minor. Oracle’sassumption is that once an hour is frequent enough for diagnosis and infrequentenough not to influence performance. The DBA must decide whether he orshe agrees with this assumption.

■ Snapshot-retention period The snapshot-retention period is the length oftime for which the AWR retains all snapshots. The default retention periodis 7 days. After the snapshot-retention period expires, Oracle will automaticallypurge the outdated snapshots from the AWR.

You can modify the length of the snapshot interval and snapshot retention by usingthe INTERVAL and the RETENTION parameters of the MODIFY_SNAPSHOT_SETTINGS of the DBMS_WORKLOAD_REPOSITORY package. Chapter 4 providesexamples showing you how to manage AWR historical data retention by modifyingthe INTERVAL and RETENTION parameters.

The ADDM runs automatically after each AWR snapshot. If you don’t like thedefault (60-minute) interval, you can change it.

Determining Optimal I/O PerformanceHow does the ADDM know what is optimal I/O performance? If your I/O system performsat a certain speed, your system can read a database block in a specific number ofmilliseconds. The ADDM makes the critical assumption that the average time toread a database block is 10 milliseconds. The DBIO_EXPECTED parameter (notan initialization parameter) indicates your I/O performance, and by default, Oracleassumes this parameter’s value is 10 milliseconds.

You can find out the current value of the DBIO_EXPECTED parameter by queryingthe DBA_ADVISOR_DEF_PARAMETERS view in the following way:

SQL> select parameter_value2 from dba_advisor_def_parameters

where advisor_name='ADDM'

Using the Automatic Database Diagnostic Monitor (ADDM) 9

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:09 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 143: OCA OCP - Oracle10G New Features For Administrators Exam Guide

10 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

4* AND parameter_name='DBIO_EXPECTED';PARAMETER_VALUE----------------10000SQL>

What do you do if you think your I/O subsystem is fast, and performs a databaseblock in only 6 milliseconds, or is slow and takes longer? You can use the DBMS_ADVISOR package to change the default value of the DBIO_EXPECTED parameter,as I’ll explain later in this chapter, in the “Using the DBMS_ADVISOR Package toManage the ADDM” section.

Running the ADDMThe new Oracle background process, MMON, schedules the ADDM to run every timethe AWR collects its most recent snapshot. Thus, Oracle will automatically generateADDM reports throughout the day.

You can also perform an ad hoc ADDM analysis any time, to find out detailsabout a performance problem that’s currently occurring in the database. Rememberthat the AWR will be taking periodic snapshots of database performance statisticsthroughout the day. You can request that the ADDM analyze the data that fallsbetween any two snapshots. Note that the two beginning and ending snapshotsdon’t need to be consecutive. The only requirements regarding the selection ofthe AWR snapshots are the following:

■ The snapshots must be clean, without any errors.

■ There shouldn’t be a database shutdown during the two snapshots.

The easiest way to view the ADDM’s findings is to use the OEM Database Control.You can get to the ADDM by clicking the Advisor Central link first, and then choosingADDM. Once you reach the ADDM page, you can view the latest performance findingsor start a new ADDM task.

Oracle runs the ADDMautomatically every hour, following theAWR snapshot collection. You may,however, run it manually whenever you

choose. You may want to run the ADDMmanually either because an alert recommendsthat you do so or because you want anADDM analysis across multiple snapshots.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:09 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 144: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You can also obtain complete ADDM reports by running the Oracle-providedSQL script addmrpt.sql, which you’ll find in your ORACLE_HOME/rdbms/admindirectory. As explained earlier, the AWR will take snapshots of database performanceat specified intervals. Assuming the default of one-hour intervals, you’ll have asmany snapshots in the AWR as the number of hours since you started the databaseinstance.

In the following example, the database was started sometime after 10:00 A.M.and there are four consecutive hourly snapshots in the system. Note that there is asnapshot captured at 9:57 A.M., but I brought down the database after that. You cancompare two snapshots only if you don’t shut down the database in between. Whyis this so? The AWR holds only cumulative database statistics. Obviously, once youshut down the database, all the cumulative data will lose its meaning.

In this example, I show how to get the ADDM report for the period between10:00 A.M. and 1:00 P.M. To do so, I need to specify the snapshot numbers pertainingto the 10:00 A.M. and 1:00 P.M. snapshot collection times. The addmrpt.sql scriptprovides this information. In the script, notice that the snapshot IDs 258 (capturedat 10:00 A.M.) and 261 (captured at 1:00 P.M.) will contain the performance statisticsfor the period between 10:00 AM and 1:00 PM. Therefore, I provide the snapshot IDs258 and 261 in response to the prompts for the beginning and ending snapshot IDs.

SQL> @c:\oracle\product\10.1.0\Db_1\RDBMS\ADMIN\addmrpt.sqlDB Id DB Name Inst Num Instance

----------- ------------ -------- ------------877021568 NINA 1 nina

Specify the number of days of snapshots to choose from~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Entering the number of days (n) will result in the most recent(n) days of snapshots being listed. Pressing <return> withoutspecifying a number lists all completed snapshots.Listing the last 3 days of Completed Snapshots

SnapInstance DB Name Snap Id Snap Started Level------------ ------------ --------- ------------------ -----nina NINA 257 21 Apr 2004 09:27 1

258 21 Apr 2004 10:00 1259 21 Apr 2004 11:00 1260 21 Apr 2004 12:00 1261 21 Apr 2004 13:00 1

Specify the Begin and End Snapshot Ids~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Enter value for begin_snap: 258Begin Snapshot Id specified: 258Enter value for end_snap: 261End Snapshot Id specified: 261

Using the Automatic Database Diagnostic Monitor (ADDM) 11

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:09 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 145: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Specify the Report Name~~~~~~~~~~~~~~~~~~~~~~~The default report file name is addmrpt_1_258_261.txt. To use this namepress <return> to continue, otherwise enter an alternative.Enter value for report_name:Using the report name addmrpt_1_258_261.txtRunning the ADDM analysis on the specified pair of snapshots ...

For space reasons, I am not showing the entire ADDM report. The textual reportthat the addmprt.sql generates is identical to the detailed report that you can getusing the OEM Database Control’s ADDM page. You’ll see this report later in thischapter, in the section “Viewing Detailed ADDM Reports.”

The ADDM doesn’t always offer you a direct recommendation for a performanceproblem that it encounters. A key aspect of an ADDM analysis is that. In manycases, it recommends that you use one of Oracle’s built-in advisors, like theSQL Tuning Advisor, to analyze a complex performance situation.

The ADDM AnalysisThe ADDM presents the results of its analysis to you in a standard format each time.Each ADDM analysis finding consists of the following four components:

■ The definition of the problem itself

■ The root cause of the performance problem

■ Recommendation(s) to fix the problem

■ The rationale for the proposed recommendations

By navigating to the Performance Details page of the ADDM using the OEMDatabase Control, you can see all the problems and the recommendations for fixingthem. For each problem in the report, ADDM displays each of its performance findingsin the form of three columns: the Impact column, the Finding column, and theRecommendations column.

The Impact column lists the performance problems in the order of their impact ontheir system. The Impact column is thus very important, because you can start workingon fixing the most serious problem that is affecting current database performance. Youmay think parsing issues are more serious than, say I/O-related issues, but if the Impactcolumn ranks I/O problems as number one, you should attend to the I/O problems first.

12 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:09 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 146: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Oracle enables the ADDM by default, as long as you set the STATISTICS_LEVEL parameter to TYPICAL or ALL. You can shut the ADDM down by simplysetting the STATISTICS_LEVEL parameter to BASIC. However, rememberthat this step will also disable many automatic performance tuning and statisticsgathering activities of Oracle Database 10g.

Let’s look at a typical ADDM problem analysis and list of recommendations. Thisanalysis is from the OEM Database Control’s ADDM page.

Problem Recommendation

The buffer cache wasundersized causing significantadditional read I/O.

Increase SGA target by increasing the value of parameter SGA_TARGETby 256M.

The throughput of the I/Osubsystem was significantlylower than expected.

Consider increasing the throughput of the I/O subsystem. Oracle’s recommendedsolution is to stripe all datafiles using the same methodology. You might alsoneed to increase the number of disks for better performance. Alternatively,consider using Oracle’s ASM solution.

Hard parsing of SQLstatements was consumingsignificant database time.

Here, the ADDM did not make any recommendations. By clicking theAdditional Information button, I found that ADDM didn’t see any reasonto tinker with the parsing issue, for the following reasons:Hard parses due to cursor environment mismatch were not consumingsignificant database time.Hard parsing SQL statements that encountered parse errors was not consumingsignificant database time.Parse errors due to inadequately sized shared pool were not consumingsignificant database time.Hard parsing due to cursors getting aged out of shared pool was not consumingsignificant database time.Hard parses due to literal usage and cursor invalidation were not consumingsignificant database time.

Database writers (DBWR)were unable to keep up withthe demand for free buffers.

Consider increasing the number of database writers (DBWR) by setting theparameter DB_WRITER_PROCESSES.

Time spent on the CPU bythe instance was responsiblefor a substantial part ofdatabase time.

Tune the PL/SQL block with SQL_ID “2b064ybzkwf1y.” Refer to the“Tuning PL/SQL Applications Chapter of Oracle’s “PL/SQL User’s Guideand Reference.”

Using the Automatic Database Diagnostic Monitor (ADDM) 13

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:09 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 147: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Viewing Detailed ADDM ReportsIf you want to view a Detailed ADDM Report for any given ADDM task, all you needto do is click the View Report button on the ADDM main page in the Database Control.You can then view the results, or if you wish, save the results to a file or print the report.

Note that in addition to the information about impact, problem, and recommendationsthat you can gain from the main ADDM page, the detailed report includes a listingof the symptoms that led to each particular finding. In addition, for some problems,the ADDM report also includes a Rationale section that details the reasoning for itsaction recommendations.

Here is an example of a detailed report:

DETAILED ADDM REPORT FOR TASK 'ADDM:877021568_1_259' WITH ID 1052-----------------------------------------------------------------

Analysis Period: 21-APR-2004 from 10:00:08 to 11:00:40Database ID/Instance: 877021568/1

Database/Instance Names: NINA/ninaHost Name: NTL-ALAPATISAM

Database Version: 10.1.0.2.0Snapshot Range: from 258 to 259Database Time: 357 seconds

Average Database Load: .1 active sessions-----------------------------------------------------------------------------FINDING 1: 87% impact (311 seconds)-----------------------------------------------------------------------------The throughput of the I/O subsystem was significantly lower than expected.

RECOMMENDATION 1: Host Configuration, 87% benefit (311 seconds)ACTION: Consider increasing the throughput of the I/O subsystem.

Oracle's recommended solution is to stripe all data file using theSAME methodology. You might also need to increase the number of disksfor better performance. Alternatively, consider using Oracle'sAutomatic Storage Management solution.

SYMPTOMS THAT LED TO THE FINDING:Wait class "User I/O" was consuming significant database time. (100%impact [467 seconds])

Notice that Recommendation 1 is shown as providing an “87% benefit.” Benefithere refers to the reduction in DB time due to the recommendation’s implementation.Thus, the ADDM is telling you that you can save a maximum of up to 87 percent ofthe total DB time by following the proposed solution.

At the end of the Detailed ADDM Report, you’ll see a section called AdditionalInformation, which usually shows insignificant wait information. Here is a typicallist of findings under the Additional Information heading:

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

14 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:09 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 148: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Wait class "Administrative" was not consuming significant database time.Wait class "Application" was not consuming significant database time.Wait class "Cluster" was not consuming significant database time.Wait class "Commit" was not consuming significant database time.Wait class "Concurrency" was not consuming significant database time.

Using the DBMS_ADVISOR Package to Manage the ADDMThe new DBMS_ADVISOR package helps you manage the attributes of the ADDMtool, as well as perform jobs like creating tasks and retrieving ADDM reports using SQL.The DBMS_ADVISOR package is part of the Server Manageability Suite of advisors,which is a set of rule-based expert systems that identify and resolve performance problemsof several database components. This set of advisors helps you manage performanceissues relating to various database components in Oracle Database 10g. The ADDMis one of this set of advisors, and you’ll learn more about the other advisors in laterchapters.

The DBMS_ADVISOR package requires the ADVISOR privilege.

The following are a few of the main procedures and functions of the DBMS_ADVISOR package. Note that these program components apply not just to theADDM, but also to all the other database advisors.

■ You use the CREATE_TASK procedure to create a new advisor task.

■ The SET_DEFAULT_TASK procedure helps you modify default valuesof parameters within a task.

■ The DELETE_TASK procedure deletes a specific task from the repository.

■ The EXECUTE_TASK procedure executes a specific task.

■ The GET_TASK_REPORT displays the most recent ADDM report.

■ The SET_DEFAULT_TASK_PARAMETER procedure modifies a defaulttask parameter.

You can use the SET_DEFAULT_TASK procedure to modify default values ofADDM parameters like DBIO_EXPECTED (discussed earlier in the “DeterminingOptimal I/O Performance” section). The following example illustrates the technique:

SQL> sho userUSER is "SYS"SQL> exec DBMS_ADVISOR.SET_DEFAULT_TASK_PARAMETER(-> 'ADDM', 'DBIO_EXPECTED', 6000);PL/SQL procedure successfully completed.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

Using the Automatic Database Diagnostic Monitor (ADDM) 15

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:09 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 149: OCA OCP - Oracle10G New Features For Administrators Exam Guide

16 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

The GET_TASK_REPORT procedure in the DBMS_ADVISOR package enablesyou to get XML, text, or HTML reports for a specified task, including an ADDMtask. Here is the structure of the GET_TASK_REPORT procedure:

DBMS_ADVISOR.GET_TASK_REPORT (task_name IN VARCHAR2,type IN VARCHAR2 := 'TEXT',level IN VARCHAR2 := 'TYPICAL',section IN VARCHAR2 := 'ALL',owner_name IN VARCHAR2 := NULL)

RETURN CLOB;

The possible values for the TYPE parameter are TEXT, XML, and HTML. Thepossible values for the LEVEL parameter, which stands for the initializationparameter STATISTICS_LEVEL, are TYPICAL, ALL, and BASIC. Rememberthat setting the STATISTICS_LEVEL parameter to BASIC will mean that youcan’t use the ADDM tool.

Here’s an example that shows how to use the GET_TASK_REPORT procedure toobtain an ADDM report (I am abbreviating the ADDM report shown in the output;it is the same report you saw earlier through the OEM Database Control and the useof SQL scripts):

SQL> select DBMS_ADVISOR.GET_TASK_REPORT('ADDM:877021568_1_252')2 from dba_advisor_tasks3 where task_id = (select max(t.task_id)4 from dba_advisor_tasks t,5 dba_advisor_log l6 where t.task_id = l.task_id AND7 t.advisor_name='ADDM' AND8* l.status='COMPLETED');

DBMS_ADVISOR.GET_TASK_REPORT('ADDM:877021568_1_252')----------------------------------------------------------------------------

DETAILED ADDM REPORT FOR TASK 'ADDM: 877021568_1_252' WITH ID 1002----------------------------------------------------------------------------Analysis Period: 14-APR-2004 from 05:00:37 to 06:00:07

Database ID/Instance: 877021568/1The analysis of I/O performance is based on the default assumption that theaverage read time for one database block is 10000 micro-seconds.DBMS_ADVISOR.GET_TASK_REPORT('ADDM:877021568_1_252')SQL>

To produce this ADDM report, you don’t need to specify any snapshots. Howthen, does Oracle know which snapshots it should consider for preparing its report?Well, when you use the DBMS_ADVISOR package to produce an ADDM report,Oracle will always use the data that it collects between the two most recent snapshots.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:09 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 150: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

Using ADDM-Related Dictionary ViewsFollowing are some of the new views that’ll help you in dealing with the ADDM:

■ The DBA_ADVISOR_RECOMMENDATIONS view shows the results of analyzingall the recommendations in the database.

■ The DBA_ADVISOR_FINDINGS view shows the findings of all the advisorsin your database.

■ The DBA_ADVISOR_RATIONALE view shows the rationale behind all therecommendations.

CERTIFICATION OBJECTIVE 3.02

Using Automatic Shared Memory ManagementEvery DBA knows how hard it is sometimes to adjust the SGA, which is the memorythat Oracle assigns to every instance to hold data and control information. You mayhave a situation where online transaction processing (OLTP) transactions dominatethe database all day, and you run heavy-duty batch jobs during the night. In cases likethis, you may need more allocation for the buffer cache during the daytime and anincrease in the large pool component of the SGA for the nightly batch jobs.

You can, of course, dynamically change several SGA components, as well as usescripts to change SGA allocations before and after batch jobs, but the fact remainsthat it is you, the DBA, who is directly responsible for adjusting the SGA componentsto match the needs of the database instance. Problems like the ORA-4031 (out ofshared pool memory) error are all too common, forcing you to juggle with the manualtuning parameters. You may also face a situation where you might be assigning toomuch SGA memory, thus wasting precious resources, or too little memory, whichaffects database performance.

Using Automatic Shared Memory Management 17

Remember that there arethree ways to retrieve an ADDM analysisreport: you can use the OEM DatabaseControl interface, the SQL*Plus interface

(by running the addmrpt.sql script), or theDBMS_ADVISOR package (by runningthe GET_TASK_REPORT procedure).

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:10 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 151: OCA OCP - Oracle10G New Features For Administrators Exam Guide

In Oracle Database 10g, for the first time, you can make the often-tricky issue ofshared memory management completely automatic. This is one of the more significantenhancements of Oracle Database 10g, and it contributes significantly to Oracle’sgoal of automatic database self-management. Oracle will automatically allocate anddeallocate memory for each of the memory pools, based on changing database workloads.Oracle will use internal views and statistics to decide on the best way to allocatememory among the SGA components. Automatic Shared Memory Managementprovides you the following benefits:

■ Less chance of running out of shared pool memory

■ Optimal use of available memory

■ Significant performance improvement because memory allocation keeps stepwith fluctuations in the database workload

Before we delve into the new Automatic Shared Memory Management feature ofOracle Database 10g, let’s quickly review the manual memory management feature,which is still available for you to use.

Manual Shared Memory ManagementOracle will still let you manage the shared memory components manually. Undertraditional shared memory management, you need to set several initialization parametersfor the various components of the SGA. These dynamic memory parameters are DB_CACHE_SIZE, SHARED_POOL_SIZE, LARGE_POOL, JAVA_POOL_SIZE, andSTREAMS_POOL_SIZE.

You can limit the size of the total amount of memory used by Oracle by settingthe SGA_MAX_SIZE parameter in your initialization file. When you do this, Oraclewill limit the sum of the various components of the SGA to the value you specify. Ifyou don’t specify an explicit SGA_MAX_SIZE parameter, it defaults to the sum of

18 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

In Oracle Database 10g,the database enables the Automatic PGAMemory Management feature by default.However, if you set the PGA_AGGREGATE_

TARGET parameter to 0 or the WORKAREA_SIZE_POLICY parameter to MANUAL,Oracle doesn’t use Automatic PGA MemoryManagement.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:10 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 152: OCA OCP - Oracle10G New Features For Administrators Exam Guide

the actual size of all the SGA components. If you set the SGA_MAX_SIZE to avalue smaller than the sum of all the SGA components, Oracle will automaticallybump up the SGA_MAX_SIZE parameter’s value to the sum of the memory assignedto all the components.

Automatic Memory ManagementIn the manual memory management model, you need to calibrate the individualcomponents of the SGA. To let Oracle automatically manage the memory allocationsto the individual components of the SGA, you need to set the new initializationparameter SGA_TARGET. By default, the SGA_TARGET parameter is set to zero.Once you provide a nonzero value for the SGA_TARGET parameter, AutomaticShared Memory Management is enabled.

In order to use Automatic Shared Memory Management, you should firstset the initialization parameter STATISTICS_LEVEL to its default value ofTYPICAL or ALL. Oracle doesn’t populate the V$SHARED_POOL_ADVICEand the V$DB_CACHE_ADVICE views if the STATISTICS_LEVEL parameteris set to BASIC.

The new Oracle Database 10g background process MMAN performs all the memoryresizing necessary for the Automatic Shared Memory Management feature. The MMANprocess constantly monitors the workload of the database and adjusts the size of theindividual memory components accordingly.

Using Automatic Shared Memory Management 19

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

All SGA automaticcomponents behave the same as inprevious versions, except the sharedpool component, which you set with theinitialization parameter SHARED_POOL_SIZE. In Oracle Database 10g, the valueof the SHARED_POOL_SIZE parameterincludes the internal overhead allocationsfor metadata such as the various datastructures for sessions and processes.

You must, therefore, make sure to increasethe size of the SHARED_POOL_SIZEparameter when you are upgrading toOracle Database 10g. You can find theappropriate value of your new SHARED_POOL_SIZE parameter before the upgradeby using the following query:

Select SUM(bytes)/1024/1024 from V$SGASTATWhere pool = 'shared pool';

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:10 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 153: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Two Sets of SGA ParametersAs you know, Oracle’s SGA is not one big chunk of memory. Rather, it consists of severalspecific components like the buffer cache and shared pool. When you use AutomaticShared Memory Management by setting the SGA_TARGET parameter to a nonzerovalue, the database doesn’t manage all of the shared memory components. Althoughwe call it Automatic Shared Memory Management, the SGA has both an automaticand a manual set of components.

Under Automatic Shared Memory Management, the database manages thefollowing four major components of the SGA, also known as the auto-tuned SGAparameters:

■ Buffer cache (DB_CACHE_SIZE)

■ Shared pool (SHARED_POOL_SIZE)

■ Large pool (LARGE_POOL_SIZE)

■ Java pool (JAVA_POOL_SIZE)

It is important to understand that even under Automatic Shared MemoryManagement, you still need to configure any SGA component other than the fourauto-tuned components. Following are the manually sized components of the SGA:

■ Redo Log Buffer

■ The KEEP and RECYCLE buffer caches (if specified)

■ The nonstandard block size buffer caches (if specified)

■ The new Streams pool SGA component

■ The new Oracle Storage Management (OSM) buffer cache, which is meantfor the optional ASM instance

Note that in addition to the automatic and manual components, Oracle also assignsa certain amount of memory to the fixed SGA, which contains database and instancestate information useful to the background processes. The fixed SGA doesn’t containany user data.

It is important to understand that the SGA_TARGET parameter shows the sumof all SGA components, not just the automatically managed memory components.Interestingly, even under Automatic Shared Memory Management, the manuallysized components get the first crack at the SGA allocated by the SGA_TARGETparameter. Oracle will first subtract the total value of all the manually sized memorycomponents from SGA_TARGET, and then allocate the remainder of the memory

20 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:10 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 154: OCA OCP - Oracle10G New Features For Administrators Exam Guide

among the four auto-tuned memorycomponents—shared pool, default buffercache, large pool, and Java pool. Let’s use asimple example to demonstrate this extremelyimportant point.

Let’s say that you set the SGA_TARGETparameter to 1000MB. You want to use multipleblock sizes in your database, so you then set thefollowing values (both of these parameters

belong to the manually sized group of SGA parameters) for the DB_nK_CACHE_SIZE parameters:

DB_4K_CACHE_SIZE=100MBDB_8K_CACHE_SIZE=200MB

In this case, you’ll have a total of 700MB (SGA_TARGET – (DB_4K_CACHE_SIZE + DB_8K_CACHE_SIZE)) left for Oracle to automatically allocate amongthe four auto-tuned SGA parameters.

Once you set the SGA_TARGET variable to a nonzero value, the database willautomatically manage shared memory (only the four automatically tuned components).But how does Oracle know how much memory to allocate for each of the four auto-tuned memory components? Well, the default values for these four componentsbegin at zero. Oracle uses an internal memory-tuning algorithm, based on databaseworkload, to allocate memory to each of the auto-tuned memory components.Oracle will gradually increase the memory allocated to each component as necessaryover time, eventually stabilizing their level at an optimal allocation. Oracle recommendsthat you try not to set a minimum for any these components, since that would interferewith the database’s ability to allocate memory optimally.

If Oracle is automatically managing your SGA, can you influence the sizes of theautomatically tuned SGA components? If you know that you will have serious problemsif you start your database instance with a zero-valued shared pool, for example, youcan set specific sizes for any of the four auto-tuned components. Oracle will ensurethat the memory allocation to these components will never fall below the minimumallocations you made. For example, if you set the BUFFER_CACHE parameter to 100Mand the SHARED_POOL parameter to 400M, Automatic Shared Memory Managementwill then use these two values as minimum levels for the two parameters.

For example, let’s say you assign the following values in the init.ora (or SPFILE):SGA_TARGET=900M and SHARED_POOL_SIZE=400M. Then Oracle will neverallocate less than 400MB of memory for the shared pool. Oracle will have 500MB

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

Using Automatic Shared Memory Management 21

Know that the SGA_TARGET parameter includes the entirememory of the SGA, including the “overheadcomponent”—memory for the internal andfixed SGA.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:10 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 155: OCA OCP - Oracle10G New Features For Administrators Exam Guide

(900 – 400) of SGA left for the other three auto-tuned parameters (of course, if youassign any memory for the manually tuned parameters, you’ll be left with even lessthan 500MB of SGA).

In summary, the two sets of SGA parameters work as follows:

■ Oracle may assign more, but not less than, the minimum values you assignfor the auto-tuned parameters.

■ Oracle cannot change the values of the manually sized components.

SGA_TARGET Parameter Size LimitsYou set the initial size of the SGA_TARGET parameter in the initialization file. If thisis the first time you are using Automatic Shared Memory Management, you can quicklyarrive at a good approximation for the SGA_TARGET parameter by summing the valueof all the SGA components using the V$SGA view, as shown here:

SQL> select sum(value) from v$sga;SUM(VALUE)------------------184549376SQL>

Once you start the instance with a certain value for SGA_TARGET, you canincrease or decrease its size dynamically by using the alter system command:

SQL> alter system set sga_target=600M;System altered.SQL>

How high can you raise the SGA_TARGET parameter? The SGA_MAX_SIZEparameter sets an upper bound on the value of the SGA_TARGET parameter. Ifyou haven’t specified an SGA_MAX_SIZE value, you can increase the value of the

22 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

The new SGA_TARGETinitialization parameter has twomajor components: the automaticallysized components and the manually sizedcomponents. In addition, you have a third

minor component, which is the smallamount of SGA memory Oracle providesfor internal allocations like fixed SGA (youcan consider this an overhead component).

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:10 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 156: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SGA_TARGET parameter up to the maximum your particular operating system willallow. Note that you may set the value of the SGA_TARGET parameter greater thanSGA_MAX_SIZE at startup time. In this case, Oracle automatically raises the valueof the SGA_MAX_SIZE parameter to match the higher value of the SGA_TARGETparameter.

What is the minimum allowable value for the SGA_TARGET parameter? If youset any of the manually sized components, you can lower the SGA_TARGET valueto the sum of the manually size parameters plus the sizes(s) of any auto-tuned parametersfor which you may have set minimum values. In addition, Oracle takes into accountfactors like the number of CPUs on your server to arrive at the minimum allowablevalue for the SGA_TARGET parameter.

Once you start your instance with a specific SGA_TARGET value, you candynamically switch to a manual memory management mode by simply setting thevalue of the SGA_TARGET parameter to zero using the alter system command.When you do this, the size of the four auto-tuned shared memory components willremain at their present levels. Even if you had started the instance with a specificvalue for some of the auto-tuned components, the current values are the ones thatthe database will continue to assign to those parameters, once you decide to setSGA_TARGET to zero. Of course, if you restart the instance, Oracle will assignthe component values that you specify in the init.ora or the SPFILE.

Although the SGA_MAX_SIZE value acts as the upper limit of the SGA_TARGETparameter, not all operating systems are alike in this regard. On several UNIX platformsthat don’t support dynamic shared memory, Oracle recommends you do not set theSGA_MAX_SIZE parameter, since those platforms use the entire physical memoryspecified by SGA_MAX_SIZE immediately after instance startup. In these cases, itdoesn’t make any sense to set the SGA_TARGET to a value smaller than the valuespecified for the SGA_MAX_SIZE parameter. In other platforms (Oracle specifiesSUN Solaris and Windows as examples), you can limit the total physical SGA useto the value set by the SGA_TARGET parameter.

Oracle recommends that you do not manually set any of the (four)automatically sized components, since it reduces the database’s abilityto adapt to database workload changes.

Let’s say you have the following situation:

SGA_MAX_SIZE=1024MSGA_TARGET=512MDB_CACHE_SIZE=128M

Using Automatic Shared Memory Management 23

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:10 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 157: OCA OCP - Oracle10G New Features For Administrators Exam Guide

24 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

You can raise the SGA_TARGET setting up to a maximum of 1024M. You canlower the SGA_TARGET value, but the DB_CACHE_SIZE value cannot go below128M, since that is the minimum value for this parameter. That is, you can reducethe SGA_TARGET value until one or more of the auto-tuned SGA componentsreach their minimum size.

The SGA_TARGET Parameter and the SGA ComponentsWhen you change the value of the SGA_TARGET parameter, say increase it from600M to 700M, all the manually configured SGA components will retain their oldvalues. Any changes you make to the SGA_TARGET parameter will affect only theautomatically configured SGA components.

The setting of the SGA_TARGET parameter influences the size of the variousSGA components. If you set the SGA_TARGET to zero explicitly, or just omit thisparameter altogether from your init.ora or SPFILE file, you must then configure thefour auto-tuned components yourself—in fact, these components aren’t auto-tunedanymore! You specify sizes for these components in the init.ora (or SPFILE) file, andyou can use the alter system command to adjust their values after the instancestarts up.

Under Automatic Shared Memory Management, Oracle allocates minimumvalues for all four auto-tuned memory components when the instance starts andadjusts them as necessary. For example, suppose that you set SGA_TARGET to 125Mand you don’t manually size any auto-tuned or manually tuned memory components.You can use the V$SGA_DYNAMIC_COMPONENTS view to see the values Oraclecurrently assigns to the auto-tuned components.

SQL> select component,current_size2* from v$sga_dynamic_components

COMPONENT CURRENT_SIZE---------------------------------------------------------------- ------------shared pool 37748736large pool 4194304java pool 4194304DEFAULT buffer cache 75497472KEEP buffer cache 0RECYCLE buffer cache 0DEFAULT 2K buffer cache 0DEFAULT 4K buffer cache 0DEFAULT 8K buffer cache 0DEFAULT 16K buffer cache 0DEFAULT 32K buffer cache 0streams pool 0

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:10 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 158: OCA OCP - Oracle10G New Features For Administrators Exam Guide

OSM Buffer Cache 013 rows selected.SQL>

As you can see, Oracle assigns initial values for all four auto-tuned parametersusing the SGA_TARGET value of 125M. You can also see that all manually sizedcomponents have a value of zero (since no allocations have been made for thesecomponents in the example).

Oracle doesn’t recommend that you set any of the auto-tuned parameters,as it reduces the ability of Oracle to optimally allocate the SGA among thevarious components.

If you look in the V$PARAMETER view, you may see different values for the auto-tuned parameters. The values shown in that view are the minimum values of theseparameters, not the actual current values.

Let’s briefly review the important points regarding setting the sizes of the SGA_TARGET parameter and the components of the SGA when you use AutomaticShared Memory Management.

■ You can increase the size of the SGA_TARGET parameter until you reachthe SGA_MAX_SIZE parameter’s value.

■ If you increase the size of SGA_TARGET, you can allocate the additionalmemory only among the auto-tuned parameters.

■ If you decrease the size of SGA_TARGET, Oracle will reduce the size of oneor more of the auto-tuned parameters. Oracle will not change the size of themanually tuned SGA components.

■ You can reduce the SGA_TARGET parameter’s size until you reach the minimumsize for any of the auto-tuned components. You may specify this minimum size,or Oracle may specify it based on the number of CPUs and other factors.

■ If you dynamically disable automatic SGA management (by setting SGA_TARGET=0), the value of the auto-tuned parameters will not be set to zero.These parameters will retain their current values. If the current values arehigher than any manually set minimums, the current values, not the minimumvalues set in the initialization files, will prevail.

■ If you assign a minimum value for the auto-tuned components, that will actas the lower bound for the SGA_TARGET parameter.

Using Automatic Shared Memory Management 25

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:10 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 159: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ If you don’t specify a minimum value for an auto-tuned SGA component,you’ll see zero values for this parameter in the V$PARAMETER view. Thedefault value of the four auto-tuned parameters is zero. In addition, the valueof the ISDEFAULT column will be TRUE.

■ If you specify a minimum value for any auto-tuned parameter, you’ll see thatvalue in the V$PARAMETER view.

■ If you decrease the size of any manually tuned component, Oracle will givethe additional memory released to one or more auto-tuned components.

■ If you increase the size of any manually tuned components, memory is reducedfrom one or more auto-tuned components.

■ If you dynamically increase the size of one of the auto-tuned parameters, thecomponent’s size goes up immediately; the additional memory comes fromone of the other auto-tuned components. On the other hand, if you decreasethe size of one of the auto-tuned components, the component’s size will notgo down. The component’s size stays at the current level and will go downonly if Oracle deems it is good to lower the size later on.

SPFILE and Automatic Memory ManagementYou can store your initialization parameters in the traditional init.ora file or the newerparameter file, SPFILE. Oracle recommends that you use the SPFILE because of theinherent benefits that come with its use. Automatic Shared Memory Management isa good example of why the SPFILE is a superior way of managing your initializationparameters, compared to the init.ora file.

Under Automatic Shared Memory Management, the database determines theideal allocations of memory for the four automatic components. It does this withthe help of internal algorithms that continually analyze the nature of the databaseworkload. After you first incorporate Automatic Shared Memory Management,Oracle doesn’t know the ideal levels for these components. It arrives at these aftera period of gradual calibration based on the nature of your workload.

What happens if you shut down the database instance? Well, if you are using theinit.ora file for specifying your initialization parameters, Oracle must go through thelaborious process of analyzing the workload again. If you use the SPFILE instead,Oracle remembers the sizes of the four auto-tuned parameters across the instanceshutdown. Thus, when you restart the instance, you won’t start from scratch; Oraclewill start with the values the auto-tuned memory parameters had before you shut downthe instance.

26 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:11 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 160: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Use the SPFILE (rather than the init.ora file) if you want Oracle to rememberthe sizes of the automatically tuned memory components across an instanceshutdown.

Automatic SGA Management with OEM Database ControlYou can use the OEM Database Control to configure Automatic Shared MemoryManagement in your database, using the following steps:

1. Click the Administration link in the Database Control home page.

2. Under the Instance heading, click the Memory Parameters button.

3. Select Enable as your choice for the Automatic Shared Memory Managementoption.

Figure 3-1 shows the Database Control page for modifying the SGA managementoptions.

Using Automatic Shared Memory Management 27

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

FIGURE 3-1 Using the Database Control for specifying SGA management options

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:11 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 161: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CERTIFICATION OBJECTIVE 3.03

Using Automatic Optimizer Statistics CollectionIn an Oracle database, the query optimizer plays a critical role in executing SQL statementsin the most efficient manner, using the least resources. You can execute a given SQLstatement in several ways, and it is the query optimizer’s job to provide the databasewith the fastest and most efficient way to perform a database query.

To arrive at the “best” plan of execution for any SQL statement, the optimizer firstlooks at the available access paths, join orders, and so on, and selects several candidateexecution plans for the query. Next, it figures out the cost of the alternative executionplans, based on their usage of I/O, CPU, and memory. For this step, the optimizeruses optimizer statistics—crucial statistics that tell the optimizer about the datadistribution and storage characteristics of tables and indexes in the database. Finally,it compares the cost of the alternative plans and picks the one with the least cost.

Oracle recommends that you let the database collect optimizer statisticsautomatically.

The optimizer relies on details about various objects to figure out the best planof execution, which usually is the execution plan with the least cost (I/O and CPUcost mostly). The statistics that the Oracle optimizer relies on are called optimizerstatistics, which include the following items:

■ Table statistics, like the number of rows in a table and the average row length

■ Column statistics, like distinct values in a column and data distribution patterns

■ Index statistics include the number of levels in the index B-Trees

■ System statistics, including CPU and I/O performance

Oracle stores all of these optimizer statistics in its data dictionary for the optimizer’suse. Since tables and indexes may change constantly in terms their data and otherproperties, it is essential that you regularly refresh the optimizer statistics so they donot become stale, and thus misleading.

Prior to Oracle8i, DBAs relied on the analyze table statements to gatherstatistics for the Oracle optimizer. In Oracle8i, you had access to the new DBMS_STATSpackage, which made the job of collecting statistics easier and more comprehensive.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

28 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:11 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 162: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You used the DBMS_STATS package to collect the latest statistics for cost-basedoptimization. Even with the availability of the DBMS_STATS package, it was stillyour responsibility, as a DBA, to schedule the statistics collection jobs.

As you are aware, the Oracle optimizer cannot function correctly if you don’t feedit correct and up-to-date statistics. Poor statistics mean nonoptimal execution plans,leading to degradation in query performance. In Oracle Database 10g, for the firsttime, you can automate the optimizer statistics collection process by allowing Oracleto collect the statistics for you.

Before we go into the details of how automatic statistics collection works, rememberthat statistics collection is just one part of query optimization. The choices you makeregarding the optimizer mode and any optimizer hints that you may use have a

significant bearing on the query optimizer’sbehavior. Thus, you need to focus on threethings—the optimizer mode, optimizer hints,and the collection of optimizer statistics—inorder to set up efficient query optimization.Let’s first quickly review the concepts of optimizermode and optimizer hints, before going on todiscuss how Oracle automatically collects theoptimizer statistics for you.

Optimizer Mode and HintsIn Oracle Database 10g, you can set the following goals for the query optimizer, usingthe initialization parameter OPTIMIZER_MODE:

■ ALL_ROWS This is the default value. Using the ALL_ROWS goal willensure the best throughput, which means it will minimize resource use.When you use the ALL_ROWS setting, Oracle uses a cost-based strategyfor all SQL statements in the session, regardless of the presence of statistics.The ALL_ROWS setting will lead to the selection of an execution plan thatwill return the full result set quickly.

■ FIRST_ROWS_n This value will ensure the minimization of response timefor returning the first n rows in the query output. Oracle uses a cost-basedapproach regardless of the presence of optimizer statistics.

Using Automatic Optimizer Statistics Collection 29

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

If you set the initializationparameter STATISTICS_LEVEL to BASIC,you disable the monitoring feature, andthus turn off the automatic collection ofoptimizer statistics.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:11 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 163: OCA OCP - Oracle10G New Features For Administrators Exam Guide

FIRST_ROWS_n will get something back quickly, although it may take longerto retrieve the full set of data. Therefore, the FIRST_ROWS setting will favorthe use of indexes.

■ FIRST_ROWS If you use this value, Oracle will use a combination ofheuristics (rules of thumb) and a cost-based approach to get you the firstfew rows in the query output. Note that the FIRST_ROWS setting existsonly for backward compatibility. Oracle recommends that you use theFIRST_ROWS_n setting instead.

The OPTIMIZER_MODE settings determine the way the query optimizer willperform optimization throughout the database. However, at times, due to lack ofaccurate statistics, the optimizer can be mistaken in its estimates, leading to poorexecution plans. In cases like this, you can override this database optimizationsetting at the individual SQL statement level, by using optimizer hints. OracleDatabase 10g also provides the new SQL profile feature, which enables you to collectauxiliary information using sampling and partial execution techniques, thereby avoidingthe use of optimizer hints. Chapter 5 discusses the SQL profile feature in detail.

Now that we have reviewed optimizer modes and optimizer hints, let’s turn to adiscussion of the last factor that determines how a query optimizer works—optimizerstatistics collection.

How Automatic Optimizer Statistics Collection WorksRemember that regular collection of statistics is vital for the Optimizer to producecorrect and efficient execution plans. Oracle Database 10g introduces automaticoptimizer statistics collection, and Oracle recommends that you let the databaseautomatically gather the statistics rather than manually collect statistics yourself.

It’s very easy to enable automatic statistics collection in Oracle Database 10g—Oracle automatically starts collecting statistics when you create the database. Allyou need to do to make sure the automatic statistics collection process works is toensure that the STATISTICS_LEVEL initialization parameter is set to TYPICALor ALL. Oracle will use the DBMS_STATS package to collect optimizer statisticson an automatic basis.

We’ll look at how Oracle sets up the automatic statistics collection process inthe following sections.

30 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:11 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 164: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using the Scheduler to Run DBMS_GATHER_STATS_JOBOracle automatically creates a database job called GATHER_STATS_JOB at databasecreation time. You can verify that this automatic statistics collection job exists by runningthe following query:

SQL> select job_name2 from dba_scheduler_jobs3* where job_name like 'GATHER_STATS%';

JOB_NAME-----------------------------------------GATHER_STATS_JOBSQL>

Oracle schedules the GATHER_STATS_JOB job for automatic execution usingthe new Scheduler tool. In Oracle Database 10g, the Scheduler replaces and enhancesthe old job scheduling capability that used the DBMS_JOBS package, and I explainit in detail in Chapter 7.

The Oracle Scheduler has two default operation windows:

■ The weeknight window covers the time between 10:00 P.M. and 6:00 A.M.,Monday through Friday.

■ The weekend window covers the time between 12:00 A.M. Saturday and12:00 A.M. Monday.

Together, the weeknight and the weekend windows are known as the maintenancewindow. Of course, you can change the default timings of the maintenance windowas necessary. Oracle automatically schedules the GATHER_STATS_JOB job to runwhen the maintenance window opens. Even if the job doesn’t complete before themaintenance window is over, the job will run to completion.

If you want to stop the automatic gathering of statistics, you may do so by disablingGATHER_STATS_JOB, as shown here:

SQL> begin2 dbms_scheduler.disable('gather_stats_job');3 end;4 /

PL/SQL procedure successfully completed.SQL>

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

Using Automatic Optimizer Statistics Collection 31

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:12 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 165: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The GATHER_STATS_JOB job calls the procedure DBMS_STATS.GATHER_DATABASE_STATS_JOB_PROC to gather the optimizer statistics. The job collectsstatistics only for objects that fall into one of the following classes:

■ Objects with missing statistics

■ Objects with stale statistics

The GATHER_DATABASE_STATS_JOB_PROC procedure is similar to theGATHER_DATABASE_STATS procedure of the DBMS_STATS package. Thesignificant difference is that GATHER_DATABASE_STATS_JOB_PROC setspriorities based on the DML activity in each table. The procedure will analyze theobjects that have had the most DML first, so that even if it doesn’t finish beforethe window closes, the tables that require new statistics the most will have beenanalyzed.

Using the Database Control to Managethe GATHER_STATS_JOB ScheduleYou can use the OEM Database Control to change the current schedule of the GATHER_STATS_JOB schedule. Here are the steps:

1. From the Database Control home page, click the Administration tab.

2. Go to the Scheduler Group and click the Windows Link

3. Click the Edit button. You’ll then be able to edit the weeknight or theweekend window timings.

Figure 3-2 shows the Scheduler Windows page of the Database Control, whereyou can modify your operating windows for the Scheduler utility.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

32 Chapter 3: Automatic Database Management

Remember that theGATHER_STATS_JOB job collects statisticsfor an object only if there are no statisticsfor that object or if the collected statistics

have become stale. Oracle considersstatistics as being stale when the databasemodifies a significant proportion, usually 10percent of a table’s rows.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:12 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 166: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using Automatic Optimizer Statistics Collection 33

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

Table MonitoringOracle Database 10g uses an automatic table-monitoring mechanism (enabled bydefault when STATISTICS_LEVEL is set to TYPICAL or ALL) to determinewhether a database object needs fresh statistics. Suppose that there are no changesin any table data in your database over a certain period. In this case, all the previouslycollected table statistics are still up-to-date, and you don’t need to collect statisticsagain for this table. On the other hand, if a table is going through numerous update,insert, and/or delete operations after the statistics are collected, the statistics are saidto become stale, since they don’t represent the true distribution of data in the table.

You cannot use the ALTER_DATABASE_TAB_MONITORING and ALTER_SCHEMA_TAB_MONITORING procedures of the DBMS_STATS package to turn tablemonitoring on and off at the database and schema level, respectively, because thesesubprograms are deprecated in Oracle Database 10g. Oracle now automatically performsthe functions previously taken care of by these subprograms.

FIGURE 3-2 The Scheduler Windows page of the OEM Database Control

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:12 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 167: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Manual Collection of Optimizer StatisticsOracle Database 10g also allows you to gather statistics manually using the DBMS_STATS package. The following are some situations when you must use manual ratherthan automatic methods of collecting statistics:

■ When you use external tables

■ When you need to collect system statistics

■ To collect statistics on fixed objects, such as the dynamic performance tables(for dynamic tables, you should use the GATHER_FIXED_OBJECTS_STATSprocedure to collect optimizer statistics)

■ Immediately after you run a bulk load job, since this will make your automaticallycollected statistics unrepresentative

Let’s look at how you can use the DBMS_STATS package to perform several tasksinvolving the collection and management of optimizer statistics.

Using the DBMS_STATS PackageThe DBMS_STATS package helps you view, collect, and modify optimizer statistics.The DBMS_STATS package has the following important procedures:

■ GATHER_TABLE_STATS collects all table statistics.

■ GATHER_INDEX_STATS collects all index statistics.

■ GATHER_SCHEMA_STATS collects statistics for all objects in a schema.

■ GATHER_DATABASE_STATS collects statistics for all database objects.

■ GATHER_DICTIONARY_STATS collects statistics for all data dictionaryobjects.

■ GATHER_SYSTEM_STATS collects system statistics.

Here’s a simple example showing how to use the DBMS_STATS package to collectan entire schema’s statistics:

EXECUTE DBMS_STATS.GATHER_SCHEMA_STATS ('SALAPATI', DBMS_STATS.AUTO_SAMPLE_SIZE);

In the example, the AUTO_SAMPLE_SIZE parameter instructs Oracle to determinethe ideal sample size for each object, based on its size and other characteristics. Bysetting the OPTIONS parameter (not shown in this example) to GATHER_STALE

34 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:12 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 168: OCA OCP - Oracle10G New Features For Administrators Exam Guide

or GATHER_AUTO, you can ensure that Oracle collects new statistics whenever itencounters stale statistics for objects. (Note that GATHER_AUTO is the same asGATHER_EMPTY plus GATHER_STALE.)

You can also use the DBMS_STATS package to delete, import, restore, and setoptimizer statistics that you have previously collected.

How often should you execute the DBMS_STATS package to collect statistics?If your database performs only a small amount of DML activities, you may collectstatistics at relatively longer intervals, say weekly or monthly. However, if yourdatabase objects go through constant change on a daily basis, you need to schedulethe statistics collection jobs much more frequently, say daily or even more often.One of the best Oracle Database 10g new features is that with the combination ofGATHER_AUTO, AUTO_SAMPLE_SIZE, and scheduled GATHER_DATABASE_STATS_JOB procedure, you can just let Uncle Oracle decide what and how muchto analyze, analyzing the important objects first.

Handling Volatile Tables by Locking StatisticsLet’s say you have a table that is truncated a few times during the day, each timegetting new rows by way of fresh data insertions. Also, let’s suppose you have anothertable that is subject to numerous deletions throughout the day. Let’s assume you havea nightly Scheduler job that performs automatic statistics collection. Clearly, in thecases I just described, the nightly statistics collection for these tables would be, in alllikelihood, somewhat unrepresentative. What do you do under such circumstances?

Oracle Database 10g’s solution is to let you “lock” optimizer statistics for tablesand schemas—in essence, freezing the most representative optimizer statistics, so

the optimizer always uses these, rather than theunrepresentative statistics caused by excessiveinsert and delete operations. When you lockstatistics in this manner, you prevent theautomatic collection of statistics for the lockedobjects or schema. Thus, the statistics you’velocked will always be seen as the true statisticsfor the table, regardless of data changes.

Use the following procedures in the DBMS_STATS package to lock and unlocktable and schema statistics.

■ LOCK_TABLE_STATISTICS

■ UNLOCK_TABLE_STATISTICS

Using Automatic Optimizer Statistics Collection 35

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

When you lock a table’sstatistics, Oracle automatically locks allthe related statistics, such as columnstatistics and index statistics, as well.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:12 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 169: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ LOCK_SCHEMA_STATISTICS

■ UNLOCK_SCHEMA_STATISTICS

Here’s an example where I lock the statistics for the test table in my schema:

SQL> execute DBMS_STATS.LOCK_TABLE_STATS('salapati','test');PL/SQL procedure successfully completed.SQL

If you have a volatile table without any statistics, you can lock the statistics.

You can lock a table with statistics or without statistics, using the LOCK_TABLE_STATS procedure in both cases. You can also override statistics locking if necessary.

Locking Tables Without Statistics You can lock a table without any statistics,by setting the statistics of a table to NULL. To set the statistics to NULL, you need tofirst delete any existing statistics, and then lock the table. Here’s how to do this:

BEGINDBMS_STATS.DELETE_TABLE_STATS('HR','EMPLOYEES');DBMS_STATS.LOCK_TABLE_STATS('HR',' EMPLOYEES');

END;/

The LOCK* procedures either freeze the current statistics in place or keep thestatistics NULL (no collection of statistics will take place after deleting thecurrent statistics).

Locking Tables with Statistics Instead of setting statistics to NULL whenyou lock a table, you can always save the same set of statistics, regardless of anytable row insert or delete operations. If you have a set of statistics that you considerrepresentative of the table when it’s fully loaded, you can lock the table with thesestatistics in place, thus preventing the excessive insertions and deletions fromskewing the optimizer statistics. In this case, use just the LOCK_TABLE_STATSprocedure, as shown in the following example.

BEGINDBMS_STATS.LOCK_TABLE_STATS('HR',' EMPLOYEES');

END;

36 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:12 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 170: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using Automatic Optimizer Statistics Collection 37

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

Overriding Statistics Locking In some cases, you may want Oracle to overrideany existing locks you have imposed on the optimizer statistics. You can do so by usingthe new FORCE argument with several procedures in the DBMS_STATS package.For the following procedures, the default is FORCE=FALSE. When you set FORCE=TRUE, they will behave as follows:

■ DELETE_SCHEMA_STATS will delete the statistics even if they are locked.

■ IMPORT_SCHEMA_STATS will ignore the statistics lock and importstatistics anyway.

■ RESTORE_SCHEMA_STATS will restore statistics even if they are locked.

■ SET_SCHEMA_STATISTICS will set the values even if the statisticsare locked.

Restoring Historical Optimizer StatisticsSuppose your newly collected optimizer statistics disappoint you, and you think an olderversion of the statistics was giving you a lot better performance. What do you do undersuch circumstances?

Fortunately, Oracle lets you automatically save all old statistics whenever yourrefresh the statistics. Thus, it’s a simple matter to ask Oracle to revert to using anolder set of “good” statistics. You can restore any type of statistics by using the

appropriate RESTORE_*_STATS procedure.For example, the RESTORE_TABLE_STATSprocedure is used to restore table statistics.Similarly, the RESTORE_DICTIONARY_STATS procedure helps you restore an olderversion of the dictionary table statistics. Oraclealso has procedures for restoring statistics at theschema, database, and system levels.

Two database views are critically useful when you want to restore older statistics:DBA_OPTSTAT_OPERATIONS and DBA_TAB_STATS_HISTORY. The DBA_OPTSTAT_OPERATIONS view contains a history of all optimizer statistics collections,as shown in the following query:

SQL> select operation,end_time2 from dba_optstat_operations;

You can’t restore anystatistics you collect using the analyzecommand. You also can’t restore any user-defined statistics.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:12 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 171: OCA OCP - Oracle10G New Features For Administrators Exam Guide

OPERATION END_TIMEgather_database_stats(auto) 19-APR-04 10.04.59.321000 PM -05:00set_system_stats 19-APR-04 01.44.53.098000 PM -05:00set_system_stats 19-APR-04 01.44.53.769000 PM -05:00set_system_stats 19-APR-04 01.44.53.832000 PM -05:00SQL>

The DBA_TAB_STATS_HISTORY view contains a record of all changes made totable statistics. By default, the DBA_TAB_STATS_HISTORY view saves the statisticshistory for 31 days. Therefore, you can restore statistics to any time within the previous31 days.

How long can you retain old statistics? As just stated, by default, Oracle willsave your statistics for a period of 31 days. However, by using the ALTER_STATS_HISTORY_RETENTION procedure of the DBMS_STATS package, you can changethe default value of the statistics history retention interval.

If you have set your STATISTICS_LEVEL parameter to TYPICAL or ALL, Oraclewill automatically purge the old statistics. To perform a manual purge of the statistics,you need to use the PURGE_STATS procedure of the DBMS_STATS package.

CERTIFICATION OBJECTIVE 3.04

Using Automatic Undo Retention TuningOracle databases use undo records to save the actions of transactions. Oracle refersto the records collectively as undo. Oracles uses the undo information to roll back, orundo, a transaction if necessary. For example, you may have inserted or deleted data,but now you want to roll back the changes to return the database to how it was beforeyou made the change.

Undo data can help you perform key tasks like the following:

■ Perform a rollback when you don’t want to commit changes

■ Provide read consistency, by preserving the before image of data so a user seesa consistent view of data, even when another user is changing the same data

■ Aid during a database recovery process, by undoing any uncommittedchanges applied to datafiles by the redo logs

■ Facilitate the flashback features that rely on undo information to function

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

38 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:12 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 172: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using Automatic Undo Retention Tuning 39

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

Until the Oracle9i database, Oracle used rollback segments to manage undoinformation. Rollback segments are complex to administer, with segments encounteringthe dreaded ORA-1555 (snapshot too old) errors on a regular basis during longtransactions. While Oracle Database 10g still enables you to use traditional rollbacksegments, that feature has been deprecated in this version. In Oracle Database 10g,

you can use either a manual mode of undomanagement (involving rollback segments), orAutomatic Undo Management (AUM). Oraclerecommends, however, that you use the AUMfeature, wherein Oracle will be in charge ofmaintaining the undo segments. You don’t havethe headaches of managing rollback segmentsanymore. In addition, you can now control theamount of time the database retains importantundo information before it overwrites the data.

Automatic Undo Management ConfigurationTo enforce Automatic Undo Management, you need to configure the followinginitialization parameters:

■ UNDO_MANAGEMENT The default value for this parameter is MANUAL,which means you are going to use the traditional rollback segments tomanage undo. If you want to use Automatic Undo Management, you needto specify AUTO as the value for this parameter.

■ UNDO_TABLESPACE If you choose Automatic Undo Management, youshould specify a separate tablespace to hold the undo information by usingthis parameter. If you don’t do this, the undo will be stored in the SYSTEMtablespace.

■ UNDO_RETENTION This parameter specifies the duration of time forwhich the database should retain the undo information. The default forthis parameter is 900 seconds.

The UNDO_RETENTION and UNDO_TABLESPACE parameters are crucial formanaging your undo data. On a simple level, it is easy to see what factors willdetermine how you set these parameters. If you have a large amount of undo

If you don’t specify themode of undo management, you will beusing manual undo management, withthe help of rollback segments. This isbecause the default undo managementmode is manual.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:13 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 173: OCA OCP - Oracle10G New Features For Administrators Exam Guide

(because of a large amount of database changes like insert and delete operations),you’ll need a correspondingly large undo tablespace to hold all the undo information.If you have several long-running SQL queries, your undo retention time should becorrespondingly long.

The Undo AdvisorThe easiest way to manage undo activity is to access the Undo Advisor from theOEM Database Control. You can get to the Undo Advisor page by clicking the UndoManagement link on the Advisor Central page of the OEM Database Control. Onceyou are on the Undo Management page, you can set parameters for undo management.You can perform the following undo management tasks from the Database Controlinterface:

■ Enable/disable Automatic Undo Management

■ Specify/modify undo tablespaces

■ Ask for undo tablespace size recommendations

■ Ask for undo retention period recommendations

■ Experiment with alternative undo retention period settings

You can use the Undo Advisor to help you configure the optimal undo retentiontime and your undo tablespace size. The Undo Advisor bases its undo managementrecommendations on the following criteria:

■ Longest running query (in minutes)

■ Average undo generation rate (KB/minute)

■ Maximum undo generation (KB/minute)

Undo Tablespace and Undo Retention ManagementUndo management involves managing the undo tablespace and undo retention issues.Let’s look at these undo management issues in the following sections.

Managing the Undo TablespaceOracle provides you two ways of making sure you don’t run out of room for undo inyour undo tablespace.

40 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:13 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 174: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ Oracle alerts you when your undo tablespace is going to run out of space,just as it alerts you about space problems in other tablespaces (for more ontablespace and other alerts, see Chapter 4).

■ Oracle alerts you if your system has long-running queries that may result inthe ORA-1555 (snapshot too old) error.

Managing Undo RetentionOracle automatically tunes the undo retention period by constantly collecting statisticson query length as well as undo generation rate. As noted earlier, the default value ofthe UNDO_RETENTION parameter is 900 seconds. So, even if you don’t explicitly askOracle to retain undo information for a specific period, once you specify the UNDO_MANAGEMENT=AUTO parameter, Oracle will automatically start retaining your undodata for 15 minutes (900 seconds).

Here is how undo retention actually works in practice (assume that you left theundo retention interval at the default value of 900 seconds):

■ If your undo tablespace has enough space, Oracle will retain undo data forat least 900 seconds.

■ If your undo tablespace doesn’t have enough free space, Oracle may choosenot to retain the undo information for 900 seconds; that is, Oracle will letnew undo records write over the older records, even before the older recordsare 900 seconds old.

Why does Oracle behave in this way? It will shorten the retention interval whenthere are new DML operations in the database and there isn’t enough free space in theundo tablespace to accommodate these new DML operations. Rather than cause theDML operations to fail due to the lack of undo space, Oracle simply chooses the “lesserevil” of overwriting some of the old redo information.

Using the Retention Guarantee OptionIf you want to absolutely, positively guarantee that Oracle retains the undo informationfor the length of time you chose by specifying the UNDO_RETENTION parameter’svalue, you can do so by using a new Oracle Database 10g feature: retention guarantee. Bydefault, Oracle disables the retention guarantee feature. You can enable the guaranteefeature at database creation time, at the undo tablespace creation time, or by using thealter tablespace command.

Using Automatic Undo Retention Tuning 41

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:13 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 175: OCA OCP - Oracle10G New Features For Administrators Exam Guide

42 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

You can check the current retention setting for your undo tablespace by issuingthe following query:

SQL> select tablespace_name,retention2 from dba_tablespaces;

TABLESPACE_NAME RETENTION-------------------------------------------SYSTEM NOT APPLYUNDOTBS1 NOGUARANTEESYSAUX NOT APPLY…SQL>

The NOGUARANTEE value under the retention column for the UNDOTBS1tablespace shows the default value of the UNDO_RETENTION parameter. By default,there is no guarantee of undo retention. You can guarantee undo retention for theUNDOTBS1 tablespace by using the following command:

SQL> alter tablespace UNDOTBS1 retention guarantee;Tablespace altered.SQL>

If you wish to enforce the retention guarantee feature right from the beginning,you can create your undo tablespace with this feature built in, as shown here:

SQL> create undo tablespace new_undodatafile ‘C:\oracle\product\10.1.0\data\new_iundo_01.dbf'size 10M autoextend onretention guarantee;

Does Automatic UndoManagement mean that you don’t need toworry about the usual ORA-1555 (snapshottoo old) errors, because Oracle reuses undosegments with unexpired undo data? Well,it all depends on how much space there isin your undo tablespace. If the availablefree space is the undo tablespace isn’tenough for your transaction-activity levels,Oracle may overwrite unexpired undo data,causing the snapshot too old errors. The

only way to eliminate this error is to usethe RETENTION GUARANTEE clause, whichguarantees that Oracle will never overwriteany undo data that is within the undoretention period. One of the main reasonswhy you may use the retention guaranteefeature is to enable the success of flashbackfeatures in your database, which dependcritically on the retention of necessary undoinformation.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:13 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 176: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using Automatic Undo Retention Tuning 43

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

If you specify the RETENTION GUARANTEE clause, you run the risk of yourDML operations failing due to lack of undo space. Therefore, don’t use thisclause unless you must guarantee the availability of undo data (for example,for the flashback query feature).

CERTIFICATION SUMMARYIn this chapter, you first learned about the AWR and how it collects database

performance statistics in the form of regular snapshots. Then you learned how theADDM uses these snapshots to automatically analyze database performance andmake recommendations to improve it if necessary.

The chapter introduced you to the new Automatic Shared Memory Managementfeature and the use of the SGA_TARGET initialization parameter. You learned abouthow Oracle can automatically manage the four auto-tuned parameters.

You learned about how Oracle Database 10g can automatically gather key optimizerstatistics for you. You reviewed the Automatic Undo Management feature and learnedthe role of the parameters UNDO_TABLESPACE and UNDO_RETENTION. Finally,you learned about the new undo retention guarantee feature, which lets you ensurethe retention of undo data.

In the Automatic Shared Memory Managementsection, you must clearly understand which arethe automatically tunable and the manuallytunable SGA components. You must also knowthe background process that coordinates thesizing of the memory components. What isthe difference between the behavior of theSHARED_POOL_SIZE component inOracle Database 10g and in the olderversions of Oracle?

There will be a couple of questionson the AWR and the ADDM. You must

understand the new time model and theimportance of the DB time metric. Whatare the different ways in which you can getan ADDM report? How do you get ADDMreports for custom intervals? What does anADDM report contain?

Expect a question regarding the automaticcollection of optimizer statistics by Oracle.How does Oracle prioritize its statisticscollection? What procedure do you useto restore older optimizer statistics?

INSIDE THE EXAMINSIDE THE EXAM

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:13 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 177: OCA OCP - Oracle10G New Features For Administrators Exam Guide

✓TWO-MINUTE DRILL

Using the Automatic Database Diagnostic Monitor (ADDM)❑ The Automatic Workload Repository (AWR) collects database performance

statistics on a regular basis and stores them in the SYSAUX tablespace.

❑ By default, the AWR collects its snapshots on an hourly basis and stores themfor a period of seven days.

❑ The ADDM uses the new time statistics model to analyze database performance.

❑ The V$SYS_TIME_MODEL and V$SESS_TIME_MODEL views show thetime statistics on a system and session level, respectively.

❑ The key time model metric, DB time, covers the actual time spent processinguser database calls.

❑ The main goal of the ADDM tool is to reduce the DB time metric.

❑ The ADDM addresses the root causes of performance problems, not justsymptoms.

❑ The AWR automatically purges the old snapshots after the default intervalof seven days.

❑ The ADDM may recommend changes in I/O or memory, as well as databaseand application configuration.

❑ The ADDM may also recommend the invocation of other managementadvisors in order to analyze a problem in depth.

❑ The MMON background process helps manage the ADDM and schedulesthe ADDM.

❑ Oracle enables ADDM by default. Just make sure to set the STATISTICS_LEVEL initialization parameter to TYPICAL or ALL.

❑ By adjusting either or both of two variables—snapshot interval and dataretention period—you can control the amount of data that AWR maintains.

❑ The DBIO_EXPECTED parameter indicates how fast your I/O system performs.

❑ You may use the DBMS_ADVISOR package to change the default value of theDBIO_EXPECTED parameter.

❑ You can view the ADDM analysis reports in three different ways: through theDatabase Control, through SQL statements, and with the help of databasepackages.

44 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:13 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 178: OCA OCP - Oracle10G New Features For Administrators Exam Guide

❑ The easiest way to view the ADDM reports is through the OEM DatabaseControl.

❑ You can obtain ADDM reports by using the SQL script addmrpt.sql.

❑ The ADDM reports have three main components: impact, findings, andrecommendations.

❑ You need the ADVISOR privilege to use the DBMS_ADVISOR package,which helps you manage the ADDM.

❑ The GET_TASK_REPORT procedure of the DBMS_ADVISOR packageenables you to produce ADDM reports.

Using Automatic Shared Memory Management❑ To use the Automatic Shared Memory Management feature, you must set

the STATISTICS_LEVEL parameter to TYPICAL or ALL.

❑ There are two sets of SGA parameters: auto-tuned and manually sized.

❑ The auto-tuned set of parameters consists of the buffer cache, shared pool,large pool, and Java pool.

❑ The default value of the SGA_TARGET parameter is zero.

❑ To automate SGA management, set the SGA_TARGET to a value greaterthan zero.

❑ Oracle subtracts the value of the manually sized parameter (and the fixedSGA) from the SGA first. It allocates the remainder of the SGA to thefour auto-tuned parameters.

❑ The default values of all four auto-tuned parameters are zero.

❑ You can dynamically increase or decrease the value of the SGA_TARGETparameter.

❑ The SGA_MAX_SIZE parameter sets the limit on how high you can setSGA_TARGET.

❑ Even under automatic SGA management, you can set the sizes for the fourindividual auto-tuned parameters.

❑ Oracle recommends that you don’t set any auto-tuned parameters yourself.

❑ Use the SPFILE if you want Oracle to remember the sizes of auto-tunedparameters across instance shutdowns.

Two-Minute Drill 45

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:13 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 179: OCA OCP - Oracle10G New Features For Administrators Exam Guide

46 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

Using Automatic Optimizer Statistics Collection❑ Oracle enables automatic optimizer statistics collection by default.

❑ You must set the STATISTICS_LEVEL parameter to TYPICAL or ALLto use Oracle’s automatic optimizer statistics collection capability.

❑ Oracle uses the GATHER_STATS_JOB job to run the automatic statisticscollection process.

❑ The GATHER_STATS_JOB job collects statistics only if they are stale ornot available.

❑ The Scheduler runs the GATHER_STATS_JOB job during the maintenancewindow.

❑ The database uses the table-monitoring feature to decide whether it shouldcollect new statistics.

❑ You can lock table and schema statistics using the LOCK_TABLE_STATISTICS and LOCK_SCHEMA_STATISTICS procedures fromthe DBMS_STATS package.

❑ If you lock a table’s statistics, Oracle locks all associated statisticsautomatically as well.

❑ You can lock a table without statistics, by setting the statistics to NULL.

❑ Use the FORCE argument to override any locks on statistics.

❑ You can restore any old statistics by using the RESTORE_*_ proceduresof the DBMS_STATS package.

❑ By default, Oracle saves optimizer statistics for 31 days.

Using Automatic Undo Retention Tuning❑ Oracle uses manual undo management by default.

❑ Set UNDO_MANAGEMENT=AUTO to use Automatic Undo Management.

❑ The default value for the UNDO_RETENTION parameter is 900 seconds.

❑ If you run out of fresh room in the undo tablespace, Oracle writes overunexpired undo data.

❑ Use the undo RETENTION GUARANTEE clause to ensure Oracle retainsundo information for the time set by the UNDO_RETENTION parameter.

❑ Your DML operations may fail on occasion if you choose to use the undoRETENTION GUARANTEE clause.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:14 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 180: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test 47

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

SELF TESTThe following questions will help you measure your understanding of the material presented in thischapter. Read all the choices carefully because there might be more than one correct answer. Chooseall correct answers for each question.

Using the Automatic Database Diagnostic Monitor (ADDM)

1. Where does the ADDM save its analysis results?

A. In the OEM repositoryB. In the ADDM tablespaceC. In the SYSTEM tablespaceD. In the SYSAUX tablespace

2. What is the key goal of the ADDM?

A. To reduce DB timeB. To reduce DB idle timeC. To reduce DB active timeD. To reduce throughput

3. In response to a performance bottleneck, what will the ADDM do?

A. Always recommend the use of management advisorsB. Always suggest its own recommendationsC. Sometimes recommend the use of management advisorsD. Propose a single recommendation to fix the problem

4. If your disk read time is 2000 microseconds, what will you need to do?

A. Use the DBMS_ADVISOR package to lower the value of the DBIO_EXPECTED parameterB. Use the DBMS_ADVISOR package to raise the value of the DBIO_EXPECTED parameterC. Use the DBA_ADVISOR package to lower the value of the DBIO_EXPECTED parameterD. Use the Database Control to lower the value of the DBIO_EXPECTED parameter

5. To retrieve the ADDM reports using SQL, what do you need to do?

A. Run the addmrpt.sql SQL scriptB. Use the DBA_ADDM viewC. Use the DBA_ADVISOR viewD. Use the DBMS_ADDM package

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:14 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 181: OCA OCP - Oracle10G New Features For Administrators Exam Guide

48 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

Using Automatic Shared Memory Management

6. To enable Automatic Shared Memory Management, what does the DBA need to do?

A. Set the STATISTICS_LEVEL parameter to BASICB. Set the STATISTICS_LEVEL parameter to TYPICAL or ALL and set SGA_TARGET_

SIZE to a nonzero valueC. Set the STATISTICS_LEVEL parameter to TYPICAL or ALL and remove the SGA_

TARGET parameterD. Set the STATISTICS_LEVEL parameter to TYPICAL or ALL and set SGA_TARGET

to zero

7. If you set the value of the SGA_TARGET parameter higher than the value of the SGA_MAX_SIZE parameter at instance startup, what will happen?

A. The instance will not start.B. SGA_TARGET will become equal to the SGA_MAX_SIZE value.C. The database will ignore the SGA_TARGET parameter.D. SGA_MAX_SIZE is automatically raised, so it is equal to the SGA_TARGET value.

8. In order to turn off automatic SGA management, what should the DBA do?

A. Set the SGA_MAX_SIZE parameter to zeroB. Set the SGA_TARGET parameter to zeroC. Set the SGA_TARGET parameter equal to the SGA_MAX_SIZE parameterD. Remove the SGA_MAX_SIZE parameter

9. You are using automatic SGA management, with SGA_TARGET set at 500M. If you setthe DB_KEEP_CACHE_SIZE to 100M, approximately how much of the SGA memorycan Oracle assign to the auto-tuned parameters?

A. 500MBB. 600MBC. 400MBD. Oracle cannot assign any memory to the auto-tuned parameters under the given circumstances.

10. If you set the sizes of all four auto-tuned parameters, which of the following is true?

A. You can’t use the Automatic Shared Memory Management feature.B. Oracle can raise the sizes of the parameters under Automatic Shared Memory Management.C. Oracle can lower the sizes of the parameters under Automatic Shared Memory

Management.D. Oracle can raise the sizes of the parameters under manual shared memory management.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:14 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 182: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

Using Automatic Optimizer Statistics Collection

11. How do you verify that the automatic statistics collection job is running?

A. Query the DBA_JOBS viewB. Query the DBA_SCHEDULER_JOBS viewC. Query the DBA_SCHEDULER viewD. Query the GATHER _DATABASE_STATS_JOB_PROC view

12. When should the DBA consider locking table statistics?

A. When the table’s data is extremely stableB. When the table’s data is extremely volatileC. When the table’s data changes by less than 10 percent on a regular basisD. When the table is never truncated

13. In order to override the locking of statistics, what should you use?

A. DBMS_STATS.DELETE_STATS procedureB. DBMS_STATS.IMPORT_SCHEMA_STATS procedureC. DBMS_STATS.DELETE_STATS procedure with the OVERRIDE optionD. DBMS_STATS.DELETE procedure with the FORCE option

14. By default, the DBA_TAB_STATS_HISTORY view saves statistics history for how long?

A. 31 daysB. 30 daysC. 1 hourD. 7 days

15. What does the LOCK_* procedure of the DBMS_STATS package help you do?

A. Lock current statisticsB. Make current statistics NULLC. Override current statistics with the latest statisticsD. Lock statistics from a previous period

Using Automatic Undo Retention Tuning

16. If you use the retention guarantee feature, you are guaranteeing that the database will neverdo what?

A. Overwrite unexpired undo dataB. Overwrite expired undo data

Self Test 49

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:14 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 183: OCA OCP - Oracle10G New Features For Administrators Exam Guide

50 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

C. Overwrite data older that the undo retention periodD. Overwrite data more recent than the undo retention period

17. To ask Oracle to retain undo information for a specific period, what must you do?

A. Use the manual undo management modeB. Specify a certain value for the UNDO_RETENTION parameterC. Use the RETENTION GUARANTEE clauseD. Use the RETENTION NO GUARANTEE clause

17. If you wish to use Automatic Undo Management, you must do which of the following?

A. Specify an undo tablespaceB. Use the retention guarantee featureC. Specify the UNDO_RETENTION parameterD. Set the value of the UNDO_MANAGEMENT parameter to AUTO

18. By default, Oracle retains your undo information for how long?

A. 31 daysB. 15 minutesC. 30 minutesD. 7 days

20. By default, how does Oracle handle undo?

A. Disables the retention guarantee featureB. Enables the retention guarantee featureC. Enables the Automatic Undo Management featureD. Enables the retention guarantee feature for the flashback query feature

LAB QUESTIONYou are currently using manual shared memory management. Your init.ora parameter file looks like this:

db_cache_size=80Mjava_pool_size=10Mlarge_pool_size=10Mshared_pool_size=100M

What do you need to do to switch to Automatic Shared Memory Management? Ensure that yourSGA allocation is the same size as before. Show the answer using the manual SQL*Plus method.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:14 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 184: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SELF TEST ANSWERS

Using the Automatic Database Diagnostic Monitor (ADDM)

1. � D. The ADDM facility stores all its analysis reports in the SYSAUX tablespace, just asthe AWR facility does.� A, B, and C provide wrong destinations for the ADDM reports.

2. � A. Reducing the DB time metric is the fundamental goal of the ADDM.� B and C are misleading answers. D is wrong because the ADDM’s goal is exactly theopposite.

3. � C. When ADDM encounters performance problems, it may propose several recommendationsthat you can directly implement, in addition to making the optional recommendation to runother management advisors.� A is wrong because the ADDM doesn’t necessarily ask you to invoke a managementadvisor. B is wrong since the ADDM may also suggest that you use management advisors.D is wrong since the ADDM doesn’t limit itself to providing a single solution for aperformance problem.

4. � A. By default, ADDM assumes that your DBIO_EXPECTED parameter has a value of10000 microseconds. Since your system disk reading speed is actually lower than this, youmust reset this parameter by lowering the value of the DBIO_EXPECTED parameter.� B is wrong because you need to lower, not raise, the value of the DBIO_EXPECTEDparameter. C is wrong since you can’t use the DBA_ADVISOR package to adjust the DBIO_EXPECTED parameter. D is wrong since you can’t use the Database Control to adjust theDBIO_EXPECTED parameter.

5. � A. To retrieve the ADDM report, you must use the Oracle-supplied addmrpt.sql script.� B is wrong because there is no DBA_ADDM view. C is wrong because the DBA_ADVISORview can’t help you produce an ADDM report. D is wrong because there is no PL/SQL packagenamed DBMS_ADDM.

Using Automatic Shared Memory Management

6. � B. You must set the STATISTICS_LEVEL parameter to TYPICAL or ALL and set theSGA_TARGET parameter to a nonzero value in order for automatic SGA management to comeinto force.� A is wrong since setting the STATISTICS_LEVEL parameter to BASIC ensures that youwon’t have automatic SGA management in your database. C and D are wrong since removing

Self Test Answers 51

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:14 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 185: OCA OCP - Oracle10G New Features For Administrators Exam Guide

52 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

the SGA_TARGET parameter or explicitly setting it to zero mean the same thing, and the defaultvalue of the parameter is zero anyway. Setting the SGA_TARGET parameter to zero means youcan’t use Automatic Shared Memory Management.

7. � D. The value of the SGA_MAX_SIZE parameter will be bumped up to the value of theSGA_TARGET parameter.� A is incorrect since the instance will start without any problem. B is incorrect because itimplies that the value of the SGA_TARGET parameter will be lowered to match the size of theSGA_MAX_SIZE parameter. Actually as answer D indicates, it’s the other way around—theSGA_MAX_SIZE parameter’s value will be raised to match the SGA_TARGET parameter’svalue. C is incorrect since the database doesn’t ignore the higher SGA_TARGET parametervalue, but uses it.

8. � B. If you set the SGA_TARGET parameter value to zero, you’ll disable automatic memorymanagement.� A, C, and D have no bearing on Automatic Shared Memory Management.

9. � C. When you use Automatic Shared Memory Management, Oracle will first deduct thesum of manually sized parameters from the SGA_TARGET parameter. Oracle can assign onlythe remaining memory to the auto-tuned parameters.� A and B are wrong, based on the analysis for the correct answer. D is wrong because youwon’t prevent Oracle from assigning memory to the auto-tuned parameters when you set thesize of one or more manually tuned memory parameters.

10. � B. Even under Automatic Shared Memory Management, you can set the sizes of theindividual auto-tuned components. Oracle will treat this as the minimum values for theseparameters, and can raise them, but won’t be able to lower them.� A is wrong because you can use Automatic Shared Memory Management, even when youset the sizes for one or more auto-tuned parameters. C is wrong because, as the correct answerexplains, Oracle can only raise, not lower, any values you set for the auto-tuned parameters.D is wrong because Oracle cannot change any of the shared memory components when youuse manual shared memory management.

Using Automatic Optimizer Statistics Collection11. � B. The new Scheduler facility runs the GATHER_DATABASE_STATS_JOB_PROC

procedure, belonging to the DBMS_STATS package, to gather optimizer statistics. The jobname is GATHER_STATS_JOB, which Oracle lists in the DBA_SCHEDULER_JOBS view.The new DBA_SCHEDULER_JOBS view is similar to the old DBA_JOBS view, and it providesinformation about all scheduled jobs in the database. You can query this view to see if theGATHER_DATABASE_STATS_JOB_PROC procedure is scheduled for running. The DBA_JOBS view exists in the Oracle Database 10g, but it won’t tell you anything about theautomatically scheduled jobs.

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:14 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 186: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test Answers 53

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

� C and D are wrong because there are no such views. A is wrong because the DBA_JOBSview will not have any information about the new Scheduler facility.

12. � B. You should consider locking down a table’s statistics when a table’s data is extremelyvolatile.� A, C, and D are all reasons why you won’t need to lock down a table’s statistics.

13. � D. Any time you need to override any statistics, you should use the FORCE argument forthe relevant DBMS_STATS package. Therefore, you can figure out that D is the right answer,since it’s the only one that uses the FORCE option.� A, B, and C are wrong since none of these alternatives use the FORCE option.

14. � A. By default, Oracle saves optimizer statistics for 31 days before purging them. You canalways change this default duration.� B, C, and D provide the wrong period.

15. � A. All the LOCK_* procedures enable you to lock current statistics.� B is wrong since the LOCK_* procedures don’t make the statistics NULL. C is wrong sincethe procedures don’t override current statistics. D is wrong because the procedures lock thecurrent statistics, not those from a previous period.

16. � A and D. A is correct because the RETENTION GUARANTEE clause guarantees that you’llnever overwrite unexpired data in the undo segments. D is correct because you won’t overwritedata more recent than the undo retention period.� B is wrong because Oracle may very well overwrite expired undo data, whether or not youuse the RETENTION GUARANTEE clause. C is wrong because there is no guarantee that Oraclewon’t overwrite data older than the data retention period.

Using Automatic Undo Retention Tuning

17. � B. UNDO_RETENTION isn’t really a mandatory parameter when you use Automatic UndoManagement. Even when you don’t specify this parameter, Oracle will automatically use adefault value for the parameter. However, if you wish the database to retain undo informationfor a specific length of time, you must use the UNDO_RETENTION parameter.� A is wrong since using manual undo management isn’t necessary to retain undo informationfor a specific period. C and D are invalid since the retention guarantee and theRETENTION NO GUARANTEE options aren’t necessary to ask Oracle to retain undo informationfor a specific period, the UNDO_RETENTION parameter will suffice for this purpose.

18. � D. You must set the UNDO_MANAGEMENT parameter to AUTO if you want Oracle tomanage the undo information.� A, B, and C are incorrect since you don’t need to specify anything other than the

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:15 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 187: OCA OCP - Oracle10G New Features For Administrators Exam Guide

UNDO_MANAGEMENT=AUTO parameter to use Automatic Undo Management. As importantas they are, all these alternatives mention factors that are optional, not mandatory for AutomaticUndo Management.

19. � B. By default, Oracle retains undo data for 600 seconds (15 minutes).� A, C, and D provide incorrect values.

20. � A. Oracle disables the retention guarantee feature by default. You can enable it by usingthe alter system command, as demonstrated in this chapter.� B is wrong since Oracle disables the option by default. C is wrong since Oracle enables manualundo management by default. D is incorrect since Oracle doesn’t enable the retention guaranteefeature by default for any purpose. Oracle recommends that you use the retention guaranteefeature sparingly, such as only when you use the flashback query feature.

LAB ANSWERFirst, find out the current SGA size using the following command:

SQL> select sum(value) from v$sga;SUM(VALUE)------------------218103808

Next, issue the following command, to switch to Automatic Shared Memory Management:

SQL> alter system set SGA_TARGET=218103808;System altered.SQL>

Although you are now technically using Automatic Shared Memory Management, since you haveset minimum values for all four auto-tuned SGA parameters in your init.ora file, Oracle can’t modifythe sizes of the components. You therefore must set the sizes of all four auto-tuned parameters to zero,by issuing the following set of commands:

SQL> alter system set db_cache_size=0;System altered.SQL> alter system set shared_pool_size=0;System altered.SQL> alter system set java_pool_size=0;System altered.SQL> alter system set large_pool_size=0;System altered.SQL>

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

54 Chapter 3: Automatic Database Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3

P:\010Comp\CertPrs8\862-4\ch03.vpThursday, September 02, 2004 4:49:15 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 188: OCA OCP - Oracle10G New Features For Administrators Exam Guide

4ManageabilityInfrastructure

CERTIFICATION OBJECTIVES

4.01 Types of Oracle Statistics

4.02 The Automatic Workload Repository(AWR)

4.03 Active Session History

4.04 Server-Generated Alerts

4.05 The Automated Tasks Feature

4.06 The Management Advisory Framework

✓ Two-Minute Drill

Q&A Self Test

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4Blind Folio 4:1

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 189: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Oracle Corporation has devoted a substantial amount of effort to making OracleDatabase 10g a truly self-managing database. Self-managing capabilities rely on amanageability infrastructure. This chapter explores several important parts of the

new manageability infrastructure.

In this chapter, you’ll learn more about the Automatic Workload Repository(AWR), which lies at the foundation of Oracle Database 10g’s self-managementcapabilities. You’ll learn how to manage the AWR, by managing the AWR snapshots.

In previous versions of Oracle, you had access to the OEM alert system. Now, inOracle Database 10g, you have an altogether new server-generated alert mechanismto help you manage the database. These server-generated alerts include boththreshold-based and event-based warnings.

The chapter also discusses the new automated tasks feature. You’ll also get anintroduction to the new set of management advisors that comes with the OracleDatabase 10g. The advisory framework is a new approach to managing the database.Now you can turn to these advisors for advice on configuring crucial factors likememory, space, and SQL statement tuning.

The chapter contains the following major sections:

■ Types of Oracle Statistics

■ The Automatic Workload Repository (AWR)

■ Active Session History (ASH)

■ Server-Generated Alerts

■ The Automated Tasks Feature

■ The Management Advisory Framework

CERTIFICATION OBJECTIVE 4.01

Types of Oracle StatisticsOracle DBAs regularly collect several types of performance statistics in order toanalyze database bottlenecks and other performance issues. In Oracle Database 10g,DBAs now have access to several new types of performance statistics. Besides database

2 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 190: OCA OCP - Oracle10G New Features For Administrators Exam Guide

statistics at the system and session levels (wait statistics, segment usage statistics, andso on), these statistics include operating system statistics (CPU statistics, disk usagestatistics, and memory usage statistics) and network statistics as well.

All performance statistics, regardless of their origin—database, operating system,or network—can be classified into several types according to the basis on which youcollect the statistics. Let’s briefly look at the various types of performance statisticsyou can collect in Oracle Database 10g.

Cumulative StatisticsCumulative statistics are the accumulated total value of a particular statistic sinceinstance startup. The statistic total logons, for example, is a cumulative statistic. Oraclecollects cumulative statistics for just about every variable for which it collects statistics.Oracle collects several types of cumulative statistics, including statistics for segmentsand SQL statements, as well as session- and system-wide statistics. By comparing thedelta values—the rates of change of the cumulative statistics between a beginning andan ending period—Oracle analyzes database performance during a specific intervalof time.

You are familiar with the important dynamic performance views V$SYSSTATand V$SESSSTAT. These two views hold many of the important cumulativestatistics for the Oracle database. Dynamic performance views are very useful injudging database performance, but unfortunately, when you shut down the database,the data in the dynamic performance views disappears completely! If you wish totrack database performance over time, or if you wish to compare the performanceimpact of database changes, you need to store the performance data in a repository.This is where the Automatic Workload Repository (AWR) comes in.

The AWR takes the difference between the cumulative data between two periodsand stores this information in its repository. This difference between two periods iscalled an AWR snapshot. By default, the database will take a performance snapshotevery hour, but you can customize this interval.

Database MetricsDatabase metrics are another important type of Oracle performance statistics. You candefine metrics as statistics that measure the rate of change in a cumulative performancestatistic.

In previous Oracle versions, you needed to compute metrics for various performancestatistics by collecting data at various periods, to calculate the rate of change of various

Types of Oracle Statistics 3

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 191: OCA OCP - Oracle10G New Features For Administrators Exam Guide

statistics. Now, Oracle places precomputed metrics at your fingertips. For example,you may be interested in a metric like the number of transactions per second duringpeak time. Dynamic performance views hold these metrics, and the AWR can alsostore them in its repository. All the Oracle management advisors use databasemetrics for diagnosing performance problems and making tuning recommendations.

You can look at statistics such as the number of user transactions and the numberof physical reads in the system as the base statistics from which you derive databasemetrics. Thus, database metrics are derived statistics. The background process MMON(Manageability Monitor) updates metric data on a minute-by-minute basis, aftercollecting the necessary fresh base statistics.

Sample DataThe new Automatic Session History (ASH) feature now automatically collects sessionsample data, which represents a sample of the current state of the active sessions. ASHcollects the data in memory, where you can view it with the help of V$ views. TheAWR helps save the ASH data permanently, by collecting it as part of its regularsnapshots. I discuss the ASH feature in detail later in this chapter, in the “AutomaticSession History” section.

4 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

MMON is a brand-newOracle Database 10g background process.This process performs mostly management-related tasks, including issuing databasealerts and capturing statistics for recentlymodified database objects. The MMONprocess transfers the memory version ofAWR statistics to disk on a regular basis (inthe form of snapshots). The ManageabilityMonitor Light (MMNL) process performslightweight manageability tasks, includingcomputing metrics and capturing session

history information for the AutomaticSession History (ASH) feature under somecircumstances. For example, the MMNLprocess will flush ASH data to disk if theASH memory buffer fills up before the one-hour interval that would normally causeMMON to flush it. (Note that althoughOracle calls MMNL the ManageabilityMonitor Light, this process shows up asManageability Monitor Process 2 whenyou query the V$BGPROCESS view.)

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 192: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Baseline DataA good way to evaluate database performance is by comparing database performancestatistics from two periods, if you know that the first period reflects “good” performance.The statistics from the period where the database performed well are called baselinedata. By comparing the current performance with the base period’s performance, youcan see if the database is faring better or worse. You could also compare individualstatistics to see which database component may be the source of your problems.

The STATISTICS_LEVEL initialization parameter is the key determinantof exactly what type of statistics the AWR collects. You can determine thetypes of statistics collected by using various values for this parameter. If youuse BASIC as the value for this parameter, the AWR turns off its statisticscollection completely. Choosing TYPICAL as the value for this parameterwill collect what Oracle deems it typically needs for monitoring databasebehavior. If you set STATISTICS_LEVEL=ALL, the AWR collects all availablestatistics. Oracle recommends that you use the default STATISTICS_LEVEL=TYPICAL setting. The ALL setting may be too comprehensive most of thetime, and if you use the BASIC setting, you won’t be able to use many ofOracle Database 10g’s automatic performance tuning features.

CERTIFICATION OBJECTIVE 4.02

The Automatic Workload Repository (AWR)The AWR is Oracle Database 10g’s brand-new feature for the automatic collection ofperformance statistics in the database, and it lies at the heart of the new self-tuningcapabilities of the Oracle database. The AWR stores its data in the new SYSAUXtablespace and, in fact, is one of the major users of that tablespace. AWR providesperformance statistics in two distinct formats:

■ A temporary in-memory collection of statistics in the SGA, which you canaccess with the help of the dynamic performance (V$) views. You can alsoview these statistics through the OEM interface.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

The Automatic Workload Repository (AWR) 5

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 193: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ A persistent type of performance data in the form of regular AWR snapshots,which you access either through data dictionary views (DBA_*) or theOEM Database Control. You can use the AWR snapshots for historicalcomparisons of performance. The new MMON background process performsthe transfer of the data from memory to disk.

Oracle DBAs traditionally have needed to maintain special database tables tocollect historical performance data. The AWR automatically collects performancestatistics for you and maintains historical data for analysis. You can view the data inthe snapshots with the help of the V$ views or create reports to examine the datain detail. Various database components and features use the data from these AWRsnapshots to monitor and diagnose performance issues. For example, as you saw inChapter 3, the ADDM relies on these snapshots for the diagnosis of performanceproblems.

Types of Data Collected by AWRThe AWR facility collects a large number of performance statistics, including thefollowing:

■ Base statistics that are also collected in the V$SYSSTAT and V$SESSSTATviews

■ New SQL statistics that aid in the identification of resource-intensive SQLstatements

■ Database object usage statistics that inform you about how the database iscurrently accessing various objects

■ Time statistics, which tell you how much time each database activity istaking

■ Wait statistics, which provide information about session waits (in previousversions, you needed to join the V$SESSION view with the V$SESSION_WAIT view to gather information on session waits; now several columns havebeen added to the V$SESSION view, so you can query the view directly)

■ Active Session History (ASH) statistics, which are flushed to the AWR ona regular basis

■ Database feature usage statistics that tell you if and how intensively yourdatabase is utilizing various features

6 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 194: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ The results of various management advisory sessions like the SegmentAdvisor and the SQL Access Advisor

■ Operating system statistics like disk I/O and memory usage within thedatabase

It is important to understand that the AWR isn’t a repository where Oracle storesall the data for the various performance indicators that it covers. The AWR storesonly a part of the statistics that it collects in memory. Whenever AWR collects asnapshot, it transfers part of the huge amount of data it holds in memory (SGA)to disk.

AWR Data HandlingAWR automatically generates snapshots to collect performance statistics. A snapshotis simply the performance data that is captured at certain point in time. As you recallfrom the previous chapter, each time the AWR generates a snapshot, the ADDMwill analyze the period corresponding to the last two snapshots. You may also createsnapshots manually if necessary. By comparing the difference in statistics betweensnapshots, the AWR knows which SQL statements are contributing significantly toyour system load. It will then focus on these SQL statements. AWR stores its data inthe SYSAUX tablespace. The space used by AWR depends on the following:

■ Data-retention period The longer the retention period, the more space used

■ Snapshot interval The more frequent the snapshots are taken, the morespace used

■ Number of active sessions The higher the number of user sessions, themore data collected by the AWR

By default, the AWR saves the data for a period of seven days, but you can modifythis period. Oracle recommends that you retain the AWR data to cover at least onecomplete workload cycle.

Managing the AWRManaging the AWR really means managing the regular snapshots that AWR collectsfrom your database. By default, the AWR collects its snapshots every 60 minutes. Ifyou think this isn’t an appropriate length of time for your purposes, you can changethe default snapshot interval easily by changing the INTERVAL parameter.

The Automatic Workload Repository (AWR) 7

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 195: OCA OCP - Oracle10G New Features For Administrators Exam Guide

In order to use the AWR feature well, you need to select a truly representativebaseline, which is a pair or range of AWR snapshots. When database performance isslow, you can compare the baseline snapshot statistics with current performancestatistics and figure out where the problems lie.

You can manage the AWR snapshots either with the help of the OEM DatabaseControl or with the Oracle-supplied DBMS_WORKLOAD_REPOSITORY package.Let’s first look at how you can use this package to manage AWR snapshots.

Using the DBMS_WORKLOAD_REPOSITORY Package toManage AWR SnapshotsYou can use the DBMS_WORKLOAD_REPOSITORY package to create, drop, andmodify snapshots, as well as to create and drop snapshot baselines.

The AWR automatically generates snapshots, but you can create a snapshotmanually, if you want to collect snapshots in between those scheduled by the AWR.You can do this by using the CREATE_SNAPSHOT procedure, as follows.

begindbms_workload_repository.create_snapshot ();end;

In order to drop a range of snapshots, use the DROP_SNAPSHOT procedure.When you drop a set of snapshots, Oracle automatically purges the AWR data thatis part of this snapshot range. The following example drops all snapshots whose snapIDs fall in the range of 40 to 60.

8 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

Snapshots provide youvalues for key performance statisticsat a given point in time. By comparingsnapshots from different periods, youcan compute the rate of change of aperformance statistic. Most of the Oracleadvisors depend on these AWR snapshotsfor their recommendations. You identify agiven snapshot by its unique snapshot

sequence numbers called snap IDs. Thedefault interval for snapshot collectionis 60 minutes, and the minimum intervalis 10 minutes. You can change the intervalbetween snapshots by adjusting theINTERVAL parameter. You can takemanual snapshots of the system any timeyou wish. You can combine manual andautomatic snapshots as well.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 196: OCA OCP - Oracle10G New Features For Administrators Exam Guide

begindbms_workload_repository.drop_snapshot_range (low_snap_id => 40,high_snap_id => 60, dbid => 2210828132);

end;

If you set the snapshot interval to 0, the AWR will stop collectingsnapshot data.

Using the Database Control to Manage AWR SnapshotsYou can manage AWR snapshots using the AWR page of the OEM Database Control,shown in Figure 4-1. To access this page, from the Database Control home page, clickthe Administration link, and go the Workload group. Then click the AutomaticWorkload Repository link. This page has two main sections: the General section andthe Manage Snapshots and Preserved Snapshot Sets section.

The Automatic Workload Repository (AWR) 9

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

FIGURE 4-1 The main AWR page

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 197: OCA OCP - Oracle10G New Features For Administrators Exam Guide

If you want to change the general settings of the AWR, you can do so by clickingthe Edit button in the General section. This will take you to the Edit Settings page,where you can modify the following:

■ Snapshot retention intervals

■ Snapshot collection intervals

■ Snapshot collection levels (Typical or All)

Click the Manage Snapshots and Preserved Snapshot Sets button to get tothe Manage Snapshots page. The Manage Snapshots page lists all the snapshotsin the AWR. You can click an individual snapshot to view complete details aboutit, including the capture time and the collection level. If you have established abaseline, you’ll also see whether a particular snapshot falls within that baseline.From the Manage Snapshots page, you can do the following:

■ Create a snapshot spontaneously (use the Create button)

■ View a list of snapshots collected over a specific period

■ Establish a range of snapshots to use as a baseline (use the Create PreservedSnapshot Set button)

■ Delete a defined range of snapshots from the list of snapshots collected overa period of time (use the Delete Snapshot Range button)

The range of snapshots you use for a baseline is the same as a preservedsnapshot set.

Creating and Deleting AWR Snapshot BaselinesThe purpose of using snapshot baselines is to have a valid measuring stick for acceptabledatabase performance, as well as to have a reference point for various system statistics.When you say database performance is bad, you must know that it’s bad compared tosomething you clearly know to be good performance.

You define a snapshot baseline on a pair of snapshots, when you know that theperiod covered by the snapshots represents typical “good” database performance.The baselines will then serve as a valid representative sample to compare withcurrent system database performance. Whenever you create a baseline by definingit over any two snapshots (identified by their snap IDs), the AWR retains thesnapshots indefinitely (it won’t purge these snapshots after the default periodof seven days), unless you decide to drop the baseline itself.

10 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 198: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You can create a new snapshot baseline by using the CREATE_BASELINEprocedure of the DBMS_WORKLOAD_REPOSITORY package. The snap IDuniquely identifies each snapshot time sequentially. You can get the snap IDs youneed to create baselines from the DBA_HIST_SNAPSHOT view. The followingexample creates a snapshot baseline named peak_time baseline:

begindbms_workload_repository.create_baseline (start_snap_id => 125,

end_snap_id => 185, baseline_name => 'peak_time baseline',dbid => 2210828132);

end;

If you don’t specify a name for the baseline, Oracle will assign a system-generatedidentifier.

You can drop a snapshot baseline by using the DROP_BASELINE procedure ofthe DBMS_WORKLOAD_REPOSITORY package:

begindbms_workload_repository.drop_baseline (baseline_name => 'peak_time

baseline',cascade => FALSE, dbid => 2210828132);end;

The CASCADE parameter is FALSE by default. By setting this parameter toTRUE, you can drop the actual snapshots as well.

Purging AWR SnapshotsAs you’ve learned, by default, the AWR runs every hour, and Oracle saves AWRstatistics for a default period of seven days. After the seven-day period, Oracle removesthe snapshots, starting with the oldest ones first. Oracle estimates that if you have tenconcurrent sessions, it will take between 200MB and 300MB of disk space to store thedata that it saves over the standard seven-day period. You must therefore ensure thatyour SYSAUX tablespace has at least this much free space, if you want Oracle to retainthe AWR data for the standard default period of seven days. The number of usersessions is a key determinant of the space necessary for the AWR statistics.

If your SYSAUX tablespace runs out of space, Oracle will automatically deletethe oldest set of snapshots, to make room for new snapshots.

The Automatic Workload Repository (AWR) 11

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 199: OCA OCP - Oracle10G New Features For Administrators Exam Guide

In addition to the number of active user sessions, two parameters affect the totalstatistics retained in the SYSAUX tablespace:

■ RETENTION As you know, the default retention period for AWR statisticsis seven days. The minimum retention period is one day. The longer theretention period, the more space the AWR will need in the SYSAUXtablespace.

■ INTERVAL By default, the AWR collects data every 60 minutes and theminimum interval value is 10 minutes. You can’t collect statistics morefrequently than in 10-minute intervals. The more frequently you schedulethe AWR, the more data the AWR will collect. And the more infrequent theAWR snapshots, the greater the chance that you may miss short bursts in diskor memory usage that may occur in your database.

You can use the DBMS_WORKLOAD_REPOSITORY package to modify thesnapshot settings, as shown here:

beginDBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS( retention => 43200,

interval => 30, dbid => 3310949047);end;

Oracle recommends that you make the retention period the same as your databaseworkload cycle. If your database is like many typical OLTP databases, you probablyhave OLTP transactions throughout the weekdays, with batch jobs scheduled duringnights and weekends. If this is the case, your workload is considered to span a week,in which case, the default AWR retention period of seven days is just fine.

Note that Oracle deletes older snapshots in chronological order. In addition,AWR always retains baseline snapshots until you remove the baselines themselves.

12 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

The default period ofretention for AWR data is seven days andthe minimum is one day. However, if thereis no room in the SYSAUX tablespace, that

fact will override all other retentionsettings. Oracle will start deletingsnapshots, by first overwriting theoldest ones with new data.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 200: OCA OCP - Oracle10G New Features For Administrators Exam Guide

If you set the value of the RETENTION parameter to zero, you disablethe automatic purging of the AWR. If you set the value of the INTERVALparameter to zero, you disable the automatic capturing of AWR snapshots.

Creating AWR ReportsOracle provides a script named awrrpt.sql (located in the $ORACLE_HOME/rdbms/admin directory) to generate summary reports about the statistics collected by theAWR facility. Don’t confuse this report with the ADDM report (created by runningaddmrpt.sql) that you learned about in Chapter 3. The AWR report doesn’t give yourecommendations, as does an ADDM report. Rather, it provides information aboutthe various kinds of performance statistics in the repository. The AWR report looksremarkably similar to the traditional STATSPACK reports.

The awrrpt.sql actually calls another script, the awrrpt1.sql script, to generate theAWR report for you. Note that you must have the SELECT ANY DICTIONARYprivilege in order to run the awrrpt.sql script.

When you run the awrrpt.sql script, Oracle will ask you to make the followingchoices for your reports:

■ Choose between an HTML or plain text report

■ Specify the beginning and ending snap IDs

■ Specify the number of days of snapshots to choose from

The AWR reports include the following types of information:

■ Load profile

■ Instance efficiency percentages (target 100 percent)

■ Top-five timed events

■ Wait events and latch activity

■ Time model statistics

■ Operating system statistics

■ SQL ordered by elapsed time

■ Tablespace and file I/O statistics

■ Buffer pool and PGA statistics and advisories

The Automatic Workload Repository (AWR) 13

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 201: OCA OCP - Oracle10G New Features For Administrators Exam Guide

14 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

Managing AWR Statistics with Data Dictionary ViewsYou can manage AWR statistics through the following data dictionary views:

■ The DBA_HIST_SNAPSHOT view shows all snapshots saved in the AWR.

■ The DBA_HIST_WR_CONTROL view displays the settings to control the AWR.

■ The DBA_HIST_BASELINE view shows all baselines and their beginningand ending snap ID numbers.

CERTIFICATION OBJECTIVE 4.03

Active Session History (ASH)The AWR snapshots are very useful, but Oracle takes these snapshots only every 60minutes. If you are interested in analyzing a performance problem that happened 10minutes ago, the AWR snapshots aren’t of any help to you. However, you do have away to get that information. Oracle Database 10g now collects the new Active SessionHistory (ASH) statistics (mostly the wait statistics for different events) for all activesessions every second, and stores them in a circular buffer in the SGA. Thus, ASHrecords very recent session activity (within the past five or ten minutes).

Note that not all the extra statistics in Oracle Database 10g described in thischapter will have a detrimental affect on performance, since the statisticsmostly come directly from the SGA, via background processes. The ASHfeature uses about 2MB of SGA memory per CPU.

Current Active Session DataAs you are aware, the V$SESSION view holds all the session data for all currentsessions. The V$SESSION view contains 72 columns of information, so it’s unwieldywhen you are trying to analyze session data. That’s why ASH samples theV$SESSION view and gets you the most critical wait information from it. Oracleprovides the new V$ACTIVE_SESSION_HISTORY view, which enables you to

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 202: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Active Session History (ASH) 15

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

access the ASH statistics. The view contains one row for each active session that ASHsamples and returns the latest session rows first.V$ACTIVE_SESSION_HISTORY is where the database stores a sample of

all active session data. What is an active session? In the V$ACTIVE_SESSION_HISTORY view, there is a column called SESSION_STATE, which indicates whethera session is active. The SESSION_STATE column can take two values: ON CPUor WAITING. A session is defined as an active session in the following cases:

■ The session state is ON CPU, meaning that it is actively using the CPU toperform a database chore.

■ The session state is WAITING, but the EVENT column indicates that thesession isn’t waiting for any event in the IDLE class.

Note that the ASH is really a rolling buffer in the SGA; it is an in-memory activesession history. Thus, in a busy database, older information is frequently overwritten,since ASH collects data every second from the V$SESSION view. ASH stores itsdata in V$ACTIVE_SESSION_HISTORY, but this view will contain only sessionsamples of the most recent active sessions, because the ASH statistics areoverwritten in memory.

Older Active Session HistoryThe new data dictionary view DBA_HIST_ACTIVE_SESSION_HISTORY provideshistorical information about recent active session history. In other words, this viewis nothing but a collection of snapshots from the V$ACTIVE_SESSION_HISTORYview. To put it in simple terms, the DBA_HIST_ACTIVE_SESSION_HISTORY viewsamples the V$ACTIVE_SESSION_HISTORY view, which itself is a sample of activesession data.

How does the database populate the DBA_HIST_ACTIVE_SESSION_HISTORY view? There are two ways to populate the view:

■ During the course of the regular (by default, hourly) snapshots performedby the AWR, the MMON background process flushes the ASH data to theAWR. By default, the MMON process performs this data transfer on anhourly basis.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 203: OCA OCP - Oracle10G New Features For Administrators Exam Guide

16 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

■ Oracle may also need to transfer data to the DBA_HIST_ACTIVE_HISTORYview in between the regular snapshots, if the memory buffer is full and youcan’t write new session activity data to it. In this case, the new MMNLbackground process will perform the flushing of data from the memory bufferto the data dictionary view.

CERTIFICATION OBJECTIVE 4.04

Server-Generated AlertsOracle DBAs generally use SQL scripts to alert them when abnormal conditionsoccur. Oracle Database 10g now has a built-in system of alerts, formally called server-generated alerts. The Oracle Database 10g Server automatically alerts you when certainproblems occur in the database.

Oracle Database 10g uses a set of indicators called metrics, which show you therate of change of a cumulative statistic. A typical example of an Oracle metric isthe number of database calls per second. Once a metric crosses a certain threshold,Oracle sends an alert to notify you that the target has a problem. Since databasemetrics are an important part of server-generated alerts, let’s first take a look at howyou monitor database metrics.

Introduction to MetricsMetrics are indicators of the health of various database targets. The set of metricsdepends on the target you are measuring. For example, key metrics help you decide ifthe host is healthy and if resources like CPU, memory, and I/O are performing at anacceptable level.

The OEM Database Control’s All Metrics page, shown in Figure 4-2, offers anexcellent way to view the various metrics. To access this page, from the DatabaseControl home page, click All Metrics under the Related Links heading. From here,you can view all the metrics in your database. For details, click the Expand All linkin the left corner of the page. If you want the drill down to the details of any specificmetric, just click it.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 204: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Table 4-1 lists the basic metric groups in Oracle Database 10g.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

Server-Generated Alerts 17

FIGURE 4-2 The All Metrics page of database control

Metric Description

Event Class Metrics Metrics collected on the wait event class level; for example, DB_TIME_WAITING

Event Metrics Metrics collected on various wait events

File Metrics Long Duration Metrics collected at the file level; for example, AVERAGE_FILE_WRITE_TIME

Service Metrics Metrics collected at the service level; for example, CPU_TIME_PER_CALL

Session Metrics Short(Long) Duration

Metrics collected at the session level; for example, BLOCKED_USERS

System Metrics Short(Long) Duration

Metrics collected at the system level

Tablespace Metrics LongDuration

Metrics collected at the tablespace level; for example, TABLESPACE_PCT_FULL.

TABLE 4-1 Oracle Database 10g Metric Groups

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 205: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Viewing In-Memory MetricsThe new MMON background process collects database metrics continuously andautomatically saves them in the SGA for one hour. You can view all the system-related metrics saved in memory by using views like V$SYSMETRIC_HISTORY andV$SYSMETRIC. Here, for example, are the typical kinds of system metrics maintainedin the V$SYSMETRIC view:

■ Buffer Cache Hit Ratio

■ CPU Usage Per Sec

■ Database CPU Time Ratio

■ Database Wait Time Ratio

■ Disk Sort Per Sec

■ Hard Parse Count Per Sec

■ Host CPU Utilization (%)

■ Library Cache Hit Ratio

■ SQL Service Response Time

■ Shared Pool Free %

The V$SERVICEMETRIC and V$SERVICEMETRIC_HISTORY views, on theother hand, provide details about service-level metrics. The V$SERVICEMETRICview, for example, contains the ELAPSEDPERCALL and the CPUPERCALLcolumns for each service, including the database service. V$SERVICEMETRIClists the metrics for the last minute (a few over the last 15 seconds), andV$SERVICEMETRIC_HISTORY gives them per minute over the last hour.

Viewing Saved MetricsThe only way Oracle will save the metric information that is continuously placed inits SGA by the MMON process is through the AWR’s snapshot mechanism. As youknow, the AWR takes its snapshots every 60 minutes by default. The AWR’s data-collection facility includes data pertaining to metrics. The metric data that AWRcollects with the help of the MMON background process is permanently stored inthe DBA_HIST_* views, such as DBA_HIST_SERVICE_NAME and DBA_HIST_SESSMETRIC_HISTORY.

18 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 206: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Server-Generated Alerts 19

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

You can view the current values of any metric by using the V$ views, such as theV$METRICNAME and V$SERVICEMETRIC views. The MMON process regularlycomputes these metrics for you. However, the various performance metricsstay in the SGA for only an hour. MMON will automatically flush the metricdata from the SGA to the DBA_HISTORY_* views on disk. These history viewsmaintain a permanent record of the various metrics. Examples of the historyviews are DBA_HIST_SUMMARY_HISTORY, DBA_HIST SYSMETRIC_HISTORY,and DBA_HIST_METRICNAME. Each of these views contains snapshots of thecorresponding V$ view. For example, the DBA_HIST_SYSMETRIC_HISTORYview contains snapshots of the V$SYSMETRIC_HISTORY view.

Database AlertsA database alert tells you that there is a potential problem in your database. The potentialproblem can occur when a threshold value for a monitored metric is crossed or a databasetarget simply becomes unavailable. For example, an undo tablespace may trigger theLong Query Warning alert, thus alerting the DBA about a long-running query thatmay fail because the system is running out of free space in the undo tablespace. Oraclecalls the threshold alerts stateful alerts. Oracle calls the types of alerts issued when atarget becomes unavailable stateless alerts.

Threshold-Based Alerts and Problem AlertsYou can set threshold values at two different levels: warning and critical. Thus, thereare three situations when a database can send an alert:

■ A monitored metric crosses a critical threshold value

■ A monitored metric crosses a warning threshold value

■ A service or target suddenly becomes unavailable

We can refer to the first two types of the alerts as threshold-based alerts and thethird type as problem alerts. Problem alerts report problems that occur in the database,such as an ORA-1555 (snapshot too old) error. Problem alerts are based on a certainpredetermined event (usually bad) occurring in the database.

Threshold-based alerts are based on thresholds for certain objects or events in thedatabase; for example, a tablespace may be reaching 95 percent of its total allocated

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 207: OCA OCP - Oracle10G New Features For Administrators Exam Guide

20 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

space. Threshold-based alerts thus are dependent on metrics, not events. Thethreshold itself could be an internally set level, or you, the DBA, can set your ownalert threshold levels. When a metric crosses a threshold, Oracle automaticallygenerates an alert to you. In addition, the database can undertake remedial actionto fix the problem (or potential problem), if you specify a response action.

When you use threshold-based alerts, Oracle further makes a distinction betweena warning type alert (severity level 5) and a critical (severity level 1) alert. Forexample, by default, the database will send you a warning alert when any tablespacehits an 85 percent space use threshold. When the usage reaches the 97 percent level,you get a critical alert.

Default Server-Generated AlertsEven if you don’t explicitly set any alerts in your database, there are several alerts thatOracle enables by default when you create an Oracle Database 10g database. Thesedefault server-generated alerts may be either problem alerts or threshold alerts. Theserver-generated alerts are very similar to the OEM alerts in prior versions of theOracle database.

The following are the default, or out-of-the-box, server-generated alerts:

■ Any snapshot too old errors

■ Tablespace space usage (warning alert at 85 percent usage; critical alert at 97percent usage)

■ Resumable session suspended

■ Recovery session running out of free space

In addition, Oracle automatically set thresholds on all metrics with the objecttype SYSTEM.

The new database alertsystem has really nothing to do with thealert log of the database. The only timethe alert log may be involved is when the

database cannot write an alert to the alertqueue, in which case, it records thisexception in the alert log.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 208: OCA OCP - Oracle10G New Features For Administrators Exam Guide

How the Server-Generated Alert Mechanism WorksAs you are probably aware, the OEM enables the notification of various types of alerts.So, what is this new server-generated alert concept? Well, under the old OEM alertnotification system, the OEM was responsible for gathering the metrics and generatingthe alerts. In the new Oracle Database 10g server-generated alert system, it is not theOEM, but rather the database itself that collects the metrics that underlie all alerts.

The new MMON process checks all the available metrics to see if any metriccrosses a preset threshold. When a database reaches a threshold for one of themonitored variables, Oracle will send you an alert. For example, the DatabaseControl can alert you, using e-mail or a pager notification, when the databasereaches any tablespace thresholds.

As described in the previous section, your database comes with a set of defaultalerts already configured. In addition, you can choose to have other alerts. You mayalso change the thresholds for the default alerts. You can perform these tasks withthe help of the OEM Database Control or with Oracle-supplied PL/SQL packages.

Using the Database Control, you can set up notification rules; for example, youcan specify a blackout period for the alerts. When the database issues an alert, youcan see that in the Database Control alert window. In addition, you’ll receive anotification, if you’ve configured the system to send you one. The alerts usuallyare accompanied by a recommendation to fix the problem as well.

Server-Generated Alerts 21

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

Tablespace usage alerts arebased on the default values of 85 percent

space usage for a warning alert and 97percent space usage for a critical alert.

Make sure you set theSTATISTICS_LEVEL parameter toTYPICAL or ALL, in order to user theserver-generated alerts feature. You canuse either the OEM Database Control or

a PL/SQL package to manage system-generated alerts. In addition, you candisplay alerts directly by subscribing tothe alert queue (ALERT_QUE).

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 209: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing AlertsSeveral new data dictionary views aid in managing both database metrics and server-based alerts. The following sections explain using the various methods to managealerts. Let’s first look at how you can use the OEM Database Control for this purpose.

Using the Database Control to Manage Server AlertsIf you’ve used the Oracle9i OEM, you’re familiar with the Enterprise Manager alerts,wherein you can configure OEM to alert you when it encounters certain errors in thedatabase, using a pager or e-mail. Server-generated alerts work in a similar fashion. Inaddition to the capability to send alerts, now you can configure alert thresholds as well.

Setting Alert Thresholds It is very easy to set your own warning and criticalthresholds for any database metric. To set alert thresholds, from the DatabaseControl home page, click the Manage Metrics link, which you’ll find under theRelated Links group. On the Manage Metrics page, click the Edit Thresholdsbutton. You’ll see the Edit Thresholds page, as shown in Figure 4-3. For eachmetric on the Edit Thresholds page, you can set the following:

■ A warning and critical threshold You can set an arbitrary threshold orcompute a threshold based on a set of baselines for a metric. For example, youmay specify that the database should generate a threshold alert if a resourceuse is 15 percent higher than its normal baseline values. You may also specifymultiple thresholds.

■ A response action This action can be a SQL script or an operatingsystem command. Oracle will automatically execute this response actionimmediately when the alert is generated. Make sure that you provide thecomplete path to the SQL script or operating system command, so the OEMManagement Agent can find it.

Setting Notification Rules When the database needs to send you an alert, itfollows any notification rules that you’ve set up. Notification rules enable you tochoose the conditions under which you want to receive a message from the OEM.For example, you many not want to be woken up at 2:00 A.M. just because atablespace with 100GB allocated space has reached an 80 percent usage level.On the other hand, you would surely want to know immediately when a 200MBtablespace has crossed the critical 97 percent usage level.

22 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 210: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You can use the Database Control to set notification rules. These rules are setthrough Preferences. From the Database Control home page, click the Preferenceslink (at the very bottom of the page) to go to the Preferences page. Then click theRules link in the Notification section. Select any metric, such as Listener Availability,and click the Edit button. Then you can set notification rules for the selected event,such as the following:

■ The precise conditions under which you want receive a notification

■ The metrics for which you would like to receive alerts

■ The severity conditions (critical and warning levels) under which youwould like to receive notification

■ The notifications you want to be sent

■ E-mail notification or an advanced notification method, if you’veconfigured one

Server-Generated Alerts 23

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

FIGURE 4-3 Using the Database Control to set alert thresholds

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 211: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using the DBMS_SERVER Package to Manage AlertsAlthough the OEM Database Control interface provides an easy way to managedatabase alerts, there may be times when you need to incorporate certain changesinside a PL/SQL program. At times like this, you can use the Oracle-supplied PL/SQLpackage DBMS_SERVER_ALERT to set up and modify thresholds on various databasemetrics. The DBMS_SERVER_ALERT package has two main procedures: GET_THRESHOLD and SET_THRESHOLD.

You use the SET_THRESHOLD procedure to define threshold settings for adatabase metric. This procedure has the following structure:

SQL> desc dbms_server_alert.set_thresholdPROCEDURE dbms_server_alert.set_thresholdArgument Name Type In/Out Default?------------------------------ ----------------------- ------ --------METRICS_ID BINARY_INTEGER INWARNING_OPERATOR BINARY_INTEGER INWARNING_VALUE VARCHAR2 INCRITICAL_OPERATOR BINARY_INTEGER INCRITICAL_VALUE VARCHAR2 INOBSERVATION_PERIOD BINARY_INTEGER INCONSECUTIVE_OCCURRENCES BINARY_INTEGER ININSTANCE_NAME VARCHAR2 INOBJECT_TYPE BINARY_INTEGER INOBJECT_NAME VARCHAR2 IN

SQL>

Here’s an example that sets up an automatic alert monitoring of CPU use by eachuser in the instance:

DBMS_SERVER_ALERT.SET_THRESHOLD(DBMS_SERVER_ALERT.CPU_TIME_PER_CALL, DBMS_SERVER_ALERT.OPERATOR_GE, '8000',DBMS_SERVER_ALERT.OPERATOR_GE, '10000', 1, 2, 'prod1',DBMS_SERVER_ALERT.OBJECT_TYPE_SERVICE,'main.regress.rdbms.dev.us.oracle.com');

This SET_THRESHOLD procedure example specifies that a warning alert is issuedwhen CPU time exceeds 8000 microseconds for each user call, and a critical alert isissued when CPU time exceeds 10,000 microseconds for each user call. The otherkey arguments are as follows:

■ CPU_TIME_PER_CALL specifies the metric identifier.

■ The observation period is set to 1 minute. Oracle issues the alert after thethreshold is crossed for 1 minute.

24 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 212: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ The number of consecutive occurrences is set to 2. This is the number oftimes the metric value crosses the threshold values before Oracle generatesthe alert.

■ The name of the instance is set to prod1.

■ The constant DBMS_ALERT.OBJECT_TYPE_SERVICE specifies theobject type on which the threshold is set. Here, the service name ismain.regress.rdbms.dev.us.oracle.com.

You use the GET_THRESHOLD procedure tofind out the current thresholdsettings for any databasemetric. You can discover boththe warning and criticalthresholds by using thisprocedure.

Using the Alert QueueEarlier, you learned how you can view and change threshold settings for the serveralert metrics using the SET_THRESHOLD and GET_THRESHOLD procedures of theDBMS_SERVER_ALERTS PL/SQL package. Of course, you may also use the OEMDatabase Control to manage alerts. In addition, you can use procedures from theDBMS_AQ and DBMS_AQADM packages for directly accessing and reading alertmessages in the alert queue. The SYS user account owns the alert queue and bydefault, the Database Control is the only user of the alert queue. However, Oracleprovides the new DBMS_AQADM package, which consists of various procedures thathelp you directly access the alerts stored in the alert queue (ALERT_QUE).

Using the DBMS_AQADM package procedures, you can subscribe to the ALERT_QUE, set thresholds for alerts, and display alert notifications. Here are some of themain procedures of the DBMS_AQADM package that help you manage databasealerts:

■ Use the GRANT_SYSTEM_PRIVILEGE procedure to grant AQ systemprivileges to users and roles.

■ Use the ADD_SUBSCRIBER procedure to add a default subscriber to aqueue.

■ Use the CREATE_AQ_AGENT procedure to register an agent.

Server-Generated Alerts 25

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

If you don’t want Oracleto send any metric-based alerts, simply setthe the warning value and the critical valueto NULL when you execute the DBMS_SERVER_ALERT.SET_THRESHOLDprocedure.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 213: OCA OCP - Oracle10G New Features For Administrators Exam Guide

26 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

■ Use the ENABLE_DB_ACCESS procedure to grant an AQ Agent-specificdatabase user’s privileges.

In addition to the DBMS_AQADM package, Oracle also offers the DBMS_AQpackage, which provides a direct interface to the Oracle Streams AdvancedQueuing (AQ) feature. You can use the DBMS_AQ procedure to manage alertnotifications. Here are some of the important procedures of the DBMS_AQdatabase package.

■ Use the REGISTER procedure to register for message notifications.

■ Use the DEQUEUE procedure to remove a message from a queue.

Using Data Dictionary Views to Manage Metrics and AlertsThe OEM Database Control is your first stop in the managing of database alerts and themetrics associated with them. There are also several new data dictionary views thatprovide information about database metrics and alerts. I’ve already mentioned theV$METRICNAME, V$SYSMETRIC, V$SERVICEMETRIC, and V$SYSMETRIC_HISTORY views earlier in this chapter. Following is a list of some of the other key views:

■ V$ALERT_TYPES displays information about server alert types.

■ DBA_HIST_SYSMETRIC_HISTORY contains snapshots ofV$SYSMETRIC_HISTORY.

■ DBA_ALERT_HISTORY provides a history of alerts that are no longeroutstanding; that is, all alerts that you have already resolved.

■ DBA_OUTSTANDING_ALERTS contains all the stateful (threshold) alertsthat have yet to be resolved.

■ DBA_THRESHOLDS shows the name as well as the critical and warningvalues for all thresholds in the database.

I’ll describe a couple of the important views in more detail in the followingsections.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 214: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Server-Generated Alerts 27

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

V$ALERT_TYPES The V$ALERT_TYPES view provides information aboutall system alert types. Three columns in this view are noteworthy:

■ STATE Holds two possible values: stateful or stateless. Stateful alerts arethose alerts that clear automatically when the alert threshold that promptedthe alert is cleared. The database considers all the nonthreshold alerts asstateless alerts. A stateful alert first appears in the DBA_OUTSTANDING_ALERTS view and goes to the DBA_ALERT_HISTORY view when it iscleared. A stateless alert goes straight to DBA_ALERT_HISTORY.

■ SCOPE Classifies alerts into database wide and instance wide. The onlydatabase-level alert is the one based on the Tablespace Space Usage metric.All the other alerts are at the instance level.

■ GROUP_NAME Oracle aggregates the various database alerts into somecommon groups. Here are the common alert groups:

■ Space, such as a suspended session, snapshot too old, or tablespaceout of space

■ Performance, such as elapsed time or CPU time exceeds set thresholds

■ Configuration-related database alerts

DBA_THRESHOLDS The DBA_THRESHOLDS view provides the currentthreshold settings for all alerts. This view is useful when you want to find out thecurrent threshold settings for any alert. Here is a simple example of how to usethe view:

SQL> select metrics_name, warning_value, critical_value,consecutive_occurrencesfrom DBA_THRESHOLDSwhere metrics_name LIKE '%CPU Time%';

The DBA_OUTSTANDING_ALERTS view shows all alerts that have yet

to be resolved. The DBA_ALERT_HISTORYview is where all cleared alerts are moved.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 215: OCA OCP - Oracle10G New Features For Administrators Exam Guide

EXERCISE 4-2

Use the DBMS_SERVER_ALERT Package to Set AlertThresholds

In the following exercise, you will define a small tablespace and then attempt to createa large table in it. The database will alert you because you’ll be crossing a thresholdsetting for the free space in the tablespace. The example will show you how to set,view, and clear an alert.

1. Create a test the tablespace using the following command:

SQL> create tablespace test datafile 'test01.dbf' size 1Mextent management local uniform size 200K;

Tablespace created.

2. Set your tablespace alert thresholds as follows (warning alert at 75% full andcritical at 90% full):

SQL> exec dbms_server_alert.set_threshold(-> dbms_server_alert.tablespace_pct_full,dbms_server_

alert.operator_ge,'75',-> dbms_server_alert.operator_ge,'90',1,1,null,-> dbms_server_alert.object_type_tablespace,'TEST');PL/SQL procedure successfully completed.SQL>

3. When you create a new table using the following SQL statement, you willset off an alert (because the ‘minextents 4’ clause for the new table will causethe tablesapce to cross its warning threshold of 75% space full):

SQL> create table test_table (name varchar2(30))tablespace teststorage (minextents 4);

Table created.SQL>

4. You can verify the tablespace alert in the following way:

SQL> select reason from dba_outstanding_alerts;REASON-----------------------------------------------------Tablespace [TEST] is [78 percent] fullSQL>

28 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 216: OCA OCP - Oracle10G New Features For Administrators Exam Guide

5. You can clear the alert by increasing the size of the datafile that is part of thetablespace named small and see what happens to the alert by querying theDBA_OUTSTANDING_ALERTS view. You’ll find that the alert is gone fromthat view, since it has been cleared.

SQL> alter tablespace test add datafile 'test02.dbf' size 2M;Tablespace altered.SQL>SQL> select reason from dba_outstanding_alerts;no rows selectedSQL>

6. Where do cleared alerts go? All cleared alerts will show up in the DBA_ALERT_HISTORY. You can verify that the cleared tablespace alert is in thatview, by using the following query.

SQL> select reason,resolution from dba_alert_history;REASON RESOLUTION-------------------------------------------------------------------Tablespace [TESTNEW] is [13 percent] full clearedSQL>

CERTIFICATION OBJECTIVE 4.05

The Automated Tasks FeatureMost Oracle DBAs are familiar with using the UNIX crontab feature or the WindowsAT facility to manage their regularly scheduled jobs. Although you can schedule thejobs, you still must decide when to run these automated tasks. Now, in OracleDatabase 10g, the database itself will perform some of the routine tasks all by itself,using the new automated tasks feature. For example, in Chapter 3, you learned howthe database now collects its own optimizer statistics, using the Scheduler facility. InChapter 1, I also explained how the DBCA lets you automate the maintenance ofbackup jobs while you are creating the database.

The new Oracle Scheduler—with its concepts of jobs, job classes, programs, andoperation windows—lies at the heart of the automated tasks feature. Therefore, let’s

The Automated Tasks Feature 29

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 217: OCA OCP - Oracle10G New Features For Administrators Exam Guide

start our discussion of the automated tasks feature by briefly looking at theScheduler.

An Introduction to the Job SchedulerThe Scheduler can perform very complex scheduling tasks for you, unlike a normalcrontab-based program. The Scheduler is nothing but a set of PL/SQL functions andprocedures, which together provide a facility to schedule and manage database andoperating system jobs. You may run PL/SQL and Java stored procedures and functions,C functions, regular SQL scripts, and UNIX or Windows scripts using the Scheduler.

The Scheduler consists of the following four important concepts:

■ Program A Scheduler program consists of metadata about what task theScheduler will run. A program consists of a specific action, along withspecific arguments to run the task. A task is any executable program, whichyou may reuse. You can create several named tasks and store them in thedatabase.

■ Job A job is a user-defined task that you schedule for running one or moretimes. A job class is a group of similar jobs. You create job classes so you canprioritize the jobs in an orderly way, when you are allocating databaseresources.

■ Schedule A schedule indicates when a job should be run. A schedule tellsthe database the date, time, and frequency of execution for a job. Scheduleshave a start date, an end date, and a repeat interval.

■ Window A window is a time-duration for which you may specify certainresource allocations. A window has a start date, an end date, and a durationthat specifies how long the window will be open each time it opens. Awindow is usually associated with a resource plan (created using the DatabaseResource Manager), which specifies how resources should be allocated amonggroups of jobs (called job classes). The Scheduler comes with a defaultmaintenance window group as you saw in Chapter 3. These include theweeknight window (10:00 P.M. to 6:00 A.M., Monday through Friday) andthe weekend window (12:00 A.M. Saturday to 12:00 A.M. Monday). Oracleautomatically configures these two Scheduler windows when you create anyOracle Database 10g database.

30 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 218: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You may use the DBMS_SCHEDULER package to manage various schedulingactivities. You can create and drop jobs, job classes, programs, and windows usingthis package. The Scheduler and the DBMS_SCHEDULER package are discussed indetail in Chapter 7.

Managing Automated TasksOracle schedules several maintenance tasks, including the automatic optimizerstatistics collection job, during the maintenance window (MAINTENANCE_WINDOW_GROUP). Every Oracle Database 10g database comes with the default programGATHER_STATS_PROG, the default job GATHER_STATS_JOB, and default jobclass AUTO_TASKS_JOB_CLASS.

As you know from Chapter 3, the job GATHER_STATS_JOB executes theDBMS_STATS.GATHER_DATABASE_STATS_JOB_PROC procedure in order tocollect optimizer statistics for the database. Oracle defines this job on the programGATHER_STATS_PROG. The job runs in the AUTO_TASKS_JOB_CLASS jobclass.

You can use the DBMS_SCHEDULER package to create a new job and add it tothe automated task schedule. You must first create the SQL or PL/SQL code thatwill perform the task functions. You can then use the CREATE_JOB procedure toadd this task to the automated task list. Here’s an example:

begindbms_scheduler.create_job(job_name => 'DAILY_BACKUP_JOB_01',job_type => 'STORED PROCEDURE',program_name => 'DAILY_BACKUP_PROGRAM',schedule_name => 'DAILY_BACKUP_WINDOW');end;/

You can also use the Database Control interface to manage all aspects of theOracle Scheduler, including creating, deleting, and modifying jobs, job classes,and windows.

The Automated Tasks Feature 31

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 219: OCA OCP - Oracle10G New Features For Administrators Exam Guide

32 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

CERTIFICATION OBJECTIVE 4.06

The Management Advisory FrameworkOracle Database 10g provides you with several server advisors to provide you withautomatic performance details about various subsystems of the database. For example,the Undo Advisor tells you what the optimal undo tablespace size might be for yourdatabase. Each of these advisors bases its actions on a specific Oracle PL/SQL packagelike the DBMS_ADVISOR package.

The management advisory framework offers you a uniform interface for all Oracleadvisors. Some of these advisors, like the PGA Advisor, have been around sinceOracle9i. What is new is that Oracle has built a Common Manageability Structurein Oracle Database 10g to make it easy to manage the advisors. This allows you touse a similar method to invoke all the advisors, and the advisors provide theirreports in a consistent fashion as well. All the advisors get their raw data from theAWR. They also store their analysis results in the AWR itself.

The advisory framework’s primary function is to help the database improve itsperformance. The ADDM recommends using the management advisors on an adhoc basis, whenever a performance problem needs a deeper analysis. DBAs can alsouse the advisors for performing what-if analyses.

The AdvisorsWe can group the automatic advisors into the following groups: memory-related,tuning-related, and space-related. In later chapters, you’ll see a complete discussionof several of the management advisors. Let’s briefly look at the advisors that fall intothese three groups.

Memory-Related AdvisorsOf the three memory-related advisors, two provide information about the SGA andone provides PGA advice. The following are the memory-related advisors:

■ Buffer Cache Advisor This advisor tells you the benefits in increasing ordecreasing the memory allocation to the BUFFER_CACHE parameter. Theadvisor shows the benefit as a decrease in disk I/O.

Obviously, if you are using Automatic Shared Memory Management, you don’tneed the Buffer Cache Advisor or the Library Cache Advisor to tell you howto size these memory components. Oracle itself will do that for you.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 220: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The Management Advisory Framework 33

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

■ Library Cache Advisor This advisor shows you the impact of changing theshared pool component of the SGA.

■ PGA Advisor This advisor provides recommendations on optimal allocationof Program Global Area (PGA) memory, based on your database workload.

Space-Related AdvisorsThe two space-related advisors are new to Oracle Database 10g:

■ Segment Advisor This advisor allows you to perform growth trend analyseson various database objects. This advisor also helps you perform objectshrinkage, thus helping you reclaim unused space in your database.

■ Undo Advisor This advisor bases its activities on system usage statistics,including the length of the queries as well as the rate of undo generation. TheUndo Advisor facilitates Oracle’s Automatic Undo Management feature. Ithelps you to correctly size your undo tablespace. It also helps you choose thecorrect undo retention parameters.

Tuning-Related AdvisorsThe ADDM, of course is the most important all-round tuning advisor in the database.Apart from the ADDM itself, there are two purely SQL tuning-related andperformance-related advisors:

■ SQL Tuning Advisor This advisor analyzes complex SQL statements andrecommends ways to improve performance. The SQL Tuning Advisor basesall its work on internal statistics and may include suggestions to collect newstatistics as well as SQL code restructuring.

■ SQL Access Advisor This advisor mainly provides you advice on creatingnew indexes, materialized views, or materialized view logs. You provide theadvisor a representative workload in order to get the advice.

Most of the database alert messages in the OEM also contain a link tospecific management advisors. Thus, you can invoke a management advisorydirectly from the alert message itself.

Managing the Advisory FrameworkYou can manage all aspects of the management advisory framework easily, using theDatabase Control interface. You can also use the DBMS_ADVISOR package to createand manage tasks for each of the management advisors.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 221: OCA OCP - Oracle10G New Features For Administrators Exam Guide

34 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

Using the DBMS_ADVISOR PackageYou can invoke any of the management advisors through the OEM interface, usingvarious wizards like the SQL Access Advisor Wizard. However, you may also run anyof the advisors using the DBMS_ADVISOR package. Before a user can use any of theadvisors, you must grant the user the ADVISOR privilege, as shown here:

SQL> grant advisor to oe;Grant succeeded.SQL>

The following are the steps you must follow in order to use the DBMS_ADVISORpackage to manage various advisors:

■ Create a task

■ Adjust task parameters

■ Perform the analysis

■ Review the advisor recommendations

These steps are described in the following sections.

Creating a Task The first step in using an advisor is creating a task. A task iswhere the advisor stores all its recommendation-related information. You create atask using the CREATE_TASK procedure, as shown here:

VARIABLE task_id NUMBER;VARIABLE task_name VARCHAR2(255);EXECUTE :task_name := 'TEST_TASK';EXECUTE DBMS_ADVISOR.CREATE_TASK ('SQL Access Advisor', :task_id,:task_name);

Defining the Task Parameters After you create a new task, the next step isto set the parameters for this task. The task parameters control the recommendationprocess. The parameters you can modify belong to four groups: workload filtering,task configuration, schema attributes, and recommendation options.

Use the DBMS_ADVISORpackage to manage any modules in theadvisory framework. You follow identicalsteps to use any advisor for tuning

purposes. These steps are creatinga task, adjusting task parameters,performing the analysis, and reviewingthe recommendations of the advisor.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 222: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The Management Advisory Framework 35

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

Here is an example showing how you can set various task parameters using theSET_TASK_PARAMETER procedure:

SQL> EXECUTE DBMS_ADVISOR.SET_TASK_PARAMETER ( -'TEST_TASK', 'VALID_TABLE_LIST', 'SH.SALES, SH.CUSTOMERS');

In this example, the VALID_TABLE_LIST parameter belongs to the workloadfiltering group of parameters. You are instructing the advisor (the SQL AccessAdvisor) to exclude all tables from the analysis, except the sales and customerstables, from the SH schema.

The following example uses the STORAGE_CHANGE parameter from therecommendation options group to add 100MB of space to the recommendations.

SQL> EXECUTE DBMS_ADVISOR.SET_TASK_PARAMETER('TEST_TASK','STORAGE_CHANGE',-100000000);

Generating the Recommendations To generate a set of recommendationsby any advisor, you execute the task that you created earlier, using the EXECUTE_TASK procedure of the DBMS_ADVISOR package. The EXECUTE_TASKprocedure will generate recommendations, which consist of one or more actions.For example, excuting the SQL Access Advisor may provide a recommendation tocreate a materialized view and a materialized view log. Here’s how you execute a tasknamed TEST_TASK:

SQL> EXECUTE DBMS_ADVISOR.EXECUTE_TASK('TEST_TASK');

Viewing the Recommendations You can view the recommendations of theadvisor task by using the GET_TASK_REPORT procedure. You may also use theDBA_ADVISOR_RECOMMENDATIONS view to check the recommendations, asshown in the following example:

SQL> select rec_id, rank, benefitfrom DBA_ADVISOR_RECOMMENDATIONS WHERE task_name = 'TEST_

TASK’;REC_ID RANK BENEFIT

---------- ---------- ----------1 2 27542 3 12223 1 54994 4 594

In this example, the RANK column shows how the four recommendations stackup against each other. The BENEFIT column shows the decrease in the executioncost for each of the four recommendations.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 223: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using the Database Control to Manage the Advisory FrameworkThe best way to use the management advisors is through the OEM Database Control.All you need to do is to click the Advisor Central link on the Database Control homepage. From the Advisor Central page, shown in Figure 4-4, you can select any of themanagement advisors in your database.

Using Dictionary Views to Manage the Advisory FrameworkSeveral new data dictionary views provide information about managing tasks, as wellrecommendations made by the various advisors. Here are the main advisor-relateddictionary views:

■ DBA_ADVISOR_TASKS

■ DBA_ADVISOR_PARAMETERS

■ DBA_ADVISOR_FINDINGS

■ DBA_ADVISOR_RECOMMENDATIONS

■ DBA_ADVISOR_ACTIONS

■ DBA_ADVISOR_RATIONALE

36 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

FIGURE 4-4 The Advisor Central page in OEM Database Control

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 224: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CERTIFICATION SUMMARYThis chapter introduced the new AWR feature, which is central to Oracle Database10g’s performance tuning. You reviewed the different kinds of data stored in the AWRand how to manage the AWR by using the DBMS_WORKLOAD_REPOSITORY package.You learned how to create and manage AWR snapshots and baselines. The chapteralso explained the ASH statistics, which are a key part of the AWR.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

The Management Advisory Framework 37

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

The test looks at your knowledge of theAutomatic Workload Repository (AWR) indepth. You must be aware of the in-memoryand persistent portions of the AWR and themechanism that records the AWR statistics ondisk. How do you create an AWR report?What are the options during the reportcreation process? Be aware that the ActiveSession History (ASH) is a component of theAWR, and that it focuses on current sessionactivity. You must also understand the role ofthe background processes MMON and MMNLclearly.

You must know all the default settings, likehow long the AWR retains information andhow often AWR snapshots occur. How do youchange these settings?

You must be aware of the various pages ofthe Database Control that you must traverse inorder to manage the automatic alerts in yourdatabase. You can expect a question (or more)about custom configuration of alerts using theDBMS_AQADM package (create AQ Agent,

add subscriber, and so on). The exam testsyour knowledge of the types of events thatset off server-generated alerts. What are thedefault tablespace usage alert settings? Whatare the various nonthreshold, or stateless,alerts?

The exam tests you on your knowledgeof the PL/SQL interface for alert thresholdsettings, which is the DBMS_SERVER_ALERTpackage. You must know exactly what eachof the SET_THRESHOLD parameters standsfor. How do you set the critical and warningthresholds to NULL? You must also know thedifferent components of the DBMS_ADVISORpackage that help you in creating an advisortuning session (create task, adjust taskparameters, perform analysis, and review theresults). The test checks your knowledge ofimportant data dictionary views like DBA_OUTSTANDING_ALERTS (where outstandingalerts are stored) and DBA_ALERT_HISTORY(where cleared alerts go).

INSIDE THE EXAMINSIDE THE EXAM

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 225: OCA OCP - Oracle10G New Features For Administrators Exam Guide

In the server-generated alerts section, you saw how Oracle generates automaticalerts. You learned how to use the Database Control to manage server alerts. Thechapter showed you how to set alerts using the DBMS_SERVER_ALERT package.

The chapter introduced you the Oracle’s automated tasks feature using theScheduler. You also learned about the various Oracle management advisors.You reviewed the use of the DBMS_ADVISOR package to manage the advisoryframework.

38 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 226: OCA OCP - Oracle10G New Features For Administrators Exam Guide

✓TWO-MINUTE DRILL

Types of Oracle Statistics❑ Oracle collects database statistics at the system and session level, as well as

operating system statistics.

❑ Cumulative statistics are totals of various statistics since the startup of theinstance.

❑ Both the V$SYSSTAT and V$SESSTAT views show cumulativeperformance statistics.

❑ Database metrics measure the rate of a change in a cumulative statistic.

❑ Database metrics are statistics that are derived from base statistics.

❑ The MMON background process issues database alerts and captures statisticsfor recently modified objects.

❑ The MMNL background process captures ASH history data when thememory buffer is full.

❑ ASH data is a sample of the most recent session data for all active sessions.

❑ Baseline data helps you to make meaningful comparisons of databaseperformance between two periods.

❑ If you set the STATISTICS_LEVEL parameter to BASIC, the AWR turnsoff its statistics collection.

❑ If you set the STATISTICS_LEVEL parameter to ALL, the AWR collectsall available statistics.

❑ If you set the STATISTICS_LEVEL to TYPICAL, the AWR collects whatOracle considers is a typically needed amount of statistics.

Automatic Workload Repository (AWR)❑ The AWR lies at the heart of the Oracle Database 10g self-management

framework.

❑ The AWR collects statistics in a temporary in-memory format, as well asa persistent component in the form of regular AWR snapshots.

❑ The MMON background process performs the AWR snapshots.

Two-Minute Drill 39

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 227: OCA OCP - Oracle10G New Features For Administrators Exam Guide

❑ By default, the AWR collects new snapshots every 60 minutes, but you canchange this interval.

❑ You can also collect manual snapshots yourself.

❑ You uniquely identify a snapshot by its snap ID sequence number.

❑ The AWR collects base, database feature, and object usage; ASH; operatingsystem; and other statistics.

❑ Managing the AWR snapshots enables you to manage the AWR.

❑ You can view AWR snapshot data through V$ views or theDatabase Control interface.

❑ The Manage Snapshots section of the AWR page in the Database Controllets you manage snapshots.

❑ You can use the DBMS_WORKLOAD_REPOSITORY package to create anddrop snapshots, as well as to change the settings of the RETENTION andINTERVAL parameters.

❑ A snapshot baseline consists of any pair of AWR snapshots.

❑ A preserved snapshot set shows the range of snapshots you use for an AWRbaseline.

❑ You can create and drop baselines using the DBMS_WORKLOAD_REPOSITORY package’s CREATE_BASELINE and DROP_BASELINEprocedures.

❑ By default, the AWR retains snapshot data for seven days, beforeautomatically purging the data. You may modify this default behavior.

❑ The minimum retention period for AWR data is one day.

❑ The minimum interval value for AWR data collection is ten minutes.

❑ If the SYSAUX tablespace fills up, Oracle will automatically purge the oldestset of AWR snapshots.

❑ The longer the AWR retention period, the larger you should make yourSYSAUX tablespace.

❑ The shorter the AWR snapshot interval, the larger you should make yourSYSAUX tablespace.

❑ Oracle recommends that you set your retention period according to thelength of your database workload cycle.

40 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 228: OCA OCP - Oracle10G New Features For Administrators Exam Guide

❑ If you set the value of the RETENTION parameter to zero, you disable theautomatic purging of the AWR.

❑ If you set the INTERVAL parameter to zero, you disable the automaticsnapshot collection by the AWR.

❑ Use the $ORACLE_HOME/rdbms/admin/awrrpt.sql script to produce AWRreports.

❑ The AWR reports are very similar to the old STATSPACK reports.

Active Session History (ASH)❑ The ASH collects active session statistics and stores them in the SGA.

❑ The V$SESSION view is sampled every second, and the samples are saved tothe V$ACTIVE_SESSION_HISTORY view.

❑ A database session is termed active, if either it is ON CPU or it is WAITINGfor an event that isn’t from the IDLE class.

❑ The DBA_HIST_ACTIVE_SESSION _HISTORY view maintains apermanent record of a sample of the ASH data in the V$ACTIVE_SESSION_HISTORY view.

❑ The background process MMON is responsible for flushing ASH data to diskperiodically.

❑ If the memory buffer for the ASH is full, the ASH data is flushed to disk bythe MMNL background process.

Server-Generated Alerts❑ Database metrics are the foundation for all Oracle alerts.

❑ The set of metrics for each alert depends on the targets that are covered.Threshold alerts are prompted when a database metric crosses a presetthreshold value.

❑ Threshold alerts are also called stateful alerts.

❑ Error or problem alerts, which are issued because a service or target becomesunavailable, are also called stateless alerts.

❑ When you fix the problems that prompted an alert, the alert is clearedautomatically.

❑ Threshold-based alerts are divided into warning and critical types.

Two-Minute Drill 41

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 229: OCA OCP - Oracle10G New Features For Administrators Exam Guide

42 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

❑ Default server-generated alerts may be problem alerts or threshold alerts.

❑ Oracle automatically sets thresholds on all metrics with the object typeSYSTEM.

❑ The MMON process computes metrics and decides when a threshold hasbeen crossed for a database metric.

❑ Set the STATISTICS_LEVEL parameter to TYPICAL if you wantto use the server-generated alerts feature.

❑ You can display alerts directly by subscribing as a consumer to theALERT_QUE.

❑ You can view current threshold settings by using the GET_THRESHOLDprocedure from the DBMS_SERVER_ALERT package.

❑ You can set thresholds by using the SET_THRESHOLD procedure.

❑ You can prevent any database alert from firing, by setting the critical orwarning threshold values to NULL.

❑ The procedures in the DBMS_AQADM package enable you to access the alertsin the ALERT_QUE.

❑ The REGISTER, DEQUEUE, and other procedures of the DBMS_AQpackage help you manage alert notifications.

❑ Database metrics history is maintained by the DBA_HIST_* dictionaryviews.

❑ The DBA_THRESHOLD dictionary view provides current threshold settingsfor all alerts.

❑ The DBA_OUTSTANDING_ALERTS view stores information about allpending alerts, and the DBA_ALERT_HISTORY view provides a historyof all resolved alerts.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 230: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The Automated Tasks Feature❑ The Oracle Scheduler is at the heart of the automated tasks feature.

❑ A program consists of metadata about a task.

❑ A job is any executable program.

❑ A schedule sets the execution time and frequency for a job.

❑ A window is a time period during which you schedule a job.

❑ By default, Oracle comes with a maintenance window, the GATHER_STATS_PROG program, the GATHER_STATS_JOB job, and the AUTO_TASKS_JOB_CLASS job class.

The Management Advisory Framework❑ The management advisory framework provides performance details about

various subsystems of the database.

❑ All management advisors get their raw data from the AWR repository andstore their analysis in the AWR as well.

❑ The main advisors are the ADDM, Buffer Cache Advisor, Library CacheAdvisor, SQL Access Advisor, SQL Tuning Advisor, Segment Advisor,and Undo Advisor.

❑ You can use the DBMS_ADVISOR package to run any of the advisors.

❑ To use an advisor, you create a task, define the task parameters, execute thetask, and view the recommendations.

Two-Minute Drill 43

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 231: OCA OCP - Oracle10G New Features For Administrators Exam Guide

44 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

SELF TESTThe following questions will help you measure your understanding of the material presented in thischapter. Read all the choices carefully because there might be more than one correct answer. Chooseall correct answers for each question.

Types of Oracle Statistics

1. What type of statistic is total logons?

A. Cumulative statisticB. Baseline statisticC. Database metricD. Type of sample data

2. Which of the following statements is true?

A. Base statistics are derived from database metrics.B. Metrics are derived from base statistics.C. The number of physical reads in the database is a metric.D. Cumulative statistics are derived from database metrics.

3. Which of the following Oracle background processes is responsible for updating metricstatistics?

A. MMANB. MMNLC. MMOND. MMMN

Automatic Workload Repository (AWR)

4. What is the persistent portion of the AWR represented by?

A. The statistics stored in the SGA by the AWRB. Statistics shown by the V$ dynamic performance viewsC. The AWR snapshotsD. Active Session History data

5. Which is the following is true about snapshots belonging to a baseline?

A. They are retained permanently in the database (never deleted).B. They are deleted when you drop the underlying baselines, provided you specify the

CASCADE=>TRUE option.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 232: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test 45

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

C. They are deleted immediately after you use them.D. They are deleted when you create any new snapshots.

6. Your SYSAUX tablespace is under space pressure. The AWR currently has data ranging fromsnap ID 101 to 322.Which of the following scenarios is the likeliest outcome?

A. Oracle will delete everything from the SYSAUX tablespace except the information for thesnap ID range 101 to 322.

B. Oracle will delete snapshot 101.C. Oracle will delete snapshot 322.D. Oracle will send an error message saying that it can’t create any more new AWR snapshots.

Active Session History (ASH)

7. Which of the following two statements regarding the V$ACTIVE_SESSION_HISTORY andDBA_HIST_ACTIVE_SESS_HISTORY views are correct?

A. The V$ACTIVE_SESSION_HISTORY is a collection of snapshots from the DBA_HIST_ACTIVE_SESS_HISTORY view.

B. The DBA_HIST_ACTIVE_SESS_HISTORY view is a collection of snapshots from theV$ACTIVE_SESSION_HISTORY view.

C. The V$ACTIVE_SESSION_HISTORY view shows only the current active session history.D. The V$ACTIVE_SESSION_HISTORY view shows recent active session history.

8. Which of the following statements regarding how ASH data is flushed are true?

A. The MMON process flushes ASH data to disk whenever the rolling buffer in memoryis full.

B. The MMNL process flushes ASH data to disk whenever the rolling buffer in memory is full.C. The MMON process flushes ASH data to disk automatically every 60 minutes.D. The MMNL process flushes ASH data to disk automatically every 60 minutes.

9. What will the AWR save?

A. All the ASH dataB. A part of the ASH dataC. All the active session ASH dataD. All the inactive session ASH data

Server-Generated Alerts

10. Stateful alerts are those alerts that pertain to thresholds. Stateless alerts pertain to problemalerts. Which of the following two statements are true?

A. Stateful alerts are first logged in the DBA_ALERT_HISTORY view.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 233: OCA OCP - Oracle10G New Features For Administrators Exam Guide

B. Stateful alerts are first recorded in the DBA_OUTSTANDING_ALERTS view.C. Stateless alerts are never recorded in the DBA_OUTSTANDING_ALERTS view.D. Stateful alerts are never recorded in the DBA_OUTSTANDING_ALERTS view.

11. Threshold alerts are stateful alerts. What happens when these occur?

A. Oracle will automatically clear the alert when you take care of the alert condition.B. You need to manually clear the alert after you take care of the alert condition.C. The alert can’t be cleared automatically or manually.D. The alert is automatically recorded in the DBA_ALERT_HISTORY view.

12. Which three of the following statements are correct?

A. The snapshot too old alert is a stateful alert.B. The snapshot too old alert is a stateless alert.C. The snapshot too old alert is an out-of-the-box server-generated alert.D. All stateless alerts are recorded directly in the DBA_ALERT_HISTORY view.

The Automated Tasks Feature

13. Which two of the following statements are correct?

A. The MMON background process saves metrics in the SGA.B. The AWR snapshot mechanism saves the in-memory metrics to disk.C. The AWR snapshots save metrics in the SGA.D. The MMON background process flushes metrics to the disk every hour.

14. You can set up thresholds on metrics using which view?

A. V$SYSMETRIC

B. V$DBMS_SERVER

C. DBA_SERVER

D. V$DBMS_SERVER_ALERT

14. When is subscribing to the ALERT_QUE necessary?

A. If you wish to use the server-generated alert system of the OEM Database ControlB. If you wish to set up a notification system for server-generated alertsC. If you wish to set up your own tool to display alerts, instead of using the OEM Database

Control interfaceD. For only critical alerts

46 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 234: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Lab Question 47

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

16. Which response best describes a resource plan?

A. Mandatory for every Job Scheduler windowB. Optional for any Job Scheduler windowC. Can’t be used with the Job SchedulerD. Can only be used if you also use a Job Class item

The Management Advisory Framework

17. Which of the following can you use to manage the database advisory framework?

A. DBA_ADVISOR

B. DBMS_ADVISOR

C. V$ADVISOR

D. DBMS_MANAGEMENT_ADVISORY

18. What is the first step in using PL/SQL packages to manage the advisory framework?

A. Create a task reportB. Create an advisory taskC. Execute the advisory taskD. Set the task parameters

19. What privilege do you need to execute any advisor procedures?

A. EXECUTE ANY ADVISORB. SELECT_ANY_CATALOGC. ADVISORD. SCHEMA OWNER

20. Which of the following two statements are true regarding the SQL Access Advisor?

A. It advises about the use of indexes and materialized views.B. It provides SQL tuning advice.C. It provides both SQL tuning and object access advice.D. It can be called by the ADDM.

LAB QUESTIONUse the manual method to get the ADDM results for a pair of snapshots gathered by the AWR.After the ADDM analysis, show how you would get the report. (Hint: Use the DBMS_ADVISORpackage.)

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 235: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SELF TEST ANSWERS

Types of Oracle Statistics

1. � A. The number of total logons is a cumulative statistic, because it counts all the logonssince you started the instance.� B, C, and D are wrong answers, since none of them is a cumulative statistic.

2. � B. Metrics are derived statistics, and their source is the base statistics.� A is wrong because base statistics aren’t derived from database metrics; it’s the other wayaround. C is wrong because the number of physical reads is a cumulative statistic, not a metric,which measures the rate of change, not the absolute size of a statistic. D is wrong becausecumulative statistics are derived from base statistics.

3. � C. The MMON process updates the metric statistics.� A, C, and D point to the wrong or a nonexistent background processes.

Automatic Workload Repository (AWR)

4. � C. AWR snapshots capture the persistent portion of the AWR data.� A is wrong because statistics stored in the SGA aren’t persistent. B is wrong because theV$ views show only the in-memory statistics. D is wrong because ASH data represents onlytemporary, in-memory data.

5. � B. The set of snapshots belonging to a baseline are automatically deleted when you dropthat baseline.

A is wrong because snapshots can be deleted. C is wrong because there is no automaticmechanism to drop the snapshots after using them. D is wrong because there is no connectionbetween creating new snapshots and dropping old ones.

6. � B. When you are under space pressure, Oracle ignores the default retention policy anddeletes the oldest snapshots first, to make room for new data. Snap ID 101 happens to be theoldest in this example.� A is wrong because Oracle deletes only the old snapshots first, not other data from theSYSAUX tablespace. C is wrong because the snapshot with the ID 322 is the most recent, notthe oldest snapshot in the AWR. D is wrong because while Oracle sends an error message, themessage is to inform you that there is a space problem in the SYSAUX tablespace.

48 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 236: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Active Session History (ASH)

7. � B and D. B is correct because the DBA_HIST_ACTIVE_SESS_HISTORY view shows asample of the contents of the V$ACTIVE_SESSION_HISTORY view. D is correct becausethe V$ACTIVE_SESSION_HISTORY view shows recent active session history.� A is wrong because the V$ACTIVE_SESSION_HISTORY view is the source for theDBA_HIST_ACTIVE_SESS_HISTORY view, not the other way around. C is wrong since theview shows only recent, not current active session history.

8. � B and C. The MMNL process flushes AWR data only when the memory buffers are full. Cis correct because the MMON background process is responsible for automatic flushing of ASHdata every 60 minutes, by default.� A is wrong since it is the MMNL process, not MMON, that flushes data to disk when thememory buffers are full. D is wrong because the MMNL doesn’t flush on schedule to disk—it isthe MMON process that performs the periodic flushing to disk.

9. � B. The AWR saves only a sample of the ASH data.� A is wrong because the AWR doesn’t store all of the ASH data. C is wrong because this issimilar to A. D is wrong because the ASH facility doesn’t capture inactive session data.

Server-Generated Alerts

10. � B and C. B is correct because all stateful (problem) alerts are recorded in the DBA_OUTSTANDING_ALERTS view first. C is correct because the same isn’t true for statelessalerts—they aren’t recorded in the DBA_OUTSTANDING_ALERTS view.

A is wrong because stateful alerts go into the DBA_ALERT_HISTORY view only afterthey are resolved, not when they are first reported. D is wrong since B is correct.

11. � A. When you clear a stateful (problem) error, Oracle will clear the alert automatically.B is wrong since you don’t need to manually clear alerts. C is wrong because the alerts are

cleared automatically. D is wrong because the alerts are recorded in the DBA_OUTSTANDING_ALERTS view first, not the DBA_ALERT_HISTORY view.

12. � B, C, and D. B and C are correct because the snapshot too old alert is an out-of-the-box,server-generated alert and is considered stateless. D is correct because stateless alerts are directlywritten to the DBA_ALERT_HISTORY view.

A is wrong because the error is stateless.

13. � B and D. The AWR snapshots are the means through which the MMON process flushesmetrics to disk on an hourly basis.

Self Test Answers 49

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:42 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 237: OCA OCP - Oracle10G New Features For Administrators Exam Guide

50 Chapter 4: Manageability Infrastructure

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

A is wrong because the MMON process isn’t responsible for in-memory statistics. C iswrong because the AWR doesn’t save metrics in the SGA—it saves them on disk.

The Automated Tasks Feature

14. � D. The DBMS_SERVER_ALERT view enables you to set up thresholds on metrics, usingthe SET_THRESHOLD procedure.� A, B, and C point to the wrong views.

15. � C. You must use the ALERT_QUE mechanism only if you want to set up your own tool todisplay alerts.� A is wrong because you don’t need to subscribe to the ALERT_QUE mechanism if youwish to use server-generated alerts through the Database Control. The OEM Database Controlis already a registered for the ALERT_QUE. B is wrong because you don’t need to set up alertnotification. D is wrong because the ALERT_QUE doesn’t have anything to do with criticalalerts.

16. � B. A resource manager is usually associated with a window, but a window doesn’t have touse it.� A is wrong because resource plans aren’t mandatory. C is wrong because you can useresource plans with the Scheduler. D is wrong since you don’t have to specify a Job Class inorder to use a resource plan with the Scheduler.

The Management Advisory Framework

17. � B. You must use the DBMS_ADVISOR package to manage the advisory framework.� B, C, and D point to wrong or nonexistent views and packages.

18. � B. The first step in using the DBMS_ADVISOR package, which helps you manage theadvisory framework, is to create an advisory task.� A, C, and D present the various steps in the wrong sequence.

19. � C. You must have the ADVISOR privilege to execute any advisor privileges in thedatabase.� A, B, and D provide wrong or nonexistent privileges.

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:42 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 238: OCA OCP - Oracle10G New Features For Administrators Exam Guide

20. � A and D. A is correct because the SQL Access Advisor advises you about the best accessto objects, including using indexes. D is correct since the ADDM can call any of themanagement advisors to provide an in-depth analysis of a performance problem.� B is wrong since the SQL Access Advisor doesn’t provide any direct SQL tuning advice.C is wrong for the same reason that B is a wrong answer.

LAB ANSWERFirst, define the bind variables:

SQL> VARIABLE taskname VARCHAR2(40)SQL> VARIABLE taskid NUMBER

Next, create the advisory task:

SQL> exec dbms_advisor.create_task('ADDM', :taskid, :taskname);

Then set the task parameters:

SQL> exec dbms_advisor.set_taskparameter(:taskname, 'START_SNAPSHOT',20);SQL> exec dbms_advisor.set_task_parameter():taskname, 'END_SNAPSHOT',24);

Execute the task:

SQL> exec dbms_advisor.execute_task(:taskname);

Finally, get the analysis results:

SQL> select dbms_advisor.get_task_report(:taskname)from dba_advisor_tasks twhere t.task_name=:taskname ANDt.owner=SYS_CONTEXT('USERENV', 'SESSION_USER');

Lab Answer 51

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4

P:\010Comp\CertPrs8\862-4\ch04.vpMonday, August 30, 2004 3:46:42 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 239: OCA OCP - Oracle10G New Features For Administrators Exam Guide

5Application Tuning

CERTIFICATION OBJECTIVES

5.01 Using the New Optimizer Statistics

5.02 Using the SQL Tuning Advisor

5.03 Using the SQL Access Advisor

5.04 Using the Performance Pages of theDatabase Control

5.05 Indexing Enhancements

✓ Two-Minute Drill

Q&A Self Test

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5Blind Folio 5:241

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:17 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 240: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Oracle DBAs spend a considerable amount of their time tuning resource-guzzling SQLstatements, so they can reduce the load on their databases and increase throughput.The new Automatic Database Diagnostic Monitor (ADDM) makes the identification

of these offending SQL statements considerably easier, basing its sophisticated recommendationson the performance data gathered by the Automatic Workload Repository (AWR).

This chapter introduces you to the new SQL Tuning Advisor, which helps youperform the new art of SQL profiling, whereby you help the Oracle optimizer generatebetter-tuned execution plans.

There are several changes in the way you can collect optimizer statistics, and thischapter explain these in detail. You’ll learn how to use the new SQL Access Advisorto define better access structures like indexes. Finally, you’ll learn how to use thePerformance pages of the OEM Database Control to effortlessly perform your SQLtuning exercises.

In the new database, there are several enhancements regarding the ability to skipunusable indexes, and to create and maintain hash-partitioned global indexes. Thefinal part of this chapter discusses these and other issues, such as specifying storagecharacteristics for index partitions.

Let’s start this important chapter with a summary of the changes in optimizerstatistics in Oracle Database 10g.

CERTIFICATION OBJECTIVE 5.01

Using the New Optimizer StatisticsThere are several interesting changes in the area of optimizer collection and the optimizermodes. Oracle supports only the cost-based query optimizer. The rule-based optimizer isfinally obsolete in Oracle Database 10g, although it remains as an unsupported feature.This means that the CHOOSE and RULE values are no longer supported as OPTIMIZER_MODE initialization parameters, although, technically, you can still use them. The sameis true of the CHOOSE and RULE hints as well.

Following are the important enhancements and changes in the optimizer’s behaviorand statistics collection areas.

242 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:17 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 241: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Automatic Statistics CollectionAs you learned in the previous chapter, Oracleautomatically collects optimizer statistics foryou now, using the GATHER_STATS_JOB job.Oracle uses the GATHER_DATABASE_STATS_JOB_PROC procedure to collect optimizerstatistics on an automatic basis. Oracle identifiesthe objects whose optimizer statistics it needs torefresh by using the information stored in AWR.It uses the Scheduler to run the statistics collectiontask in the predefined “maintenance window.”

GATHER_DATABASE_STATS_JOB_PROC procedure collects statistics for allobjects that have no prior statistics or have stale statistics, because a large proportionof the rows (more than 10 percent) have been modified.

You can still use the DBMS_STATS.GATHER_DATABASE_STATS procedure(with the GATHER AUTO option) to gather similar statistics yourself. However, thebig difference is that Oracle prioritizes its optimizer collection, ensuring that it collectsstatistics for objects that have stale or outdated statistics before the maintenancewindow is up.

The Cost ModelThe default cost model in Oracle Database 10g is CPU+IO. The computing of bothCPU as well as I/O usage gives the optimizer a good idea of the true cost of SQLstatements. Oracle captures the CPU information when you start the instance.

Changes in theDBMS_STATS PackageThe DBMS_STATS package has several changes,including changes in the key GATHER_DATABASE_STATS and GATHER_SCHEMA_STATS procedures. There are new values forthe GRANULARITY argument in both of theseprocedures. The GRANULARITY argument ispertinent only if the underlying table is partitioned.

AUTO is the default value for this argument. If you specify AUTO as the granularitylevel, Oracle collects global-, partition-, and subpartition-level statistics, if you use

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

Using the New Optimizer Statistics 243

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

The default value forthe OPTIMIZER_MODE initializationparameter is ALL_ROWS. The ALL_ROWSmode optimizes the throughput of thesystem, which means that it will minimizethe resource cost for executing the entireSQL statement and returning all the rows.

The automatic statisticsgathering feature is enabled by default. Ifyou wish to disable it, you can do so byexecuting the following:

DBMS_SCHEDULER.DISABLE('GATHER_STATS_JOB');

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:17 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 242: OCA OCP - Oracle10G New Features For Administrators Exam Guide

the LIST subpartitioning method (otherwise, it skips the subpartition-level statistics).If you specify GLOBAL and PARTITION as the options, Oracle doesn’t collectsubpartition-level statistics.

You have the option of running statistics collection serially or in parallel. TheDEGREE parameter of the DBMS_STATS package determines the degree of parallelism.The argument now has a new value called AUTO_DEGREE, which means that Oraclewill automatically determine the degree of parallelism. It could be 1, which impliesserial, not parallel execution, or DEFAULT_DEGREE, which is system default degreeof parallelism, based on the initialization parameters pertaining to parallelism. Oraclerecommends that you let it select the degree of parallelism based on size of the object,number of CPUs, and cetain parallelism-related initialization parameters.

Dynamic SamplingYou may, on occasion, encounter situations where you have database objects whosestatistics are suspect or are missing altogether. In cases like this, the database willcalculate if it is advantageous to estimate statistics using a small sample of the object’sdata. This feature is called dynamic sampling, and it has been available since Oracle9i.If you execute a query numerous times or if the query is very time-consuming, dynamicsampling may benefit that SQL statement, by yielding superior execution plans.

If you want to use automatic dynamic sampling in your database, set theOPTIMIZER_DYNAMIC_SAMPLING initialization parameter to at least 2 (thedefault value). If you set the level to zero, Oracle won’t perform dynamic sampling.If you set it too high, you’ll be imposing an unacceptable burden on your database.

Table MonitoringIf you use either the GATHER AUTO or STALE settings when you use the DBMS_STATSpackage, you don’t need to explicitly enable table monitoring in Oracle Database 10g;Table monitoring tracks the number of DML changes to a table since the last statisticscollection. In previous versions, you had to specify the MONITORING keyword in theCREATE (or ALTER) TABLE statement in order to enable the DBMS_STATS packageto automatically gather statistics for a table. In Oracle Database 10g, the MONITORINGand NO MONITORING keywords are deprecated. Oracle uses the DML change informationlogged in the DBA_TAB_MODIFICATIONS view to determine which objects havestale statistics. Just make sure that you set the STATISTICS_LEVEL parameter toeither the default TYPICAL or ALL setting.

244 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:18 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 243: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Statistics Collection for Dictionary ObjectsOracle Database 10g allows you to collect optimizer statistics on data dictionary tablesto enhance performance. Oracle has two basic types of dictionary objects (dictionarytables): fixed and real. All dynamic performance tables are fixed tables, since you can’talter or remove them. The real dictionary tables belong to the SYS, SYSTEM, andother schemas that own the various Oracle components.

Collecting Statistics for Fixed ObjectsOracle recommends that you gather statistics for fixed objects only once for everydatabase workload. Typically, a workload is a week for most OLTP databases. You cangather fixed object statistics by using the GATHER_DATABASE_STATS procedureand setting the GATHER_FIXED argument to TRUE (the default is FALSE).

You can also gather statistics for all fixed objects by using the new GATHER_FIXED_OBJECTS_STATS procedure of the DBMS_STATS package, as shown here:

SQL> sho userUSER is "SYS"SQL> exec dbms_stats.gather_fixed_objects_stats('ALL');

You must have the SYSDBA or ANALYZE ANY DICTIONARY system privilegeto analyze any dictionary objects or fixed objects.

If you wish, you can collect statistics for an individual fixed table by using thestandard DBMS_STATS procedures that enable table-level statistics collection. Thenyou can collect statistics for a fixed table just as would for any regular database table.

Using the New Optimizer Statistics 245

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

If you use the GATHER_DATABASE_STATS or GATHER_DATABASE_STATS procedure of the DBMS_STATSpackage with OPTIONS set to GATHERAUTO, you’ll be analyzing only those

database objects that have changed enoughto warrant fresh statistics. Make sure youhaven’t set the STATISTICS_LEVELparameter to BASIC, because this turnsoff the default table monitoring feature.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:18 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 244: OCA OCP - Oracle10G New Features For Administrators Exam Guide

246 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

Collecting Statistics for Other Dictionary ObjectsYou can collect statistics for the real dictionary tables by using one of the followingmethods:

■ Use the DBMS_STATS.GATHER_DATABASE_STATS (or GATHER_SCHEMA_STATS) procedure, by setting the GATHER_SYS argument to TRUE.Alternatively, you can use the GATHER_SCHEMA_STATS ('SYS') option.

■ Use the DBMS_STATS.GATHER_DICTIONARY_STATS procedure.

CERTIFICATION OBJECTIVE 5.02

Using the SQL Tuning AdvisorLet’s say you ask the ADDM to look into some performance problem, and you finallyfind out what ails your database: not surprisingly, poor SQL statements are slowingdown the database again. What do you do? Normally, this is where your troubles begin,because you now embark on a journey that could be highly frustrating and time-consuming. Oracle Database 10g has a much better option for you. When you needto fix bad SQL, just turn the new SQL Tuning Advisor loose. The advisor will tellyou the following:

■ How to improve the execution plan

■ Why it recommends a certain fix

■ Estimated benefits if you follow its advice

■ How to implement its recommendations (this may be the best part, as theadvisor even gives you the actual commands necessary to tune the offendingSQL statements)

Providing SQL Statements to the SQL Tuning AdvisorWhere does the SQL Tuning Advisor get the highly resource-intensive SQL statementsto conduct its analysis? You can feed the advisor SQL statements that you may gatherfrom the following sources:

■ You may create a new SQL statement or set of statements as an input forthe SQL Tuning Advisor. Especially if you are working with a developmentdatabase, this may be your best source of questionable SQL statements.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:18 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 245: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using the SQL Tuning Advisor 247

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

■ The ADDM may often recommend high-load statements.

■ You can choose a SQL statement that’s stored in the AWR.

■ You may choose a SQL statement from the database cursor cache.

If you have a set of SQL statements that you want the advisor to tune, you cancreate a SQL Tuning Set (STS), which is a set of multiple SQL statements, alongwith their execution information like the average elapsed time and bind values.Isolated SQL statements sometimes fail to capture the characteristics of your databaseworkload realistically. An STS not only captures a database workload’s informationeffectively, but also simplifies the tuning of several large SQL statements at once.Note that you can also use one or more STSs as the basis for a new STS.

How the SQL Tuning Advisor WorksOnce you hand the SQL Tuning Advisor a SQL statement or an STS to analyze, theadvisor invokes the Oracle optimizer in a new mode, called the tuning mode. As yourecall, the optimizer always tries to find the best execution plan for a statement.Unfortunately, since it needs to do this live, in production conditions, it can’t takemore than an extremely short period to devise its solution. Thus, the optimizer resortsto heuristics and other similar techniques to come up with its best estimate of a goodplan. This is the normal mode of the optimizer, where it quickly generates optimalexecution plans for SQL statements.

What if you give the optimizer enough time to conduct a full-blown analysis ofaccess paths, object characteristics, and so on?

In Oracle Database 10g, you can invoke the optimizer in the new tuning mode,wherein the optimizer conducts an in-depth analysis to improve its execution plans.Instead of mere seconds, in tuning mode, the optimizer may take several minutes tocome up with a set of recommendations, rather than an optimal SQL execution plan.These recommendations are intended to help you optimize the execution plan, alongwith the rationale for them and the expected benefit if you follow the recommendations.

Since it sometimes takes several minutes for the optimizer to work through itsanalysis in the tuning mode, use it for fixing only your highly resource-intensiveSQL statements.

When you use the Oracle optimizer in the tuning mode, it’s referred to as theAutomatic Tuning Optimizer (ATO). In this mode, you aren’t really using theoptimizer to develop quick execution plans. Your goal is to see if the ATO canimprove on the usual optimizer execution plans. The ATO lies at the heart of the

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:19 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 246: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SQL Tuning Advisor’s capability to tune SQL statements for you. Through the advisor,you can now use the Oracle optimizer in the tuning mode (the ATO) to improveSQL performance.

The ATO performs the following four tuning tasks:

■ Statistics analysis

■ SQL profiling

■ Access path analysis

■ SQL structure analysis

These tasks are described in the followingsections, along with the types of recommendationsthat the SQL Tuning Advisor makes.

Statistics AnalysisAs its first task, the ATO ensures that statisticsexist for all the objects in the SQL statement and

that those statistics are representative—that is, not stale. Accurate and up-to-datestatistics are essential for generating efficient execution plans. When it finds any tableswith missing or stale statistics, the ATO recommends collecting new statistics forthem. The ATO will also collect auxiliary information to fill in the missing statistics.If an object’s statistics are stale, it corrects them, using adjustment factors.

SQL ProfilingThe ATO collects auxiliary information to improve the execution plans. The ATO’sgoal at this stage is to verify that its own estimates of factors like column selectivityand cardinality of database objects are valid. It may use the following three verificationor validation methods to test to verify its initial estimates:

■ Dynamic data sampling Using a sample of the data, the ATO can check itsown estimates of various factors like cost and cardinality for the statement inquestion. The ATO may decide to apply correction factors to the data, if thesampling process reveals that its estimates are significantly off the mark.

■ Partial execution The ATO may partially execute a SQL statement, so itcan check if its original estimates are good enough. It compares the run-timeperformance with the expected performance (based on the execution plan).

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

248 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

The ATO performs fourtypes of analysis: statistics analysis, SQLprofiling, access path analysis, andSQL structure analysis.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:19 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 247: OCA OCP - Oracle10G New Features For Administrators Exam Guide

This feature is a bold attempt to go beyond normal collection of object statistics.Object statistics aren’t always enough; an optimizer may need more informationto get the right plan. So the ATO partially runs statements to gather statement-execution statistics to use in addition to the object statistics. Therefore, whatit is checking is not whether the estimates of column selectivity and otherfactors are correct, but whether a plan derived purely from inspection of thosestatistics is actually the best plan.

■ Past execution history statistics The ATO may also use any existinghistory of the SQL statement’s execution to determine appropriatesettings for parameters like OPTIMIZER_MODE.

If there is sufficient auxiliary informationfrom either the statistics analysis or the SQLprofiling phase, the ATO builds a SQL profile.Although we say that the ATO will “build aSQL profile,” in reality, it simply recommendsthat you create a SQL profile. A SQL profileis simply a set of auxiliary or supplementaryinformation about a SQL statement.

Once you accept the recommendation of theSQL Tuning Advisor to create a SQL profile in the tuning mode, Oracle will storethat SQL profile in the data dictionary. The Oracle optimizer, even while running inits normal mode, will use it, along with the statistics that you’ve already collected, toproduce better execution plans. Whenever you use the same SQL statement in thefuture, Oracle will automatically apply the SQL profile that you’ve created for it.

As long as you have minor changes in tableand index data and normal growth of objects,the SQL profile continues to be relevant. Overtime, you may want to refresh or replace theSQL profile for a statement by running theATO again.

One of the biggest advantages of SQL profiles is that they provide you aneffective way to tune “code that you can’t touch.” Packaged applications areusually hard to tune for DBAs, since there are limitations on accessing andmodifying code. Since the SQL profiles are saved in the data dictionary, youcan use them to tune even packaged applications.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

Using the SQL Tuning Advisor 249

The ATO may use dynamicsampling, partial statement execution, orhistorical SQL execution statistics to validateits initial estimates of cost, selectivity, andcardinality for a SQL statement.

A SQL profile isn’t thesame as a stored execution plan.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:19 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 248: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Access Path AnalysisThe ATO analyzes the potential impact of using improved access methods, such asadditional or different indexes. As you know, addition of a critical index can speed upa query substantially. But what if the new index you create affects other SQL statementsadversely? The SQL Advisor is aware of this possibility, and thus makes its index-relatedrecommendations in the following way:

■ If an index is very effective, it may recommend creating it immediately.

■ It may recommend running the SQL Access Advisor (described later inthis chapter) to make a comprehensive impact analysis of the additionof the new index.

SQL Structure AnalysisThe ATO may also make recommendationsto modify the structure, both the syntax andsemantics, in your SQL statements. Oracle willlook at typical problems like the following:

■ Design mistakes, such as a Cartesian product

■ Use of inefficient SQL constructs; for example,the NOT IN construct is known to be very slowcompared to the NOT EXISTS construct

SQL Tuning Advisor Recommendations

The SQL Tuning Advisor can recommend that you do the following:

■ Create indexes to speed up access paths

■ Accept a SQL profile, so you can generate a better execution plan

■ Gather optimizer statistics for objects with no or stale statistics

■ Rewrite queries based on the advisor’s advice

Using the SQL Tuning AdvisorYou can use the SQL Tuning Advisor with the help of Oracle database packages or withthe OEM Database Control interface. The following sections describe both techniques.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

250 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

The ATO will identify badlyconstructed SQL statements, but it doesn’tautomatically rewrite the queries for you. Inthe final analysis, you know your applicationbetter than the optimizer, and thereforeOracle only provides advice.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:19 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 249: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

Using the DBMS_SQLTUNE PackageThe DBMS_SQLTUNE package is the main Oracle Database 10g interface to tune SQLstatements. Let’s first look at how you can use the package to create and manageSQL statement tuning tasks.

To use the DBMS_SQLTUNE package, you must have the ADVISOR privilege.

Performing Automatic SQL Tuning Following are the main steps in usingthe DBMS_SQLTUNE package to tune SQL statements.

1. Create a task. You can use the CREATE_TUNING_TASK procedure tocreate a task to tune either a single statement or several statements.

2. Execute the task. You start the tuning process by running the EXECUTE_TUNING_TASK procedure.

3. Get the tuning report. By using the REPORT_TUNING_TASK procedure,you can view the results of the SQL tuning process.

EXERCISE 5-1

Use the DBMS_SQLTUNE PackageUse the DBMS_SQLTUNE package to create a simple tuning task and view the tuningreport. Your exercise can use the following structure:

SQL> declare2 tname varchar2(30);3 begin4 tname:=5 dbms_sqltune.create_tuning_task(6 sql_text=>'select count(*) from hr.employees,hr.dept');7 end;8 /

Check to make sure that your task was created by using the following query:SQL> select task_name from user_advisor_log;Get a task report by using the following statement:SQL> select dbms_sqltune.report_tuning_task('TASK_NAME') from dual;

Using the SQL Tuning Advisor 251

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:19 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 250: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing SQL Profiles Use the DBMS_SQLTUNE.ACCEPT_SQL_PROFILEprocedure to create a SQL profile based on the recommendations of the ATO.

You must have the CREATE_ANY_PROFILE privilege in order to create theSQL profile.

Managing SQL Tuning Categories Suppose you have several profiles, allsomewhat different, for a SQL statement. How does Oracle know which profile touse in a given case? All SQL profiles that you create for various SQL statements belongto specific SQL tuning categories. When a user logs in to the database, Oracle assignseach user to a specific tuning category, based on the value of the initialization parameterSQLTUNE_CATEGORY. Thus, the category name qualifies the lookup of SQL profilesby Oracle during the execution of a SQL statement.

The default value of the SQLTUNE_CATEGORY parameter is DEFAULT. Thus,any SQL profiles that belong to the default category will apply to all users who log into the database. After the user logs in, you can change the SQL tuning category forall the users by using an ALTER SYSTEM command, or you can change a session’stuning category by using an ALTER SESSION command. For example, suppose thatyou have already created the categories PROD and DEV. You can change the SQLtuning category for all users with the following command:

SQL> alter system set SQLTUNE_CATEGORY = PROD;

To change a session’s tuning category, use the following command:

SQL> alter session set SQLTUNE_CATEGORY = DEV;

Oracle will now apply all profiles under the category DEV, until you log out from thatsession. When you log in again, the default tuning category will again determine theprofiles available to your session.

252 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

The ATO will build aSQL profile only if it generates auxiliaryinformation during the statistics analysisand SQL profiling steps. If it builds a SQLprofile, it will recommend that you actually

create a SQL profile. Once you create anew SQL profile, Oracle automaticallyapplies that profile to the SQL statementwhen you next execute it.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:20 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 251: OCA OCP - Oracle10G New Features For Administrators Exam Guide

A session can change its SQL tuning category by using the ALTER SESSIONstatement shown in this section. You may also use the DBMS_SQLTUNE.ALTER_SQL_PROFILE procedure to change the SQL tuning category.

Using the Database Control to Run the SQL Tuning AdvisorTo manage the SQL Tuning Advisor from the Database Control, click the AdvisorCentral link under the Related Links group, and then click the SQL Tuning Advisorlink. You will see the main SQL Tuning Advisor page, where you can select the sourcefor the SQL statements that you want the SQL Advisor to analyze. You have a choiceof two main kinds of SQL statements:

■ Top SQL These SQL statements couldbe current top SQL statements from thecursor cache or saved high-load SQLstatements from the AWR.

■ SQL Tuning sets You can create anSTS from a set of SQL statements thatyou provide. They could be brand-newstatements, or you could get them fromAWR snapshots or baselines.

Once you click any of the four links, you’ll be taken to the data source you selected.From there, you can launch the SQL Tuning Advisor. Follow the instructions to viewthe advisor report and analyze the recommendations.

CERTIFICATION OBJECTIVE 5.03

Using the SQL Access AdvisorThe SQL Access Advisor is another useful component of the Advisory Framework. TheSQL Access Advisor primarily provides advice regarding the creation of indexes,materialized views, and materialized view logs, in order to improve query performance.The advisor recommends both bitmap indexes and B-Tree indexes. It also recommendsthe optimization of materialized views so you can “fast refresh” them and thus takeadvantage of general query rewriting.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

Using the SQL Access Advisor 253

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

There are several possiblesources for the tuning advisor’s STS input,including high-load SQL statementsidentified by the ADDM, statements in thecursor cache, statements from the AWR,a custom workload, or another STS.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:20 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 252: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

Providing Input for the SQL Access AdvisorAs in the case of the SQL Tuning Advisor, you can provide the input for the SQLAccess Advisor’s analysis from the SQL cache, the AWR, or new SQL statementsyou’ve created for testing purposes. No matter the source of the SQL workload, theSQL Access Advisor can recommend indexes and materialized views that can improvethe performance of the entire workload. Often, a well-written SQL statement mayperform poorly due to the lack of the right index or a materialized view. The advisorwill suggest appropriate indexes and view and provides you the rationale for thoserecommendations. The advisor can take into account multiple combinations ofactions to arrive at the best tuning strategy.

Here are the four main sources of a SQL Access Advisor’s workload:

■ Current and recent SQL activity, which includes statements from the SQLcache (from the V$SQL view)

■ An STS stored in the AWR

■ A user-defined workload, which enables you to test a workload before anapplication goes into production

■ An hypothetical workload you’ve created from specific schemas and tables

How the SQL Access Advisor WorksThe goal of the SQL Access Advisor is to reduce the processing time of SQL statements,by creating additional structures like indexes and/or materialized views. You can chooseto have the advisor recommend just indexes, just materialized views, or both.

The SQL Access Advisor takes into account user-defined constraints by supportingthe following:

■ Storage constraints

■ Refresh time constraints

■ Full or partial workloads

254 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

The three types of databaseobjects that the SQL Access Advisor mayrecommend that you create, drop, or retainare indexes, materialized views, and

materialized view logs. There are fourmain sources of input for the advisor: SQLcache, user-defined workload, hypotheticalworkload, and STS from the AWR.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:20 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 253: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Modes of Operation

You can operate the SQL Access Advisor in two modes:

■ Limited (partial) In the limited mode, which is more or less a reactivemode of tuning, the advisor will concern itself with only problematic or high-cost SQL statements. In these situations, the advisor makes recommendationsthat affect only the current statement or statements. Limited mode returnsquickly after processing the statements with the highest cost, potentiallyignoring statements with a cost below a certain threshold.

■ Comprehensive (full) Comprehensive analysis is more like a proactive typeof analysis. It will perform a complete and exhaustive analysis of all SQLstatements in a representative set of SQL statements, after considering theimpact on the entire workload, not just a few SQL statements. For example,a particular index may help a certain query, but may be quite detrimentalfor the entire workload’s point of view. Thus, a comprehensive analysisenables the advisor to provide better global tuning advice, but, of course,it takes a lot of time to complete.

You can also use workload filters to specify which kinds of SQL statements theSQL Access Advisor should select for analysis, from the workload it has in front ofit. For example, you may use filter options like top resource using SQL statements,specific users or tables, and so on. The workload filters enable the reduction of thescope of the SQL statements in the workload. The advisor applies these filters tofocus its tuning efforts, say, limiting its analysis to only those statements that toucha certain set of tables.

SQL Access Advisor RecommendationsFollowing are some of the specific types of recommendations made by the SQL AccessAdvisor:

■ Add new indexes or materialized views.

■ Add a new materialized view log.

■ Modify indexes or materialized views by adding columns.

■ Change an index type.

■ Drop an unused index or materialized view.

Using the SQL Access Advisor 255

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:20 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 254: OCA OCP - Oracle10G New Features For Administrators Exam Guide

256 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

Managing the SQL Access AdvisorYou can manage the SQL Access Advisor either through the OEM Database Controlor by using the DBMS_ADVISOR package. Both techniques are described in thefollowing sections.

Using the DBMS_ADVISOR PackageFollowing is a brief summary of the steps involved in using the DBMS_ADVISOR package:

1. Create and manage a task, by using a SQL workload object and a SQLAccess task.

2. Specify task parameters, including workload and access parameters.

3. Using the workload object, gather the workload.

4. Using the SQL workload object and the SQL Access task, analyze the data.

You can also use the QUICK_TUNE procedure of the DBMS_ADVISOR packageto quickly analyze a single SQL statement, without needing to go through all thesesteps. You can create tasks, prepare workloads for the SQL statement, execute thetask, save the results, and finally implement the recommendations as well. Here’s aquick example of using the QUICK_TUNE procedure:

VARIABLE task_name VARCHAR2(255);VARIABLE sql_stmt VARCHAR2(4000);EXECUTE :sql_stmt := 'SELECT COUNT(*) FROM customers

WHERE cust_region=''TX''';EXECUTE :task_name := 'MY_QUICKTUNE_TASK';EXECUTE DBMS_ADVISOR.QUICK_TUNE(DBMS_ADVISOR.SQLACCESS_ADVISOR, -

:task_name, :sql_stmt);

Using the Database Controlto Run the SQL Access AdvisorTo manage the SQL Access Advisor from theDatabase Control, click the Advisor Central linkunder the Related Links group, and then clickthe SQL Access Advisor link. You will see themain SQL Access Advisor page.

First, choose the access method—materializedview or an index—that you would like theadvisor to evaluate. You can use the AdvancedOptions section to specify the following options:

Oracle creates the newindexes in the schema and tablespacesof the table on which they are created.If a user issues a query that leads to arecommendation to create a materializedview, Oracle creates the materialized viewin that user’s schema and tablespace.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:21 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 255: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using the Performance Pages of the Database Control 257

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

■ Space Restrictions These options include setting space size limits that theadvisor’s recommendations can’t exceed. You may also limit the number ofindexes that the advisor can create.

■ Tuning Options These options prioritize the advisor’s access recommendationsby items like buffer gets, CPU time, disk reads, and elapsed time.

■ Default Storage Locations These options enable you to override the defaultlocations defined for the schema and the tablespaces.

CERTIFICATION OBJECTIVE 5.04

Using the Performance Pagesof the Database Control

As you’ve seen in prior chapters, the ADDM and the server-generated alerts provideyou with proactive database management support. The OEM Database Control is anessential part of the push by Oracle to automate most of the DBA’s job functions inOracle Database 10g. Using the Database Control, you can analyze these importantcomponents of both the database as well as system performance.

In the following sections, we’ll look at two Database Control pages that highlightthe OEM performance management features: the Database Home page and thePerformance page.

The Database Home PageThe Oracle Database Home page allows you to view the current state of the databaseby displaying various metrics that portray the overall health of the database. The OracleDatabase Home page, shown in Figure 5-1, provides a launching point for performance

tuning, as well as other management activities.Here are some of the statistics the Database

Home page shows you (in addition to the ADDMfindings):

■ CPU usage

■ Database waits

■ Top SQL statements

The three major tuningareas that the OEM Database Control willshow you are CPU and wait classes, topSQL statements, and top sessions in theinstance.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:21 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 256: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ Top user sessions

■ SQL response time

The Database Performance PageThe Database Performance page shows you the overall status of the database and helpsyou quickly identify causes of performance bottlenecks. Figure 5-2 shows the three mainitems on the Performance page:

■ Host

■ Sessions waiting and working

■ Instance throughput

Host Performance DataThe Host part of the page shows two important graphs dealing with resource use onthe host:

■ Average Run Queue This shows how hard the CPU is running. A high runqueue indicates that there is contention for CPU time. The run queue tellsyou how many processes are ready to run but are unable to do so, due to aCPU bottleneck.

■ Paging Rate This shows the rate at which the host server is writing memorypages to the swap area on disk. Paging slows down your system because of theextra I/O, and it indicates that your system is memory-bound.

Sessions Performance DataThe sessions graph shows which active sessions are on the CPU and which are waitingfor resources like locks, disk I/O, and so on. By clicking specific boxes, you can drill downto any wait that seems serious.

Oracle recommends that you start investigating waits if the level of waits is attwice the Maximum CPU line in the sessions graph.

Instance Throughput Performance DataIf your instance throughput is decreasing, along with an increasing amount of contentionwithin the database, you should start looking into tuning your database.

258 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:21 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 257: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using the Performance Pages of the Database Control 259

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

FIGURE 5-2 The Database Control Database Performance page

FIGURE 5-1 The Database Control Database Home page

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:22 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 258: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CERTIFICATION OBJECTIVE 5.05

Indexing EnhancementsThere are several index-related enhancements in Oracle Database 10g. Primary amongthem are the following:

■ Skipping unusable indexes

■ Creating and maintaining hash-partitioned global indexes

■ Using the new UPDATE INDEXES clause

Let’s start our discussion in this section with a look at enhancements in the skippingof unusable indexes.

Skipping Unusable IndexesIn previous versions of Oracle, modification of any partitions of a table using the SPLITor MERGE command, for example, left the indexes in an unusable state. In Oracle9i,the SKIP_UNUSABLE_INDEXES=TRUE parameter enabled you to avoid the indexesthat were rendered unusable. In Oracle Database 10g, the default value of this parameteris TRUE. Thus, you can guarantee that the optimizer will always ignore the unusableindexes at parse time.

When you use the SKIP_UNUSABLE_INDEXES=TRUE specification, the databasemay skip an index that it would have usedotherwise, thus leading to suboptimal executionplans. That’s why the database records thisinformation regarding the presence of unusableindexes in the alert log.

The SKIP_UNUSABLE_INDEXES parameter could be quite dangerous inpractice. The Oracle Database 10g default means that your SQL will alwaysrun, but it may be running very badly because of broken indexes. With previousreleases, you would always know about the problem immediately.

260 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

In Oracle Database 10g,the default value of SKIP_UNUSABLE_INDEXES parameter is TRUE.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:22 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 259: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using Hash-Partitioned Global IndexesUntil Oracle Database 10g, you could create only range-partitioned global indexes ontables. Now you can create hash-partitioned global indexes as well. As with the globalrange partitioning, you can use a maximum of 32 columns in the global index. Oracle’shash functions determine the values in each partition now, instead of a range of valuesin a range-partitioned global index. Oracle Database 10g assigns rows to the partitionsusing a hash function on values in the partitioning key columns.

Benefits of Hash-Partitioned Global IndexesYou can hash-partition indexes on tables, partitioned tables, and index-organized tables.This feature provides higher throughput for applications with large numbers of concurrentinsertions. In some applications, new insertions into indexes are biased heavily towardthe right side of the index. This is usually the case when you have an index on a columnthat is a monotonically increasing sequence number. You can’t avoid heavy contentionfor the index resources in such a situation, in addition to causing potential node splitting.Since the partitioning key (and the number of partitions in the index) is the primarydeterminant of in which partition the index entries are placed, it isn’t likely that amonotonically increasing sequence number would cause contention on one side of theindex. Hash-partitioned global indexes thus improve concurrency and raise throughputin OLTP systems.

For monotonically increasing key situations, range partitioning will cause contentionon the right edge of the highest range partition. Reverse keying the index will spreadthe activity, but only across the highest partition. Hash partitioning will distribute theworkload across all the index partitions, but still with contention at each index’sright edge; reverse-key hash partitioning will not only distribute the activity acrossall the partitions, but also spread it within each partition. Oracle also has more optionsavailable to it for parallel query and DML operations.

As with the hash-partitioned table, you can specify only the tablespace for thehash-partitioned indexes as part of the storage attribute.

One of the advantages of range-partitioned indexes is that you can perform partitionpruning, which makes it easy to skip irrelevent partitions. However, hash-partitionedglobal indexes overcome this disadvantage by being able to access all partitions inthe index in parallel. If you have queries with range predicates, for example, hash-partitioned indexes perform better than range-partitioned indexes.

Indexing Enhancements 261

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:22 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 260: OCA OCP - Oracle10G New Features For Administrators Exam Guide

262 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

Hash-Partition ManagementWhen you create a hash-partitioned index, you can specify each partition its owntablespace, or you can specify the total number of partitions and use the STORE INclause to allocate the hash partitions among the available number of tablespaces. If youskip the STORE IN clause, Oracle will place the hash partition in the user’s defaulttablespace. All partitions in a hash-partitioned global index share identical physicaland storage attributes.

You use the following statement for creating a hash partitioned global index, ifyou wish to specify each hash partition individually:

SQL> create index sales_hashon sales_items (sales_id) globalpartition by hash (sales_id) (

partition p1 tablespace tbs_1,partition p2 tablespace tbs_2,partition p3 tablespace tbs_3partition p4 tablespace tbs_4);

You can also create a hash partitioned global index by specifying the number of hashpartitions (4 in our example) with the optional STORE IN clause, as shown here:

SQL> create index sales_hashon sales_items (sales_id) globalpartition by hash (sales_id)

partitions 4store in (tbs_1,tbs_2,tbs_3,tbs_4);

You can’t perform the following operations on hash-partitioned global indexes:ALTER INDEX REBUILD, ALTER TABLE SPLIT INDEX PARTITION, ALTERTABLE MERGE INDEX PARTITITON, and ALTER INDEX MODIFY PARTITION.

Using the New UPDATE INDEXES ClauseIn previous versions of Oracle, when your performed DDL actions, such as adding, moving,or merging table partitions, you couldn’t explicitly specify the storage characteristics forthe associated local index. Oracle created the local indexes either in the default tablespace

or in the same tablespaces as the underlying tablepartitions. The DDL on the table partitions alsoleft the local indexes in an unusable state, forcingyou to rebuild them.

In Oracle Database 10g, you can now specifystorage attributes, as well as keep you localindexes from being rendered unusable, with thehelp of a single new clause. By using the UPDATEINDEXES clause during a partitioned table DDLstatement, you can avoid making your local

Using the new UPDATEINDEXES clause during a partitionedtable DDL command will help you do twothings: specify storage attributes for thecorresponding local index segments andhave Oracle automatically rebuild them.

P:\010Comp\CertPrs8\862-4\ch05.vpWednesday, September 15, 2004 1:09:29 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 261: OCA OCP - Oracle10G New Features For Administrators Exam Guide

indexes unusable by making Oracle automatically rebuild them, thus increasing theavailability of your database. Here’s an example of the usage of the UPDATEINDEXES clause during partitioned table DDL:

SQL> alter table MY_PARTS2 MOVE PARTITION my_part1 tablespace new_tbsp3 UPDATE INDEXES4 (my_parts_idx5 (PARTITION my_part1 TABLESPACE my_tbsp);

Note that if you don’t specify the index name in the preceding statement, Oraclewill rebuild the indexes to put them back into a usable state.

The MOVE operation is actually implemented as two separate DDL statements:first, Oracle moves the table, and then it rebuilds the index. So even though itis slow, you do end up with an efficient index.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

Indexing Enhancements 263

You must be aware of the role of the GATHER_STATS_JOB Scheduler job as well as theproper settings of the STATISTICS_LEVELparameter for optimizer statistics collection.

The certification exam tests you knowledge ofthe SQL Access Advisor and the SQL TuningAdvisor rather thoroughly. You must knowthe particular types of Oracle objects aboutwhich the SQL Access Advisor will makerecommendations. You must remember all thepossible sources of data for both of these advisors.

The exam focuses on the Automatic TuningOptimizer (ATO). What is the differencebetween the regular Oracle optimizer and theATO? You must understand each type of analysisthe ATO performs as part of the SQL tuningprocess. Review all four types of analysescarefully, paying attention to the various kindsof verification methods in the SQL profilingphase of the analysis. Know how to create a SQLprofile, as well as how Oracle uses it. When doesthe ATO recommend a SQL profile?

On the exam, don’t be surprised to see acouple of questions about using the OEMDatabase Control to manage databaseperformance. You must know the basicapproach of the Database Control regardingperformance management (CPU and waits,top SQL, and top sessions). You must practiceusing the Database Control to locate statisticsabout CPU and waits, SQL, and sessions.What’s on the Database Control DatabaseHome page? What are the three sections of theDatabase Performance page? How do you drilldown to various contention areas? Where andwhat are the Top Waiting SQL and the TopWaiting Sessions charts? How do you drill downto the Top SQL by Waits chart?

Expect a question testing your knowledge ofthe SKIP_UNUSABLE_INDEXES and/or theUPDATE INDEXES clause, both concerningOracle Database 10g enhancements to thepartitioning option. Review the benefits ofhash-partitioned global indexes.

INSIDE THE EXAMINSIDE THE EXAM

P:\010Comp\CertPrs8\862-4\ch05.vpWednesday, September 15, 2004 1:09:30 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 262: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CERTIFICATION SUMMARYThis chapter started with an overview of the enhancements and changes in the

optimizer statistics collection in Oracle Database 10g. You learned about the automaticstatistics collection process. The SQL Tuning Advisor takes away the drudgery involvedin tuning complex SQL code, and you learned how to manage this advisor usingPL/SQL packages as well as the Database Control.

You learned about the SQL Access Advisor and how you can get advice aboutproper indexes and materialized views in your database.

You saw how you could use the Database Control’s Performance page to drilldown into any performance issue of interest. You learned about the innovations inthe skip unusable indexes feature. You saw how you could specify storage characteristicsfor index partitions in the course of DDL statements. You were introduced to thenew hash-partitioned global indexes, which can reduce index contention in somespecial circumstances.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

264 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:23 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 263: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Two-Minute Drill 265

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

✓TWO-MINUTE DRILL

Using the New Optimizer Statistics❑ Rule-based optimization is now obsolete.

❑ The CHOOSE and RULE values for the OPTIMIZER_MODE parameter arenot supported in Oracle Database 10g, although you can still continue touse them.

❑ The default value for the OPTIMIZER_MODE parameter is ALL_ROWS.

❑ Oracle prioritizes its automatic statistics collection, with preference givento objects with stale or no statistics.

❑ The default cost model for the optimizer is CPU+I/0.

❑ The default value for the GRANULARITY argument is AUTO.

❑ If you specify GLOBAL and PARTITION options, Oracle doesn’t collectsubpartition-level statistics.

❑ The DEFAULT setting for the DEGREE argument means that you’ll use asystem-based degree of parallelism.

❑ Use the OPTIMIZER_DYNAMIC_SAMPLING parameter to use automaticdynamic sampling.

❑ Table monitoring is automatic in Oracle Database 10g.

❑ Oracle recommends that you collect optimizer statistics for data dictionarytables, both fixed and real.

Using the SQL Tuning Advisor❑ You can use the AWR data or the ADDM recommendations, or create your

own SQL statements to input to the SQL Tuning Advisor.

❑ A SQL Tuning Set (STS) is a set of SQL statements that you would like totune together.

❑ There are two modes for the optimizer now: normal mode and tuning mode.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:23 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 264: OCA OCP - Oracle10G New Features For Administrators Exam Guide

266 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

❑ Use the optimizer in the tuning mode only for highly resource-intensivestatements.

❑ The fours steps of a SQL Tuning Advisor job are statistics analysis, SQLprofiling, access path analysis, and SQL structure analysis.

❑ You can manage the SQL Tuning Advisor by using the DBMS_SQLTUNEpackage.

❑ You can create a new profile by using the ACCEPT_SQL_PROFILE procedure.

❑ All SQL profiles belong to a specific SQL tuning category.

❑ The default value of the SQLTUNE_CATEGORY parameter is DEFAULT.

Using the SQL Access Advisor❑ The SQL Access Advisor provides advice on creating indexes, materialized

views, and materialized view logs.

❑ The SQL Access Advisor may also recommend the dropping of unused indexes.

❑ You can use the SQL Access Advisor in a limited or comprehensive mode.

❑ You can manage the SQL Access Advisor through the DBMS_ADVISORpackage.

❑ You can use the QUICK_TUNE procedure of the DBMS_ADVISOR packageto analyze a single SQL statement.

Using the Database Control for Performance Tuning❑ Using the Database Control, you can monitor CPU, waits, top SQL, and top

sessions.

❑ The three main sections on the Database Performance page are Host, SessionsWaiting and Working, and Instance Throughput.

❑ The Host section shows the average run queue and the paging rate.

❑ The session graphs show which sessions are on CPU and which sessions arewaiting for resources.

❑ Oracle recommends investigating waits if the level of waits is at twice theMaximum CPU line in the sessions graph.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:23 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 265: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Indexing Enhancements❑ The default value of SKIP_UNUSABLE_INDEXES is TRUE.

❑ You can now use hash-partitioned global indexes.

❑ Oracle assigns rows to various partitions using a hash function on thepartitioning key column.

❑ Hash-partitioned global indexes increase concurrency, especially if the indexis on monotonically increasing sequence numbers.

❑ You can’t perform certain index maintenance operations on hash-partitionedglobal indexes.

❑ You can use the UPDATE_INDEXES clause to set storage attributes as well asto keep local indexes from being made unusable during a DDL operation.

Two-Minute Drill 267

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:24 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 266: OCA OCP - Oracle10G New Features For Administrators Exam Guide

268 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

SELF TESTThe following questions will help you measure your understanding of the material presented inthis chapter. Read all the choices carefully, because there might be more than one correct answer.Choose all correct answers for each question.

Using the New Optimizer Statistics

1. What is the default value for the OPTIMIZER_MODE initialization parameter?

A. FIRST_ROWS

B. ALL_ROWS

C. CHOOSE

D. COST

2. If you are using LIST subpartitioning and you specify the value of the GRANULARITYargument as AUTO, what statistics will Oracle collect?

A. Global statistics onlyB. Global and partition statistics onlyC. Global, partition, and subpartition statisticsD. No partitioned table statistics

3. How can you collect statistics for fixed data dictionary tables?

A. By using the DBMS_STATS.GATHER_DICTIONARY_STATS procedureB. By using the DBMS_STATS.GATHER_FIXED_OBJECTS_STATS procedureC. By using GATHER_SCHEMA_STATS with the SYS optionD. By using the statement EXEC DBMS_STATS.GATHER_FIXED_OBJECTS_

STATS('USER');

Using the SQL Tuning Advisor

4. What can you create a SQL Tuning Set (STS) from?

A. Several SQLs statements from the AWRB. One or more other STSsC. A single SQL statementD. Only the most high-load SQL statements in your database

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:24 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 267: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test 269

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

5. Which of the following is true about the SQL Tuning Advisor?

A. It automatically collects statistics if they are missing.B. It only makes recommendations to collect statistics.C. It ignores optimizer statistics completely.D. It uses only the available statistics and nothing else.

6. If you create a SQL profile, when can you use it?

A. In the tuning mode of the optimizer onlyB. In the normal mode of the optimizerC. In neither the tuning nor the normal mode of the optimizerD. Along with existing statistics, to get better SQL execution plans

7. How do you create a new SQL profile?

A. With the ACCEPT_SQL_PROFILE procedureB. With the CREATE_SQL_PROFILE procedureC. With both the ACCEPT_SQL_PROFILE and CREATE_SQL_PROFILE proceduresD. A SQL profile is automatically created each time you execute a new SQL statement.

Using the SQL Access Advisor

8. Which of the following is true about the SQL Access Advisor?

A. It will not recommend the creation of an index until it completes a full, comprehensiveanalysis.

B. It can recommend the dropping of an index during a limited mode of operation.C. It can recommend the dropping of an index during a comprehensive mode of operation.D. It can change an index type under certain conditions.

9. How can you manage the SQL Access Advisor?

A. Through the DBMS_SQLTUNE packageB. Through the DBMS_ADVISOR packageC. Through the SQL_TUNE packageD. Through the DBA_ADVISOR package

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:24 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 268: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using the Database Control for Performance Tuning

10. Oracle recommends that you start investigating database waits when what occurs?

A. The level of waits is the same as the Maximum CPU line in the sessions graph.B. The level of waits is smaller than the Maximum CPU.C. The level of waits is at twice the Maximum CPU line.D. The level of waits is slightly higher than the Maximum CPU line.

11. A high paging rate indicates that your system is what?

A. CPU-boundB. Memory-boundC. I/O-boundD. SGA-bound

12. Which three major tuning areas does Database Control provide information about?

A. CPU and wait classesB. Most-used objectsC. Top SQL statementsD. Memory usageE. Top sessions affecting the instance

13. What does the Database Control Performance Page show?

A. Host informationB. Memory usageC. CPU usageD. User activityE. Throughput information

Indexing Enhancements

14. When you have a monotonically increasing sequence number as an indexed column, which ofthe following is true?

A. Hash-partitioned global indexes are useful.B. Range-partitioned global indexes are better.C. Hash-partitioned local indexes are better.D. Range-partitioned local indexes are better.

270 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:24 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 269: OCA OCP - Oracle10G New Features For Administrators Exam Guide

15. What is the benefit of using the UPDATE INDEXES clause in an ALTER TABLE statement?

A. You can keep your indexes form being rendered unusable.B. You can specify storage attributes.C. You can update statistics on your indexes.D. You can keep your index nodes from splitting excessively.

LAB QUESTIONUse the DBMS_SQLTUNE package to do the following:

■ Create a tuning task.

■ Execute the tuning task.

■ View the tuning results.

■ Create a SQL profile, if one is recommended by the SQL Tuning Advisor.

Lab Question 271

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:24 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 270: OCA OCP - Oracle10G New Features For Administrators Exam Guide

272 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

SELF TEST ANSWERS

Using the New Optimizer Statistics

1. � B. The default optimizer mode in Oracle Database 10g is ALL_ROWS.� A, C, and D are not the correct default optimizer alternatives in Oracle Database 10g.

2. � C. If you’re using the LIST partitioning method, Oracle will collect all statistics, down tothe lowest level of granularity—the subpartition.� A, B, and D point to the wrong alternatives.

3. � B. The GATHER_FIXED_OBJECTS_STATS procedure lets you collect statistics for thefixed data dictionary tables.� A is wrong because the GATHER_DICTIONARY_STATS procedure collects only thenonfixed data dictionary tables. C is wrong as well, for the same reason as answer A. D seemscorrect, but you must specify ALL, not USER, in order to gather statistics for all the fixed tables.

Using the SQL Tuning Advisor

4. � A and B. An STS is created from any set of SQL statements, including those you getfrom the AWR. B is correct because you can create a STS from either a set of individual SQLstatements or from other STSs.� C is wrong because a single SQL statement isn’t enough to create an STS. D is wrongbecause there is no requirement that only high-load SQL statements can be included inan STS.

5. � B. The SQL Tuning Advisor only makes recommendations to collect statistics. It mightperform sampling or collect auxiliary information to help derive a SQL profile, but it doesn’tautomatically start the statistics collection process.� A is wrong because the advisor only recommends that you collect statistics. C is wrongbecause the advisor never ignores statistics. D is wrong as well, since the advisor does usequite a bit of information in addition to pure optimizer statistics.

6. � B and D. B is correct since you can use the SQL profiles only in the normal mode ofthe optimizer. D is also correct since Oracle uses the SQL profiles along with the availablestatistics.� A is wrong because you don’t use the SQL profile in the tuning mode only. C is wrongbecause you can use the SQL profiles in the normal mode by the optimizer.

7. � A. When the SQL Tuning Advisor recommends a SQL profile, you can create the profileby using the ACCEPT_SQL_PROFILE procedure.� B is wrong because there is no such procedure. C is wrong because of the same reasons as B.D is wrong since Oracle doesn’t automatically create a SQL Profile.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:24 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 271: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test Answers 273

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

Using the SQL Access Advisor

8. � C and D. C is correct because the SQL Access Advisor can recommend dropping an indexonly if you use it in the full (comprehensive) mode. D is correct because the advisor recommendsthe changing of the index type under some conditions.� A is wrong because you don’t need a full analysis for the advisor to recommend indexes.B is wrong because a limited mode of operation cannot recommend dropping of indexes andmaterialized views.

9. � B. You can manage the SQL Access Advisor by using the DBMS_ADVISOR package.� A, C, and D point to wrong or nonexistent packages.

Using the Database Control for Performance Tuning

10. � C. Oracle recommends that you investigate database waits if the level of waits in theDatabase Control graphs is at twice the Maximum CPU line.� A, B, and D specify the wrong information.

11. � B. Paging is related to memory.� A, C, and D are wrong because they really don’t have a direct bearing on paging rates.

12. � A, C, and E. The three major tuning areas that the Database Control focuses on as part ofits performance management approach are CPU and wait classes, top SQL statements, and topsessions affecting instance.� B is wrong since the Database Control doesn’t track object usage. D is wrong since memoryusage isn’t a major tuning area in the Database Control performance management approach.

13. � A, D, and E. The Database Control Performance Page contains three sections displayinghost information, user activity, and throughput information.� B and C are wrong since memory and CPU usage information aren’t shown on thePerformance Page.

Indexing Enhancements

14. � A. When you have monotonically increasing indexed column, hash-partitioned globalindexes are ideal, because they spread the column values more or less uniformly among thepartitions.� B is wrong since range-partitioned global indexes are the worst choice for this type ofindexed columns. C and D refer to local indexes, which aren’t really better than the globalindexes in this case.

15. � A and B. By using the UPDATE INDEXES clause, you can specify storage attributes aswell as keep your indexes from being rendered unusable.� C and D have nothing to do with the UPDATE INDEXES clause.

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:25 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 272: OCA OCP - Oracle10G New Features For Administrators Exam Guide

LAB ANSWERFirst, create three bind variables, to hold your query string and the task name, as shown here:

SQL> variable test_query varchar2(1000)SQL> variable test_task varchar2(1000)SQL> variable test_profile varchar2(1000)

Now insert your query into the bind variable test_query.

SQL> begin2 :test_query:='SELECT CHANNEL_ID FROM SH.SALES WHERE PROD_ID=146;';3 end;4 /

PL/SQL procedure successfully completed.SQL> begin

:test_task := DBMS_SQLTUNE.create_tuning_task (sql_text => :test_query,bind_list => SQL_BINDS(anydata.ConvertNumber(100)),user_name => 'SAM',scope => 'COMPREHENSIVE',time_limit => 60,task_name => 'test_tuning_task',description => 'Query on SALES table');end;

/

Execute the task using the EXECUTE_TUNING_TASK procedure, as follows:

SQL> begindbms_sqltune.execute_tuning_task (TASK_NAME=>:test_task);end;

View the tuning report, using the REPORT_TUNING_TASK function, as follows:SQL> select dbms_sqltune.report_tuning_task

task_name=>:test_task)from dual;

Create the SQL profile, if one is recommended by the SQL Tuning Advisor, by using the ACCEPT_SQL_PROFILE function, as shown here:

SQL> begin:test_profile := dbms_sqltune.accept_sql_profile(task_name => 'test_tuning_task');end;/

274 Chapter 5: Application Tuning

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5

P:\010Comp\CertPrs8\862-4\ch05.vpTuesday, September 14, 2004 3:23:25 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 273: OCA OCP - Oracle10G New Features For Administrators Exam Guide

6Space and Storage

ManagementEnhancements

CERTIFICATION OBJECTIVES

6.01 Proactive Tablespace Management

6.02 Reclaiming Unused Space

6.03 Using the Undo and Redo Logfile SizeAdvisors

6.04 Tablespace Enhancements

6.05 Using Sorted Hash Clusters

6.06 Copying Files Using the Database Server

✓ Two-Minute Drill

Q&A Self Test

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6Blind Folio 6:1

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:53 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 274: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

In Chapter 4, you learned about the new automatic database alerts. In this chapter, you’llsee how you can reduce space-related errors by proactively managing tablespace usage.Undo space management is tricky sometimes, especially when you run long transactions.

You can use tablespace usage alerts to manage normal tablespaces as well as the undo tablespace.

A major problem for many Oracle DBAs is how to reclaim unused space in thedatabase. You need to run SQL scripts to find out the amount of free space, andpossibly move or re-create database objects to recover the excess space. Due to thetime these database-reorganizing efforts consume, quite often, the free space is neverreclaimed. In Oracle Database 10g, you can shrink segments in line and in place.Thus, you can reclaim unused space without affecting database availability.

In this chapter, you’ll learn about the new Segment Advisor, which helps youisolate candidates for shrinking and to track segment growth over time, so youcan plan your space requirements correctly. You’ll next learn how to use the UndoAdvisor and the Redo Logfile Size Advisor. This chapter also introduces you to thenew data structure called the sorted hash cluster, which helps you store data sortedby nonprimary key columns.

You read about the new SYSAUX tablespace in Chapter 1. In this chapter, you’llget the details of creating and managing the SYSAUX tablespace. You’ll learn abouttemporary tablespaces and assigning temporary tablespace groups to users. You’ll alsolook at topics like renaming tablespaces and creating a default temporary tablespace.Large databases need large datafiles. The new bigfile tablespaces address this need byenabling the creation of large tablespaces with just a single data file. This chapterconcludes by showing you how to copy files using the database server.

Let’s start with a quick look at the new concept of proactive tablespace managementin Oracle Database 10g.

CERTIFICATION OBJECTIVE 6.01

Proactive Tablespace ManagementIn Oracle Database 10g, by default, all tablespaces have built-in alerts that notify youwhen the free space in the tablespace goes below a certain predetermined thresholdlevel. There are two default alert thresholds: critical and warning. The new backgroundprocess, MMON, is responsible for monitoring tablespace free space and sending outalerts. Oracle issues an alert each time the database crosses either one (warning orcritical) of the alert thresholds. When you clear the proactive alert by assigning

2 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:53 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 275: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

more space to the tablespace, Oracle issuesanother alert to acknowledge the fixing of theproblem.

By default, Oracle sends out a warning alertwhen your tablespace is 85 percent full and acritical alert when the tablespace is 97 percentfull. You may change these default settings, oreven turn the entire alerting mechanism off,if you so desire. The DBA_THRESHOLDS view

will provide information about the thresholds in your database.The proactive tablespace alerts come with some caveats:

■ You can’t set alerts for dictionary-managed tablespaces. You can set alertsonly for locally managed tablespaces.

■ When you take a tablespace offline or make it read-only, you must turnthe alerting mechanism off (using the DBMS_SERVER_ALERT package).You can turn the alerts back on after you change the status of thetablespaces again.

■ For the undo tablespace, the active and unexpired extents togetherconstitute the used space in that tablespace. The same default warningand critical thresholds (97 percent and 85 percent, respectively) applyto the undo tablespace as well.

You can manage the tablespace usage alerts by setting or modifying the alertthresholds. You can do this with the OEM Database Control or by using the PL/SQLpackage DBMS_SERVER_ALERT. Let’s first learn how to manage the tablespacespace usage alert using Database Control.

Using the Database Controlto Manage ThresholdsYou can use the OEM Database Control toset database-wide default thresholds. Here isa summary of the steps you need to follow touse the Database Control for this purpose:

1. From the Database Control home page,click the Manage Metrics link.

2. In the Manage Metrics page, click the EditThresholds button

Proactive Tablespace Management 3

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

If you are migrating toOracle Database 10g, Oracle turns off theautomatic tablespace alerting mechanismby default. You can use the DBMS_SERVER_ALERT package to set the alert thresholds.

If you get a snapshottoo old alert warning, you may need toincrease the size of your undo tablespace.In addition, you may consider increasingthe length of the undo retention period.Note that you’ll get a maximum of onlyone undo alert during any 24-hour period.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:53 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 276: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

3. From the Edit Thresholds page, you can set thresholds for the TablespaceUsage metric. Click the Specify Multiple Thresholds button. This will bringyou to the Specify Multiple Thresholds: Tablespace Used page. You can setthresholds for a specific tablespace from here.

Using the DBMS_SERVER_ALERT PackageYou can also use the DBMS_SERVER_ALERT package to manage database thresholds.In Chapter 4, you were introduced to two of the package’s procedures: SET_THRESHOLDand GET_THRESHOLD. Using these procedures, you can perform the following tasks:

■ Set warning and critical thresholds

■ Set database-wide default values for tablespace space usage

■ Find out the levels of the current default tablespace usage thresholds

■ Turn off the space-usage tracking mechanism for any tablespace

CERTIFICATION OBJECTIVE 6.02

Reclaiming Unused SpaceA segment’s high-water mark (HWM) shows the highest point of space usage everreached by that segment. If you have used 80 percent of a table segment’s space byinserting rows into that segment, for example, the HWM for that segment will beat 80 percent. Later on, even if you delete half the rows, the table’s HWM remains at80 percent. This has a detrimental effect on full-table scans and index scans, as Oraclewill scan the table all the way to the HWM, even if currently there is very little datain the table due to deletions over time.

A table segment with large number of deletions will thus be sparsely populated,with the deletions leading to fragmentation of the space, leaving several gaps belowits HWM level. Oracle will move the HWM lower only when you truncate all thetable rows. The only way for you to reclaim the space you allotted to a table is todrop the table altogether or truncate it.

In segments using Automatic Segment Storage Management (ASSM), youdon’t really have an HWM. Instead, there is the high HWM, above which noblocks are formatted, and the low HWM, below which all blocks are formatted.

4 Chapter 6: Space and Storage Management Enhancements

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:53 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 277: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Reclaiming Unused Space 5

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

In previous versions of Oracle, the only way to compact the unused pockets of spacein table or index segments was to move the object or redefine it. These reorganizationssometimes could be very time-consuming.

In Oracle Database 10g, you can now use the new segment-shrinking capability tomake sparsely populated segments give their space back to their parent tablespace.You can reduce the HWM, thus compacting the data within the segments. In OracleDatabase 10g, you can shrink the following types of segments:

■ Tables, including index-organized tables (IOTs)

■ Partitions and subpartitions of a table

■ Indexes

■ Materialized views and materialized view logs

Oracle handles the shrinking operation internally as an insert/delete operation.Note that any triggers on the tables will not fire when you perform the insertionsand deletions, since you are only moving the data around, not changing it. Eachbatch of insertions/deletions constitutes one transaction. When you shrink a tableto compact space, the indexes on the table remain intact and are in a usable stateafter the shrinking operation.

Restrictions on Shrinking SegmentsThe following are some restrictions that apply to shrinking segments:

■ You can’t shrink any segment that uses free lists. This means that you canonly shrink segments that use Automatic Segment Space Management.

■ You must enable row movement (for heap-organized segments). Enablingrow movement lets you specify whether Oracle can move a table row toa different location. Oracle may need to move a row, for example, duringtable compression or an update operation on partitioned data. During a

The segment-shrinkingcapability is termed an on line and in placeoperation. It’s on line because users cancontinue to access the tables during the

shrinking operation. The operation is inplace because you don’t need any duplicateor temporary database space during thesegment-shrinking operations.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:54 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 278: OCA OCP - Oracle10G New Features For Administrators Exam Guide

segment-shrinking operation, ROWIDs maychange, thus necessitating the enabling ofrow movement.

■ Even with ASSM-based segments, youcan’t shrink tables that are part of a cluster,tables with LONG columns, certain typesof materialized views, and certain types ofIOTs. You also can’t shrink tables withfunction-based indexes.

Manual Segment ShrinkingYou can use simple SQL commands to shrink segments. However, there is aprerequisite to running the command. You must first enable row movement for anysegment that you want to shrink. You can enable row movement by using the ENABLE

ROW MOVEMENT clause of the ALTER TABLEcommand, as shown here:

SQL> alter table test ENABLE ROW MOVEMENT;

Of course, if you’ve already specified theENABLE ROW MOVEMENT clause at tablecreation time, you won’t need to issue anycommands to enable row movement beforestarting the segment-shrinking operation.

By default, row movement is disabled at the segment level.

The segment-shrinking operation compacts fragmented space in the segments andoptionally frees the space.

There are two phases in a segment-shrinking operation:

■ Compaction phase During the compaction phase, the rows in a table arecompacted and moved toward the left side of the segment. You thus makethe segment dense, but the HWM remains where it was. The recovered spaceis not yet released to the tablespace. During this phase, you can issue DMLstatements and queries on a segment while it is being shrunk. Oracle holdslocks on packets of the rows involved in the DML operations. If you have

6 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

The following objects can’tbe shrunk: clustered tables, tables withLONG columns, tables with on-commitmaterialized views, tables with ROWID-based materialized views, LOB segments,IOT mapping and overflow segments, andtables with function-based indexes.

You must enable rowmovement before shrinking segmentsbecause the segment-shrinking operationmay cause the ROWIDs in heap-organizedsegments to change.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:54 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 279: OCA OCP - Oracle10G New Features For Administrators Exam Guide

any long-running queries, Oracle can read from all the blocks that havetechnically been reclaimed during the shrinking operation. Of course, thiscapability is dependent on the time interval you specified for your undoretention parameter.

■ Adjustment of the HWM/releasing space phase During the second phase,Oracle lowers the HWM and releases the recovered free space under the oldHWM to the parent tablespace. Oracle locks the object in an exclusive mode.This implies that you can’t issue any INSERT, UPDATE, and DELETEDML statements against the segment. During this phase, Oracle invalidatesany cursors referencing the segment as well. This second phase lasts for a veryshort period.

During the compacting phase, the object is online and available, but duringthe second phase, the object becomes unavailable, albeit very briefly.

The basic statement to shrink segments performs both phases of the segment-shrinking operation (first compacting, then resetting the HWM and releasing thespace) in sequence. Here’s the statement:

SQL> alter table test SHRINK SPACE;

Once you issue the ALTER TABLE table SHRINK SPACE command,Oracle will first compact the segment, and then reset the HWM level and yieldthe freed space to the tablespace.

To avoid disruption of DML activity and cursor invalidation problems,perform just the compact operations during peak levels of activity.

Since the second phase, the resetting of the HWM, will affect DML operations,you may not want to use it when a large number of users are connected to the database.Instead, you may want to issue the following command, which compacts only thespace in the segment:

SQL> alter table test SHRINK SPACE COMPACT;

This way, during peak hours, the database will merely compact the space in thesegment. During off-peak hours, you can issue the ALTER TABLE test SHRINKSPACE command, and this will finish the shrinking process by performing thesecond phase.

Reclaiming Unused Space 7

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:54 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 280: OCA OCP - Oracle10G New Features For Administrators Exam Guide

If you use the CASCADE option during asegment-shrinking operation, all the dependentsegments will be shrunk as well. For example,if you shrink a table, all the dependent indexsegments will be automatically shrunk. Here’show you specify the CASCADE option:

SQL> alter table test SHRINK SPACE CASCADE;

Shrinking SegmentsUsing the Database Control

You can easily perform all segment-shrinking operations using the OEM DatabaseControl interface. First, make sure that you have row movement enabled for thesegment you wish to shrink. You can enable row movement using the DatabaseControl, by following the links Schema, Tables, Edit Tables, then Options. Here,you can enable row movement by choosing that option for your segment.

You can shrink a table segment by first choosing the Tables link under the Schemalisting. On the Tables page, select Shrink Segments from the Actions field and clickGo. This takes you to the Shrink Segment page, shown in Figure 6-1. On this page,you can choose to shrink a segment in the two ways described in the previous section:

■ Compact segments and release space

■ Compact segments

Using the Segment AdvisorHow do you know which of your segments is a good candidate for shrinking? How doyou find out which objects have unused space that they won’t be needing in the future?

Using the new Segment Advisor, you can easily identify the segments that aregood candidates for shrinking. The Segment Advisor bases its recommendations onthe amount of fragmentation within an object. It determines whether objects haveenough space to be reclaimed, taking into account the future space requirements.It bases its estimates of the future space requirements of an object on historicaltrends. Besides helping you select candidates for shrinking, the Segment Advisor isalso helpful in sizing new database objects. The following sections describe how touse the advisor for both purposes.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

8 Chapter 6: Space and Storage Management Enhancements

If you use the ALTERTABLE table_name SHRINK SPACEcommand to shrink a table, Oracle willcompact the space, adjust the HWM, andrelease the space. If you add the COMPACTclause, Oracle will only compact the spacein the table segment.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:54 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 281: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Choosing Candidate Objects for ShrinkingYou can invoke the Segment Advisor at either the individual segment level or tablespacelevel. You can call the Segment Advisor from the Database Control’s Advisor Centralpage (from the Database Home page, click Advisor Central in the Related Links section,and then click Segment Advisor), Tablespaces page, or Schema Object page. Figure 6-2shows the main Segment Advisor page.

You can run the Segment Advisor in two modes:

■ Comprehensive analysis The Segment Advisor will perform an analysisregardless of whether there are prior statistics. If there aren’t any priorstatistics, the Segment Advisor will sample the objects before generatingits recommendations. This analysis is more time-consuming.

■ Limited analysis This analysis is based strictly on the statistics collectedon the segment. If there aren’t any statistics or an object, the advisor won’tperform any analysis.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

Reclaiming Unused Space 9

FIGURE 6-1 The Database Control Shrink Segment page

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:54 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 282: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Where does the Segment Advisor get the data for its recommendations? TheAutomatic Workload Repository (AWR) collects all space-usage statistics duringits regular snapshot collection. The Segment Advisor, to estimate future segmentspace needs, uses the growth trend report based on the AWR space-usage data.The growth trend report predicts future segment growth patterns as well as tracespast growth trends. The Segment Advisor stores its results in the AWR as well.

You must use locally managed tablespaces if you want the database to producegrowth trend reports.

Estimating Object SizeWhen you create a new database, it is customary to use spreadsheets to help you figureout how much space to allocate to new database objects like tables and indexes. Youcan now use the Segment Advisor to determine your future segment resource usage.You provide the structure of your table (column data types, column sizes, and thePCTFREE parameter’s size) or index and the number of rows, and the advisor willtell you how much space you need.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

10 Chapter 6: Space and Storage Management Enhancements

FIGURE 6-2 The Database Control Segment Advisor page

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:55 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 283: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

Using the Undo and Redo Logfile Size Advisors 11

In order to use the segment resource estimation feature, follow these steps:

1. From the Database Control home page, click the Administration tab.

2. Under the Storage section, click the Tables link.

3. Click the Create button to create a new table.

4. You’ll now be on the Create Table page. Under the Columns section, specifyyour column data types. Then click the Estimate Table Size button.

5. On the Estimate Table Size page, specify the estimated number of rows in thenew table, under Projected Row Count. Then click the Estimated Table Sizebutton. This will show you the estimated table size.

CERTIFICATION OBJECTIVE 6.03

Using the Undo and Redo Logfile Size AdvisorsThe Segment Advisor is not the only space-related advisor in Oracle Database 10g.You can also use the Undo Advisor and the Redo Logfile Size Advisor to help youmanage the undo and redo activity in your database. Let’s look at how to use theseadvisors.

The Undo AdvisorThe Undo Advisor helps you perform the following tasks:

■ Set the undo retention period

■ Set the size of the undo tablespace

You can access the Undo Advisor through the Database Control, as follows:

1. From the Database Control home page, click Administration.

2. Click the Undo Management button, which is under the Instance list.

3. From the main Undo Management page, click the Undo Advisor button inthe right corner.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:55 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 284: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The AWR collects statistics on undo activity in the database. In Oracle Database 10g,the database uses this AWR information to decide on the appropriate number ofundo segments to bring online when you start the instance. Oracle uses the sameAWR data to decide on the number of undo segments to bring online when youswitch undo tablespaces. In both cases, the ramp-up time for the database to bringundo segments online is much lower than in previous versions.

The Redo Logfile Size AdvisorYou can control database recovery time by setting the appropriate size for the mean timeto recover (MTTR) from a crash. The FAST_START_MTTR_TARGET initializationparameter determines instance recovery time after a crash.

In order to be of the optimal size, your redo log files should be set just large enoughthat the database isn’t performing more checkpoints than that required by the valueof your FAST_START_MTTR_TARGET parameter. Small log file sizes may mean thatthe database writer will be performing incremental checkpointing more frequentlythan what is dictated by your MTTR value. As you know, frequent log switchingwill tend to drive the incremental checkpoint activity, causing the database writerto perform excessive disk I/O. Ideally, this activity should be driven by the MTTRtarget rather than by log switching. So, too small a size for the redo log files couldresult in excessive checkpointing, which in turn, increases disk activity, which isdetrimental to system performance. However, if you set the redo log file size toolarge, there isn’t enough checkpointing, which makes it harder to meet your MTTRrequirements.

The Redo Logfile Size Advisor is enabled only if you set the FAST_START_MTTR_TARGET parameter.

The Redo Logfile Size Advisor will make recommendations about the smallest onlineredo log files you can use. This advisor recommends that you size your redo log filesto at least the recommended minimum size. A new column in the V$INSTANCE_RECOVERY view, OPTIMAL_LOGFILE_SIZE, shows you the optimal size of theredo log file for your FAST_START_MTTR_TARGET setting.

You can access the Redo Logfile Size Advisor through the Database Control,as follows:

1. From the Database Control home page, click Administration.

2. Under the Storage section, choose Redo Log Groups.

12 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:55 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 285: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Tablespace Enhancements 13

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

3. Select any redo log group, and then choose the Sizing Advice option fromthe Action drop-down list.

4. Click Go to get the redo log file size advice.

CERTIFICATION OBJECTIVE 6.04

Tablespace EnhancementsOracle Database 10g includes several interesting enhancements pertaining to tablespaces.These enhancements involve the management the SYSAUX tablespace, defaultpermanent tablespaces, temporary tablespace groups, and bigfile tablespaces. Let’s startour discussion with the management of the new SYSAUX tablespace.

Managing the SYSAUX TablespaceOracle Database 10g mandates the creation of the SYSAUX tablespace, which servesas an auxiliary to the SYSTEM tablespace.

Until now, the SYSTEM tablespace was the default location for storing objectsbelonging to components like the Workspace Manager, Logical Standby, OracleSpatial, Logminer, and so on. The more features the database offered, the greaterwas the demand for space in the SYSTEM tablespace. In addition, several featureshad to be accommodated in their own repositories, like the Enterprise Manager andits Enterprise Manager repository, and the Oracle Text feature with its DRSYS location.On top of all this, you had to create a special tablespace for the STATSPACK repository.

To alleviate this pressure on the SYSTEM tablespace and to consolidate all therepositories for the various Oracle features, Oracle Database 10g offers the SYSAUXtablespace as a centralized, single storage location for various database components.Using the SYSAUX tablespace offers the following benefits:

■ You have fewer tablespaces to manage, because you don’t need to createa separate tablespace for many database components. You just assign theSYSAUX tablespace as the default location for all the components.

■ There is reduced pressure on the SYSTEM tablespace, which is used asthe default tablespace for several features.

■ If you are using Real Application Clusters (RAC) with raw devices, you’llhave fewer raw devices to manage, since every tablespace under RAC requiresat least one raw device.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:55 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 286: OCA OCP - Oracle10G New Features For Administrators Exam Guide

14 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

The size of the SYSAUX tablespace depends on the size of the database componentsthat you’ll store in it. Therefore, you should base your SYSAUX tablespace sizingon the components and features that your database will use. Oracle recommendsthat you create the SYSAUX tablespace with a minimum size of 240MB.

Creating the SYSAUX TablespaceIf you use the Oracle Database Configuration Assistant (DBCA), you can automaticallycreate the SYSAUX tablespace when you create a new database, whether it is basedon the seed database or is a completely new, built from scratch, user-defined database.During the course of creating a database, the DBCA asks you to select the file locationfor the SYSAUX tablespace. When you upgrade a database to Oracle Database 10g,the Database Upgrade Assistant (DBUA) will similarly prompt you for the file information

for creating the new SYSAUX tablespace.You can create the SYSAUX tablespace

manually during database creation time. Here’sthe syntax for creating the SYSAUX tablespace(showing only the relevant parts of the CREATEDATABASE statement):

Create database mydbuser sys identified by abc1defuser system identified by uvw2xyz...sysaux datafile '/u01/oracle/oradata/mydb/sysaux01.dbf' size 500M reuse...;

You can set only the datafile location when you create the SYSAUX tablespaceduring database creation, as shown in the preceding example. Oracle sets all the

The SYSAUX tablespaceis mandatory, whether you create a newtablespace or migrate to Oracle Database 10g.

What happens if you omitthe SYSAUX creation clause from theCREATE DATABASE statement? Oraclewill create the SYSAUX tablespace anyway.Oracle will create both the SYSTEM andSYSAUX tablespaces automatically, withtheir datafiles in system-determined defaultlocations. If you are using Oracle Managed

Files (OMF), the datafile location willbe dependent on the OMF initializationparameters. If you include the DATAFILEclause for the SYSTEM tablespace, youmust use the DATAFILE clause for theSYSAUX tablespace as well, unless youare using OMF.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:55 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 287: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Tablespace Enhancements 15

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

other attributes, which are mandatory. You cannot later change the location or otherattributes with the ALTER TABLESPACE command.

Oracle requires that the SYSAUX tablespace have the following attributes:

■ Permanent

■ Read/write

■ Locally managed

■ Automatic segment space management

Altering the SYSAUX TablespaceIf you have the SYSDBA system privilege, you can alter the SYSAUX tablespace, usingthe same ALTER TABLESPACE command that you use for your other tablespaces.Here’s an example:

SQL> alter tablespace sysaux add datafile'/u01/app/oracle/prod1/oradata/sysaux02.dbf' size 500M;

Usage Restrictions for the SYSAUX TablespaceAlthough the use of the ALTER TABLESPACE command may make it seem like theSYSAUX tablespace is similar to the other tablespaces in your database, several usagefeatures set the SYSAUX tablespace apart. Here are the restrictions:

■ You can’t drop the SYSAUX tablespace by using the DROP TABLESPACEcommand during normal database operation.

■ You can’t rename the SYSAUX tablespace during normal database operation.

■ You can’t transport a SYSAUX tablespace.

Relocating SYSAUX OccupantsAs you recall, the purpose behind the creation of the SYSAUX tablespace is the needfor storing data belonging to the large number of database components in OracleDatabase 10g. What happens if you later decide that you want to move componentsout of the SYSAUX tablespace to a different tablespace? You may want to do this inresponse to a severe space pressure on the SYSAUX tablespace, for example.

You can monitor space usage of the SYSAUX tablespace occupants by using thenew data dictionary view V$SYSAUX_OCCUPANTS. Here’s the structure of this view:

SQL> desc v$sysaux_occupantsName Null? Type----------------------------------------- -------- --------------OCCUPANT_NAME VARCHAR2(64)OCCUPANT_DESC VARCHAR2(64)

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:55 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 288: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SCHEMA_NAME VARCHAR2(64)MOVE_PROCEDURE VARCHAR2(64)MOVE_PROCEDURE_DESC VARCHAR2(64)SPACE_USAGE_KBYTES NUMBER

The SPACE_USAGE_KBYTES column will tell you how much of the SYSAUXtablespace’s space each of its occupants is currently using. The MOVE_PROCEDUREcolumn tells you the specific procedure you must use in order to move a given

occupant out of the SYSAUX tablespace.Let’s say that you decide to move an occupant

of the SYSAUX tablespace into a new tablespace.You must first find out which procedure you mustuse to move this occupant, since each of theoccupants of the SYSAUX tablespace may needa separate procedure to allow this.

Here’s a simple query that demonstrates howto find out which procedure to employ for movingan occupant of the SYSAUX tablespace:

SQL> select occupant_name, move_procedure

2* from v$sysaux_occupants

OCCUPANT_NAME MOVE_PROCEDURE

---------------------------------------------------------------- ---------------

LOGMNR SYS.DBMS_LOGMNR_D.SET_TABLESPACE

LOGSTDBY SYS.DBMS_LOGSTD BY.SET_TABLESPACE

STREAMS

AO DBMS_AW.MOVE_AWMETA

XSOQHIST DBMS_XSOQ.Olapi MoveProc

SM/AWR

SM/ADVISOR

SM/OPTSTAT

SM/OTHER

STATSPACK

ODM MOVE_ODM

SDO MDSYS.MOVE_SDO

WM DBMS_WM.move_proc

ORDIM

ORDIM/PLUGINS

ORDIM/SQLMM

EM emd_maintenance.move_em_tblspc

TEXT DRI_MOVE_CTXSYS

ULTRASEARCH MOVE_WK

JOB_SCHEDULER

20 rows selected.

SQL>

16 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

You can move occupantsinto and out of the SYSAUX tablespace. Inorder to perform the move operation, youmust have the SYSDBA privilege and ensurethat tablespace is online. For each user ofthe SYSAUX tablespace, there is a specificmove procedure to effect the move.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:56 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 289: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Tablespace Enhancements 17

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

Once you find out the name of the correct procedure to employ in order tomove a SYSAUX occupant, you can perform the move itself, using the appropriate

procedure. For example, you can move theoccupant named WM in the following manner:

SQL> exec dbms_wm.move_proc('DRSYS')

This preceding MOVE statement will movethe user WM from the SYSAUX tablespaceto the DRSYS tablespace.

Renaming TablespacesIn previous versions of Oracle, a major limitation concerning tablespaces was that youcouldn’t rename a tablespace once you created it. In Oracle Database 10g, you can renametablespaces easily by using a simple command (from users to users_new in this example):

SQL> alter tablespace users rename TO users_new;

The ability to rename tablespaces saves substantial amounts of administrative timeand effort. You can rename permanent as well as temporary tablespaces.

You can now transport a tablespace even if the target database contains identicallynamed tablespaces as the source. You just need to rename the identically namedtablespaces in the target database before you start the transport of the tablespaces.

Oracle advises you not to use tablespace names as part of the filenames, sinceOracle will not rename the datafiles as part of the tablespace-renaming procedure.

If you perform recovery on a datafile whose header contains the old tablespacename, once you recover past the tablespace renaming point, the datafile header willreplace the old tablespace name with its new name.

There are some restrictions and requirements, however, in renaming tablespaces:

■ Your compatibility level must be set to 10.0 or higher.

■ You can’t rename the SYSTEM or SYSAUX tablespace, or offline tablespaces.

■ Tablespace identifiers remain the same.

■ If the renamed tablespace is the default tablespace for any user before therenaming, it will continue being the default after renaming.

■ If the tablespace is read-only, the datafile headers aren’t updated, althoughthe control file and the data dictionary are.

You can’t relocate thefollowing occcupants of the SYSAUXtablespace: STREAMS, STATSPACK, JOB_SCHEDULER, ORDIM, ORDIM/PLUGINS,ORDIM/SQLMM, and SMC.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:56 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 290: OCA OCP - Oracle10G New Features For Administrators Exam Guide

For an undo tablespace, the name change has different implications, based onwhether you used the init.ora file or the SPFILE to start the instance. If you areusing the init.ora file, Oracle writes a message stating that you should change thevalue (location) of the UNDO_TABLESPACE parameter in the init.ora file. If youused the SPFILE to start the instance, Oracle will automatically write the new namefor the undo tablespace in your SPFILE, provided you specified the tablespace nameas the undo tablespace name in your SPFILE.

Default Permanent TablespacesEvery user in an Oracle database has a default permanent tablespace, which is wherethe objects created by that user will be placed by default. For example, if the userdoesn’t specify a tablespace in a CREATE TABLE statement, that table will go intothe user’s default tablespace.

What happens when you don’t specify a default tablespace for a user? Well, inprevious versions of Oracle, the SYSTEM tablespace automatically became thedefault permanent tablespace for that user. That’s not exactly a smart thing, sinceyou don’t want just any user to start creating objects in the SYSTEM tablespace.

In Oracle Database 10g, if you don’t specify a default tablespace during user creation,the user isn’t automatically expected to use the SYSTEM tablespace as the default

tablespace. You can now create a defaultpermanent tablespace that all users will use asthe default permanent tablespace, when youdon’t specifically assign a permanent tablespaceduring user creation.

You can use the Database Control or SQLstatements (ALTER DATABASE) to designatea default permanent tablespace. You can alsospecify a default permanent tablespace during

database creation time. In the following sections, we’ll look at the different waysto designate the default permanent tablespace.

You can’t drop a default permanent tablespace without attending to somepreliminaries first. You must first assign a different tablespace as the defaulttablespace for all the users, and only then proceed to dropping the currentdefault tablespace.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

18 Chapter 6: Space and Storage Management Enhancements

The users SYS, SYSTEM,and OUTLN continue to use the SYSTEMtablespace as their default permanenttablespace. All the other users must usethe new default permanent tablespace.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:56 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 291: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Specifying the Default Tablespace During Database CreationYou can specify a default permanent tablespace during database creation by using thenew DEFAULT TABLESPACE clause. Here’s a (partial) database creation statementshowing how to use the DEFAULT TABLESPACE clause to specify a default permanenttablespace named deftbs for all users in the database:

SQL> create database mydbuser SYS identified by abc1defuser SYSTEM identified by uvw2xyzdefault tablespace deftbs datafile ……;

The DEFAULT TABLESPACE clause isn’t mandatory. If you don’t use one, Oraclewill still create the database, with the SYSTEM tablespace set as the default tablespace,as in previous versions. However, Oracle recommends that you specify the DEFAULTTABLESPACE clause explicitly, so your users aren’t forced to use the SYSTEMtablespace as their default tablespace.

Using the Database Control to Specify the Default TablespaceYou can use the OEM Database Control to quickly assign and change the defaultpermanent tablespace for your database. Here’s the procedure for designating adefault permanent tablspace using the Database Control:

1. From the Database Control home page, click Administration.

2. From the Storage Section, choose the Tablespaces link.

3. Click the tablespace you want to designate as the default permanent tablespace.If the tablespace doesn’t exist, first create it before you proceed any further.

4. From the Edit Tablespace page, select the Set As Default PermanentTablespace option in the Type section. Then click Apply.

Using SQL to Specify the Default TablespaceYou can designate any tablespace as the default permanent tablespace after databasecreation by using the ALTER TABLESPACE command, as follows:

SQL> alter database default tablespace new_tbsp;

Tablespace Enhancements 19

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:56 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 292: OCA OCP - Oracle10G New Features For Administrators Exam Guide

When you designate a default tablespace in this manner, all current users willbe assigned to the new default permanent tablespace. New users are automaticallyallotted this tablespace as their default permanent tablespace as well.

Viewing Default Tablespace InformationTo find out what the name of your current default permanent tablespace is, simpleexecute the following query, which uses the view DATABASE_PROPERTIES:

SQL> select property_value from database_properties2 where property_name='DEFAULT_PERMANENT_TABLESPACE';

PROPERTY_VALUE---------------------------USERSSQL>

Temporary Tablespace GroupsLarge transactions may sometimes run out of temporary space. Large sort jobs, especiallyon tables with many partitions, strain temporary tablespaces. Oracle Database 10gintroduces the concept of a temporary tablespace group, which actually represents a listof temporary tablespaces. Using a tablespace group, a user can utilize multiple temporarytablespaces simultaneously in different sessions.

Using temporary tablespace groups, rather than the usual single temporary tablespace,provides several benefits, including the following:

■ SQL queries are less likely to run out of sort space, because the query cannow use several temporary tablespaces for sorting.

■ You can now specify multiple default temporary tablespaces at the databaselevel.

■ Parallel execution servers in a parallel operation will efficiently utilizemultiple temporary tablespaces.

■ A single user can simultaneously use multiple temporary tablespaces indifferent sessions.

How does one go about creating a temporary tablespace group? Well, interestingly,you don’t explicitly create a temporary tablespace group. When you assign the firsttemporary tablespace to a tablespace group, you automatically create the temporarytablespace group.

20 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:56 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 293: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Characteristics of Temporary Tablespace GroupsHere are some of the main characteristics of a temporary tablespace group:

■ There is a minimum of one tablespace in a temporary tablespace group.There is no explict maximum number of tablespaces.

■ If you delete all members from a temporary tablespace group, the group isautomatically deleted as well.

■ A temporary tablespace group has the same namespace as tablespaces.

■ You can’t name a temporary tablespace thesame as the name of any tablespace group.

■ When you need to assign a temporarytablespace to a user, you can just use thetemporary tablespace group name, insteadof the actual temporary tablespace. Thisprinciple also applies when you create thedefault temporary tablespace for the database.

Creating a Temporary Tablespace GroupYou implicitly create a temporary tablespace group when you specify the TABLESPACEGROUP clause in a CREATE TABLESPACE statement, as shown here:

SQL> create temporary tablespace temp_old tempfile'/u01/oracle/oradata/temp01.dbf'

size 500Mtablespace group group1;

The preceding SQL statement will create a new temporary tablespace, temp_now,along with the new tablespace group named group1. Oracle creates the new tablespacegroup since the temporary tablespace temp_old is the first tablespace assigned to it.

You can also create a temporary tablespace group by specifying the same TABLESPACEGROUP clause in an ALTER TABLESPACE command, as shown here:

SQL> alter tablespace temp_old2 tablespace group group1;

Tablespace altered.SQL>

Tablespace Enhancements 21

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

Just as a temporarytablespace group is created when you assignthe first temporary tablespace to it, thegroup is also deleted when you remove thelast temporary tablespace from the group.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:56 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 294: OCA OCP - Oracle10G New Features For Administrators Exam Guide

In the preceding statement, since there wasn’t a prior temporary tablespace groupnamed group1, Oracle will create a new group with that name.

Creating Temporary Tablespaces Not Belonging to a GroupTo tell Oracle not to allocate a temporary tablespace to a tablespace group, specifya pair of quotation marks ('')—for the tablespace group name. Here’s an example:

SQL> create temporary tablespace temp_new tempfile 'temp_new1.f'SIZE 500m TABLESPACE GROUP '';

The preceding statement creates a temporary tablespace called temp_new, which is like thetraditional temporary tablespaces and doesn’t belong to a temporary tablespace group.

Use the TEMPFILE clause, not the DATAFILE clause, when you allocatespace to a temporary tablespace.

If you completely omit the TABLESPACE GROUP clause, you’ll create just a regulartemporary tablespace, which is not part of any temporary tablespace group, as shown inthe following example.

SQL> create temporary tablespace temp_new22 tempfile 'c:\oracle\tmp3.f' size 5M;Tablespace created.

SQL>

Adding a Tablespace toTemporary Tablespace GroupYou add a temporary tablespace to group by usingthe ALTER TABLESPACE statement. You canalso change the group a temporary tablespacebelongs to in the same way. For example, youcan specify that your new tablespace temp_newbelong to the group named group1 by issuing thefollowing command:

SQL> alter tablespace temp_new tablespace group group1;

Note that the database would create a new group with the name group1 if thatgroup did not already exist.

22 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

If you specify the NULLtablespace group (for example, CREATETEMPORARY TABLESPACE GROUP …GROUP ''), it is equivalent to the normaltemporary tablespace creation statement(without any groups).

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:57 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 295: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Setting a Group As the DefaultTemporary Tablespace for the DatabaseYou can use a temporary tablespace group as your mandatory default temporarytablespace for the database. If you issue the following command, all users without adefault tablespace can use both the temp_old and temp_new tablespaces (assumingthat they are part of the group group1) as their default temporary tablespaces.

SQL> alter database default temporary tablespace group1;Database altered.SQL>

This assigns all the tablespaces in group1 as the default temporary tablespaces for thedatabase.

Using a Temporary Tablespace GroupWhen You Create and Alter UsersWhen you create new users, you can now assign users to a temporary tablespace group,instead of the usual single temporary tablespace. Here’s an example:

SQL> create user sam identified by sam2 DEFAULT TABLESPACE users3* TEMPORARY TABLESPACE group1;

User created.SQL>

Once you create a user, you can also use the ALTER USER statement to changethe temporary tablespace group of the user. Here’s the SQL statement to do this:

SQL> alter user sam temporary tablespace group2;

Viewing Temporary Tablespace Group InformationYou can use the new data dictionary view DBA_TABLESPACE_GROUPS to managethe temporary tablespace groups in your database. Here is a simpley query on the viewthat shows the names of all tablespace groups:

SQL> select group_name, tablespace_name2 from dba_tablespace_groups;

GROUP_NAME TABLESPACE_NAME----------------------------------GROUP1 TEMP01SQL>

Tablespace Enhancements 23

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:57 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 296: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You can also use the DBA_USERS view to find out which temporary tablespacesor temporary tablespace groups are assigned to each user. Here’s an example:

SQL> select username, temporary_tablespace from dba_users;USERNAME TEMPORARY_TABLESPACE------------------------------ -----------------------------SYS TEMPSYSTEM TEMPSAM GROUP1SCOTT TEMP. . .SQL>

Bigfile TablespacesOracle Database 10g can contain up to 8 exabytes (8 million terabytes) of data. Don’tpanic, however, thinking how many milions of datafiles you need to manage in orderto hold this much data. You now have the option of creating really big tablespaces,called, appropriately, bigfile tablespaces. A bigfile tablespace (BFT) contains only onevery large file. Depending on the block size, a bigfile tablespace can be as large as 128terabytes.

In previous versions, you always had to juggle with the distinction between datafilesand tablespaces. Now, using the bigfile concept, Oracle has made a tablespace logicallyequal to a datafile, by creating the new one-to-one relationship between tablespacesand datafiles. With Oracle Managed Files, datafiles are completely transparent toyou when you use a bigfile tablespace, and you can directly deal with the tablespaceitself in many kinds of operations.

Here’s a summary of the many benefitsoffered by using bigfile tablespaces:

■ You need to create only as many datafilesas there are tablespaces. Fewer datafilesmean that you can use a smaller setting forthe DB_FILES initialization parameter.(The DB_FILES parameter determinesthe maximum number of datafiles that canbe open.)

■ You don’t need to constantly add datafiles to your tablespaces.

■ You have simplified datafile management in large databases, because you dealwith tablespaces directly, not many datafiles.

24 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

The traditional tablespacesare now referred to as smallfile tablespaces.Smallfile tablespaces are the defaulttablespaces in Oracle Database 10g.You can have both smallfile and bigfiletablespaces in the same database.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:57 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 297: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ The database has a significant increase in storage capacity, because you don’treach the maximum files limitation quickly when you use bigfile tablespaces.

■ You can set the CREATE DATABASE clause MAXDATAFILES to a lowersize, and thus reduce the size of the control file. The MAXDATAFILESparameter specifies the control file’s initial space allocation to datafileinformation.

Restrictions on Using Big File TablespacesThere are few restrictions on using bigfile tablespaces. You can use bigfile tablespacesonly if you use a locally managed tablespace with ASSM. Oracle also recommends thatyou use bigfile tablespaces along with a Logical Volume Manager (LVM) or the AutomaticStorage Management (ASM) feature, which support striping and mirroring. Otherwise,you can’t really support the massive datafiles that underlie the bigfile tablespace concept.Both parallel query execution and RMAN backup parallelization would be adverselyimpacted if you used bigfile tablespaces without striping.

To avoid creating millions of extents when you use a bigfile tablespace in a verylarge (greater than a terabyte) database, Oracle recommends that you change thedefault extent allocation policy (AUTOALLOCATE) to UNIFORM and set a very highextent size. In databases that aren’t very large, Oracle recommends that you stick tothe default AUTOALLOCATE policy and simply let Oracle take care of the extent sizing.

Locally managed undo and temporary tablespaces can be bigfile tablespaces,even if you don’t use ASSM.

Making Bigfile the Default Tablespace TypeYou can now specify bigfile as the default tablespace type during database creation.If you don’t explicitly specify bigfile as your default tablespace type, your databasewill have smallfile tablespaces as the default. Smallfile tablespaces are nothing butthe normal traditional tablespaces that you use currently in Oracle databases. Here’sa portion of the CREATE DATABASE statement showing how you specify a bigfiletablespace as the default:

create database testset default bigfile tablespace…

You can also dynamically change the default tablespace type to bigfile (or smallfile),thus making all tablespaces you subsequently create that type. Here’s an example

Tablespace Enhancements 25

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:57 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 298: OCA OCP - Oracle10G New Features For Administrators Exam Guide

that shows how to set the default tablespace type in your database to bigfile fromnow on:

SQL> alter database set default bigfile tablespace;

Once you set the default type of your tablespace, all the tablespaces you subsequentlycreate will be of the bigfile type, unless you manually override the default setting, asshown in the next section.

Creating a Bigfile Tablespace ExplicitlyIrrespective of which default type you choose—bigfile or smallfile—you can always createa bigfile tablespace by specifying the type explicitly in the CREATE TABLESPACEstatement, as shown here:

create bigfile tablespace bigtbsdatafile '/u01/oracle/data/bigtbs_01.dbf' size 100G...

In the preceding statement, the explicit specification of the BIGFILE clausewill overrirde the default tablespace type, if it was a smallfile type. Note that if yourdefault tablespace type was bigfile, then you can use the keyword SMALLFILE tooverride the default type when you create a tablespace.

When you specify the CREATE BIGFILE TABLESPACE tablespace_name clause, Oracle will automatically create a locally managed tablespace withASSM. You can specify the datafile size in kilobytes, megabytes, gigabytes, orterabytes.

Creating bigfile tablespaces on operating system platforms that don’t supportlarge files will limit tablespace capacity to the maximum file size that theoperating system can support.

Migrating Database ObjectsYou can migrate database objects from a smallfile tablespace to a bigfile tablespace orvice versa, if you are planning to change your tablespace type. You can migrate theobjects using the ALTER TABLE … MOVE or the CREATE TABLE AS SELECTcommand. Alternatively, you may use the Data Pump export and import tools to movethe objects between the two types of tablespaces, as described in Chapter 2.

26 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:57 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 299: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Tablespace Enhancements 27

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

Altering a Bigfile Tablespace’s SizeYou can use the RESIZE and AUTOEXTEND clauses in the ALTER TABLESPACEstatement to modify the size of a bigfile tablespace.

The RESIZE clause lets you resize a bigfile tablespace directly, without using theDATAFILE clause, as shown here:

SQL> alter tablespace bigtbs resize 120G;

The AUTOEXTEND clause enables automatic file extension, again without referringto the datafile. Here’s an example:

SQL> alter tablespace bigtbs autoextend on next 20G;

Note that both these space extension clauses can be used directly at the tablespacelevel, not the file level. Thus, both of these clauses provide datafile transparency—youdeal directly with the tablespaces and ignore the underlying datafiles.

Viewing Bigfile Tablespace InformationYou can gather information about the bigfile tablespaces in your database by using thefollowing data dictionary views:

■ DBA_TABLESPACES

■ USER_TABLESPACES

■ V$TABLESPACE

All three views have the new column BIGFILE, whose value indicates whethera tablespace is of the bigfile type (YES) or smallfile type (NO).

You can also use the following query to determine the default tablespace type foryour database:

SQL> select property_value2 from database_properties3* where property_name='DEFAULT_TBS_TYPE';

PROPERTY_VALUE--------------SMALLFILESQL>

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:57 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 300: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The following query helps in finding out which of your tablespaces have bigfiletablespaces:

SQL> select tablespace_name, bigfile FROM dba_tablespaces;TABLESPACE_NAME BIG----------------- --------SYSTEM NORBS NOUSERS NOTEMP NOTOOLS NOINDX NODRSYS NOSYSAUX NOBIG_TBS YES9 rows selected.SQL>

Bigfile Tablespaces and ROWID FormatsBigfile tablespaces use the extended ROWID format, and the only supported way toextract the ROWID components is by using the DBMS_ROWID package. The DBMS_ROWID package lets you create and extract the components of ROWIDs. Smallfile andbigfile tablespaces have different formats; therefore, you must specify the tablespacetype when you use the DBMS_ROWID package. You can specify the tablespace type byusing the new parameter TS_TYPE_IN, which can take the values BIGFILE andSMALLFILE.

For bigfile tablespaces, there is only a single file, with the relative file number alwaysset to 1024. The encoded block number consists of a concatenation of the datafilenumber and the data block that contains the row. For smallfile tablespaces, theROWIDs are in the format Object# - File# - Block# - Row#. For bigfile tablespaces,the format is Object# - Block# - Row#.

The encoded block number for bigfile tablespaces can be much larger than thosefor traditional smallfile tablespaces. Bigfile tablespace block numbers are relative tothe tablespace the rows belong to, and are unique as well.

If you are using bigfile tablespaces to construct an internal or externalROWID string, use the ROWID_CREATE function of the DBMS_ROWIDpackage. The relative file number (RELATIVE_FNO) will always be 1024for bigfile tablespaces.

28 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:57 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 301: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using Sorted Hash Clusters 29

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

You can use the DBMS_ROWID package to get the ROWID formats of a bigfiletablespace, as shown here:

SQL> select distinct DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID,'BIGFILE ')FROM test_rowid;

Since the ROWID formats are different for bigfile and smallfile tablespaces, thedatabase needs to know the tablespace type when it is creating and extracting ROWIDs.Several parameters belonging to the package DBMS_ROWID need to use the newinput parameter TS_TYPE_IN, which informs Oracle whether the tablespace typeis bigfile or smallfile. The TS_TYPE_IN parameter can take the values BIGFILEor SMALLFILE. It is a part of the DBMS_ROWID procedures ROWID_INFO, ROWID_BLOCK_NUMBER, and ROWID_RELATIVE_FNO.

CERTIFICATION OBJECTIVE 6.05

Using Sorted Hash ClustersSuppose you have a query that requires that the rows be returned in a specific order.You can’t specify that Oracle save the table data in the same order as the query mightrequire it to be output. Oracle bases its row placement in the table purely on storageconditions. To guarantee a specific row order, you must use an ORDER BY clause.The ORDER BY clause will return the rows in a guaranteed order, but often involvesa substantial use of memory and CPU time. Oracle Database 10g introduces the newsorted hash cluster storage scheme, which can help you retrieve sorted data faster andwith much less resource usage.

What Is a Sorted Hash Cluster?When you are dealing with a set of tables that share common columns and are frequentlyused together in queries, it is better to create a table cluster. A table cluster is a group oftables that Oracle physically stores together in the same data blocks.

For example, suppose that your employees and departments table share thedepartment_id column. When you cluster the employees and departments tables,

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:57 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 302: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Oracle stores all rows for each department from both the employees and departmentstables in the same physical location (same data blocks). A cluster key value is thevalue of the cluster key columns for a particular row. In our example, department_idis your cluster key. Since you store related rows physically together, your disk I/O willbe less and disk-access times will be faster. You might gain substantially by clusteringtables that you frequently join in many of your queries.

A hash cluster groups data according to a hash function it applies to the clusterkey value of each row. Oracle then stores all rows with identical cluster key valuestogether on disk. Hash clusters are recommended when you frequently use equalityqueries (for example, return all rows for dept_id=20). Oracle hashes the cluster keyvalue, and the hashed key value will point directly to the area on disk where therows are stored.

In a sorted hash cluster, rows corresponding toindividual values of the hash function are sortedon specific columns. The rows are organized aslists of sorted rows, with each list correspondingto a separate value of the hash key column. Eachlist will then have its rows sorted in the orderspecified by the sort key columns. In other words,the table’s rows are already presorted by the sortkey column.

Here are some of the main features of sortedhash clusters:

■ You can create indexes on sorted hash clusters.

■ You must use the cost-based optimizer, with up-to-date statistics on thesorted hash cluster tables.

■ You can insert row data into a sorted hash clustered table in any order, butOracle recommends inserting them in the sort key coumn order, since it’smuch faster.

Defining Sort Hash ClustersIn order to define a sorted hash cluster, you must first create the cluster itself, and thencreate the actual table or tables that are part of the cluster. Let’s look at both of these steps.

30 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

The selection of the orderkey column for a sorted hash clusteris important, since you would needadditional sorting when you use anORDER BY clause on a suffix of thesort key columns. The same is truewhen you use nonsorted key columns.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:57 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 303: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Creating the ClusterWhen you create a regular hash cluster, youneed to specify only the cluster key. To create asorted hash cluster, you must specify an additionalsort key as well. Thus, the sort hash cluster hastwo keys: the cluster key and the sort key. Here’sthe statement that creates a cluster calledmessage_cluster:

SQL> create cluster call_cluster2 (call_number NUMBER3 , call_timestamp NUMBER SORT4 , call_duration NUMBER SORT)5 hashkey 100006 single table hash is order_number7 size 50;Cluster created.

SQL>

In the call_cluster cluster, the cluster key is call_number, and the combination ofcall_time and call_duration is the sort key. SIZE indicates the space in bytes that isnecessary to store the cluster key metadata.

Creating Cluster TablesIn order to define a table as part of the sorted hash cluster, you must use the CLUSTERclause when you create the table. You must also ensure that the table’s cluster keycolumns and sort key columns are specified in the same order as in the parent cluster.Here’s a simple example, showing the creation of the calls table, based on the call_cluster cluster created in the previous section.

SQL> create table calls2 (call_number NUMBER3 , call_timestamp NUMBER4 , call_duration NUMBER5 , call_info VARCHAR2(50))6 CLUSTER call_cluster7 (origin_number,call_timestamp,call_duration);

Table created.SQL>

Using Sorted Hash Clusters 31

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

For a given cluster keyvalue, the cluster can return the rows inascending or descending order. If you wantto retrieve rows in ascending order, theORDER BY clause isn’t mandatory.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:58 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 304: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The calls table is linked to the call_cluster cluster with the keyword CLUSTER.This table stores the call records for a company, with the origin_number columnrepresenting the originating telephone number. The calls from each originatingnumber are processed during the preparation of customer bills. The idea is that bystoring them in a sorted hash cluster, it is easy to process the bills on a first-in, first-out basis, if they are already sorted on the sort key, consisting of the call_timestampand call_duration columns.

In our example, if you wanted to query the orders table for a certain order_number(the cluster key), the cluster key value is hashed to its metadata entry in the sortedhash cluster segment. This provides the sorted list of rows for that particular hashkey column.

CERTIFICATION OBJECTIVE 6.06

Copying Files Using the Database ServerYou normally use UNIX or Windows utilities to copy or move binary files. OracleDatabase 10g introduces a new way to copy files using the database server itself.By using this new file-copy method, you bypass the operating system altogether.The DBMS_FILE_TRANSFER package helps you copy binary files to a differentlocation on the same server or transfer files between Oracle databases.

Both the source and destination files should be of the same type, eitheroperating system files or ASM files.

File Copy RequirementsThere are a few prerequisites that you must satisfy in order to use the DBMS_FILE_TRANSFER package to copy files locally or remotely:

■ The maximum file size is 2 terabytes, and the file must be in multiples of 512bytes.

■ You can’t perform any character set conversion during the copy process.

■ All nonprivileged users of the database must have explicit privileges beforethey can access a file created by using DBMS_FILE_TRANSFER.

32 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:58 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 305: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Let’s see how you can use the DBMS_FILE_TRANSFER package to performvarious types of file-copy procedures.

Copying Files on a Local SystemIn order to copy files on a local file system, you must use the COPY_FILE procedureof the DBMS_FILE_TRANSFER package. In the following example, a file namedexm_old.txt is being copied from the /u01/App/Oracle directory to the /u01/App/Oracle/Example directory on the same server. In the process of copying the file, itsname is changed to exm_new.txt.

First, you must first create the necessary directories: one for the source and theother for the destination directory. You can use the following commands to createthe directories:

create directory source_dir as '/u01/app/oracle';create directory dest_dir as '/u01/app/oracle/example';

Once you create the directories, you must run the DBMS_TRANSFER.COPY_FILE procedure to copy the file from the source to the destination directory. Here’sthe code:

begindbms_file_transfer.copy_file(source_directory_object => 'SOURCE_DIR',source_file_name => 'exm_old.txt',destination_directory_object => 'DEST_DIR',destination_file_name => 'exm_new.txt');

end;

A user other than the SYSTEM user must have the READ privilege on thesource directory and the WRITE privilege on the destination directory inorder to execute the DBMS_TRANSFER.COPY_FILE procedure.

Transferring a File to a Different DatabaseIn the previous section, you saw how you can copy files on a local system. You can alsotransfer files to make copies of local files on a remote file system. You use the PUT_FILE procedure of the DBMS_FILE_TRANSFER package to perform this remote filetransfer.

Copying Files Using the Database Server 33

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:58 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 306: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Let’s use a simple example to demonstrate this interserver file-transfer capability.As when you copy files on a local system, you first need to create the source anddestination directories. Then execute the PUT_FILE procedure as follows:

begindbms_file_transfer.put_file(source_directory_object => 'SOURCE_DIR',source_file_name => 'exm_old.txt',destination_directory_object => 'DEST_DIR',destination_file_name => 'exm_new.txt'destination_database => 'US.ACME.COM');

end;

The preceding example uses the DESTINATION_DATABASE clause, whichenables you to transfer datafiles from your local server to another database. In orderto transfer a file the other way around, you must replace the PUT_FILE procedurewith the GET_FILE procedure.

You can monitor the progress of all your file-copy operations using the V$SESSION_LONGOPS view. You may also use the Oracle Scheduler to schedule the file-copyoperations.

CERTIFICATION SUMMARYThis chapter started with a review of proactive tablespace alerts. You then learned

about the new feature that allows you to reclaim space by shrinking segments. Next,you saw how to use the Segment Advisor to estimate the size of database objects aswell as perform other useful tasks. You also quickly reviewed the two space-relatedadvisors: the Redo Logfile Size Advisor and the Undo Advisor.

The major portion of this chapter was spent discussing several interesting tablespace-related features, including the ability to rename tablespaces, the mandatory SYSAUXtablespace, the use of temporary tablespace groups, and default permanent tablespaces.You also learned how the new bigfile tablespaces can make your job a lot easier whenyou are dealing with very large databases.

Next, the chapter discussed sorted hash clusters, which reduce the need to sort data.Lastly, you were introduced to the new Oracle Database 10g feature that enables youto copy files directly through the database server.

34 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:58 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 307: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

Copying Files Using the Database Server 35

The certification exam asks you several questionsabout the new tablespace enhancements inOracle Database 10g. Expect at least onequestion on the new SYSAUX tablespace,probably about the process of relocatingoccupants in and out of that tablespace.What are the special features (restrictions)of a SYSAUX tablespace, compared with anormal tablespace (you can’t rename, drop,or transport a SYSAUX tablespace).

You must understand how to use the advisorthat will help you perform segment shrinking(the Segment Advisor). You must also knowthe prerequisites for a segment-shrinkingoperation. Of course, you are going to see aquestion or two testing your knowledge ofthe difference between the SHRINK SPACEcommand with and without the COMPACToption. When does Oracle compact space, andwhen does it adjust the high-water mark andrelease space held by a compacted object?

The test focuses on the new temporarytablespace group concept. The test expects youto know the properties of temporary tablespacegroups. You must also know how to create

temporary tablespace groups, as well as assignand deassign temporary tablespaces to temporarytablespace groups. Expect a question on thenew bigfile tablespace type. Specifically, youmust be aware of what the Oracle Database10g default tablespace type is and how tochange it.

You must remember that you can now createa default permanent tablespace in OracleDatabase 10g. The test may examine yourunderstanding of the DEFAULT TABLESPACEcommand to create a permanent defaulttablespace during database creation. How do youalter the current default permanent tablespace?What is the default permanent tablespace whenyou create a new database using the DatabaseConfiguration Assistant (DBCA)?

The tablespace renaming feature is newin Oracle Database 10g, and the exam maytest your understanding of when you can andcannot rename tablespaces. What are the bestpractices for tablespace renaming?

You must also understand how to use theRedo Logfile Size Advisor to configure optimalonline redo log file sizes.

INSIDE THE EXAMINSIDE THE EXAM

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:58 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 308: OCA OCP - Oracle10G New Features For Administrators Exam Guide

✓TWO-MINUTE DRILL

Proactive Tablespace Management

❑ All Oracle Database 10g tablespaces have built-in alerts.

❑ The warning tablespace alert is when the tablespace is 85 percent full,and the critical alert is at 97 percent full.

❑ Use the DBMS_SERVER_ALERT package to set alert thresholds.

❑ Use the SET_THRESHOLD and GET_THRESHOLD procedures to managedatabase thresholds.

❑ You can set alert thresholds for only locally managed tablespaces.

Reclaiming Unused Space

❑ The high-water mark (HWM) is the highest point of space usage everreached by a segment.

❑ You can use the new segment-shrinking capability to make segments releasespace that is fragmented or empty.

❑ You can shrink tables, indexes, partitions, subpartitions, materialized views,and materialized view logs.

❑ Segment shrinking in Oracle Database 10g is on line and in place.

❑ After a table-shrinking operation, the indexes are intact and in a usable state.

❑ You can shrink only segments in ASSM managed tablespaces

❑ You must first enable row movement before you can shrink a table, becauseROWIDs could change during a shrinking operation.

❑ By default, row movement is disabled at the segment level.

❑ You perform a segment-shrinking operation in two stages: compacting dataand releasing the space.

❑ DML statements can continue during the first stage, but not during thesecond stage of shrinking a segment.

❑ Oracle recommends that you don’t perform the second stage of a segment-shrinking operation during busy periods.

❑ Use the CASCADE option to shrink all the dependent objects of a segment.

36 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:58 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 309: OCA OCP - Oracle10G New Features For Administrators Exam Guide

❑ You can run the Segment Advisor in the comprehensive or limited mode.

❑ To estimate future space needs, the Segment Advisor uses the growth trendreports.

Using the Undo and Redo Logfile Size Advisors

❑ The Undo Advisor helps you set the undo retention period.

❑ You can also set the size of the undo tablespace with the help of the UndoAdvisor.

❑ The FAST_START_MTTR_TARGET parameter sets the instance recovery time.

❑ Too small redo log files relative to the MTTR setting lead to excessivecheckpointing.

❑ If the redo log files are too large, there isn’t enough checkpointing.

❑ You have optimally sized redo logs when the database isn’t performing anymore checkpointing than that required by the FAST_START_MTTR_TARGET parameter.

Tablespace Enhancements

❑ The SYSAUX tablespace is auxiliary to the SYSTEM tablespace and holdsdata belonging to various Oracle components.

❑ The SYSAUX tablespace is mandatory in Oracle Database 10g.

❑ If you don’t create a SYSAUX tablespace, Oracle will create one by default.

❑ The SYSAUX tablespace keeps the pressure low on the SYSTEM tablespaceand makes it easier to manage the various database components.

❑ A SYSAUX tablespace must be read/write, permanent, locally managed, anduse ASSM.

❑ You can’t drop or rename the SYSAUX tablespace during normal tablespaceoperations.

❑ You must use a specific “move procedure” to move an occupant of the SYSAUXtablespace to a different tablespace.

❑ You can rename a tablespace by using the ALTER TABLESPACE command.

❑ You can’t rename the SYSTEM, SYSAUX, and offline tablespaces.

❑ You may specify a default permanent tablespace during database creation.

Two-Minute Drill 37

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:58 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 310: OCA OCP - Oracle10G New Features For Administrators Exam Guide

❑ You can use multiple temporary tablespaces simultaneously in various sessions,by using the temporary tablespace group concept.

❑ You create a temporary tablespace group automatically when you assign atemporary tablespace to it.

❑ A user can use multiple temporary tablespaces in different sessions.

❑ A bigfile tablespace consists of only a single large file.

❑ In a bigfile tablespace, there is a one-to-one relationship between a datafileand a tablespace.

❑ If you use bigfile tablespaces, you can reduce the value of the MAXDATAFILESclause during database creation and use a smaller setting for the DB_FILESinitialization parameter.

❑ Oracle recommends using bigfile tablespaces with file systems that supportstriping and mirroring.

❑ You can have bigfile and smallfile tablespaces together in the same database.

❑ The default tablespace for a database continues to be the traditional smallfiletablespace.

❑ You use the DBMS_ROWID package to extract the ROWID components ofbigfile tablespaces.

❑ You must use a new parameter called TS_TYPE_IN in the DBMS_ROWIDprocedures. The new parameter will help you determine the tablespace type.

❑ The encoded block number in the ROWIDs can be much larger for bigfiletablespaces.

Using Sorted Hash Clusters

❑ Sorted hash clusters enable the retrieval of sorted data faster than using anORDER BY clause.

❑ A hash cluster groups data according to a hash function it applies to thecluster key value of each row.

❑ The table rows are organized as lists of sorted rows, with each row correspondingto a separate value of the hash column.

❑ You would still need to use an ORDER BY clause on a suffix of the sort keycolumns.

38 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:58 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 311: OCA OCP - Oracle10G New Features For Administrators Exam Guide

❑ Before you can create the tables that are part of a cluster, you must create thecluster itself.

❑ If you want to retrieve data in ascending order, the ORDER BY clause isn’tmandatory.

❑ Oracle recommends inserting hash cluster table data in the sort key columnorder.

Copying Files Using the Database Server

❑ You can use the DBMS_FILE_TRANSFER package to transfer files betweentwo databases or two different servers.

❑ Both the source and destination files should be of the same type.

❑ Use the COPY_FILE procedure to copy files on a local system.

❑ Use the PUT_FILE and GET_FILE procedures to perform file transfersto and from a database on a remote file system.

❑ You can use the Scheduler facility to schedule file-transfer operations.

Two-Minute Drill 39

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:59 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 312: OCA OCP - Oracle10G New Features For Administrators Exam Guide

40 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

SELF TESTThe following questions will help you measure your understanding of the material presented in thischapter. Read all the choices carefully, because there might be more than one correct answer. Chooseall correct answers for each question.

Proactive Tablespace Management

1. For which two types of tablespaces can you set proactive tablespace alerts?

A. Locally managedB. Dictionary-managedC. Read-onlyD. Online

2. Which of the following is true about alerts?

A. You’ll get a maximum of one undo alert per every 12-hour period.B. You’ll get a maximum of one undo alert during a 24-hour period.C. You’ll get a maximum of one tablespace alert during a 124-hour period.D. You’ll get a maximum of one tablespace alert during a 24-hour period.

3. Which one of the following is responsible for sending out tablespace alerts?

A. DBMS_SERVER_ALERT packageB. MMON background processC. Database ControlD. Scheduler

Reclaiming Unused Space

4. Which of the following segments cannot be shrunk?

A. Heap-organized table segmentsB. Index-organized table segmentsC. Index segmentsD. Undo segments

5. The DBA issues the following command:

SQL> alter table test SHRINK SPACE

Which of the following would be the result of this statement?

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:59 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 313: OCA OCP - Oracle10G New Features For Administrators Exam Guide

A. There would be immediate release of the free space.B. There would be only a compacting of the data, not a release of data.C. There would be no impact on DML operations in the database.D. There would be an impact on the DML operations in the database.

6. What is the first step before you start shrinking a segment?

A. Make sure there are indexes on all the table segments.B. Enable row movement for any segment you want to shrink.C. Disable row movement for any segment you want to shrink.D. Issue the ALTER TABLE … COMPACT command.

Using the Undo and Redo Logfile Size Advisors

7. What does the Undo Advisor help you do?

A. Set the undo retention periodB. Set the undo intervalC. Set the size of the undo tablespaceD. Figure out the number of undo segments you must create

8. What does the initialization parameter FAST_START_MTTR_TARGET determine?

A. The instance recovery timeB. The database restore timeC. The number of redo log groupsD. The undo retention period

9. Which of the following is true of optimally sized redo log files?

A. They should perform very frequent checkpointing.B. They should perform very infrequent checkpointing.C. The amount of checkpointing isn’t related to the size of the redo log file.D. They should perform just the right amount of checkpointing as that required by your MTTR.

Tablespace Enhancements

10. If you don’t explicitly specify the SYSAUX tablespace during database creation, what happens?

A. The database creation will fail.B. Oracle will create a default SYSAUX tablespace.

Self Test 41

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:59 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 314: OCA OCP - Oracle10G New Features For Administrators Exam Guide

42 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

C. Oracle will create a default SYSTEM tablespace.D. Oracle will let you create a SYSAUX tablespace later on.

11. Which one of the following is true when you rename a default permanent tablespace for a user?

A. You’ll need to create a new default tablespace for the user before you can do anything.B. The tablespace will continue to be the default tablespace after you rename it.C. You must first remove all the current users from the tablespace.D. You can’t rename a default permanent tablespace.

12. Which of the following statements is true when you are considering dropping the currentdefault permanent tablespace for the database?

A. You’ll first need to first reassign another tablespace as the new default (permanent)tablespace for the database.

B. The original tablespace will continue to be the default tablespace.C. You must first remove all the current users from the tablespace.D. You can’t drop a default permanent tablespace.

13. Which one of the following is true regarding tablespace types?

A. If you create a database with bigfile set as the default tablespace type, you can’t convertlater to smallfile tablespaces.

B. If you create a database with smallfile set as the default tablespace type, you can’t convertlater to bigfile tablespaces.

C. It doesn’t matter what default type of tablespace you create a database with; you can changethe default tablespace type anytime you wish.

D. You can’t switch the tablespace type once you create a database.

14. To avoid a large number of extents for bigfile tablespaces in very large databases, which of thefollowing does Oracle recommend that you do?

A. Use the UNIFORM clause for allocating new extents and set a very high extent size.B. Use the AUTOALLOCATE clause and simply let Oracle take care of the extent sizing.C. Use the AUTOALLOCATE clause for allocating new extents and set a very high extent size.D. Use the UNIFORM clause and simply let Oracle take care of the extent sizing.

Using Sorted Hash Clusters

15. Which of the following is true regarding creating tables for a sorted hash cluster?

A. You must first create the hash cluster before you create the member tables.B. You must create the member tables before you create the cluster.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:59 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 315: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Lab Questions 43

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

C. You create the tables and the cluster together, in the same SQL statement.D. Once you create the clusters, the tables that are part of the cluster are created automatically

by Oracle.

16. What happens if you use an ORDER BY clause on a suffix of the sort key columns?

A. You won’t need to perform any sorting if you use an ORDER BY clause.B. You’ll need to perform additional sorting when you use an ORDER BY clause.C. You’ll perform the same amount of sorting as when there is no suffix on the sort key

columns.D. You cannot use an ORDER BY clause on a suffix of the sort key column.

Copying Files Using the Database Server

17. Which one of the following statements is true when you use the DBMS_FILE_TRANSFERpackage to transport files?

A. If the source file is a UNIX file, the destination file can be an ASM file.B. If the destination file is a UNIX file, the source file can be a UNIX file.C. If the destination file is a UNIX file, the source file can be an ASM file.D. If the source file is an ASM file, the destination file can be an ASM file.

18. If you want to transfer a file using the DBMS_FILE_TRANSFER package, what do youneed to do?

A. You must use the COPY_FILE procedure to copy files to a different server.B. You must use the COPY_FILE procedure to copy files to a local database.C. You must use the PUT_FILE procedure to copy files to a different server.D. You must use the GET_FILE procedure to copy files to a different server.

LAB QUESTIONS1. On the USERS tablespace, set a warning threshold of 80 percent and a critical threshold of 95

percent.

2. How do you check the database-wide threshold values for the USERS tablespace?

3. How do you turn off the space-usage tracking for the USER tablespace?

4. How do you reset the database-wide threshold values of the USERS tablespace to the defaultdatabase values?

5. How do you check the status of your threshold?

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:59 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 316: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SELF TEST ANSWERS

Proactive Tablespace Management

1. � A and D. A is correct because you can provide alerts only in locally managed tablespaces.D is correct, since you can’t provide alerts in an offline tablespace.� B is wrong since dictionary-managed tablespaces aren’t eligible for proactive tablespacealerts. C is a wrong answer because you can’t provide alerts for read-only tablespaces.

2. � B. You will get a maximum of one undo tablespace alert during a 24-hour period.� A, C, and D provide wrong time intervals.

3. � B. The MMON background process monitors the tablespace thresholds and is responsiblefor sending proactive alerts.� A, C, and D don’t send out any alerts.

Reclaiming Unused Space

4. � D. You cannot shrink undo segments belonging to the undo tablespace.� A, B, and D are wrong answers since they all point to eligible candidates for segmentshrinking.

5. � D. The release of the space would have an impact on DML operations.� A, B, and C are wrong since the command would compact the data first and then releaseit, meanwhile impacting the DML operations going on in the database.

6. � B. You must ensure that row movement is enabled, since the shrinking process could altersome ROWIDs in a heap-organized table.� A, C, and D point out the wrong requirement.

Using the Undo and Redo Logfile Size Advisors

7. � A and C. The Undo Advisor helps you set the undo retention period, as well as the size ofthe undo tablespace.� B is wrong since there is no such thing as an undo interval. D is wrong because when youuse Automatic Undo Management, you don’t create the undo segments—Oracle does this.

8. � A. The FAST_START_MTTR_TARGET initialization parameter sets the mean time torecovery (MTTR) following an instance crash.� B, C, and D are wrong since the FST_START_MTTR_TARGET deals with instancerecovery rather than database restore, number of redo log groups, or undo management.

44 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:59 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 317: OCA OCP - Oracle10G New Features For Administrators Exam Guide

9. � D. Optimally sized redo log files should be the smallest consistent with keeping thecheckpointing to a minimum amount.� A, B, and C aren’t logically correct answers, since they ignore the MTTR target.

Tablespace Enhancements

10. � B. Oracle will create the SYSAUX tablespace in a default location, even if you fail tospecify it. The same is true of the SYSTEM tablespace.� A is wrong since database creation will succeed even when you don’t specify a SYSTEMor SYSAUX tablespace. If you issue the CREATE DATABASE statement with no other clauses,Oracle will create a database with datafiles for the SYSTEM and SYSAUX tablespaces in system-determined default locations. C is wrong since Oracle doesn’t create a SYSTEM tablespace inlieu of the SYSAUX tablespace. D is wrong since you can’t create the SYSAUX tablespaceafter database creation—the SYSAUX tablespace is always created at database creation.

11. � B. When you rename a default permanent tablespace, nothing really changes—the olddefault permanent tablespace continues to be the default permanent tablespace, with a newname.� A is wrong since you don’t need to create a new default permanent tablespace for theusers. C is wrong since the users continue to be assigned to the same permanent tablespacethroughout. D is wrong since you can rename a permanent tablespace.

12. � A. You must ensure that there is always a default tablespace for all the users in the database,before you can drop an old one.� B is wrong since the original default permanent tablespace will be replaced by the newdefault permanent tablespace. C is wrong since you don’t remove any users from the tablespace.D is wrong since you can drop a default permanent tablespace after making sure you have analternative default permanent tablespace for all the users.

13. � C. It doesn’t matter what type of tablespace you create the database with. You can alwayschange back and forth between the two types of tablespaces: smallfile and bigfile.� A, B, and D are wrong, since they contradict C.

14. � A. Oracle recommends that you set the extent size yourself, by using the UNIFORM clauseand selecting a very large extent size.� B is wrong because you use the AUTOALLOCATE for normal sized, not very large databases.C is wrong for the same reason as B. Besides, you can’t choose extent sizes when you useAUTOALLOCATE. D specifies the correct option, UNIFORM, but turns out to be the wronganswer, since it states that you should let Oracle choose the extent sizes.

Self Test Answers 45

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:44:59 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 318: OCA OCP - Oracle10G New Features For Administrators Exam Guide

46 Chapter 6: Space and Storage Management Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

Using Sorted Hash Clusters

15. � A. The hash cluster must exist before you can create any member tables.� B is wrong because you must first create the cluster and then the tables that are part ofthe cluster. C is wrong since you need to create the hash cluster first. D is wrong since Oracledoesn’t automatically create the tables that are part of a cluster.

16. � B. If you use an ORDER BY clause on a suffix of the sort key columns or nonsort keycolumns, additional sorting is required, assuming there are no indexes on the table.� A is wrong since you’ll need to perform sorting even with the ORDER BY clause. C iswrong since you’ll perform more sorting than before. D is wrong since you can use an ORDERBY clause on a suffix of the sort key column.

Copying Files Using the Database Server

17. � B and D. The source and destination files must be of the same type—UNIX or ASM.� A and C are wrong, since the file systems don’t match in both cases.

18. � B and C. B is correct because the COPY_FILE procedure is meant for local file copies.C is correct because you must use the PUT_FILE procedure to transfer files to a remotedatabase server.� A is wrong because you can only make copies from a local server with the COPY_FILEprocedure. D is wrong since the GET_FILE procedure helps you bring files from a remoteserver to your local server, not the other way around, as the answer indicates.

LAB ANSWERS1. On the USERS tablespace, use the following to set a warning threshold of 80 percent and

a critical threshold of 95 percent:

SQL> begindbms_server_alert.set_threshold (dbms_server_alert.tablespace_pct_full,dbms_server_alert.operator_ge, 80,dbms_server_alert.operator_ge, 95, 1, 1, NULL,dbms_server_alert.object_type_tablespace, 'USERS');end;

You can use the NULL value to return to the database-wide default values.

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:45:00 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 319: OCA OCP - Oracle10G New Features For Administrators Exam Guide

2. Check the database-wide threshold values for the USERS tablespace as follows:

SQL> select warning_value, critical_valuefrom dba_thresholdswhre metrics_name = 'Tablespace Space Usage' AND

object_name = 'USERS'/

3. Turn off the space-usage tracking for the USER tablespace as follows:

SQL> begindbms_server_alert.set_threshold (dbms_server_alert.tablespace_pct_full,dbms_server_alert.operator_do_not_check, '0',dbms_server_alert.operator_do_not_check, '0', 1, 1, NULL,dbms_server_alert.object_type_tablespace, 'USERS');

end;

4. Reset the database-wide threshold values of the USERS tablespace to the default databasevalues as follows:

SQL> begindbms_server_alert.set_threshold (dbms_server_alert.tablespace_pct_full,NULL, NULL, NULL, NULL, 1, 1, NULL,dbms_server_alert.object_type_tablespace, 'USERS');

end;

5. Check the status of your threshold as follows:

SQL> select reason, resolutionfrom dba_alert_historywhere object_name = 'USERS';

SQL> select reason, message_levelfrom dba_outstanding_alertswhere object_name = 'USERS';

Lab Answers 47

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6

P:\010Comp\CertPrs8\862-4\ch06.vpFriday, September 03, 2004 10:45:00 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 320: OCA OCP - Oracle10G New Features For Administrators Exam Guide

7The Oracle

Scheduler andthe Database

Resource Manager

CERTIFICATION OBJECTIVES

7.01 Simplifying Management Tasks Usingthe Scheduler

7.02 Managing the Basic SchedulerComponents

7.03 Managing Advanced SchedulerComponents

7.04 Viewing Information About the Scheduler

7.05 Database Resource ManagerEnhancements

✓ Two-Minute Drill

Q&A Self Test

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7Blind Folio 7:1

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7Blind Folio 7:1

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:34 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 321: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Oracle DBAs and developers frequently use the DBMS_JOB package to scheduledatabase jobs. The package is a commonly used scheduling utility that has beenaround for a number of years. However, Oracle databases suffered from not having

a real scheduling facility, especially when compared to the Microsoft SQL Server database.Oracle Database 10g provides you with the terrific new scheduling feature, aptly named theScheduler. In this chapter, you’ll learn first about the Scheduler framework and then how tomanage this brand-new Oracle 10g feature.

In the latter part of this chapter, you’ll learn about the Oracle Database 10genhancements to the Database Resource Manager. These include using the ResourceManager to impose idle session limits, returning sessions automatically to their initialconsumer groups after their top call is over, creating mapping between sessions andresource consumer groups, and using new methods of CPU allocation among resourceplans and resource groups.

Let’s start with an introduction to the new Scheduler and see how you can simplifymanagement tasks by using it.

CERTIFICATION OBJECTIVE 7.01

Simplifying Management TasksUsing the Scheduler

The set of functions and procedures in the DBMS_SCHEDULER package form thebackbone of the new Scheduler facility. The Scheduler helps you schedule jobs withinthe database or in the server that hosts the database. Using the Scheduler vastly simplifies adatabase administrator’s tasks relating to the running of regular database jobs. The mostimportant architectural feature of the Scheduler is its modular approach to managingtasks: it breaks down each task into location, time, and database object, thus simplifyingmanagement. The modular approach helps different users to reuse similar jobs, withminor modifications. The Scheduler works closely with the Database Resource Managerand utilizes the resource consumer group and resource plan concepts not only to schedulejobs according to a timetable, but also to allocate scarce server resources according toorganizational needs and priorities. This focus on resource allocation marks the Scheduleras a much more sophisticated and powerful scheduling tool than the DBMS_JOBSpackage.

2 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:34 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 322: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

A severe limitation of the DBMS_JOBS package is that it can only schedulePL/SQL-based jobs. You can’t use it to schedule operating system scripts or anexecutable. To run these non-database-type jobs, you must use a scheduling featurelike crontab in UNIX or the AT facility in Windows servers. You may even haveto use a third-party tool to get the job done. The Oracle Database 10g Schedulerfeature offers you the capability to perform not only PL/SQL jobs, but also operatingsystem shell scripts, Java programs, and native binary executables.

Basic Scheduler ComponentsThe Scheduler consists of three basic components—jobs, programs, and schedules.You are familiar with the concept of an Oracle job from using the DBMS_JOB packagein the previous versions. However, the other two components, programs and schedules,are new in the Scheduler. The concepts of a program and a schedule lead to a modularapproach to the management of tasks. For example, several users can perform similartasks, with minor changes in the time and resource usage, by simply using similar schedulesand programs.

Let’s look at the three main components of the Scheduler in the following sections.

JobsA job is a task that you schedule to run one or more times. A job contains informationabout what it should execute and time of execution. A Scheduler job can execute aPL/SQL block of code, a native binary executable, a Java application, or a shell script.You can create a new job by either specifying all the details, such as the code the jobshould execute and the time and frequency of the execution, or you can simply usesaved programs and schedules, to facilitate the creation of a job.

When you create a new job, Oracle adds an entry to the job table. There is onejob table for each database. When you execute a job, the database makes an entry inthe job log.

SchedulesA schedule is a specification of when and how frequently the database should execute ajob. The important thing to note here is that you can use the same schedule for severaljobs. Schedules are like any other database entities, and you store them just as you dothe other objects. Users can share schedules.

The schedule and program components of the Scheduler are purely optional.

Simplifying Management Tasks Using the Scheduler 3

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:34 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 323: OCA OCP - Oracle10G New Features For Administrators Exam Guide

ProgramsA program contains information about the code, script, or executable that’s to beexecuted as part of a job. The information contains a program name, the programaction (PL/SQL code or a UNIX shell script, for example), and other similar items.As with schedules, several jobs can share the same program.

You can combine the three main components of the Scheduler—jobs, schedules,and programs, to create and run scheduled jobs in your database, as you’ll see in latersections of this chapter.

Advanced Scheduler ComponentsIn addition to jobs, schedules, and programs, the Scheduler also uses several advancedconcepts: job classes, windows, and resource groups. These advanced features set apartthe Scheduler from its predecessor, the DBMS_JOBS package, in the matter of schedulingdatabase jobs. These advanced concepts enable the prioritizing of jobs in the databaseand the allocation of resources in accordance with your priorities. Let’s look at thesecomponents in the following sections.

Job ClassesA job class groups similar jobs into one large entity. The jobs that are part of a job classshare common characteristics like resource requirements. By helping you to classifyseveral jobs into related groups on the lines of functionality or shared attributes, jobclasses facilitate the calibration of limited resources among different groups of jobs inyour database.

Job classes group jobs with common characteristics. The main purpose ofusing a job class is to manage resource allocation among jobs. A job canbelong to only one job class.

After grouping jobs into classes on the functionality (marketing, administration,finance, and so on), you can use the concept of a job class to do the following:

■ Assign the job priority level for an individual job, with the priority values rangingfrom 1 to 5. A higher-priority job always starts before a lower-priority job.

■ Specify common attributes such as the frequency of log purging.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

4 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:34 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 324: OCA OCP - Oracle10G New Features For Administrators Exam Guide

WindowsA window represents an interval of time during which you can schedule jobs. The purposebehind using a window is to change resource allocation during a time period. For example,a “maintenance window” may last from Friday night to Sunday evening. Each windowis associated with a specific resource plan (created with the help of the Database ResourceManager). By using a window in which to schedule a job, you ensure that the job willonly run during a certain time interval, when a certain resource plan associated withthat window is active. The concept of resource plan–based windows enables you toensure optimal use of your scarce resources.

Windows can overlap, and when they do, Oracle chooses the window withthe higher priority. The window with the higher priority opens, and the otherwindow will close.

Window GroupsWindow groups are simply a collection of similar windows. Once you create a windowgroup, you can then specify that a job will run during a window group. For example,you can create a window for your weekends and a window for your holidays. You canthen group both these windows into a single maintenance window, if you wish. Thekey idea here is that a window group comprises windows with similar characteristics.You have the choice of specifying a window or window group as the schedule for a job.

Resource Allocation Among JobsThe Scheduler and the Database Resource Manager are tightly integrated in OracleDatabase 10g, thus making it easy to prioritize your jobs and assign the right levelof resources to jobs. You can use the Resource Manager feature to control resourceallocation in your database. The important thing to note here is that the Schedulerdoesn’t allocate resources at the individual job level—it does so at the job class level.Oracle assigns each job class to a specific resource consumer group. If you don’t specifya resource consumer group for any job class, that job class will by default be assigned tothe default consumer group.

The resource consumer group that a job class belongs to will determine theallocation of resources to that job class. Thus, you can use the Database ResourceManager to prioritize Scheduler jobs.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Simplifying Management Tasks Using the Scheduler 5

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:34 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 325: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Scheduler ArchitectureThe Scheduler architecture consists primarily of the job table, job coordinator, and thejob workers (or slaves). Let’s look at each of these components in the following sections.

The Job TableThe job table contains information about the jobs, such as the job name, programname, and job owner. You can examine the job table by using the DBA_SCHEDULER_JOBS view.

The Job CoordinatorWhen you create a new job or execute a job, a background process (cjqNNN)automatically wakes up and starts coordinating the running of the job. The Schedulersleeps when there aren’t any jobs to execute. The job coordinator regularly looks in thejob table to find out what jobs to execute. The job coordinator creates and managesthe job worker processes that execute the job.

The Job WorkersWhen the job coordinator instructs a job worker to execute a job, the worker processstarts a database session and starts a transaction. It then starts executing the job, andonce the job completes, it commits and ends the transaction and terminates thedatabase session.

It is the job of the job workers to

■ Update the job table, to indicate that the job has been completed

■ Update the job log table

■ Update the run count

Scheduler PrivilegesJobs, schedules, and programs are like any other database object when it comes toownership and privileges. Oracle creates all jobs, programs, and schedules in the currentuser’s schema. However, Oracle creates all the advanced Scheduler components, likejob classes, windows, and window groups, at the database level, not the schema level,and their owner is the SYS schema.

6 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:35 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 326: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The MANAGE SCHEDULER system privilege lets you do the following:

■ Create, drop, and alter job classes, windows, and window groups. (You stillcan’t create a job in a job class you create, unless you have a separate EXECUTEprivilege on that job class.)

■ Stop any job.

■ Start and stop windows prematurely.

By default, all Scheduler objects are in uppercase, unless you wrap the lowercasenames in double quotes, as in “test_job”.

You must have the CREATE JOB privilege to create the basic job, schedule, andprogram components. In order to use the advanced Scheduler components likewindows, window groups, and job classes, you need the MANAGE SCHEDULERsystem privilege.

Once you create a job or some other Scheduler component, it will be a part ofyour own schema. You can assign other users the right to use one of your componentslike a job, schedule, or program by giving them EXECUTE privileges on thatcomponent. For example, you can grant the EXECUTE privileges for a certainprogram or for a certain job class. Note that

■ The EXECUTE ANY PROGRAM privilege lets a user execute any programunder any schema.

■ The EXECUTE ANY CLASS privilege lets you assign a job to any job class.

In order for a user to modify a Scheduler component, you must grant the user thefollowing privilege (you use the appropriate component):

SQL> grant alter on <job, program or schedule> to scott;

When you create a job, as you are aware, you can use programs, schedules, jobclasses, and windows. Once you have the CREATE JOB privilege, you can startcreating your job, with the following restrictions:

■ To create the job itself, you must have the CREATE JOB privilege.

■ If you specify a program that you happen to own, you don’t need anyprivileges to specify the program.

■ If you specify a program owned by a different user, you must have the EXECUTEprivilege on that program, or the EXECUTE ANY PROGRAM system privilege.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Simplifying Management Tasks Using the Scheduler 7

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:35 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 327: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ You can specify a schedule, whether owned by you or a different user, withoutany privileges.

■ You don’t need any special privileges to specify a window or windows group.However, since all of these objects are in the SYS schema, you must fullyqualify these components when you use them in your CREATE JOB or anyother statement.

■ If you wish to assign your new job to a job class, you must either have theEXECUTE privilege on that class, or the more powerful EXECUTE ANYCLASS system privilege.

The SCHEDULER_ADMIN role contains all the Scheduler system privileges,with the WITH ADMIN OPTION clause. The DBA role contains the SCHEDULER_ADMIN role.

CERTIFICATION OBJECTIVE 7.02

Managing the Basic Scheduler ComponentsThe basic Scheduler components—jobs, programs, and schedules—have several commonmanageability features. For example, you follow a similar procedure to create, alter, anddrop all three components. Similarly, you can use the SET_ATTRIBUTES procedureof the DBMS_SCHEDULER package to change the attributes of all three components.Let’s start with managing Scheduler jobs in the next section.

All Scheduler objects are of the form [schema].name. All Scheduler names arein uppercase, unless you surround them with double quotes.

Managing JobsCreating and managing jobs, of course, is at the heart of the Scheduler facility. As you’lllearn, you can create and run jobs independently, or you can create a job using schedulesand programs. Use of saved programs and schedules enables you to eliminate theredefinition of the program or schedule each time you create a new job. This reusabilityof the Scheduler components is a highly useful feature, since users can customize schedulesand programs to meet their needs. Let’s start with the creation of Scheduler jobs.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

8 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:35 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 328: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Creating JobsYou create a job using the CREATE_JOB procedureof the DBMS_SCHEDULER package. You canspecify all the job execution details directly usingthe CREATE_JOB procedure. Programs andschedules, as you’ve seen earlier, are saved databaseobjects that contain information pertaining tojobs, like the job type and the start and end times.

Later, you’ll see how to use programs and schedules to make the creation of jobs easy tomanage. Here’s a simple example that shows how to create a basic Scheduler job. Notethat there aren’t any programs or schedules in this job—this is the most straightforwardway to specify a job, with all pertinent information specified in the job creation statementitself. More sophisticated examples later on show you how to embed most of the repetitiveinformation within saved schedules and windows.

SQL> begin2 dbms_scheduler.create_job(3 job_name => 'test_job1',4 job_type => 'PLSQL_BLOCK',5 job_action => 'DELETE FROM persons WHERE sysdate=sysdate-1',6 start_date => '28-JUNE-04 07.00.00 PM Australia/Sydney',7 repeat_interval => 'FREQ=DAILY;INTERVAL=2',8 end_date => '20-NOV-04 07.00.00 PM Australia/Sydney',9 comments => 'TEST JOB');10* end;SQL> PL/SQL procedure successfully completed.SQL>

Your new job, test_job1, isn’t ready to be used yet, since by default, all new jobsare disabled when they are created. You need to enable a job in order to use it.

Note how similar the preceding job creationstatement is to using the traditional DBMS_JOBpackage to create a new job. Incidentally, youcan still use the DBMS_JOB package in OracleDatabase 10g, since it’s left there for backward-compatibility purposes. Let’s look at the variouscomponents of our CREATE_JOB procedure.

job_name This parameter provides a way tospecify a name for your job.

Managing the Basic Scheduler Components 9

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

You’ll be the owner of ajob if you create it in your own schema.However, if you create it in another schema,that schema user will be owner of the job.Thus, the fact that you create a job doesn’tmean that you are necessarily the ownerof that job.

The parameter values youspecify when you create a job will overridethe default values for the saved programsand schedules.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:35 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 329: OCA OCP - Oracle10G New Features For Administrators Exam Guide

job_type This parameter tells the Scheduler what type of job—a PL/SQL block,a stored procedure, a shell script, or a Java program—that the job must execute.

job_action This parameter specifies the exact procedure, command, or scriptthat the job will execute.

start_date and end_date These parameters specify the date that a new jobshould start and end. (Many jobs may not have an end_date parameter, sincethey are ongoing jobs.)

repeat_interval This attribute tells the Scheduler how often it should executethe job. In our example, the repeat interval is 'FREQ=DAILY;INTERVAL=2',which means that you run the job every other day. You can specify a repeat intervalin one of two ways:

■ Use a PL/SQL date/time expression.

■ Use a database calendaring expression.

If you omit the repeat_interval attribute, a job will run only once.

Note that a big feature of the Scheduler tool is its ability to run operating systemscripts and executables in addition to PL/SQL code. Here’s an example that showshow you can schedule a job on your server. The job runs the check_freespace.kshUNIX script every half an hour.

begindbms_scheduler.create_job(job_name => 'CHECK_FREE_SPC',job_type => 'EXECUTABLE',job_action => '/u01/app/oracle/admin/dba/scripts/check_freespace.sh',repeat_interval => 'FREQ=MINUTELY; INTERVAL=30',enabled => true,comments => 'Check free space in tablespaces');end;/

The script will run every 30 minutes ('FREQ=MINUTELY; INTERVAL=30'),and the job_type parameter shows that it’s an executable program. The job_action parameter tells the Scheduler which OS script to execute.

Let’s briefly look at how you can set your repeat interval using calendaring expressionsand PL/SQL date/time expressions.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

10 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:35 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 330: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

■ Using a calendaring expression Calendaring expressions generate the nextdate of execution for a job. A calendaring expression is a straightforward,English-like expression consisting of the following three components:

■ Frequency A mandatory component of a calendaring expression,represented by the keyword FREQ. Possible values are YEARLY, MONTHLY,WEEKLY, DAILY, HOURLY, MINUTELY, and SECONDLY.

■ Repeat interval Refers to how often the database must repeat the job.The keyword INTERVAL shows the repeat interval.

■ Specifiers Provides detailed information about when a job shouldbe run. Possible values are BYMONTH, BYWEEKNO, BYYEARDAY,BYMONTHDAY, BYDAY, BYHOUR, BYMINUTE, and BYSECOND.

Of these three components, specifiers are optional, but the repeat intervaland frequency are mandatory. You’ll need specifiers only when you need tospecify complex repeat intervals. Here are some examples of using the threecomponents to provide values for the repeat_interval attribute of theCREATE_JOB procedure:FREQ=DAILY; INTERVAL=10 executes a job every 10 days

FREQ=HOURLY; INTERVAL=2 executes a job every other hour

FREQ=WEEKLY; BYDAY=FRI executes a job every Friday.

FREQ=WEEKLY; INTERVAL=2; BYDAY=FRI executes a job every other Friday.

FREQ=MONTHLY; BYMONTHDAY=1 executes a job on the last day of the month

FREQ=YEARLY; BYMONTH=DEC; BYMONTHDAY=31 executes a job on the 31st of December.

FREQ=MONTHLY; BYDAY=2FRI executes a job every second Friday of the month

In the preceding set of examples, the BY* clause is the optional specifiercomponent, which provides additional information that the frequent andrepeat interval components can’t provide.

■ Using a PL/SQL expression You can also create more complex repeatintervals than what the calendaring expressions enable you to do by usingPL/SQL expressions, with the proviso that all such expressions must evaluateto a date or a timestamp datatype. When you use a date/time expression forspecifying the repeat interval, you end up with a date/time datatype as thevalue of the interval. Look at the following example:

repeat_interval => 'SYSTIMESTAMP + INTERVAL '10' MINUTE'

The repeat_interval specification in the preceding example shows theuse of a PL/SQL expression. The expression states that Oracle will executethe job every ten minutes. Each time a job executes, Oracle evaluates therepeat_interval clause to compute the next scheduled execution timeof the job—in this case, ten minutes into the future.

Managing the Basic Scheduler Components 11

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:35 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 331: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Administering JobsYou can use the DBMS_SCHEDULER package to perform all the administrative tasksassociated with jobs. Let’s look at some of the main job-related administrative tasks inthe following sections.

Enabling and Disabling Jobs All jobs are disabled by default when you createthem. You must explicitly enable them in order to activate and schedule them. Youcan enable a job by issuing the following command:

SQL> exec dbms_scheduler.enable ('TEST_JOB1');PL/SQL procedure successfully completed.

You can disable a job by issuing the following command:

SQL> exec dbms_scheduler.disable ('TEST_JOB1');PL/SQL procedure successfully completed.

Dropping a Job You can drop a job by using the DROP_JOB procedure,as shown here:

begindbms_scheduler.drop_job (job_name => 'test_job1');

end;/

Running and Stopping a Job You can run a job manually (at other than theregularly scheduled times) by using the RUN_JOB procedure, as shown here:

SQL> exec dbms_scheduler.run_job('TEST_JOB1');

You may want to run a job manually to test it before scheduling on a regular basis,or to correct some errors in a job that already ran. When you run a job manually, itruns in your own session, and the job coordinator and the job slave don’t enter thepicture.

You can stop a job immediately by using the STOP_JOB procedure, as shown here:

SQL> exec dbms_scheduler.stop_job('TEST_JOB1');

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

12 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:35 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 332: OCA OCP - Oracle10G New Features For Administrators Exam Guide

EXERCISE 7-1

Creating a Job to Perform an Online BackupCreate a simple job, which will execute a script at a scheduled time. Here’s a samplejob creation code:

begindbms_scheduler.create_job (job_name => 'EXECUTABLE',job_action =>'/U01/APP/ORACLE/DBA/SCRIPT/PROD1_ONLINE_BKP.sh',start_date => '05-JUL-04 11.00.00 PM',repeat_interval => 'FREQ=DAILY;INTERVAL=2', /* every other day */comments => Alternate day online backup');

end;/

Managing ProgramsA program contains metadata, including the name and type of the program, and whata job will execute, whether it is a PL/SQL procedure, a script, or an executable. Whenyou use programs, you can alter the job task, or what the job will actually do, withoutdirectly modifying the job definition itself. Programs enable you to control the run-time behavior of the job task. Different jobs can pick the same program from a libraryof programs, thus helping you avoid having to specify all the details of a program inyour job creation statement.

Let’s start by looking at how you can create programs. Later you’ll learn aboutprogram-related administrative tasks.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Managing the Basic Scheduler Components 13

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

In both the STOP_JOB andRUN_JOB procedures, there is a FORCEargument, which is set to false by default.The FORCE attribute determines whetherthe job can be stopped or dropped if it is

currently running. By setting FORCE=TRUE,you can stop or drop a job immediately byusing the appropriate procedure. You musthave the MANAGE SCHEDULER systemprivilege to use the FORCE setting.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 333: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Creating a ProgramTo create a new Scheduler program, use the CREATE_PROGRAM procedure of theDBMS_SCHEDULER package, as shown here:

SQL> begin2 dbms_scheduler.create_program(3 program_name => 'TEST_PROGRAM',4 program_action => 'SCOTT.UPDATE_SCHEMA_STATS',5 program_type => 'STORED_PROCEDURE',6 enabled => TRUE);7* end;

SQL> /PL/SQL procedure successfully completed.SQL>

By default, Oracle creates a program in the creator’s schema. If you want tocreate the program in a different user’s schema, you must qualify the programname with the schema name.

The program component has all the job details. Once you create a program in themanner shown here, you can simplify your job creation statement for the job TEST_JOB1 by replacing the job_type and job_action attributes with the nameof the program (TEST_PROGRAM) that already contains the specification of theseattributes. The program_type and program_action will provide the informationthat the three job attributes provided in your first job creation statement. You canbegin to see why this type of a modular approach is beneficial—different jobs canuse the same program, thus simplifying the specification and creation of jobs.

Let’s re-create our TEST_JOB1 job, using the program component this time.Here’s the much simpler job creation statement:

SQL> begin2 dbms_scheduler.create_job(3 job_name => 'TEST_JOB1',4 program_name => 'TEST_PROGRAM',5 repeat_interval=> 'FREQ=DAILY;BYHOUR=12',6 ENABLED => TRUE;

ENABLED => TRUE);7* end;

SQL> /PL/SQL procedure successfully completed.SQL>

In the preceding example, the use of a program (TEST_PROGRAM) lets you avoidspecifying the job_type and job_action parameters in the CREATE_JOB

14 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 334: OCA OCP - Oracle10G New Features For Administrators Exam Guide

statement. You thus have a choice between specifying all job attributes directly inthe CREATE_JOB statement itself, or using a stored program to supply some of thejob attributes.

Administering ProgramsYou can enable, disable, drop, and modify Scheduler programs using various proceduresfrom the DBMS_SCHEDULER package.

Enabling and Disabling Programs You can enable a program in the followingmanner, using the ENABLE procedure:

SQL> exec dbms_scheduler.enable('TEST_PROGRAM');PL/SQL procedure successfully completed.

You can disable a program in the following manner, using the DISABLE procedure:

SQL> exec dbms_scheduler.disable('TEST_PROGRAM');PL/SQL procedure successfully completed.

Dropping a Program You can drop a saved program by using the DROP_PROGRAM procedure, as shown here:

SQL> exec dbms_scheduler.drop_program('TEST_PROGRAM');PL/SQL procedure successfully completed.SQL>

Managing SchedulesLet’s say you have a number of jobs, all of which use similar execution time schedules.In cases like this, the Scheduler makes it easy for you to use a common schedule. If youneed to modify some aspect of the schedule, all the jobs that use the schedule canautomatically inherit those changes. Let’s start by looking at how you create a schedule.

Creating a ScheduleYou use the CREATE_SCHEDULE procedure of the DBMS_SCHEDULER package tocreate a schedule, as shown here:

SQL> begin2 dbms_scheduler.create_schedule(3 schedule_name => 'TEST_SCHEDULE',4 start_date => SYSTIMESTAMP,

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Managing the Basic Scheduler Components 15

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 335: OCA OCP - Oracle10G New Features For Administrators Exam Guide

5 end_date => SYSTIMESTAMP + 30,6 repeat_interval => 'FREQ=HOURLY;INTERVAL= 12',7 comments => 'Every 12 hours');8* end;

SQL> /PL/SQL procedure successfully completedSQL>

The TEST_SCHEDULE schedule states that a job with this schedule will beexecuted immediately and then be reexecuted every 12 hours, for a period of 30days. Note the following things about the creation of the TEST_SCHEDULEschedule:

■ The CREATE_SCHEDULE procedure has three important parameters(there is also an optional comment parameter).

■ The start and end times are always precise to a second.

■ You specify the start and end times using the TIMESTAMP WITH TIMEZONE datatype. The Scheduler also supports all NLS_TIMESTAMP_TZ_FORMAT settings.

■ You must use a calendering expression to create the repeat interval.

Once you create the schedule TEST_SCHEDULE, you can simplify the job creationprocess even further. Now you can use both TEST_PROGRAM and TEST_SCHEDULEto simplify job creation, as shown here:

SQL> begin2 dbms_scheduler.create_job(3 job_name => 'TEST_JOB02',4 program_name => 'TEST_PROGRAM',5 schedule_name => 'TEST_SCHEDULE');6 end;7 /

PL/SQL procedure successfully completed.SQL>

As you can see, TEST_JOB02 is really easy to create, since you are using botha saved program as well as a saved schedule. The use of the saved schedule meansthat you don’t have to specify the start_date, end_date, and the repeat_interval attributes while creating TEST_JOB02, since TEST_SCHEDULEalready has all that information.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

16 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 336: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Administering SchedulesA schedule states when and how often a job should be run. You can save a scheduleas a database object and share it with other users. Let’s look at some of the basicadministrative tasks concerning schedules.

Creating a Schedule You create a schedule using the CREATE_SCHEDULEprocedure. You can create a schedule in your own or some other schema. You’velearned how to use the CREATE_SCHEDULE procedure in the previous section.

The most important attributes of a scheduleare the start and end dates and the frequencyof execution, which is set by the repeat_interval attribute. You can alter thevarious attributes of a schedule by using theSET_ATTRIBUTE procedure of the DBMS_SCHEDULER package. You may alter allattributes except schedule_name.

EXERCISE 7-2

Creating a ScheduleCreate a simple schedule on the lines of the following example. In the example, therepeat_interval attribute specifies that a job will execute every five minutes.

SQL> begindbms_scheduler.create_schedule (scheduler_name => 'TEST_SCHEDULE',start_date => SYSTIMESTAMP,repeat_interval => 'FREQ=MINUTELY;INTERVAL=5',comments => 'A test schedule.');

end;/

Dropping a Schedule You can drop a schedule with the DROP_SCHEDULEprocedure, but there are some interesting things to note in this regard. For example,

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Managing the Basic Scheduler Components 17

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

When you create aschedule, Oracle provides access toPUBLIC. Thus, all users can use yourschedule, without any explicit grantof privileges to do so.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 337: OCA OCP - Oracle10G New Features For Administrators Exam Guide

if you have any jobs or windows that use the schedule you want to drop, yourprocedure will fail, as shown here:

SQL> begin2 dbms_scheduler.drop_schedule(schedule_name => 'TEST_SCHEDULE');3 end;4 /

beginERROR at line 1:ORA-27479: Cannot drop "SAM.TEST_SCHEDULE" because other objects depend on itORA-06512: at "SYS.DBMS_ISCHED", line 615ORA-06512: at "SYS.DBMS_SCHEDULER", line 1070ORA-06512: at line 2SQL>

In our example, TEST_JOB03 uses the schedule TEST_SCHEDULE, and therefore,your attempt to drop the schedule results in an error. You can override this defaultbehavior by using the FORCE attribute and setting it to true, as shown here:

SQL> begin2 dbms_scheduler.drop_schedule(schedule_name => 'TEST_SCHEDULE',3 force => TRUE);4 end;5 /

PL/SQL procedure successfully completed.SQL>

When you drop a schedule by using the FORCE=TRUE attribute, you’ll drop theschedule, even if there are jobs and windows that use the schedule. The Schedulerfirst disables the dependent jobs/windows before dropping the schedule itself.

CERTIFICATION OBJECTIVE 7.03

Managing Advanced Scheduler ComponentsIn the previous section, you learned how to manage the basic Scheduler components—jobs, programs, and schedules. In this section, let’s look at how to manage the advancedScheduler components—job classes and windows (and window groups). You’ll alsolearn how the Scheduler makes good use of the Database Resource Manager features,such as resource consumer groups and resource plans, to efficiently allocate scarce OSand database resources. Too often, heavy batch jobs run past their window of opportunity

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

18 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 338: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

and spill over into the daytime, when OLTP transactions demand the lion’s share ofthe resources. Prioritizing jobs to ensure that they are guaranteed adequate resources toperform along accepted lines is an essential requirement in production databases. TheScheduler uses the concepts of job classes and windows to prioritize jobs.

Job ClassesYou can create and schedule a job all by itself, or you can manage it as part of a job class.Although both types of jobs will perform the same actions, you can’t really allocateresources when you run a job as an entity by itself. Job classes group all jobs with similarcharacteristics and common resource requirements together. Using job classes helpsyou prioritize jobs by allocating resources differently among the various jobs.

The Scheduler associates each job class with a resource consumer group, which letsthe Scheduler group jobs according to common resource requirements. Dependingon the resource consumer group a job class belongs to, the Scheduler will determinethe appropriate resource allocation. This ability to associate job classes with resourceconsumer groups provides an efficient way to prioritize jobs in the database.

You use the CREATE_JOB_CLASS procedure of the DBMS_SCHEDULER to createa job class. Unlike a job, a job class can’t be created in a user’s schema—no matterwho creates it, all job classes are created in the SYS schema. You can create a jobclass only if you have the MANAGE SCHEDULER privilege.

Creating a Job ClassYou create a job class by using the CREATE_JOB_CLASS procedure of the DBMS_SCHEDULER package, as shown here:

begindbms_scheduler.create_job_class (

job_class_name => 'admin_jobs',

Managing Advanced Scheduler Components 19

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

All jobs must belong toa job class. There is a default job class,DEFAULT_JOB_CLASS, to which all jobswill belong if you don’t explicitly assignthem to a job class. Similarly, there is a

default resource consumer group, theDEFAULT_CONSUMER_GROUP, to whicha job class will map if you don’t expresslyassign that job class to a user-createdresource consumer group.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 339: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

resource_consumer_group => 'admin_group',logging_level => dbms_scheduler.logging_offlogging_history => 30);

);end;

Let’s look at the parameters of the CREATE_JOB_CLASS procedure in thepreceding example:

■ Job_class_name is the name of the job class.

■ Resource_consumer_group tells us that all the jobs that are members ofour new class will have the admin_group as their resource consumer group.

■ The logging_level parameter, which is set to LOGGING_OFF, can takethe following three values:

■ Logging_off There is no logging of any kind for the jobs.

■ Logging_runs For each run of a job in the job class, there will bea detailed entry in the job log.

■ Logging_full For each run of a job in the job class, there will bea detailed entry in the job log. In addition, the Scheduler logs all operationsperformed on the other jobs in the job class. These operations include thecreation, dropping, altering, enabling, or disabling of the other jobs.

The default logging level is to log all job runs (LOGGING_RUNS option).The LOGGING_FULL option gives you the most information about jobs.

■ Logging_history specifies the number of days (30 in this case) that thedatabase will retain the logs before purging them. Oracle will automaticallycreate a daily job called the PURGE_LOG, which cleans the log entries. Thefollowing query shows that this job exists:

SQL> select job_name2 from dba_Scheduler_jobs;

JOB_NAME------------------------------GATHER_STATS_JOBPURGE_LOG…SQL>

If you want to clear the logs manually, you can do so by using the DBMS_SCHEDULER.PURGE_LOG procedure.

20 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 340: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing Advanced Scheduler Components 21

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

When you create the ADMIN_JOBS job class, Oracle will automatically store it inthe SYS schema, and the same is true of any other job class that you might createin the database. Any user in the database can create a job in the ADMIN_JOBS jobclass, provided they have the EXECUTE privilege on that specific job class, or theyhave the EXECUTE ANY JOB CLASS privilege.

Altering a Job ClassAfter you create a job class, you can alter all of its attributes except the job_nameattribute. You can use the ALTER_ATTRIBUTES procedure to change a job class’sattributes, as shown in the following code. You can change the START_DATE, END_DATE, and other logging-related attributes as well. In the example, the attributeyou are changing is START_DATE. The VALUE clause holds the new value of theSTART_DATE attribute.

SQL> begin2 dbms_scheduler.set_attribute(3 name => 'ADMIN_JOBS',4 attribute => 'START_DATE',5 value => '01-JAN-2005 9:00:00 PM US/Pacific');6* end;

SQL>

You can’t change any attributes of the default job class, which is named, well,the DEFAULT_JOB_CLASS.

The PURGE_LOG procedureof the DBMS_SCHEDULER package takestwo important parameters—log_historyand which_log. You use the log_history parameter to specify the numberof days to keep logs before the Schedulerpurges them. The which_log parameter

enables you to specify whether you want topurge job or window logs. For example, topurge all job logs more than seven days old,you use the statement:

exec dbms_scheduler.purge_log(log_history=7,

which_log =>'JOB_LOG')

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 341: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Dropping a Job ClassYou can drop a job class by executing the DROP_JOB_CLASS procedure, as shown here:

begindbms_scheduler.drop_job_class('TEST_CLASS');end;

Review of the Database Resource ManagerMuch of the Scheduler’s power comes from its ability to interact with the DatabaseResource Manager to allocate resources among the various scheduled jobs. In order tofully comprehend this interaction, it pays to quickly review the concepts of the DatabaseResource Manager. Let’s take a brief detour to do that in this section.

Using the Database Resource Manager, you can allocate percentages of your serverCPU to contending applications and users. You can also limit operations that youthink are going to run too long, as well as control the degree of parallelism used byvarious jobs. You may also terminate long-running sessions and guarantee minimumprocessing resources to certain users, regardless of the system load.

You can fully use the resource controlling power of the Database Resource Managerby creating the basic components and modifying them over time. The four maincomponents are the resource consumer group, resource plan, resource allocationmethod, and resource plan directive.

Resource Consumer Group A group of users or sessions that have identicalprocessing and resource requirements is known as a resource consumer group. Youcan manually assign users to resource consumer groups or let the database assign theuser sessions to specific groups based on the value of various user session attributes.You may dynamically reassign a session to a different consumer group.

22 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

If you want to drop a jobclass with jobs in it, you must specify theFORCE=TRUE option in your DROP_JOB_CLASS procedure. When you do this, thejobs in the dropped job class are disabled

and moved to the default job class in yourdatabase. If the job is already running whenyou drop its job class, the job will run tocompletion anyway.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:36 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 342: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing Advanced Scheduler Components 23

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Resource Plan How you allocate resources among the various resource consumergroups is your resource plan. For example, a resource plan may allocate 50 percentof the CPU resources to the Finance Group, 30 percent to the Sales Group, and20 percent to the Administration Group of users.

Resource Allocation Method You can choose the method, or policy, ofallocation of resources among the various resource consumer groups.

Resource Plan Directive You can assign a resource consumer group to a resourceplan, thus deciding what resources each resource consumer group gets. Plan directivesalso enable you to specify the parameters for each resource allocation method. Forexample, you may limit the degree of parallelism of all users in the AdministrativeGroup to 2, instead of using the default value, which is an unlimited number ofparallel sessions.

With this brief review of the Database Resource Manager behind us, let’s move onto see how you can use the concept of a time window to activate different resourceplans at different times.

Working with Scheduler WindowsAlthough the Scheduler works in tandem with the Database Resource Manager toallocate resources in an optimal way to all the jobs scheduled for running, you willwant to allocate different amounts of resources at different times. This is where theconcept of the Scheduler window serves as a handy device. Windows enable theautomatic changing of resource plans based on a schedule.

The basic purpose of a window is to switch the active resource plan during acertain time frame. All jobs that run during this window will be controlled bythe resource plan that’s in effect during that window. Without windows, you’llhave to manually switch the resource manager plans.

A window is an interval with a specific begin and end time, for example, “from 12midnight to 6:00 A.M.” However, a window is not merely a chronological device likea schedule, specifying when a job will run; every window is associated with a resourceplan. When you create a window, you specify a resource plan as a parameter. Thisability to activate different resource plans at different times is what makes a windowa special scheduling device that enables you to set priorities.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 343: OCA OCP - Oracle10G New Features For Administrators Exam Guide

24 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

A Scheduler window consists of the followingthree major attributes:

■ Schedules, which are the times when thewindow is in effect

■ Duration, which determines the lengthof time a window stays open

■ Resource plan, which determines the resourcepriorities among the job classes

Note that schedules and duration are part of all Scheduler schedules; the resourceplan sets a Scheduler window apart from a simple schedule. Each time a window isopen, a specific active resource plan is associated with it. Thus, the same job will beallocated different resources if it runs under different windows.

You can specify what resources you want to allocate to various job classes duringa certain time period (say midnight to 6:00 A.M.) by associating a resource planwith the window you create for this period. When the window opens, the databaseautomatically switches to the associated resource plan, which becomes the activeresource plan. The systemwide resource plan associated with the window will controlthe resource allocation for all jobs and sessions that are scheduled to run within thiswindow.When the window finishes, there will be another switch to the orginal resourceplan that was in effect, provided no other window is in effect at that time.

If a window is open and the Resource Manager is not turned on, the window won’tbe able to switch the resource plans. In this case, the window will continue to openas scheduled and run the jobs that have been assigned for that window. Thus, thewindow in this case serves only as a basic schedule component.

You can see which window is currently active and the resource plan associated withthat window by using the following query:

SQL select window_name, resource_plan from dba_scheduler_windowswhere active='TRUE';WINDOW_NAME RESOURCE_PLAN------------------------------ --------------------------TEST_WINDOW TEST_RESOURCEPLAN

SQL>

The V$RESOURCE_PLAN provides information on currently active resourceplans in your database. If you want to view the active resource plan when thereis no window open, you can use the following query:

SQL> select * from v$resource_plan;

All windows, like job classes,are created in the SYS schema, no matterwhich user creates them. To create awindow, you must have the MANAGESCHEDULER system privilege.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 344: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing Advanced Scheduler Components 25

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Creating a WindowYou create a window by using the CREATE_WINDOW procedure. Let’s look at twoexamples using this procedure, one with an inline specification of the start and endtimes and the repeat interval, and the other where you use a saved schedule insteadto provide these three scheduling attributes. In the first example, the window creationstatement specifies the schedule for the window.

begindbms_scheduler.create_window (

window_name => 'TEST_WINDOW',start_date => '01-JAN-05 12:00:00AM',repeat_interval => 'FREQ=DAILY',resource_plan => 'TEST_RESOURCEPLAN',duration => interval '60' minute,end_date => '31-DEC-05 12:00:00AM',window_priority => 'HIGH',comments => 'Test Window');

end;/

Let’s look at the individual attributes of a window in TEST_WINDOW:

■ Resource_plan tells us that while this window is open, resource allocationto all the jobs that run in this window will be guided by the resource plandirectives in the resource plan TEST_RESOURCEPLAN.

■ Window_priority is set to HIGH. The default priority level is LOW.These are the only two values possible. If two windows overlap, the windowwith the high priority level has precedence. Since only one window can beopen at a given time, when they overlap, the high-priority window will openand the lower-priority window doesn’t open.

■ Start_date indicates that your window first becomes active at 12:00 A.M.on January 1, 2005. You can also say that the window will open at this time.

■ The duration attribute shows that the window will remain open for a periodof 60 minutes, after which it will close.

■ Repeat_interval tells us the next time the window will open again.In our case, it is 12:00 A.M. on January 2, 2005.

■ End_date tells us that this window will open for the last time on December31, 2005, after which it will be disabled and closed.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 345: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Since the Scheduler doesn’t check to make sure that there are prior windowsfor any given schedule, you have the possibility of overlapping windows. Notethat Oracle doesn’t recommend overlapping windows.

In the second example, shown here, you see how you can create a window usinga saved schedule. Obviously, it is much simpler to create a window this way.

begindbms_scheduler.create_window (

window_name => 'TEST_WINDOW',schedule_name => 'TEST_SCHEDULE',resource_plan => 'TEST_RESOURCEPLAN',duration => interval '160' minute,comments => 'Test Window');

end;/

In the preceding CREATE_WINDOW procedure, the use of the schedule TEST_SCHEDULE lets you avoid specifying the start_date, end_date, and repeat_interval parameters.

A window is automatically enabled upon its creation.

Once you create a window, you must associate it with a job or job class, so thejobs can take advantage of the automatic switching of the active resource plans.

Managing WindowsYou can open, close, alter, enable/disable, or drop a window using the appropriateprocedure of the DBMS_SCHEDULER package. You need the MANAGE SCHEDULERprivilege to perform any of these tasks. Note that since all windows are created in theSYS schema, you must always use the [SYS].window_name syntax when you referenceany window.

Opening a Window When a window opens, there will be a switch in theresource plan, and all jobs that are currently running will see a change in theirresource allocation, as specified by the particular resource plan associated with thewindow that just opened. A window is designed to open at a certain time (start_time) and stay open for a fixed length of time (duration). The rest of the time,the window stays closed.

26 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 346: OCA OCP - Oracle10G New Features For Administrators Exam Guide

A window will automatically open at a time specified by its start_timeattribute. Only one window can be open at any given time.You can also open awindow manually anytime you wish, by using the OPEN_WINDOW procedure. Evenwhen you manually open a window prematurely, that window will still open at itsregular open time specified by its interval. Here’s an example that shows how youcan open a window manually:

dbms_scheduler.open_window (window_name =>'BACKUP_WINDOW',duration => '0 12:00:00');

Look at the duration attribute in the preceding statement. When you specifythe duration, you can specify days, hours, minutes, seconds, in that order. Thus, thesetting means 0 days, 12 hours, 0 minutes, and 0 seconds.

Manually opening a window doesn’t affect the regular schedule of thewindow.

Note that you can open an already open window. If you do this, the duration ofthe window will last a time period equal to its duration attribute. That is, if youopen a window that has been running for 30 minutes and its duration is 60 minutes, yourwindow will last a total of the initial 30 minutes plus an additional 60 minutes, for atotal of 90 minutes.

You must have the MANAGE SCHEDULER system privilege in order to open,close, disable, or drop a window.

Closing a Window To close a window, you use the CLOSE_WINDOW procedure,as illustrated by the following example:

dbms_scheduler.close_window('BACKUP_WINDOW');

If a job is running when you close a window, the job will continue to run to itscompletion. However, a running job may close upon the closing of its window ifyou create a job with the attribute STOP_ON_WINDOW_CLOSE set to TRUE.

You can alter all attributes except the window_name attribute by using theSET_ATTRIBUTES procedure.

Managing Advanced Scheduler Components 27

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 347: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Disabling a Window To disable a window, you use the DISABLE procedure,as shown here:

dbms_scheduler.disable (name => 'BACKUP_WINDOW');

You can only disable a window if no job uses that window or if the window isn’topen. If the window is open, you can disable it by using the DISABLE program withthe FORCE=TRUE attribute.

Dropping a Window When you drop a window, you automatically remove itfrom its window group.You can drop a window by using the DROP_WINDOW procedure.By using the FORCE=TRUE attribute, you can do the following:

■ Disable all the jobs that use that window

■ Drop an open window

If a job associated with a window is running, a DROP_WINDOW procedure willcontinue to run through to completion and is disabled after it completes. If you setthe STOP_ON_WINDOW_CLOSE attribute to TRUE, however, the job will immediatelystop when you drop an associated window. If you use the FORCE=TRUE setting,you’ll disable all jobs that use that window.

Prioritizing JobsAs you are aware, all database jobs are collected into job classes. You then map eachjob class to a specific resource consumer group. A resource plan is assigned to a resourceconsumer group and thus indirectly to each job class as well, by the Database ResourceManager. The active resource plan (as determined by the currently open window) willapportion resources to groups, thus giving different levels of resources to different jobs,based on their job class.

The Scheduler works closely with the Resource Manager to ensure proper resourceallocation to the jobs. The Scheduler will start a job only if there are enough resourcesto run.

To see which resource consumer group a session belongs to, you can use thefollowing query:

SQL> select sid, serial#,username,resource_consumer_group from v$session;

Within each Scheduler window, you can have several jobs running, with varyingdegrees of priority. You can prioritize jobs at two levels—class and job. The prioritization

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

28 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 348: OCA OCP - Oracle10G New Features For Administrators Exam Guide

at the class level is based on the resources allocated to each resource consumer groupby the currently active resource plan. For example, the FINANCE_JOBS class mightrank higher than the ADMIN_JOBS class, based on the resource allocations dictatedby its active resource plan.

Within the FINANCE_JOBS and ADMIN_JOBS classes, there will be severalindividual jobs. Each of these jobs has a job priority, which can range from 1 to 5,with 1 being the highest priority. You can use the SET_ATTRIBUTES procedureto change the job priority of any job, as shown here:

begindbms_scheduler.set_attribute (name => 'test_job',attribute => 'job_priority',value => 1);

end;

The default job priority for a job is 3, which you can verify with the following query:

SQL> select job_name, job_priority from dba_Scheduler_jobs;JOB_NAME JOB_PRIORITY------------------------------ ------------ADV_SQLACCESS1523128 3ADV_SQLACCESS5858921 3GATHER_STATS_JOB 3PURGE_LOG 3TEST_JOB03 3TEST_JOB1 36 rows selected.SQL>

When you have more than one job within the same class scheduled for the sametime, the job_priority of the individual jobs determines which job starts first.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Managing Advanced Scheduler Components 29

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Please take time todistinguish between interclass priority levelsand intraclass job priority levels. Be awarethat job priority is only within a class, and

therefore, a low-priority job belonging to ahigh-priority class wll run ahead of a high-priority job in a low-priority class.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 349: OCA OCP - Oracle10G New Features For Administrators Exam Guide

30 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Window PrioritiesSince windows might have overlapping schedules, you may frequently have more thanone window open at the same time, each with its own resource plan. At times like this,the Scheduler will close all windows except one, using certain rules of precedence.Here is a summary of the windows precedence rules:

■ If two windows overlap, the window with the higher priority opens and thewindow with the lower priority closes.

■ If two windows of the same priority overlap, the active window remains open.

■ If you are at the end of a window and you have other windows defined forthe same time period, the window that has the highest percentage of timeremaining will open.

Window GroupsA window group is a collection of windows, and is part of the SYS schema. Windowgroups are optional entities, and you may make a window a part of a window groupwhen you create it, or add windows to the group at a later time.You can specify eithera single window or a window group as the schedule for a job.

As explained earlier in this chapter, you may take two or more windows that havesimilar characteristics—for example, some night windows and a holiday window—and club them together to create a “downtime window group.” The concept of awindow group is for convenience only, and its use is purely optional.

Managing Scheduler AttributesIn earlier sections in this chapter, you’ve seen how you can use the procedure SET_ATTRIBUTE to modify various components of the Scheduler. Attributes like JOB_NAME and PROGRAM_NAME are unique to the job and program components.

You can retrieve the attributes of any Scheduler component with the GET_SCHEDULER_ATTRIBUTE procedure of the DBMS_SCHEDULER package.

Unsetting Component AttributesUse the SET_ATTRIBUTE_NULL procedure to set a Scheduler component’s attributesto NULL. For example, to unset the comments attribute of the program TEST_PROGRAM, you can use the following code:

execute dbms_scheduler.set_attribute_null('TEST_PROGRAM', 'COMMENTS');

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 350: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing Advanced Scheduler Components 31

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Altering Common Component AttributesThere are some attributes that are common to all Scheduler components. The procedureSET_SCHEDULER_ATTRIBUTE lets you set these common, or global level, attributevalues, which affect all Scheduler components. Let’s discuss these common attributesin the following sections.

default_timezone If jobs and windowsspecifications use the calendering syntax but omitthe start date, the Scheduler derives the timezone from the default_timezone attribute.

log_history This attribute refers to the numberof days the Scheduler will retain job and windowlogs. The default retention period is 30 days.

max_job_slave_processes The Scheduler determines the optimal number ofjob slave processes, based on your processing requirements. However, you can set alimit on the number of job slave processes using the max_job_slave_processesattribute, whose default value is NULL, and the range is from 1 to 999.

Viewing Information About the SchedulerYou can use a set of data dictionary views to manage the Scheduler. Let’s take a brieflook at the important Scheduler-related data dictionary views.

DBA_SCHEDULER_JOBS This view provides the status and general informationabout scheduled jobs in your database. Here’s a simple query using the view:

SQL> select job_name, program_name fromdba_scheduler_jobs;

JOB_NAME PROGRAM_NAME-----------------------------------------------------ADV_SQLACCESS1523128 ADV_SQLACCESS5858921GATHER_STATS_JOB GATHER_STATS_PROGPURGE_LOG PURGE_LOG_PROGTEST_JOB03…SQL>

DBA_SCHEDULER_RUNNING_JOBS This view provides you withinformation regarding currently running jobs.

Oracle recommendsthat you set the default_timezoneattribute to a region’s name instead ofabsolute time zone offset, in order toensure that daylight saving adjustmentsare being taken into account.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 351: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

DBA_SCHEDULER_JOB_RUN_DETAILS This view provides informationabout status and the duration of execution for all jobs in your database, as the followingexample shows.

SQL> select job_name, status, run_durationfrom dba_Scheduler_job_run_details;

JOB_NAME STATUS RUN_DURATION---------------------------------------------------GATHER_STATS_JOB SUCCEEDED +000 00:09:37ADV_SQLACCESS5858921 FAILED +000 00:00:03SQL>

DBA_SCHEDULER_SCHEDULES This view provides information on allcurrent schedules in your database, as shown in the following query:

SQL> select schedule_name, repeat_interval2* from dba_Scheduler_schedules;

SCHEDULE_NAME REPEAT_INTERVAL------------------------------------------------------------------------DAILY_PURGE_SCHEDULE freq=daily;byhour=3;byminute=0;bysecond=0SQL>

DBA_SCHEDULER_JOB_LOG This viewenables you to audit job management activitiesin your database. The data that this view willcontain depends on how you set the loggingparameters for your jobs and job classes.

In order to set the logging level at the job classlevel, you need to use the DBMS_SCHEDULERprocedure’s LOGGING_FULL and LOGGING_

RUNS when you create your job class, as shown in the earlier section “Creating aJob Class.”

In order to set the logging levels at the individual job level, you use the SET_ATTRIBUTE procedure of the DBMS_SCHEDULER. In the SET_ATTRIBUTEprocedure, you can set the attribute logging_level to two different values:

DBMS_SCHEDULER.LOGGING_FULLDBMS_SCHEDULER.LOGGING_RUNS

The LOGGING_RUNS option will merely record the job runs, while the LOGGING_FULL option turns on full job logging. Here is an example showing how you can turnon full job logging at the job level:

execute dbms_scheduler.set_attribute ('TESTJOB','LOGGING_LEVEL', dbms_Scheduler.LOGGING_FULL);

32 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

The DBA_SCHEDULER_JOB_RUN_DETAILS view providesinformation about the status and durationof execution for all Scheduler jobs.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:37 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 352: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing Advanced Scheduler Components 33

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Purging Job LogsBy default, once a day, the Scheduler will purge all window logs and job logs that areolder than 30 days. As long as the Scheduler is active, it runs the PURGE_JOB job toperform this automatic purging of the logs. You can also manually purge the logs byexecuting the procedure yourself, as shown here:

execute dbms_scheduler.purge_log (log_history => 1,job_name => 'TEST_JOB1');

You can modify the retention period (the default is 30days) of the logs for a jobclass by using the SET_ATTRIBUTE procedure, as shown here:

dbms_scheduler.set_attribute('TEST_JOB_CLASS', 'log_history', '7');

In the preceding example, the log_history attribute resets the log retentionperiod to seven days.

In order to clear all window and job logs, use the following command:

execute dbms_scheduler.purge_log();

As a DBA, you can setlogging at the job class level in order toaudit Scheduler jobs. Once you set thelogging at the class level, an individual usercan only increase the amount of logging.For example, if you set LOGGING_RUNS atthe job class level, the creator of a job may

turn off logging at the job level, yet theScheduler will log the job run information.A user, however, can increase the logginglevel to LOGGING_FULL for a job, thusraising the level of logging from the LOGGING_RUNS level you set to a higher logging level.

The log_historyattribute specifies the number of days tokeep the logs. It can take a value between

0 and 999. If you set it to 0, it means thatyou want to purge all log entries daily.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 353: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CERTIFICATION OBJECTIVE 7.04

Database Resource Manager EnhancementsThe Database Resource Manager helps you to effectively manage your server resources.There are several important enhancements in the Resource Manager tool in OracleDatabase 10g. Using the idle_time resource plan, you can set limits on idle time foruser sessions that are blocking other sessions. You can specify that a session is returnedto its original consumer group automatically, after a top call. You can now use consumergroup mappings to assign priorities to consumer groupings. There is also a new CPUallocation method in the DBMS_RESOURCE_MANAGER package.

Let’s start our discussion of the Resource Manager enhancements by looking at thenew ways you can set idle time-outs in Oracle Database 10g.

Setting Idle Time-OutsYou can now limit the maximum idle time for a session as well as the maximum timean idle session can block another session. Until now, the only way to limit session idletime was by setting the value of the IDLE_TIME attribute while creating or altering adatabase profile.

You set the new idle time limits using the CREATE_PLAN_DIRECTIVE procedureof the Database Resource Manager. The new argument MAX_IDLE_TIME determinesthe maximum idle time of a session. The other new argument, MAX_IDLE_BLOCKER_TIME, determines the maximum amount of time an idle session can block anothersession. Here is an example:

exec dbms_resource_manager.create_plan_directive(plan => 'new_plan', -group_or_subplan => 'sales',comment => 'sales group', -cpu_p1 => 60,parallel_degree_limit_p1_P1 => 4max_idle_time => 600,max_idle_blocker_time => 300);

The default value for both the MAX_IDLE_TIME and MAX_IDLE_BLOCKER_TIME is NULL, which implies that the idle time is unlimited.

34 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 354: OCA OCP - Oracle10G New Features For Administrators Exam Guide

In the preceding example, the maximum time a session can remain idle is cappedat 600 seconds by the MAX_IDLE_TIME attribute. After this time, if a session continuesto sit idle, without executing or waiting for I/O, the PMON process kills the sessionand cleans up after it. The MAX_IDLE_BLOCKER_TIME ensures that the PMONalso kills any session that is idle for more than 300 seconds and is blocking anothersession. The PMON process grabs the offending sessions during its regular databasechecks, which it conducts on a minutely basis.

Automatic Switching Back to Initial Consumer GroupsWhen you create plan directives for the Database Resource Manager using the CREATE_PLAN_DIRECTIVE procedure of the DBMS_RESOURCE_MANAGER package, youcan use several switch parameters to stipulate the action to be taken after a specifiedtime period. The SWITCH_TIME parameter specifies the length of time that a sessioncan continue to execute before a certain action is taken.

In Oracle Database 10g, you now have a new switch parameter called SWITCHTIME_IN_CALL. Like the SWITCH_TIME parameter, this parameter also specifies the timethat a session can execute before a certain action is taken. However, the SWITCH_TIME_IN_CALL parameter has only one specific purpose: if you specify a valuefor this parameter, say 600 seconds; after that interval passes, at the end of the call,Oracle will switch the consumer group of that session to its initial consumer group.The initial consumer group you started with is specified by the SWITCH_GROUPattribute in the CREATE_PLAN_DIRECTIVE procedure that you use to implementthe Database Resource Manager. Unlike SWITCH_TIME, the SWITCH_TIME_IN_CALL parameter will only downgrade your session to a lower priority group for thatone call, whereas SWITCH_TIME will downgrade you permanently.

You cannot specify both SWITCH_TIME and SWITCH_TIME_IN_CALL plandirectives for a single consumer group.

The ability to switch sessions back to their initial consumer group at the end oftheir top call is a huge enhancement because it means that you can now use theResource Manager in the web environment, with connection pooling from themiddle tier. Previously, if you downgraded a connection because one web clientissued a horrific statement, it would stay downgraded for any subsequent jobs, evenif they came from other web clients.

Database Resource Manager Enhancements 35

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 355: OCA OCP - Oracle10G New Features For Administrators Exam Guide

36 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Creating Mappings to Assign Priorities to Resource GroupsAt any given time, a user session can belong to only one resource consumer group.You can now configure the Database Resource Manager to assign consumer groupsto sessions by mapping various session attributes to consumer groups. The ability tomap session attributes and consumer groups enables you to do two things:

■ Assign sessions to consumer groups

■ Assign priorities to indicate which mappings have precedence

Let’s first look at how you can assign consumer groups to sessions.

Creating Mapping Between Sessions and Consumer GroupsThere are two types of session atrributes—login attributes and run-time attributes. Whena user first logs into the database, the Resource Manager looks at the login attributes inorder to evaluate to which consumer group it should assign the session. The run-timeattributes are useful when an already logged in user’s session needs to be assigned toanother consumer group. Let’s look at the individual session atrributes in more detail,in the following section.

The ability to create session mappings is another enhancement that strengthensthe use of the Database Resource Manager in managing web applications. Inearlier versions of Oracle, the ORACLE_USER attribute was the only mapperavailable, and all your web clients were likely to use the same ORACLE_USERattribute through a connection pool. But in Oracle Database 10g, the DatabaseResource Manager can map sessions to groups according to what they are doing.

Session Attributes These are the key elements in the mapping of sessions andconsumer resource groups. As mentioned in the previous section, there are two typesof session attributes—run-time and login. Following are the login attributes:

■ ORACLE_USER The standard Oracle Database username

■ CLIENT_OS_USER The operating system name of the user

■ CLIENT_MACHINE The name of the machine from which the user isconnecting to Oracle

■ CLIENT_PROGRAM The name of the program the user is employing tolog into the database, for example, a SQL*Plus session

■ SERVICE_NAME The name used by the user to log into the database

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 356: OCA OCP - Oracle10G New Features For Administrators Exam Guide

There are five session attributes:

■ MODULE_NAME The module name in the application that is currentlyexecuting in the database

■ MODULE_NAME_ACTION The current module name and action beingperformed by the session

■ SERVICE_MODULE A combination of the service and the module name

■ SERVICE_MODULE_ACTION A combination of the service name, modulename, and action name

■ EXPLICIT An explicit mapping requested by the client

Creating the Mappings You map a session’s attributes to a consumer group byusing the SET_CONSUMER_GROUP_MAPPING procedure of the DBMS_RESOURCE_MANAGER package. You create an explict mapping between each session attributeand the resource group pair, as shown here:

execute dbms_resource_manager.set_consumer_group_mapping (DBMS_RESOURCE_MANAGER.ORACLE_USER, 'scott', 'dev group');

In the previous listing, a user with the operating system name SAM can log in asthe Oracle user SCOTT, and will be assigned to the “dev” consumer resource group.Notice that the ORACLE_USER attribute is being mapped to the resource group‘dev group’. In the following example, I map user SAM to the ‘prod group’, basedon the CLIENT_OS_USER attribute.

execute dbms_resource_manager.set_consumer_group_mapping -(DBMS_RESOURCE_MANAGER.CLIENT_OS_USER, 'SAM', 'prod_group');

Automatic Consumer Group Switching Oracle will follow an automaticconsumer group switching policy based on the specific mapping in force at any giventime. Here’s a summary of the switching policy:

■ When you first log in, you are mapped to the initial resource group based onthe attribute being mapped.

■ If you change a run-time attribute later, you are switched automatically to adifferent consumer group.

■ It is possible to be switched to the same consumer group you are currently in.

Database Resource Manager Enhancements 37

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 357: OCA OCP - Oracle10G New Features For Administrators Exam Guide

38 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Assigning Mapping Priorities As you can surmise, a single session can bemapped to several consumer resource groups, because you can map each sessionattribute to a consumer group. You may, for example, map a resource group basedon the value of a session’s MACHINE_NAME, CLIENT_OS_USER, MODULE_NAME,CLIENT_NAME, SERVICE_NAME_ACTION, or some other login or run-timeattribute. Naturally, there is room for a conflict or ambiguity regarding which resourcegroup to assign to a session, since there are multiple attributes to each session, andeach of them may be assigned to a different resource group. The Database ResourceManager uses priority levels to resolve such ambiguities. Let’s look at how you canassign priorities among session attributes.

You set session attribute mapping priorities byusing the SET_CONSUMER_GROUP_MAPPING_PRI procedure of the DBMS_RESOURCE_MANAGER package. This procedure helpsyou prioritize session mappings. In order toestablish priorities among the various attributes,you assign each session attribute a priority levelthat ranges from 1 to 10, with 1 being thehighest and 10 the lowest. Here’s an example:

SQL> dbms_resource_manager.set_consumer_group_mapping_pri ((explicit => 1,client_machine => 2,module_name => 3,oracle_user => 4,service_name => 5,client_os_user => 6,client_program => 7,module_name_action => 8,service_module => 9,service_module_action => 10);

All the priority levels you see in the preceding listing are the default prioritylevels of each of the session attributes, which you may change with the SET_CONSUMER_GROUP_MAPPING procedure.

In the preceding example, the session attribute ORACLE_USER has a prioritylevel of 4. Thus, even if the ORACLE_USER and the CLIENT_OS_USER attributesare mapped to different consumer resource groups, Oracle will assign the user to thegroup mapped to the ORACLE_USER session attribute because its priority level (4)is higher than the priority level of the CLIENT_OS_USER attribute (6).

A session must be a memberof a particular resource group in order to beswitched to it—a mere mapping between asession attribute and that group won’t sufficeto switch resource groups.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 358: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The MODULE_NAME and MODULE_NAME_ACTION attributes offer you powerful capabilitieswhen you are using web applications. Typically,middle-tier applications use a single usernamefor all the users, but use different MODULE_NAME and MODULE_NAME_ACTION attributesto distinguish between the type of work performedby individual users. The resource manager cannow detect what application module a sessionis actually invoking at any given moment, andassign resources appropriately (by associating the

session to the appropriate resource consumer group), independently of the DB logon(which is probably pooled from a middle tier).

New Database Resource Manager Allocation MethodsIn Oracle Database 10g, you have new methods of allocating CPU resources. Whenyou use the CREATE_CONSUMER_GROUP procedure, you can now set the CPU_MTHattribute to a RUN_TO_COMPLETION setting. When you use the CREATE_PLANprocedure to create a resource plan, you have a new setting called RATIO, for theCPU_MTH variable. Let’s take a quick look at both of these changes in the followingsections.

The RUN_TO_COMPLETION Allocation Method When you create aconsumer group using the CREATE_CONSUMER_GROUP procedure, the CPU_MTHoption provides the method to distribute your CPU among the sessions in the consumergroup. The default value for the CPU_MTH option is ROUND_ROBIN. The newRUN_TO_COMPLETION method specifies that the session with the largest activetime should be scheduled ahead of other sessions. Here’s an example:

exec dbms_resource_manager.create_consumer_group (consumer_group => 'sales',cpu_mth => 'RUN TO COMPLETION',comment => 'this is the new 10g cpu_mth option');

Usually, you would give batch and large data warehouse-type jobs a low priorityto avoid impacting your OLTP operations. But the RUN_TO_COMPLETIONCPU allocation method accords top priority to large jobs run by a particulargroup.

Database Resource Manager Enhancements 39

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Application developersmay also set the MODULE_NAME andMODULE_NAME_ACTION through theuse of the DBMS_APPLICATION_INFOpackage. The SERVICE_NAME attribute isthe connect string that you specify in yourtnsnames.ora file.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 359: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

The Ratio Allocation Method Previously, in Oracle9i, when you createda new resource plan, the CPU_MTH (the CPU resource allocation method) couldonly take a single value—EMPHASIS. In Oracle 10g, you can now use a newCPU allocation method when you create a resource plan, called RATIO. The RATIOallocation method is meant for single-level resource plans that use ratios to specifythe allocation of CPU. EMPHASIS remains as the default CPU allocation method,and it is for multilevel plans that use percentages to specify how CPU is allocatedamong various resource groups. Following is an example that shows how to specifyRATIO as a resource plan’s CPU allocation method.

dbms_resource_manager.create_plan(plan => 'service_level_plan',cpu_mth -> 'RATIO',comment => 'service level plan');

Once you choose the new RATIO allocation policy by specifying it as the CP_MTH value in the CREATE_PLAN statement, you aren’t quite ready to use the ratiomethod. You must also use the CREATE_PLAN_DIRECTIVE procedure and set theCPU_P1 directive to actually set the ratios for the CPU allocation. Here is an example:

SQL> dbms_resource_manager.create_plan_directive(plan => 'service_level_plan',group_or_subplan => 'GOLD_CG',comment => 'Gold service level customers',cpu_p1 => 10);

dbms_resource_manager.create_plan_directive(plan => 'service_level_plan',group_or_subplan => 'SILVER_CG',comment => 'Silver service level customers',cpu_p1 => 5);

dbms_resource_manager.create_plan_directive(plan => 'service_level_plan',group_or_subplan => 'BRONZE_CG',comment => 'Bronze service level customers',cpu_p1 => 2);

dbms_resource_manager.create_plan_directive(plan => 'service_level_plan',group_or_subplan => 'OTHER_GROUPS',comment => 'Lowest priority sessions',cpu_p1 => 1);

In the preceding example, there are four consumer groups—Gold_CG, Silver_CG, Bronze_CG, and the default OTHER_GROUPS. The CPU is allocated using theRATIO method. For every 18 units, the ratio of CPU allocation would be 10:5:2:1 for

40 Chapter 7: The Oracle Scheduler and the Database Resource Manager

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:38 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 360: OCA OCP - Oracle10G New Features For Administrators Exam Guide

the GOLD_CG, SILVER_CG, BRONZE_CG, and OTHER_GROUPS consumer groups,respectively. If at times you only have sessions for the first two groups—GOLD_CG andSILVER_CG—then these two groups would split the CPU resources in a 10:5 ratio.

Database Resource Manager Enhancements 41

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

The exam has questions that test yourfamiliarity with the logging and purging ofScheduler jobs. Know the default purgingprocedure for jobs and the various logginglevels. Which logging level gives you themost information?

You must remember the names andfunctions of the basic and advancedScheduler components. What is thepurpose of using advanced components likejob classes, windows, and window classes?What privileges do you need to manage eachof these components? The test will most likelyprobe your knowledge of job priorities. Knowthe difference between inter-job class andintra-job class priorities. When windowsoverlap, how does the Scheduler determinewindow priorities?

You must know how to set repeat intervalsfor jobs. Pay particular attention to calendaringexpressions. Practice with calendaring

expressions that set repeat intervals like oncea week and every five minutes.

You must know the DBMS_SCHEDULERpackage very well. Understand the differentparameters like start_date, end_date,repeat_interval, and duration. Howand which Scheduler attributes can you set atthe global level? The exam will test yourknowledge of the DBA_SCHEDULER_JOB_RUN_DETAILS and DBA_SCHEDULER_JOB_LOG views.

The exam tests your knowledge of the newresource allocation methods when you use theDBMS_RESOURCE_MANAGER package. Whatdo the RATIO and the RUN_TO_COMPLETIONresource allocation methods do? Know how toassign priorities using the DBMS_RESOURCE_MANAGER package, and how mappings arecreated between session attributes and specificconsumer resource groups.

INSIDE THE EXAMINSIDE THE EXAM

You must understand thatthe RUN_TO_COMPLETION and the oldROUND_ROBIN allocation methods arepart of the CREATE_CONSUMER_GROUPprocedure, and they apply to resource

consumer groups. The RATIO and the oldEMPHASIS allocation methods, on the otherhand, are used with the CREATE_PLANprocedure and apply to resource plans.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 361: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CERTIFICATION SUMMARYThe chapter started with an introduction to the all-new Oracle Scheduler feature.You learned about the basic building blocks of the Scheduler—jobs, programs, andschedules. You also learned how to create and administer these basic components.

You were introduced to the main features of the advanced Scheduler components,including job classes and windows. You saw how you can associate job classes withresource consumer groups. You also learned how you can control resource allocationby associating resource plans with Scheduler windows.You learned how to query themain data dictionary view concerning the Scheduler.

In the last part of this chapter, you learned about the advancements in the DatabaseResource Manager feature. These include the new idle time-outs for consumer groups,automatic switching of consumer groups at the end of the top call, and the automaticassignment of sessions to consumer groups through the mapping of session attributes.You then learned how to utilize the new CPU_MTH methods for allocating CPU—the RUN_TO_COMPLETION and RATIO methods.

42 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 362: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Two-Minute Drill 43

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

✓TWO-MINUTE DRILL

Simplifying Management Tasks by Using the Scheduler

❑ The Scheduler replaces DBMS_JOB as the main scheduling facility inOracle Database 10g.

❑ Use the DBMS_SCHEDULER package to manage the Scheduler.

❑ You can schedule PL/SQL programs, Java programs, native binaryexecutables, and shell scripts.

❑ Jobs, programs, and schedules are the basic Scheduler components.

❑ A job is a task you run one or more times.

❑ You can run a job by itself or with a saved program and/or a saved schedule.

❑ A schedule tells you when and how frequently you should run a job.

❑ A program contains metadata about a job.

❑ A job class groups several similar jobs into one large entity.

❑ In a job class, the priority levels range from 1 to 5.

❑ A higher-priority job always starts before a lower-priority job.

❑ A window represents a time during which you can schedule a job.

❑ A window always has a resource plan associated with it.

❑ A window group is a collection of windows.

❑ The Scheduler assigns each job class to a specific resource consumer group.

❑ The default resource consumer group is the DEFAULT_CONSUMER_GROUP.

❑ The default job class is the DEFAULT_JOB_CLASS.

❑ The job table records information about all the jobs run by the Scheduler.

❑ The background process cjqNNN automatically starts and monitors therunning of a job.

❑ The job slaves start database sessions and execute the job.

❑ Jobs, programs, and schedules are created in the current user’s schema.

❑ Job classes, windows, and windows groups are created in the SYS schema.

❑ To create the basic components, you need the CREATE JOB privilege.

❑ To use the advanced Scheduler components, you must have the MANAGESCHEDULER system privilege.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 363: OCA OCP - Oracle10G New Features For Administrators Exam Guide

44 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

❑ The EXECUTE ANY PROGRAM privilege lets a user execute a programunder any schema.

❑ The SCHEDULER_ADMIN role contains all the Scheduler system privileges.

Managing the Basic Scheduler Components

❑ All Scheduler objects are of the form [schema].name.

❑ When you create a job, the parameter values you specify will override thedefault values for programs and schedules.

❑ You create a job using the CREATE_JOB procedure.

❑ You can run a PL/SQL block, a Java program, a shell script, or a native binaryexecutable as part of your job.

❑ You can use a PL/SQL date/time expression or a calendaring expression forsetting the repeat_interval parameter.

❑ Calendaring expressions have three components: frequency, repeat interval,and any optional specifiers.

❑ You must have the MANAGE SCHEDULER privilege in order to use theFORCE setting when you stop or drop a job.

Managing Advanced Scheduler Components

❑ The Scheduler uses job classes, windows, and window classes to prioritize jobsin the database.

❑ Each job class is associated with a resource consumer group.

❑ The logging level when you create a job class can take the values LOGGING_OFF, LOGGING_RUNS, or LOGGING_FULL.

❑ The default logging level is LOGGING_RUNS.

❑ The purpose of a window is to automatically switch resource plans duringcertain periods.

❑ Windows consist of three basic components: schedules, duration, andresource plan.

❑ Window priorities can take the values LOW or HIGH.

❑ You can have overlapping windows, since the Scheduler doesn’t check beforecreating new windows.

❑ You can use the SET_ATTRIBUTES procedure to change the job priorityof a job.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 364: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Two-Minute Drill 45

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

❑ Window priorities are resolved by checking which window has the higherpriority level, or whichever window opened first, if the window priorities arethe same.

❑ You can use the SET_ATTRIBUTE_NULL procedure to set a Schedulercomponent’s attributes to NULL.

Viewing Information About the Scheduler

❑ The DBA_SCHEDULER_JOBS view provides information about the statusand general information about scheduled jobs.

❑ The DBA_SCHEDULER_RUNNING_JOBS view provides information aboutcurrently running jobs.

❑ The DBA_SCHEDULER_JOB_RUN_DETAILS view provides informationabout the status and the duration of execution for all jobs.

❑ The DBA_SCHEDULER_SCHEDULES view provides information on allsaved schedules.

Database Resource Manager Enhancements

❑ You can now set idle time limits using the CREATE_PLAN_DIRECTIVEprocedure of the DBMS_RESOURCE_MANAGER package.

❑ You can use the MAX_IDLE_TIME parameter to limit idle sessions. You canuse the MAX_IDLE_BLOCKER_TIME to limit idle sessions that are blockingother sessions.

❑ The new SWITCH_TIME_IN_CALL parameter automatically returns asession to its original resource consumer group, after the database completesthe top call.

❑ You can create mappings between session attributes and resource consumergroups.

❑ You can create as many mappings as there are session attributes.

❑ You can assign session attribute mapping priorities by using the DBMS_RESOURCE_MANAGER.SET_CONSUMER_GROUP_MAPPING_PRIprocedure.

❑ You can now set the CPU_MTH attribute to the new RUN_TO_COMPLETION setting.

❑ You can now use the new CPU allocation method RATIO, which uses ratiosto specify the allocation of CPU resources among various resource groups.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 365: OCA OCP - Oracle10G New Features For Administrators Exam Guide

46 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

SELF TESTThe following questions will help you measure your understanding of the material presented inthis chapter. Read all the choices carefully because there might be more than one correct answer.Choose all correct answers for each question.

Simplifying Management Tasks by Using the Scheduler

1. Whose job is it to update the job table and the log table?

A. The worker (slave) processB. The SYS userC. The Database Resource ManagerD. The cjqNNN background process

2. Which of the following do you need to specify a stored schedule that’s owned bya different user?

A. You must have the EXECUTE ANY SCHEDULE privilege.B. You don’t need any privileges to use a stored schedule.C. You need the MANAGE SCHEDULER privilege.D. You need the EXECUTE ANY JOB privilege.

3. Which of the following is true when you are using saved schedules and programs as part of anew job?

A. If you explicitly use parameters that are also in the schedules or programs, the parametervalues you specify will override the values specified for the parameters in the schedules andprograms.

B. If you explicitly use parameters that are also in the schedules or programs, the parametervalues you specify will be overridden by the values specified for the parameters in theschedules and programs.

C. You can’t use separate parameter values in a job creation statement if they are already partof a schedule or a program.

D. You cannot use saved schedules and programs with a new job.

4. If you create a job in user SCOTT’s schema, who will be the owner of the job?

A. SCOTT will be the owner of the job.B. SYS will be the owner of the job.C. You will be the owner of the job.D. PUBLIC will be the owner of the job.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 366: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test 47

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Managing the Basic Scheduler Components

5. What is the correct syntax to create a schedule that executes every second?

A. FREQ=SECONDLY; INTERVAL=1/60

B. FREQ=SECONDLY; INTERVAL=1

C. FREQ=SECONDLY

D. FREQ=HOURLY; INTERVAL=1/60

6. Regarding your ability to combine the various components of the Scheduler, which of thefollowing are possible?

A. Use a job by itself all the time.B. Use a job and a program together.C. Use a job, schedule, and a program together.D. Use a program and a schedule together.

7. What is the priority level for a job in a job class?

A. From 1 to 5B. From 1 to 999C. From 1 to 10D. A job can only take a value of HIGH or LOW.

8. Scheduler job table information can be seen in which view?

A. DBA_RESOURCE_MANAGER viewB. DBA_JOBS viewC. DBA_SCHEDULER_JOBS viewD. DBA_SCHEDULER view

Managing Advanced Scheduler Components

9. You create a new job class and name it my_job_class. Where will this job class be saved?

A. In your schema.B. In the SYS schema.C. In all schemas that are part of the database.D. Job classes aren’t saved under any one schema.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 367: OCA OCP - Oracle10G New Features For Administrators Exam Guide

48 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

10. You create a job class and set the LOGGING_RUNS option for the LOGGING_LEVELparameter. What will be the result?

A. The database will not perform any logging for individual jobs.B. The database will not perform a detailed logging of the job runs.C. The database will perform a detailed logging of the job runs.D. For each run of a job, there will just be a mention of the job only in the job log.

11. The DBA wishes to drop an existing job class. The DBA notices that a job from the job classshe wants to drop is currently running. Which of the following scenarios would be true?

A. You cannot drop the jobs along with the job class definition.B. If you use the FORCE=TRUE option, the running jobs will stop immediately and the job

class will be removed as well.C. Just use the DROP_JOB_CLASS with no options to drop the job class and kill any running

jobs right away.D. If you use the FORCE=TRUE option, the running jobs will continue to completion anyway,

but the job class and its jobs will be removed.

12. What important attribute does a window have, that a schedule doesn’t?

A. A programB. An intervalC. A resource planD. A resource consumer group

Viewing Information About the Scheduler

13. To see which Scheduler jobs are currently running, which view would you use?

A. DBA_SCHEDULER_RUNNING_JOBS viewB. DBA_SCHEDULER_JOB_RUN_DETAILS viewC. DBA_SCHEDULER_SCHEDULES viewD. DBA_SCHEDULER_JOBS view

14. Using the SET_ATTRIBUTE procedure, you can set the logging_level attribute to whichtwo values?

A. LOGGING_NONE and LOGGING_RUNSB. LOGGING_DEFAULT and LOGGING_RUNS

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 368: OCA OCP - Oracle10G New Features For Administrators Exam Guide

C. LOGGING_DETAILED and LOGGING_RUNSD. LOGGING_FULL and LOGGING_RUNS

15. What will the command EXECUTE DBMS_SCHEDULER.PURGE_LOG(); do?

A. Purge only all the window logsB. Purge only all the job logsC. Purge all window and job logsD. Purge only yesterday’s job logs

16. Where can you find the status and duration of execution of all jobs in your database?

A. DBA_SCHEDULER_JOB_RUN_DETAILS

B. DBA_SCHEDULER_RUNNING_JOBS

C. DBA_SCHEDULER_SCHEDULES

D. DBA_SCHEDULER_JOBS

Database Resource Manager Enhancements

17. Which procedure of the DBMS_RESOURCE_MANAGER package enables the DBA to set idletime limits?

A. DBMS_RESOURCE_MANAGER.create_plan_directive

B. DBMS_RESOURCE_MANAGER.create_resource_plan

C. DBMS_RESOURCE_MANAGER.create_resource_group

D. DBMS_RESOURCE_MANAGER.idle_time

18. In the context of using the DBMS_RESOURCE_MANAGER package to set mapping priorities,what kind of attribute is MODULE_NAME?

A. Run-time session attributeB. Neither a run-time nor a login session attributeC. Login attributeD. Could be either a run-time attribute or a login session attribute

19. What is the default value for the CPU_MTH option when you are creating a consumer group?

A. ROUND_ROBIN

B. RATIO

C. RUN_TO_COMPLETION

D. DEFAULT

Self Test 49

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:39 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 369: OCA OCP - Oracle10G New Features For Administrators Exam Guide

50 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

20. When you create a mapping between consumer groups and session attributes, how manyconsumer resource groups can a single session map to?

A. Only one consumer resource groupB. At most two resource consumer groupsC. As many resource consumer groups as there are session attributesD. A unique consumer resource group each time you log in again

LAB QUESTIONS

Lab 1

Use the Database Resource Manager to ensure that all idle sessions will not last more than 20 minutes.Also ensure that you kill all idle sessions that have been around for more than a minute and are blockingother user sessions.

Lab 2

Create a schedule, a program, and a job to gather data at five-minute intervals in your database.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 370: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test Answers 51

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

SELF TEST ANSWERS

Simplifying Management Tasks by Using the Scheduler

1. � A. The worker (slave) process updates the job table and log table.� B and C are wrong since neither the SYS user nor the Database Resource Manager playany role in updating the log and the job tables. D is wrong since the cjqNNN backgroundprocess identifies the job coordinator, who doesn’t execute any chores directly, but ratherhands them to the slave (worker) processes. These jobs include updating the Scheduler joband log tables.

2. � B. You don’t need any privileges to use any of the saved schedules in the database.� A, C, and D are wrong since you don’t need any specific privileges to use a saved schedule.

3. � A. If you use separate parameter values for any schedule- or program-related parameterswhile creating a job, those values will override the values for these parameters specified in anyschedules or programs that you may be using in the job creation statement.� B is wrong because it states the opposite of the correct answer. C is wrong since you canspecify parameter values for the parameters specified in a schedule or a program. D is wrongsince you can use saved programs and schedules when you create a new job.

4. � A. The creator of a job need not be the owner of a job. User Scott will be the owner ofthe job since you’re creating the job in Scott’s schema.� B, C, and D are incorrect since a job is owned by the user in whose schema you createthe job.

Managing the Basic Scheduler Components

5. � B and C. B is correct since FREQ=SECONDLY will help you execute a schedule thatwill execute on a minutely basis. Answer C will also execute the schedule every second.� A is wrong since it states that the program will execute 60 times in one second! D iswrong since it will execute the job every minute, not every second.

6. � A, B, and C are all correct. You can use a job all by itself or with either or both of theoptional objects—schedule and program.� D is wrong since you can’t use the Scheduler without a job.

7. � A. The priority level for a job can range from 1 to 5.� B, C, and D are the wrong priority levels.

8. � C. The DBA_SCHEDULER_JOBS view captures the data in the Scheduler job table.� A, B, and D refer to the wrong views.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 371: OCA OCP - Oracle10G New Features For Administrators Exam Guide

52 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

Managing Advanced Scheduler Components

9. � B is correct because all job classes are saved in the SYS schema.� A and C are wrong since they point to the wrong schemas. D is wrong since it says thatjob classes can’t be saved in any schema.

10. � C. LOGGING_RUNS means there will be a detailed log of all job runs.� A is wrong since there will be logging. B is wrong since there will be detailed logging ofall job runs. D is wrong since the logging isn’t merely limited to the mention of the job—therewill be a detailed logging for each job.

11. � D is correct since using the FORCE=TRUE option will remove the job class, but anycurrently running jobs will continue to completion.� A is wrong since you can drop a job along with its job class. However, note that when youdrop a job class, its jobs aren’t really dropped, but disabled. B is wrong since the FORCE=TRUEoption won’t stop a running job before it completes. C is wrong since you can’t kill running jobswhile dropping a job class.

12. � C. A window always has a resource plan, but a schedule doesn’t have one.� A and B are wrong since both windows and schedules have a program and interval. D iswrong since you don’t have to specify the resource consumer group for either a window or aschedule.

Viewing Information About the Scheduler

13. � A. The DBA_SCHEDULER_RUNNING_JOBS view shows you details about all currentlyrunning jobs.� B is wrong since the DBA_SCHEDULER_JOB_RUN_DETAILS view shows you the statusand duration of execution of all jobs in your database. C is wrong because the DBA_SCHEDULER_SCHEDULES view provides information on all schedules in your database. D is wrong becausethe DBA_SCHEDULER_JOBS view shows the status and general information for all yourscheduled jobs.

14. � D. LOGGING_FULL and LOGGING_RUNS options are valid.� A, B, and C are wrong since they contain a nonexistent logging option.

15. � C. The command will purge all window and job logs.� A is wrong since the command will also purge all job logs. B is wrong because the commandwill also purge all window logs. D is wrong because the command will purge all window andjob logs, not just yesterday’s logs.

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 372: OCA OCP - Oracle10G New Features For Administrators Exam Guide

16. � A. The DBA_SCHEDULER_JOB_RUN_DETAILS view provides the status and durationof execution of all jobs.� B, C, and D point to the wrong data dictionary views. Please refer to the explanation forQuestion 13 for more details on why these are incorrect answers.

Database Resource Manager Enhancements

17. � A. The CREATE_PLAN_DIRECTIVE procedure lets you specify idle time limits for sessions.� B is wrong since the CREATE_RESOURCE_PLAN directive helps you specify resourceplans. C is a wrong choice since the CREATE_RESOURCE_GROUP is only useful for specifyingthe members of a resource consumer group. D refers to a nonexistent procedure.

18. � A. The MODULE_NAME attribute belongs to the group of run-time session attributes.� B, C, and D are wrong because MODULE_NAME is a run-time attribute.

19. � A. The old ROUND_ROBIN method is still the default method.� B, C, and D aren’t default values for the CPU_MTH option.

20. � C. You can map a single session to as many resource consumer groups as there are sessionattributes, since you can map each of the attributes to a separate resource consumer group.� A, B, and D provide the wrong alternatives.

LAB ANSWERS

Lab 1

To kill idle sessions that go over a set idle time limit, use the DBMS_RESOURCE_MANAGER packagein the following way, and set the MAX_IDLE_TIME and MAX_IDLE_BLOCKER_TIME parameters.(Note that you must create the pending area before you can create the following plan.)

SQL> begindbms_resource_manager.create_plan_directive (plan => 'TEST_PLAN',group_or_subplan => 'TEST_GROUP',comment => 'Limit user idle time',max_idle_time => 600,max_idle_blocker_time => 300);

end;

Lab Answers 53

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 373: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Lab 2

1. Create the program.

SQL> begindbms_scheduler.create_program (program_name => 'DAILY_GATHERING',program_action => 'DAILY_DATA_GATHERING',program_type => 'STORED_PROCEDURE',enabled => 'TRUE');

end;

2. Create the schedule.

SQL> begindbms_scheduler.create_job (job_name => 'DAILY_GATHERING_JOB',program_name => 'DAILY_GATHERING',start_date => 'TRUNC(SYSDATE+1)+22/24',repeat_interval => 'TRUNC(SYSDATE+1)+22/24',comments => 'Daily Data Gathering Job.');end;

SQL> begindbms_scheduler.create_schedule (schedule_name => 'TEST_SCHEDULE',start_date => SYSTIMESTAMP,repeat_interval => 'FREQ=MINUTELY;INTERVAL=5',comments => 'A test schedule.');

end;

3. Create the job using the program and schedule you created in the previous two steps.

SQL> begindbms_scheduler.create_job (job_name => 'DAILY_GATHERING_JOB',program_name => 'DAILY_GATHERING',schedule_name => 'TEST_SCHEDULE');

end;

54 Chapter 7: The Oracle Scheduler and the Database Resource Manager

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7

P:\010Comp\CertPrs8\862-4\ch07.vpTuesday, September 07, 2004 4:38:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 374: OCA OCP - Oracle10G New Features For Administrators Exam Guide

8Backup and

RecoveryEnhancements

CERTIFICATION OBJECTIVES

8.01 Using the Flash Recovery Area

8.02 Using Incremental Backups

8.03 Enhanced RMAN Commands

8.04 Miscellaneous Backup and RecoveryEnhancements

✓ Two-Minute Drill

Q&A Self Test

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8Blind Folio 8:1

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:55 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 375: OCA OCP - Oracle10G New Features For Administrators Exam Guide

2 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

Oracle Database 10g contains several interesting innovations in the backup and recoveryarea. You can now store all recovery-related files, such as archive logs and databasebackups, in a unified location on disk. This unified storage location is the new flash

recovery area, and it enables DBAs to simplify file management for all recovery-related files.Cheaper and faster modern disk storage means that you can recover more quickly from a disk-based recovery strategy than from a tape-based backup strategy.

The RMAN can now help you recover image copies using incremental backupfiles. Oracle Database 10g contains new methods for making faster incrementalbackups. This chapter also looks at several changes in the RMAN backup commands,including the deprecation of the COPY command. You’ll also learn how to performa hot recovery without needing to restore backup files first, by using the SWITCHDATABASE command. This capability will enable you to implement a faster databaserecovery.

You can also create compressed backup sets in Oracle Database 10g to save onstorage space. You’ll learn about simplified database recovery after using RESETLOGS,without needing the usual full backup. You’ll learn how to drop a database using theDROP DATABASE command. You’ll review the new features that let you specify limitson your backup windows.

Let’s start with a detailed look at the interesting and very useful flash recoveryarea feature.

CERTIFICATION OBJECTIVE 8.01

Using the Flash Recovery AreaThe flash recovery area serves as the default storage area for all files related to backupand restore operations. You can use an Oracle-managed directory, an operating systemfile system, or an Automatic Storage Management (ASM) disk group for your flashrecovery area. Traditionally, Oracle DBAs have needed to manage the backup-relatedstorage areas, making sure that there was enough storage space to save their backup-related files. Oracle recommends that you now let the database take care of these chores,by using the new strategy of automatic disk-based backup and recovery.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:55 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 376: OCA OCP - Oracle10G New Features For Administrators Exam Guide

To enable this feature, you simply designate sufficient disk space as the flashrecovery area, specify the area’s maximum size, and let Oracle know how long youwant to retain the backup-related information. Oracle will then manage the backupof related files, including archive log files, control files, and other files. Oracle willdelete the files that your database no longer needs because the files have becomeobsolete or they have been backed up to tape. Thus, your main tasks will be provisioningadequate space for the flash recovery area and selecting the appropriate retentionperiod for keeping the related files.

Once you create the flash recovery area, you can direct all you backup files, includingthe archived redo log files, to that area. Oracle will manage these files for you,deleting the files that either are backed up to tape or are older than the backupretention interval. In order to automatically delete unwanted files, the flash recoveryarea concept relies on the Oracle Managed Files (OMF) system. OMF automates filemanagement in Oracle databases by automatically creating and managing the operatingsystem files that you allocate for your database. All you need to do to get an OMFfile system going is to configure a couple of OMF-related initialization parameters:DB_CREATE_FILE_DEST and DB_CREATE_ONLINE_LOG_DEST_n. As youare aware, OMF has the capability to automatically create and delete Oracle files,without the DBA’s intervention. The RMAN capitalizes on this capability of theOMF file system to perform its backup- and recovery-related functions through usingthe flash recovery area.

You can also use a flash recovery area on top an ASM file system (see Chapter 10for a discussion of ASM file systems). ASM file systems consolidate disks into easilymanageable disk groups, and provide striping and mirroring capabilities based on theOracle database itself.

The flash recovery area provides the following benefits:

■ Single storage location for all recovery-related files

■ Automatic management of recovery-related disk space

■ Faster backup and restore operations, sinceyou don’t need to restore tape backups

■ Increased reliability of backups, since disksare generally safer storage devices than tapes

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

Using the Flash Recovery Area 3

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

Several databases canshare a central flash recovery area.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:55 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 377: OCA OCP - Oracle10G New Features For Administrators Exam Guide

4 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

What’s in the Flash Recovery Area?You keep all the files you need for media recovery in the flash recovery area. Ideally,your flash recovery area must hold a complete backup of all your datafiles, any incrementalbackups you may have, control file backups, and all the archived redo logs that arenecessary for media recovery. You can also use the flash recovery area as a disk cachefor tape.

The flash recovery area may contain the following files:

■ Datafile copies You can make copies of the database datafiles using the newRMAN command BACKUP AS COPY. You can use this command to createimage copies of all datafiles, which the RMAN will automatically store in theflash recovery area.

■ Control file autobackups The flash recovery area serves as the defaultlocation for all control file autobackups made by the RMAN. The databaseplaces any control file backups it generates in the flash recovery area.

■ Archived redo log files Since Oracle automatically deletes all obsolete filesand files that have been transferred to tape, the flash recovery area is an ideallocation for archived redo log files. You don’t need to manually delete the oldarchived redo log files, because Oracle will automatically delete the files ifyou store them in the flash recovery area.

■ Online redo log files Oracle recommends that you save a multiplexed copyof your online redo log files in the flash recovery area. Oracle will generate itsown names for the online redo log files. The default size of an online redo filethat’s created in the flash recovery area is 100MB. The following statementscan create online redo logs in the flash recovery area: CREATE DATABASE,ALTER DATABASE ADD LOGFILE, ALTER DATABASE ADD STANDBYLOGFILE, and ALTER DATABASE OPEN RESETLOGS.

■ Current control files Oracle also recommends that you store a multiplexedcurrent control file in the flash recovery area.

All files that you need torecover from a media failure are part ofyour flash recovery area. You should beable to completely recover your database

by using the files in the flash recovery area.In addition to these recovery files, you mayalso store other database files in the flashrecovery area.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:55 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 378: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using the Flash Recovery Area 5

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

■ RMAN files If you specify a location for the flash recovery area by usingthe DB_RECOVERY_FILE_DEST initialization parameter, the RMANwill, by default, use the flash recovery area for storing its backup-related files.Oracle will also automatically use OMF files and will generate the filenames.As noted, Oracle saves all control file backups and autobackups made by theRMAN in the flash recovery area as well.

■ Flashback logs Oracle stores all flashback logs in the flash recovery area. If youenable the flashback database feature (discussed in Chapter 9), Oracle copiesimages of each altered block in every datafile into flashback logs stored in theflash recovery area. The database will use these flashback logs to reconstructthe datafile contents as of any moment at which it captured the logs.

Oracle calls the multiplexed redo log files and control files in the flash recoveryarea permanent files, since they should never be deleted and are part of the livedatabase. Oracle terms all the other files in the flash recovery area (recovery-related files) transient files, since Oracle will delete them eventually after theyhave become obsolete or have already been copied to tape.

The background process Archiver (ARCn) automatically creates a copy of allarchived redo logo files in the flash recovery area if you specify the flash recoveryarea as the archive log destination. You can specify the flash recovery area as thedestination for your archived redo log files by using the LOG-ARCHIVE_DEST_10parameter. If you create a flash recovery area and do not set any other local archivingdestinations, LOG_ARCHIVE_DEST_10 is implicitly set to the USE_DB_RECOVERY_FILE_DEST. (That is, archived redo log files will be sent automatically to the flashrecovery area location.)

If you’ve also configured other archive log locations by using the LOG_ARCHIVE_DEST_n parameter, Oracle will also place copies of archived redo logs in those otherlocations. In the following example, I turned on archiving for the database nina withoutconfiguring an explicit archive log location. On issuing the ARCHIVE LOG LISTcommand, this is what I got:

SQL> archive log listDatabase log mode Archive ModeAutomatic archival EnabledArchive destination USE_DB_RECOVERY_FILE_DESTOldest online log sequence 825Next log sequence to archive 827Current log sequence 827SQL>

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:55 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 379: OCA OCP - Oracle10G New Features For Administrators Exam Guide

6 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

I am using a flash recovery area for the database nina. The USE_DB_RECOVERY_FILE_DEST location for the archive logs points to the flash recovery area for thedatabase, which is the C:\Oracle\Product\10.1.0\flsh_recovery_area\nina\ directoryon my Windows XP server.

Sizing the Flash Recovery AreaHow large should your flash recovery area be? Oracle recommends that your flashbackarea size be equal to the sum of the size of your database, any incremental backups thatyou may have made, and all the archived redo logs on disk. If you have a 100GB sizeddatabase, and you have about forty 0.5GB sized redo logs on disk, your flash recoveryarea needs more than 120GB of space. Your flash recovery area should be large enoughfor you to save a set of the following files:

■ A copy of all datafiles

■ Incremental backups

■ Online redo logs

■ Archived redo logs not yet backed up to tape

■ Control files

■ Control file autobackups (these will include copies of the control fileand the SPFILE)

Note that this list includes both online redo log files and control files. Oraclerecommends that you save both a duplexed redo log file and a current control file inyour flash recovery area, along with all the other recovery-related files (database filecopies and the archived redo log files).

At the minimum, Oracle recommends that you keep the archived logs not yetsaved to tape in the flash recovery area.

The size of your database, of course, will be the main determinant of the sizeof the flash recovery area. The size of the flash recovery area also depends on thefollowing factors:

■ Your RMAN backup retention policy

■ The type of storage device you are using for your backups (tape and disk orjust a disk device)

■ The amount of data block changes in your database

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:56 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 380: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Creating a Flash Recovery AreaYou can create a flash recovery area in several ways:

■ You can configure the flash recovery area during database creation using theDatabase Creation Assistant (DBCA).

■ You need to configure two initialization parameters to configure a flashrecovery area. Since these initialization parameters are dynamic, you canalso create a flash recovery area while the database is running.

■ Of course, you can also use the OEM Database Control to configure a flashrecovery area.

Configuring a Flash Recovery AreaYou use the DB_RECOVERY_FILE_DEST and DB_RECOVERY_FILE_DEST_SIZE initialization parameters to configure a flash recovery area in your database.

The DB_RECOVERY_FILE_DEST parameter specifies the location of the flashrecovery area, such as the /u01/App/Oracle/flsh_rcv directory.

The DB_RECOVERY_FILE_DEST_SIZE parameter specifies the maximum sizeof the flash recovery area. Note that the database isn’t going to assign or allocate thisspace to the flash recovery area immediately. If you assign a 2GB chunk of file spaceto the flash recovery area, Oracle will use this space when it needs to store new filesin it. If no files are stored in the flash recovery area, all the space allocated to itremains under the control of the operating system, although the space is technicallyassigned to the flash recovery area.

You must first specify the DB_RECOVERY_FILE_DEST_SIZE parameterbefore you can specify the DB_RECOVERY_FILE_DEST parameter.

Using the Flash Recovery Area 7

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

When you use the DB_RECOVERY_FILE_DEST parameter tospecify the destination of your flashrecovery area, you can use a directory,file system, or ASM disk group as your

destination. Oracle will actually let you usea file server device for the flash recoveryarea, provided that it is one that hasbeen verified by the Oracle StorageCompatibility Program.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:56 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 381: OCA OCP - Oracle10G New Features For Administrators Exam Guide

8 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

Dynamically Defining the Flash Recovery AreaYou can dynamically create or modify the flash recovery area using the two initializationparameters DB_RECOVERY_FILE_DEST and DB_RECOVERY_FILE_DEST_SIZEin the following manner:

SQL> alter system set2* db_recovery_file_dest_size = 2G scope=both

System altered.SQL> alter system set2 db_recovery_file_dest = 'C:\oracle\recovery_area' scope=both;

System altered.SQL>

You must always specify the size parameter, DB_RECOVERY_FILE_DEST_SIZE,before specifying the location parameter, DB_RECOVERY_FILE_DEST. Also, makesure that you first create the specific flash recovery area directory (in this example,it is the recovery_area directory) before using the DB_RECOVERY_FILE_DESTparameter.

The SCOPE=BOTH clause ensures that any changes you make will be applicableimmediately, in addition to being written permanently to your SPFILE.

The flash recovery area and DB_RECOVERY_FILE_DEST location aresynonymous.

Disabling the Current Flash Recovery AreaYou can disable the current flash recovery area by setting the DB_RECOVERY_FILE_DEST parameter to blank (''), which has the effect of unsetting the current destinationfor the flash recovery area files. Note that you can use the V$RECOVERY_FILE_DEST view to check the location of the flash recovery area. The following exampleillustrates how you can disable your flash recovery area.

SQL> select name from v$recovery_file_dest;NAME---------------------------C:\oracle\recovery_areaSQL> alter system set2 db_recovery_file_dest = '';

System altered.SQL> select name from v$recovery_file_dest;NAME---------------------------SQL>

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:56 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 382: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Note that even after you disable the flash recovery area, the RMAN will continueto access the files located in the flash recovery area for backup and recovery purposes.However, the RMAN won’t have access to the automatic space management featuresof the flash recovery area.

Default File Location and the Flash Recovery AreaUsing the flash recovery area implies that you are using OMF. If you are configuringa flash recovery area in your database, you can’t use the usual LOG_ARCHIVE_DESTand LOG_ARCHIVE_DUPLEX_DEST parameters to specify redo log archive destinations.You must instead use the newer LOG_ARCHIVE_DEST_n parameters. When you useOMF files, Oracle determines the default location for the datafiles, control files, andredo log files, based on the values of the initialization parameters DB_CREATE_FILE_DEST and DB_CREATE_ONLINE_LOG_DEST_n, which determine the location ofall OMF files. When you create the flash recovery area on top of the OMF files, thedefault location of the control files and redo log files will be based on your choice amongthe two initialization parameters, as well as a third parameter that specifies the locationof the flash recovery area. This additional parameter is the new DB_RECOVERY_FILE_DEST parameter.

Thus, the three important initialization parameters—DB_CREATE_FILE_DEST,DB_CREATE_ONLINE_LOG_DEST_n, and DB_RECOVERY_FILE_DEST—determine where and how many control files and redo log files Oracle will create whenyou use a flash recovery area built on top of an OMF-based file system. I summarize thevarious possibilities in the following sections.

Oracle Corporation recommends that your DB_RECOVERY_FILE_DESTlocation not be the same as the DB_CREATE_FILE_DEST location or anyof the DB_CREATE_ONLINE_LOG_DEST_n locations.

Control FilesIf you set the CONTROL_FILE parameter manually in your initialization file beforestarting the instance to create a new database, Oracle will create the control files inthat location. If you haven’t set the CONTROL_FILES parameter, Oracle will createthe control files in various default locations, according to the following rules:

■ If you specify the DB_CREATE_ONLINE_LOG_DEST_n parameter, Oraclewill create an OMF-based control file in n number of locations, with the firstdirectory holding the primary control file.

Using the Flash Recovery Area 9

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:56 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 383: OCA OCP - Oracle10G New Features For Administrators Exam Guide

10 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

■ If you specify the DB_CREATE_FILE_DEST and DB_RECOVERY_FILE_DESTparameters, Oracle will create an OMF-based control file in both of these locations.

■ If you just specify the DB_RECOVERY_FILE_DEST parameter, Oracle will createan OMF-based control file in the flashrecovery area only.

■ If you omit all three of the initialization parameters, Oracle will create a non-OMF-based control file in the system-specific default location.

Redo Log FilesIf you omit the LOGFILE clause during database creation, Oracle will create the redolog files according to the following rules:

■ If you specify the DB_CREATE_ONLINE_LOG_DEST_n parameter, Oraclewill create an online redo log member in n number of locations, up to theMAXLOGMEMBERS limit for the database.

■ If you specify the DB_CREATE_FILE_DEST and DB_RECOVERY_FILE_DEST parameters only, Oracle will create an online redo log member in bothof these locations up to the MAXLOGMEMBERS limit for the database.

■ If you just specify the DB_RECOVERY_FILE_DEST parameter, Oracle willcreate an online redo log member in the flash recovery area only.

■ If you omit all three initialization parameters, Oracle will create a non-OMFonline redo log file in the system-specific default location.

Backing Up the Flash Recovery AreaWhen you configure the flash recovery area, the RMAN will automatically place itsbackup files in that area. Oracle will use the OMF files and automatically generate thefilenames itself. Before going further, let’s clarify the difference between the two waysyou can store database backups using RMAN:

■ Image copies These are identical to your normal operating system file copies.Image copies are byte-by-byte copies of Oracle database files. However, thebig difference between the copies made by the operating system and the RMANimage copies is that the RMAN records information about its image copies

If the database creates anOMF control file, and it is using a serverparameter file, then the database sets theCONTROL_FILES initialization parameterin the server parameter file.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:56 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 384: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using the Flash Recovery Area 11

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

in the RMAN repository. Since you can’t use a backup unless it is part ofthe RMAN recovery catalog, you can’t use normal operating system backupcopies inside RMAN.

■ Backup sets These are logical entities, consisting of individual components(files) called backup pieces. Backup pieces store the contents of one or severalOracle database files. You can’t access the backup pieces on an individualbasis; you must access them as part of a backup set.

You can back up the flash recovery area itself by using simple RMAN backupcommands. In order for the commands to work, you must set CONFIGURE BACKUPOPTIMIZATION to ON. You can back up the flash recovery area only to a tapedevice using these backup commands.

The RMAN command BACKUP RECOVERY AREA backs up all flash recoveryfiles in the current or previous flash recovery area destinations. This command willback up only those files that have never been backed up to tape before. The filesthat the command will back up include full backups, incremental backups, controlfile autobackups, archive logs, and datafile copies.

The RMAN command BACKUP RECOVERY FILES command backs up all thefiles that the BACKUP RECOVERY AREA command does, but from all areas on yourfile system, not just from the flash recovery area.

You can use the RMAN command BACKUP RECOVERY FILE DESTINATIONto move disk backups created in the flash recovery area to tape.

Managing the Flash Recovery AreaThere really isn’t a whole lot you need to do in the way of managing the flash recoveryarea. You must take care to size the flash recovery area large enough so there is no spacepressure in that area. Let’s first discuss how the flash recovery area manages its space,and then see the dictionary view that helps you manage the flash recovery area.

Neither of the twocommands, BACKUP RECOVERY AREA orBACKUP RECOVERY FILES, will back upany permanent files in the flash recovery

area, such as the current control file andthe current redo log file. These commandswill also not back up the flashback logs.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:57 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 385: OCA OCP - Oracle10G New Features For Administrators Exam Guide

12 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

Space ManagementOnce you create the flash recovery area, Oracle will start storing recovery-related filesin that area, until it uses up all the space you allocated to the flash recovery area.Whenever you add a new file to the flash recovery area, Oracle automatically updatesits list of backup files that are candidates for deletion. This list consists of those filesthat either have been backed up to tape or are obsolete as per your retention rules.Oracle automatically deletes files on this list when it needs space for incoming newrecovery-related files.

When the flash recovery area runs low on space and it can’t delete any files torelieve the space pressure, Oracle issues an automatic warning alert, once the flashrecovery are is 85 percent full. When the area uses up 97 percent of its space, Oraclewill send a critical alert. Oracle sets these warning and critical thresholds, and youcan’t change them.

Oracle will add entries to both your alert log file and the DBA_OUTSTANDING_ALERTS view to mark any flash recovery area space alerts. Oracle will continue toplace new recovery-related files in the flash recovery area, until it hits the 100 percentspace usage barrier, at which point it will issue an error stating that your flash recoveryarea is out of room.

If you ever receive the out-of-space warning and critical alerts because of spacepressure in you flash recovery area, you have the following options:

■ Consider changing your backup retention and archive log retention policies.

■ Increase the size of the DB_RECOVERY_FILE_DEST_SIZE parameter toallocate more space to your current flash recovery area.

■ Use the BACKUP RECOVERY AREA command in the RMAN to back up thecontents of the flash recovery area to a tape device.

■ Use the RMAN to delete unnecessary backup files. The RMAN commandsCROSSCHECK and DELETE EXPIRED come in handy during this deletionprocess.

Note that if the database can’t archive any redo log files because the flashrecovery area is full, the database will hang, as it always does when your traditionalarchive destination fills up.

Data Dictionary ViewsThe V$RECOVERY_FILE_DEST view is the main source to help you manage theflash recovery area. This view contains information about the flash recovery area.Here’s its structure:

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:57 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 386: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SQL> desc v$recovery_file_destName Null? Type----------------------------------------- -------- ---------------------NAME VARCHAR2(513)SPACE_LIMIT NUMBERSPACE_USED NUMBERSPACE_RECLAIMABLE NUMBERNUMBER_OF_FILES NUMBERSQL>

In the v$recovery_file_dest view, the SPACE_LIMIT column tells youhow much space has been allocated to the flash recovery area (by the DB_RECOVERY_FILE_DEST_SIZE parameter). The SPACE_RECLAIMABLE column tells youhow much space you can reclaim by getting rid of obsolete and redundant files inthe flash recovery area.

A new column, named IS_RECOVERY_DEST_FILE, has been added to theV$LOGFILE, V$CONTROLFILE, V$ARCHIVED_LOG, V$DATAFILE_COPY,and V$BACKUP_PIECE views. The column can take a value of YES or NO. If thecolumn value is YES, that means that the respective file in that view is in the flashrecovery area.

Moving the Flash Recovery AreaIf you need to move your flash recovery area to a different location, you can do so byusing the DB_RECOVERY_FILE_DEST initialization parameter, as in this example:

ALTER SYSTEM SET DB_RECOVERY_FILE_DEST='/u01/app/oracle/new_area' SCOPE=BOTH;

Oracle will immediately start creating all the new flash recovery area files in yournew flash recovery area location.

You can leave the permanent files (control files and online redo log files), flashbacklogs, and transient files in their original location. Eventually, Oracle will delete allthe transient files from the previous flash recovery area location, when each of thembecome eligible for deletion. However, if you want to move your current permanentfiles, transient files, or flashback logs to the new flash recovery area, you can do so byusing the standard file-moving procedures.

Using the Flash Recovery Area 13

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:57 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 387: OCA OCP - Oracle10G New Features For Administrators Exam Guide

14 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

CERTIFICATION OBJECTIVE 8.02

Using Incremental BackupsA full backup includes every block in the datafiles. Incremental backups capture onlythose data blocks that have changed since the last backup. Incremental backups helpyou avoid spending huge amounts of time and resources that you’ll need for performingfrequent full database backups. The RMAN can perform an incremental backup atthe database, tablespace, or datafile level. In Oracle Database 10g, there are severalenhancements pertaining to incremental backups. The main enhancements are theability to recover with incrementally updated backups and the fast incremental backupcapability. Let’s first look at how you can reduce recovery time by using incrementallyupdated backups.

Recovering with Incrementally Updated BackupsOracle Database 10g gives you the ability to recover databases using incrementallyupdated backup files. Currently, the standard operating procedure is for you to applyarchived redo logs to your datafile backup copies in order to perform a media recovery.For example, if your database needs a recovery on Friday and your last backup was doneon Sunday night, you must apply all the archive logs that your database generatedsince Sunday night.

In Oracle Database 10g, you can apply incremental backups to your datafile imagecopies when you use the RMAN. This application of incremental backups to imagecopies enables you to roll forward or recover the image copy to a specified point intime. Here’s how this efficient recovery strategy works:

1. Apply the incremental backups to datafile image copies. Use the RECOVERCOPY OF DATAFILE command of the RMAN to perform the recovery. Thiswill update all of your datafile image copies, all the way up to the system changenumber (SCN) in the latest incremental backup. The RMAN will treat thisupdated datafile image copy as a normal datafile image copy.

2. Then apply the archive logs since the last incremental backup only. Applythese archive logs to the updated datafile image copies. Note that here is wherethe incrementally updated backups provide their value, since you don’t needto apply all the archive logs since the last backup, but only those logs since thelast incremental backup! You don’t need to perform a full image copy afterincrementally restoring your database files.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:57 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 388: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using Incremental Backups 15

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

If you have incremental backups available, along with the archived redo logs,the RMAN will always choose incremental backups over archived redo logs duringrecoveries, because it is a much faster way to recover your database. However, notethat for a level 0 incremental backup, Oracle may not choose incremental backupsover the archived redo logs.

Oracle recommends that you make whole backups of your database regularly,and make daily (or more frequent) incremental backups. You must retain allof these backups on disk. You can then perform a quicker full database orpoint-in-time recovery using the incrementally updated backup approach,and make minimal use of the slower archived log-based recovery technique.Thus, during a recovery, the incremental backups will have already been applied,and the only archive logs needed will be those since the last incremental backup.

You can always restart the recovery process, if the process fails while it is applyingthe incremental backup files to the datafile image copies. If you have multiple versionsof an image copy in the RMAN catalog, the RMAN will automatically use the latestversion. If there are overlapping incremental backups, the RMAN will choose the onecovering the longer period.

Fast Incremental BackupsDuring an incremental backup, Oracle must scan the entire datafile, even if only avery small part of the file has changed. This makes for unnecessarily long incrementalbackup times. Oracle Database 10g contains enhancements that help you make muchfaster incremental backups.

Oracle Database 10g maintains a new file, the change tracking file, to track thephysical location of all database changes. The RMAN simply reads this file tofind out which data blocks to read and copy during an incremental backup process.Thus, RMAN avoids needing to read entire datafiles during incremental backups,and your backup times are dramatically shorter than before.

Incremental backups helprestore datafiles by applying changes at thedatabase block level. Archived redo logsapply changes at the transaction level.Incrementally updated backups lead to afaster recovery, since you need to apply

only data block changes, and that is alwaysmuch faster than applying individualtransactions. Thus, Oracle prefers thatyou use incremental backups over archivedlogs during a recovery, whenever you havea choice.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:57 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 389: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

A new background process, the change tracking writer (CTWR), is in charge ofwriting the block change information to the change tracking file. The size of thechange tracking file will depend on the size of the database, the amount of DMLactivity, the number of old backups maintained by the change tracking file, andthe number of active instances, if you are using Real Application Clusters (RAC).

Oracle recommends that you place the change tracking file on the same disksas the datafiles.

Enabling Block Change TrackingOracle Database 10g doesn’t track block changes by default. You must explicitly enablethe feature, by using the following command:

SQL> alter database2 enable block change tracking3 using file 'C:\ORACLE\RECOVERY_AREA\CHANGETRACK.LOG';

Database altered.SQL>

If you store the change tracking file along with you database files, the file will bedeleted automatically when you disable block change tracking. You can rename orrelocate a change tracking file by using the ALTER DATABASE RENAME FILEcommand, as shown here:

SQL> alter database rename file2 'C:\ORACLE\RECOVERY_AREA\CHANGETRACK.LOG'3* to 'C:\ORACLE\NEWCHANGE.LOG';

You must make sure that your database is in the mount stage before you canrename the change tracking file.

You may disable block change tracking by using the following command:

SQL> alter database disable block change tracking;Database altered.SQL>

16 Chapter 8: Backup and Recovery Enhancements

The change tracking filecontains the physical location of alldatabase changes. The minimum size is10MB. Oracle creates the file automaticallyand allocates additional space in 10MB

increments. The file’s size depends on yourdatabase size, number of instances in anRAC, and the number of old backups thefile maintains.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:57 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 390: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

Monitoring Block Change TrackingYou can monitor the block change tracking feature in your database (as noted in theprevious section, this feature is turned off by default) by using the V$BLOCK_CHANGE_TRACKING and V$BACKUP_CONTROLFILE views.

The V$BLOCK_CHANGE_TRACKING view shows the name, size, and status ofyour change tracking file, as shown in this example:

SQL> select filename, status, bytes2 from v$block_change_tracking;

FILENAME STATUS BYTES-----------------------------------------------------------------C:\ORACLE\RECOVERY_AREA\CHANGETRACK.LOG ENABLED 11599872SQL>

You can use the V$BACKUP_DATAFILE view to see how the block changefeature is helping you minimize the file scanning done by the incremental backupprocess. You can use the ratio between the value of the BLOCKS_READ columnand the DATAFILE_BLOCKS column to figure out the percentage of blocks Oracleis reading in order to perform its incremental backups. If the BLOCKS_READ/DATAFILE_BLOCKS ratio is too high, you may need to take more frequentincremental backups to reduce the ratio.

CERTIFICATION OBJECTIVE 8.03

Enhanced RMAN CommandsOracle Database 10g has several new RMAN commands, and some older commandshave been deprecated. You’ll also find some enhancements in the RMAN scriptingfeature. Let’s review these changes, starting with the BACKUP AS COPY command.

Using the BACKUP AS COPY CommandThe RMAN COPY command has been deprecated in Oracle Database 10g. The newcommand that replaces it is BACKUP AS COPY. In the older backup commands, whenyou created a backup set, you needed to use RMAN later on to extract individualdatafiles from the backup set. The new BACKUP AS COPY command creates image

Enhanced RMAN Commands 17

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:58 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 391: OCA OCP - Oracle10G New Features For Administrators Exam Guide

18 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

copies, so you don’t need to extract them from a backup set. Using a single BACKUPAS COPY command, you can now copy all of the following:

■ A database

■ One or multiple tablespaces

■ One or multiple datafiles

■ One or more multiple archived redo logs

■ One or more control files

You can use the BACKUP AS COPY command to create image copies of datafiles,as shown here:

RMAN> BACKUP AS COPY DATABASE;

If you want RMAN to create image copies by default, use the following RMANconfiguration command:

RMAN> configure device type disk2> backup type to copy;old RMAN configuration parameters:CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO COMPRESSED BACKUPSET;new RMAN configuration parameters:CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY PARALLELISM 1;new RMAN configuration parameters are successfully storedreleased channel: ORA_DISK_1RMAN>

To create a backup set, rather than an image copy, you can use the followingcommand:

RMAN> backup as backupset database;

Performing BackupsYou can back up various database elements as follows:

■ Entire database backup You can now perform an image file backup of theentire database, by using the following command:

RMAN> backup database;

■ Previous database image copy If you wish to back up a previous image copyof all the database files and control files in your database, use the followingcommand:

RMAN> backup copy of database;

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:58 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 392: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Enhanced RMAN Commands 19

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

■ Tablespace You can back up all datafiles belonging to a tablespace by usingthe following command (USERS is the tablespace in this example and thenext one):

RMAN> backup tablespace users;

■ Previous tablespace image copy If you want to make a backup of a previousimage copy or a backup set of a tablespace, you can do so by using the followingcommand:

RMAN> backup copy of tablespace users;

■ Single datafile You use the following command to perform a backup of asingle datafile (datafile 10 in this example):

RMAN> backup datafile 10;

■ Previous datafile backup The following command backs up a previouslybacked up datafile:

RMAN> backup copy of datafile 10;

■ Current control file To back up a current control file, use the followingcommand (equivalent to the SQL command ALTER DATABASE BACKUPCONTROLFILE):

RMAN> backup current controlfile;

■ Previous control file copies In order to copy all the previously made controlfile copies, use the following command.

RMAN> backup controlfilecopy all;

The output of a backup command may be an image copy or a backup set,depending on whether your CONFIGURE DEVICE TYPE DISK BACKUP TYPEparameter is set to COPY or BACKUPSET.

Using the CATALOG CommandIn Oracle Database 10g, you can issue the CATALOG command to make the RMANstart cataloging backup files immediately. You can use the command when you aresearching for new files or when you want to let the RMAN know that you are usinga new backup directory.

The CATALOG command has the following syntax:

RMAN> catalog backuppiece 'filename';

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:58 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 393: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Instead of the keyword BACKUPPIECE, you can use the keyword DATAFILECOPY, if youare cataloging an image copy of a datafile instead of a backup piece from a backup set.

Here is an example of the use of the CATALOG command:

RMAN> catalog datafilecopy “C:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\NINA\DATAFILE\01_MF_SYSAUX_OGOGDVDC_.DBF”;catalogued datafile copydatafile copyfilename= C:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\NINA\DATAFILE\01_MF_SYSAUX_OGOGDVDC_.DBF recid=4 stamp=530016304RMAN>

You can also use the reverse command, UNCATALOG, to get rid of a backup piecefrom the RMAN catalog, as shown here:

RMAN> change backuppiece 'file_name' uncatalog;

The following example uncatalogs the datafile copy cataloged in the previousexample:

RMAN> change datafilecopy"C:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\NINA\DATAFILE\01_MF_SYSAUX_OGOGDVDC_.DBF" UNCATALOG;Uncatalogued datafile copydatafile copyfilename= C:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\NINA\DATAFILE\01_MF_SYSAUX_OGOGDVDC_.DBF recid=4 stamp=530016304Uncatalogued 1 objectsRMAN>

Let’s say you suspect that there are somebackup files in various directories that aren’tyet a part of the RMAN catalog. Some of thefilenames may be hard to remember, since theymay be OMF-based files. Instead of worryingabout where all the backup files might be, youcan simply ask the RMAN to search in a certaindirectory for all backup files that aren’t part of

the catalog already. You use the CATALOG START WITH command to perform thisjob, as shown in the following example.

RMAN> catalog start with2> "C:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\NINA\DATAFILE";searching for all files that match the pattern C:\ORACLE\PRODUCT\10.1.0\

20 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

If you eliminate all backuppieces from the RMAN catalog, the RMANwill remove the backup set informationas well.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:58 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 394: OCA OCP - Oracle10G New Features For Administrators Exam Guide

FLASH_RECOVERY_AREA\NINA\DATAFILEList of Files Unknown to the Database=====================================File Name: C:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\NINA\DATAFILE\O1_MF_SYSAUX_0G0GDVDC_.DBFDo you really want to catalog the above files (enter YES or NO)? YEScataloging files...cataloging doneList of Cataloged Files=======================File Name: C:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\NINA\DATAFILE\O1_MF_SYSAUX_0G0GDVDC_.DBFRMAN>

The CATALOG START WITH command comes in very handy if you happen tolose your RMAN recovery catalog. In earlier releases, there was no way to tell theRMAN about a backup set. This was a complete showstopper for many DBAs. Ifyour recovery catalog was destroyed, even though all the backup sets were perfectand you knew exactly where they were and what was in them, there was no way totell a newly created catalog to use them. Now you can just point it at the tape libraryand let it find everything. This is an important and long overdue enhancement.

Enhancements in RMAN ScriptsThere are two important enhancements in the RMAN scripting feature. The first is theconvertibility of text files into stored scripts and vice versa. The second is the shareabilityof RMAN scripts among databases.

Convertibility of RMAN ScriptsThe RMAN lets you use scripts to perform backups and recovery, to save you the drudgeryof typing the commands in repeatedly, using the command line. RMAN offers you twokinds of scripts: stored scripts and text scripts. Stored scripts are stored in the RMANrecovery catalog, and the text scripts are kept in regular text files. Stored scripts offerthe advantage that any user who logs in to RMAN can access them easily, comparingto accessing the text files, which may be stored anywhere.

In previous versions of Oracle, you couldn’t convert a text script into a storedscript and vice versa. In Oracle Database 10g, this limitation goes away: you cannow change a stored script into a text script and a text script to a stored script.

Here’s an RMAN command that sends the contents of a stored script to a text file:

RMAN> print script full_backup to file 'my_script_file.txt';

Enhanced RMAN Commands 21

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:58 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 395: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Global RMAN ScriptsIn previous Oracle versions, you could execute a stored script only if you were connectedto the target database where the script was originally created, thus making the scriptslocal in nature. Oracle Database 10g enhances stored scripts by providing the newconcept of global scripts, which you can execute against any database registered in therecovery catalog, as long as your RMAN client is connected to the recovery catalogand a target database simultaneously.

Multiple databases can share the same RMAN scripts, provided the databasesconnect to the database with the RMAN catalog. Of course, you must use the RMANrecovery catalog in order to use this feature.

The following two statements show the syntax for creating a local and a globalscript, respectively.

RMAN> create script full_backup{backup database plus archivelog;delete obsolete;}

RMAN> create global script global_full_backup{backup database plus archivelog;delete obsolete;}

The EXECUTE SCRIPT command will let you execute a global or local script,as shown here:

RMAN> run { execute script full_backup; }

The following PRINT SCRIPT command prints out your global scripts.

RMAN> print global script full_backup;

CERTIFICATION OBJECTIVE 8.04

Miscellaneous Backup and Recovery EnhancementsThis section briefly covers miscellaneous enhancements in the database backup andrecovery area. Some of the enhancements apply to the RMAN interface only, andsome apply to both the RMAN and user-performed backup and recovery.

22 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:58 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 396: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using the Database Control to Configure BackupsTo use the OEM Database Control to configure your backup procedures, on theDatabase Control home page, click the Maintenance tab. In the Backup/Recoveryregion of the Maintenance page, choose Configure Backup Settings. You can useone of the following choices to tell RMAN where to place its target files:

■ In the location you specify for the FORMAT option in a backup command

■ In the location you specify with the CONFIGURE CHANNEL FORMAT option

■ In the location you specify for the DB_RECOVERY_FILE_DEST (flashrecovery area) parameter

If you don’t use any of these alternatives, the backup files will go into an operatingsystem-specific default directory.

Automatic Channel FailoverIf one of the channels on which the RMAN is performing a backup fails, the RMANwill automatically try to use an alternative channel, provided you are using multiplechannels. The backup process will continue without a hitch, although the RMANreports the channel problem in the log files and saves the information in the V$RMAN_OUTPUT view.

Implementing Fast RecoveryDuring a normal recovery process in previous versions, you needed to restore thebackup files first, before starting the recovery process. In Oracle Database 10g, you canuse the backup files directly during a recovery process, instead of needing to restorethem first. You can still perform the traditional restore/recovery in the RMAN, byusing the RESTORE DATABASE command. However, for those special times whenyou really need a fast recovery, Oracle Database 10g offers the SWITCH DATABASEcommand.

The SWITCH DATABASE command doesn’t restore your backup files from thebackup location. The RMAN simply adjusts the pointers for the datafiles in thecontrol file, so they now point to the backup files in your flash recovery area. Thus,RMAN will convert the backup files into the current datafiles, and then start therecovery process with these files.

Miscellaneous Backup and Recovery Enhancements 23

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:59 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 397: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

You must use image copies rather than backups sets in order to utilize thefast recovery process with the SWITCH DATABASE command.

The SWITCH DATABASE command is straightforward:

RMAN> switch database to copy;

Since you don’t need to copy any files, only rename the recovery files, the recoveryprocess is very fast. However, it comes with a price: you need to make sure that youhave additional backups made as soon as possible, to make up for the fact that you haveused up one of your backups to recover your database.

Recovering Datafiles Without BackupsIf you lose a datafile and it turns out that you don’t have a backup, you can still usethe RMAN to recover that datafile. You must, however, have a copy of the controlfile with references to the lost datafile, since RMAN needs the information from thecontrol file to recover the datafile. In addition, you must have all the archived redolog files from the time the datafile was lost, up to the time you want to recover.

The ability to recover a file that has never been backed up has always been availablefrom SQL*Plus, with the help of the CREATE DATAFILE X AS Y statement. Now,in Oracle Database 10g, you can create the lost file as part of an RMAN RESTOREDATABASE command.

Compressed BackupsOracle Database 10g lets you compress RMAN backups to save on storage. However,there is a cost to the compression feature: your recovery times will be longer when youuse compressed backup sets, since there is now the additional step of uncompressing thebackup sets before starting the recovery. Nevertheless, all recovery procedures remainthe same when you use a compressed backup set. The compression factor will dependon the nature of the data in your datafiles. Oracle recommends using this in preferenceto an external compression utility, and you certainly shouldn’t use both utilities together.

24 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

You can compress only adatabase that’s using the Oracle Database10g version server software. You must setthe COMPATIBLE initialization parameter

to a minimum of 10.0.0. You can’t compressan image copy; you can compress a backuponly if you are using backup sets.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:59 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 398: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

Here is the RMAN command that lets you compress a backup set:

RMAN> backup as compressed backupset database;

RMAN disables backup compression by default. If you want to make backupcompression the default mode, you may do so by using the following command.

RMAN> configure device type disk parallelism 42> backup type to compressed backupset;old RMAN configuration parameters:CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY PARALLELISM 1;new RMAN configuration parameters:CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO COMPRESSED BACKUPSET;new RMAN configuration parameters are successfully storedreleased channel: ORA_DISK_1RMAN>

The V$BACKUP_FILES view contains information on backup filenames and filesizes, and will also tell you about the compression status of the files. Here’s a simplequery that shows the size of a file, as well as whether RMAN will compress the fileduring a backup:

SQL> select fname, compressed, backup_typefrom v$backup_files;

Simplified Recovery Through RESETLOGSWhen you perform an incomplete recovery or a recovery using a backup control file,you must open the database with the RESETLOGS option. The RESETLOGS optionreinitializes the redo log files, and thus changes the database incarnation. You’ll starta new sequence of redo logs after using the RESETLOGS option to open the database.In previous versions of Oracle, this meant that you couldn’t use any backups from theprevious incarnations (before the RESETLOGS operation) to recover the database. Thisis why you needed to perform a whole database backup immediately after a RESTLOGSoperation.

In Oracle Database 10g, you can use backups taken before an incomplete recoveryoperation; that is, you can use backups from older incarnations of the database. So,you don’t need to make a full backup after you use the RESETLOGS option. You canperform an incomplete recovery with the RESETLOGS option and immediately openthe database, thereby substantially reducing your downtime following a media problem.

Since you can use older archived redo logs created prior to using the RESETLOGSoption, you may now end up with situations where there may be multiple archivedlogs from various database incarnations with identical sequence numbers. In order to

Miscellaneous Backup and Recovery Enhancements 25

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:59 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 399: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

distinguish the archived redo logs from several database incarnations, OracleDatabase 10g uses a new format for the archived redo log files. The initializationparameter LOG_ARCHIVE_FORMAT uses a text string and a set of variables tospecify the default archive log format. Oracle applies the string generated by usingthis format to the string generated from the LOG_ARCHIVE_DEST parameter tocome up with the complete path and filename for archived redo log files.

Previously, you used the following format for the LOG_ARCHIVE_FORMATparameter to specify the archived redo log format:

LOG_ARCHIVE_FORMAT="log%t_%s.arc"

In this format specification, the variable t stands for thread number, and the variables stands for the log sequence number.

The new archive redo log format in Oracle Database 10g is of the following form:

LOG_ARCHIVE_FORMAT="log%t_%s_%r.arc"

In the new archive log format, there is anadditional variable r, which stands for theRESETLOGS identifier.

The V$DATABASE view contains severaladditional columns to help you manage informationregarding all RESETLOGS operations. Thesecolumns include RESETLOGS_CHANGE#,RESETLOGS_TIME, and RESETLOGS_ID.

The V$LOG_HISTORY and V$OFFLINE_RANGE views provide information aboutredo logs belonging to different database incarnations. Here’s a simple query on theV$LOG_HISTORY view:

SQL> select sequence#, resetlogs_change#,2* resetlogs_time from v$log_history;

SEQUENCE# RESETLOGS_CHANGE# RESETLOGS---------- ----------------- ---------

831 318842 23-MAR-04832 318842 23-MAR-04833 318842 23-MAR-04

…454 rows selected.SQL>

Dropping a DatabaseSometimes, you may want to drop test database or drop your old database after yousuccessfully migrate to a new version of Oracle. It’s very easy to drop an Oracle

26 Chapter 8: Backup and Recovery Enhancements

The change in the LOG_ARCHIVE_FORMAT initialization parameterenables the new feature of a recoverythrough RESETLOGS.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:59 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 400: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

Database 10g database. You can use the new command DROP DATABASE to removea database, in both the RMAN as well as the SQL*Plus interface. You may also usethe DBCA to drop the database.

Here is how you drop a database in the RMAN:

RMAN> drop database;

In SQL*Plus, you use an identical command:

SQL> drop database;

Your database must be mounted EXCLUSIVE and not be open in order to usethe DROP DATABASE command, whether you’re using the RMAN or SQL*Plusinterface to drop a database. In addition, you must have SYSDBA privileges.

Here are some features of the DROP DATABASE command:

■ Oracle will drop all control files and datafiles automatically, whether you usethe SQL*Plus, RMAN, or DBCA interface to drop a database.

■ Oracle doesn’t remove archived redo logs and backups.

■ If you are using an SPFILE, Oracle will remove it automatically.

The DROP DATABASE command removes all datafiles and control files. Oracledoesn’t remove any backups or archived redo log files when you drop a database.

Miscellaneous Backup and Recovery Enhancements 27

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

The DROP DATABASEcommand is irrevocable—you can’t rollback the command. Also, remember that

Oracle automatically drops only the controlfields and datafiles, not the archived redolog files and backup files.

After you drop a database,no matter which one of the three methodsyou use (RMAN, SQL*Plus, or DBCA),the RMAN catalog continues to list thedropped database information. Regardlessof which method you use to drop a

database, you need to use the followingRMAN command to wipe out all tracesof the dropped database from the RMANregistry:

RMAN> unregister database;

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:59 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 401: OCA OCP - Oracle10G New Features For Administrators Exam Guide

To make the RMAN remove all database backup copies as well as the archived redolog files, you can add the INCLUDING BACKUPS clause to your DROP DATABASEcommand in the RMAN, as shown here:

RMAN> drop database including backups;

Specifying Limits for Backup DurationSometimes, a DBA may run into a situation where a nightly backup is interfering withthe performance of a critical database job. In order to avoid major spikes in resourceuse, you can dictate the database to “take it easy,” by taking a longer time to finish the

backup. The new DURATION command in theRMAN provides this capability.

You can use the DURATION command asan option for your regular backup commands,such as BACKUP AS COPY, to specify the time(in hours and minutes) a backup job can take.You specify the DURATION clause in the backupcommand in the following manner.

DURATION <hrs>:<mins> [PARTIAL] [MINIMIZE {TIME|LOAD}]

In the DURATION clause, the options work as follows:

■ PARTIAL Normally, when your database backup jobs run past the timeinterval you specify through the DURATION parameter, the RMAN job errorsout and the backup is canceled. This is the RMAN’s default behavior whenit runs past any specified duration. You can override this default behavior byspecifying the PARTIAL clause, which will prevent the issuing of any RMANerror messages.

■ MINIMIZE TIME This option tells the RMAN to “hurry up” and finish asfast as it can.

■ MINIMIZE LOAD This option tells the RMAN to “slow down” if it is wellwithin its allotted time for a backup job.

You must use disks if you want to use the MINIMIZE TIME option, since yougenerally want a tape backup to end as quickly as possible.

Here is a simple example illustrating the use of this very interesting clause duringa database backup:

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

28 Chapter 8: Backup and Recovery Enhancements

The DURATION optionduring backups replaces the old RATE andREADRATE options used to modulate theRMAN file-reading speed.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:09:59 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 402: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Miscellaneous Backup and Recovery Enhancements 29

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

RMAN> backup as copy2> duration 02:003> minimize time database;

This BACKUP AS COPY command example specifies the following:

■ Limit the backup time to two hours (DURATION 02:00)

■ Run the backup at full speed, enabling it to possibly finish under the two-hour limit (MINIMIZE TIME)

■ Back up the entire database (DATABASE)

Placing All Datafiles in Backup ModeOracle Database 10g allows you to place all datafiles in a backup mode during an onlinedatabase backup. It also enables you to take all the datafiles out of the backup mode atthe same time. Let’s look at the new backup commands for performing these tasks.

Starting the Online BackupPreviously, during an online (hot) database backup, you needed to place each tablespaceinto the backup mode separately by using the BEGIN BACKUP TABLESPACE command.In Oracle Database 10g, you don’t need to specify tablespaces individually during anonline backup. You can use the ALTER DATABASE command to specify that all datafilesin the entire database be placed in the backup mode simultaneously. Your databasemust be open and in the ARCHIVELOG mode in order to use this command. Here’sthe syntax of the command:

SQL> alter database begin backup;

You need to place the datafiles in an online backup mode only if you areperforming a user-managed recovery, in order to guarantee that any fracturedblocks can be recovered (assure consistency). You don’t need this command inthe RMAN, since an RMAN backup does not contain any fractured blocks.

Remember that theDURATION clause’s PARTIAL option leadsto an error if the backup exceeds its time

limit. The MINIMIZE TIME option gets thejob done the fastest. The MINIMIZE LOADoption minimizes resource use.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:00 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 403: OCA OCP - Oracle10G New Features For Administrators Exam Guide

30 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

If the backup process encounters any nonexistent, read-only, or offline files, Oracleskips them, and the backup will continue. No errors are issued.

If you encounter any of the following situations, your attempt to start an onlinebackup will fail, with a “cannot start online backup error” message.

■ A user-managed online backup is in progress.

■ An RMAN online backup is in progress.

■ A file is in the process of being made a read-only file.

■ A file fails verification.

Ending the Online BackupYou must use the ALTER DATABASE END BACKUP command to end the onlinebackup. You can issue this command when the database is in a mounted or an openstate. The status of a datafile determines how the database treats that file. Here is asummary of the relationship between file status and the END BACKUP command:

■ Offline files will cause a warning message, but the END BACKUP commanditself will complete successfully.

■ Read-only files are skipped by the database.

■ Nonexistent datafiles are also skipped.

■ You can’t use the END BACKUP command while the database is going throughan RMAN backup.

Automatic Auxiliary Instance CreationOracle Database 10g, like its predecessors, lets you perform a tablespace point-in-timerecovery (TSPITR) to recover from certain database errors. You may specify the previouspoint in time you want to revert to by using a sequence number or an SCN.

The biggest headache in the previous Oracle versions while performing a TSPITRwas that you had to create an auxiliary database instance and remove it after finishingthe TSPITR process. Setting up the auxiliary instance was complex, making thismethod of recovery unappetizing to many DBAs. In Oracle Database 10g, you don’tneed to create the auxiliary instance. Oracle will now create the auxiliary instanceand remove it after the recovery is over.

Since you are creating your auxiliary instance in the same location as yourprimary database, you need to be aware of the possibility of some performancedegradation during the TSPITR operation.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:00 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 404: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

You must provide the locations for all files of the auxiliary instance to the RMAN, so itcan create the instance. Here are the various ways in which you can submit the auxiliaryfile location to the RMAN, ranked from the most important to the least important:

■ AUXILIARY DESTINATION

■ SET NEWNAME FOR DATAFILE

■ CONFIGURE AUXNAME FOR DATAFILE

■ DB_FILE_NAME_CONVERT

Oracle recommends that you must use the AUXILIARY DESTINATION argumentto provide the file locations for a RECOVER TABLESPACE operation.

Miscellaneous Backup and Recovery Enhancements 31

The exam will certainly query your knowledgeof the flash recovery area. You must know therelevant initialization parameters for creatingthe flash recovery area and the kinds of filesyou can store in it. What are the differencesbetween recovery-related files and other filesin the flash recovery area? You may also see aquestion on how control file and redo log fileplacement will depend on the combinationof the flash recovery area and the OMF filedestination parameters (DB_CREATE_ONLINE_DEST_n and DB_CREATE_FILE_DEST).

You must understand the new RMANcommands like BACKUP AS COPY andRECOVER COPY OF DATAFILE. What isthe new RMAN command to back up anentire database? What is the command toimplement a fast recovery using RMAN?What do the DURATION clause andthe PARTIAL, MINIMIZE LOAD, andMINIMIZE TIME options mean duringa backup command?

Expect a question on the new recoverytechnique that uses incrementally updatedbackups. What command do you use torecover with an incrementally updatedbackup? Expect some questions on the newfast incremental backup feature and how youenable it (by enabling block change tracking).What is the change tracking file? What doesthe new CTWR background process do?Know the details of the new compressed backupsfeature. You most certainly will face questionson using the simplified recovery process throughRESETLOGS. What changes in the initializationparameters make this possible? You mustremember the commands that enable you toimplement a fast recovery (SWITCH DATABASETO COPY).

Know the steps in dropping a database.What files are removed by Oracle when youissue the DROP DATABASE command?

INSIDE THE EXAMINSIDE THE EXAM

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:00 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 405: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CERTIFICATION SUMMARYThis chapter dealt with several interesting enhancements related to backup and recovery.You were introduced to the new flash recovery area concept, which helps centralizeall your recovery-related storage efforts. You then looked at the new techniques toreduce your incremental backup times. You also learned how to recover faster byapplying incremental backups to datafile image copies.

Several new RMAN commands were explained in this chapter, including theBACKUP AS COPY and CATALOG commands. You also learned about the newscripting enhancements in the RMAN.

You learned about the new SWITCH DATABASE command, which helps you cutback on restore/recovery times in a crisis. You also learned how to compress yourRMAN backups. You learned about the enhancements that let you avoid needingto back up your databases after a RESETLOGS operation. You also learned how youcan use archived redo logs from a previous database incarnation. You learned how todrop the database with the DROP DATABASE command. You saw how you could usethe DURATION option to control backup windows during certain times. You also sawhow Oracle Database 10g can help you during a TSPITR operation, by automaticallycreating and removing the auxiliary instance.

32 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:00 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 406: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Two-Minute Drill 33

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

✓TWO-MINUTE DRILL

Using the Flash Recovery Area

❑ The flash recovery area is the default storage location for all recovery-relatedfiles.

❑ You may use an Oracle-managed directory, operating system file system, or anASM disk group for your flash recovery area.

❑ Oracle automatically deletes obsolete files and files that have been backed upto tape.

❑ If you don’t use OMF files, Oracle can’t automatically delete unnecessaryrecovery files from the flash recovery area.

❑ The flash recovery area contains datafile copies, control file autobackups,archived redo log files, RMAN backup files, and flashback logs.

❑ Oracle recommends that you store a duplexed copy of the online redo logfiles and the current control file in your flash recovery area.

❑ The size of the flash recovery area should be greater than the sum of thedatabase size, any incremental backups, and all the archived logs on disk.

❑ The size of the flash recovery area also depends on your RMAN retentionpolicy.

❑ You use the two initialization parameters DB_RECOVERY_FILE_DEST andDB_RECOVERY_FILE_DEST_SIZE to configure the flash recovery area.

❑ Both the flash recovery area initialization parameters are dynamic.

❑ You must first set the DB_RECOVERY_FILE_DEST_SIZE parameter beforeyou can set the DB_RECOVERY_FILE_DEST parameter.

❑ You can disable the flash recovery area by using the DB_RECOVERY_FILE_DEST parameter and setting it to a null location.

❑ You can back up the flash recovery area by using the command BACKUPRECOVERY AREA, using the RMAN interface.

❑ The BACKUP RECOVERY FILES command in the RMAN backs up allrecovery files, irrespective of their location.

❑ Oracle sends you both warning and critical alerts when the flash recoveryarea space starts to fill up.

❑ The V$RECOVERY_FILE_DEST view is your main source for informationregarding the flash recovery area.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:00 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 407: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using Incremental Backups

❑ In Oracle Database 10g, you can apply incremental backups to image copiesof datafiles.

❑ Oracle prefers using the incremental backup approach to using archived logs.

❑ Oracle Database 10g maintains a change tracking file, where the changetracking writer (CTWR) background process writes information about blockchanges.

❑ The change tracking file is automatically deleted when you disable blockchange tracking.

❑ The ratio between the value of the BLOCKS_READ column and theDATAFILE_BLOCKS column, shown in the V$BACKUP_DATAFILEview, will tell you if you should make more frequent incremental backups.

Enhanced RMAN Commands

❑ The RMAN COPY command is deprecated in Oracle Database 10g.

❑ The BACKUP AS COPY command creates image copies of the database,tablespaces, and datafiles.

❑ The CATALOG command helps you search for new files that need to becataloged.

❑ The UNCATALOG command lets you uncatalog items from the RMANrecovery catalog.

❑ The CATALOG START WITH command lets you specify a directory forRMAN to search for recovery-related files.

❑ You can convert RMAN stored scripts into text file-based scripts and viceversa.

❑ The global scripts feature lets several databases use common scripts. You mustuse a recovery catalog for this feature to work.

Miscellaneous Backup and Recovery Enhancements

❑ If an RMAN channel fails during a backup, the RMAN will automaticallyswitch over to an alternative channel, provided you have configured multiplechannels.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

34 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:00 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 408: OCA OCP - Oracle10G New Features For Administrators Exam Guide

❑ Using the SWITCH DATABASE command, you can recover directly frombackup files, without restoring them first.

❑ You can recover a datafile even if you don’t have a backup for it, as long asyou can get the pertinent information from the relevant control file.

❑ The RMAN lets you compress backup sets to save on space requirements.

❑ You can now recover through a RESETLOGS operation, because backups/archives from previous incarnations are usable.

❑ The new LOG_ARCHIVE_FORMAT parameter contains a new RESETLOGSidentifier to help identify the redo logs from different database incarnations.

❑ You can now drop a database using either the RMAN or SQL*Plus interface,with the command DROP DATABASE.

❑ When you drop a database, Oracle will remove datafiles, control files, and theSPFILE automatically.

❑ Oracle doesn’t automatically remove the archived redo logs and backup fileswhen you drop a database.

❑ No matter which method you use to drop the database, you must use the RMANcommand UNREGISTER DATABASE to remove database information from theRMAN catalog.

❑ Using the DURATION clause, you can set limits on your backup job duration.

❑ The PARTIAL option of the DURATION clause prevents errors when youcross the time interval for a backup.

❑ The MINIMIZE TIME option of the DURATION clause will speed up yourbackups.

❑ The MINIMIZE LOAD option of the DURATION clause may slow downyour backups.

❑ You can put all datafiles in the backup mode simultaneously with the commandALTER DATABASE BEGIN BACKUP.

❑ The RMAN can now automatically create and remove the auxiliary instancenecessary during a TSPITR operation.

Two-Minute Drill 35

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:01 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 409: OCA OCP - Oracle10G New Features For Administrators Exam Guide

36 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

SELF TESTThe following questions will help you measure your understanding of the material presented in thischapter. Read all the choices carefully, because there might be more than one correct answer. Chooseall correct answers for each question.

Using the Flash Recovery Area

1. Which of the following items are stored in the flash recovery area?

A. DatafilesB. Undo segmentsC. Datafile copiesD. Archived redo log files

2. When can you create a flash recovery area?

A. At database creation timeB. Anytime, since you can create it using dynamic initialization parametersC. Only after you shut down the database and start it up in the mount stateD. Only if the database is already running

3. The DBA is running low on space and can provide only the least possible space to the flashrecovery area. The DBA should, at a minimum, have enough space in the flash recovery areato store which of the following items?

A. Archived logs not yet saved to tapeB. Online redo log files and current control filesC. Datafile copies and archived redo log filesD. Archived redo log files

4. What happens once the DBA disables the flash recovery area?

A. The RMAN will continue to be able to access the files in the flash recovery area.B. The RMAN will be unable to access the files in the flash recovery area.C. The RMAN will be unable to access the automatic space management features of the flash

recovery area.D. The RMAN can use only the automatic space management features of the flash recovery area.

5. If the DBA specifies the DB_CREATE_FILE_DEST and the DB_RECOVERY_FILE_DESTparameters at database creation time, what will Oracle do?

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:01 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 410: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test 37

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

A. Create an OMF control file in both locations specified by the two parametersB. Create an OMF control file in the flash recovery area onlyC. Create an OMF control file in the system-specified default locationD. Create an OMF control file in the location specified by the DB_RECOVERY_FILE_DEST

parameter only

Using Incremental Backups

6. What does using incrementally updated backups involve?

A. The updating of archived redo log files with incremental backupsB. The direct updating of datafiles with incremental backupsC. The updating of image copies of datafiles with incremental backupsD. The updating of the control files with incremental backups

7. To apply incremental backups, which of the following commands must you use?

A. RECOVER BACKUP OF DATABASE

B. RECOVER DATAFILE

C. RECOVER COPY OF DATAFILE

D. RECOVER COPY OF DATABASE

8. Incremental backups apply changes at what level?

A. Transaction levelB. Oracle block levelC. Operating system block levelD. Datafile level

9. What does the CTWR process do?

A. Updates the incremental backupsB. Updates the change tracking fileC. Applies the database block changesD. Checks for space in the flash recovery area

10. To enable block change tracking in your database, what must you do?

A. Use the ENABLE BLOCK CHANGE TRACKING commandB. Do nothing, since Oracle enables block change tracking by defaultC. First create the change tracking file in the default locationD. First restart the database in the mount state, before creating the change tracking file

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:01 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 411: OCA OCP - Oracle10G New Features For Administrators Exam Guide

38 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

Enhanced RMAN Commands

11. What can you do using the new BACKUP AS COPY command?

A. Extract image copies directly from backup setsB. Make image copies without needing to extract them from backup setsC. Make copies at all levels except the database levelD. Make an image copy of only a single file at a time

12. Which of the following commands backs up the entire database?

A. BACKUP DATABASE

B. BACKUP COPY OF DATABASE

C. BACKUP ALL

D. BACKUP BACKUPSET DATABASE

13. What does the RMAN CATALOG command do?

A. Helps you create image copies of datafilesB. Helps you create image copies of current control filesC. Helps you catalog any new files that aren’t a part of the recovery catalogD. Helps you catalog only the old files

14. What does the RMAN BACKUP CONTROLFILECOPY ALL command do?

A. Backs up all previously made control file copiesB. Backs up all control files that were never backed up beforeC. Makes a copy of all current control filesD. Stores the backed up control file copies on tape

15. What happens when you uncatalog all the metadata about backup pieces from the RMANcatalog?

A. The RMAN automatically removes the catalog.B. The RMAN removes the backup set information from the catalog as well.C. You can’t remove all of the backup pieces from the catalog.D. The RMAN replaces the backup sets with image copies.

Miscellaneous Backup and Recovery Enhancements

16. The DBA needs to recover the production database in the shortest time possible. What is theDBA’s best choice?

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:01 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 412: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Lab Questions 39

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

A. Use the RESTORE DATABASE commandB. Use the RECOVER DATABASE commandC. Use the SWITCH BACKUP commandD. Use the SWITCH DATABASE command

17. Which of the following backups can you compress?

A. Only backup setsB. Only image copiesC. Both image copies and backup setsD. Only single datafile copies

18. Which of the following is true about using the RESETLOGS option?

A. You don’t need to back up the database.B. You must back up the database right away.C. You can use archive redo logs from an older incarnation of the database.D. You can’t use archive redo logs from an older incarnation of the database.

19. What happens when you use the DROP DATABASE command?

A. Only the datafiles, control files, and archived redo logs are removed.B. Only the datafiles, control files, and backups are removed.C. Only the datafiles, control files, and online redo log files are removed.D. Only the datafiles, archived redo log files, and backups are removed.

20. Which of the following commands tells the database to slow down if it is within its allottedtime for a database backup?

A. MINIMIZE PARTIAL

B. MAXIMIZE LOAD

C. MINIMIZE TIME

D. MINIMIZE LOAD

LAB QUESTIONS1. Show how you would drop a database using the RMAN. Show the step-by-step procedures

in detail.

2. Show how you would catalog all the files in a disk location using the RMAN.

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:01 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 413: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SELF TEST ANSWERS

Using the Flash Recovery Area

1. � C and D. Oracle stores datafile copies and archived redo log files in the flash recoveryarea.� A is incorrect since Oracle doesn’t store datafiles in the flash recovery area—it storesdatafile copies. B is incorrect since there are no undo-related files in the flash recovery area. Allundo-related information is stored in the undo tablespace.

2. � A and B. A is correct since you can choose the flash recovery area option during databasecreation when you use the DBCA tool. B is correct as well, because the initializationparameters DB_RECOVERY_FILE_DEST and DB_RECOVERY_FILE_DEST_SIZE aredynamic parameters.� C is wrong since you don’t need to restart the database to create a flash recovery area. D isincorrect because, while you can configure the flash recovery area with dynamic initializationparameters, it doesn’t imply that you can configure the area only when the database is running.

3. � A. Oracle recommends that, at a minimum, you must keep the archived logs not yet savedto tape in the flash recovery area.� B, C, and D offer invalid recommendations.

4. � A and C. A is correct because, even after you disable the flash recovery area, the RMANcontinues to be able to access any recovery-related files it stored in the flash recovery area. C iscorrect because you’ll be unable to access the automatic space management features of the flashrecovery area if you disable the feature.� B is incorrect since you continue to be able to access the files even after the flash recoveryarea is disabled. D is wrong since you can’t use any automatic features of the flash recovery areaafter you disable it.

5. � A. Oracle will create an OMF-based control file in both the locations.� B, C, and D identify the wrong locations.

Using Incremental Backups

6. � C. Incrementally updated backups involve the updating of image copies of datafiles withincremental backups.� A is incorrect since you never update the archived redo logs with incremental backups.B is wrong since you never update datafiles with incremental backups—you update datafilecopies. D is wrong because you don’t update any control files with incremental backups.

40 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:01 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 414: OCA OCP - Oracle10G New Features For Administrators Exam Guide

7. � C and D. To apply incremental backups, you use the RECOVERY COPY OF DATAFILE orRECOVERY COPY OF DATABASE command.� A and B offer the wrong commands.

8. � B. Incremental changes apply changes to datafiles at the Oracle block level.� A is wrong because it is the archived redo logs that apply changes at the transaction level.In fact, this is why the application of block changes is much faster during a recovery. C iswrong since it is the Oracle block level, not the operating system block level, that Oracleapplies changes to the datafiles. D is wrong since changes aren’t applied at the granularityof a datafile, but at the granularity of an Oracle data block.

9. � B. The CTWR process writes block change information to the change tracking file.� A is wrong since the CTWR process doesn’t update the incremental backups. C is wrongsince the CTWR process doesn’t apply block level changes—it merely records them. D iswrong because the CTWR isn’t in charge of checking for space in the flash recovery area.

10. � A. To enable block change tracking in your database, you must enable it explicitly, byusing the ENABLE BLOCK CHANGE TRACKING command.� B is wrong since Oracle disables block change tracking by default. C and D are wrongbecause you don’t need to create any files to enable block change tracking. It is the job ofOracle to create the change tracking file automatically when you enable block changetracking.

Enhanced RMAN Commands

11. � B. The BACKUP AS COPY command enables you to make direct image copies of files,without needing to extract them from backup sets as before.� A is wrong since you don’t need to extract image copies from backup sets anymore, onceyou use this command. C is wrong because the command will make image copies at all levels,including the database level. D is wrong since the command can make copies of one or a set offiles simultaneously.

12. � A. The BACKUP DATABASE command backs up the entire database.� B is wrong since the BACKUP COPY OF DATABASE command will back up a previousimage copy of all the database and control files. C is wrong because the command is made upto mislead you. D is wrong since the command given there has a syntax error.

13. � C. The CATALOG command helps you recatalog the recovery area in search of new files.� A and B are wrong since the command doesn’t help you make copies, it only catalogsthem. D is wrong because the command isn’t limited to cataloging old files.

Self Test Answers 41

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:02 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 415: OCA OCP - Oracle10G New Features For Administrators Exam Guide

14. � A. The BACKUP CONTROLFILE ALL command backs up all previously made control filecopies.� B and C are wrong since the command doesn’t back up the current control files, even ifthey have never been backed up before. D is wrong because the command has nothing to dowith tape backup.

15. � B. When you remove all backup pieces for a backup set, the RMAN will remove thebackup set as well from its recovery catalog.� A is wrong since RMAN never removes the catalog automatically. C is wrong because youcan remove all the backup pieces from the catalog. D is wrong since RMAN doesn’t replaceany backup sets with image copies.

Miscellaneous Backup and Recovery Enhancements

16. � D. The SWITCH DATABASE commands lets you recover in the shortest time possible,because all you do is simply point the control file to the backup files instead of the olddatafiles. You can immediately start the recovery process, since there is no real restore processinvolved.� A will perform a database restore and start the recovery process but is very time consumingand therefore will not be the fastest way to recover. B is wrong because the RECOVERDATABASE command needs a restore of the database files from your backup location beforeyou start the recovery. Thus, it takes much longer to recover with this method. C is incorrectsince it points to a nonexistent command.

17. � A. You can compress only a backup set, not an image copy.� B and C are wrong because they state that you can compress image copies, which isn’ttrue. D is wrong since there is no limitation that states that you can compress only singledatafile copies; you may copy entire backup sets.

18. � A and C. A is correct since in Oracle Database 10g, you don’t need to back up yourdatabase after a RESETLOGS operation. C is correct because you can use older archive logsfrom a different incarnation.� B is wrong because you don’t need to back up your database after a RESTLOGS operationin Oracle Database 10g. D is wrong since you can use older archive logs from a differentdatabase incarnation.

19. � B. When you use the DROP DATABASE command, all datafiles, current control files, andbackups are removed.� A, C, and D list the wrong sets of files that the DROP DATABASE command will cause tobe removed from your server.

42 Chapter 8: Backup and Recovery Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:02 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 416: OCA OCP - Oracle10G New Features For Administrators Exam Guide

20. � D. The MINIMIZE LOAD option tells the database to slow down if it appears that itsgoing to make its target interval of time.� A and B are wrong since MINIMIZE PARTIAL and MAXIMIZE LOAD are nonexistentoptions. C is wrong because MINIMIZE TIME tells the database to work harder.

LAB ANSWERS1. To drop a database using the RMAN, follow this procedure:

Connect to the target database through the RMAN, making sure you are using the recoverycatalog:

rman target/catalog rman/rman@testdb

Catalog all the database backups, both in the flash recovery area and in other locations:

RMAN> catalog start with '/u01/app/oracle/rcv_area'; # flash recoveryareaRMAN> catalog start with '/u09/app/oracle/arch_dest2'; # second archivedest

Delete all backups and copies associated with the database:

RMAN> delete backupset; # deletes all backupsRMAN> delete copy; # delete all image copies (including archived logs)

Finally, drop the database and automatically unregister it from the recovery catalog:

RMAN> drop database;

2. To catalog all files in a disk location, first connect to the target database as before and providethe RMAN with the names of the directories you want it to catalog:

RMAN> catalog start with '/u01/app/oracle/datafiles/';

The following command will catalog all files in the recovery area:

RMAN> catalog recovery area;

Lab Answers 43

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8

P:\010Comp\CertPrs8\862-4\ch08.vpWednesday, September 08, 2004 1:10:02 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 417: OCA OCP - Oracle10G New Features For Administrators Exam Guide

9Flashback

TechnologyEnhancements

CERTIFICATION OBJECTIVES

9.01 General Flashback TechnologyConsiderations

9.02 Flashback Database

9.03 Flashback Drop

9.04 Flashback Table

9.05 Row Level Flashback Features

✓ Two-Minute Drill

Q&A Self Test

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9Blind Folio 9:1

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:37 PM

Color profile: DisabledComposite Default screen

Page 418: OCA OCP - Oracle10G New Features For Administrators Exam Guide

This chapter reviews Oracle’s flashback technology, which operates at many levels,serving a varied list of objectives. The flashback features of Oracle let you undological corruptions or user errors by retrieving data from a past time period. The

rationale behind flashback technology is to enable quick recovery from logical errors withouthaving to resort to time-consuming point-in-time recovery strategies using backups and archivedredo logs. Several of the flashback recovery features rely on the familiar undo data, since theyall need information from the past to recover from logical errors. In Oracle Database 10g, anew type of recovery log, called a flashback log, enables the flashback database feature. You canuse the flashback features of Oracle Database 10g to perform queries that return past data, toperform queries that show the history of changes to table data, to undo undesirable changes totable data, and to recover table(s) or even an entire database to a previous point in time.

Flashback technologies are superior to traditional recovery methods like point-in-timerecovery, which have become prohibitively slow in larger databases. Flashback techniqueshold an advantage over the use of the LogMiner tool as well. Flashback techniques arefaster because they focus purely on specific items of the changed data—there is noneed to parse entire redo log files to glean information about a single bad transaction.Oracle indexes all the changes, both on a row as well as transaction basis, for fast access.The flashback commands are simple as well. Thus, flashback techniques provide youwith a fast and efficient way to recover from logical (or user made) data errors. InOracle Database 10g, you can use the flashback technology at the database, table,and transaction levels, as summarized here:

■ Flashback database enables you to take the entire database to a past point intime (using flashback logs). Example: useful when you drop a user accidentally,truncate a large table, or a batch job applies partial changes only.

■ Flashback drop lets you retrieve accidentally dropped tables and indexes (usingthe recycle bin). Example: useful when you accidentally drop a table. Thisfeature also lets you restore a table to an earlier state in the event of an error.

■ Flashback table lets you recover a table to a time in the past (using undo data).Example: useful in situations when you update a table with the wrong WHEREclause.

■ Flashback query lets you query and restore data rows to a point in time (usingundo data). Examples: you want to compare current data against past data, oryou want to undo the effect of incorrectly run DML statements.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

2 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:38 PM

Color profile: DisabledComposite Default screen

Page 419: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Although all the recovery features in this chapter are called flashback features,not all of them rely on the flash recovery area or the new flashback logs. Onlythe flashback database feature uses the flash recovery area and flashback logs.The flashback drop feature relies on the new recycle bin concept. All theflashback query features rely on undo data.

We’ll look at the various Oracle Database 10g flashback features in detail in thischapter. Let’s start with a review of the building blocks that enable Oracle to offeryou all the amazing and painless recovery techniques.

CERTIFICATION OBJECTIVE 9.01

General Flashback Technology ConsiderationsBefore we delve into the various flashback features, let’s review Oracle’s undo management,which is at the heart of several of the new features. Let’s see how the concept of guaranteedundo retention turns out to be critical for the functioning of the flashback technology.

If you have a damaged disk drive, or if there is physical corruption (not logicalcorruption due to application or user errors) in your database, you must stilluse the traditional methods of restoring backups and using archived redo logsto perform the recovery.

General Flashback Technology Considerations 3

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Most flashback features(flashback transaction query, flashbackversions query, flashback table) rely onundo data. The flashback database feature

relies on the new flashback logs. Theflashback drop (table) feature relies onthe new concept of a recycle bin.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:38 PM

Color profile: DisabledComposite Default screen

Page 420: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Guaranteed Undo RetentionOracle automatically collects undo data and stores it in the undo segments. Undo datarecords the effects of individual transactions in changing table row data. Traditionally,Oracle has used undo data to provide read consistency for queries, to roll back unneededtransactions, and to recover terminated transactions. Starting with the Oracle9i version,Oracle has been using undo data for even farther-reaching purposes—to query past dataand recover from logical errors in the data. In Oracle Database 10g, use of undo datahas been extended to flashback entire tables to a past time, as well as perform transactionauditing.

The initialization parameter UNDO_RETENTION enables you to specify the lengthof time Oracle must retain undo information in the undo segments. Oracle Database 10gautomatically tunes undo information by collecting statistics on the longest-runningqueries and the undo generation rate in your database. If you don’t set the UNDO_RETENTION parameter, or you specify a zero value for the parameter, Oracleautomatically tunes undo, using 900 seconds as the default value for the parameter.By setting a much higher value than the default of 900 seconds, you can go backfurther in the past. Since many flashback features in Oracle Database 10g depend onhaving enough undo data, you should set the UNDO_RETENTION parameter muchhigher than the default value. (In addition to enabling more effective flashback features,this will also reduce the occurrence of the old snapshot too old errors.)

In previous chapters, you learned about the new guaranteed undo retention conceptin Oracle Database 10g. Guaranteed undo retention simply means that Oracle willkeep undo information in the undo segments for the entire length of the undo retentionperiod you specify (using the UNDO_RETENTION parameter), no matter what. Thatis, if you specify half an hour as the undo retention interval, Oracle will retain all undosegments for half an hour in the undo tablespace, even if there is space pressure in

the undo segments. If there were no room forsaving undo information for the new transactions,any new DML transactions would fail, since Oraclewon’t able to store the undo information forthose changes. Thus, if you don’t size your undotablespace correctly, there is a trade-off betweenguaranteeing undo information and the potentialfailure of some DML statements.

You can specify undo guarantee in several ways: You can specify undo guaranteefor the undo tablespace when you create the database. You can also specify guaranteedundo retention by using the RETENTION GUARANTEE clause when you create a newundo tablespace, as shown here:

4 Chapter 9: Flashback Technology Enhancements

By default, Oracle doesn’tguarantee undo retention. When you dochoose to guarantee undo retention, thedefault interval is 900 seconds (15 minutes).

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:38 PM

Color profile: DisabledComposite Default screen

Page 421: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SQL> create undo tablespace test1datafile ‘c:\oracle\product\10.1.0\oradata\undotbs_01.dbf’size 100M autoextend onretention guarantee;

Tablespace created.SQL>

You can also use the ALTER TABLESPACE command to tell Oracle to guaranteeundo retention in your database, as shown here:

SQL> alter tablespace test1retention guarantee;

Tablespace altered.SQL>

You can use the RETENTION NOGUARANTEE clause to turn off the guaranteedretention of undo information.

Use Oracle’s Undo Advisor to get approximate undo parameter values as wellas suggestions regarding the sizing of your undo tablespace to successfullysupport flashback for a specified time.

Time Mapping GranularityOracle gives you a choice between using either clock time or the system change number(SCN) to specify exactly what time in the past you want to go back to. Oracle uses aninternal mapping between clock times and SCNs. Thus if you specify a certain clocktime, Oracle will pick an SCN time that’s within three seconds of the clock time youspecify.

Oracle retains the mapping between your clock time and SCNs for a period thatis as long as your UNDO_RETENTION initialization parameter.

Two new SQL functions convert SCNs to a corresponding timestamp value andvice versa. Let’s review these functions in the following sections.

SCN_TO_TIMESTAMPThe SCN_TO_TIMESTAMP SQL function lets you convert an SCN to a calendartime (TIMESTAMP) value. Here’s an example:

SQL> SELECT current_scn, SCN_TO_TIMESTAMP(current_scn)2 FROM v$database;

General Flashback Technology Considerations 5

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:39 PM

Color profile: DisabledComposite Default screen

Page 422: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CURRENT_SCN SCN_TO_TIMESTAMP(CURRENT_SCN)------------- -----------------------------------5956956 03-JUL-04 09.37.16.000000000 AM

SQL>

TIMESTAMP_TO_SCNThe TIMESTAMP_TO_SCN function is the inverse of the SCN_TO_TIMESTAMPfunction. It converts a timestamp to its corresponding SCN.

CERTIFICATION OBJECTIVE 9.02

Flashback DatabaseWhen you discover a major logical corruption in your database, the usual recourse isto perform a point-in-time recovery. This type of recovery involving the use of datafilebackup copies and archived redo logs is very cumbersome and time consuming. Flashbackdatabase does the same job as a traditional point-in-time recovery: it takes the databaseback to a specific point in time or system change number (SCN). The big difference,of course, is that you don’t need to restore any backup datafiles, and you may need, atthe most, just a fraction of the archived redo log information. Consequently, a flashbackdatabase operation lets you recover from logical corruptions much faster than with theusual point-in-time incomplete database recoveries.

You must understand that flashing back a database is possible only when there isno media failure. If you lose a datafile, you’ll have to recover using a restored datafilefrom backups. You must have all the datafiles and they must all be uncorrupted inorder to conduct a flashback database operation.

The critical thing to note is that no matter what the extent of the logical corruption,traditional point-in-time recoveries require the restoration of datafiles and applicationof archived redo logs. With flashback database, the extent of time taken for recoverydirectly depends on the amount of changes that you need to undo. Thus, the size ofthe error, not the size of the database, determines the time it takes to recover.

How Flashback Database WorksOnce you enable the flashback database feature (I show how to do this in upcomingsections), at regular intervals, the database copies images of each altered block in the

6 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:39 PM

Color profile: DisabledComposite Default screen

Page 423: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

datafiles from memory (flashback buffer) to the new flashback logs. Oracle logsflashback data at infrequent intervals to reduce the I/O and CPU overhead. Oraclestores these flashback logs in the flashback recovery area. That’s why the first step inturning the flashback database feature on is to make sure you have configured a flashrecovery area.

The new memory buffer, flashback buffer, logs images of all altered data blocks inthe database. You can use these before images of data blocks to reconstruct a datafileso you can back out any changes made after a specified target time and turn the fileback to a time in the past. In reality, however, the flashback database logs are used torecover to a time just before the target time. Oracle uses traditional archive logs towrite changes for the short gap in time between the target recovery point in timeand the actual recovery time. A new background process, RVWR (Recovery Writer),starts up automatically when you enable the flashback database feature. The RVWRprocess writes the contents of the flashback buffer to the flashback database logs.The flashback database logs are somewhat similar to the traditional Oracle redo logs.Indeed, both logs are written to from a buffer area. However, the big difference isthat there are no archived flashback database logs! Oracle stores all the flashbackdatabase logs in the flash recovery area.

When you want to restore a database to a past target time using the flashbackdatabase feature, Oracle will restore each data block to its state at the time immediatelybefore the target time that the flashback logs were written. For example, if you wantto flashback to 8:00 A.M., it may turn out that the flashback logs nearest to the targettime were written at 7:56 A.M. To cover this gap, you must apply the changes fromarchived or online redo log files pertaining to that period. This is the reason why,although you aren’t doing a traditional point-in-time recovery using backup files andarchived redo log files, you must have redo logs available for the entire time periodspanned by the flashback logs.

Traditional point-in-time incomplete recovery involves the restoration of backupdata files first. After the restore, you apply the archive redo logs to advance the databaseforward. In flashback database, you don’t use any backup data files. You simply applythe flashback database logs to take the database back in time.

Oracle recommends that you set your redo log buffer for large databases toat least 8MB. The flashback buffer size will be at least log_buffer times two,thus ensuring that Oracle allocates the typical maximum memory possiblefor your flashback buffer, which is about 16MB.

Flashback Database 7

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:39 PM

Color profile: DisabledComposite Default screen

Page 424: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Always remember that Oracle doesn’t guarantee that you can flashback yourdatabase to the flashback retention target that you set by using the FLASHBACK_RETENTION_TARGET init parameter. Oracle stores the flashback logs you need fora flashback database operation in the flash recovery area. If Oracle is running low onfree space in the flash recovery area for newly arriving archived redo log files, it willremove some flashback logs to make room. That’s why it is absolutely essential tomonitor the flash recovery area size to ensure you don’t lose any critical flashbacklogs necessary to recover your database.

Flashback Database ConsiderationsThere are several considerations that you must be aware of when you use the flashbackDatabase feature. Here’s a summary:

■ All commands of the Flashback Database feature work the same in RMANas well as SQL*Plus. The only difference is that RMAN will automaticallyretrieve the necessary archived redo logs.

■ If you’ve lost a datafile or for some reason can’t use a datafile, you can’t useFlashback Database to recover. You must have all the datafiles to flashbackyour database to a past period.

■ If a datafile was resized during the time span covered by the Flashback Databaseoperation, you can’t flashback that datafile. Instead, you must offline thatparticular datafile before you start the flashback database operation.

■ If a control file has been restored or re-created during the time span you wantto flashback over, you can’t use the Flashback Database feature.

■ For good performance, Oracle recommends using fast file systems that don’tuse operating system file caching. Large flashback database logs add to youroverhead when using operating system file caching.

8 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

The time taken to flashbacka database strictly depends on how far backyou want to flashback and the amount ofdata block changes in the meantime. If you

have a heavy DML-based database, you’llhave more data block changes than if thedatabase was mainly supporting queries.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:40 PM

Color profile: DisabledComposite Default screen

Page 425: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ To increase disk throughput, Oracle recommends using multiple disk spindles,with small stripe sizes (128K) for flash recovery areas.

■ You can’t flashback a database to before a RESETLOGS operation.

■ You can’t flashback a datafile that was dropped during the time span coveredby the flashback table operation.

■ You can’t flashback a datafile that was shrunk during the time span coveredby the flashback table operation.

Configuring Flashback DatabaseYou need to perform a set of operations before you can use the Flashback Databasefeature. Let’s review these operations here:

1. Ensure that your database is in the archivelog mode.

2. Your database must be using the flash recovery area. (See Chapter 8 for detailson configuring the flash recovery area.) If you haven’t configured the flashrecovery area, you must do so before you can proceed further.

3. You must use the new initialization parameter DB_FLASHBACK_RETENTION_TARGET to set your flashback retention target. The flashback retention targetspecifies how far back you can flashback your database. The value of the DB_FLASHBACK_RETENTION_TARGET parameter determines how muchFlashback Database log data your database will store in the flashback recoveryarea. Of course, you must have enough space in your flash recovery area tocontain these Flash Database logs. Here’s an example that shows how to setyour flashback target to 1 day (1440 minutes):

SQL> ALTER SYSTEM SET2 DB_FLASHBACK_RETENTION_TARGET=1440;

System altered.SQL>

Flashback Database 9

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

If you want to undo theeffects of a Flashback Database operation,you must recover the database by rolling it

forward. Flashback Database rolls back thedatabase. To undo it, you therefore mustroll forward the database.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:40 PM

Color profile: DisabledComposite Default screen

Page 426: OCA OCP - Oracle10G New Features For Administrators Exam Guide

4. Shut down the database and restart in the MOUNT EXCLUSIVE mode.(If you are using a single instance, the simpler MOUNT command will do.)

SQL> SHUTDOWN IMMEDIATE;Database closed.Database dismounted.ORACLE instance shut down.SQL>SQL> startup mount;ORACLE instance started.Total System Global Area 117440512 bytesFixed Size 787728 bytesVariable Size 95419120 bytesDatabase Buffers 20971520 bytesRedo Buffers 262144 bytesDatabase mounted.SQL>

5. Turn the flashback database feature on with the following command:

SQL> alter database flashback on;Database altered.SQL>

6. Use the ALTER DATABASE OPEN command to open the database. To confirmwhether the flashback database feature is enabled, issue the following query:

SQL> select flashback_on from v$database;FLA---YESSQL>

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

10 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

You can find out if theflashback feature is enabled by queryingthe V$DATABASE view. The three thingsyou must do to configure the flashbackdatabase are as follows: configure the flashrecovery area, set the DB_FLASHBACK_RETENTION_TARGET parameter, and

finally, use the ALTER DATABASE FLASHBACKON command. You can turn the feature offby using the ALTER DATABASE FLASHBACKOFF command. Make sure you restart thedatabase in the MOUNT EXCLUSIVE modebefore using this command.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:40 PM

Color profile: DisabledComposite Default screen

Page 427: OCA OCP - Oracle10G New Features For Administrators Exam Guide

When you disable the flashback database feature, Oracle deletes all flashbackdatabase logs in the flash recovery area.

Configuring Flashback Database Using Database ControlIf you want to take the easy way out, you can use the OEM Database Control tool toconfigure flashback logging in your database. Here are the steps you must follow.(Make sure you have archive logging turned on.)

1. From the Home page, click on the Maintenance tab.

2. Go to the Backup/Recovery section and click on Configure Recovery Settings.

3. Under the Flash Recovery Area section, first specify the flash recovery areadestination and size.

4. Check the box next to “Enable flashback logging for fast database point-in-time recovery,” as shown in Figure 9-1.

Flashback Database 11

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

FIGURE 9-1 Configuring Flashback Database using Database Control

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:41 PM

Color profile: DisabledComposite Default screen

Page 428: OCA OCP - Oracle10G New Features For Administrators Exam Guide

12 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Flashback Storage IssuesFlashback database logs (stored in the flash recovery area) make it possible for you toperform a flashback database operation. The flash recovery area is primarily meant as astorage location for recovery-related files like datafile copies, incremental backups, andarchived redo logs. The database accords priority to storing these recovery-related filesover retaining flashback database logs. Accordingly, the database will delete flashbackdatabase logs if it needs the flash recovery area space to accommodate new recovery-related files. Therefore, you must ensure that you have allocated sufficient space toyour flash recovery area to hold all your flashback database logs.

The value of the DB_FLASHBACK_RETENTION_TARGET parameter (1440minutes in our example) determines how much flashback data the database shouldretain in the form of flashback database logs in the flash recovery area. In order toestimate the space you need to add to your flash recovery area for accommodatingthe flashback database logs, first run the database for a while with the flashbackdatabase feature turned on. Then run the following query:

SQL> select estimated_flashback_size, retention_target,flashback_size from v$flashback_database_log;ESTIMATED_FLASHBACK_SIZE RETENTION_TARGET FLASHBACK_SIZE------------------------ ---------------- ----------------------

126418944 1440 152600576SQL>

If there isn’t sufficient data to perform a flashback all the way back to whereyou want to take the database, you can use standard recovery procedures torecover the database.

The V$FLASHBACK_DATABASE_LOG view provides information that helps youestimate the amount of flashback data needed for your current database workloadlevel of DML activity (since queries don’t produce any flashback data). Let’s understandthe three key columns in the V$FLASHBACK_DATABASE_LOG view:

■ RETENTION_TARGET shows you the target retention time in minutes.

■ ESTIMATED_FLASHBACK_SIZE shows you the estimated size of flashbackdata needed to satisfy the value you specified for the RETENTION_TARGETparameter. Oracle bases its flashback data estimates on either the DML changesin the database since the instance started, or the most recent interval of timeequal to your retention target. Oracle chooses the shorter of these two choicesto prepare its flashback data estimate.

■ FLASHBACK_SIZE column shows the current size, in bytes, of theflashback data.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:41 PM

Color profile: DisabledComposite Default screen

Page 429: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Although the query on the V$FLASHBACK_DATABASE_LOG view enables youto come up with an estimate of the disk space for the flashback database logs, thatisn’t a guarantee that the space will meet your needs. To really know how far backyou can flashback your database at any given time, you must query the V$FLASHBACK_DATABASE_LOG in the following manner:

SQL> select oldest_flashback_scn,oldest_flashback_timefrom v$flashback_database_log;

OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_-------------------- -----------------

5964669 07-03-04 12:22:37SQL>

If the query results indicate that you can’t wind back your database as far as youwould like, you must increase the size of your flash recovery area. You do this so theflash recovery area can hold a larger amount of flashback database logs.

The database incurs an I/O overhead while logging the flashback data. The viewV$FLASHBACK_DATABASE_STATS helps you monitor the I/O overhead oflogging flashback data. Here’s the structure of the V$FLASHBACK_DATABASE_STATS view:

SQL> desc v$flashback_database_stat;Name Null? Type----------------------------------------- -------- ----------BEGIN_TIME DATEEND_TIME DATEFLASHBACK_DATA NUMBERDB_DATA NUMBERREDO_DATA NUMBERESTIMATED_FLASHBACK_SIZE NUMBERSQL>

Flashback Database 13

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Just because you have setyour retention target at a high valuedoesn’t ensure that Oracle will guaranteethe retaining of flashback database logs to

satisfy the retention target. If the flashbackrecovery area gets full, Oracle will removethe flashback database logs to make roomfor new recovery files.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:41 PM

Color profile: DisabledComposite Default screen

Page 430: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Let’s take a closer look at the elements in the V$FLASHBACK_DATABASE_STAT view:

■ BEGIN_TIME and END_TIME stand for the beginning and ending hourlytime intervals for which the view’s statistics were collected. Oracle collectsflashback data on an hourly basis for a maximum of 24 hours. If you issue aquery on the table, however, it may return 25 rows, the 25th row being for themost recent fraction of time after the last (24th) row was logged in the view.

■ FLASHBACK_DATA stands for the number of bytes of flashback data writtenduring the interval.

■ DB_DATA stands for the number of bytes of database data read and writtenduring the interval.

■ REDO_DATA stands for the number of bytes of redo data written duringthe interval.

■ ESTIMATED_FLASHBACK_SIZE is identical to the value ofthe ESTIMATED_FLASHBACK_SIZE column in the V$FLASHBACK_DATABASE_LOG view.

The V$FLASHBACK_DATABASE_STAT view helps you monitor how yourflashback data generation is changing across a day’s time. You can adjust either orboth of your retention target and flash recovery area size based on the statisticsprovided by this view.

If you don’t want certain tablespaces to be part of your flashback operations, youcan specify that Oracle not log any flashback database data for these tablespaces.You can specify turning off the flashback database feature at the tablespace levelwhen creating the tablespace itself, or later on, by using the ALTER TABLESPACEcommand. Here is an example:

SQL> alter tablespace users flashback off;Tablespace altered.SQL>

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

14 Chapter 9: Flashback Technology Enhancements

When you turn theflashback database feature off for atablespace, as shown in the previousexample, make sure that you take the

tablespace offline. Otherwise, Oracle willissue an error when you try to use theFLASHBACK DATABASE command.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:42 PM

Color profile: DisabledComposite Default screen

Page 431: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Flashback Database ExamplesWhen you issue the FLASHBACK DATABASE statement, Oracle will first check thatall the archived and online redo log files spanning the entire flashback period are available.It automatically reverts all the currently online datafiles to the SCN or time you specifyin the FLASHBACK DATABASE statement.

Let’s look at a few examples to illustrate the use of the FLASHBACK DATABASEcommand. In the first example, I first create a table called persons and load it withsome test data. I then use the flashback database feature to effortlessly get back to aspecified SCN. The example follows.

First, I check for the number of rows in the persons table.

SQL> select count (*) from persons;COUNT(*)

----------32768

I note what the current SCN of the database is with the following SQL command:

SQL> select current_scn from v$database;CURRENT_SCN-----------

5965123

I then double the number of rows in our test table, persons, I check the currentnumber of rows, and I get the following answer:

SQL> select count (*) from persons;COUNT(*)

----------65536

My goal is to get back to the time when the row count in the persons table was32768. I can do this easily by flashing back to the SCN 5965123. To use any flashbackfeature, I must restart the database in the MOUNT (exclusive) mode, as shown here:

SQL> startup mount;ORACLE instance started.…Database mounted.

I can now turn the flashback database feature on by using the following command:

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Flashback Database 15

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:42 PM

Color profile: DisabledComposite Default screen

Page 432: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SQL> flashback database to SCN 5964663;Flashback complete.

Note that TO SCN takes the database back to its state at that SCN. You can alsotake a database back to its state just before an SCN by using the TO BEFORE SCNclause. Alternatively, you may use the TO_TIMESTAMP or TO BEFORE TIMESTAMPto revert the database to a specified timestamp, or one second before the specifiedtimestamp.

In order to query the persons table, I must first open the database, which I try todo here:

SQL> alter database open;alter database open*ERROR at line 1:ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

I then use the ALTER DATABASE OPEN RESETLOGS command to open thedatabase. In order to have a write access to the database that I just flashed back,I must reopen the database with an ALTER DATABASE OPEN RESETLOGS statement.To make sure that you have indeed used the current SCN or target time, you mayfirst want to use the ALTER DATABASE OPEN READ ONLY statement. Once youconfirm that you have flashed the database back to the correct point in time orthe correct SCN, you can finalize matters by using the ALTER DATABASE OPENRESETLOGS statement. If after the initial check (in the read-only mode), youdecide to go back further in time, you can flashback the database again. If youdetermine that you flashed back too far into the past, you can use redo logs to rollforward. The ALTER DATABASE OPEN RESETLOGS statement should be usedonly after you are finally satisfied about the correctness (timewise)of the data.

SQL> alter database open resetlogs;Database altered.

You can verify that your database has been flashed back by using the followingquery on the persons table:

SQL> select count(*) from persons;COUNT(*)-----------32768

16 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:42 PM

Color profile: DisabledComposite Default screen

Page 433: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

In the previous example, I used an SCN to tell the database how far back itshould flashback. However, you may use an archived log sequence, or a prior time aswell, to specify the flashback point. Here are some examples using time and logsequence numbers:

SQL> flashback database to sequence 12345; /* will flashbackthe database to the log sequence numbered 1234) */SQL> flashback database to timestamp (SYSDATE -1/24); /* will flashback the database to an hour ago */

EXERCISE 9-1

Using the Flashback Database FeatureList the contents of your flash recovery area. Configure the flashback database featurein your database. Check the current SCN of your database. What is the oldest SCNyou can flashback your database to?

CERTIFICATION OBJECTIVE 9.03

Flashback DropOne of the biggest occupational hazards of a DBA’s job is the fact that you couldinadvertently drop a key production table. There are countless stories of how DBAshave dropped or truncated the wrong table in the wrong database, with disastrous

Flashback Drop 17

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Once you flashback thedatabase to a certain point in time, you canflashback the database to a different timeif you think you used the wrong flashbacktarget time the first time around. If youwant, you can perform a recovery to roll

the database forward, after the flashbackoperation. If you want to completely undothe effects of the flashback databaseoperation, just use the command RECOVERDATABASE to perform a complete recoveryof the database.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:42 PM

Color profile: DisabledComposite Default screen

Page 434: OCA OCP - Oracle10G New Features For Administrators Exam Guide

18 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

consequences, at an organizational as well as a personal level. Well, Oracle Database 10gfinally takes this hazard away, since you can’t mistakenly drop a table anymore! Whenyou drop a table by using the command DROP TABLE PERSONS, for example, thepersons table doesn’t go away immediately, as before. If you change your mind or realizeyou’ve made a mistake, you don’t have to perform a database point-in-time recovery.You simply use the following magical command to get your “lost” table back:

SQL> FLASHBACK TABLE persons TO BEFORE DROP;

In an Oracle 10g database, when you drop a table, Oracle doesn’t automatically dropthe space allocated to the table. It simply renames and stores the table and its dependentobjects in the database’s recycle bin. Using the Flashback Drop operation as shown inthe previous example, you then recover the dropped table from the recycle bin.

How the Flashback Drop Feature WorksIn previous versions of Oracle, when you used the DROP TABLE command, Oracleimmediately dropped the table and all its dependent objects. The database also releasedall the space in that table segment back to the database. In Oracle Database 10g, whenyou drop a table, the table is gone in name only—the table itself, with all its rows, ismerely renamed and stays in the same location as before. If you query the DBA_FREE_SPACE view, you’ll see additional space, indicating that the table segment has givenup its space. However, this additional free space is merely the potential free space youcan possibly reclaim, if you really get rid of the table later on. Thus, when you drop atable or an index, the space occupied by the objects is not reclaimable immediately bythe database, although you can see the space as free space in the DB_FREE_SPACEview. Oracle reclaims the space only if it experiences space pressure. Oracle’s goal hereis to retain the dropped objects for the maximum time possible.

As stated earlier, when you issue the DROP TABLE command, Oracle merelyrenames the table and moves it to a recycle bin. The recycle bin is not an area ondisk, unlike your flash recovery area. The recycle bin is merely a data dictionarytable that maintains information about dropped tables, such as their original namesand the new names that Oracle gives them when it temporarily renames them andplaces them in the recycle bin.

All objects that you drop will first sit in the recycle bin and continue to take uptheir original space allocation in their tablespaces. Oracle will permanently remove

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:43 PM

Color profile: DisabledComposite Default screen

Page 435: OCA OCP - Oracle10G New Features For Administrators Exam Guide

them from the recycle bin—and therefore, from the database—when either a userpurges them or Oracle automatically reclaims the space. To summarize:

■ You remove a table permanently with a PURGE command. You can use thePURGE command as an option with the DROP TABLE (or INDEX) command.You may also use the command to drop an object currently saved in therecycle bin.

Or

■ Oracle automatically removes the dropped objects in the recycle bin becauseof space pressure. Space pressure is said to occur when there isn’t enough freespace in a tablespace when you need to create a new object or extend more spaceto an existing object. Oracle first allocates all the available free space in thetablespace to the new object. When it runs out of available free space, Oraclewill start automatically purging the occupants of the recycle bin to make roomin the tablespace.

Querying the Recycle BinWhen you drop a table, Oracle lists the object in the recycle bin, which is a data dictionarytable named RECYCLEBIN$. You can view the contents of the recycle bin by usingeither the DBA_RECYCLEBIN (database level) view or the USER_RECYCLEBIN(user level) view. The DBA_RECYCLEBIN shows all dropped database objects, providedthey are still in the recycle bin. Here is an example that shows how to retrieve informationabout any dropped objects in your database:

SQL> select owner,original_name,object_name,2 ts_name,droptime3* from dba_recyclebin;

OWNER ORIGINAL_NAME OBJECT_NAME TS_NAME--------------------------------------------------------------------sam PERSONS BIN$xTMPjHZ6SG+1xnDIaR9E+g==$0 USERS

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Flashback Drop 19

There could be severalrecycle bins, each owned by the personwho dropped an object. The USER_RECYCLEBIN view displays information

about the recycle bin owned by the currentuser. The DBA_RECYCLEBIN view displaysinformation about all recycle bins in thedatabase.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:43 PM

Color profile: DisabledComposite Default screen

Page 436: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The DBA_RECYCLEBIN (and the USER_RECYCLEBIN) view shows detailsabout objects in all recycle bins in the database. Two important columns of the vieware the CAN_UNDROP and CAN_PURGE columns, which tell you whether youcan undrop and purge an object, respectively.

You can also use the command SHOW RECYCLEBIN to view the contents of therecycle bin, as shown here:

SQL> show recyclebinORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME---------------- ------------------------------ ------------ -------------PERSONS BIN$xTMPjHZ6SG+1xnDIaR9E+g==$0 TABLE 2004-07-04:12:08:57SQL>

The SHOW RECYCLEBIN command shows only those objects that you canundrop.

When Oracle moves a dropped table to the recycle bin it assigns the table a system-generated name, which is usually 30 characters long. If you look in the DBA_TABLES,DBA_OBJECTS, and DBA_SEGMENTS views, you are still listed as the owner of thetable. The reason is that as long as the dropped table is still in the recycle bin, youcan recover it by using the FLASHBACK TABLE command.

How can you tell by looking at the DBA_TABLES view which of your tables arein the recycle bin with system given names, and which are not? A simple query onDBA_TABLES will resolve this issue, as shown here:

SQL> select table_name, dropped from dba_tables;

Any table that was dropped and is still inthe recycle bin will show a YES value for theDROPPED column, and NO otherwise.

If you wish, you can query tables in therecycle bin. Understand that the recycle binknows your table by its system-generated nameonly—therefore, your query must include notthe original name of the dropped table, but thenew name given it while it is temporarily stored

in the recycle bin. Here’s an example that shows you how to query the dropped tablepersons. (Make sure you enclose the system name of the dropped table in double quotes.)

20 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

The recycle bin helps yourecover dropped tables only. If you truncatea table, you can’t recover it using the recyclebin. If you truncate a large table, you mightwant to use the flashback database feature.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:43 PM

Color profile: DisabledComposite Default screen

Page 437: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SQL> select * from "BIN$ksisyyg0TxKnt18rqukpQA==$0";NAME--------------------

Valerie alapatisam alapatinina alapatinicholas alapatishannon alapatiSQL>

Restoring Dropped TablesThe amazing power of the Flashback Drop feature lies in its ability to effortlessly recoverdropped tables and indexes. In order to restore a dropped table, you use the FLASHBACKTABLE …TO BEFORE DROP command, after making sure that your table is listed aspart of the recycle bin. You can use either the original name of the table you droppedor the new system-generated name when you recover a table and its dependent objectsfrom the recycle bin. Here is an example using the original name of the table to restore it.(In the example, I first dropped the persons table, which had 10240 rows.)

SQL> flashback table persons2* to before drop;

Flashback complete.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Flashback Drop 21

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Oracle renames all objectsin the recycle bin, including the dependentobjects like indexes, triggers, and constraints.When you flashback a table, Oracle willrecover the dependent objects as well,but they’ll continue to have their cryptic

system-generated names. You may want torename these objects to names that followyour organization’s object naming conventionsafter you complete the flashback tableoperation.

You can use the SELECTcommand to query the objects in the recycle

bin. You can’t use INSERT, UPDATE, andDELETE commands on these objects.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:44 PM

Color profile: DisabledComposite Default screen

Page 438: OCA OCP - Oracle10G New Features For Administrators Exam Guide

If you wish, you may use the system-generated name for the flashback table operation,as shown here:

SQL> flashback table "BIN$ksisyyg0TxKnt18rqukpQA==$0"2 to before drop;

Flashback complete.SQL>

You can also use the flashback operation as an opportunity to rename your droppedtable upon recovery, using the following command. (You may use the same commandwith the original name of the table in the first line, instead of the system-generatedname.)

SQL> flashback table "BIN$ksisyyg0TxKnt18rqukpQA==$0"to before droprename to NEW_PERSONS;

You may find this ability to rename a tablewithin the flashback command very helpfulwhen you’ve already created a new table withthe same name as the dropped table.

If you drop and re-create a table with thesame name, the recycle bin will have severalversions of the dropped table, each with a uniquesystem-generated table name. If you then issuea FLASHBACK TABLE … TO BEFORE DROP

command, Oracle will simply recover the latest version of the table. If you don’t wantOracle to do this, you have the following options:

■ In the FLASHBACK TABLE command, provide the specific system-generatedname of the table you want to recover.

■ Keep issuing the FLASHBACK TABLE command until you recover the particulartable you want.

Permanently Removing TablesWhat do you do when you are sure that you want to get rid of a table permanently?When you issue the DROP TABLE command, you can specify the new PURGE option,which will ensure that Oracle removes the table permanently and immediately, withoutmoving it to the recycle bin. The PURGE clause comes in especially handy when you

22 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

When you recover a tablefrom the recycle bin using the FLASHBACKTABLE… TO BEFORE DROP command,Oracle removes the object from therecycle bin.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:44 PM

Color profile: DisabledComposite Default screen

Page 439: OCA OCP - Oracle10G New Features For Administrators Exam Guide

want to drop a sensitive table and don’t want it to appear in the recycle bin for securitypurposes. Here’s how you use the PURGE command:

SQL> drop table persons purge;Table dropped.SQL>

The DROP TABLE …PURGE command is the equivalent of the DROP TABLEcommand in previous versions of Oracle. Using the PURGE clause is equivalentto first dropping the table and then purging it from the recycle bin.

Let’s say you drop the persons table fromthe tablespace USERS. Now the persons tablebecomes a part of the recycle bin. When a usercreates a new table in the USERS tablespace,Oracle assigns free space that doesn’t correspondto the dropped persons table. If there isn’tenough free space in the USERS tablespace tocreate the new table, Oracle will automaticallypurge objects from the recycle bin. If there areseveral objects in the recycle bin, Oracle firstremoves the oldest objects that it had placed

in the recycle bin. If the space pressure continues even after purging tables fromthe recycle bin, Oracle may extend the tablespace, provided it is autoextensible.

Here is how you can use the PURGE command to permanently remove variousobjects from your recycle bin:

■ PURGE TABLE or INDEX will remove the table or index. You can also usethe DROP TABLE … PURGE command, but that command applies to objectsthat aren’t a part of the recycle bin. You may also drop an object by using therecycle bin name of the object, for example:

SQL> purge table "BIN$Q1qZGCCMRsScbbRn9ivwfA==$0"Table purged.SQL>

If you have several tables of the same original name in the recycle bin, thePURGE command will drop the first table that you originally dropped.

■ PURGE TABLESPACE removes all objects that are part of that tablespace.Of course, if you remove a table, all of its dependent objects, such as indexes,

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Flashback Drop 23

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Once you remove an objectfrom the recycle bin with the PURGEcommand, or if you drop an object withthe PURGE command, you can’t apply theflashback drop feature with those objects(or their dependent objects)—the purgedobjects are gone forever!

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:44 PM

Color profile: DisabledComposite Default screen

Page 440: OCA OCP - Oracle10G New Features For Administrators Exam Guide

24 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

will be dropped as well. When you issue the PURGE TABLESPACE command,the dependent objects of a table that live in other tablespaces will be removedas well. If you want to remove all objects of a single user, scott, for example,from the recycle bin, you may use the following command:

SQL> purge tablespace users user scott;

■ If you drop a tablespace with the command DROP TABLESPACE…INCLUDINGCONTENTS, all the tablespace’s objects will be dropped permanently rightaway, without being placed in the recycle bin. In addition, any objects belonging

to the tablespace that are part of the recyclebin are purged immediately. If you use theDROP TABLESPACE command by itself,without the INCLUDING CONTENTSclause, the tablespace must not have anyobjects in it. Otherwise, the command willfail. In addition, if there are any objects inthe recycle bin that originally belonged tothis tablespace, those objects will be purgedfrom the recycle bin.

■ If you use the command DROP USER … CASCADE, Oracle immediatelydrops the user and all objects owned by the user from the database. Anyobjects in the recycle bin that belong to that user are automatically purged.

■ PURGE RECYCLEBIN or PURGE USER_RECYCLEBIN will remove all objectsbelonging to the user issuing the command.

■ PURGE_DBA_RECYCLEBIN will removeall objects in the recycle bin. You must havethe SYSDBA privilege to purge the entirerecycle bin.

EXERCISE 9-2

Using the Flashback Drop FeatureCreate a test table with a couple of indexes. Drop the table with the traditional DROPTABLE command. Re-create the table and drop it again. Repeat this process a fewtimes. Show the ways in which you can retrieve the very first table you dropped.

Understand the differencebetween the DROP USER and DROP USER…CASCADE command. Similarly, understandthe difference between a DROP TABLESPACEand a DROP TABLESPACE …INCLUDINGCONTENTS command.

When you drop a user, Oracledrops all the user’s objects permanently. Inaddition, Oracle permanently removes anyof the user’s objects that are in the recyclebin as well.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:45 PM

Color profile: DisabledComposite Default screen

Page 441: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Flashback Table 25

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Restrictions on Flashback DropCertain restrictions apply to the use of the Flashback Drop feature. Let’s look at theimportant restrictions here:

■ You can use the Flashback Drop feature on any table that belongs to any non-SYSTEM, locally managed tablespace.

■ Dependent objects can be in either a locally or dictionary managed tablespace,to be stored in the recycle bin.

■ The following types of dependent objects aren’t saved in the recycle bin whenyou drop a table:

■ Materialized view logs

■ Referential integrity constants

■ Bitmap join indexes

■ You can’t save a table that has fine-grained auditing (FGA) or Virtual PrivateDatabase policies defined on it.

CERTIFICATION OBJECTIVE 9.04

Flashback TableOracle’s Flashback Table feature lets you perform an online, point-in-time recoveryon one or more tables. The FLASHBACK TABLE statement lets you restore an earlierstate of a table to recover from human or application errors. For example, you mayneed to perform a point-in-time recovery on a table when a user mistakenly appliesan update statement with the wrong WHERE clause. The Flashback Table featurerelies on undo information in the database undo segments to perform the point-in-time recovery without ever having to restore any data files or apply any archived redo

The table that you wantto flashback must be in a non-SYSTEM,locally managed tablespace. However,

the dependent objects of that table canbe in a dictionary or locally managedtablespace.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:45 PM

Color profile: DisabledComposite Default screen

Page 442: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

log files. Ensure that you set your UNDO_RETENTION parameter to a time interval largeenough to cover the longest span of time forwhich you might want to recover a table. You canuse this feature to roll back any changes made toa table to a past SCN or time. Oracle acquiresexclusive DML locks on the table or tables thatit is recovering, but the tables are online andavailable to other users.

How Flashback Table WorksFlashback table technology uses undo information to restore data rows in changedblocks of tables. The changed information is in the undo segments, and Oracle usesthe undo data to undo or roll back the table data using DML statements like INSERT,UPDATE, and DELETE. Let’s review the necessary steps to perform a flashback tableoperation.

The flashback features aren’t supported for the user SYS.

First, make sure you have all the privileges necessary to perform the FlashbackTable operation. You must have either the FLASHBACK ANY TABLE or the morespecific FLASHBACK object privilege on the table you want to recover. In addition,you must have the SELECT, INSERT, DELETE, and ALTER privileges on the table.

Second, make sure you enable row movement in the table, since the flashbackoperation doesn’t preserve Oracle ROWIDs when it restores rows in the changeddata blocks of the table.

SQL> alter table persons enable row movement;Table altered.

Once you enable row movement in the table(s), you are ready to flashback thetable to any time in the past, or any SCN in the past. Here’s an example that showshow to flashback a table to a past SCN:

SQL> flashback table persons to scn 6039341;Flashback complete.

26 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

All indexes and otherdependent objects of a table, suchas dependent on-commit materializedviews, remain intact during a flashbacktable operation.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:45 PM

Color profile: DisabledComposite Default screen

Page 443: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You may also specify a time to flash back to, using the following command:

SQL> flashback table persons to timestamp to_timestamp(‘2004-07-04 08:05:00’, ‘YYYY-MM-DD HH24:MI:SS’);

The previous FLASHBACK TABLE command restores the persons table to 8.05 A.M.

on July 4, 2004.The persons table continues to be online and accessible to users for all queries.

However, Oracle acquires exclusive DML locks on the table during the FlashbackTable operation. The restore is an in-place, online operation and thus doesn’t involveany offlining of the datafiles or tablespaces, a procedure that’s common duringtraditional point-in-time recovery. However, Oracle disables all relevant triggers bydefault and reenables them upon completing the table recovery. You may simplyappend the ENABLE TRIGGERS clause to your FLASHBACK TABLE command ifyou want to override this default behavior. Here’s an example:

SQL> FLASHBACK TABLE person TO TIMESTAMP TO_TIMESTAMP(‘2004-07-04 08:05:00’, ‘YYYY-MM-DD HH24:MI:SS’)ENABLE TRIGGERS;

Undoing a Flashback Table OperationCan you undo a flashback operation? Yes! If it turns out that your flashback table resultsaren’t satisfactory, you can use the FLASHBACK TABLE statement again to go back tojust before you were when you issued the first statement. This is why it is important tonote your current SCN before using a Flashback Table operation. That way, if you everwant to undo a Flashback Table operation, you simply use the FLASHBACK TABLE… TO SCN statement to roll forward the table to a more recent time.

Restrictions on Flashback TableSeveral restrictions apply to the Flashback Table recovery feature. Let’s look at theimportant restrictions in this section.

The entire Flashback Table operation executes as a single transaction.

■ You can’t flashback a system or remote table.

■ You can’t flashback a table back to a time preceding any DDL operation thatchanges the structure of a table (for example, adding or dropping a column).

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Flashback Table 27

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:46 PM

Color profile: DisabledComposite Default screen

Page 444: OCA OCP - Oracle10G New Features For Administrators Exam Guide

28 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

■ Either the flashback operation succeeds entirely or it fails; it is a singletransaction. That is, if you have several tables in a FLASHBACK TABLEcommand, Oracle will recover all tables or none.

■ If there are any constraint violations during the flashback recovery, Oracleabandons the recovery process and leaves the tables as they were before thecommencement of the flashback operation.

■ If you shrink a table or otherwise change any of the nonstorage attributes ofa table (other than storage attributes such as PCTFREE, INITTRANS, andMAXTRANS), you can’t flashback to a time before you made these changes.

■ Oracle doesn’t flashback statistics of the recovered objects. You may, therefore,wish to collect new statistics for the recovered objects after you complete theflashback operation.

CERTIFICATION OBJECTIVE 9.05

Row Level Flashback FeaturesThus far in this chapter, you’ve seen the application of flashback techniques at a tableor the database level. You can also use the flashback techniques to perform very usefultasks at the row level. The row level flashback features provide ways to select informationfrom the past, see all the versions of a row, and change necessary row data. All rowlevel flashback features rely on undo data. The length of time you can go back forquery purposes depends on the setting of your UNDO_RETENTION initializationparameter. If you wish to provide your users the ability to flashback queries for a length

of two hours, for example, you must set the UNDO_RETENTION parameter to 7220. The defaultvalue for this parameter is only 900 seconds(15 minutes). There are three types of rowlevel flashback query features—FlashbackQuery, Flashback Versions Query, and FlashbackTransaction Query. Let’s look at these features indetail in the following sections.

Flashback Query (SELECT…AS OF)The Flashback Query feature isn’t new to Oracle Database 10g, but I’m reviewing itbriefly here for completeness. This feature retrieves data from a time in the past using

The value of the UNDO_RETENTION parameter determines thelength of time your users can flashbacktheir queries.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:46 PM

Color profile: DisabledComposite Default screen

Page 445: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

the AS OF clause of the SELECT statement. The Flashback Query feature enables youto perform queries on the database at a target time in the past. For example, if a useraccidentally deletes data rows during data entry, you can query the table using FlashbackQuery to retrieve the lost rows and reinsert them in the table. All the changes are madeusing simple SQL statements, and you don’t need to restore and recover any datafiles.

You may need to query past data in order to undo incorrect changes, verify thepast numbers in a column, or compare present data in a column with its past values.To query data from the past, simply use the normal SELECT statement with an ASOF clause. You may use SCN numbers or timestamps for this purpose. The AS OFclause ensures that Oracle returns the committed data in the table as of a previousSCN or timestamp. If you omit the AS OF clause, Oracle will retrieve data as of thecurrent SCN or a specific SCN or clock time if you have specified either one. Here’sa simple example that illustrates how you can query the past state of a table:

SQL> select * from persons as of timestampto_timestamp('2004-07-04 08:05:00', 'YYYY-MM-DD HH:MI:SS')where name = 'ALAPATI';

After verifying that the rows shown by your SELECT statement will correct thedata entry, you may undo the damage by simply inserting the correct rows, again withthe help of the SELECT … AS OF construct, this time in a subquery, as shown here:

SQL> insert into employee(SELECT * FROM employee AS OF TIMESTAMPTO_TIMESTAMP('2004-07-04 08:05:00', 'YYYY-MM-DD HH:MI:SS')where name = 'ALAPATI');

Flashback Versions QueryThe Flashback Versions query feature enables users to query the history of a given rowin a table. For a given interval, the feature enables you to retrieve different versions ofspecific rows that existed during that interval.When you issue a SELECT statementusing the VERSIONS clause, Oracle will return the different committed versions ofthe same row between two SCNs or two timestamps. You may also use the VERSIONSclause in subqueries of DML and DDL statements.

Row Level Flashback Features 29

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Flashback Versions query,like all the other Oracle flashback features,relies on undo data. You must set yourUNDO_RETENTION initialization parameter

to an adequate interval if you want to ensurethat your SELECT statement returns all theversions you are interested in.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:47 PM

Color profile: DisabledComposite Default screen

Page 446: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

The Flashback Versions Query feature enables the retrieval of all committedversions of the same table row between two time points. If you’ve updated the rowten different times, the Flashback Versions Query will get you all ten of those rows.The syntax of the versions query is as follows:

VERSIONS {BETWEEN {SCN | TIMESTAMP} start AND end}

In the preceding syntax statement, you can use the VERSIONS clause as a partof your normal SELECT statement, with an optional BETWEEN clause appended

to it. Optionally, you can specify the SCN orTIMESTAMP clauses. You must specify the startand end expressions, which indicate the starttime and end time of the interval for which youare seeking the different row versions.

The output of a Flashback Versions Queryis unlike the output of your typical SELECTstatement. In addition to the column valuesyou specify in the SELECT statement, for each

version of the row, Oracle will provide you with values for a set of pseudocolumns foreach row version. It is these pseudocolumns that tell you the story of when exactly arow change took place, and what exactly was done to the row at that time. Here is abrief explanation of each pseudocolumn that will be part of the flashback versionsquery output:

■ VERSIONS_STARTSCN and VERSIONS_STARTTIME Thispseudocolumn tells you the SCN and timestamp when this particular rowwas first created.

■ VERSIONS_ENDSCN and VERSIONS_ENDTIME These pseudocolumnstell you when this particular row expired.

30 Chapter 9: Flashback Technology Enhancements

The Flashback VersionsQuery feature retrieves only committedtransactions. Remember that the queryretrieves both deleted and subsequentlyreinserted rows.

An index-organized table(IOT) will show an update operation asa separate insert and a delete operation.Your versions query would produce boththe deleted and inserted rows as twoindependent versions. The first version

would show a D for the delete operationunder the VERSIONS_OPERATIONpseudocolumn (explained below), andthe subsequent insert column wouldshow an I for the same pseudocolumn.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:47 PM

Color profile: DisabledComposite Default screen

Page 447: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

■ VERSIONS_OPERATION This pseudocolumn provides you withinformation as to the type of DML activity that was performed on theparticualr row. The DML activities are indicated by letters: I stands forinsert, D for delete, and U for an update.

■ VERSIONS_XID This pseudocolumn stands for the unique transactionidentifier of the transaction that resulted in this row version.

Flashback Versions Query ExampleHere’s an example of using the Flashback Versions Query feature:

SQL> select versions_xid XID, versions_startscn START_SCN,versions_endscn END_SCN, versions_operation OPERATION,empname, salary from hr.empversions between scn minvalue and maxvalueas of scn 113900where empno = 111;

XID START_SCN END_SCN OPERATION EMPNAME SALARY---------------- ---------- --------- ---------- ---------- ----------0004000700000058 113855 I Tom 927000200030000002D 113564 D Mike 555000200030000002E 112670 113564 I Mike 555

The example retrieves three versions of a row for empno (employee number) 111.The AS OF SCN of the query is 113900. That is, you want to know what versionsof the row existed at this SCN. The query asks for the empname, salary and othrinformation for emno 111. The empno 111 is orginally to a new employee and if thatemployee is deleted, may be reassigned to a different employee. Thus, you may seedifferent employee names for the same empno valuye over time. Although you seethree versions of rows for empno 111, only one of them still exists at SCN 113900.Which version is it?

Read the query output from top to bottom. Pay particular attention to theSTART_SCN and the END_SCN columns. As you know, the START_SCNpseudocolumn tells you when a row was created. The END_SCN tells you when

Row Level Flashback Features 31

If the VERSIONS_STARTSCNand the VERSIONS_STARTTIME are NULL,then the row was created before the lowerbound specified by your BETWEEN clause.If the VERSIONS_ENDSCN and the

VERSIONS_ENDTIME are NULL, this meansthat this row version is current when you triedto use the Flashback Versions Query operation,or the row was part of a delete operation.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:47 PM

Color profile: DisabledComposite Default screen

Page 448: OCA OCP - Oracle10G New Features For Administrators Exam Guide

a row expired. All rows will have a START_SCN, but may have a NULL value forthe END_SCN if the version of the row still exists at the current SCN.

The Flashback Versions Query asks to bring all versions as of the SCN 113900.The first row, which inserted (operation = I) the first_name TOM at 113855, is thelatest version of the row. Since the END_SCN is NULL for the first row, you knowthat this row still exists at the SCN 113900. The middle row doesn’t have an END_SCN either (NULL), so why is this row not the current incarnation of the row? If

you look under the OPERATION column, yousee the letter D, indicating that the middle rowwas deleted. The bottom or third row has anEND_SCN number, so clearly this row expiredat SCN 113564.

Note that you could have substituted theVERSIONS BETWEEN TIMESTAMP … forthe VERSIONS BETWEEN SCN nn AND nnclause, if you decided to use timestamps insteadof SCNs to specify the time interval for retrievingthe various versions of the row.

Restrictions and Observations on Flashback Versions QueryThe following requirements and limitations apply to the Flashback Versions Queryfeature:

■ You can’t use this feature to query a view.

■ Your VERSIONS clause can’t be applied across DDL operations.

■ The query will ignore changes in row data that are purely physical, as is thecase during a segment shrink operation.

■ You can’t use this feature to query external temporary and fixed tables.

If you want to query past data at a precise time, you must use an SCN. If you usea timestamp, the actual time queried might be up to three seconds earlier thanthe time you specify. Internally, Oracle Database uses SCNs, which are mappedto timestamps, with a granularity of three seconds. This time-to-SCN mappinggap may throw you off if you’re trying to flashback to an exact time in the pastthat’s immediately after a DDL operation. Your entire table might be gone, andyou’ll get a major error instead of the Flashback Versions Query results!

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

32 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

You must know how to tellthe current, or live, version of a row whenyou use the Flashback Versions Queryfeature. You must understand when a rowexpires and how an END_SCN of NULLfor a deleted row means that the row nolonger exists.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:48 PM

Color profile: DisabledComposite Default screen

Page 449: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Flashback Transaction QueryOracle Database 10g provides a new view called Flashback Transaction Query that letsyou identify which transaction or transactions were responsible for certain changesduring a certain interval. A Flashback Transaction Query is a query on the FLASHBACK_TRANSACTION_QUERY view. Using a Flashback Transaction Query, you can obtaintransaction information, including the necessary SQL statements to undo all the changesmade by a transaction. This feature enables you not only to correct logical errors, but alsoconduct transaction audits in your database.

You are probably well aware of the use of Oracle’s LogMiner tool to undo SQLstatements. However, LogMiner has a serious drawback: Oracle must serially readentire redo log files to get to the necessary information. The Flashback TransactionQuery feature lets you use an indexed access path to quickly get to the necessaryundo data directly, instead of traversing through an entire redo log file. In addition,you can correct the effects of a single transaction or a set of bad transactions duringan interval of time.

Using the Flashback Transaction Query FeatureThe Flashback Transaction Query feature lets you view all database chages at the

transaction level, in order to recover from suer errors or to audit transactions..A newOracle 10g view called FLASHBACK_TRANSACTION_QUERY enables you to querypast transactions and correct them, if necessary. Using the Flashback Transaction Queryfeature simply means querying the FLASHBACK_TRANSACTION_QUERY view, togather information about changes made at the transaction level, as well as to retrievethe SQL code to undo the changes made by the unwanted transactions.

The FLASHBACK_TRANSACTION_QUERY view contains several useful columnsthat let you identify a transaction’s timestamp, the identity of the user that madethe transaction, the type of operations made during the transactions, as well the

Row Level Flashback Features 33

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

If you omit the AS OF clausein a Flashback Versions Query, data isretrieved as of the current SCN, or the

clock time or SCN if you have specifiedeither one.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:48 PM

Color profile: DisabledComposite Default screen

Page 450: OCA OCP - Oracle10G New Features For Administrators Exam Guide

undo statements necessary to retrieve the original row. Here’s the structure of theFLASHBACK_TRANSACTION_QUERY view:

SQL> desc FLASHBACK_TRANSACTION_QUERYName Null? Type----------------------------------------- -------- ----------XID RAW(8)START_SCN NUMBERSTART_TIMESTAMP DATECOMMIT_SCN NUMBERCOMMIT_TIMESTAMP DATELOGON_USER VARCHAR2(30)UNDO_CHANGE# NUMBEROPERATION VARCHAR2(32)TABLE_NAMEVARCHAR2(256)TABLE_OWNER VARCHAR2(32)ROW_ID VARCHAR2(19)UNDO_SQLVARCHAR2(4000)

You must have the SELECT ANY TRANSACTION system privilege to querythe FLASHBACK_TRANSACTION_QUERY view.

In the preceding description, the various columns stand for the following items:

■ START_SCN and START_TIMESTAMP tell you when a certain row wascreated.

■ COMMIT_SCN and COMMIT_TIMESTAMP provide information aboutwhen a transaction was committed.

■ XID, ROW_ID, and the UNDO_CHANGE# help identify the transaction,the row, and the undo change number, respectively.

■ OPERATION refers to the type of DML operation—update, insert, or delete .

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

34 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Sometimes you’ll notice avalue of UNKNOWN under the OPERATIONcolumn, instead of an INSERT, DELETE,or an UPDATE. This simply means that the

transaction didn’t have enough undoinformation to correctly identify itsoperation type.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:49 PM

Color profile: DisabledComposite Default screen

Page 451: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ LOGON_USER, TABLE_NAME, TABLE_OWNER columns provide the name of theuser who made the changes, the table’s name,and its schema, respectively.

■ UNDO_SQL gives you the exact SQLstatement to undo a transaction. Here’s anexample of the type of data you would findunder the UNDO_SQL column:

SQL> select undo_sql from flashback_transaction_query2 where table_owner = 'SAMALAPATI';

UNDO_SQL------------------------------------------------------------------------delete from "SAMALAPATI"."PERSONS" where ROWID = 'AAANZ+AAEAAAAIEAAG';delete from "SAMALAPATI"."PERSONS" where ROWID = 'AAANZ+AAEAAAAIEAAF';delete from "SAMALAPATI"."PERSONS" where ROWID = 'AAANZ+AAEAAAAIEAAE';insert into "SAMALAPATI"."PERSONS"("NAME") values ('sam alapati');insert into "SAMALAPATI"."PERSON"("NAME") values ('nina alapati');

The following Flashback Transaction Query uses the FLASHBACK_VERSIONS_QUERY view to derive the transaction ID (XID), operation type, the start and commitSCNs, the user’s name, and the SQL statement to undo the transaction.

SQL> select opEration, start_scn, logon_user,undo_sql from flashback_transaction_querywhere XID = HEXTORAW('0A001A00AD020000');

OPERATION START_SCN LOGON_USER UNDO_SQL------------------------------------------------------------------DELETE 6039310 SAMALAPATI insert into

“SAMALAPATI"."PERSONS"("NAME") Values ('nina alapati');SQL>

In our simple example, there is only a single delete operation that you need toperform, in case you wish to undo the changes made by this transaction. However,transactions usually contain several DML statements, in which case you have to applythe undo changes in the sequence that the query returns them in order to correctlyrecover the data to its original state.

Using Flashback Transaction Query andFlashback Versions Query TogetherYou’ve learned how you can derive a version history of the changes made to a tableusing the Flashback Versions Query feature. This feature provides the various versions

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Row Level Flashback Features 35

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

The Flashback TransactionQuery feature retrieves only committedtransactions. The query retrieves thedeleted and subsequently reinserted rows.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:49 PM

Color profile: DisabledComposite Default screen

Page 452: OCA OCP - Oracle10G New Features For Administrators Exam Guide

(the what) of a row, along with their unique version IDs and other information such asthe timestamps and SCNs when the row versions were created. However, this featuredoesn’t have all the necessary information to correct the changed row data usingappropriate SQL statements to undo an undesirable change. The Flashback TransactionQuery feature provides you with the necessary information to identify not only thetype of operations performed on each version of a row, but also the necessary undoSQL (the how) to put the rows back in their original state.

Let’s use a simple example to demonstrate how you can combine the FlashbackVersions Query and the Flashback Transaction Query features to undo undesirablechanges to your data.

First, let’s use the Flashback Versions Query feature to identify all the row versionsin a certain table that have changed in a certain time period. The following query letsyou do this:

SQL> select versions_xid XID, versions_startscn START_SCN,versions_endscn END_SCN, versions_operation OPERATION,empname, salary FROM hr.emp

versions between SCN MINVALUE and MAXVALUEwhere empno = 111;

XID START_SCN END_SCN OPERATION EMPNAME SALARY---------------- ---------- --------- ---------- ---------- ----------0004000700000058 113855 I Tom 927000200030000002D 113564 D Mike 555000200030000002E 112670 113564 I Mike 5553 rows selectedSQL>

In the previous query, let’s say we identified the second row, which indicates adelete operation (D) as the culprit. By mistake, one of our users has incorrectly deletedthe row. All you need to do in order to extract the correct SQL to undo this deleteoperation is to take the transaction ID (XID) from the Flashback Versions Queryshown in the previous section, and search for it in the FLASHBACK_TRANSACTION_QUERY view. Here’s the query you’ll need to execute:

SQL> select xid, start_scn START, commit_scn commit,operation op, logon_user user,undo_sql from flashback_transaction_queryWHERE xid = HEXTORAW('000200030000002D');

XID START COMMIT OP USER UNDO_SQL---------------- ----- ------ -- ---- ------------------------000200030000002D 195243 195244 DELETE HR insert into "HR"."EMP"("EMPNO","EMPNAME","SALARY") values ('111','Mike','655');000200030000002D 195243 195244 INSERT HR delete from "HR"."DEPT"where ROWID = 'AAAKD4AABAAAJ3BAAB';

36 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:49 PM

Color profile: DisabledComposite Default screen

Page 453: OCA OCP - Oracle10G New Features For Administrators Exam Guide

000200030000002D 195243 195244 UPDATE HR update "HR"."EMP"set "SALARY" = '555' where ROWID = 'AAAKD2AABAAAJ29AAA';000200030000002D 195243 113565 BEGIN HR4 rows selectedSQL>

Flashback Transaction Query ConsiderationsHere are a few cautions and restrictions involving the use of the Flashback TransactionQuery feature:

■ You may want to turn on minimal supplemental logging in order to supportoperations involving chained rows and special storage structures such asclustered tables.

■ If you query a transaction involving an IOT, an update operation is alwaysshown as a two-step delete/insert operation.

■ If your Flashback Transaction Query involves a dropped table or a droppeduser, it returns object numbers and user IDs instead of the object names andusernames, respectively.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

Row Level Flashback Features 37

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

It is important for you to understand themechanism behind the various flashbackfeatures. Understand that you rely on the flashrecovery area (Flashback Database), undo data(Flashback table, Flashback Transaction Query,and Flashback Versions Query). What featureenables you to recover a dropped table (therecycle bin)?

The test will contain questions relatingto the flash recovery area. How do youconfigure the flash recovery area? How doyou monitor and size the flash recovery area?

You must know when to use each of theflashback techniques. For example, what

flashback technique would you use when youdrop a table accidentally? Which technique isbest when you truncate a large table or applypartial changes in a large table? How aboutwhen you use the wrong WHERE clause toupdate a table? Know how and why you canuse the Flashback Transaction Query and theFlashback Versions Query features together.

The exam will contain questions relating tothe recycle bin. Know the difference betweenthe DROP TABLE and DROP TABLE…PURGE commands. The test will probe yourknowledge of the recycle bin object namingconventions. How can you flashback a table

INSIDE THE EXAMINSIDE THE EXAM

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:49 PM

Color profile: DisabledComposite Default screen

Page 454: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CHAPTER SUMMARYOracle offers you the point-in-time recovery technologies to help you go back to a pastpoint in time in the event of a logical error. However, performing a point-in-timerecovery is time consuming, and the new flashback technology offers ways to undological errors by simply “rewinding” the database or a table to a previous time. Thischapter introduced you to the new Oracle Database 10g flashback techniques thatenable you to perform effortless recovery at a row, table, and even the database level.You first learned how the undo data forms the bedrock of the flashbacktechnology.You learned how to flashback a database as well as an individual table.You reviewed the new recycle bin concept, which helps you recover dropped databasetables and their dependent objects.

You also learned how to use the Flashback Versions Query feature to discover all theversions of a given row. You then learned how to use the Flashback Transaction Queryfeature, which enables you to see the changes made by particular transactions and alsoto undo any undesirable changes. You can use this feature to audit certain transactionsor to recover from logical errors.

38 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

more than once? When does the databasereclaim the space belonging to a droppedobject? (Either use the PURGE command,or the database must suffer space pressure.)What happens to the recycle bin contentswhen you issue commands to drop a tablespaceor a user? Know how to query objects in therecycle bin. What commands help you bypassthe recycle bin?

You must understand why you needto enable row movement before a certain

flashback operation. Can you roll back a flashbackoperation?

The test will contain questions on flashback-related views like V$FLASHBACK_DATABASE_LOG and V$FLASHBACK_DATABASE_STAT.What do these two views help you do? (Theyhelp you size the flashback area and set theflashback retention target.) How do you findout the flashback status for a database?

INSIDE THE EXAMINSIDE THE EXAM

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:50 PM

Color profile: DisabledComposite Default screen

Page 455: OCA OCP - Oracle10G New Features For Administrators Exam Guide

✓TWO-MINUTE DRILL

General Flashback Technology Considerations

❑ Flashback technology offers you ways of undoing logical errors at the database,table, and row levels.

❑ The guaranteed undo retention feature is critical to the functioning of severalflashback features that rely on undo data.

❑ If you have a damaged disk or some physical corruption, you must still use thetraditional recovery techniques.

❑ Flashback technology uses undo data to query past data as well as to recoverfrom logical errors.

❑ Undo retention is the length of time Oracle retains undo data.

❑ By default, Oracle doesn’t guarantee undo retention.

❑ The default undo interval under guaranteed undo retention is 900 seconds.

❑ You can use the RETENTION GUARANTEE clause to institute guaranteedundo retention, either when you create a tablespace, or later, by using theALTER TABLESPACE command.

❑ You can use either a system change number or regular clock time to tell Oraclethe time in the past that you want it to go back to.

❑ Oracle picks an SCN that’s within three seconds of the clock time that youspecify.

❑ The SCN_TO_TIMESTAMP SQL function converts an SCN to a calendartime.

❑ The TIMESTAMP_TO_SCN function converts a timestamp to itscorresponding SCN.

Flashback Database

❑ The Flashback Database feature lets you take a database to a past point in time.

❑ The flashback Database feature enables point-in-time recoveries without backupfiles and archived redo logs.

❑ The size of the logical error, not the size of the database, determines recoverytime when you use the flashback database feature.

Two-Minute Drill 39

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:50 PM

Color profile: DisabledComposite Default screen

Page 456: OCA OCP - Oracle10G New Features For Administrators Exam Guide

❑ The flashback buffer logs images of altered data blocks in the database.

❑ Oracle uses the before images of the data blocks to reconstruct a datafile.

❑ The new background process RVWR is in charge of writing the contentsof the flashback buffer to the flashback database logs.

❑ Oracle stores all Flashback Database logs in the flashback recovery area,and you can’t archive them.

❑ You can use all Flashback Database commands the same way in both RMANand SQL*Plus.

❑ If you’ve lost a datafile, or if you have resized a datafile during the relevantperiod, you can’t use the Flashback Database feature.

❑ Since flashing back a database involves the rolling back of data to undo itseffects, you must roll forward the database using redo logs.

❑ To configure the Flashback Database feature, you must first set up your flashrecovery area and then set your retention target using the DB_FLASHBACK_RETENTION_TARGET parameter. You can then turn the Flashback Databasefeature on, with the ALTER DATABASE FLASHBACK ON command.

❑ You can turn the Flashback Database feature off with the ALTERDATABASE FLASHBACK OFF command.

❑ If you disable the Flashback Database feature, Oracle deletes all the FlashbackDatabase logs in the flash recovery area.

❑ Oracle gives priority to the storing of recovery-related files (datafile copies,incremental backups, and archived redo logs) over Flashback Database logs.

❑ The ESTIMATED_FLASHBACK_SIZE column of the V$FLASHBACK_DATABASE_LOG view provides you with the estimated size of flashback dataneeded to satisfy your retention target.

❑ The FLASHBACK_SIZE column of the V$FLASHBACK_DATABASE_LOGview shows the current size of flashback data.

❑ The V$FLASHBACK_DATABASE_STATS view helps you monitor the I/Ooverhead of logging flashback data.

❑ You can turn flashback data collection off for individual tablespaces after takingthe tablespaces offline first.

❑ You can flashback a database using a log sequence number, an SCN, or a timespecified by TIMESTAMP .

40 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:51 PM

Color profile: DisabledComposite Default screen

Page 457: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Flashback Drop

❑ The DROP TABLE command doesn’t drop a table right away, as in previousversions.

❑ Oracle saves a table in the recycle bin after you issue the normal DROP TABLEcommand.

❑ You can retrieve a dropped table by using the Flashback Drop feature.

❑ The command to retrieve a table is FLASHBACK TABLE table_name TOBEFORE DROP.

❑ The DBA_FREE_SPACE view shows additional free space when you drop atable, but Oracle doesn’t actually reclaim this space immediately.

❑ Oracle reclaims the space occupied by an object only after either the user orthe database purges the object permanently from the recycle bin.

❑ Oracle will try to keep dropped objects in the recycle bin as long as possible.It purges objects automatically only when it’s under space pressure.

❑ You can view the contents of the recycle bin by using the DBA_RECYCLEBINand USER_RECYCLEBIN views, or the SHOW RECYCLEBIN command.

❑ The SHOW RECYCLEBIN command only shows those objects that you canundrop.

❑ You can’t recover a truncated table.

❑ You can issue queries against a dropped table, provided you use the system-given names.

❑ When you drop any object, Oracle renames all dependent objects that itstores in the recycle bin.

❑ In the FLASHBACK TABLE … TO BEFORE DROP command, you can givethe original name of the object or its system-given name after it is stored inthe recycle bin.

❑ The PURGE option of the DROP TABLE command will remove a tablepermanently from the database or from the recycle bin, if the object is beingstored there after renaming it.

❑ If there are several identically named tables in the recycle bin, the PURGEcommand will remove the first table that you dropped.

❑ The PURGE TABLESPACE command removes a tablespace from the recycle bin.

Two-Minute Drill 41

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:51 PM

Color profile: DisabledComposite Default screen

Page 458: OCA OCP - Oracle10G New Features For Administrators Exam Guide

❑ The PURGE TABLESPACE tablespace_name USER user_namecommand will remove all objects of a user from the recycle bin.

❑ The DROP TABLESPACE …INCLUDING CONTENTS command drops allthe objects in the tablespace directly, bypassing the recycle bin.

❑ The PURGE RECYCLEBIN and the PURGE USER_RECYCLEBIN commandsremove all objects belonging to a user from the recycle bin.

❑ The PURGE DBA_RECYCLEBIN command will remove all objects from therecycle bin.

❑ When you drop a user, Oracle permanently drops all of the user’s objects,thereby bypassing the recycle bin.

❑ You can use the Flashback Drop feature only on non-SYSTEM, locally managedtablespaces.

❑ Dependent objects of a table can be in either a locally managed or dictionary-managed tablespace.

❑ Oracle doesn’t store a materialized view log, bitmap join indexes, or referentialintegrity constraints in the recycle bin.

❑ You can’t use the Flashback Table feature if a table has fine-grained auditingor a Virtual Private Database defined on it.

Flashback Table

❑ Using the Flashback Table feature, you can restore a table back to a pointin time.

❑ During a Flashback Table operation, the tables are online and in place.

❑ Oracle acquires exclusive DML locks on the table it is flashing back.

❑ All indexes and other dependent objects of a table that is being flashed backwill remain intact during the operation.

❑ Oracle uses undo data to roll back table data during the flashback operation.

❑ You must have the FLASHBACK ANY TABLE or FLASHBACK objectprivileges on the table.

❑ You must also have the ALTER, INSERT, UPDATE, and DELETE privilegeson the table.

❑ You must enable row movement before you can flashback a table.

42 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:52 PM

Color profile: DisabledComposite Default screen

Page 459: OCA OCP - Oracle10G New Features For Administrators Exam Guide

❑ You can flashback a table using a past SCN or a past time period, using theTIMESTAMP function.

❑ You can undo a Flashback Table operation by simply using the FLASHBACKTABLE command again.

❑ You can’t flashback a system or remote table.

❑ The flashback operation is a single transaction, so either the entire operationsucceeds, or the whole operation will fail.

❑ If you shrink a table or change any nonstorage attributes of a table, you can’tflashback a table to a time before you made these changes.

❑ Oracle doesn’t flashback statistics of recovered tables and indexes.

Row Level Flashback Features

❑ The Flashback Versions Query feature lets you query the history of a datarow by selecting all versions of a row.

❑ Oracle returns only committed versions of a row.

❑ You can use SCNs or timestamps to indicate the interval for the flashbackversions query feature.

❑ In addition to column values, Oracle will also provide values for thepseudocolumn for each row version. The VERSIONS_XID pseudocolumngives you the unique transaction identifier for a row version.

❑ The VERSIONS_OPERATION pseudocolumn indicates the type of DMLactivity that was performed on a particular version of a row.

❑ You can’t use the Flashback Versions Query feature to query a view, externaltables, temporary tables, and fixed tables.

❑ You can’t apply the VERSIONS clause across DDL operations.

❑ The Flashback Versions Query feature ignores purely physical changes likethose that occur during a segment shrink operation.

❑ The Flashback Transaction Query feature focuses on the changes made toa row during a certain interval.

❑ The Flashback Transaction Query feature enables transaction audits andthe correction of logical errors.

Two-Minute Drill 43

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:53 PM

Color profile: DisabledComposite Default screen

Page 460: OCA OCP - Oracle10G New Features For Administrators Exam Guide

44 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

❑ The Flashback Transaction Query operation is faster than the LogMinertool, because you use an indexed access path to quickly get to the appropriateundo data.

❑ You use the Flashback Transaction Query feature by querying the FLASHBACK_TRANSACTION_QUERY view.

❑ When you see the value UNKNOWN in the OPERATION column of theFLASHBACK_TRANSACTION_QUERY view, it means that the transactiondidn’t have enough undo information to enable Oracle to correctly identifyits operation type.

❑ The UNDO_SQL column of the FLASHBACK_TRANSACTION_QUERYview gives you the SQL necessary to undo the DML statement that changeda row.

❑ You can use the Flashback Versions Query and Flashback Transaction Queryfeatures together, to first identify the correct row version and then undo itseffects.

❑ When you use the Flashback Transaction Query on an IOT, an update operationis shown as separate delete and insert statements.

❑ If you encounter a dropped user or table, the FLASHBACK_TRANSACTION_QUERY view will show only the user IDs and object IDs, instead of usernamesand object names.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:53 PM

Color profile: DisabledComposite Default screen

Page 461: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test 45

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

SELF TEST

General Flashback Technology Considerations

1. What is the purpose of the flashback technology in Oracle Database 10g?

A. Recovery from physical corruption of a data fileB. Recovery from physical and logical corruption of a data fileC. Recovery from logical corruption of a data fileD. Recovery from a problem brought on by a damaged disk drive

2. The initialization parameter UNDO_RETENTION is used for what purpose?

A. To specify the length of time Oracle must retain undo data in the undo tablespaceB. To specify the length of time Oracle must retain undo data in the flash recovery areaC. To specify the length of time Oracle must retain undo data in the data filesD. To specify the length of time Oracle will retain undo data in the flashback database logs

3. Which one (or more) of the following is true?

A. Oracle guarantees undo retention by default.B. Oracle doesn’t guarantee undo retention by default.C. The default undo interval is 1440 minutes (1 day).D. The default undo interval is 900 seconds (15 minutes).

4. Which of the following statements is true? (Please choose more than one answer.)

A. Oracle uses clock times internally, but it maps them to SCN times.B. Oracle uses SCNs internally, but it maps them to clock times.C. Oracle will pick an SCN within three seconds of the clock time you specify.D. Oracle will pick an SCN within one second of the clock time you specify.

Flashback Database

5. Which of the following statements is correct when you use the Flashback Database feature?

A. You don’t need to apply any archived logs at all.B. You need to apply only one archived log during recovery.C. You must apply all archived logs produced during the time interval covered by the flash

database operation.D. You must apply archived logs only for a small amount of time, since the flashback database

logs will recover to a point just before the target time.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:53 PM

Color profile: DisabledComposite Default screen

Page 462: OCA OCP - Oracle10G New Features For Administrators Exam Guide

6. What should you do before you can turn the flashback database feature on?

A. Start the database with the STARTUP command.B. Start the database with the STARTUP MOUNT command.C. Start the database with the STARTUP MOUNT EXCLUSIVE command.D. Start the database with the STARTUP NOMOUNT command.

7. What happens to the flashback database logs when you disable the flashback database feature?

A. Oracle will delete all the flashback database logs from the flash recovery area.B. Oracle will archive all the flashback database logs that are currently in the flash recovery

area, and delete them afterwards.C. Oracle will clear the flashback buffer area.D. Oracle will leave the flashback database logs in the flash recovery area, and remove them

only when it’s under space pressure.

8. Which of the following views contains the ESTIMATED_FLASHBACK_SIZE column?

A. V$FLASHBACK_DATABASE_LOG viewB. V$FLASHBACK_DATABASE_STATS viewC. Both the V$FLASHBACK_DATABASE_LOG and the V$FLASHBACK_DATABASE_STATS

views have this column.D. V$FLASHBACK_DATABASE view

Flashback Drop

9. What is the equivalent of the old DROP TABLE command in Oracle Database 10g?

A. DROP TABLE … TO BEFORE DROP

B. DROP TABLE works exactly the way it did in previous versions.C. DROP TABLE … PURGE

D. DROP TABLE NO PURGE

10. Which one (or more) of the following statements is true?

A. The SHOW RECYCLEBIN command shows all objects that you can undrop.B. The SHOW RECYCLEBIN command shows all objects that you can undrop and purge.C. The DBA_RECYCLEBIN view shows all objects that you can undrop and purge.D. The DBA_RECYCLEBIN only shows items that you can undrop.

11. After you drop a table using the DROP TABLE command,

46 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:54 PM

Color profile: DisabledComposite Default screen

Page 463: OCA OCP - Oracle10G New Features For Administrators Exam Guide

A. You can query the table by using its original name only.B. You can query the table by using its new system-generated name only.C. You can query the table by using the original or system-generated name.D. You can’t query a table once you drop it.

12. When you use the command PURGE RECYCLEBIN,

A. Oracle will remove all the objects in the recycle bin that are owned by all users.B. Oracle will only remove objects from the recycle bin that belong to the current user.C. Oracle will remove only the tables belonging to the current user.D. You must ensure that you have the SYSDBA privilege.

Flashback Table

13. The Flashback Table feature is ideal in which of the following situations?

A. When you drop a userB. When you truncate a tableC. When you drop a tableD. When you update a table with the wrong WHERE clause by mistake

14. What kinds of privilege(s) are necessary for you to use the flashback table feature?

A. ALTER TABLEB. FLASHBACK ANY TABLEC. No special privileges are necessary—you must be the owner of the object.D. FLASHBACK TABLE privilege on the table you are flashing back

15. Which one of the following statements is correct?

A. You must enable row movement in the table you are flashing back, because the flashbackoperation doesn’t preserve Oracle ROWIDs.

B. You must disable row movement in the table you are flashing back, because the flashbackoperation doesn’t preserve Oracle ROWIDs.

C. You must disable row movement in the table you are flashing back, because the flashbackoperation preserves Oracle ROWIDs.

D. You must enable row movement in the table you are flashing back, because the flashbackoperation preserves Oracle ROWIDs.

16. What is the most likely outcome if Oracle violates any constraints during a flashback tableoperation?

Self Test 47

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:54 PM

Color profile: DisabledComposite Default screen

Page 464: OCA OCP - Oracle10G New Features For Administrators Exam Guide

A. The database continues to flashback the database, after logging a warning in the alert log.B. The database abandons the flashback process and leaves the table in the state it is at that

point in time.C. The database abandons the flashback process and leaves the tables as they were before the

start of the flashback operation.D. You have to disable all constraints before you start a flashback database operation. Therefore,

there is no chance of your violating any table constraints.

Row Level Flashback Features

17. Which row or rows does the flashback versions query generate?

A. All committed versions of a rowB. All committed and uncommitted versions of a rowC. Only the most recent committed version of a rowD. The oldest committed row

18. What do the pseudocolumns of a flashback versions query tell you?

A. When a row version was first createdB. What kind of DML operation was performed on a rowC. The UNDO statement(s) necessary to undo the results of a transactionD. The REDO statement(s) necessary to undo the results of a transaction

19. Which of the following statement (or statements) is true?

A. The flashback transaction query relies on the FLASHBACK_TRANSACTION_QUERY view.B. The flashback transaction query relies on the FLASHBACK_TRANSACTION_QUERY

procedure.C. The flashback transaction query cannot be used together with the flashback versions query

feature.D. The flashback transaction query can be used together with the flashback versions query

feature.

20. Which of the following statements is true?

A. The VERSIONS_XID column of the FLASHBACK_TRANSACTION_QUERY view maps tothe VERSIONS_XID pseudocolumn shown in the output of a FLASHBACK_VERSIONS_QUERY select statement.

48 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:54 PM

Color profile: DisabledComposite Default screen

Page 465: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Lab Question 49

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

B. The XID column of the FLASHBACK_VERSIONS_QUERY view maps to the VERSIONS_XID pseudocolumn shown in the output of a FLASHBACK_VERSIONS_QUERY selectstatement.

C. The XID column of the FLASHBACK_TRANSACTION_QUERY view maps to theVERSIONS_XID pseudocolumn shown in the output of a FLASHBACK_VERSIONS_QUERY select statement.

D. The VERSIONS_XID column of the FLASHBACK_TRANSACTION_QUERY view maps tothe XID pseudocolumn shown in the output of a FLASHBACK_VERSIONS_QUERY selectstatement.

LAB QUESTIONCreate a table with an index, constraint, primary key, materialized view log, and a trigger. Drop thetable. Recover the table and its objects using the appropriate flashback techniques. Verify the resultsto make sure you recovered all the objects of the table.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:54 PM

Color profile: DisabledComposite Default screen

Page 466: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

SELF TEST ANSWERS

General Flashback Technology Considerations

1. � C. The flashback technology is purely meant to address logical corruptions in data dueto user and application errors.� A and D are wrong because physical corruption of datafiles means that you must use thetraditional recovery techniques, which involve using backup data files. B is wrong since flashbacktechnology doesn’t address physical corruption of data.

2. � A. The UNDO_RETENTION parameter specifies the time period that undo data is savedin the undo segments, which are located in the undo tablespace.� B is wrong because Oracle doesn’t retain undo data in the flash recovery area. C is incorrectsince undo data is not saved in datafiles, but in the undo tablespace. D is wrong since flashbackdatabase logs don’t contain undo data; they contain the changed images of Oracle data blocks.

3. � B and D. B is correct because Oracle doesn’t guarantee undo retention by default. Youhave to enable undo retention explicitly. D is correct because once you enable undo retention,Oracle will save undo data for a default period of 900 seconds.� A is wrong because Oracle doesn’t guarantee undo retention by default. C is wrong becausethe default undo interval is 900 seconds.

4. � A and C. A is correct because Oracle uses clock times internally, but it maps them to SCNs.C is correct because the time mapping granularity between Oracle’s clock times and SCNs is 3seconds. Therefore, Oracle will pick an SCN within three seconds of clock time that you specify.� B is wrong because Oracle uses clock times internally and maps them to SCNs. D isincorrect because the time mapping granularity is three seconds, not one second.

Flashback Database

5. � D. When flashing back a database, the Flashback Dtabase logs you must apply will takeyou to a point that’s a little bit before your target time. You must apply archive logs to rollforward for that point on, to your target time.� A is wrong since you most likely will have to use some archived log(s). B is wrong sincethere is no guarantee that a single archived log will be sufficient. The number of archived logsyou need will depend on the size of the archived logs and the amount of DML changes in yourdatabase. C is wrong because you don’t have to apply any of the logs produced during the flashbackoperation.

6. � B and C. You must start the database in the MOUNT EXCLUSIVE mode before you canconfigure the flashback database feature. If you have a single instance, the STARTUP MOUNTcommand is sufficient. If you have a Real Application Cluster, you’ll have to use the analogous

50 Chapter 9: Flashback Technology Enhancements

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:55 PM

Color profile: DisabledComposite Default screen

Page 467: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test Answers 51

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

MOUNT EXCLUSIVE command. Since I didn’t specify whether you are dealing with a singleinstance or a Real Application Cluster, both B and C would be correct alternatives.� A is wrong since you can’t open the database before turning the flashback database feature on.D is wrong since you have to be in the MOUNT, not in the UNMOUNT state, before turning theflashback feature on.

7. � A. Oracle will immediately delete all Flashback Database logs once you disable the flashbackdatabase feature.� B is incorrect since Oracle never archives Flashback Database logs. C is wrong because Oracledoesn’t clear the flashback buffer area when you disable the Dlashback Database feature. D is wrongbecause Oracle deletes the Flashback Database logs immediately and doesn’t wait until it is underspace pressure.

8. � C. Both the V$FLASHBACK_DATABASE_LOG and the V$FLASHBACK_DATABASE_STATS views contain an identical column, the ESTIMATED_FLASHBACK_SIZE.� A and B are only partially correct, since they provide the name of only one of the viewsthat contains the column ESTIMATED_FLASHBACK_SIZE. D refers to a nonexistent view.

Flashback Drop

9. � C. The DROP TABLE …PURGE command is the equivalent command to the old DROPTABLE command, since it immediately drops the table permanently.� A is wrong since the command doesn’t drop a table—it recovers it after you drop it. B iswrong because the Oracle Database 10g DROP TABLE command doesn’t drop a table rightaway as in previous versions. D is wrong because it refers to a nonexistent command.

10. � A and C. A is correct because the SHOW RECYCLEBIN command only shows the objectsyou can undrop. C is correct because the DBA_RECYCLEBIN view shows all the objects youcan undrop and purge, under the CAN_UNDROP and CAN_PURGE columns, respectively.� B is wrong because the command doesn’t show objects you can purge. D is wrong becausethe DBA_RECYCLEBIN also shows items you can purge.

11. � B. Once you drop a table and it’s in the recycle bin, you can continue to make SELECTstatements against the table (but not the UPDATE, DELETE, and INSERT commands).However, you’ll have to refer to the table by its system-generated name, since there may beseveral tables in the recycle bin with the same original name.� A and C are wrong because you can’t address a table in the recycle bin by its originalname. D is wrong since you can query after you drop it, provided it’s in the recycle bin and youaddress it by its new, system-generated name.

12. � B. When you use the PURGE RECYCLEBIN command (or the PURGE USER_RECYCLEBINcommand), you get rid of all objects owned by the current user.� A is wrong because Oracle removes only the objects owned by the user issuing the PURGE

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:55 PM

Color profile: DisabledComposite Default screen

Page 468: OCA OCP - Oracle10G New Features For Administrators Exam Guide

52 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

RECYCLEBIN command. C is wrong since Oracle removes all objects belonging to the currentuser, not just tables. D is wrong because you must have the SYSDBA privilege only to use thePURGE DBA_RECYCLEBIN command.

Flashback Table

13. � D. You can use the Flashback Table feature to take the table back to a previous point intime. Therefore, it is ideal in situations where you’ve updated a table with the wrong WHEREclause.� A is wrong because when you drop a user (and the user’s objects), you need to flashbackthe entire database. B is wrong because when you truncate a table, you are better offperforming a flashback database operation. C is incorrect since you can use the flashback dropfeature to bring back a table that you’ve accidentally dropped.

14. � A, B, and D. A is correct because you must have the INSERT, DELETE, UPDATE,and ALTER privileges on the table to which you want to apply the Flashback Table feature.B is correct since the FLASHBACK ANY TABLE system privilege enables you to performthe operation on any table in any schema. D is also correct since the FLASHBACK TABLEprivilege on the table you are flashing back is adequate to perform the operation.� C is wrong because you do need special privileges as explained by alternatives A, B, and D.

15. � A. You must enable row movement before you perform a flashback database operationbecause Oracle doesn’t preserve ROWIDs during the operation.� B and C are wrong since you must enable, not disable, row movement. D is wrong sinceOracle doesn’t preserve ROWIDs.

16. � C. If Oracle encounters any constraint violations, it abandons the flashback process andleaves the tables as they were before the start of the operation.� A is wrong because Oracle stops the flashback operation. B is incorrect since Oracle leavesthe table in its original state, not the current state. D is wrong since you don’t have to disable allconstraints before you start the flashback table operation. You may leave them in an enabled state.

Row Level Flashback Features

17. � A. The flashback versions query generates all committed versions of a row.� B is wrong because the query doesn’t produce any uncommitted versions of a row. C and Dare wrong since Oracle will output all the versions of a row.

18. � A and B. The pseudocolumns of a flashback versions query provide information on when arow version was first created (VERSION_STARTSCN and VERSION_STARTTIME columns)and what kind of DML operation took place (the VERSIONS_OPERATION column) amongother things.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:56 PM

Color profile: DisabledComposite Default screen

Page 469: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Lab Answer 53

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

� C and D are wrong since the flashback versions query doesn’t provide any informationabout undoing changes; it is the flashback transaction query that provides you with the undoinformation.

19. � A and D. A is correct since the flashback transaction query feature relies on the FLASHBACK_TRANSACTION_QUERY view. D is correct since you can use the two features together to audittransactions and to correct logical transaction errors.� B is wrong since FLASHBACK_TRANSACTION_QUERY is a view, not a procedure. C iswrong since you can use the two features together.

20. � C. The XID column belongs to the FLASHBACK_TRANSACTION_QUERY, and it mapsto the VERSIONS_XID pseudocolumn output by the flashback versions query select statement.� A, B, and D refer to the wrong source for the XID column and VERSION_XID pseudocolumn.

LAB ANSWERA user drops a table and you should get it back by using the flashback command.

1. First, connect as sysdba, enable the database flashback, and set a retention time of one day.SQL> connect sys/password as sysdbaSQL> alter system set db_flashback_retention_target = 1440; -- Ex: for two days.SQL> alter database flashback on;

2. Next create your table called test_table.

SQL> create table test_table (c1 number, c2 number, c3 varchar2(50));

Create a simple trigger on test_table.

SQL> create or replace trigger test_triggerbefore delete or update or insert ontest_tablebeginnull

end;Add a primary key constraint to your table.

SQL> alter table flashback_tableadd constraint pk1flashback_tableprimary key (c1);

3. Create an index on the name column.

SQL> create index name_idxon test_table(name);

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:56 PM

Color profile: DisabledComposite Default screen

Page 470: OCA OCP - Oracle10G New Features For Administrators Exam Guide

54 Chapter 9: Flashback Technology Enhancements

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9

4. Create a materialized view log on test_table and perform an insert into your table.SQL> create a materialized view log on test_table;SQL> begin

for this in 1..1000 loopinsert into test_table(this, this + 100, ‘Test flashback…’);end loop;commit;end;

5. Display all the objects and constraints that belong to the user.SQL> select object_name, object_type

from user_objects/

SQL> select constraint_name, constraint_type, table_namefrom user_constraints/

6. Now, drop the test table.SQL> drop table test_table flashback cascade;

7. Again, display all the objects and constraints that belong to you. You can see that all the deletedobjects were renamed and still belong to you. Also, notice that Oracle has dropped and renamedall of the table’s constraints as well..

SQL> select object_name, object_typefrom user_objects ;

SQL> select constraint_name, constraint_type, table_namefrom user_constraints;

8. Connect as SYSDBA and use the FLASHBACK TABLE command to recover a table and all itspossible dependent objects from the recycle bin.

SQL> flashback tabletest_table to before drop;

9. Check the contents of your recycle bin.SQL> select original_name, object_name, type, ts_name,

droptime, related, spacefrom dba_recyclebinwhere original_name = ‘TEST_TABLE’;

SQL> flashback table test_table to before drop;

10. Verify that your test_table has been retrieved by using the following statement:SQL> select count(*) from test_table;

Notice that the materialized view log was not flashed back. All the other objects, including theconstraints, were recovered successfully. The flashback procedures can’t recover materialized view logs.

P:\010Comp\CertPrs8\862-4\ch09.vpMonday, August 30, 2004 4:26:56 PM

Color profile: DisabledComposite Default screen

Page 471: OCA OCP - Oracle10G New Features For Administrators Exam Guide

10Automatic Storage

Management

CERTIFICATION OBJECTIVES

10.01 Introduction to AutomaticStorage Management

10.02 Managing the ASM Instance

10.03 Managing ASM Disk Groups

10.04 Managing ASM Files

10.05 Migrating a Database to ASM

✓ Two-Minute Drill

Q&A Self Test

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10Blind Folio 10:1

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:17:59 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 472: OCA OCP - Oracle10G New Features For Administrators Exam Guide

2 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

Automatic Storage Management (ASM) is one of Oracle Database 10g’s most importantand revolutionary enhancements. The Oracle Managed Files (OMF) feature, whichhas Oracle create and name files for you, was introduced a couple of versions ago.

ASM is Oracle’s new feature that lets you finally completely automate your file managementtasks. ASM even enables you to bypass using a third-party Logical Volume Manager, mirroringand striping your disks directly from within Oracle.

This chapter introduces you to ASM by first exploring its architecture. Thechapter then takes you through the details of administering ASM in your database.Administering ASM means managing the ASM instance, disk groups, and ASM files.You’ll also learn how to migrate to an ASM system using the RMAN.

Let’s start with a review of the nature of ASM and its architecture.

CERTIFICATION OBJECTIVE 10.01

Introduction to Automatic Storage ManagementOracle DBAs sometimes maintain hundreds or even thousands of datafiles for each ofthe databases they manage. File and I/O management, in fact, is typically one of thelargest consumers of a DBA’s time. Oracle introduces the new Automatic StorageManagement (ASM) system to simplify your management tasks by automating diskand file management.

Every bit of data you have in Oracle is stored somewhere on a disk. Your job is tohelp retrieve that data from disk as quickly as possible. Disk I/O is much slower thanaccessing data currently in random access memory (RAM), and it often turns outto be the single biggest bottleneck for busy OLTP systems. ASM not only simplifiesdatabase storage administration, but it also optimizes the database storage layout forthe best performance. ASM is built on top of OMF, and it takes OMF much further

than simply having Oracle create and name filesfor you. ASM acts as Oracle’s own Logical VolumeManager (LVM), by handling striping andmirroring functions previously done by third-party tools. DBAs spend a lot of time worryingabout I/O load balancing. ASM has features thatautomatically perform load balancing for you!

You can’t use operatingsystem commands or utilities to accessASM files. You must use the RMAN tocopy ASM files.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:17:59 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 473: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Introduction to Automatic Storage Management 3

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

You don’t need to move to the new ASM system overnight. Instead, you cancontinue using your present file systems and slowly migrate to ASM files over time.Oracle lets you mingle operating system, OMF, and ASM files together in a singledatabase.

Benefits of ASMASM enables you to manage data by selecting the desired reliability and performancecharacteristics for classes of data, rather than interacting with large storage systems ona per-file basis. ASM file systems offer several benefits, including the following:

■ ASM prevents disk fragmentation, so there won’t be any need to performtime-consuming relocation of data.

■ You can keep all your datafiles and tablespaces in an ASM storage system.ASM will manage your datafiles, control files, redo logs, archive logs, RMANbackup sets, and so on. You can manage database objects such as tablespaceswithout needing to specify and track filenames.

■ Your DBA file management duties are simpler, because you’ll be dealing witha few disk groups, instead of directly handling numerous datafiles. Managingvery large databases becomes simple when you use an ASM system.

■ ASM performs mirroring and striping, thus increasing reliability andperformance. Mirroring is applied on a file basis, rather than on a disk basis,thus giving you more control over which files you want to protect.

■ ASM automatically balances I/O load in parallel across all available disk drivesto prevent hot spots and maximize performance. When you add new disks,ASM automatically moves data around to balance I/O load among thedisks. ASM load-balances file activity by uniformly distributing file extentsacross all disks in a disk group. This automatic online disk space reorganizationsaves you plenty of time.

■ ASM helps you maintain redundant copiesof data to provide fault tolerance. If youwish, you can build an ASM storage systemon top of vendor-supplied reliable storagemechanisms.

■ ASM is free! You don’t pay anything extrafor the ASM feature, since it’s part of yourOracle Database 10g Server software.

You can use an ASMstorage system for any Oracle databasefiles, including datafiles, control files,online redo log files, archived redo logs,and RMAN backup sets.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:17:59 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 474: OCA OCP - Oracle10G New Features For Administrators Exam Guide

ASM ArchitectureASM has three important components: the ASM instance, disk groups, and ASMfiles. ASM runs as a tiny enterprise of its own, with its own instance and backgroundprocesses, helping Oracle Database 10g manage its files.

ASM files are at the core of all ASM activity. You use ASM so you can use itsfiles for your database. Unlike in the case of normal Oracle operating system-baseddatabase files, you don’t directly access ASM files. ASM files are part of larger entitiescalled ASM disk groups, which act as the default location for all your database files. Youuse ASM disk groups to get to the ASM files. When you use ASM files, you don’t needto refer to your tablespaces by filenames; you use simple disk group names instead.

You don’t need to change the way you manage your Oracle database when youswitch to an ASM storage system. You can even have your current operating system-based files coexist with new datafiles that you create as ASM files. All your logicalconcepts like extents, segments, and tablespaces remain intact in an ASM system.

Here’s a summary of the basic characteristics of an ASM-based storage system:

■ You can store all Oracle database files as ASM files. There is a one-to-onemapping between an Oracle database file (datafile, control file, and so on)and an ASM file.

■ An ASM disk group consists of a set of disk drives.

■ A database can have multiple disk groups.

■ An ASM disk group can also contain files from several disk groups.

■ An ASM file is always spread over all the disks in an ASM disk group. An ASMfile can belong to only one disk group.

■ ASM allocates disk space in units called allocation units. All ASM disks arepartitioned in allocation units of 1MB.

In order to use an ASM file system, you must first start an ASM instance, whichis somewhat like a small database instance (without its own database files). The ASMinstance manages the disk groups, and its main purpose is to help the database accessthe ASM files. The Oracle database contacts the ASM instance for informationabout the ASM datafiles, and then accesses those files directly on its own. Let’s lookat the ASM instance in detail in the following section.

4 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:17:59 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 475: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing the ASM Instance 5

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

CERTIFICATION OBJECTIVE 10.02

Managing the ASM InstanceBefore you can use the ASM files, you must ensure that the ASM instance is up andrunning. You create an ASM instance just as you would create any other Oracle instance.The big difference is that you have only a handful of initialization parameters to set upfor an ASM instance. In addition, an ASM instance doesn’t mount any Oracle databasefiles. Its main job is to maintain ASM file metadata, so the database can use it to accessthe files directly.

In order to use ASM, you must have an ASM instance running on your server.

Unlike a normal Oracle database,an ASM instance doesn’t have a data dictionary,making it necessary for you to connect only as an administrator, either through operatingsystem authentication as SYSDBA or SYSOPER, or by using a password file, if you’reconnecting remotely.

Here’s a summary of the ASM instance’s functions:

■ Manage disk groups

■ Protect disk groups

■ Communicate file metadata to database instances using the ASM files

Creating an InstanceTo create an ASM instance, you must have the SYSDBA privilege. You can performmost managing tasks (except creating the instance and a few others) with just theSYSOPER privilege. Of course, you must also belong to an operating system group thathas the privileges to connect as a SYSDBA, a group like the typical dba group. If youconnect as a SYSDBA, you’ll have complete administrative privileges in an ASMinstance. If you connect as a user with the SYSOPER privilege, you’ll have the ability

to execute the following commands:

■ STARTUP/SHUTDOWN

■ ALTER DISKGROUP CHECK

■ ALTER DISKGROUP MOUNT/DISMOUNT/REMOUNT

■ ALTER DISKGROUP OFFLINE

You must issue all diskgroup management commands from withinan ASM instance. You database has nodirect connection to ASM disk groups.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:17:59 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 476: OCA OCP - Oracle10G New Features For Administrators Exam Guide

6 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

In addition to the right to execute these commands, a SYSOPER privilege holdercan also use all the data dictionary views associated with an ASM instance. TheSYSDBA privilege lets you perform all the listed commands, as well as the morepowerful CREATE DISKGROUP, ADD DISK, DROP DISK commands and theRESIZE clause in the ALTER DISKGROUP statement..

An ASM instance takes up about 100MB of space. Most ASM instances shouldneed no more than 64MB of SGA.

Initialization Parameters for the ASM InstanceYou must create an initialization parameter file to create a new ASM instance.Fortunately, since the ASM instance doesn’t have its own datafiles and the like,you’ll need to configure only a minimal number of initialization parameters.

If you set only one parameter—INSTANCE_TYPE—correctly (INSTANCE_TYPE=ASM), Oracle will start up the ASM instance with default values for allthe other parameters.

The following are the key initialization parameters that you must configure foryour ASM instance.

■ INSTANCE_TYPE You must set theINSTANCE_TYPE parameter to ASM.

■ DB_UNIQUE_NAME You normally won’tneed to set this parameter, as it applies onlyto ASM within a cluster or on a node. Theparameter shows the unique name for a groupof ASM instances in a cluster or on a node.The default value for this parameter is +ASM.Change this only if you think you’re going tohave more than one ASM instance runningon the same node.

■ ASM_POWER_LIMIT This parameter indicates the maximum speed to beused by this ASM instance during a disk rebalance operation. When you addor delete individual disks, ASM moves around an amount of data equal to thestorage you are adding or reducing from a disk group. ASM does this so it canevenly redistribute the datafiles and balance I/O load across the disks. Thedefault for this parameter is 1, and the range is 1 to 11 (1 is slowest and 11fastest). You have the option of specifying the rebalance speed by using thePOWER clause in the disk REBALANCE command, as in this example:

ALTER DISKGROUP dgroup1 REBALANCE POWER 4;

If you don’t explicitly setthe INSTANCE_TYPE parameter to ASM,your ASM instance will fail to start. Thedefault value for this parameter is RDBMS,which is applicable to normal Oracledatabases.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:17:59 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 477: OCA OCP - Oracle10G New Features For Administrators Exam Guide

■ ASM_DISKSTRING This parameter setsthe disk location for Oracle to consider duringa disk-discovery process. When you add anew disk to a disk group, for example, theASM instance will discover the new disk bylooking up the directories listed in its ASM_DISKSTRING parameter. Thus, by settingthis parameter, you can limit the number of

disks that ASM considers for disk discovery. The default for this parameter isNULL. It can take a list of values, as shown here:

ASM_DISKSTRING =’/dev/rdsk/*s1’, ‘/dev/rdsk/c1*

■ ASM_DISKGROUPS This parameter lets you specify the name of any diskgroup that you want the ASM instance to automatically mount at instancestartup. The default value for this parameter is NULL. If you use an init.oratext file, you must make sure to add the names of any disk groups that youwant to mount when the instance starts up. On the other hand, if you use anSPFILE, Oracle will automatically make the necessary additions and deletionsto the SPFILE when you create, add, or drop a disk group.

The ASM instance uses the LARGE_POOL memory buffer. You should allocateat least 8MB to this parameter, so it can serve the ASM instance effectively.

Creating the ASM InstanceYou can either create the ASM instance manually, or use the DBCA to create it. You cancreate an ASM instance through an init.ora file, just as you can create database instances(see Exercise 10-1). An ASM instance usually requires bout 100MB of disk space.

EXERCISE 10-1

Creating an ASM instanceLet’s create an init.ora file with the five key ASM-related initialization parameters.Here’s our init.ora file:

INSTANCE_TYPE=ASMDB_UNIQUE_NAME= +ASMASM_POWER_LIMIT =1ASM_DISKSTRING = ‘/dev/rdsk/*s1’, /dev/rdsk/c1*’

Managing the ASM Instance 7

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

If you leave the ASM_DISKSTRING parameter set as NULL, ASMwill find all disks to which it has read/writeaccess during a disk-discovery process.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:00 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 478: OCA OCP - Oracle10G New Features For Administrators Exam Guide

ASM_DISKGROUPS = dgroupA, dgroupBLARGE_POOL_SIZE = 16M

Now, export your new ASM instance name and run the following commands:

$ export ORACLE_SID=ASM$ sqlplus /nologSQL> connect / AS sysdbaConnected to an idle instance.SQL> startupASM instance startedTotal System Global Area 147936196 bytesFixed Size 324548 bytesVariable Size 96468992 bytesDatabase Buffers 50331648 bytesRedo Buffers 811008 bytesASM diskgroups mounted

Using the Database Configuration Assistant (DBCA) makes it very easy to createan ASM instance. When you create a new Oracle database, as shown in Figure 10-1,the DBCA offers you three storage options: file systems, raw devices, and ASM.

If you choose file systems or raw devices for storage, and you decide to use an ASMfile system later on, you’ll need to separately create your own ASM instance. However,if you choose ASM for storage, the DBCA will check to see if an ASM instance areadyexists on your server. If it does, the DBCA will then show you the disk groups beingmanaged by that ASM instance and ask you to choose the disk groups for your newOracle database.

If you choose ASM as your storage mechanism and you haven’t already configuredan ASM instance, the DBCA will automatically create one for you, after asking youto provide a username and password for the separate SYS user for the ASM instance(you’ll need this for remote database access).

The DBCA automatically creates an entry in the oratab file on UNIX systems, sothe operating sytem is aware of the new instance. On Windows systems, the DBCAcreates the Oracle service and makes the appropriate Windows Registry entries. TheDBCA also creates a parameter file and a password file for the new ASM instance.

ASM Instance ArchitectureAn ASM instance has several background processes like the SMON, PMON, andLGWR processes. In addition, there are two new background processes: ASM Rebalance

8 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:00 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 479: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing the ASM Instance 9

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

Master (RBAL) and ASM Rebalance (ARBn). Here’s what the two backgroundprocesses do:

■ The RBAL process is in charge of coordinating disk activity.

■ The ARBn processes (there could be several of these, like ARB0, ARB1, andso on) perform the actual rebalancing work like moving the data extents around.

In addition to the ASM instance background processes RBAL and ARBO, anyOracle database instance that uses an ASM instance will have two new ASM-relatedbackground processes, the RBAL and the ASM Background (ASMB) processes. Thisis what these two new database processes do:

■ The RBAL process performs global opens of the disks in the ASM disk groups.

■ The ASMB background process connects as a foreground process into your ASMinstance. Remember that the ASM instance must be in operation in order for

FIGURE 10-1 Using the DBCA to configure ASM during database creation

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:00 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 480: OCA OCP - Oracle10G New Features For Administrators Exam Guide

10 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

your database to access ASM files. The ASMBprocess acts as the link between the ASMinstance and your database instance,communicating information like datafilecreation, deletion, updating statistics, andperforming instance health checks.

Managing an ASM InstanceYou can use the OEM Database Control to manage all aspects of the ASM instance. Thehome page of the Database Control shows the status of your ASM instance. From theASM home page, you can click the Configuration tab to go the ASM Configurationpage, where, you can modify your current ASM instance parameters. You can also goto the Automatic Storage Management home page and check on ASM instanceperformance issues, like I/O response time and throughput for the disk groups beingmanaged by your ASM instance.

You can also use manual commands to start up and shut down the ASM instance.Let’s review the startup and shutdown procedures for ASM instances in the followingsections.

Starting an ASM InstanceThe STARTUP command for an ASM instance is quite similar to the STARTUPcommand for your Oracle databases, with a couple of interesting differences. Make

sure you set the INSTANCE_TYPE parameterto ASM, so Oracle knows it is an ASM instance,not a regular Oracle database.

During the mount phase of the normal OracleSTARTUP command, an Oracle database readsthe control file and mounts the file systemsspecified in the control file. An ASM instancedoesn’t have any file systems to mount. Rather,an ASM instance mounts the disk groups

The ASM Rebalance(ARBn) process performs the actualdisk rebalancing work.

Oracle databases expectthe ASM instance to be always running, sothey can access the ASM files. You shouldset up automatic startup procedures for

ASM instances following a host bootup.In Windows, for example, you should makethe ASM instance an automatically startedservice.

When starting an ASMinstance, you can use the STARTUPcommand with the NOMOUNT, MOUNT,RESTRICT and FORCE options.Youcan’t use the STARTUP OPEN syntax.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:00 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 481: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing the ASM Instance 11

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

specified by the initialization parameter ASM_DISKGROUPS. The NOMOUNT commandworks in an analogous way to the way it works in regular Oracle databases: it startsthe ASM instance without mounting any disk groups.

When you issue a STARTUP FORCE command, the ASM instance is shut downwith a STARTUP ABORT command before restarting it. If you use the STARTUPRESTRICT command, it prevents any client Oracle database instances from connectingto the ASM instance.

Shutting Down an InstanceYou shut down an ASM instance just as you would shut down a normal Oracle database.Here’s an example:

$ sqlplus /nologSQL> connect / AS sysdbaConnected.SQL> shutdown normalOn the Job: If the ASM instance fails, thedatabase instances connected to it will also shut down. However,the reverse isn’t true; the failure of a database instance hasno impact on an ASM instance.

There are some caveats, however, in using the SHUTDOWN command in the caseof an ASM instance. The up and down status of all Oracle databases connected toan ASM instance critically depend on the ASM instance’s status. If you shut down anASM instance, all Oracle databases currently connected to it will also shut down. Whenyou issue a SHUTDOWN command to an ASM instance, it forwards the SHUTDOWN

In order to use theASM feature, you must have your ASMinstance running. This, however, meansthat you just start the ASM instance in

the MOUNT mode. There are no datafilesto open in an ASM instance, so you don’tuse the OPEN option for the STARTUPcommand.

If you either start up yourASM instance with the STARTUP RESTRICTcommand or issue the ALTER SYSTEM

ENABLE RESTRICTED SESSION commandin a normal ASM instance, Oracle databaseinstances can’t connect to the ASM instance.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:00 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 482: OCA OCP - Oracle10G New Features For Administrators Exam Guide

12 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

command, in the same mode, to the Oracle databases that are connected to the ASMinstance.

If you shut down an ASM instance in the NORMAL mode (use the SHUTDOWNNORMAL command or just the SHUTDOWN command), the ASM instance waits forall connected Oracle database instances to terminate their ASM connections beforeshutting down. In the IMMEDIATE (and TRANSACTIONAL) mode, an ASM instancewaits until all currently executing SQL in the dependent databases completes, butdoesn’t wait for the database instances to disconnect.

If you issue the SHUTDOWN ABORT command, the following events occur:

■ The ASM instance instantly aborts.

■ All open connections to the ASM instances are terminated.

■ As a result of connections to the ASM terminating, all dependent Oracledatabases will terminate immediately.

CERTIFICATION OBJECTIVE 10.03

Managing ASM Disk GroupsAn ASM disk group is a collection of disks that is somewhat analogous to the logicalvolumes created by an LVM from underlying physical disks. You manage the underlyingdisks of a disk group indirectly, by managing the disk group. Thus, even if you have alarge number of disks, you can aggregate them into a very small number of disk groups,which makes life easy for you. When you add storage to your ASM system, you simplyadd disks to an ASM disk group. Therefore, if your database is growing at a fast rate,

When an Oracle databaseuses ASM files by connecting to an ASMinstance, it will stay open only as longas its connection to the ASM instance isintact. If the connection terminates, theOracle instance will terminate as well. AnySHUTDOWN command you use in the ASM

instance will also apply, in the same mode,to all connected databases. For example,if you shut down the ASM instance with |the SHUTDOWN IMMEDIATE comamnd,all databases connected to that instancewill also shut down in the SHUTDOWNIMMEDIATE mode.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:00 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 483: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing ASM Disk Groups 13

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

the total stoarge will increase, but the number of disk groups could remain at a small,stable number.

Providing Performance and Redundancy with Disk GroupsOne of the biggest selling points in switching to ASM file management for Oracledatabases is that it offers you both additional performance and protection, while decreasingthe management overhead, especially for large, mission-critical databases. These benefitsare similar to the benefits offered by LVM tools provided by third-party vendors. However,the big advantage of ASM over the third-party tools is that the Oracle DBA can takeover most of the disk management tasks when using an ASM-based storage system.

You don’t need to be an expert in file sytems, RAID, or logical volumes to use ASMfiles in your database. If you understand how ASM manages disk groups and how Oracleaccesses the database files that are spread over the the ASM disks, you are ready touse ASM.

ASM can perform both striping and mirroring tasks better than a third-partyLVM, because it understands the Oracle file types and uses an appropriatestrategy for each type.

ASM provides both performance and redundancy, the first through striping andthe second through the mirroring of data on the disk drives. Let’s look at these twofeatures in the following sections.

ASM StripingASM systems use disk groups and disks, with your database files being stored on the ASMdisks. The way you place (or write) your database files over ASM disks plays a criticalrole in determining I/O performance. To provide you with optimal I/O performance,ASM stripes files across all the disks that are part of a disk group. For performance reasons,you must use disks of the same type and performance capacity in a disk group.

ASM provides two types of data striping, depending on the database file type:

■ Coarse striping The most common striping scheme in an ASM system iscoarse striping, so called because the stripe size is a relatively large 1MB chunkof file space. You may use coarse striping for all files in an Oracle database,except the control files, online redo log files, and flashback files.

■ Fine striping Some of your database files, like redo log files, may need fasteraccess than others. To reduce file latency, ASM provides a fine striping scheme,where the striping is in smaller chunk sizes of 128KB. If you have 20 disks inyour disk group, ASM would stripe your redo logs in 128KB sized chunks across

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:00 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 484: OCA OCP - Oracle10G New Features For Administrators Exam Guide

all 20 of the disks. Thus, when you perform I/O operations, you can access yourfile data in parallel, thus improving performance. You may want to use finestriping for control files, online redo log files, and flashback files.

ASM MirroringDisk mirroring provides data redundancy. If you lose a disk, you can use its mirror diskto continue operations without missing a beat. ASM mirroring is not the same as anoperating sytem-level mirroring scheme, although the goal of both is to provideredundancy. Operating system-based LVMs mirror entire disks. ASM mirrors extents.Whenever ASM allocates an extent (also called the primary extent, as opposed to amirrored extent), it simultaneously allocates a mirror copy of the extent to one of thedisks in the same disk group. A disk could have its mirror extents on one or several disksin the disk group.

When any disk in a disk group fails, ASM reconstructs the failed disk on the fly byusing the mirrored extents from the other disks in the disk group. What’s the advantageto mirroring extents rather than mirroring disks? When ASM is reconstructing a lostdisk, your storage system will take a smaller I/O hit, because several disks are sharingthe I/O necessary to reconstruct the failed disk device.

Failure Groups You can lose the services of a disk not only when the disk drivefails, but also if a shared resource such as a disk controller bites the dust. When aSCSI disk controller fails, all the disks connected to it will be inaccessible. A set ofdisks that can all fail because they share a common resource, is called a failure group.When you are trying to protect your data by introducing redundancy, you do so onthe basis of failure groups. That is, if you want to ensure that you have redundancy,you must store your mirrored copy in a separate failure group.

ASM never places a primary extent and its mirror copy in the same failure group.Thus, even if you lose several disks in a failure group, ASM can survive the disaster,by starting the reconstruction of the lost devices from the mirrored copies of theirextents from disks that are outside the disk’s failure group.

Types of ASM Mirroring ASM supports three types of disk mirroring, eachproviding a different level of data redundancy. When you create a new ASM diskgroup, you need to decide the level of disk mirroring you need:

■ External redundancy This type really doesn’t provide any mirroring. Youchoose this level of mirroring when you are using operating system storage

14 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:01 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 485: OCA OCP - Oracle10G New Features For Administrators Exam Guide

array protection. Disk groups under this redundancy level don’t have anyfailure groups.

■ Normal redundancy This type provides two-way mirroring. Since you mirrorthrough the creation of failure groups, you must have two failure groups, eachgroup relying on a separate disk controller. Two-way mirroring means thatwhen one copy of a file extent is written to a disk in failure group Group A,a mirrored copy of the file extent is simultaneously written to a disk in failuregroup Group B. Thus, to support a normal redundancy level, you must createat least two failure groups.

■ High redundancy This type provides three-way mirroring, which means youshould have three failure groups, each controlled by a separate disk controller.When one copy of a file extent is written to a disk in failure group Group A,a mirrored copy of the file extent is simultaneously written to both a disk inGroup B and a disk in Group C. Thus, to support a normal redundancy level,you must create at least three failure groups.

Creating a Disk GroupThe easiest way to create a disk group is to use the Databae Control’s Disk GroupAdminstration page. You can select the redundancy level, disk group name, and thelist of disks that you want to be part of a disk group.

You can also create a disk group manually by using the CREATE DISKGROUPcommand. For example, suppose that you have three SCSI disk controllers and a totalof twelve disks. Disks Diska1 through Diska4 are on a separate SCSI controller fromdisks Diskb1 through Diskb4. Similarly, disks Diskc1 through Diskc4 are on yet anotherdisk controller. You can create three failure groups, each with four disks. The firstfour disks, Diska1–a4, will be on disk controller 1; the second four disks, Diskb1–b4, willbe on disk controller 2; and the last four disks, Diskc1–c4, will be on disk controller 3.

First, start the ASM instance in the NOMOUNT mode. (If you want to accesspreviously created diskgroups, you must use the MOUNT mode.) If none exists, theinstance is ready for you to create a disk group now. Then you can create yourthree disk groups to correspond with your three failure groups, using the CREATEDISKGROUP command, as shown here:

% sqlplus /nologSQL> connect / as sysdbaConnected to an idle instance.SQL> startup nomount

Managing ASM Disk Groups 15

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:01 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 486: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SQL> create diskgroup test_group1 high redundancy 2 failgroup groupA disk3 ‘/devices/diska1’,4 ‘/devices/diska2’,5 ‘/devices/diska3’,6 '/devices/diska4',7 failgroup groupB disk8 '/devices/diskb1',9 '/devices/diskb2',

10 '/devices/diskb3',11 '/devices/diskb4';12 failgroup groupC disk13 ‘/devices/diskc1’,14 ‘/devices/diskc2’,15 ‘/devices/diskc3’,16 ‘/devices/diskc4’,

Oracle uses the search string of the format /devices/diska1 to find the diskson your system. The use of the FAILGROUP and REDUNDANCY keywords is purelyoptional. If you don’t specify the FAILGROUP keyword, each disk in the disk groupwill be in its own failure group.

Here are the implications of using the HIGH REDUNDACY setting for the newdisk group, test_group1:

■ There are three failure groups, each defined by the FAILGROUP keyword(you must have at least three failure groups if you specify high redundancy).

■ Each of the failure groups has four disks.

■ When Oracle writes data to the disks in the first failure group, GroupA, italso writes those extents to disks in the other two failure groups, GroupBand GroupC.

16 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

When you create a new diskgroup, ASM will automatically mount it.Don’t forget to add the diskgroup’s name toyour init.ora text file, if you don’t alreadyhave it there when you start the databasein the NOMOUNT mode. If you put the name

of the disk group in the inita.ora file, Oraclewill automatically mount it the next timeyou start the instance. Of course, if you’reusing an SPFILE instead, Oracle willautomatically write the new disk group’sname in the SPFILE.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:01 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 487: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing ASM Disk Groups 17

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

EXERCISE 10-2

Create a Disk GroupCreate a disk group with two disk groups with normal redundancy. Notice the twofailure groups that this level of redundancy implies.

SQL> create diskgroup dgroup1 normal redundancyfailgroup controller1 disk‘/dev/rdsk/c0t0d0s2’ name testdisk size 100G,‘/dev/rdsk/c0t1d0s2’,‘/dev/rdsk/c0t2d0s2’failgroup controller2 disk‘/dev/rdsk/c1t0d0s2’,‘/dev/rdsk/c1t1d0s2’,‘/dev/rdsk/c1t2d0s2’;

Adding Disks to a Disk GroupYou use the ALTER DISKGROUP command to add a new disk to a disk group, asshown here:

SQL> alter diskgroup test_group1 add disk'/devices/diska5' name diska5,'/devices/diska6' name diska6,

There are two interesting points to note in this example:

■ There is neither a FAILGROUP nor a REDUNDANCY specification for thetwo new files. When you don’t specify a failure group for a disk, the disk is inits own failure group.

■ There is a new NAME clause in this example. In the previous example, therewas no NAME clause. There, Oracle would assign its own system-generatednames.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:01 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 488: OCA OCP - Oracle10G New Features For Administrators Exam Guide

18 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

Dropping Disks and Disk GroupsYou use the ALTER DISKGROUP command to drop a disk from a disk group, asshown here:

SQL> alter diskgroup test_group1 drop disk diska5;

You can use the UNDROP clause to keep a pending DROP DISK command fromtaking place. If you’ve already dropped the disk, you can’t retrieve it with the UNDROPclause. If you’ve used the optional FORCE clause when you dropped a disk, or if you’veissued a DROP DISKGROUP command, you can’t use the UNDROP clause. Here’s anexample demonstrating how to use the UNDROP clause in an ALTER DISKGROUPcommand:

SQL> alter diskgroup test_group1 undrop disks;

This command will cancel the pending drop of all disks from the disk group test_group1.In order to remove an entire disk group, you use the following command, after

putting the database in the MOUNT state.

SQL> drop diskgroup test_groupA including contents;

Rebalancing Disk GroupsOne of the perennial concerns for a DBA is the existence of hot spots in the disk system,which may lead to I/O bottlenecks. ASM rebalances a disk group automatically anddynamically, whenever you add or remove a disk from a disk group. ASM strives for aconstant I/O balance across all the disks in a disk group. Thus, when you add new disksor remove some disks, this I/O balance is disturbed, but ASM sets it right automatically.It does this by simply moving just enough data around to match the space you addedor removed. For example, if you add a 14GB size disk, ASM will reassign only 14GBof datafiles to rebalance the disk group.

Since there is some I/O impact on your system during disk group rebalancingoperations, you may be better off consolidating your disk add and remove operations,so ASM needs to perform fewer rebalancing operations. Here’s an example of the diskrebalancing command:

SQL> alter diskgroup dgroup1 rebalance power 5;

The POWER clause specifes the parallelization level for the REBALANCE command.In other words, the POWER clause controls the speed of a rebalance operation. Thehigher the POWER clause value, the faster ASM will complete the disk rebalancingoperation. The default for POWER is 1 (the default value for the ASM_POWER_LIMIT

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:01 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 489: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing ASM Files 19

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

parameter). By specifying the POWER clause in a REBALANCE command, you canoverride the power value set by the ASM_POWER_LIMIT initialization parameter.

CERTIFICATION OBJECTIVE 10.04

Managing ASM FilesASM doesn’t create any datafiles like the datafiles you create when using operatingsystem files. When you use ASM file management, any datafile you create will becomean ASM file. You simply specify an ASM disk group, instead of a file or disk, when youwant to create a new datafile, redo log file, or control file. For example, you may createa new tablespace called test_tbsp with the following command, if you’re using ASMdisk groups:

SQL> create tablespace test_tbsp datafile ‘+test_group1’;

You can’t use ASM to create alert, trace, binary, and password files.

In the previous command, the DATAFILE clause specifies a file type, indicatingthat the file is going to be used as a datafile (rather than as a control file or onlineredo log file, for example). The CREATE TABLESPACE command addresses a diskgroup (test_group1), not a specific disk in the group. Indeed, there is no referenceto any specific datafile either.

ASM does create a datafile, but it is meaningless to compare it with datafiles thatyou now use in your Oracle databases. The new ASM datafile will be spread over all thedisks in the disk group test_group1. Thus, you can’t back up a single disk to copythe datafile. Unlike conventional database files, Oracle always creates every ASM filewith a specfic redundancy level and striping policy. These redundancy and stripingpolicies are set permanently for the files, and you specify the attributes when you createdisk groups, as you’ve seen earlier in this chapter.

You can increase the speedof a rebalancing operation, and thus minimizethe I/O impact of modifying ASM storage (byadding or deleting disks), by doing any of thefollowing things: raising the value of the ASM_

POWER_LIMIT initialization parameter; usinga high value for the POWER clause in a diskrebalance operation; or performing all yourdisk adding, resizing, and dropping operationsat the same time.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:01 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 490: OCA OCP - Oracle10G New Features For Administrators Exam Guide

20 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

All ASM files are OMF files, and Oracle will automatically delete them when youdon’t need them any longer. However, if you specify a user alias for an ASM file, thatfile in’t considered an OMF file, so Oracle can’t automatically delete that file.

Let’s look at some special ASM file management issues in the following sections.

Types of ASM FilenamesIn an ASM file system, you never need to know a filename when assigning that fileto a tablespace or some other object. You just refer to a disk group—that’s it! ASMautomatically generates the filenames. When you use ASM for an Oracle database file,the operating system can’t see these files, but the RMAN and Oracle’s other tools canview them.

To administer the files, you don’t need to know their individual names; you justneed to know the name of the disk group that contains the file. Of course, if you issuea command like ALTER DATABASE BACKUP CONTROLFILE TO TRACE, you’ll seethe actual name of the ASM files in the output. If ASM uses a fully qualified name fora datafile, you can see it in views like V$DATAFILE and V$LOGFILE.

You can’t use an ASM file system for administrative files like trace files, auditfiles, alert logs, backup files, export files, tar files, and core files. Oracle storesthe ASM filenames in the control files and the RMAN recovery catalog, just asit does with regular operating system-based files or OMF-based files.

You can name an ASM file in several ways, depending on whether you are creatinga file or referencing an already existing file. The naming convention may also dependon whether you creating a single files or multiple files at once. The four main ASMfilenaming conventions are fully qualified ASM filenames, numeric ASM filenames,alias ASM filenames, and incomplete ASM filenames. Here is an overview of howthey work:

■ You use fully qualified ASM filenames only for referencing existing ASM files.

Any database files thatyou create by providing a user alias aren’tautomatically deleted by ASM (when Oracle

considers them ready for deletion), since theyaren’t deemed OMF files. Only files createdby ASM will be automatically deleted.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:01 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 491: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing ASM Files 21

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

■ You use numeric ASM filenames only for referencing existing ASM files.

■ You use alias ASM filenames for creating new ASM files, as well as referringto existing ASM files. You use alias filenames with templates only for creatingnew ASM files.

■ You use incomplete filenames (with or without an alias) only for file creationoperations.

The following sections describe the filename types in more detail.

Fully Qualified ASM FilenamesWhen ASM creates a file, it always uses a fully qualified filename. You use this fullyqualified name for referencing existing ASM files. Here’s the syntax of an ASM file usinga fully qualified filename:

+group/dbname/file_type/tag.file.incarnation

where:

■ group is the disk group name.

■ dbname is the name of the database to which the Oracle file belongs.

■ file_type shows the ASM file type, which maps to an Oracle file type. Forexample, the ASM file type controlfile maps to an Oracle control file.Similary, the ASM datafile and online_log file types map to Oracledatafiles and online redo logs, respectively.

■ tag is type-specific information about the file, such as the tablespace name fora datafile. A control file, for example, is mapped to the ASM tag CF (or BCF,if it’s a backup control file). A datafile’s tag is always of the format ts_name>_<file#>. An online redo log is mapped to the tag log_<thread#>.

■ file.incarnation is the file/incarnation number pair, used to ensureuniqueness.

You can’t supply a fully qualified ASM filename while creating a new file.

Here’s an example of a fully qualified ASM filename:

+dgroup1/proddb/controlfile/CF.257.1

Realize that no matter what naming convention you use for an ASM file, Oracle willalways automatically generate a fully qualified ASM filename when you create a file.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:01 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 492: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Oracle also refers to a fully qualified ASM filename as a system alias. This isbecause ASM will create and maintain these aliases, and you can’t modify them.

Numeric ASM FilenamesASM derives numeric filenames from fully qualified ASM filenames and uses them torefer to existing files. ASM doesn’t use numeric filenames in file creation and doesn’tuse these names while reporting file information to you. However, you can use theseabridged names to refer to any file. Here’s the form of a numeric filename:

+group.file.incarnation

Here is an example of a numeric ASM filename (the file number is 251 and theincarnation number is 8675309).

+dgroup2.251.8675309

Alias ASM FilenamesYou can use ASM alias files both when creating new ASM files and when referring toexisting files. The only thing common to alias ASM filenames and the previous two

types of ASM filenames is the disk group name.In an alias ASM filename, once you first providethe disk group name, you can provide your ownname string to complete the filename. You caneasily tell an alias ASM filename from thepreviously defined filenaming conventionsbecause there aren’t any dotted pairs of numbersat the end of an alias ASM filename. Here’s anexample of an alias ASM filename:

+dgroup1/myfiles/control_file1+dgroup2/mydir/second.dbf

Incomplete ASM FilenamesYou can use an incomplete ASM filename only when creating files. Incomplete filenamesinclude just the group name and nothing else. Here’s an example of an incomplete ASMfilename:

+dgroup1

22 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

Make sure you understandthat alias ASM filenames mean that thefiles aren’t OMF-managed files. Thus, Oraclewon’t automatically remove these files whenit doesn’t have any further need for them.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:01 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 493: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You may also use a template while using an incomplete ASM filename, as shownin the following example.

+dgroup1(datafile)

In this example, the template, DATAFILE, is within the parentheses.

A template determines the attributes to be applied to a file when you createa new file.

Alias Filename ManagementWhen you review the ASM files later in this chapter, you’ll see how Oracle automaticallygenerates fully qualified names for all the ASM files you create in your database. AliasASM filenames provide the capability to employ user-friendly filenames to substitutefor the cryptic system-generated filenames.

Creating Disk Group Directories for Alias FilenamesOracle maintains a hierarchical directory structure for all the fully qualified filenamesin each disk group (along with any file aliases you may create, as shown later in thischapter). If you intend to use alias ASM filenames, you must first create a directorystructure to support your alias filenaming conventions. For example, the followingstatement creates a hierarchical directory for disk group dgroup1.

alter diskgroup dgroup1 add directory '+dgroup1/mydir';

Once you create the directory dgroup1/mydir as shown in the example, you can useit to create alias ASM filenames, such as +dgroup1/mydir/control_file1for a control file.

Managing ASM Files 23

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

When you use an incompleteASM filename, the use of a template isoptional. However, if you omit the template,ASM will use the default system templatefor that file type to decide the redundancy

and striping characteristics for that file. Forexample, when creating a datafile for atablespace, ASM will use the default templatefor a datafile file type if you don’t providea specific template in the filename.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:02 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 494: OCA OCP - Oracle10G New Features For Administrators Exam Guide

24 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

Using Templates with AliasesYou can also use a template to create an alias ASM filename. You can use template-basedASM filenames only for creating new files. Here’s the syntax of a template-based alias ASMfilename:

dgroup(template_name)/alias

Here’s an example of an alias ASM filename with a template (where the templatename is SPFILE):

+dgroup1(spfile)/config1

Adding AliasesIf you don’t use an alias for a file at the file creation time, you can always modify afilename later to add an alias for the file. You can add a filename alias or rename anexisting alias name, using the ADD ALIAS or RENAME ALIAS clause of the ALTERDISKGROUP statement. Here’s an example that shows how you can replace a fullyqualified ASM filename with your own alias ASM filename:

alter diskgroup dgroup1 add alias '+dgroup1/mydir/second.dbf'for '+dgroupA/sample/datafile/mytable.342.3';

You can also delete an alias by using the DROP ALIAS clause of the ALTERDISKGROUP statement.

Dropping Files and Aliases from a Disk GroupAlthough ASM files are usually OMF files, there may be times when you use your ownaliases for some ASM files. As mentioned earlier, if you use your own aliases for ASMfiles, those files won’t be automatically deleted by Oracle. In situations like this, you’llthen need to use the DROP FILE command to drop those files and aliases.

Here is an example of dropping an alias name:

alter diskgroup dgroup1 drop file '+dgroup1/payroll/compensation.dbf';

The following is an example of using a system-generated filename to drop adatafile:

alter diskgroup dgroup1drop file '+dgroupA/sample/datafile/mytable.342.372642';

If you just drop a file alias, Oracle won’t drop the file. If you drop a file usingthe DROP FILE command, however, Oracle drops both the file and its alias.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:02 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 495: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Managing ASM Files 25

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

ASM Filename UsageYou have seen how you can use several forms of ASM filenames. You’ve also learnedhow you can use different filenames for the same file. When do you use a particular formof a filename? The correct form of the ASM filename you should use depends on thecontext in which you are using the filename. Here’s a brief summary of when you shoulduse a particular type of ASM filename:

■ For referring to an existing file, you can use a fully qualified filename, a numericfilename, or an alias filename (but not an alias name with a template or anincomplete filename with or without a template).

■ For creating a single file, you can use any kind of filename, with the exceptionof a fully qualified filename.

■ For creating multiple files, you use only an incomplete filename or an incompletefilename with a template.

Since the very purpose in using ASM is to eliminate the need to specify filenameswhen managing database files, you must avoid using the ASM filenames as much aspossible, even though most SQL commands will let you use them just like normalfilenames. For example, when you re-create a control file with the RESETLOGS option,you may use the ASM filenames, as shown in the following example:

create controlfile reuse database "TEST" resetlogs archivelogmaxlogfiles 16maxlogmembers 2maxdatafiles 30maxinstances 1maxloghistory 226

logfilegroup 1 ('+DGROUP1','+DGROUP2') size 100M,group 2 ('+DGROUP1','+DGROUP2') size 100M

datafile'+DGROUP1/db/datafile/system.260.3' size 500M,'+DGROUP1/db/datafile/sysaux.259.3' size 500M

In the previous example, note that the datafiles already exist, so you can usethe fully qualified ASM filenames for the datafiles. As you know, fully qualified ASMfilenames can’t be used to create an ASM file—they can be used only to refer toASM files. The RESETLOGS option will re-create (reinitialize) the redo log files, soyou can use the incomplete ASM filename format for the redo log files. You can useincomplete filenames only to create new ASM files, as shown earlier in this chapter.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:02 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 496: OCA OCP - Oracle10G New Features For Administrators Exam Guide

ASM File TemplatesYou can’t create all ASM files with the same file attributes. File attributes in this contextrefer to attributes like the redundancy level (external, normal, or high) and the stripingformat (fine or coarse). For example, ideally, the file attributes of an online redo logfile must be different from those of datafiles. Oracle makes it easy for you to specify fileattributes by letting you use templates to specify the attributes when you are creatingfiles. These templates are applied to the individual files, but they are associated withthe disk group in which the files are created.

Whenever you create a disk group, Oracle establishes a set of initial system defaulttemplates for that disk group. Each of the system templates will contain a set of specificfile attributes. When you create files under this disk group, you can choose from amongthese Oracle-provided system templates. Table 10-1 shows some system templates andthe file attributes they imply.

An example will make the use of ASM file templates clear. Let’s say you wantto create a new tablespace called test_tbsp in an ASM file system. You know thatthe tablespace will use datafiles (not online logs or control files). You thus use theDATAFILE template for your tablespace:

SQL> create tablespace test_tbsp datafile ‘+test_group1’;

Your tablespace datafile will then inherit the default attributes of a DATAFILEtemplate (such as the coarse striping level).

You may alter the attributes of a default system template or create you own uniquetemplates, if you wish. However, you may not delete the default system templates.

The following example shows how you can create your template, calledPRODUCTION, using the ALTER DISKGROUP command.

SQL> alter diskgroup test_group1 add template production attributes (mirror fine)

26 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

TemplateName File Type

ExternalRedundancy

NormalRedundancy

HighRedundancy Striped

CONTROL Control files Unprotected 2-way mirror 3-way mirror Fine

DATAFILE Datafiles and copies Unprotected 2-way mirror 3-way mirror Coarse

ONLINELOG Online logs Unprotected 2-way mirror 3-way mirror Fine

ARCHIVELOG Archive logs Unprotected 2-way mirror 3-way mirror Coarse

TABLE 10-1 ASM Default File Group Templates

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:02 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 497: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Migrating a Database to ASM 27

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

Once you create the production template, you can create an ASM datafile usingthat template. The datafile you create will inherit the attributes you specified for yournew PRODUCTION template (two-way mirroring and fine striping). Here’s how youwould create your new datafile using the PRODUCTION template (the disk grouptest_group1 creates files based on the PRODUCTION template):

SQL> create tablespace test_tbsp2 datafile ‘+test_group1’;

If you want to drop a template, you may do so with the following command:

SQL> alter diskgroup test_group1 drop template production;

CERTIFICATION OBJECTIVE 10.05

Migrating a Database to ASMMigrating your database to an ASM disk group-based storage system database is one ofthe Oracle Database 10g upgrade certification objectives. Before we get to the actualdatabase migration procedures, let’s look at the necessary ASM-related initializationparameter changes.

Setting Instance ParametersYou need to focus on the following initialization parameters when you create an ASM-based Oracle database:

■ INSTANCE_TYPE When you create the ASM instance, the INSTANCE_TYPE parameter is set to ASM. However, for normal databases, you can eitherset this to RDBMS or leave it out, since the default value for this parameter isRDBMS.

A template’s mainfunction is to simplify ASM file creation.Templates are associated with a diskgroup, but they are applied to individualfiles. You can’t change a files’s attributes

once you create it using a certaintemplate. If you wish to change an ASMfile’s attributes, you must use the RMANto copy the file into a new file with theattributes you want.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:02 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 498: OCA OCP - Oracle10G New Features For Administrators Exam Guide

28 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

■ DB_BLOCK_SIZE The value of the DB_BLOCK_SIZE parameter must beset to one of the standard block sizes: 2KB, 4KB, 8KB, 16KB, or 32KB.

■ LOG_ARCHIVE_FORMAT If you set the LOG_ARCHIVE_FORMAT to anincomplete ASM filename (such as +dgroupA), Oracle will ignore it. If youset it to an ASM directory, Oracle will use the directory and create non-OMFfiles in that directory.

You must use incomplete ASM filenames (or incomplete ASM filenames witha template) as the destination for the following initialization parameters:

■ DB_CREATE_FILE_DEST_n

■ DB_CREATE_FILE_DEST

■ DB_RECOVERY_FILE_DEST

■ CONTROL_FILES

■ LOG_ARCHIVE_DEST_n

■ LOG_ARCHIVE_DEST

■ STANDBY_ARCHIVE_DEST

Creating an ASM-Based DatabaseBy specifying the following parameters, you can create an ASM disk group-based Oracledatabase:

DB_CREATE_FILE_DEST = '+dgroup1'DB_RECOVERY_FILE_DEST = '+dgroup2'DB_RECOVERY_FILE_DEST_SIZE = 100G

The database creation statement is very simple, as shown here:

SQL> CREATE DATABASE test;

Oracle will create a SYSTEM tablespace and a SYSAUX tablespace in the diskgroup dgroup1. An undo tablespace will also be created in dgroup1, if you’ve configuredautomatic undo space management. A multiplexed redo file log group and a controlfile will be created in both group1 and group2.

Adding datafiles is very easy in an ASM-based Oracle database, since you don’tneed to specify the datafiles. In the test database, you can use the following commandsto create a tablespace and add a new redo log file, respectively:

create tablespace test_tbsp;alter database add logfile;

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:02 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 499: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Migrating Your Database to ASMThe RMAN can help you migrate your current database to an ASM storage system. Ifyou want to migrate your current database to ASM disk groups, you may do so by usingthe following steps (this example uses an SPFILE):

1. Shut down the database in a consistent mode (not SHUTDOWN ABORT).

2. Make the necessary changes to your SPFILE, so your database can use OMFfiles. Set the OMF destinations for the initialization parameter you reviewed inthe previous section to their appropriate ASM destinations (ASM disk groups).

3. Delete the control file parameter from your SPFILE, since Oracle willautomatically create new control files by restoring them from the non-ASMinstance control files.

4. Start up the database using the command STARTUP NOMOUNT, and thenexecute the following commands (as an RMAN script):

restore controlfile from ‘/u01/test/c1.ctl’;alter database mount;backup as copy database format ‘+dgroup1’;switch database to copy;

SQL “alter database rename ‘/u01/test/log1’ to ‘+dgroup1’ “; -- foreach redo log member

SQL> “alter database open resetlogs”;SQL ”alter tablespace temp add tempfile” –- for each temporary tablespaceSQL “alter database tempfile ‘/u01/temp1’ drop”;

5. The RMAN script will back up the database and switch current datafilesto the backups. The script also renames all current online redo log filesand re-creates all temporary files for the temporary tablespace.

6. Delete all the old Oracle database files.

Migrating a Database to ASM 29

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

When you migrate to anASM database, Oracle will automaticallycreate the control files for you. Oracle will

rename the existing redo log files andre-create all the temporary files forthe temporary tablespace.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:02 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 500: OCA OCP - Oracle10G New Features For Administrators Exam Guide

30 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

Using the Data Dictionary to Manage ASMThere are several new data dictionary views in Oracle 10g to help you manageAutomatic Storage Mangement. Let’s briefly review these new views (the first threeviews have rows for both the ASM instance as well as your database instances).

V_ASM_DISKGROUP

■ In an ASM instance, this view provides information about a disk group. Ina database instance, this view contains one row for every ASM disk groupmounted by the ASM instance.

V_ASM_CLIENT

■ In an ASM instance, this view identifies all the client databases using variousdisk groups. In a Database instance, the view contains one row for the ASMinstance if the database has any open ASM files.

V$ASM_DISK

■ In an ASM instance, this view contains one row for every disk discovered bythe ASM instance. In a database instance, the view will only contain rows fordisks in use by that database instance.

V$ASM_FILE

■ The V$ASM_FILE view contains one row for every ASM file in every diskgroup mounted by the ASM instance.

V$ASM_TEMPLATE

■ This view contains one row for every template present in every disk groupmounted by the ASM instance.

V$ASM_OPERATION

■ The V$ASM_OPERATION view provides information about any activelong-running operations in the ASM instance. Several ASM commands likeREBALANCE and RESIZE, take considerable time to complete. The commandprompt may return right away when you use these commands, however. Youcan use the V$ASM_OPERATION view to monitor these types of long-runningoperations.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:02 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 501: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Migrating a Database to ASM 31

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

CHAPTER SUMMARYThis chapter reviewed the new Automatic Storage Management (ASM) feature ofOracle Database 10g. ASM builds on the OMF files concept and now makes it possibleto manage large databases without needing to worry about naming database files. Thechapter showed you how managing disk groups is a far more efficient way of managingstorage than handling storage at the operating system file level.

You also learned how ASM rebalances files automatically when you add or removedisks from disk groups. You learned how to configure and manage an ASM instance.

The exam concentrates evenly on all aspectsof using ASM. From a conceptual point ofview, you need to understand the relationshipbetween ASM files and disk groups on onehand, and Oracle database files on the other.You must be able to answer questions on whattypes of Oracle files you can store in an ASMstorage system. Pay particular attention to theASM instance parameter file and know theimportance of each of the initializationparameters. The test focuses on the newbackground processes in ASM-based systems,as well as the relationship between disk groupsand failure groups.

The test will probe into your knowledgeof the various startup and shutdown commandsin an ASM-based system. Know the relationshipbetween shutting down an ASM instanceand the running of the connected Oracleinstances. For example, what happens tothe connected Oracle instances if you abort

an ASM instance? Rebalancing of disks ina disk group is a significant ASM detail,and expect a question regarding rebalancingoperations or parameters.

You must understand how to refer to ASMfiles in different situations (for example, whilecreating a new control file). File aliases andfile templates are also bound to show up in oneor more questions. Know how you use differentfilenaming syntax for various purposes (creatingand referring to files). What are file templates,what do you define them on, and why do youuse them?

The test may also contain questions regardingmigrating your current database to an ASM-based system. You must clearly understand thesteps of the migration process. Important pointsto remember are how Oracle handles the controlfile redo log files and datafiles for the newlyconverted database. In other words, how doesthe database create the new files?

INSIDE THE EXAMINSIDE THE EXAM

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:02 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 502: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You then learned how to create and manage disk groups. ASM files use special namingconventions, and you learned about the various types of ASM filenames in this chapter.Toward the end of this chapter, you saw how to create ASM-based databases. You alsolearned how to migrate your current databases to an ASM-based storage system.

32 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:02 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 503: OCA OCP - Oracle10G New Features For Administrators Exam Guide

✓TWO-MINUTE DRILL

Introduction to Automatic Storage Management❑ ASM automates and optimizes database storage for optimal performance.

❑ ASM is built on top of OMF files.

❑ You need to use the RMAN to copy ASM files.

❑ You can mingle ASM, OMF, and operating system files together.

❑ ASM simplifies storage management because you deal with only a few diskgroups, not a large number of disks and datafiles.

❑ ASM automatically balances I/O load.

❑ ASM helps you maintain redundant copies of data to provide fault tolerance.

❑ You access ASM files by accessing ASM disk groups.

Managing the ASM Instance❑ You must have the SYSOPER privilege to create an ASM instance.

❑ The ASM instance doesn’t mount files. It mounts disk groups.

❑ The ASM instance’s main job is to maintain ASM file metadata.

❑ The ASM instance is in charge of communicating file metadata to thedatabase instances.

❑ In order to use ASM, the ASM instance must be running.

❑ Your database never connects directly to ASM disk groups.

❑ You must issue all disk group management commands from an ASM instance.

❑ The only initialization parameter that you must provide for an ASM instanceis the INSTANCE_TYPE parameter.

❑ The INSTANCE_TYPE parameter must be set to ASM for starting an ASMinstance.

❑ The ASM_POWER_LIMIT parameter determines the speed of a rebalanceoperation.

❑ The ASM_DISKSTRING parameter limits the disk-discovery process.

❑ The ASM instance uses the LARGE_POOL memory.

❑ The ASM instance has two new background processes: RBAL and ARBn.

Two-Minute Drill 33

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:03 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 504: OCA OCP - Oracle10G New Features For Administrators Exam Guide

❑ The Oracle instance using ASM will have two new processes: RBAL andASMB.

❑ The ASMB process is the link between the Oracle database instance andthe ASM instance.

❑ You can’t use the STARTUP OPEN command for an ASM instance.

❑ If the ASM instance shuts down, all Oracle databases connected to theinstance will terminate as well.

Managing ASM Disk Groups❑ AN ASM disk group is a collection of disks.

❑ ASM provides redundancy through disk mirroring.

❑ ASM provides performance through disk striping.

❑ You can stripe your disks at a coarse or fine level.

❑ ASM mirrors extents, not entire disks.

❑ A set of disks that can all fail because they are connected to a commonresource is called a failure group.

❑ There are three levels of ASM redundancy: external, normal, and high.

❑ Normal redundancy involves two-way mirroring, and high redundancyinvolves three-way mirroring.

❑ The number of failure groups determines the degree of redundancy.

❑ You can create disk groups with the CREATE DISKGROUP command. Youcan alter them with the ALTER DISKGROUP command and drop them withthe DROP DISKGROUP command.

Managing ASM Files❑ Oracle automatically deletes any unnecessary files only if they are OMF-

based files.

❑ When you create a tablespace, you don’t need to specify a datafile. Just usea disk group’s name instead.

❑ You can see fully qualified filenames in the V$LOGFILE andV$DATAFILE views.

❑ ASM uses fully qualified filenames to refer to a file.

34 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:03 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 505: OCA OCP - Oracle10G New Features For Administrators Exam Guide

❑ A fully qualified filename is also called a system alias.

❑ ASM derives numeric filenames from fully qualified filenames and uses themto refer to existing files.

❑ You can use alias ASM filenames to create as well as refer to ASM files.

❑ You use incomplete filenames only to create files, not to refer to them.

❑ You must create disk group directories if you want to use alias filenames.

❑ You can drop a file and its alias using the DROP FILE clause in the ALTERDISKGROUP command.

❑ ASM file templates let you specify file attributes when you are creating a file.

❑ You can alter the default system templates, but you can’t drop them.

❑ You can’t change a file’s attributes once you create it.

Migrating to ASM❑ If you set your LOG_ARCHIVE_FORMAT initialization parameter to an

incomplete ASM filename, Oracle will ignore it.

❑ You must use incomplete ASM filenames, with or without a template, forall initialization parameters that require a destination (except log files).

❑ You can use the RMAN to migrate your database to ASM.

❑ You can use the V$ASM_OPERATIONS view to monitor long-running ASMoperations.

Two-Minute Drill 35

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:03 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 506: OCA OCP - Oracle10G New Features For Administrators Exam Guide

36 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

SELF TESTThe following questions will help you measure your understanding of the material presented in thischapter. Read all the choices carefully, because there might be more than one correct answer. Chooseall correct answers for each question.

Introduction to Automatic Storage Management

1. Which of the following statements about ASM instances is true?

A. ASM instances need to be open before Oracle can access ASM database files.B. ASM instances need to be mounted before Oracle can access ASM database files.C. ASM instances must be started, but in an unmounted state, before Oracle can access ASM

database files.D. ASM instances need to be shut down before Oracle can access ASM database files.

2. You must use which type of commands to copy ASM files?

A. RMAN commandsB. OMF commandsC. Operating system commandsD. Logical Volume Manager commands

3. Which types of files can you use in a single database?

A. Either ASM or OMF filesB. OMF, ASM, and operating system filesC. OMF and ASM filesD. ASM and Logical Volume Manager-based operating system files

4. ASM performs load balancing by distributing which items?

A. File extents across all disks in a disk groupB. ASM disks across ASM disk groupsC. File extents across all disks in all disk groupsD. Heavily used tables uniformly across all disks in a disk group

Managing the ASM Instance

5. What are the functions of an ASM instance?

A. Managing disk groups and communicating file metadata to the Oracle database usingASM files

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:03 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 507: OCA OCP - Oracle10G New Features For Administrators Exam Guide

B. Managing database files and communicating file metadata to the ASM instance usingASM files

C. Managing disk groups and communicating file metadata to the RMAND. Protecting disk groups

6. What is the only initialization parameter that you absolutely must set to create an ASM instance?

A. DB_UNIQUE_NAME

B. INSTANCE_TYPEC. ASM_POWER_LIMITD. ASM_DISKSTRING

7. What happens if you don’t set the ASM_DISKSTRING parameter for an ASM instance?

A. Your ASM instance won’t start.B. Your Oracle database won’t be able to communicate with the ASM instance.C. The disk-discovery process may take a longer time when you add a disk to a disk group.D. ASM won’t perform disk discovery when you add a new disk to a disk group.

8. What does the ARBn background process do in an ASM instance?

A. Coordinates disk activityB. Performs disk rebalance workC. Coordinates disk rebalance workD. Manages the RBAL process

9. When you start an ASM instance in the MOUNT mode, what does the instance mount?

A. Oracle database filesB. Individual ASM disks that belong to a particular databaseC. Disk groups specified by the ASM_DISKGROUPS parameterD. The instance doesn’t have any database files, so it doesn’t mount anything

Managing ASM Disk Groups

10. What do ASM disk groups provide?

A. Redundancy through stripingB. Performance through mirroringC. Redundancy through mirroringD. Performance through striping

Self Test 37

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:03 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 508: OCA OCP - Oracle10G New Features For Administrators Exam Guide

38 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

10. What does ASM stripe?

A. Database files across all the disk groupsB. ASM disks across all the disk groupsC. ASM disk groups across all the database filesD. Database files across all the disks in a disk group

12. What does ASM mirror?

A. DisksB. FilesC. ExtentsD. Disk groups

13. For two-way mirroring, how many failure groups do you need at a minimum?

A. None (two-way mirroring doesn’t need any failure groups)B. One failure groupC. Two failure groupsD. Three failure groups

Managing ASM Files

14. Which of the following types of files will the database automatically delete?

A. All unnecessary filesB. All unnecessary ASM files without aliasesC. All unnecessary ASM files with aliasesD. All unnecessary ASM files with and without aliases

15. When can you use a fully qualified name?

A. Only to create a new ASM fileB. Only to refer to an ASM fileC. To create and to refer to an ASM fileD. For only ASM system files

16. What are incomplete filenames used for?

A. Referring to multiple filesB. Creating single filesC. Creating multiple filesD. Creating ASM system files

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:03 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 509: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Lab questions 39

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

17. Which of the following is true about changing an ASM file’s attributes?

A. You must use the ALTER DISKGROUP command to alter the template.B. You must use the ALTER DISKGROUP command to alter the file attributes directly.C. You must use a new file alias for the file before altering its attributes.D. You can’t change a file’s attributes after you create it.

Migrating to ASM

18. If you set the LOG_ARCHIVE_FORMAT initialization parameter to an ASM directory, whatwill Oracle do?

A. Oracle will use the directory and create non-OMF files in that directory.B. Oracle will use the directory and create OMF files in that directory.C. Oracle will not use that directory, unless the online redo log files are also in an ASM directory.D. Oracle will use the directory only if you use an incomplete ASM filename.

19. When you migrate your current database to ASM-based storage, what should you do with yourredo log files?

A. Rename them to ASM disk groupsB. Reinitialize the current online redo logsC. Oracle will automatically copy them when you migrate to an ASM-based databaseD. Copy them from their present locations to the ASM disk directly

20. What is the most important thing that the V$ASM_OPERATION view helps you do?

A. Monitor the success or failure of disk-balancing operationsB. Monitor long-running operationsC. Monitor the migration to an ASM instanceD. Monitor all disk groups to see if disk rebalancing is necessary

LAB QUESTIONS1. Show how you would add a disk to an existing disk group.

2. Show how you would remove an existing disk group.

3. Show how you would undo the pending disk removal operation.

4. Show all your ASM disks using a data dictionary view.

5. Show all your ASM files using a data dictionary view.

6. Create a tablespace using an ASM disk group.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:03 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 510: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SELF TEST ANSWERS

Introduction to Automatic Storage Management

1. � B. The ASM instance must be mounted before Oracle can access the ASM database files.When you start the ASM instance in the MOUNT mode, the instance mounts all the ASM diskgroups. Without accessing the disk groups, you can’t access the ASM datafiles that are on theASM disks.� A is wrong because an ASM instance cannot ever be opened like an Oracle databaseinstance. C is wrong because if the ASM instance isn’t mounted, you can’t access the ASM diskgroups. D is wrong since the ASM instance must be running for Oracle to access its ASM-baseddatabase files.

2. � A. You can copy ASM files only with RMAN commands.� B is wrong because there are no OMF commands to copy files. C is wrong since theoperating system doesn’t “see” ASM files, so it can’t manage them. D is wrong because youdon’t need a Logical Volume Manager to use with your ASM files.

3. � B. You can use all three types of files—OMF, ASM, and operating system files—in thesame database.� A, C, and D specify the wrong combinations of files.

4. � A. ASM performs I/O load balancing by distributing file extents uniformly across all disksin a disk group.� B is wrong since ASM doesn’t perform load balancing through distributing disks acrossdisk groups. C is wrong because the file extents are spread only across disks in the same diskgroup. D is wrong because ASM doesn’t deal with database tables in any way.

Managing the ASM Instance

5. � A and D. The key job of the ASM instance is to manage disk groups. It also communicatesinformation about the disk group to the Oracle database using ASM files. Another key taskmanaged by the ASM instance is protecting disk groups .� B is wrong because ASM doesn’t manage database files directly—that job falls to thedatabase. C is wrong because ASM doesn’t communicate file metadata to the RMAN.

6. � B. The only ASM initialization parameter that you must set is the INSTANCE_TYPEparameter. You must set it to a value of ASM to indicate to the Oracle executable that you arestarting an ASM instance, not a regular Oracle database instance.

40 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:04 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 511: OCA OCP - Oracle10G New Features For Administrators Exam Guide

� A, C, and D are wrong because none of these parameters are necessary to start an ASMinstance. The instance can use the default values for all three parameters in order to start.

7. � C. The ASM_DISKSTRING parameter specifies the location of the ASM disk groups. Ifyou don’t specify a value for this parameter, the disk-discovery process undertaken by ASMinstance will take a longer time, since it will look in all directories to which the ASM instancehas read/write access.� A is wrong because the ASM instance will start, even when you don’t specify a value forthe ASM_DISKSTRING parameter. B is wrong because the ASM instance will communicatenormally with the Oracle database. D is wrong because ASM will perform the disk-discoveryprocess, but it may take a longer time to do so if you omit the ASM_DISKSTRING parameter.

8. � B. The ARBn background process performs the actual disk rebalancing work in an ASMinstance.� A and C are wrong since it is the RBAL background process that coordinates the diskactivity, not the ARBn process. D is wrong because the RBAL process manages the ARBn process,not the other way around.

9. � C. When you mount an ASM instance, the instance mounts the disk groups you specifyby using the ASM_DISKGROUPS initialization parameter.� A is wrong because ASM instances don’t mount Oracle database files. B is wrong since anASM instance mounts disk groups, not individual disks that are part of the disk group. D is wrongsince the ASM instance does mount disk groups.

Managing ASM Disk Groups

10. � C and D. Mirroring provides redundancy, and striping enhances performance.� A and B are wrong since they mix up the functions of mirroring and striping.

11. � D. ASM stripes database files across all the disks in a disk group.� A is wrong because ASM doesn’t stripe database files across multiple disk groups. B and Care wrong since ASM doesn’t stripe disks or disk groups—it stripes database files.

12. � C. ASM mirroring is different from operating system mirroring in that it mirrors individualextents, not disks.� A, B, and D refer to the wrong unit for ASM mirroring.

13. � C. You need two failure groups at a minimum for two-way mirroring.� A is wrong because you do need failure groups for any mirroring. B is wrong because a singlefailure group doesn’t ensure protection of any kind. D is wrong because three failure groupsprovide three-way mirroring.

Self Test Answers 41

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:04 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 512: OCA OCP - Oracle10G New Features For Administrators Exam Guide

42 Chapter 10: Automatic Storage Management

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

Managing ASM Files

14. � B. The database will automatically delete all ASM files without aliases, because they areconsidered OMF files.� A is wrong because the database will automatically delete only the OMF files, not all theunnecessary files. B and D are wrong since Oracle considers files with aliases non-OMF files,and therefore, it won’t automatically delete them.

15. � B. You can use a fully qualified name only to refer to an ASM file.� A and C are wrong since you can’t use fully qualified names to create files. D is wrong sinceyou can use fully qualified names for nonsystem files.

16. � C. Incomplete ASM filenames are used only for creating multiple files.� A is wrong because incomplete filenames can’t be used to merely refer to files. B is wrongbecause incomplete filenames are not limited to creating single files. D is wrong since incompletefilenames aren’t limited to system files.

17. � D. You can’t change a file’s attributes once you create it.� A, B, and C are wrong since you can’t change a file’s attributes after creating it.

Migrating to ASM

18. � A and D. A is correct because Oracle will create non-OMF files in that directory. D iscorrect because Oracle will use the directory only if it has an incomplete ASM filename.� B is wrong since Oracle will create non-OMF files in that directory. C is wrong since Oraclewill use that directory.

19. � A. When you migrate your database to ASM files, you must individually rename each ofyour online redo log files to ASM disk groups.� B is wrong since you don’t reinitialize your online redo log files, as this would clear them.C is wrong since Oracle will not automatically copy your online redo log files. D is wrong sinceyou copy the files to disk groups, not directly to the underlying disks.

20. � B. The most important function of the V$ASM_OPERATION view is to help you monitorlong-running ASM operations.� A, C, and D are wrong since the V$ASM_OPERATION doesn’t help you monitor any ofthese things.

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:04 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 513: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Lab Answers

1. To add a disk to an existing disk group, use the following:

SQL> alter diskgroup dgroup1add failgroup controller1‘/dev/rdsk/c0t3d0s2’ NAME a5;

2. Remove an existing disk group as follows:

SQL> drop diskgroup dgroup1 including contents;

3. You can undo a pending disk removal operation with this command:

SQL> alter diskgroup dgora1 undrop disks;

4. To show all your ASM disks using a data dictionary view, use the following:

SQL> select name, failgroup, bytes_read, bytes_writtenfrom v$asm_disk;

5. To show all your ASM files using a data dictionary view, use the following:

SQL> select group_number, file_number, bytes, type, stripedfrom v$asm_file;

6. Create a tablespace using an ASM disk group as follows:

SQL> create tablespace test_tbspdatafile ‘+dgroup1’ size 500M

Self Test Answers 43

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10

P:\010Comp\CertPrs8\862-4\ch10.vpTuesday, August 31, 2004 10:18:04 AM

Color profile: Generic CMYK printer profileComposite Default screen

Page 514: OCA OCP - Oracle10G New Features For Administrators Exam Guide

11Enhancements in

Analytical SQL andMaterialized Views

CERTIFICATION OBJECTIVES

11.01 Enhancements in the MERGE Statement

11.02 Using Partitioned Outer Joins

11.03 Using the SQL MODEL Clause

11.04 Materialized View Enhancements

✓ Two-Minute Drill

Q&A Self Test

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11Blind Folio 11:1

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:46 PM

Color profile: DisabledComposite Default screen

Page 515: OCA OCP - Oracle10G New Features For Administrators Exam Guide

This chapter deals with analytical SQL enhancements to support data warehousingapplications and enhancements to several materialized view features. You’ll start offwith a review of the analytical SQL enhancements in Oracle Database 10g. The MERGE

statement is now enhanced, with support for conditional statements. The new partitionedouter joins help in the densification of data, which will yield better calculation performance forseveral analytical queries, especially those dealing with time-series data. The brand-new MODELSQL clause provides spreadsheet-like array computations that are highly scalable, directly fromwithin your Oracle database.

Oracle Database 10g presents several improvements to the management ofmaterialized views, which are critical in data warehousing environments. Oraclesupports fast refresh for materialized join views under even more conditions now.You can use the new procedure TUNE_MVIEW of the DBMS_ADVISOR package toenhance the fast refresh and query rewrite capabilities of your materialized views.You’ll also review several new materialized view enhancements like improvementsto the partition change tracking feature and materialized view refresh when you’reusing trusted, instead of enforced, constraints.

Let’s start the chapter with a discussion of the enhancements to the powerfulMERGE statement.

CERTIFICATION OBJECTIVE 11.01

Enhancements in the MERGE StatementThe MERGE statement is primarily of value when you’re moving vast amounts of datain a data warehousing application. When you are extracting data from a source systeminto a data warehouse, not all of the data will be completely new. You may find that someof the table rows are new, while others are modifications of existing data. Therefore, you’llneed to insert some of the new data and also update some existing data with the newdata from the source. For example, if a sales transaction is completely new, you’ll insertthat row into the data warehouse table. If that particular transaction already exists, you’llmerely update the necessary columns.

Oracle9i made available the highly useful MERGE statement, which enables youconveniently perform both inserts and updates in a single SQL statement. You canperform an UPDATE-ELSE-INSERT operation using a MERGE statement. Oracle

2 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:47 PM

Color profile: DisabledComposite Default screen

Page 516: OCA OCP - Oracle10G New Features For Administrators Exam Guide

has enhanced the MERGE statement in Oracle Database 10g. Let’s review the MERGEstatement prior to Oracle Database 10g, and then cover its new capabilities in thefollowing sections.

The Basic MERGE StatementThe basic MERGE statement has the following structure:

merge <hint> into <table_name>using <table_view_or_query>on (<condition>)when matched then <update_clause>when not matched then <insert_clause>;

Here’s a simple example of a basic MERGE statement, as of the Oracle9i version:

SQL> merge into sales s using new_sales non (s.sales_transaction_id = n.sales_transaction_id)

when matched then updates_quantity = s_quantity + n_quantity, s_dollar = s_dollar + n_dollar

when not matched then insert (sales_quantity_sold, sales_dollar_amount)values (n.sales_quantity_sold, n.sales_dollar_amount);

The ON condition (s.sales_transaction_id = n.sales_transaction_id) determines if an update or an insert operation will take place. The previousstatement will update a row in the new_sales table, if that row already exists (thesales_transaction_id column identifies the row). If there is no such row, Oracle willinsert a new row with values for the sales_quantity_sold and sales_dollar_amountcolumns.

Conditional UPDATE and INSERT StatementsRather than an unconditional insertion or updating of all the table rows, you may wantto insert or update data only when certain conditions are met. In Oracle Database 10g,the MERGE statement has been enhanced to allow you to conditionally insert or deletedata. Now, Oracle allows you to use a WHERE clause in a MERGE statement’s UPDATEor INSERT clause to conditionally update or insert data.

Here’s an example that shows how you can conditionally insert and update datausing a MERGE statement (note the USING clause in the MERGE statement):

SQL> merge using product_cChanges s -- Source tableinto products p -- Destination table

Enhancements in the MERGE Statement 3

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:47 PM

Color profile: DisabledComposite Default screen

Page 517: OCA OCP - Oracle10G New Features For Administrators Exam Guide

on (p.prod_id = s.prod_id) -- Search/Join conditionwhen matched then update -- Update if joinset p.prod_list_price = s.prod_new_pricewhere p.prod_status <> “EXPIRED” -- Conditional updatewhen not matched theninsert -- Insert if not joinset p.prod_list_price = s.prod_new_pricewhere s.prod_status <> “EXPIRED” -- conditional insertNote that Oracle

will skip the insert or update operation if the statement doesn’t satisfy theWHERE condition. Both the insert and the update operations would occur only ifthe product is not an expired item. (where s.prod_status <> “EXPIRED”).

The DELETE Clause with the MERGE StatementYou can now use the MERGE statement with an optional DELETE clause in a MERGEstatement. However, you can’t use theDELETE clause independently in aMERGE statement,as with the UPDATE or INSERT clause. You must embed the DELETE statement insidethe UPDATE statement. This means that the DELETE statement isn’t a “global” clause,but rather works in the confines of the data affected by the UPDATE clause of the MERGEstatement. The following example shows how the DELETE clause is embedded withinthe UPDATE clause.

SQL> merge using product_changes sinto products p on (d.prod_id = s.prod_id)when matched thenupdate set d.prod_list_price = s.prod_new_price,d.prod_status = s.prod_new_statusdelete where (d.prod_status = “OLD_ITEM”)when not matched theninsert (prod_id, prod_list_price, prod_status)values (s.prod_id, s.prod_new_price, s.prod_new_status);

The preceding MERGE statement will first update the prod_list_price and theprod_status columns of the product table wherever the join condition is true. Thejoin condition (d..prod_id = s.prod_id) joins the two tables, product (the sourcetable) and product_changes (the destination table).

Here are a couple of considerations when using the DELETE statement:

■ The DELETE clause affects only the rows that were updated by the MERGEstatement.

■ The MERGE statement will delete only the rows included in the join conditionspecified by the ON clause.

4 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:48 PM

Color profile: DisabledComposite Default screen

Page 518: OCA OCP - Oracle10G New Features For Administrators Exam Guide

When you use this MERGE statement, theUPDATE clause fires first, and it may set someof the prod_new_status values to expired. TheDELETE clause will then remove all the rowswhose prod_new_status value was set to expiredby the UPDATE clause.The DELETE clause willnot remove any other rows with the expiredstatus, unless they are part of the join definedin the ON clause.

CERTIFICATION OBJECTIVE 11.02

Using Partitioned Outer JoinsOracle provides a rich set of analytical functions to help you in business reporting.Using these functions, you can avoid the need to program tedious user-defined functionsand formulas. Prior to Oracle Database 10g, you had access to the following analyticalfunctions:

■ Ranking and percentile functions include cumulative distributions, percentileranks, and N-tiles.

■ Moving window calculations provide the capacity to compute sums and averages.

■ Lag/lead functions help you compute period-to-period changes.

■ First/last functions help you figure out the first and last values in an orderedgroup.

■ Linear-regression functions help you calculate linear regression and otherrelated statistics.

Oracle Database 10g provides an extension of the SQL outer join concept toimprove the performance of analytical functions when they encounter data withmissing values for some combinations of dimension values. In the following sections,I’ll introduce you to some basic data warehousing concepts and analytical processingfeatures, before explaining how to use partitioned outer joins to handle problemscaused by sparse data (data with missing values).

Using Partitioned Outer Joins 5

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

The DELETE clause in aMERGE operation will evaluate only theupdated values (values updated by theUPDATE clause) and not the original valuesthat were evaluated by the UPDATE clause.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:48 PM

Color profile: DisabledComposite Default screen

Page 519: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Fact Tables, Measures, and DimensionsFact tables contain the business data of an organization. Sales and inventory items aretwo common examples of the type of data captured in a fact table. Of course, fact tablescontain facts, but the data is also referred to as a measure. Thus, sales in a sales facttable and inventory in an inventory fact table are the measures. Literally, a measuredenotes what it is that you are measuring.

Fact tables often contain links to several entities like time, product, and marketregion. For example, the fact table might tell you what a firm’s total sales are for theyear 2005. However, you are more likely to want the data to answer more meaningfulquestions like, “What are our sales for dish detergents in the New York area duringthe first quarter of 2005?” To answer questions like this, you use the concept ofdimensions.

A dimension is a means of dividing your data into meaningful categories. Usingdimensions, you can turn your raw facts into meaningful data. For example, for thesales fact table, the correct dimensions may be time (year and quarters), product, andregion. It is customary in data warehousing applications to create small tables, calleddimension tables, to describe the various dimensions. These dimension tables serve asthe reference, or lookup, tables. The combination of several dimension values helpsyou answer detailed analytical questions. For example, using the time, region, andproduct dimension values, you can easily answer complex business questions like thequestion posed in the previous paragraph.

The use of a central fact table and a number of dimension tables linked to it throughforeign keys is called a star schema in data warehousing circles. The primary key ofthe fact table is usually a composite key that is made up of all of its foreign keys.

Dimension tables are usually organized along a hierarchical basis. Thus, thedetailed data in a dimension, which is normally collected at the lowest possiblelevel, is aggregated into more useful aggregates. When you move up a hierarchy, itis called rolling up. Conversely, when you move down a hierarchy of a dimension,it is called drilling down. For example, in the customers dimension, customers mayroll up to a city. The cities may be rolled up into a division. The division may be rolledup into a region. Regions may, in turn, be rolled up into a country.

How Analytical Functions Process DataAnalytical SQL functions efficiently deliver complex summary, aggregation, and otheranalytical results. In order to produce these results, analytical functions follow a methodicalprocessing order. Analytical processing usually follows a three-step sequence:

6 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:48 PM

Color profile: DisabledComposite Default screen

Page 520: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using Partitioned Outer Joins 7

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

■ Grouping In the preliminary grouping step, Oracle performs the variousjoins, WHERE, GROUP BY, and similar grouping operations.

■ Calculation (analysis) In this middle stage of analytical processing, theresult sets from the grouping step are divided into sets of rows called partitions.The result set from the previous step could be broken into one, a few, or manypartitions. Oracle then hands the result set of the grouping process from theprevious step to the analytical functions. The middle stage is at the heart ofanalytical function usage, since this where the analytical functions processthe rows of each of the partitions.

■ Output ordering Finally, Oracle hands you the output in the precise orderspecified by any ORDER BY clause that you may specify at the end of yourquery.

Data DensificationThe concept of data densification has to do with the fact that you may view yourdata in two different forms:

■ Dense data is when you have rows for all possible combinations of dimensionvalues, even when you don’t have any data (facts) for certain combinations.

■ You have sparse data when you don’t show any values for certain combinations ofdimension values, if you don’t have any data (facts) for those combinations.In real life, data is usually sparse.

To understand why dense data is better, let’s say that you are dealing with time-series data. If you have sparse data, you’ll have the problem of an inconsistent numberof rows for groups of dimensions. This makes it harder for you to use some SQLanalytical functions such as the lag and lead functions, which help you computeperiod-to-period changes. These functions perform slowly, and the report formattingwould be uneven. Performance takes a big hit when you don’t have a row for eachcombination of the dimensions.

Partitioned outer joins help turn sparse data intodense data, thus helping you avoid the drawbacksof using sparse data for analytical computations.When you use a partitioned outer join, Oraclereplaces the missing values along any dimensions.You thus have faster performance and a better

The partitioned outer joinis ideal for time dimensions, but it can beused for any kind of dimensions.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:49 PM

Color profile: DisabledComposite Default screen

Page 521: OCA OCP - Oracle10G New Features For Administrators Exam Guide

8 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

reporting format when you use partitioned outer joins. We’ll look at how partitionedouter joins work after a quick review of Oracle’s join methods.

A Review of Oracle Join MethodsLet’s quickly review Oracle’s join methods before plunging into the partitioned outerjoin concepts. Join queries combine rows from two or more tables, views, or materializedviews. Oracle performs a join whenever multiple tables appear in the query’s FROMclause. The query’s SELECT list can select any columns from any of these tables.The WHERE clause, also called the join condition, compares two columns, each from adifferent table. To execute the join, Oracle combines pairs of rows, each containingone row from each table for which the join condition evaluates to TRUE.

Oracle joins are of the following types:

■ Natural joins A natural join is based on all columns that have the samename in the two tables. It selects rows from the two tables that have equalvalues in the relevant columns.

■ Inner joins An inner join (also called a simple join) is a join of two or moretables that returns only those rows that satisfy the join condition. An innerjoin is the default join type for a join operation.

■ Outer joins An outer join extends the result of an inner join. An outer joinreturns all rows that satisfy the join condition and also returns some or all ofthose rows from one table for which no rows from the other satisfy the joincondition.

■ A left outer join performs an outer join of tables A and B and returns allrows from table A. For all rows in table A that have no matching rows intable B, Oracle returns NULL for any SELECT list expressions containingcolumns of table B.

■ A right outer join performs an outer join of tables A and B and returns allrows from table B. For all rows in table B that have no matching rows intable A, Oracle returns NULL for any SELECT list expressions containingcolumns of table A.

■ A full outer join performs an outer join and returns all rows from A and B,extended with NULLs if they do not satisfy the join condition.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:49 PM

Color profile: DisabledComposite Default screen

Page 522: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using Partitioned Outer Joins 9

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

Partitioned Outer JoinsA partitioned outer join is nothing but an extension of an Oracle outer join. You usepartitioned outer joins to fill the gaps in sparse data. In order to use a partitioned outerjoin, you add the PARTITION BY clause to the outer join clause. The PARTITIONBY clause partitions the rows in your query output on the basis of the expression youprovide within the clause.

Here’s the syntax of a partitioned outer join:

select .....from table_referencepartition by (expr [, expr ]... )right outer join table_referenceandselect .....from table_referenceleft outer join table_referencepartition by {expr [,expr ]...)

For example, suppose your SELECT list consists of three columns: product, time_id, and quantity. The logical partitioning can be done on the basis of the followingcondition:

partition by product order by time_id

The query output will be partitioned into groups by the product column. If there weretwo products—bottles and cans—there would be two partitions. Once Oracle logicallypartitions the query output, it applies the outer join to each of the logical partitions.You can thus view the output of a partitioned outer join as a UNION of several outerjoins, consisiting of a join of each of the logical partitions with the other table in thejoin. In the example, the bottle and can partitions are joined to the other table byusing the time_id column.

Sparse DataLet’s look at a typical set of sparse data by using the following example, which shows theweekly and year-to-date sales for the same set of 11 weeks in two years (2004 and 2005).

Select substr(p.prod_Name,1,15) product_name, t.calendar_year year,t.calendar_week_number week, SUM(amount_sold) salesfrom sales s, times t, products p

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:49 PM

Color profile: DisabledComposite Default screen

Page 523: OCA OCP - Oracle10G New Features For Administrators Exam Guide

10 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

where s.time_id = t.time_id and s.prod_id = p.prod_id ANDp.prod_name in ('Bounce') andt.calendar_year in (2004,2005) andt.calendar_week_number between 20 and 30group by p.prod_name, t.calendar_year, t.calendar_week_number;

PRODUCT_NAME YEAR WEEK SALES--------------- ---------- ---------- ----------Bounce 2004 20 801Bounce 2004 21 4062.24Bounce 2004 22 2043.16Bounce 2004 23 2731.14Bounce 2004 24 4419.36Bounce 2004 27 2297.29Bounce 2004 28 1443.13Bounce 2004 29 1927.38Bounce 2004 30 1927.38Bounce 2005 20 1483.3Bounce 2005 21 4184.49Bounce 2005 22 2609.19Bounce 2005 23 1416.95Bounce 2005 24 3149.62Bounce 2005 25 2645.98Bounce 2005 27 2125.12Bounce 2005 29 2467.92Bounce 2005 30 2620.17

We should normally have a total of 22 rows (11 weeks for each year) of sales data.However, we have a set of sparse data, with only 18 rows. Four rows are missing,because we have no data for weeks 25 and 26 in the year 2004 and weeks 26 and 28in the year 2005.

Making the Data DenseUsing the query with the partitioned outer join produces the following output, whichgets rid of the sparse data we had in the earlier query output. Instead of blanks, we nowhave zero values. In the following query, let’s call our original query v, as we selectdata from the table times, which we’ll refer to as t. Note that all 22 rows are retrievedthis time, leaving no gaps in our time series.

select product_name, t.year, t.week,

NVL(sales,0) dense_sales from(select substr(p.prod_name,1,15) product_name,t.calendar_year year, t.calendar_week_number week,

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:50 PM

Color profile: DisabledComposite Default screen

Page 524: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using Partitioned Outer Joins 11

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

SUM(amount_sold) salesfrom sales s, times t, products pwhere s.time_id = t.time_id and s.prod_id = p.prod_id andp.prod_name in ('Bounce') andt.calendar_year in (2004,2005) andt.calendar_week_number between 20 and 30group by p.prod_name, t.calendar_year, t.calendar_week_number) vpartition by (v.product_name)right outer join(select distinct calendar_week_number week, calendar_year yearfrom timeswhere calendar_year IN (2004, 2005) andcalendar_week_number between 20 AND 30) t

on (v.week = t.week AND v.Year = t.Year)order by t.year, t.week;PRODUCT_NAME YEAR WEEK DENSE_SALES--------------- ---------- ---------- -----------Bounce 2004 20 801Bounce 2004 21 4062.24Bounce 2004 22 2043.16Bounce 2004 23 2731.14Bounce 2004 24 4419.36Bounce 2004 25 0Bounce 2004 26 0Bounce 2004 27 2297.29Bounce 2004 28 1443.13Bounce 2004 29 1927.38Bounce 2004 30 1927.38Bounce 2005 20 1483.3Bounce 2005 21 4184.49Bounce 2005 22 2609.19Bounce 2005 23 1416.95Bounce 2005 24 3149.62Bounce 2005 25 2645.98Bounce 2005 26 0Bounce 2005 27 2125.12Bounce 2005 28 0Bounce 2005 29 2467.92Bounce 2005 30 2620.17

For the four added rows that had no sales data, the NVL function transformed theNULL values to 0. This is how partitioned outer joins convert sparse data into adense form. You may also choose to replace the NULL values with the most recentnon-NULL values. To do this, you can add the IGNORE NULLS clause to the OracleLAST_VALUE and FIRST_VALUE functions.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:50 PM

Color profile: DisabledComposite Default screen

Page 525: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CERTIFICATION OBJECTIVE 11.03

Using the SQL MODEL ClauseIt is common for Oracle users to process data using third-party tools, since Oracle SQLhas traditionally lacked sophisticated modeling capabilities to produce complex reports.A basic example is the use of spreadsheets, which apply formulas to transform data intonew forms. In previous versions of Oracle, in order to produce these spreadsheet-likereports, you needed to either download data into spreadsheet programs like MicrosoftExcel or use dedicated multidimensional online analytical processing (OLAP) serverssuch as Oracle Express. For example, you might use Excel to convert your businessdata into rule-based business models, with the help of various macros. But third-partyspreadsheet tools are cumbersome to use, and you need to expend considerable effortand time to constantly import updated Oracle data into the spreadsheet programs.

Oracle Database 10g offers the extremely powerful MODEL clause, which enables theuse of SQL statements to categorize data and apply sophisticated formulas to producefancy reports directly from within the database itself. You can now produce highlyuseful Oracle analytical queries, overcoming several drawbacks of Oracle SQL. Withthe new MODEL clause, you can use normal SQL statements to create multidimensionalarrays and conduct complex interrow and interarray calculations on the array cells.Here, you’ll learn how the MODEL clause produces its powerful results.

How the MODEL Clause WorksOracle professionals commonly make heavy use of multiple table joins and unions whendealing with complex data warehousing data. These techniques help you peform verycomplex computations, but they are usually slow and computationally expensive. TheMODEL enhancement enables you to perform complex enterprise-level computations.

The MODEL clause provide interrow calculation functionality by enabling you tocreate multidimensional arrays of your query data and letting you randomly accessthe cells within the arrays. The way the MODEL clause addresses individual cells iscalled symbolic cell addressing. The MODEL clause also performs symbolic array computation,by transforming the individual cells using formulas, which it calls rules.

The MODEL clause enables you to apply business models to your existing data.When you use the MODEL clause as part of a query, Oracle feeds the data retrievedby the query to the MODEL clause. The MODEL clause rearranges the data into a

12 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:50 PM

Color profile: DisabledComposite Default screen

Page 526: OCA OCP - Oracle10G New Features For Administrators Exam Guide

multidimensional array and applies your business rules to the individual elements ofthe array. From the application of various user-specified business rules, Oracle derivesupdated as well as newly created data. However, you won’t actually see an array asyour final form of the output, since Oracle will format the new and updated datainto a row format when it delivers the MODEL clause’s output to you.

The first step in a MODEL-based query is the creation of the multidimensional array.The following section explains the basis of the arrays created by the MODEL clause.

Creating the Multidimensional ArraysThe MODEL clause creates the multidimensional arrays that are at the heart of itsfunctionality by mapping all the columns of the query that contains a MODEL clauseinto the following three groups.

■ Partitions These are similar to the analytical function partitions describedearlier in this chapter. Basically, a partition is a result handed to the MODELclause by previous grouping operations. The MODEL clause is alwaysseparately applied to the data within each partition.

■ Dimensions These are the same dimensions that you saw earlier in thischapter; for example, they might be time, region, and product.

■ Measures Measures are the fact table data on which you are modeling yourreport, such as sales or inventories. You can look at the aggregate measure asconsisting of a bunch of measure cells, with each of the cells identified by aunique combination of dimensions. For example, if sales is your measure, thenthe sales of detergents for the third quarter of 2004 in the New York region isone cell of the measure, since you can have only one such unique combinationof your three dimensions: product (detergents), time (third quarter of 2004),and region (New York region).

The next section looks at how the MODEL feature uses rules to modify yourmultidimensional array data.

Transforming Array Data with RulesA rule in the context of the MODEL clause is any business rule or formula you wantto apply to the array data created by the MODEL clause. You may, for example, use aformula to forecast next year’s sales on the basis of the preceding two years’ sales data.You create a simple forecasting formula that expresses your business reasoning, andthen pass it along to the MODEL clause as a rule.

Using the SQL MODEL Clause 13

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:51 PM

Color profile: DisabledComposite Default screen

Page 527: OCA OCP - Oracle10G New Features For Administrators Exam Guide

14 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

You use the keyword RULES to indicate that you are specifying the rules that theMODEL clause must apply to its multidimensional array data. For example, you couldspecify a simple rule as follows:

MODEL…RULES…(sales['Kleenex', 2005] = sales['Kleenex', 2003] + sales['Kleenex', 2004]…

This rule specifies that the sales of Kleenex for the year 2005 would be the sum of thesales of Kleenex in the years 2003 and 2004.

When you specify the RULES keyword, you may also want to indicate whether therules you are specifying will be transforming existing data or inserting new rows ofdata. By default, the RULES keyword operates with the UPSERT specification. Thatis, if the measure cell on the left hand of a rule exists, Oracle will update it. Otherwise,Oracle will create a new row with the measure cell values. Here’s an example:

MODEL…RULES UPSERTsales (‘Kleenex, 2005) = sales (‘Kleenex, 2003’) + sales (‘Kleenex, 2004)…(MORE RULES HERE)

In this rules specification, if there is already a table or view row that shows the sales forKleenex in the year 2005, Oracle will update that row with the values derived fromapplying the rule formula. If there is no such row, Oracle will create a new row to showthe forecasted sales of Kleenex for the year 2005.

If you don’t want Oracle to insert any new rows, but just update the existing rows,you can change the default behavior of the RULES clause by specifying the UPDATEoption for all the rules, as shown here:

MODEL…RULES UPDATESales (‘Kleenex, 2005) = sales (‘Kleenex, 2003’) + sales (‘Kleenex, 2004)…(MORE RULES HERE)

The previous two examples demonstrated how to apply different rule options atthe MODEL clause level. You may also specify rule options at the individual rulelevel, as shown here:

RULES(UPDATE sales (‘Kleenex, 2005) = sales (‘Kleenex, 2003’) + sales (‘Kleenex, 2004)

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:51 PM

Color profile: DisabledComposite Default screen

Page 528: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Using the SQL MODEL Clause 15

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

When you specify a rule option at the individual rule level as shown in this example,the use of the RULES keyword is optional.

You can specify that Oracle should evaluate the rules in either of the followingtwo ways:

■ sequential order Oracle will evaluate a rule in the order it appearsin the MODEL clause.

■ automatic order Rather than evaluating a rule based on its orderof appearance in a list of several rules, Oracle will evaluate the rule on thebasis of the dependencies between the various rules in the MODEL clause.If rule A depends on rule B, Oracle will evaluate rule B first, even thoughrule A appears before rule B in the list of rules under the RULES keyword.

Sequential order is the default order of processing rules in a MODEL clause.

Producing the Final OutputAs its output, the MODEL clause will give the results of applying your rules to themultidimensional arrays it created from your table data. A MODEL-based SQL analyticalquery typically uses an ORDER BY clause at the very end of the query to precisely orderits output.

You can use the optional RETURN UPDATED ROWS clause after the MODEL keywordto specify that only the new values created by the MODEL statement should be returned.These new values may either be updated values of a column or newly created rows.

If you specify a rule optionat the rule level, it will overrirde the RULESspecification at the MODEL clause level. Ifyou don’t specify a rule option at the rule

level, the MODEL level option applies to allthe rules. If you don’t specify an optionat the MODEL level, the default UPSERToption will prevail.

When I say that the MODELclause will create or update rows, I strictlymean that the changes are shown in theMODEL clause output. The MODEL clause

doesn’t update or insert rows into the tableor views. To change the base table data, youmust use the traditional INSERT, UPDATE,or MERGE statements.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:51 PM

Color profile: DisabledComposite Default screen

Page 529: OCA OCP - Oracle10G New Features For Administrators Exam Guide

A MODEL Clause ExampleLet’s look at a simple SQL example that demonstrates the capabilities of the MODELclause. Here’s the query:

SQL> select country, product, year, salesfrom sales_view

where country in ('Mexico', 'Canada')MODELpartition by (country) DIMENSION BY (product, year)measures (sale sales)rules

(sales['Kleenex', 2005] = sales['Kleenex', 2004] + sales['Kleenex',2003],sales['Pampers', 2005] = sales['Pampers', 2004],sales['All_Products', 2005] = sales['Kleenex', 2005] + sales['Pampers',2005])

order by country, product, year;

Sales units are the measure in this example. The query partitions the data by countryand form the measure cells consists of product and year combinations. The three rulesspecify the following:

■ Total sales of Kleenex in 2005 are forecast as the sum of Kleenex sales inthe years 2003 and 2004.

■ Total sales of Pampers in the year 2005 are forecast to be the same as thesales in 2004.

■ Total product sales in 2005 are computed as the sum of the Kleenex andPampers sales in 2005.

Here’s the output generated by using the preceding SQL statement with the MODELclause (the new data created by the MODEL clause is shown in boldface here):

COUNTRY PRODUCT YEAR SALES-------------------- --------------- ---------- ----------Mexico Kleenex 2002 2474.78Mexico Kleenex 2003 4333.69Mexico Kleenex 2004 4846.3Mexico Kleenex 2005 9179.99Mexico Pampers 2002 15215.16Mexico Pampers 2003 29322.89Mexico Pampers 2004 81207.55Mexico Pampers 2005 81207.55Mexico All_Products 2005 90387.54

16 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:52 PM

Color profile: DisabledComposite Default screen

Page 530: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Canada Kleenex 2002 2961.3Canada Kleenex 2003 5133.53Canada Kleenex 2004 6303.6Canada Kleenex 2005 11437.13Canada Pampers 2002 22161.91Canada Pampers 2003 45690.66Canada Pampers 2004 89634.83Canada Pampers 2005 89634.83Canada All_Products 2005 101071.96

The SELECT clause first retrieves the product, year, and sales data for the twocountries (Mexico and Canada) and feeds it into the MODEL clause. The MODELclause takes this raw data and rearranges it into a multidimensional array, based onthe values of the PARTITION BY (country) and DIMENSION BY (product andyear) clauses. After the MODEL clause creates the array, it applies the three formulaslisted under the RULES clause to the data. It finally produces the resulting row data,after ordering it by country, product, and year.

Note that the MODEL clause shows the original table or view data, as well as thenew data that the MODEL clause has calculated from the three rules supplied in theMODEL clause. The MODEL clause applies the rules within each partition of data.

CERTIFICATION OBJECTIVE 11.04

Materialized View EnhancementsMaterialized views have storage structures like regular Oracle tables, and they are usedto hold aggregate or summary data. One of the biggest advantages of materialized viewsis that you can use them to precompute joins on commonly used tables, called the detailtables. Expensive joins and aggregates are precomputed and stored by Oracle in materializedviews, also referred to as summaries. These materialized views are transparent to the endusers, who still address the detailed base tables in their queries. The Oracle optimizerknows when a materialized view would offer superior results compared with addressingthe base tables directly. Oracle uses the query-rewriting mechanism behind the scenesto automatically rewrite a user’s query if it thinks that using a materialized view wouldgive faster results.

A materialized view can include aggregations like SUM, COUNT(*), MAX, MIN,and any number of joins. You may index materialized views as well. If you aren’t sure

Materialized View Enhancements 17

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:52 PM

Color profile: DisabledComposite Default screen

Page 531: OCA OCP - Oracle10G New Features For Administrators Exam Guide

18 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

which materialized view to create, you can use the SQL Access Advisor to help youdesign and evaluate materialized views.

Once you create a materialized view, you have two main concerns:

■ Refreshing the materialized views so they contain the latest data

■ Ensuring that your query rewrite mechanism will use the materialized viewto rewrite queries

In the next two sections, we’ll look at the fast refresh feature and query rewritingmechanisms, and then look at the new Oracle Database 10g procedure that helpsyou optimize your materialized views.

Materialized View Fast Refresh FeatureData in the base (detail) tables of a materialized view changes over time, due to variousDML operations. Thus, a materialized view should be refreshed frequently to keep up withthe changes in the underlying tables. There are several ways to refresh a materialized view.One of the best ways is to use the fast refresh method, which applies incremental changesto refresh materialized views. The fast refresh method of updating materialized viewsrelies on the use of materialized view logs. Materialized view logs are created on theunderlying base tables, not on the materialized views themselves.

Here is a basic materialized view log creation statement:

SQL> CREATE MATERIALIZED VIEW LOG ON sales WITH ROWID(prod_id, cust_id, time_id, channel_id, promo_id, quantity_sold, amount_sold)INCLUDING NEW VALUES;

The following are some of the importantrestrictions on using the fast refresh method(note that some restrictions are general; othersare specific to the type of materialized view—whether it is based on aggregates or joins):

■ The materialized view must not use SYSDATE,ROWNUM, RAW, or LONG datatypes.

■ A materialized view can’t have GROUP BY clauses.

■ You must include the ROWIDs of all the tables in the FROM list in theSELECT list of the query.

■ You must have materialized view logs with ROWIDs for all the base tables.

For fast refresh ofmaterialized views, the definition ofthe materialized view logs must normallyspecify the ROWID clause.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:52 PM

Color profile: DisabledComposite Default screen

Page 532: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

The Query Rewrite FeatureAutomatic query rewriting is the key feature that makes materialized views a faster meansof processing complex data warehousing-type queries compared to the direct use of the basetables. Oracle takes your query against the base tables and rewrites it to use the underlyingmaterialized views, if Oracle’s query optimizer decides it’s a faster way to return the queryresults. However, query rewriting is not guaranteed, and Oracle fails to rewrite queries onoccasion. When this happens, Oracle can’t use the underlying materialized views.

In order to ensure a query rewrite, a query must meet the following conditions:

■ QUERY_REWRITE_ENABLED = TRUE (the default value in OracleDatabase 10g)

■ The underlying materialized views must be enabled for query rewrite, byusing the ENABLE QUERY REWRITE clause. You can specify this clauseeither with the ALTER MATERIALIZED VIEW statement or when youcreate the materialized view.

■ You must set the query rewrite integrity level appripriately by specifyingthe relevant value for the QUERY_REWRITE_INTEGRITY parameter.For example, if a materialized view is not fresh you set query rewrite integrityto ENFORCED, then Oracle won’t use the materialized view. To enablequery rewrite in this situation and cases where you have constraints thathaven’t been validated, you need to set the integrity level to a less restrictivlevel of granularity such as TRUSTED or STALE_TOLERATED.

■ The database must be able to drive either all or part of the results requestedby the query from the precomputed result stored in the materialized view.

Here’s a brief list of the important restrictions on using the query rewrite feature:

■ You can’t refer to any RAW or LONG RAW datatypes and object REFs.

■ You can’t use any nonrepeatable expressions like SYSDATE and ROWNUM.

■ If you include a column or expression in the GROUP BY clause, it must alsobe a part of the SELECT list.

Materialized View Enhancements 19

In Oracle Database 10g,the ENABLE_QUERY_REWRITE parameteris TRUE by default. You must, however,ensure that the OPTIMIZER_FEATURES_

ENABLE initialization parameter is set to10.0.0 or higher. The QUERY_REWRITE_INTEGRITY initialization parameter stillhas the same default value (ENFORCED).

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:53 PM

Color profile: DisabledComposite Default screen

Page 533: OCA OCP - Oracle10G New Features For Administrators Exam Guide

20 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

The SQL Access Advisor can help you by suggesting ideal materialized views forthe detail tables in a query, and this advisor can also help you create the materializedviews. Once you create the materialized views, you can use various procedures ofthe DBMS_MVIEW package to optimize your materialized views. Here is a summaryof the two key procedures of the DBMS_MVIEW package that help in understandingthe capabilities of materialized views and potential materilaized views, especiallyconcerning rewrite availability:

■ EXPLAIN_MVIEW This procedure tells you what kinds of query rewritesare posible. It will also tell you why a certain materialized view isn’t fastrefreshable.

■ EXPLAIN_REWRITE This procedure tells you why a query failed torewrite. If the query rewrites, the procedure will tell you which materializedviews will be used

The DBMS_ADVISOR package offers you thenew procedure TUNE_MVIEW, which you canuse in the SQL Access Advisor. ?This is a newOracle Database 10g procedure that helps youalter a materialized view to ensure query rewritingwherever it is possible. The procedure will letyou decompose a materialized view into twoor more materialized views or to restate thematerialized view in a way that is more conduciveto a fast refresh and query rewrite.

The DBMS_ADVISOR.TUNE_MVIEW procedure will optimize the materializedview in such a way that it can use several types of query rewrites. This procedure willalso provide you with the necessary statements to ensure a fast refresh. Let’s look atthe DBMS_ADVISOR.TUNE_MVIEW procedure in detail in the following section.

Materialized View Optimizationwith the TUNE MVIEW Procedure

The new Oracle Database 10g TUNE_MVIEW procedure of the DBMS_ADVISORpackage helps you in fixing problematic materialized views, where either a fast refreshor a query rewrite is not happening as you would like. The procedure takes a CREATE

The DBMS_ADVISOR.TUNE_MVIEW procedure recommendsmaterialized views with optimized definingqueries, decomposition of nonrefreshablematerialized views, and fixes for materializedview log problems.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:53 PM

Color profile: DisabledComposite Default screen

Page 534: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Materialized View Enhancements 21

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

MATERIALIZED VIEW as its input and performs the following materialized viewtuning functions:

■ Redefine materialized views so they refresh fast as well as use query rewrite, ifthe materialized views are currently not using these features for some reason.

■ Fix materialized view log problems that may be keeping the view from usingthe fast refresh mechanism. These problems include verifying that a materializedview log exists in the first place. If the materialized view log exists, it may haveproblems, like missing columns, which prevent its use by a materialized view.

■ If a materialized view turns out to be nonrefreshable, break it up intosubmaterialized views that are eligible for a fast refresh. The parent materializedview can then reference the submaterialized views, thus getting around itsinability to refresh fast.

If a materialized view isn’t fast refreshable, the data in the materialized view willbecome stale, thus making your queries progressively worthless. When you find thata materialized view isn’t fast refreshable, it’s usually because one or more of the fastrefresh restrictions aren’t satisfied. The DBMS_ADVISOR.TUNE_MVIEW procedureprovides you with the necessary SQL statements that you need to implement to ensurethat you can fast refresh your materialized views.

The DBMS_MVIEW.EXPLAIN_MVIEW procedure tells you why you can’t refresha materialized view. The DBMS_ADVISOR.TUNE_MVIEW procedure tells youhow to make the materialized view eligible for a fast refresh. In addition, theDBMS_ADVISOR.TUNE_MVIEW procedure also makes recommendations toenable a query rewrite.

You use the DBMS_ADVISOR.TUNE_MVIEW procedure as follows, either beforecreating a new materialized view or when you are tuning an existing materialized view:

begindbms_advisor.tune_mview (:task_name,‘CREATE MATERIALIZED VIEW test_mvREFRESH FAST WITH ROWID ENABLE QUERY REWRITEAS SELECT DISTINCT prod_name, prod_typeFrom products’);end;

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:53 PM

Color profile: DisabledComposite Default screen

Page 535: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The preceding code will populate the new DBA_TUNE_MVIEW view, which you mustquery to see how you can change your materialized view to make it fast refreshable aswell as capable of using query rewrite. The DBA_TUNE_MVIEW view has the followingstructure:

SQL> desc dba_tune_mviewName Null? Type----------------------------------------- -------- -------------OWNER VARCHAR2(30)TASK_NAME VARCHAR2(30)ACTION_ID NOT NULL NUMBERSCRIPT_TYPE VARCHAR2(14)STATEMENT CLOBSQL>

You use the TASK_NAME column value to identify and query a particular TUNE_MVIEW recommendation. (Make sure you provide a value for the TASK_NAMEvariable that I highlighted in the previous PL/SQL code block.) The ACTION_IDcolumn shows the command order number. The SCRIPT_TYPE column can takevalues of CREATE or DROP (or UNKNOWN). The CREATE value is for the newmaterialized view recommendation. The DROP value shows the materialized viewthat the TUNE_MVIEW procedure wants you to drop. The STATEMENT column ofthe view shows the recommended materialized view changes that make your materializedview eligible for a fast refresh and a query rewrite. If you wish, you can use the DBMS_ADVISOR.GET_TASK_SCRIPT procedure to output the recommendations to atext file.

Here’s the basic syntax of a query on the DBA_TUNE_MVIEW view:

SQL> select statementfrom dba_tune_mviewwhere task_name = :task_nameorder by script_type, action_id;

If the original materialized view statement isn’t eligible for fast refresh, the DBMS_ADVISOR.TUNE_MVIEW procedure suggests an alternate way of defining yourmaterialized view. In this case, the DBMS_ADVISOR.TUNE_MVIEW proceduremight recommend the following changes to make your materialized view eligiblefor a fast refresh of its materialized view logs. (Note that the new materialized viewrecommendation replaces the DISTINCT clause in the original materialized viewwith the COUNT(*) and GROUP BY clauses.)

22 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:54 PM

Color profile: DisabledComposite Default screen

Page 536: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SQL> create materialized view test_mvrefresh fast with rowid enable query rewriteas select prod_type t,

prod_name p, count(*)from productsgroup by prod_type, prod_name

Let’s look at a couple of examples that illustrate how you can use the DBMS_ADVISOR.TUNE_MVIEW procedure to enable the fast refresh of a recalcitrantmaterialized view.

Creating Materialized View LogsAs you know, one of the restrictions on the fast refresh feature is that you must includethe ROWIDs of all tables that are in the FROM list in your SELECT list. Thus, if acertain statement fails due to noninclusion of the ROWIDs of the tables in the FROMlist, the DBMS_ADVISOR.TUNE_MVIEW procedure will suggest the inclusion of theROWIDs, as shown in the following example.

SQL> create materialized view test_mvbuild immediate refresh fast enable query rewriteas select e.ROWID r1, d.ROWID r2,e.first_name, d.department_namefrom departments d, employees ewhere e.department_id = d.department_id;

The third line shows how you can use the ROWIDs to modify the materializedview. This materialized view will now be eligible for query rewrite, as long as youmake sure that you create the following pair of materialized view logs, one for eachof the tables in the materialized view.

SQL> create materialized view log onemployeeswith sequence, rowidincluding new values;

SQL> create materialized view log on departmentswith sequence, rowid including new values

Decomposing Materialized ViewsSometimes, a materialized view isn’t fast refreshable because it violates one of therestrictions for a fast refresh, like having an unflattenable inline view. In cases likethis, the TUNE_MVIEW procedure helps you by making recommendations for thedecomposition of the materialized view into two nested submaterialized views.

Materialized View Enhancements 23

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:54 PM

Color profile: DisabledComposite Default screen

Page 537: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The parent materialized view will refer to the submaterialized view that you create.Again, you must create materialized view logs on each of the tables in the materializedview in order to make it eligible for the fast refresh feature. The following types of situationscall for a materialized view decomposition:

■ A subquery in the WHERE clause

■ Use of set operations like UNION, UNION ALL, INTERSECT, and MINUS

■ Use of inline views

Partition Change Tracking EnhancementsYou generally use materialized views in a data warehouse setting. Thus, it’s no surpisethat many materialized views will have partitioned base tables, since data warehousetables are large, and hence, usually partitioned. Oracle’s partition change tracking (PCT)feature lets you figure out which rows of a materialized view are affected by a change ina base table’s partitioning. Why is this ability important? Well, Oracle doesn’t performa query rewrite on a materialized view it considers stale, and it considers a materializedview stale if the base table partitioning has changed.

The PCT feature, by maintaining links to table partitions and materialized viewrows, helps the materialized views handle the aftermath of a partitioning change inthe base tables. By enabling Oracle to consider only a part of a materialized view asstale, PCT will enable the use of the query rewrite feature by letting it use those rowsthat are still fresh, provided you use the QUERY_REWRITE_INTEGRITY=ENFORCEDor TRUSTED mode.

Any time you change a base table’s partition scheme, the relevantmaterialized view rows become stale.

In Oracle Database 10g, there are severalenhancements with regard to the PCT feature.Let’s briefly review these enhancements in thefollowing sections.

List-Partitioning SchemeIn previous versions, you could use the PCT

feature only for partitioned base tables using the range and range-hash partitioningschemes. Now, you can also use it for detail tables using the list-partitioning scheme.

24 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

A PCT-based materializedview refresh will minimize the amout ofrefreshes and maximize the use of thequery rewrite feature.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:55 PM

Color profile: DisabledComposite Default screen

Page 538: OCA OCP - Oracle10G New Features For Administrators Exam Guide

ROWID Columns as Partition MarkersMaterialized view joins sometimes make ROWID references in their defining queriesYou can now use a ROWID column as a PCT column in order to help identify tablepartitions during a PCT refresh.

Join DependencyYou can now use a PCT-based refresh if your MVcontains a join-dependent expression of one of itstables. A table is a join-dependent table if youequijoin it with a partitioned base table on itspartioning key column. An expression consistingof columns from the resulting equijoin is a join-dependent expression.

Truncating Materialized View PartitionsIn previous versions, PCT used DELETE statements to remove materialized views. InOracle Database 10g, the database truncates materialized view partitions, as long as thefollowing conditions apply:

■ You are limited to range partitioning only (for both the base tables andthe materialized view), and the partitioning bounds must be the same for thematerialized view and its base tables.

■ There should be a one-to-one relationship between the two sets of partitions(base table paritions and the materialized view partitions).

■ You must partition the materialized view on its single PCT key column.

■ You shouldn’t refresh on the basis of atomic transactions.

Forcing a RefreshThe PCT feature automatically refreshes your materialized view when there are partitionmaintenance operations in the underlying base tables. However, you may sometimes wishto manually use a PCT-based refresh, even in the absence of any base table partitioningscheme modifications. The DBMS_MVIEW.REFRESH procedure has a new option, P,to indicate a forced PCT-based refresh. Here’s the syntax:

execute dbms_mview.refresh(mview_name, method =>’P’)

Materialized View Enhancements 25

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

Oracle Database 10gextends the use of PCT to list-partitionedtables, enables the use of ROWID columnsas partition markers, and lets you use aPCT refresh if a materialized view containsa join-dependent expression.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:55 PM

Color profile: DisabledComposite Default screen

Page 539: OCA OCP - Oracle10G New Features For Administrators Exam Guide

26 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

Other Materialized View EnhancementsIn addition to the introduction of the TUNE_MVIEW procedure to help with the fastrefresh and query rewrite features, and improvements to the PCT feature, OracleDatabase 10g provides several other enhancements related to materialized views.I summarize these enhancements in the following sections.

Materialized View Execution PlansIn Oracle Database 10g, both the plan tableused by the explain plan feature and theV$SQL_PLAN view will show you if a particular query is using a materialized view.In Oracle Database 10g, you can find out if a materialized view was accessed directlyor if Oracle rewrote the query in order to use the materialized view. The new feature

here is that now you can clearly tell if Oracle isusing a materialized view as a result of a queryrewrite or because the programmer specified it.

Here’s an example that shows an executionplan that indicates how a materialized view isbeing used as result of the query rewrite. If youdon’t see the keyword REWRITE, it means thatthe materialized view was accessed directly.

Query PlanSELECT STATEMENTSORT ORDER BYMATERIALIZED VIEW REWRITE ACCESS FULL EMP_INFO

The REWRITE_OR_ERROR HintIf a planned query rewrite doesn’t take place,Oracle will end up running the original query.Since the whole point of rewriting the query wasto make a slow query fast, you may not want thisto happen. Oracle Database 10g contains a new

optimizer hint called REWRITE_OR_ERROR, which forces a query to error out if itcan’t rewrite the query:

select /*+ REWRITE_OR_ERROR */

Instead of running the original query, the hint throws the following error andstops the execution of the SQL statement.

ORA-30393: A query block in the statement did not rewrite

The explain plan featureshows you whether a materialized viewis being accessed as a result of a queryrewrite or because you specified directmaterialized view access.

The REWRITE_OR_ERROR hint stops the execution of a SQLstatement if a query doesn’t rewrite.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:56 PM

Color profile: DisabledComposite Default screen

Page 540: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Materialized View Enhancements 27

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

New Columns in the REWRITE_TABLEIn the previous section, you saw how a REWRITE_OR_ERROR hint will stop theexecution of a query that failed to rewrite. In cases like this, you can use the DBMS_MVIEW.EXPLAIN_REWRITE procedure to find out why the query failed to rewrite(the procedure also tells you which materialized view will be used if the query doesrewrite). Using the output from the execution of this procedure, you can find outwhat you need to do in order to make the query rewrite, if that is at all possible.

Following is the syntax for using the EXPLAIN_REWRITE procedure. Note thatthis version is for when you want to create a table to hold the procedure’s output.You can also use a VARRAY instead of a table if you want to access the procedure’soutput directly.

dbms_mview.explain_rewrite (query IN [VARCHAR2 | CLOB],mv IN VARCHAR2,statement_id IN VARCHAR2;

To obtain the output into a table, you must run the utlxrw.sql script (locatedin the $ORACLE_HOME/rdbms/admin directory) before calling EXPLAIN_REWRITE. This script creates a table named REWRITE_TABLE in the currentschema.

In order to view the results of the EXPLAIN_REWRITE procedure, first createthe REWRITE_TABLE table, using the utlxrw.sql script, as shown here:

SQL> @c:\oracle\product\10.1.0\Db_1\RDBMS\ADMIN\utlxrw.sqlTable created.SQL>

Here’s the structure of the REWRITE_TABLE:

SQL> desc rewrite_tableName Null? Type----------------------------------------- -------- -----------------------STATEMENT_ID VARCHAR2(30)MV_OWNER VARCHAR2(30)MV_NAME VARCHAR2(30)SEQUENCE NUMBER(38)QUERY VARCHAR2(2003)MESSAGE VARCHAR2(512)PASS VARCHAR2(3)MV_IN_MSG VARCHAR2(30)MEASURE_IN_MSG VARCHAR2(30)JOIN_BACK_TBL VARCHAR2(30)JOIN_BACK_COL VARCHAR2(30)

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:56 PM

Color profile: DisabledComposite Default screen

Page 541: OCA OCP - Oracle10G New Features For Administrators Exam Guide

28 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

ORIGINAL_COST NUMBER(38)REWRITTEN_COST NUMBER(38)FLAGS NUMBER(38)RESERVED1 NUMBER(38)RESERVED2 VARCHAR2(10)

Four REWRITE_TABLE columns are new in Oracle Database 10g:

■ JOIN_BACK_TBL provides the name for the table with which a join backoperation was performed in the materialized view.

■ JOIN_BACK_COL provides the name of the column involved in the joinback operation.

■ ORIGINAL_COST shows the cost of the prematerialized view query.

■ REWRITTEN_COST is the cost of the rewritten query, if there was one.If not, this column will be zero.

The MESSAGE column shows the EXPLAIN_REWRITE procedure errormessage. If it contains multiple materialized views, you’ll see a separate row foreach materialized view.

Materialized Join View EnhancementsOracle Database 10g contains enhancements to materialized join views (MJVs), whichcontain only joins (and not aggregates). In Oracle Database 10g, you can now conducta fast refresh of a materialized join view, under the following conditions:

■ If the materialized join view contains a self join in its FROM clause, you mustinclude the ROWID columns for each instance in the SELECT list. Thematerialized join view log must contain all the ROWID coumns as well.

■ If the materialized join view has an inline view (or a named view), thedatabase must be able to perform complete view merging. Once the viewmerging is done, the SELECT list must have the ROWID columns for all thetables in the FROM clause.

The REWRITTEN_COSTcolumn of the REWRITE_TABLE shows thecost for any materialized view that wasused in a query rewrite. The column will

show a zero if there was no rewrite of aquery or if a diffent materialized view wasused, even if there was a query rewrite.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:56 PM

Color profile: DisabledComposite Default screen

Page 542: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Materialized View Enhancements 29

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

■ If you are dealing with remote tables in materialized join views, make surethat all of the tables are on the same site. The SELECT list must have theROWID columns for all the tables in the FROM clause.

Partition Maintenance OperationsIn previous versions of Oracle, when dealing with partitioned materialized views, youneeded to perform partition maintenance operations by using the ALTER TABLEcommands against the materialized view container tables, rather than the materializedviews themselves. In Oracle Database 10g, you can issue commands that truncate,exchange, or drop partitions by using the ALTER MATERIALIZE VIEW statement.For example, you can drop a partition from a partitioned materialized view in thefollowing manner:

alter materialized view <mv_name>drop partition <partition_name>

Materialized View Refresh Using Trusted ConstraintsOracle doen’t enforce functional dependencies in dimensions. Similarly, it doesn’tenforce primary key and foreign key relationships that are RELY constraints. As aresult of this behavior, when you refresh a materialized view, you may end up withinconsistent results.

When you create a materialized view, you can specify the policy that Oracleshould adopt when it encounters constraints during a materialized view refresh.If you use the ENFORCED option, Oracle won’t refresh any materialized view withconstraint violations. If you use the TRUSTED constraints option, on the other

hand, Oracle will perform a materialized viewrefresh. However, Oracle will set the new columnUNKNOWN_TRUSTED_FD in the DBA_MVIEWS view to a value of Y following therefresh. This indicates that the materialized viewis now in an unknown state, because it usedtrusted functional dependencies that were notenforced by Oracle during the refresh process.

For a fast refresh ofmaterialized join views—whether they useself joins, inline views, or remote tables—you must create materialized view logs on

each of the base tables. The materializedview logs must also contain the ROWIDcolumn.

If you use the TRUSTEDoption, the resulting materialized viewsare in an unknown state, and you can usethem for a query rewite in a TRUSTED ora STALE_TOLERATED mode only.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:57 PM

Color profile: DisabledComposite Default screen

Page 543: OCA OCP - Oracle10G New Features For Administrators Exam Guide

30 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

CHAPTER SUMMARYThis chapter started by reviewing the two new enhancements to the MERGE commandin a SQL statement. You then learned about the difference between dense and sparsedata, and how to densify data using the new partitioned outer join enhancement.

The SQL MODEL clause offers you tremendous analytical capabilities when dealingwith interrow calculations in a data warehouse setting. This chapter provided a basicreview of the MODEL clause enhancement, after first reviewing some essential datawarehousing concepts.

The exam will test your knowledge of theenhancements to the DBMS_ADVISORpackage. You must understand how the newTUNE_MVIEW procedure helps fast refreshand query rewrite when you use materializedviews. You must remember the specific waysin which the TUNE_MVIEW procedure canhelp in tuning materialized views (decompositionof nonwritable materialized views, for example).Under what conditions is it good to decomposea materialized view? How does the TUNE_MVIEW procedure contributein promotinga fast refresh of a query? You must also beconversant with the important procedures ofthe DBMS_MVIEW package. What does theEXPLAIN_MVIEW procedure help you do?

The exam will test your knowledge of theMERGE statement enhancements. Exactlywhat rows will the DELETE clause delete ina MERGE statement?

You most likely are going to encounter aquestion on the new partitioned outer joinfeature. Know that it is simply an extensionof the outer join feature in previous versions.

The MODEL clause is too important not tobe touched by the exam. You must thoroughlyunderstand the concepts of partitions, measures,and dimensions. What role do rules play in aMODEL clause? What are the default semanticsof rules in a MODEL clause (UPSERT)? Whatis the difference between sequential order andautomatic order when you are evaluating a setof rules?

Expect a question about the PCT featureon the exam. What enhancements has Oracleintroduced for PCT in Oracle Database 10g?What are the preconditions for using theTRUNCATE PARTITION command whenyou are performing PCT operations?

You must know how to enable the automaticquery rewriting feature in Oracle Database 10g(hint: it is automatic!). What hint will stopquery execution if the query fails to rewrite?Expect a query on materialized join views aswell. What are the conditions under whichOracle supports fast refresh for materializedjoin views?

INSIDE THE EXAMINSIDE THE EXAM

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:57 PM

Color profile: DisabledComposite Default screen

Page 544: OCA OCP - Oracle10G New Features For Administrators Exam Guide

There are several important Oracle Database 10g enhancements pertaining tomaterialized views. Important among these is the new TUNE_MVIEW procedure ofthe DBMS_ADVISOR package. You saw how you can ensure (almost!) a fast refreshof materialized views, as well as increase query rewrites using the DBMS_ADVISOR.TUNE_MVIEW procedure. You also reviewed materialized join view enhancements,materialized view refreshing using trusted constraints, and PCT enhancements.

Materialized View Enhancements 31

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:57 PM

Color profile: DisabledComposite Default screen

Page 545: OCA OCP - Oracle10G New Features For Administrators Exam Guide

32 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

✓TWO-MINUTE DRILL

Enhancements in the MERGE Statement❑ The MERGE statement enables you to perform conditional update and insert

operations when loading data from a source table into another table.

❑ In Oracle Database 10g, you can use a WHERE clause in a MERGE statement’sUPDATE or INSERT clause to conditionally update or insert data.

❑ In addition to the INSERT and UPDATE clauses, you can now use a DELETEclause in a MERGE statement.

❑ The DELETE clause in a MERGE statement will delete only rows included injoin condition (specified by the ON clause).

❑ The DELETE clause of the MERGE statement evaluates only the post-updatedvalues of rows.

Using Partitioned Outer Joins❑ The partitioned outer join is an extension of the Oracle SQL outer join concept.

❑ Fact tables contain the data of an organization, and dimension tables containdescriptions of the dimensions you use to categorize data into meaningful entities.

❑ Dimension tables are organized on a hierarchical basis, enabling you to performroll up and drill down operations.

❑ The analytical process follows a processing order consisting of the grouping,calculation (analysis), and output ordering steps.

❑ Dense data doesn’t contain gaps in any of the dimensional cells.

❑ Sparse data is data that contains no values for some combinations of dimensionvalues.

❑ Sparse data presents analytical and report formatting problems.

❑ Dense data leads to better-performing analytical queries, especially when you’redealing with time-series data.

❑ Partitioned outer joins help turn sparse data into dense data by replacing missingvalues in the data.

❑ You create a partitioned outer join by adding the PARTITION BY clause tothe outer join clause.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:58 PM

Color profile: DisabledComposite Default screen

Page 546: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Two-Minute Drill 33

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

Using the SQL MODEL Clause❑ The SQL MODEL clause provides you with spreadsheet-like output capabilities.

❑ The MODEL clause provides interrow and interarray analytical capabilities.

❑ The MODEL clause enables you to perform symbolic cell addressing and symbolicarray computations.

❑ The MODEL clause doesn’t change table data, unless you explicitly use aseparate UPDATE, INSERT, or MERGE statement to modify table data withthe MODEL clause’s output.

❑ The MODEL clause first creates multidimensional arrays from the raw dataderived from using the initial SELECT statement.

❑ Oracle uses partitions, measures, and dimensions to derive the multidimensionaldata arrays from table data.

❑ The MODEL clause then applies simple or complex business rules to the arraydata, using rules that you can specify.

❑ A rule is any business rule or formula that you apply to the array data derivedby the MODEL clause.

❑ A rule can update or insert data. The default rule semantics at the MODELlevel use the UPSERT operation.

❑ You can use UPDATE instead of the default UPSERT rule semantics.

❑ If you specify a rule level option, it will override an option specified at therules level.

❑ You can specify sequential order or automatic order for evaluating multiplerules in a MODEL clause.

❑ Sequential order is the default rule processing order.

❑ The RETURN UPDATED ROWS clause will return only any new values createdby the MODEL clause.

❑ The MODEL clause output shows both the original data and the data that theMODEL clause has inserted or updated.

Materialized View Enhancements❑ Oracle Database 10g enables query rewriting by default.

❑ The DBMS_MVIEW.EXPLAIN_REWRITE procedure tells you why Oracleisn’t rewriting a query to take advantage of an existing materialized view.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:58 PM

Color profile: DisabledComposite Default screen

Page 547: OCA OCP - Oracle10G New Features For Administrators Exam Guide

34 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

❑ The DBMS_ADVISOR.TUNE_MVIEW procedure helps fast refresh a materializedview, as well as enhance query rewriting.

❑ The DBMS_ADVISOR.TUNE_MVIEW procedure helps in fixing problemswith materialized view logs.

❑ The DBMS_ADVISOR.TUNE_MVIEW procedure also can suggest breakingup a materialized view into submaterialized views to ensure a fast refresh ofthe parent materialized view.

❑ The DBA_TUNE_MVIEW view contains the results of executing the TUNE_MVIEW procedure.

❑ The STATEMENT column of the DBA_TUNE_MVIEW view shows therecommended materialized view changes.

❑ The DBMS_ADVISOR.TUNE_MVIEW procedure can suggest that you includethe ROWIDs of all tables in the SELECT list of a materialized view.

❑ A materialized view decomposition into parent and submaterialized viewsmay be called for when you have subqueries in the WHERE clause or use aninline view which you can’t flatten.

❑ The EXPLAIN PLAN statement will now show you if the materialized viewuse is because of a query rewrite or developer specification.

❑ The new REWRITE_OR_ERROR hint stops the execution of a SQL statementif query rewriting doesn’t take place.

❑ There are four new columns in the REWRITE_TABLE to help you figure outthe cost of an original and rewritten query.

❑ Once you create materialized view logs with a ROWID column, you can nowconduct a fast refresh of a materialized view join that contains self joins, inlineviews, or remote tables.

❑ You can directly use the ALTER MATERIALIZED VIEW statement to performpartitioning maintenance operations on partitioned materialized views.

❑ Oracle will conduct a fast refresh when dealing with trusted constraints, but itwill put the materialized view into an unknown state.

❑ You must use the TRUSTED or STALE_TOLERATED mode when dealingwith materialized views that are in an unknown state due to the use of trustedfunctional dependencies and constraints.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:57:59 PM

Color profile: DisabledComposite Default screen

Page 548: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Two-Minute Drill 35

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

❑ The partition change tracking (PCT) feature is now applicable to list-partitionedtables or when your materialized view contains join-dependent expressions.

❑ PCT operations truncate data now, instead of deleting it.

❑ You can now manually use a PCT-based refresh, even in the absence of partitionoperations, by specifying the new option when executing the DBMS_MVIEW.REFRESH procedure.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:58:00 PM

Color profile: DisabledComposite Default screen

Page 549: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SELF TESTThe following questions will help you measure your understanding of the material presented in thischapter. Read all the choices carefully because there might be more than one correct answer.Choose all correct answers for each question.

Enhancements in the MERGE Statement

1. What does the MERGE statement do if an identical row already exists in the table?

A. It deletes the existing row first.B. It inserts the duplicate row.C. The MERGE operation fails with an error message.D. It performs an update, although there won’t be any difference in the row ultimately.

2. When using the MERGE statement, what will the DELETE clause delete?

A. All rows that satisfy the DELETE clause’s WHERE conditionB. All rows that satisfy the DELETE clause’s WHERE condition, provided they have been

updated by the UPDATE clauseC. All rows that satisfy the DELETE clause’s WHERE condition, provided they have been

newly inserted by the INSERT clauseD. All rows that fail to satisfy the UPDATE clause

3. Which one of the three clauses—INSERT, DELETE, and UPDATE—fires first in a MERGEstatement if all three of them are present?

A. INSERT clauseB. DELETE clauseC. UPDATE clauseD. Depends on the order in which you specify the three operations

4. Which rows will the DELETE clause in a MERGE statement delete?

A. Rows modified by the UPDATE clauseB. Rows inserted by the INSERT clauseC. Rows neither updated nor inserted by the MERGE statementD. Rows selected by the WHERE clause embedded inside the INSERT clause

36 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:58:00 PM

Color profile: DisabledComposite Default screen

Page 550: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test 37

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

Using Partitioned Outer Joins

5. The partitioned outer join is especially beneficial for which type of data?

A. Time-series dataB. Cross-section dataC. Summary dataD. Analytical data

6. What can the output of a partitioned outer join be considered as?

A. UNION of several outer joins, each join being between a partition and the other table(s) inthe join

B. UNION of several equijoins, each join being between a partition and the other table(s) inthe join

C. UNION of several self joins, each join being between a partition and the other table(s) inthe join

D. UNION of several inner joins, each join being between a partition and the other table(s) inthe join

7. Which of the following is true when you densify sparse data by using partitioned outer joins?

A. The missing data must be filled in by zeros.B. You can use the IGNORE NULLS clause with the LAST_VALUE function to replace the

missing values with the most recent non-NULL value in that column.C. The missing data must be filled in by NULLs.D. You must provide the missing data by updating the column with the missing values.

8. What will the PARTITION BY clause in a partitioned outer join statement do?

A. Partition the underlying table, using Oracle’s partitioning optionB. Partition the output rows into equal segmentsC. Partition the table into equal subpartitionsD. Partition the rows in the output based on the expression your provide within the clause

Using the SQL MODEL Clause

9. What is symbolic cell addressing?

A. The way the MODEL clause makes statistical calculationsB. The way the MODEL clause addresses statistical symbols

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:58:01 PM

Color profile: DisabledComposite Default screen

Page 551: OCA OCP - Oracle10G New Features For Administrators Exam Guide

38 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

C. The way the MODEL clause addresses the individual cells of an arrayD. The way the MODEL clause addresses the rules

10. What can you derive by using a MODEL clause?

A. Both updated and deleted dataB. Both updated and newly created dataC. Only updated dataD. Only newly changed data

11. By default, the RULES keyword operates with which specification?

A. UPDATE specificationB. INSERT specificationC. UPDATE and UPSERT specificationsD. UPSERT specification

12. What will the RETURN UPDATED ROWS keyword in a MODEL clause do?

A. Return only the new rows, not the updated rowsB. Return only the updated rows, not the new rowsC. Return both the updated and the new rowsD. Return all rows that are going to be deleted

Materialized View Enhancements

13. What does the fast refresh method of updating materialized views always use?

A. Incremental changesB. Decomposed submaterialized viewsC. Query rewriteD. Materialized view logs

14. Under some conditions, for fast refresh to occur, which of the following must be true?

A. Materialized view logs must specify the ROWID clause.B. The materialized view must use GROUP BY clauses.C. The materialized view must use ROWIDs.D. The materialized view must use ROWNUMs.

15. Which of the following will tell you why a certain materialized view isn’t fast refreshable?

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:58:01 PM

Color profile: DisabledComposite Default screen

Page 552: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test 39

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

A. EXPLAIN_REWRITE procedureB. TUNE_MVIEW procedureC. MVIEW_EXPLAIN procedureD. EXPLAIN_MVIEW procedure

16. What does the TUNE_MVIEW procedure do?

A. Automatically creates any necessary materialized view logsB. Recommends the creation of any necessary materialized view logsC. Automatically creates the materialized viewD. Automatically conducts a fast refresh of a materialized view

17. What does the DBA_TUNE_MVIEW view show?

A. The results of executing the TUNE_MVIEW procedureB. The output of the CREATE_MVIEW procedureC. The output of the EXPLAIN_MVIEW procedureD. The output of both the TUNE_MVIEW and EXPLAIN_MVIEW procedures

18. Which of the following helps you identify your statement in the DBA_TUNE_MVIEW view?

A. The STATEMENT variableB. The STATEMENT_ID columnC. The VIEW_ID columnD. The TASK_NAME variable

19. What does the REWRITE_OR_ERROR hint do?

A. Rewrites the query if it doesn’t lead to any errorsB. Stops executing a query if it can’t rewrite itC. Sends out a report of all the rewrite errorsD. Enforces a query rewrite even if it leads to an error

20. In Oracle Database 10g, which of the following is true regarding the partition change trackingfeature?

A. It has been extended to Oracle partitions.B. It has been extended to rule partitioning.C. It has been extended to hash partitioning.D. It has been extended to list partitioning.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:58:01 PM

Color profile: DisabledComposite Default screen

Page 553: OCA OCP - Oracle10G New Features For Administrators Exam Guide

40 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

LAB QUESTIONCompare the results of a regular outer join with the new partitioned outer join. For this lab exercise,you need to use the SH schema in the sample schemas supplied by Oracle as part of your Oraclesoftware.

1. Create a small table with sales data for various years for two products.

2. Create another table with just time data, so you can join the first table with this one.

3. Use a traditional outer join and check the results.

4. Use a partitioned outer join and compare its results with those from step 3.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:58:01 PM

Color profile: DisabledComposite Default screen

Page 554: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

SELF TEST ANSWERS

Enhancements in the MERGE Statement

1. � D. The MERGE statement will perform the update, but the row will not change its values.� A is wrong because the MERGE statement always performs an UPDATE operation first. B iswrong because the INSERT statement doesn’t fire. C is wrong because the existence of an identicalrow will not lead to any errors.

2. � B. The DELETE clause in a MERGE statement will delete all rows that meet the WHEREcondition, subject to the important provision that these rows must have been updated by theUPDATE clause in the MERGE statement.� A is wrong because the DELETE clause will not delete all rows that satisfy the WHEREclause, but only those that have been updated prior to the DELETE operation. C and Dindicate the wrong rows.

3. � C. In a MERGE statement, the UPDATE operation always takes place first.� A, B, and C are wrong because the UPDATE operation is performed first.

4. � A. The DELETE clause in a MERGE statement will delete only those rows that are modifiedby the UPDATE clause.� B and D are wrong because the DELETE clause will not delete any rows that are insertedas a result of the INSERT operation. C is wrong because the DELETE clause will lead to thedeletion of only those rows that have been updated because of the UPDATE operation.

Using Partitioned Outer Joins

5. � A. Partitioned outer joins help you transform sparse data into dense data. Since havingdense data is very important for time-series based data, this is the right answer.� Although you can use partitioned outer joins with the data mentioned in B, C, and D,they are most useful for time-series data. Alternative D could confuse some, since you mightargue that analytical data includes time-series data.

6. � A. You could view the output of a partitioned outer join as a union of several smallerouter joins between each of the partitions and the other table(s) in the join operation.� B, C, and D are wrong since they refer to equijoins, self joins, and inner joins, whereasthe partitioned outer join performs only outer joins.

7. � B. You can use the IGNORE NULLS clause with the LAST_VALUE function to replacethe missing values with the most recent non-NULL value in that column.

Self Test Answers 41

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:58:02 PM

Color profile: DisabledComposite Default screen

Page 555: OCA OCP - Oracle10G New Features For Administrators Exam Guide

42 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

� A and C are wrong because you are not required to use zeros or NULLs to fill in missingvalues. D is wrong because you don’t provide the values for the missing data—you use thepartitioned outer joins to do that job for you.

8. � D. The PARTITION BY clause will partition the rows in the output based on theexpression you provide inside the PARTITION BY clause.� A and C are wrong because the PARTITION BY clause doesn’t actually partition thetables. B is wrong because the output isn’t partitioned into equal segments, but rather ispartitioned on the basis of the expression you provide within the PARTITION BY clause.

Using the SQL MODEL Clause

9. � C. Symbolic cell addressing is the way the MODEL clause handles the individual cells ofa multidimensional array.� A, B, and D are wrong because symbolic cell addressing deals only with addressing cellswithin the array.

10. � B. Using a MODEL clause, you can derive both updated and new data.� A is wrong since you don’t see and deleted data in the output produced by the MODELclause. C and D are wrong since you can derive both updated and new data when you usethe MODEL clause.

11. � D. By default, the RULES keyword operates with the UPSERT specification.� A, B, and C offer the wrong specifications.

12. � C. The RETURN UPDATED ROWS clause ensures that the MODEL clause outputs both theupdated and the new rows.� A and B are wrong since you drive both updated as well as new data. D is wrong since theMODEL clause doesn’t delete data.

Materialized View Enhancements

13. � A and D. A is correct since a fast refresh is accomplished by using incremental changes.D is also correct, since the materialized view logs hold the incremental change data.� B is wrong because the fast refresh method doesn’t depend on decomposing your materializedviews. C is wrong since the fast refresh method is a method of freshening the data and doesn’thave anything to with query rewriting.

14. � A and C. Under some conditions, both the materialized views and the materialized viewlogs must use ROWIDs to ensure a fast refresh.� B is wrong because a GROUP BY operation is something you must avoid in order to forcea fast refresh. D is wrong because ROWNUM don’t force a fast refresh either.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:58:03 PM

Color profile: DisabledComposite Default screen

Page 556: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test Answers 43

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

15. � D. The EXPLAIN_MVIEW procedure tells you why a materialized view isn’t fast refreshable.� A is wrong because the EXPLAIN_REWRITE procedure tells you if a materialized viewwill or won’t rewrite a query. B is wrong because the TUNE_MVIEW procedure helps you inmaking a materialized view fast refreshable. C is wrong because it refers to a nonexistent procedure.

16. � B. The TUNE_MVIEW procedure only makes recommendations, including the creation ofnecessary materialized view logs, to make a query fast refreshable.� A, B, and D are wrong since the TUNE_MVIEW procedure doesn’t automatically createany views, logs, or a fast refresh of a materialized view. It’s a purely advisory view. You canimplement the changes recommended by the view.

17. � A. The DBA_TUNE_MVIEW view holds the output of the TUNE_MVIEW procedure.� B, C, and D are wrong since they refer to the wrong procedures as the source of the view.

18. � D. The TASK_NAME variable helps you identify your query in the DBA_TUNE_MVIEWview (WHERE TASKNAME = :TASK_NAME).� A, B, and C refer to the wrong variables or columns.

19. � B. The REWRITE_OR_ERROR hint will stop any query that fails to rewrite and issues anautomatic error.� A is wrong because the hint doesn’t rewrite the query if it doesn’t have errors. C is wrongsince the hint doesn’t send a report of the errors—it merely sends a single error message whena query fails to rewrite. D is wrong since the hint does not force a query rewrite when there areerrors—it terminates the execution of the query when the query fails to rewrite and issues an error.

20. � D. In Oracle Database 10g, the PCT feature has been extended to materialized views basedon list-partitioned tables.� A is wrong because you could use the PCT feature with partitioned tables in earlier versionsof Oracle. Similarly, B and C are wrong since you could use the PCT feature in both rule- andhash-partitioned tables.

Lab Answer

1. Create the tables to show sales data for two products and check the data in the new table,as in this example:

SQL> create table s1 as2 select distinct time_id, prod_id, quantity_sold3 from sales4 where time_id between '02-JAN-2005'5 and '05-JAN-2005'6* and prod_id < 15;

Table created.

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:58:04 PM

Color profile: DisabledComposite Default screen

Page 557: OCA OCP - Oracle10G New Features For Administrators Exam Guide

44 Chapter 11: Enhancements in Analytical SQL and Materialized Views

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

SQL> select * from s1;TIME_ID PROD_ID QUANTITY_SOLD----------- ---------- -------------02_JAN-2005 13 102_JAN-2005 14 103_JAN-2005 14 104_JAN-2005 13 1

2. Create a second table with four rows in it, one for each day of January 2005, and check thedata in the table after creating it, as in this example:

SQL> begin2 for i in 0..3 loop3 insert into t1 values (to_date('02-JAN-2005') + i);4 end loop;5* end;

PL/SQL procedure successfully completed.SQL> select * from t1;TIME_ID-----------02_JAN-200503_JAN-200504_JAN-200505_JAN-2005

3. Create a regular outer join between tables s1 and t1. The following example uses the Oraclefunction CUMULATIVE, to produce cumulative values for each day, from the quantity_soldcolumn values. The regular outer join will show a day, even if there aren’t any matching valuesfor it in the s1 table. This query shows a row for the 05-Jan-2005 date, even though there areno product sales for that date (shown in table s1).

SQL> select prod_id, time_id, quantity_sold,2 sum(quantity_sold) over3 (partition by prod_id4 order by time_id)5 as cumulative

6 from s17 right outer join t18 using (time_id)9 order by prod_id, time_id;PROD_ID TIME_ID QUANTITY_SOLD CUMULATIVE

---------- ----------- ------------- ----------13 02_JAN-2005 1 113 04_JAN-2005 1 214 02_JAN-2005 1 114 03_JAN-2005 1 2

05_JAN-2005

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:58:04 PM

Color profile: DisabledComposite Default screen

Page 558: OCA OCP - Oracle10G New Features For Administrators Exam Guide

4. Finally, use a partitioned outer join, to see how you can improve over the results obtained withjust a regular outer join. The partitioned outer join in this example partition-joins the data bythe prod_id column, and shows rows for each day one of the products wasn’t sold. Product ID 13didn’t sell on the third and fifth of January 2005. Product ID 14 didn’t sell on the fourth andfifth. However, the partitioned outer join ensures that you see rows for both the products, forall the days.

SQL> select prod_id, time_id, quantity_sold,2 sum(quantity_sold) over3 (partition by prod_id4 order by time_id)5 as cumulative6 from s17 partition by (prod_id)8 right outer join t19 using (time_id)10* order by prod_id, time_id;PROD_ID TIME_ID QUANTITY_SOLD CUMULATIVE

---------- ----------- ------------- ----------13 02_JAN-2005 1 113 03_JAN-2005 113 04_JAN-2005 1 213 05_JAN-2005 214 02_JAN-2005 1 114 03_JAN-2005 1 214 04_JAN-2005 214 05_JAN-2005 2

8 rows selectedSQL>

Self Test Answers 45

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11

P:\010Comp\CertPrs8\862-4\ch11.vpTuesday, August 31, 2004 1:58:04 PM

Color profile: DisabledComposite Default screen

Page 559: OCA OCP - Oracle10G New Features For Administrators Exam Guide

12MiscellaneousNew Features

CERTIFICATION OBJECTIVES

12.01 VPD and Auditing Enhancements

12.02 Enhancements in ManagingMultitier Environments

12.03 SQL and PL/SQL Enhancements

12.04 Miscellaneous Enhancements

✓ Two-Minute Drill

Q&A Self Test

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12Blind Folio 12:1

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:27 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 560: OCA OCP - Oracle10G New Features For Administrators Exam Guide

The first part of this chapter deals with enhancements in Oracle’s VPD (Virtual PrivateDatabase) feature. You’ll learn about new VPD features like applying column-levelsecurity policies, static and nonstatic policies, and sharing VPD functions. You’ll also

review the concept of a unified audit trail and the use of fine-grained auditing for DML statements.

The latter part of this chapter deals with miscellaneous new features of OracleDatabase 10g, including some new SQL enhancements and new PL/SQL packages.You’ll look at the aggregation of meaningful statistics across a multitier environment.These new statistics help you perform end-to-end tracing of Oracle sessions. Theexciting new topic of regular expressions provides POSIX-like regular expressioncapabilities that help you write more powerful SQL search statements. You’ll alsolearn about the new linguistic and sorting methods in Oracle Database 10g SQL.

Let’s start this final chapter by reviewing the enhancements in the Virtual PrivateDatabase and auditing areas.

CERTIFICATION OBJECTIVE 12.01

VPD and Auditing EnhancementsOracle8i and Oracle9i introduced the concepts of fine-grained access control (FGAC)and Secure Application Contexts. Oracle calls the combination of these two featuresVirtual Private Database (VPD). Fine-grained access policies use the applicationattributes defined in an application context, helping you enforce security policies at

the row level. VPD lets you implement securitypolicies at a fine level of granularity by attachingyour security policy to the data objects themselves(tables, views, and synonyms). These securitypolicies contain directives to transparently changea user’s statement whenever a user accesses a table,view, or synonym that’s part of a VPD securitypolicy.

You can apply VPD policies to index maintenance operations that you may performwith any CREATE INDEX and ALTER INDEX statements. You may want to applyVPD policies to these operations because you need full table access to create an index.Thus, if you can create and rebuild an index, you can view all the table’s data.

2 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

VPD policies apply to tables,views, and synonyms. You can apply VPDpolicies toSELECT, INSERT, DELETE,UPDATE, and any INDEX statements.

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:27 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 561: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You can use an application context independently of FGAC.

Column-Level VPDOracle Database 10g introduces the capability to enforce security at the column level.VPD can apply fine-grained access control (which you define with the help of policyfunctions) only when you access certain security-relevant columns. For example, if youdefine salary as a security-relevant column in table emp, then employees can continueto freely access information in all the other columns. However, Oracle will dynamically

modify any SQL statements that refer to the salarycolumn in order to protect sensitive data. SinceOracle already provides row-level access control(FGAC), this new column-level access controlextends access control to the individual data itemlevel in a table. Note that Oracle will rewrite aSQL statement only if a SQL query accesses thesecurity-relevant columns.

Types of BehaviorYou apply the column-level VPD to tables and views with the help of the DBMS_RLS.ADD_POLICY procedure. You specify the security-relevant column names withthe sec_relevant_cols parameter of this package. When you use column-levelVPD, you have a choice of two types of behavior by the policy—default behavior andcolumn-masking behavior. Default behavior will restrict the number of rows returned byany query that contains the security-relevant columns(s). Column-masking behavior, onthe other hand, will return all the rows, but show null values for the security-relevantcolumns in those rows.

Creating a Column-Level PolicyIn order to create a column-level security policy, you must have EXECUTE privilegeson the DBMS_RLS package. You must first create a policy function that will implantyour VPD policy. You then use the DBMS_RLS package to apply your policy to a tableor view. Here’s an example of how you create a column-level policy:

begindbms_rls.add_policy (object_schema=>'scott',

object_name=>'emp',policy_name=>'test_policy',

VPD and Auditing Enhancements 3

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

A column-level VPD policyapplies only to tables and views and not tosynonyms. You may apply a policy functionto queries as well as DML statements.

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:27 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 562: OCA OCP - Oracle10G New Features For Administrators Exam Guide

4 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

function_schema=>'test_schema',policy_function=>'test_function’,statement_type=’insert,update’sec_relevant_cols=>'salary,commission');

end;

Example of a Column-Level VPDIn the preceding column-level policy, the salary and commission columns in table empare the security-relevant columns. The VPD predicate will apply to all INSERT andUPDATE statements that include either or both the salary and commission columns.Normally, a VPD policy is applied to an entire row. A column-level VPD policy willrestrict the rows retrieved by a query if the query references any of the security-relevantcolumns. The following example shows how to create VPD with a column-level securitypolicy.

Creating the Policy Function First create a new policy function, test_function,which will restrict access to the salary and commission columns if an employee is notpart of department 5.

create or replace function test_function (objowner IN 2, varchar2objname IN varchar2)return varchar2 ascon varchar2 (200);

begincon := 'deptno = 5';return (con);

end test_function;/

Create the VPD Once you create the test_function policy function, youcan create the VPD by applying it to a table, as shown here:

begindbms_rls.add_policy (object_schema => 'scott',

object_name => 'emp',policy_name => 'test_policy',function_schema => 'scott',policy_function => 'test_function',sec_relevant_cols => 'salary,commission');

end;/

If you reference either or both of the security-relevant columns, salary andcommission, the rows in the output are restricted, as shown in the following example:

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:28 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 563: OCA OCP - Oracle10G New Features For Administrators Exam Guide

VPD and Auditing Enhancements 5

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

SQL> select deptno, empno, ename, job, sal, comm from emp;DEPTNO EMPNO ENAME JOB SAL COMM---------- ---------- --------- ---------- ----------

5 7369 SMITH CLERK 100005 7566 JONES MANAGER 29755 7788 SCOTT ANALYST 30005 7876 ADAMS CLERK 11005 7902 FORD ANALYST 3000

5 rows selected.

You can implement column-masking behavior by using the sec_relevant_cols_opt => DBMS_RLS.ALL_ROWS parameter. This allows you to display allrows but hide the values of the specified columns for the restricted rows. Here’s anexample:

begindbms_rls.add_policy (object_schema => 'scott',

object_name => 'emp',policy_name => 'sp_job',function_schema => 'scott',policy_function => 'pf_job',sec_relevant_cols => 'sal,comm',sec_relevant_cols_opt => DBMS_RLS.ALL_ROWS);

end;/

Once you choose the column-masking behavior by using the DBMS_RLS.ALL_ROWS option, your query will return all rows, but it will show the salary and commissionvalues for only those employees that belong to department 5.

SQL> select deptno,empno, ename, job, sal, comm from emp;DEPTNO EMPNO ENAME JOB SAL COMM-----------------------------------------------------------

5 7369 SMITH CLERK 1000010 7499 ALLEN SALESMAN10 7521 WARD SALESMAN5 7566 JONES MANAGER 29752 7654 MARTIN SALESMAN1 7698 BLAKE MANAGER8 7782 CLARK MANAGER5 7788 SCOTT ANALYST 30002 7839 KING PRESIDENT1 7844 TURNER SALESMAN5 7876 ADAMS CLERK 11004 7900 JAMES CLERK5 7902 FORD ANALYST 30002 7934 MILLER CLERK

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:28 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 564: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You can grant the privilege GRANT EXEMPT ACCESS POLICY to a userso that he or she may bypass a security policy, as shown here:

SQL> grant exempt access policy to hr;Grant succeeded.

New Policy TypesBy default, all Oracle VPD policy functions are dynamic in nature. That is, Oracle willexecute the security policy statement each time a DML statement refers to it. This leadsto the expenditure of valuable system resources due to the constant need to reexecuteand evaluate security policies. Each time Oracle reparses a SQL statement or executes it,it reexecutes any policy function that the statement might have. Oracle Database 10gintroduces new policy types designed to improve server performance by avoiding theneed for reexecution and by allowing the sharing of policies across multiple databaseobjects. Let’s look at these new policy types in the following sections.

Static PoliciesOracle Database 10g lets you configure static policies. The database executes a staticpolicy function just once, and caches the predicate resulting from the policy evaluationin the SGA. It then applies this predicate to all queries accessing the protected objects.If you think that all queries, regardless of which user issues them, need the same policypredicate, you might want to configure a static policy.

A static policy is one that will always return the same WHERE clause, such asdeptno=something so that even though the “something” may be different foreach statement executed against the table, the actual SQL doesn’t change (a bit likea bind variable). But a dynamic policy is one that could generate a different WHEREclause. For instance, the function could query usercontext and, depending on theresult, generate different WHERE clauses. Thus, some users would get deptno=…,and others would get mgr=…, for example. So flagging a policy as static is simplytelling Oracle that the function can only return one value (possibly containing avariable) no matter who executes it, whereas a dynamic policy is based on a functionthat has several different return values. If you tell Oracle that the policy will alwaysget the same return value, then Oracle doesn’t have to repeatedly generate it.

You can add a static policy using the DBMS_RLS.ADD_POLICY procedure, asshown here:

6 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:28 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 565: OCA OCP - Oracle10G New Features For Administrators Exam Guide

begindbms_rls.add_policy (object_schema=>'scott',

object_name=>'emp',policy_name=>'test_policy',function_schema=>'test_schema',policy_function=>'test_function’,statement_type=’select,insert,update’policy_type => dbms_rls.staticsec_relevant_cols=>'salary , commission');

end;

In the preceding example, the highlighted line shows how you specify a static policytype. The default policy type in Oracle Database 10g is dynamic.

If you want to allow the sharing of the same static policy function over differentdatabase objects, you can set the POLICY_TYPE parameter to the following value:

POLICY_TYPE => DBMS_RLS.SHARED_STATIC

Context-Sensitive PoliciesYou may sometimes want to configure a policy such that it will change based onany session context changes. That is, each time certain context attributes within a user’ssession change, you want the policy function to automatically change as well. In caseslike this, you can use the new context-sensitive policies. When you use a context-sensitivefunction, Oracle will evaluate the policy function when it first parses the statement.Thereafter, Oracle will evaluate the policy function each time there is a local applicationcontext change. Here’s our DBMS_RLS example, this time with a context-sensitivepolicy type.

Context-sensitive VPD policies are particularly useful in a web-based applicationwith connection pooling, where a session needs to change its behavior dependingon the CLIENT_IDENTIFIER of the user using the session at any given moment.

VPD and Auditing Enhancements 7

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

The default Oracle policytype in Oracle Database 10g is dynamic,but you can configure static and context-sensitive policies. If you want to enforce

the same business policy over severaldatabase objects, you can do so bysharing either a static or a context-sensitive policy.

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:28 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 566: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

begindbms_rls.add_policy (object_schema=>'scott',

object_name=>'emp',policy_name=>'test_policy',function_schema=>'test_schema',policy_function=>'test_function’,statement_type=’select,insert,update’policy_type => dbms_rls.context_sensitivesec_relevant_cols=>'sal,comm');

end;

If you want to allow the sharing of the same context-sensitive policy function overdifferent database objects, you can set the POLICY_TYPE parameter to the followingvalue when you use the DBMS_RLS.ADD_POLICY procedure:

POLICY_TYPE => DBMS_RLS.SHARED_CONTEXT_SENSITIVE

Auditing EnhancementsOracle databases provide several auditing mechanisms. You have the option to auditdatabase activity based on data content by attaching audit policies directly to objects.Oracle calls this feature fine-grained auditing (FGA).When you use FGA, Oracle createsaudit records based on the specific query and the data that the SQL statement accesses.

In Oracle Database 10g, enhancements to auditing features include uniform audittrails for standard auditing and FGA, enhanced auditing of enterprise users, and severalFGA enhancements. Let’s review Oracle Database 10g auditing enhancements bylooking at uniform audit trails for standard and fine-grained auditing.

Uniform Auditing TrailsOracle Database 10g helps you audit database activities in a uniform manner by usinga new uniform audit trail for both standard and fine-grained audit log records. Both thestandard audit trail and FGA audit trail track similar audit fields in Oracle Database 10g.

8 Chapter 12: Miscellaneous New Features

You now have five differentpolicy types, with DYNAMIC being the defaulttype. There are two static policy types—STATIC and SHARED_STATIC. There aretwo context-sensitive policies—CONTEXT_

SENSITIVE and SHARED_CONTEXT_SENSITIVE. The purpose behind havingseveral types of policies is aimed at reducingthe number of executions of policy functions,which sometimes cripple performance.

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:28 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 567: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You can view the new uniform audit trail by using the DBA_COMMON_AUDIT_TRAIL view. In the following text, the variables in the parentheses are columnsof this view.

Standard auditing now collects the followingadditional information:

■ System change numbers (SCN)

■ Bind variable information (SQL_BIND)and the exact SQL text (SQL_TEXT) inthe audited statement

In Oracle Database 10g, FGA collects the following additional information:

■ Serial number of audit records (ENTRYID)

■ Statement numbers that help you identify which audit entries belong to a SQLstatement (STATEMENTID)

In addition, the following attributes are common to both standard and FGA audittrails:

■ Global timestamp (GLOBAL_UID)

■ A unique instance number for Real Application Cluster instances (INSTANCE_NUMBER)

■ A transaction identification number to trace individual records to a transaction(TRANSACTIONID)

Enterprise User AuditingWhen you use an LDAP-compliant directory like the Oracle Internet Directory, yourusers are known as enterprise users. Oracle Database 10g lets you audit the activities ofthe enterprise users in the database. Enterprise users can map to either an exclusive ora shared schema in your database. If the enterprise user maps to an exclusive schema inyour database, the database username and the enterprise user are identical. In sharedschemas, the database username and the enterprise users are different. Let’s see howOracle enhances enterprise user auditing in both types of user mapping.

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

VPD and Auditing Enhancements 9

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

You can view the new SCNand SQL text/bind variable informationonly if you use the new AUDIT_TRAIL=DB_EXTENDED specification in yourinitialization parameter file.

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:28 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 568: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Exclusive Schemas If the enterprise user accesses the database by mapping toan exclusive schema, in both standard and fine-grained auditing, the GLOBAL_UIDcolumn shows the user’s global identity. In standard auditing, the USERNAME columnshows the user’s identity in the database, and in fine-grained auditing, the DB_USERcolumn shows the user’s identity in the database.

Shared Schemas If the enterprise user accesses the database by mapping to ashared schema, in both standard and fine-grained auditing, the GLOBAL_UID columnshows the user’s global identity. In standard auditing, the USERNAME column showsthe shared schema, and in fine-grained auditing, the DB_USER column shows theshared schema.

Fine-Grained Auditing EnhancementsIn previous versions of Oracle, fine-grained auditing supported only SELECT statements.Oracle Database 10g provides the following fine-grained auditing enhancements:

■ You can auditSELECT, INSERT, UPDATE, DELETE, and MERGE statements.

■ You can provide more than one relevant column for fine-grained auditing.

■ You can now use NULL fine-grained auditing policy predicates.

■ Since fine-grained auditing imposes significant SQL information overhead,you can avoid the writing of SQL text and SQL bind information to LOBs.

FGA and DML StatementsOracle Database 10g’s FGA features deal with DML statements of all types, but thereare some important provisions that you must remember. Here’s a summary of new DMLstatement considerations:

■ Oracle Database 10g will audit a DML statement with an FGA policy definedon it if the data rows (old and new) qualify under the policy predicate.

■ If you have a relevant column(s) in the security policy, the DML statement willbe audited only if it references the column(s) and the data meets the FGApolicy requirements.

■ Oracle always audits a qualified DELETE statement, regardless of whetheryou have specified relevant columns or not.

10 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:28 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 569: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Enhancements in Managing Multitier Environments 11

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

CERTIFICATION OBJECTIVE 12.02

Enhancements in Managing Multitier EnvironmentsDebugging of performance problems in multitier environments is difficult, since you can’teasily track a client across different database sessions. Oracle Database 10g introducesnew statistical attributes that help you perform end-to-end tracing. Let’s look at these newattributes in the following sections.

New Dimensions for Statistics Collection and TracingPrevious versions of Oracle enabled statistics collection only at the individual SQLstatement, session, or instance level. Most DBAs are very familiar with session-basedtracing. These three levels are adequate in most cases for simple database configurations.However, when you are dealing with complex multitier architectures using connectionpooling and shared server architectures, these simple statistical aggregation levels aresimply inadequate in monitoring performance problems. Realizing this, Oracle Database 10gprovides you with several new dimensions for collecting statistics, as follows:

■ Client identifier

■ Service name

■ Combinations of service name, module name, and action name

These three new dimensions for collecting statistics offer you new and powerfulmeans of monitoring problems in multitier architectures. The new statistics focus onthe clients and services, rather than database sessions and SQL statements. With the

Oracle’s FGA featureaudits MERGE statements by viewingthe INSERT and DELETE statementsin the MERGE statement as individual

statements. If there are applicableFGA policies for the INSERT or UPDATEstatement, Oracle will audit theMERGE statement.

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:28 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 570: OCA OCP - Oracle10G New Features For Administrators Exam Guide

help of metrics and statistics for these new dimensions, you can improve performancemonitoring of clients and services, as well as manage your workload more efficiently.

One of the most difficult problems in a multitier environment is the inability totrace a client’s work on an end-to-end basis. The middle tier would frequently transferthe same client to different sessions, making tracing of the client extremely difficult.In Oracle Database 10g, the new variable CLIENT_IDENTIFIER enables you to tracethe same client from the time the user logs into the system until the user logs off,regardless of how many different sessions the client switches to through the applicationserver.

You can see the value of the CLIENT_IDENTIFIER variable in two ways. You canuse the V$SESSION view (CLIENT_IDENTIFIER column) or use the followingquery, which makes use of the system context.

SQL> select sys_context('USERENV', 'CLIENT_IDENTIFIER')2 from dual;

SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER')------------------------------------------salapatiSQL>

Besides enabling the tracing of individualclient sessions, end-to-end tracing also enablesyou to track a transaction using hierarchicalcombinations of the the service, module, andaction names. You can find out what traces arecurrently enabled in your database by using theDBA_ENABLED_TRACES view.

Enabling the Collection of Client and Service StatisticsYou use the DBMS_MONITOR package to enable client- and service-level statisticsaggregation. The procedures you can use to enable and disable the tracing and collectionof the new statistics are summarized next.

Client-Level StatisticsYou use the CLIENT_ID_STAT_ENABLE procedure to enable the collection ofstatistics for a client identifier, as shown here:

SQL> execute dbms_monitor.client_id_stat_enable(<client_id>);

12 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

By default, waits andbinds aren’t traced.

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:28 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 571: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Enhancements in Managing Multitier Environments 13

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

You can disable the collection of client-level statistics by using the CLIENT_ID_STAT_DISABLE procedure.

Service-Level StatisticsYou use the SERV_MOD_ACT_STAT_ENABLE procedure to enable the collection ofstatistics for a client identifier, as shown here:

SQL> execute dbms_monitor.serv_mod_act_stat_enable(<service_name,<module_name>, <action_name>);

You can disable the collection of client-level statistics by using the SERV_MOD_ACT_STAT_DISABLE procedure.

Tracing Clients and ServicesYou can use the new client identifier (CLIENT_ID) and the combination of service,module, and action names to trace sessions on both a global and session level. Let’sfirst see how you enable and disable tracing.

Enabling and Disabling TracingYou can enable and disable tracing by using various procedures of the DBMS_MONITORpackage. Here’s a summary of how to enable and disable tracing.

Client Identifier Tracing You use the following procedures to enable and disabletracing for client identifiers:

■ CLIENT_ID_TRACE_ENABLE Enable global (database-wide) tracing ofa client identifier

■ CLIENT_ID_TRACE_DISABLE Disable client identifier tracing

Service, Module, and Action Tracing You use the following procedures toenable and disable tracing for combinations of service names, module names, andaction names on a global basis.

■ SERVICE_MOD_ACT_TRACE_ENABLE Enable global (database-wide)tracing

■ SERVICE_MOD_ACT_TRACE_DISABLE Disable global (database-wide)tracing (module and service names are optional)

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:29 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 572: OCA OCP - Oracle10G New Features For Administrators Exam Guide

You may want to refer to the DBMS_APPLICATION_INFO package to seehow to set both a module name and action name so that you have a moduleand an action to trace after enabling their tracing with the SERVICE_MOD_ACT_TRACE_ENABLE procedure. The DBMS_APPLICATION_INFO has twoprocedures, SET_MODULE and SET_ACTION, which allow programmers tospecify module and action names. The SET_MODULE procedure sets the nameof the current application or module. The SET_ACTION procedure sets thename of the current action within the current module.

Using the TRCSESS Tool to Analyze Trace FilesWhen there are several trace files from a given session, it is hard to combine the outputof all the traces into a unified format. You can use Oracle’s TRCSESS command-lineutility to consolidate the information from all your trace files into a single output file.Once you consolidate the trace files, you can use the familiar TKPROF utility to formatthe trace file output into a readable format. Here’s the general syntax for using theTRCSESS tool:

$ trcsess output=<user.trc> clientid=<user_name> *.trc

Viewing the New StatisticsOnce you have enabled the collection of the new client identifier, service, module, andaction names statistics, you can view them by using Database Control. There are alsoseveral new views that help you track these important statistics. Here are some of theimportant new views:

■ DBA_ENABLED_AGGREGATIONS Displays information about enabledstatistics aggregation

■ DBA_ENABLED_TRACES Shows all enabled traces in the system

■ V$CLIENT_STATS Displays statistics on a client level (CLIENT_IDENTIFIER based)

■ V$SERVICE_STATS Displays basic performance statistics

■ V$SERV_MOD_ACT_STATS Displays statistics for a combination of serve/module/action names.

14 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:29 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 573: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CERTIFICATION OBJECTIVE 12.03

SQL and PL/SQL EnhancementsThere are several SQL and PL/SQL enhancements in Oracle Database 10g, and you’vealready seen some of them, like the MODEL clause, in earlier chapters. In the followingsections, I’ll review some of the more important enhancements from the point of viewof an Oracle DBA.

UTL_COMPRESS PackageOracle Database 10g provides the new UTL_COMPRESS package to compress anduncompress data, with the compressed output compatible with the output of the familiarGZIP and GUNZIP compression utilities. You may want to compress data to save onstorage space. You can choose betweeen compression speed and the quality of compression.Quality of compression refers to the reduction in size due to compressing data. There isan inverse relationship between speed and quality of the compression job.

UTL_MAIL PackageIn previous versions, Oracle provided the UTL_SMTP package to send email. However,this isn’t an intuitive package to understand and is quite unwieldy for sending simpleemail notes. In addition, you had to understand the underlying SMTP protocol featuresto use it. In Oracle Database 10g, you have access to a new utility for sending email,the UTL_MAIL package. You can now send programmatically composed emails usingsimple PL/SQL API. You use simple parameters to specify email components such assender, receiver, copies, blind copies, subject, and so on.

In order to use the UTL_MAIL package to send email, you must first execute theutlmail.sql script located in your ORACLE_HOME/rdbms/admin directory.You mustalso execute the prvtmail.plb script located in the same directory. Here’s a simpleexample that shows how to send an email using the UTL_MAIL package:

SQL> execute utl_mail.send -> (sender => '[email protected]', -> recipients => '[email protected]', -> subject => 'testing 10g Packages',> message => 'No attachements with this note');

SQL and PL/SQL Enhancements 15

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:29 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 574: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Regular ExpressionsOracle provides several operators to help you with string manipulation and searching.Operators such as the SQL LIKE, REPLACE, SUBSTRING and INSTRING are oldstandbys in many a search expression. However, these older operators have seriouslimitations when it comes to searching and manipulating complex patterns in data. Youwould have to write numerous lines of SQL and PL/SQL code to search for complexexpressions. Oracle Database 10g enhances your ability to perform convenient searchesand string manipulation by adding regular expression support to both SQL and PL/SQLprogramming. Oracle’s regular expression features follow the syntax and semanticsof the operators defined by the POSIX regular expression standards. You use specialregular expression functions that parallel the traditional search operators such as LIKE,INSTRING, SUBSTRING, and REPLACE.

A regular expression searches for patterns in a character string, which is the source forthe search value. The source character string can be one of the CHAR, VARCHAR2,NCHAR, or NVARCHAR2 datatypes. The regular expression function can be oneof the following:

REGEXP_LIKEREGEXP_REPLACEREGEXP_INSTRINGREGEXP_SUBSTRING

The REGEXP_LIKE function evaluates strings using characters as defined by theinput character set. The regular expression function will search for a certain patternin a regular expression, indicated by the source_string parameter in the function.The expression represented by the pattern variable is the regular expression. A regularexpression is usually a text literal and can be any of the datatypes CHAR, VARCHAR2,NCHAR, or NVARCHAR2. Regular expressions can be long if you wish, with amaximum size of 512 bytes. In addition to the search pattern indicated by source_string, you can use an optional matching condition (match parameter) to modifythe default matching behavior. For example, a value of ‘i’ specifies case-insensitivematching, and a value of ‘c’ specifies case-sensitive matching.

Here’s the generic syntax of the REGEXP_LIKE function:The SQL operator REGEXP_LIKE is useful in searching for regular expressions.

If you want to perform string manipulation tasks, you can use the built-in functionsREGEXP_INSTR, REGEXP_REPLACE, and REGEXP_SUBSTR. You can use theseregular expression functions as extensions of their normal SQL counterparts like INSTR,REPLACE, and SUBSTR. For example, the REGEXP_LIKE function is similar to the

16 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:29 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 575: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SQL and PL/SQL Enhancements 17

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

LIKE condition, except that REGEXP_LIKE will perform regular expression matchinginstead of the simple pattern matching performed by the LIKE function.

To match characters and to indicate the beginning and end of lines, regularexpression features use characters such as ., *, ^, and $, which are common in UNIXand Perl programming. The character ^, for example, tells Oracle that the charactersfollowing it should be at the beginning of the line. Similarly, the character $ indicatesthat a character or a set of characters must be at the very end of the line. Here’s anexample using the REGEXP_LIKE function. (The query picks up all names withconsecutive vowels in their names.)

SQL> select last_namefrom employeeswhere regexp_like (last_name, '([aeiou])\1', 'i');

LAST_NAME-----------De HaanGreenbergKhooGeeLee……

EXERCISE 12-1

Using a regualr expression in a queryUse the appropriate regular expression built-in function to search for all employeesthat were hired in the years 1996 and 1997. (Use the table employees in the sampleschema HR.)

SQL> SELECT last_name,first_name, salary,2 TO_CHAR(hire_date,'yyyy') year_of_hire3 FROM hr.employees4* WHERE REGEXP_LIKE (TO_CHAR (hire_date, 'yyyy'), '^199[6-7]$');

LAST_NAME FIRST_NAME SALARY YEAR------------------------- -------------------- ---------- ----Alapati Nina 4800 1997Chen John 8200 1997Sciarra Ismael 7700 1997Baida Shelli 2900 1997Tobias Sigal 2800 1997Wilson Shannon 8000 1996

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:29 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 576: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Case-Insensitive and Accent-Insensitive Query and SortOracle Database 10g provides support for case-insensitive queries and sorts, allowingusers to search and sort their data whatever the case and accent of the characters mightbe. You use the NLS_SORT parameter to specify the lingusitic sort name and whetherit is a case-insensitive or accent-insensitive sort.

When you use the NLS_SORT parameter, you can use the optional suffixes AI orCI to specify whether the sort is accent insensitive (AI) or case insensitive (CI). Here’sthe general syntax of the NLS_SORT parameter and an example of its usage:

NLS_SORT = <NLS_sort_name>[_AI| _CI]NLS_SORT = FRENCH_M_AI.

In the previous example, the name of the NLS_SORT is FRENCH_M. The optionalsuffix AI indicates this is an accent-insensitive (and case-sensitive) sort.You canindicate a case-insenstitive sort by using the suffix CI.

CLOB and NCLOB Implicit ConversionsThe maximum size of an LOB datatype (BLOB, CLOB, and NCLOB) in OracleDatabase 10g is much larger than the old limit of 4GB. You can now have LOBs thatcan be sized in terabytes, with the maximum size being about 128TB.

Oracle Database 10g also provides implicit conversion between CLOB and NCLOBdatatypes. Before this version, you had to explicitly convert CLOBs into NCLOBs andvice versa, using the TO_CLOB and TO_NCLOB functions. International applicationssupporting multiple language characters required the deployment of function calls toconvert these kinds of data.

Oracle Database 10g introduces the implicit conversion between LOBs and NCLOBs.Oracle now supports implicit conversion in SQL IN/OUT bind variables, PL/SQLfunction and procedure parameter passing, and PL/SQL variable assignment.

User-Specified Quoting CharactersIn prior versions of Oracle, programmers had to use quotation strings in character stringliterals. Oracle Database 10g lets you choose any convenient delimiter and define itdynamically as the quoting character. You can choose any single or multibyte character,or paired characters like [ ], {}, (), and <>. You may even choose a single quotation markas your delimiter.

18 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:29 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 577: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Miscellaneous Enhancements 19

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

You use the new quote operator q to provide your own quotation mark delimiters.Here’s a simple example that illustrates how you can use the new quote operator toavoid using escape characters for single quotation marks in text literals:

SQL> select cust_address FROM oe.customerswhere cust_last_name = q'X 'John's Bait Shop' X'

CERTIFICATION OBJECTIVE 12.04

Miscellaneous EnhancementsThere are several enhancements in Oracle Database 10g that don’t fit within the topicsof any of the earlier chapters in this book. I summarize these enhancements in thefollowing sections.

Easy Connect Naming MethodOracle DBAs can now simplify client configuration by using the new easy connectnaming method. Your database clients can now connect to Oracle Database 10g databaseservices without any configuration fields or name lookup services. All that your clientswill need to connect to the database server is the host name and the optional port numberand service name of the database.

The only condition for using the easy connect naming method is that you shouldhave support for the TCP/IP protocol on both the client and the server. You don’t haveto configure a tnsnames.ora file. You can look at this new connecting method as anextension of the host naming method introduced in Oracle9i. Here’s the general syntaxof this new connecting method :

$ sqlplus /nolog

connect username/password@[//]host[:port][/service_name]

In the new easy connect method, there are four different things you need to focuson: host, the // notation, port number (default port = 1521), and service name. Ofthese four things, only the host name is mandatory. For example, you can connect tothe dev1 database located on the server hp50 with the following connect identifier(note that I’m connecting directly from the operating system prompt, so I replace thekeword CONNECT with SQLPLUS):

C:\>sqlplus appowner/password@hp50:1521/dev1

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:29 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 578: OCA OCP - Oracle10G New Features For Administrators Exam Guide

20 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

When you install an Oracle database, Oracle will configure your sqlnet.ora file touse the new configuration-less client connect method. The NAMES.DIRECTORY_PATH parameter in the sqlnet.ora file shows all connect methods. The new easy connectmethod is referred to as EZCONNECT in a sqlnet.ora file. Look at the followingsqlnet.ora file:

# sqlnet.ora Network Configuration File:C:\oracle\product\10.1.0\Db_1\network\admin\sqlnet.ora# Generated by Oracle configuration tools.NAMES.DEFAULT_DOMAIN = netbsa.orgSQLNET.AUTHENTICATION_SERVICES = (NTS)NAMES.DIRECTORY_PATH = (TNSNAMES,EZCONNECT)

The last line shows you the connect methods that Oracle Net will use to resolveconnect identifiers to connect descriptors. In this example, TNSNAMES is the firstoption, so Oracle NET will use the tnsnames.ora file first by default. If it can’t connectusing the tnsnames.ora file, it will then use the EZCONNECT connecting method.If you want Oracle Net to use the EZCONNECT method first, you can use OracleNet Manager to reconfigure the sqlnet.ora file so your NAMES.DIRECTORY_PATHwill be as follows. (You may manually change the sqlnet.ora file as well.)

NAMES.DIRECTORY_PATH = (EZCONNECT, TNSNAMES)

Simplified Shared Server ConfigurationOracle Database 10g is shared server aware, meaning that you don’t have to configureany shared server parameters. A dispatcher will start automatically when you start adatabase instance, but no shared server process will start. If you want to start a sharedserver while your instance is running, you can do so by setting a non-zero value for theSHARED_SERVER initialization parameter, as shown here:

SQL> alter system set shared_servers=4System altered.SQL>

Enabling Resumable Space AllocationOracle Database 10g introduces a new initialization parameter, RESUMABLE_TIMEOUTto enable resumable statements at the system or the session level. To set the resumabletime-out to three hours, for example, you’d specify RESUMABLE_TIMEOUT=10800(3x60x60) in your initialization parameter file. The default for this initializationparameter is zero, meaning that resumable space allocation is disabled for all databasesessions. You can dynamically use the parameter in the following way to enable resumablespace allocation at the instance level:

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:29 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 579: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Miscellaneous Enhancements 21

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

SQL> alter system2 set resumable_timeout=7200;

System altered.SQL>

You can dynamically change the RESUMABLE_TIMEOUT parameter at an individualsession level as well, by using the ALTER SESSION command. The old method ofenabling resumable statements at the session level by using the command ALTERSESSION ENABLE RESUMABLE still works in Oracle Database 10g.

Flushing the Buffer CacheWhen you are testing SQL statements on a development system, there are times whenyou wish that you could wipe out the data in your buffer cache in order to accuratelycompare the output from various iterations of your queries. Previously, you could onlyflush the shared pool to remove any cached SQL statements from the SGA. You can flushthe database buffer cache in Oracle Database 10g by using the following command:

SQL> alter system flush buffer cache;System altered.SQL>

LogMiner EnhancementsThere are three important changes in the LogMiner tool. Let me summarize the changesbriefly here.

Automatic Adding of Redo Log FilesYou can now simply specify a time or SCN, and LogMiner will automatically add thenecessary redo log files by scanning the control files for the log information. You mustuse the DBMS_LOGMNR.CONTINUOUS_MINE procedure to facilitate this automaticgathering of redo log files for mining purposes.

Disabling Generation of ROWIDsYou can disable the generation of physical ROWIDs by using the NO_ROWID_IN_STMToption when you use the DBMS_LOGMNR package.

Easier Removal of Redo Log FilesTo remove redo log files, you can now use the new REMOVE_LOGFILE procedure withthe DBMS_LOGMNR package.

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:29 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 580: OCA OCP - Oracle10G New Features For Administrators Exam Guide

22 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

Real-Time Transaction MonitoringOracle Database 10g introduces enhancements to the V$FAST_START_SERVERSand the V$FAST_START_TRANSACTIONS views to enable real-time monitoring ofnormal transaction rollback and transaction recovery by the SMON background process.You can also make better estimations of your transaction recovery time by calculatingmore accurate rollback times during transaction recoveries. Let’s review the changes inreal-time transaction monitoring in Oracle Database 10g.

The V$FAST_START_SERVERS ViewThis view provides information about all the recovery servers performing (or thathave performed) parallel transaction recovery. In Oracle Database 10g, you have anew column, XID, that gives you the transaction ID of the transaction that a recoveryserver is working on.

The V$FAST_START_TRANSACTIONS ViewThis view shows information about the progress of the transactions that Oracle iscurrently recovering. The STATE column shows the value RECOVERING for all

transactions that are being recovered right now.In addition, the view stores historical recoveryinformation until the next shutdown of theinstance. The transactions already recovered byOracle have the value RECOVERED under theSTATE column. If any transaction has yet to berecovered, the STATE column will show the valueTO BE RECOVERED.

Oracle Database 10g has added the followingnew columns to the V$FAST_START_TRANSACTIONS view to enhance yourability to keep track of the progress of transaction recovery:

■ XID Stands for the transaction ID.

■ PXID Parent transaction ID.

■ RCVSERVERS Number of servers used in the last recovery. If SMONis doing the recovery, the value of this parameter is always 1.

Automatic Checkpoint TuningDBAs have to consider the trade-off between a quick recovery time and I/O overheadwhen trying to figure out the appropriate checkpoint interval. In Oracle9i, you had

The enhancements intransaction rollback monitoring help youset the FAST_START PARALLEL_ROLLBACK initialization parameter at anappropriate level.

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:29 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 581: OCA OCP - Oracle10G New Features For Administrators Exam Guide

access to the FAST_START_MTTR_TARGET initialization parameter, which enabledyou to specify the mean time for a crash recovery.

In Oracle Database 10g, there is no need for you to set the FAST_START_MTTR_TARGET parameter because Oracle itself will automatically tune the checkpointingprocess. Automatic checkpoint tuning means that Oracle will write out the dirty bufferswhile incurring the least amount of impact in the way of physical I/Os.

You can enable automatic checkpoint tuning by simply setting the FAST_START_MTTR_TARGET parameter to any non-zero value. Oracle automatically tunescheckpointing even if you completely leave out the FAST_START_MTTR_TARGETparameter. However, by explicitly setting the parameter to zero, you can disable Oracle’sautomatic checkpoint tuning.

Miscellaneous Enhancements 23

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

You can expect some type of question on thenew column-level VPD policies. The examtests your expertise in customized VPD policytypes. What are the five VPD policy types, andwhen do you use them? Be sure to understandhow to use shared policy functions. The examwill contain questions on the new auditingfeatures. Understand what the new AUDIT_TRAIL=DB_EXTENDED specification willhelp you do. You must be familiar with theDBA_COMMON_AUDIT_TRAIL view andits important columns.

You are going to see questions on fine-grained auditing enhancements, includingtopics like support for DML statements (andthe MERGE statement), multicolumn FGApolicies, and NULL FGA policy predicates.How does Oracle audit MERGE statements?Look up the DBMS_FGA package and studythe ADD_POLICY procedure carefully,with particular emphasis on the AUDIT_COLUMN, AUDIT_COLUMN_OPTS,and the AUDIT_TRAIL columns.

The exam will test your knowledge of the newCLIENT_IDENTIFIER, SERVICE_NAME,MODULE_NAME, and ACTION_NAMEattributes. What are these attributes useful for?Please look up the DBMS_MONITOR package andstudy the CLIENT_ID_TRACE_ENABLEand the SERV_MOD_ACT_TRACE_ENABLEprocedures. Also look up the procedures thatenable and disable statistics collection for thenew attributes. You must know how to enableand disable end-to-end tracing using the newattributes.

Among the miscellaneous SQL and PL/SQLtopics, focus on regular expressions and the newpackages to send email and compress data. Knowthe Oracle Database 10g enhancements inCLOB to NCLOB conversions, the new quoteoperator, and how to perform case- and accent-insensitive querying and sorting. The examalso may have questions on the new resumablestatement parameter, the easy connect namingmethod, and the easy configuration of sharedservers.

INSIDE THE EXAMINSIDE THE EXAM

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:30 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 582: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CHAPTER SUMMARYYou reviewed the new column-level VPD policies in this chapter. You learned how tocreate a VPD with security-relevant columns.You also learned about the new static andcontext-sensitive policies and how you can share them across objects.The chaptercovered the Oracle Database 10g enhancements in the auditing area, including the newuniform audit trail for standard and fine-grained auditing .You learned about the newenterprise user auditing enhancements as well as other FGA enhancements.

The new attributes—client identifier, service name, module name, and actionname—enhance your ability to perform end-to-end tracing as well as monitor yourdatabase workload. You learned how to enable and disable client- and service-leveltracing and statistics collection.

The chapter introduced you to the new UTL_MAIL and the UTL_COMPRESSPL/SQL packages. You had an introduction to the powerful regular expressions feature.The chapter also reviewed the new case- and accent-insensitive sorting techniquesas well as user-specified delimiters.

Under miscellaneous enhancements, you briefly reviewed the new easy connectnaming method, simpler shared server configuration, the new resumable spaceallocation initialization parameter, and enhancements to the LogMiner tool and real-time transaction monitoring.

24 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:30 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 583: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Two-Minute Drill 25

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

✓TWO-MINUTE DRILL

VPD and Auditing Enhancements❑ Oracle Database 10g introduces the new column-level security mechanisms

(VPD).

❑ You can now assign certain columns as security-relevant columns.

❑ You can apply a column-level VPD policy to tables and views, but notto synonyms.

❑ You can apply policy functions to queries as well as DML statements.

❑ You implement the column-level VPD policies with the help of the DBMS_RLS.ADD_POLICY procedure.

❑ Default behavior will restrict the number of rows returned.

❑ Column-masking behavior will return all rows, but show NULL for thesecurity-relevant columns.

❑ You implement column-masking behavior by using the sec_relevant_cols_opt => DBMS_RLS.ALL_ROWS parameter when using the ADD_POLICY procedure.

❑ By default, all Oracle VPD policy functions are dynamic.

❑ A static policy is only executed once and reused for all subsequent queries.

❑ A context-sensitive policy changes with session context changes.

❑ Both static and context-sensitive policies can be shared or nonshared policies.

❑ You have a new uniform audit trail for both standard and FGA audit log records.

❑ You have to set the AUDIT_TRAIL=DB_EXTENDED parameter value in orderto see bind variables and the complete SQL text of the audited statements.

❑ There are several enhancements in the enterprise user auditing in OracleDatabase 10g.

❑ You can audit queries and DML statements (including the MERGE statement)in the course of fine-grained auditing.

❑ You can provide multiple columns for FGA as well as use NULL FGA auditingpolicy predicates.

❑ Oracle will always audit a qualified DELETE statement under FGA.

❑ Oracle’s FGA feature audits MERGE statements by viewing them as consistingof individual UPDATE and INSERT statements.

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:30 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 584: OCA OCP - Oracle10G New Features For Administrators Exam Guide

26 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

Enhancements in Managing Multitier Environments❑ New dimensions for collect statistics include client identifier, service name,

and combinations of service name, module name, and action name.

❑ The CLIENT_IDENTIFIER attribute facilitates end-to-end tracing.

❑ You use procedures from the DBMS_MONITOR package to enable and disablestatistics collection and to trace the new client- and server-related attributes.

❑ The new TRCSESS tool helps you analyze the output of multiple trace files.

SQL and PL/SQL Enhancements❑ The UTL_COMPRESS package lets you compress and uncompress data.

❑ The UTL_MAIL package offers you a simpler alternative to the UTL_SMTPpackage for sending email.

❑ Regular expressions provide powerful means of searching and manipulatingcomplex patterns.

❑ You can use the regular expression equivalents of the LIKE, REPLACE,SUBSTR, and INSTR functions.

❑ You can now specify accent-insensitive and case-insensitive sorting when youuse the NLS_SORT parameter.

❑ You can now implicitly convert CLOB and NCLOB datatypes.

❑ Users can choose custom delimiters and define them as a quoting character.

Miscellaneous Enhancements❑ The new EZCONNECT client connection method cuts down on client

configuration work.

❑ Shared server configuration is simpler now, and you only have to configure theSHARED_SERVER parameter. The dispatcher process starts automaticallywith instance startup.

❑ The new initialization parameter RESUMABLE_TIMEOUT enables theresumable statements feature at the system or session level.

❑ You can now flush the buffer cache by using ALTER SYSTEM command.

❑ The LogMiner tool allows the easy addition and removal of redo log files.

❑ Changes to the V$FAST_START_SERVERS and the V$FAST_START_TRANSACTIONS views enhance real-time monitoring of transaction rollbackand recovery.

❑ In Oracle Database 10g, you can let the database automatically tune databasecheckpointing.

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:30 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 585: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SELF TEST

VPD and Auditing Enhancements

1. Which of the following does a column-level VPD policy apply to?

A. TablesB. SynonymsC. ViewsD. Materialized viewsE. Indexes

2. Which of the following type of SQL statements may you apply a policy function to?

A. DDL statementsB. SELECT statements onlyC. Queries and DML statementsD. INSERT and DELETE statements onlyE. INSERT, DELETE, and UPDATE statements

3. Which of the following statements regarding column-level VPD are true?

A. Default behavior will return all columns.B. Default behavior will restrict the number of rows returned.C. Column-masking behavior will return all rows.D. Column-masking behavior will restrict the number of rows returned.

4. Which of the following is the default policy type in Oracle Database 10g?

A. POLICY_TYPE=DBMS_RLS.STATICB. POLICY_TYPE=DBMS_RLS.DYNAMICC. POLICY_TYPE=DBMS_RLS.SHAREDD. POLICY_TYPE=DBMS_RLS.CONTEXT_SENSITIVE

5. How does Oracle Database 10g audit a MERGE statement?

A. It audits only the UPDATE part of the MERGE statement.B. It audits only the DELETE part of the MERGE statement.C. It audits the MERGE statement with the underlying INSERT or UPDATE statements.D. It doesn’t audit MERGE statements.

Self Test 27

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:30 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 586: OCA OCP - Oracle10G New Features For Administrators Exam Guide

28 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

Enhancements in Managing Multitier Environments

6. What are the two ways in which you can find out the value of the new attribute, CLIENT_IDENTIFIER?

A. V$INSTANCE

B. V$SESSION

C. DBA_USERS

D. SYS_CONTEXT

7. How do you enable tracing for all calls for a given application client?

A. EXEC DBMS_MONITOR.client_id_trace_enable

B. EXEC DBMS_MONITOR.client_id_stat_enable

C. EXEC DBMS_MONITOR.client_identifier_trace_enable

D. EXEC DBMS_MONITOR.serv_mod_act_trace_enable

8. What do you use the SERV_MOD_ACT_TRACE_ENABLE procedure for?

A. To trace a client session throughout its lifeB. To enable SQL tracing for a combination of client ID, service name, and module nameC. To enable SQL tracing for a combination of username, service name, and module nameD. To enable SQL tracing for a combination of service name, action name, and module name

9. What does the TRCSESS utility do?

A. Help you enable a sessionwide traceB. Help you interpret end-to-end tracing outputC. Consolidate information from several trace files into a single outputD. Stress the system to see how much load it can handle when you introduce new SQL

statements in the database.

10. What are the three benefits of using the new statistics aggregation dimensions in OracleDatabase 10g (client identifier, service name, module name, and action name)?

A. Monitoring performance of individual clientsB. Managing the workloadC. Setting threshold-based alertsD. Providing correct input to ADDM

SQL and PL/SQL Enhancements

11. Which of the following are new Oracle Database 10g enhancements regarding conversionbetween CLOB and NCLOB datatypes?

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:30 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 587: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Self Test 29

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

A. Implicit conversion of SQL IN and OUT bind variables in queries and DML statementsB. Explicit conversion of SQL IN and OUT bind variables in queries and DML statementsC. Implicit conversion of SQL IN and OUT bind variables in queries onlyD. Implicit conversions of SQL IN and OUT bind variables in DML statements only, but not

in queries

12. Which of the following is not an Oracle regular expression function?

A. REGEXP_LIKE

B. REGEXP_BETWEEN

C. REGEXP_REPLACE

D. REGEXP_SUBSTR

13. Which of the following shows a correct specification of a regular expression?

A. REGEXP_LIKE (source_string, pattern, match_option)

B. REGEXP_LIKE (source_string, match_option, pattern)

C. REGEXP_LIKE (pattern, source_string, match_option)

D. REGEXP_LIKE (match, pattern, match_option)

14. Which two of the following are enhancements to the NLS_SORT function?

A. Case-insensitive functionalityB. Case-sensitive functionalityC. Accent-sensitive functionalityD. Accent-insensitive functionality

15. The output of the UTL_COMPRESS compressed data is compatible with which of thefollowing?

A. GZIP onlyB. GZIP and GUNZIPC. GUNZIP onlyD. Neither GZIP nor GUNZIP

Miscellaneous Enhancements

16. Which two of the following statements will work if your goal is to enable resumable statementsin Oracle Database 10g?

A. ALTER SESSION SET RESUMABLE STATEMENTS=TRUE

B. ALTER SESSION SET RESUMABLE =TRUE

C. ALTER SESSION SET RESUMABLE_TIMEOUT=3600

D. RESUMABLE TIMEOUT=3600

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:30 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 588: OCA OCP - Oracle10G New Features For Administrators Exam Guide

30 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

17. In Oracle Database 10g, which of the following do you have to do in order to start a sharedserver?

A. ALTER SYSTEM SET SHARED_SERVERS=8

B. ALTER SYSTEM SET DISPATCHERS=2

C. ALTER SYSTEM ENABLE SHARED SERVER

D. ALTER SYSTEM START DISPATCHER

18. Which two of the following will ensure automatic checkpoint tuning by Oracle?

A. Set the FAST_START_MTTR_TARGET parameter to a positive value.B. Set the FAST_START_MTTR_TARGET parameter to zero.C. Don’t set the FAST_START_MTTR_TARGET parameter.D. Set the FAST_START_MTTR_TARGET to a value of TRUE.

19. Which of the following is mandatory when you are using the easy connect naming method?

A. Host nameB. Database nameC. Service nameD. Port number

20. Which DBMS_LOGMNR feature facilitates the automatic adding of redo log files for mining?

A. REMOVE_LOGFILE

B. CONTINUOUS_MINE

C. NO_ROWID_IN_STMT

D. AUTOMATIC_LOGFILE

LAB QUESTIONGiven the following statement, use regular expressions to search for a comma followed by a space. Youmust then have zero or more characters that are not commas, and include another comma in the end.

'first child, second child , third child',

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:31 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 589: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SELF TEST ANSWERS

VPD and Auditing Enhancements

1. � A and C. Column-level VPD policies apply only to tables and views.� B, D, and E are wrong since column-level VPD policies don’t apply to these objects.

2. � C. You may apply a policy function to anySELECT, INSERT, UPDATE, or DELETEstatement.� A, B, and D are wrong since they either point out the wrong type (DDL statements)or leave out some DDL statements that are allowed.

3. � B and C. B is correct because the default behavior under a column-level VPD will restricttheir rows returned to only those that meet the VPD column-level restrictions. C is correct sincethe column-masking behavior will always return all rows, but will have NULL values for thecolumns to which the column-level VPD policy applies.� A and D are wrong since the actions they represent are exactly opposite to the actualbehavior of Oracle, as explained above for the correct answers.

4. � B. The default policy type in Oracle Database 10g is dynamic.� A, C, and D are wrong since dynamic policy type is the default.

5. � C. Oracle will treat a MERGE statement as individual UPDATE and INSERT statements,and will audit those statements on an individual basis.� A and B are wrong since Oracle audits both UPDATE and INSERT statements. D is wrongsince Oracle does audit MERGE statements.

Enhancements in Managing Multitier Environments

6. � B and D are correct since you find out the value of the CLIENT_IDENTIFIER attributeby querying the V$SESSION view, or by using SYS_CONTEXT.� A and C are wrong since neither the V$INSTANCE nor the DBA_USERS view has anyinformation on the CLIENT_IDENTIFIER attribute.

7. � A. You use the client_id_trace_enable procedure to enable tracing of the CLIENT_IDENTIFIER attribute, which enables end-to-end tracing of all calls for a database client.� B is wrong because the procedure enables you to collect statistics, not trace sessions. C iswrong because it refers to CLIENT_IDENTIFIER instead of CLIENT_ID. D is wrong becausethis procedure is for tracing a combination of service name, module name, and action names.

Self Test Answers 31

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:31 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 590: OCA OCP - Oracle10G New Features For Administrators Exam Guide

8. � D. The SERV_MOD_ACT_TRACE procedure enables SQL tracing for a combination ofservice name, action name, and module name.� A, B, and C are wrong because the SERV_MOD_ACT_TRACE procedure doesn’t help withtracing client activities directly.

9. � C. The TRCSESS utility consolidates output from several tracing sessions into a singleoutput, so you can trace a session more effectively.� A is incorrect because the TRCSESS utility doesn’t help you with enabling a trace. B iswrong because it’s the TKPROF utility that helps interpret the output of a trace. D is wrongbecause the TRCSESS session isn’t a stress testing tool.

10. � A, B, and C. The new statistics aggregation dimensions help you monitor individual clientperformance, manage the workload, and set threshold-based alerts.� D is wrong because the ADDM tool doesn’t get any data based on the new statisticsaggregation dimensions.

SQL and PL/SQL Enhancements

11. � A. Oracle now implicitly converts SQL IN and OUT bind variables in both queries andDML statements when they involve CLOB and NCLOB datatypes.� B is wrong since you had do the conversion explicitly in Oracle9i, not Oracle Database 10g.C and D are wrong since the implicit conversion happens in both queries and DML statements.

12. � B. The REGEXP_BETWEEN is not a valid Oracle regular expression function.� A, C, and D are wrong since all of these are valid Oracle regular expression functions.

13. � A. All regular expression specification must first provide the source string, after which comesthe pattern (regular expression) and finally, any optional match options.� B and C are wrong since they present the right components in the wrong order. D is wrongsince it includes a nonexistent component (match).

14. � A and D. Oracle Database 10g provides both case-insensitive and accent-insensitivefunctionality through the NLS_SORT function.� B and C are wrong since you already have these features in Oracle9i.

15. � B. The output of the UTL_COMPRESS utility is compatible with the output of the GZIPand GUNZIP utilities.� A, C, and D are wrong alternatives since the UTL_COMPRESS utility’s output is compatiblewith output from both the GZIP and GUNZIP utilities.

32 Chapter 12: Miscellaneous New Features

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:31 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 591: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Miscellaneous Enhancements

16. � C and D. C is correct since this statement was valid in Oracle9i and continues to work thesame way in Oracle Database 10g. D shows how you can enable resumable statements with thenew RESUMABLE TIMEOUT initialization parameter.� A and B are wrong because they present statements with the wrong syntax.

17. � A. In Oracle Database 10g, you only need to set the number of shared servers by using theALTER SYSTEM SET SHARED SERVERS command to start the shared server.� B, C, and D are wrong since they are all nonexistent commands.

18. � A and C. You let Oracle automatically tune checkpointing by either setting the FAST_START_MTTR_TARGET to a non-zero value or leaving it out completely.� B is wrong since setting the FAST_START_MTTR_TARGET to zero will disable automaticcheckpoint tuning. D refers to a nonexistent option.

19. � A. Host name is the only item that’s mandatory in the new easy connect naming method.� B, C, and D are wrong since none of these is mandatory under the new naming method.

20. � B. If you specify the CONTINUOUS_MINE option, and specify a STARTSCN or STARTTIMEparameter value, Oracle will automatically add the redo logs by default.� A is wrong because this option helps you remove redo log files, not add them automatically.C is wrong since this option is used for generating reconstructed statements without a ROWID.D refers to a spurious procedure name.

LAB ANSWERThe following regular expression-based query will get you the result you have been asked to produce.Notice the use of the pattern ', [^,]*,' in the query.

SQL> select regexp_substr('first child, second child , third child',2 ', [^,]*,')3* from dual;

REGEXP_SUBSTR('F-------------------, second child ,SQL>

Lab Answer 33

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12

P:\010Comp\CertPrs8\862-4\ch12.vpTuesday, August 31, 2004 1:48:31 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 592: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Glossary

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1Blind Folio 1:1

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 593: OCA OCP - Oracle10G New Features For Administrators Exam Guide

2 Glossary

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

accent-insensitive sort An accent-insensitive sort is a new sorting option inOracle Database 10g. You can use the session parameter NLS_SORT to specify thelinguistic sort name. The _AI value is suffixed to a sort name to indicate an accent-insensitive sort.

Active Session History (ASH) Active Session History (ASH) consists ofrecent session activity. ASH is actually a rolling buffer in memory, and you can viewthe statistics using the V$ACTIVE_SESSION_HISTORY view. The ManageabilityMonitor (MMON) process flushes ASH data to disk every 60 minutes.

ADDM See Automatic Database Diagnostic Monitor.

advisory framework The advisory framework consists of a set of server-basedadvisors that are designed around a common infrastructure. Automatic DatabaseDiagnostic Monitor (ADDM) is part of the advisory framework, as are the SQLTuning Advisor and other advisors. All the advisors have a uniform interface anda common data source: the Automatic Workload Repository (AWR).

ALERT_QUE You can subscribe to the ALERT_QUE and read the ALERT_QUEif you wish to create your own tool to display database alerts, rather than using theOracle Database 10g Database Control.

ALL_ROWS ALL_ROWS is the default value for the OPTIMIZER_MODEinitialization parameter. The optimizer uses a cost-based approach for all SQLstatements in the session, regardless of the presence of statistics, and optimizes witha goal of best throughput (minimum resource use to complete the entire statement).

ARBn ARBn is an Automatic Storage Management (ASM) background processthat performs the rebalancing of data extents. You can have multiple ARB processes,named ARB1, ARB2, and so on.

ASH See Active Session History.

ASM See Automatic Storage Management.

ASM_DISK_GROUPS The ASM_DISK_GROUPS initialization parameterspecifies the list of names of disk groups to be mounted by an ASM instance atinstance startup or when you issue the ALTER DISKGROUP ALL MOUNT statement.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 594: OCA OCP - Oracle10G New Features For Administrators Exam Guide

ASM_DISKSTRING The ASM_DISKSTRING initialization parameter specifiesan operating system-dependent value used by ASM to limit the number of disksconsidered for discovery. When a new disk is added to a disk group, the ASM instancewill discover the new disk using the value of ASM_DISKSTRING. If you omit thisparameter, the ASM instance will find all disks to which it has read/write access.

ASM file aliases Automatic Storage Management (ASM) alias filenamesprovide a more intuitive way of referring to ASM files, rather than using the fullyqualified names (system aliases) that ASM generates when it creates new files.

ASM file templates Automatic Storage Management (ASM) files are namedcollections of attributes that you apply to a file during its creation. Templates simplifyfile creation. Templates are applied to a file, but are actually associated with a disk group.

ASM filenames Automatic Storage Management (ASM) filenames can be ofthe following forms: fully qualified, numeric, alias, alias with template, incomplete,and incomplete with template. The correct filenaming form depends on the contextin which you intend to use the file. The three different contexts are referencing anexisting file, creating a single new file, and creating multiple new files.

ASM files Automatic Storage Management (ASM) files are Oracle database filesstored in ASM disk groups. All ASM files are Oracle Managed Files (OMF), and youmust back up them with the Recovery Manager (RMAN). ASM doesn’t managebinary files, alert logs, trace files, or password files.

ASM instance An Automatic Storage Management (ASM) instance is thespecial instance you need to start in order to use ASM in your database. ASMinstances are unique in the sense that they don’t mount databases, but merely makeASM files available to regular database instances. Databases communicate with anASM instance to get information about the ASM file layouts.

ASM_POWER_LIMIT The ASM_POWER_LIMIT initialization parameterpertains to an ASM instance, and it controls the speed of a disk-rebalancingoperation. The range is 1 to 11, with 1 as the default and 11 providing the fastestrebalancing when you add or remove disks from an ASM disk storage system. Thehigher the limit, the faster rebalancing will complete. Lower values will take longer,but they consume fewer processing and I/O resources.

ASM_POWER_LIMIT 3

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 595: OCA OCP - Oracle10G New Features For Administrators Exam Guide

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

ASMB ASMB is a background process that exists in each database that usesAutomatic Storage Management (ASM). When you start the database, the ASMBprocess connects to the ASM process and a foreground process, and conducts allcommunication between the database and the ASM instance.

ATO See Automatic Tuning Optimizer.

AUDIT_TRAIL The AUDIT_TRAIL initialization parameter enables ordisables database auditing. AUDIT_TRAIL can take the values db or true, os,and db_extended. The db_extended value enables database auditing and sendsaudit records to the database audit trail (the SYS.AUD$ table). It also populates theSQLBIND and SQLTEXT CLOB columns of the SYS.AUD$ table.

automatic channel failover When you backup your database with theRecovery Manager (RMAN), one of the channels may fail during the process.Automatic channel failover is the new feature whereby RMAN will attempt tocomplete the backup on another channel.

automatic checkpoint tuning Oracle Database 10g automatically tunescheckpointing activity to minimize recovery time while reducing the impact ofcheckpointing on performance. You don’t need to set any checkpoint-relatedparameters. You can either enable automatic checkpoint tuning by setting anonzero value for the FAST_START_MTTR_TARGET initialization parameteror omit it from your init.ora or SPFILE file.

Automatic Database Diagnostic Monitor (ADDM) The AutomaticDatabase Diagnostic Monitor (ADDM) is a self-diagnostic engine that is part ofOracle Database 10g. ADDM helps the database diagnose its performance anddetermine how to resolve problems. ADDM runs automatically after each AutomaticWorkload Repository (AWR) statistics capture and performs analysis on a proactivebasis. ADDM diagnoses the performance of the system, using time as a commoncurrency between components.

automatic maintenance tasks The automatic maintenance tasksinfrastructure enables Oracle Database 10g to automatically perform routineadministrative tasks such as collecting optimizer statistics during a predefinedmaintenance window. By default, the maintenance window starts at 10 P.M. everynight and lasts until 6 A.M. the next morning, and also includes the entire weekend.You can customize attributes of the maintenance window, including start and endtime, frequency, and days of the week.

4 Glossary

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 596: OCA OCP - Oracle10G New Features For Administrators Exam Guide

automatic undo retention tuning 5

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

automatic optimizer statistics collection Oracle Database 10g fullyautomates optimizer statistics collection. The Oracle Scheduler comes with a built-in job called GATHER_STATS_JOB, which executes the DBMS_STATS.GATHER_DATABASE_STATS_JOB_PROC procedure to automatically collect the statistics.All you need to do is ensure that the STATISTICS_LEVEL initialization parameteris set to TYPICAL or ALL (not BASIC). Oracle automatically gathers statistics forall database objects that have stale or missing statistics.

Automatic Shared Memory Management Automatic Shared MemoryManagement simplifies System Global Area (SGA) memory management byautomatically allocating memory among the four auto-tuned parameters: databasebuffer cache (default pool), shared pool, large pool, and Java pool. To use AutomaticShared Memory Management, set the SGA_TARGET initialization parameter to anonzero value and set the STATISTICS_LEVEL initialization parameter toTYPICAL or ALL.

automatic shared server configuration The automatic shared serverconfiguration helps you to easily switch between shared server and dedicated serverconfigurations without needing to start a dispatcher.

Automatic Storage Management (ASM) Automatic Storage Management(ASM) is an integration of the file system and a built-in volume manager for Oracledatabase files. It extends the concept of stripe and mirror everything (SAME)principles to optimize disk performance. ASM simplifies the optimal layout ofdatafiles, control files, and log files. Database files are automatically distributedacross all available disks, and database storage is rebalanced whenever storageconfiguration changes.

Automatic Tuning Optimizer (ATO) The SQL Tuning Advisor calls theAutomatic Tuning Optimizer (ATO) to perform four types of analysis: statisticsanalysis, SQL profiling, access path analysis, and SQL structure analysis.

Automatic Undo Management Automatic Undo Management is therecommended way to mange the undo in Oracle databases, although you couldstill do it manually. Once you specify the automatic undo management mode inthe init.ora (or spfile) file and create an undo tablespace, Oracle will automaticallycreate and manage the necessary undo segments.

automatic undo retention tuning Oracle Database 10g automatically tunes theinitialization parameter UNDO_RETENTION to control retention of undo informationin rollback segments.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 597: OCA OCP - Oracle10G New Features For Administrators Exam Guide

6 Glossary

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

Automatic Workload Respository (AWR) The Automatic WorkloadRepository (AWR) is an embedded, self-managing repository that captures workloadinformation and performance-related statistics on a routine basis. The database usesinformation contained in the repository for self-management activities.

AWR See Automatic Workload Repository.

backup compression If disk space is an issue, or your media-management softwaredoes not support compression, you can use the Recovery Manager (RMAN) backupcompression feature to compress RMAN backup sets.

base statistics Base statistics refer to raw performance statistics, such as the numberof physical reads since instance startup. Metrics are derived from base statistics.

bigfile tablespace A bigfile tablespace is a large tablespace containing just onefile. Oracle Database 10g lets you create both bigfile tablespaces and traditionaltablespaces, now called smallfile tablespaces. The default tablespace type is smallfile.The bigfile tablespace type makes a tablespace logically equal to a datafile.

block change tracking Oracle tracks the physical location of database changesin a new file called the change-tracking file. The Recovery Manager (RMAN) usesthe change-tracking file to determine which data blocks to read during an incrementalbackup, thus making incremental backups faster by avoiding the reading of entiredatafiles.

calendaring expression A calendaring expression is the primary methodof setting the REPEAT_INTERVAL attribute for a Scheduler job. A calendaringexpression has three attributes: frequency, repeat interval, and an optional specifier.

case-insensitive sort A case-insensitive sort is a new sorting option in OracleDatabase 10g. You can use the session parameter NLS_SORT to specify the linguisticsort name. The _CI value is suffixed to a sort name to indicate a case-insensitive sort.

CATALOG START WITH The CATALOG START WITH command in theRecovery Manager (RMAN) will look at all files that are not a part of the catalogalready, starting with the specified directory. This saves you time and effort inremembering cryptic filenames.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 598: OCA OCP - Oracle10G New Features For Administrators Exam Guide

compressed backups 7

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

change-aware incremental backups By using the new change-tracking file,the Recovery Manager (RMAN) can avoid scanning the entire datafile during anincremental backup. Instead, it will scan only the changed blocks of data, thusreducing backup time.

change-tracking file Oracle tracks the physical location of database changes ina new file called the change-tracking file. The Recovery Manager (RMAN) uses thechange-tracking file to determine which data blocks to read during an incrementalbackup, thus making incremental backups faster by avoiding the reading of entiredatafiles.

Clone Database Tool The Clone Database Tool is an Enterprise Managerwizard that lets you step through a database cloning operation. With this tool,which uses RMAN to perform the cloning, you can clone a database to anotherOracle Home while the source database is open.

column-level VPD Virtual Private Database (VPD) is now more fine-grained.Column-level VPD enables you to enforce row-level security when a security-relevantcolumn is referenced in a query. You can now enforce VPD rewrite when a queryreferences a particular column. You thus enforce access control based on the securitycolumns that are accessed by a user.

column-masking behavior By default, when a query references a security-relevant column, column-level VPD restricts the number of rows returned. By usingcolumn-masking behavior (using the SEC_RELEVANT_COLS_OPT parameter ofthe DBMS_RLS.ADD_POLICY procedure), all rows will be displayed, includingthose that reference security-relevant columns.

COMPATIBLE The COMPATIBLE initialization parameter allows you to use anew release of Oracle, while at the same time guaranteeing backward-compatibilitywith an earlier version. The parameter specifies the release with which Oracle mustmaintain compatibility.

compressed backups You can now use binary compression to reduce the sizeof your backup sets. You must have the compatibility set to at least 10.0.0 and usethe following Recovery Manager (RMAN) command:

BACKUP AS COMPRESSED BACKUPSET DATABASE;

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 599: OCA OCP - Oracle10G New Features For Administrators Exam Guide

8 Glossary

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

configurationless client connect Configurationless client connect is a newconnection identifier for SQL clients, which doesn’t depend on any configurationfiles and doesn’t require name lookup services. In the client identifier syntax, all youmust have are the host, port, and service name to connect to a database server. Thisalso known as the easy naming connect method. This method simplifies networkmanagement by enabling a database connection to be made without the need to firstconfigure a network service name or perform other network configuration on theclient. To configure the easy connect method, you specify the keyword EZCONNECTin your sqlnet.ora file.

context-sensitive policies A context-sensitive policy changes when certainsession context attributes change within a user’s session. The database reevaluatesthe policy function each time there is a context change. The policy predicates willthus change, based on session context changes.

cross-platform transportable tablespaces Cross-platform transportabletablespaces are tablespaces that can be transported across diffferent operating systemplatforms.

CTWR The CTWR is the new Oracle background process that writes databasechange information to the change-tracking file.

Data Pump The Data Pump export and import utilities provide high-speedmovement of data from one database to another. These utilities offer severaladvantages over the original Oracle export and import utilities, including the abilityto completely restart export and import jobs, detach and reattach to long-runningjobs, estimate how much disk space an export job would consume, and performexport and import operations over the network. The Data Pump utilities alsosupport fine-grained object selection.

DATA_PUMP_DIR DATA_PUMP_DIR is an environment variable that youcan define to specify the directory object name in Data Pump. When you use thisvariable, you don’t need to specify the DIRECTORY parameter in a Data Pump job.

Data Pump direct path Direct path is one of two access methods that DataPump supports to load and unload table data. If it is possible, Data Pump tries to usethe direct-path access method to load and unload data. The other access method isexternal tables.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 600: OCA OCP - Oracle10G New Features For Administrators Exam Guide

Database Control (Enterprise Manager) Database Control is the newname for the Oracle Enterprise Manager GUI for managing Oracle databases. Youcan use the Database Control for managing single databases, and the software comeswith the Oracle Database 10g Server software.

database features usage tracking Oracle Database 10g automatically tracksusage of various database features. This enables you to evaluate how each feature isbeing utilized in the database.

Database Upgrade Assistant (DBUA) The Database Upgrade Assistant(DBUA) is a GUI-based Oracle tool that simplifies the task of upgrading to OracleDatabase 10g from an older version of Oracle software.

database wait model The database wait model enables you to determine whatsessions are waiting for, keeps a history of waits and wait durations per session, andmaintains wait statistics for SQL statements in a dynamic performance view.

datafile conversion If you are transporting tablespaces across platforms, thefiles in both platforms must have the same endian format. If the endian formats aredifferent, you need to convert the datafiles either before or after you move thedatafiles that belong to the tablespaces you’re transporting.

DB_FLASHBACK_RETENTION_TARGET The DB_FLASHBACK_RETENTION_TARGET initialization parameter specifies the upper limit (inminutes) on how far back in time the database may be flashed back. Of course,how far back you can flashback a database depends on how much flashback dataOracle has kept in the flash recovery area.

DB_RECOVERY_FILE_DEST The DB_RECOVERY_FILE_DESTinitialization parameter specifies the default location for the flash recovery area.

DB_RECOVERY_FILE_DEST_SIZE The DB_RECOVERY_FILE_DEST_SIZE initialization parameter specifies (in bytes) the limit on the total spaceallocated for the database recovery files created in the flash recovery area.

DBA_DATAPUMP_JOBS The DBA_DATAPUMP_JOBS view displays allData Pump jobs in the database.

DBA_DATAPUMP_JOBS 9

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 601: OCA OCP - Oracle10G New Features For Administrators Exam Guide

10 Glossary

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

DBA_ENABLED_TRACES The DBA_ENABLED_TRACES view displaysinformation about enabled SQL traces. The view shows the following types oftraces: CLIENT_ID, SERVICE, SERVICE_MODULE, and SERVICE_MODULE_ACTION.

DBA_OUTSTANDING_ALERTS The DBA_OUTSTANDING_ALERTSview describes alerts that have yet to be resolved.

DBA_SCHEDULER_JOB_LOG The DBA_SCHEDULER_JOB_LOG viewdisplays log information for all Scheduler jobs in the database.

DBA_SCHEDULER_JOB_RUN_DETAILS The DBA_SCHEDULER_JOB_RUN_DETAILS view displays log run details for all Scheduler jobs in the database.

DBA_SERVER_REGISTRY The DBA_SERVER_REGISTRY view displaysinformation about the components loaded into the database. It helps you determinethe success of your database upgrade process.

DBMS_ADVISOR DBMS_ADVISOR is the database package that is thefoundation for the Server Manageability Suite of advisors (advisory framework)that identify and resolve performance problems related to the various databaseserver components.

DBMS_AQADM The DBMS_AQADM package provides procedures to manageOracle Streams Advanced Queuing (AQ) configuration and administration information.

DBMS_DATAPUMP The DBMS_DATAPUMP package is used to perform theData Pump export and import of data.

DBMS_METADATA The DBMS_METADATA package lets you retrievemetadata from the database dictionary.

DBMS_MONITOR The DBMS_MONITOR package lets you use PL/SQL forcontrolling additional tracing and statistics gathering.

DBMS_MVIEW The DBMS_MVIEW package enables you to understand thecapabilities of materialized views and potential materialized views, including theirrewrite capability. The pacakge also enables you to refresh materialized views andpurge logs.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 602: OCA OCP - Oracle10G New Features For Administrators Exam Guide

DURATION 11

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

DBMS_RLS The DBMS_RLS package contains the procedures to implementand manage fine-grained access control, which is used to implement Virtual PrivateDatabase (VPD).

DBMS_SCHEDULER The DBMS_SCHEDULER package provides a collectionof functions and procedures that help you manage the Oracle Scheduler facility.

DBMS_SERVER_ALERT The DBMS_SERVER_ALERT package lets you issuealerts when some threshold has been violated.

DBMS_SQLTUNE The DBMS_SQLTUNE package provides the interface totuning SQL statements.

DBUA See Database Upgrade Assistant.

dense data Dense data is data where there is a row for each combination of thevarious dimensions.

disk group An Automatic Storage Management (ASM) disk group is a set ofdisks managed as a single logical unit. You add or remove storage from a disk groupby adding or removing ASM disks from a disk group. All ASM files are stored in adisk group.

disk group mirroring Automatic Storage Management (ASM) disk groupsare mirrored at the extent level to protect data. There are three types of mirroring:external redundancy, normal redundancy, and high redundancy.

disk group rebalancing Automatic Storage Management (ASM) automaticallydynamically rebalances disk groups when you add or remove disks from a disk group.ASM always keeps I/O balanced by moving around only the amount of data proportionalto the amount of storage that is being added or removed from the disk group.

DROP DATABASE The new DROP DATABASE command drops a databaseby deleting all database files, all online logs, control files, and server parameter files(SPFILES).

DURATION DURATION is a Recovery Manager (RMAN) backup commandoption that can take the values PARTIAL, MINIMIZE TIME, and MINIMIZELOAD. The DURATION option lets you control the speed and duration of yourbackup operations.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:40 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 603: OCA OCP - Oracle10G New Features For Administrators Exam Guide

12 Glossary

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

dynamic policies Dynamic policies apply to the Virtual Private Database(VPD) concept. Dynamic policies change based on certain variables such as thetime of day, thus returning different sets of rows for the same query. Previously,all VPD policies were dynamic by default, which meant that Oracle executedthe function for each DML statement. You can now use new static policies.

end-to-end application tracing The new end-to-end application tracingcapability simplifies the debugging of performance problems in multitier environments.It also makes debugging and tracing of applications, which use MODULE and ACTIONname annotation, easier and more efficient.

endian format Endian format is the byte ordering of files. When you transporttablespaces across platforms, you must ensure that the endian format is identical onboth platforms. If not, you need to convert the datafiles to ensure that they are thesame on the source and target platforms.

ESTIMATE The ESTIMATE parameter is a Data Pump export parameter andspecifies the method that export will use to estimate how much disk space each tablein the export job will consume (in bytes).

ESTIMATE_ONLY The ESTIMATE_ONLY Data Pump parameter estimatesthe space that an export or import job would require, without actually performingthe export operation.

EXCLUDE The EXCLUDE Data Pump parameter enables you to exclude adatabase object from an export or import operation.

EXPLAIN_MVIEW The EXPLAIN_MVIEW procedure of the DBMS_MVIEWpackage tells you whether a materialized view is fast refreshable or eligible forgeneral query rewrite.

external table access driver Data Pump provides an external table accessdriver (ORACLE_DATAPUMP) that reads and writes files to enable high-speedloading and unloading of database tables.

external table population External table population is the ability to load datainto platform-independent, Oracle proprietary flat files from a database table.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 604: OCA OCP - Oracle10G New Features For Administrators Exam Guide

external tables External tables enable you to use external data as a virtual tablethat you can view and join to other tables, without needing to load the data inactual database tables. External tables are read-only (no DML activity is possible).

EZCONNECTt See configurationless client connect.

failure group A failure group is an Automatic Storage Management (ASM)concept that refers to the set of disks inside a particular disk group that share acommon resource, whose failure must be tolerated. A common example is a set ofdisks that connect to a common SCSI controller.

fast incremental backups The fast incremental backups feature speeds upincremental backups by tracking block changes in the new change-tracking file.The new background process CTWR writes changed block information to thechange-tracking file, and the Recovery Manager (RMAN) will back up only thechanged blocks.

fast ramp-up Fast ramp-up is the new feature wherein the database usesAutomatic Workload Repository (AWR) statistics to decide the number of undosegments to bring online when you start an instance or when you switch an undotablespace.

fine-grained access control Fine-grained access control enables you to buildapplications that enforce security policies at a low level of granularity. (These policiesare also referred to as VPD policies.) You can use it, for example, to restrict anemployee to see only his or her own information in a database table.

FIRST_ROWS You can specify FIRST_ROWS as the value for theOPTIMIZER_MODE initialization parameter. Under the FIRST_ROWSsetting, Oracle will use a mix of cost and heuristics to find a best plan forfast delivery of the first few rows.

flash recovery area The flash recovery area is an unified storage location forbackups, archive logs, and any other files needed for Oracle recovery. The backupfiles are automatically deleted after they are backed up by the Recovery Manager(RMAN). The flash recovery area is also the location for saving the FlashbackDatabase logs.

flash recovery area 13

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 605: OCA OCP - Oracle10G New Features For Administrators Exam Guide

14 Glossary

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

Flashback Database The Flashback Database feature lets you quickly bring yourdatabase to a prior point in time by undoing all the changes that have taken placesince that time. You enable the Flashback Database feature after you first configurea flash recovery area, and then set the retention target with the DB_FLASHBACK_RETENTION_TARGET initialization parameter. The flashback time interval willactually depend on the number of flashback database logs stored in the flashrecovery area.

Flashback Database logs Flashback Database logs are a new type of databaselog files, which are analogous to redo logs. When you turn on the Flashback Databasefeature, Oracle will start logging before images of data blocks that are being changed.These before images are saved in the Flashback Database logs, which are automaticallycreated and managed in the flash recovery area. The new background process RVWR(recovery writer) writes the Flashback Database data from the flashback buffer to theFlashback Database logs.

Flashback Drop The Flashback Drop feature lets you undo the effects of aDROP TABLE statement. The dropped tables are saved in the Recycle Bin. Thecommand you actually use to flashback a table is of the format FLASHBACK TABLEtable-name TO BEFORE DROP.

Flashback Query The Flashback Query feature lets you query a database as ofa certain clock time or a system change number.

Flashback Table The Flashback Table feature lets you recover a table to a pointin time in the past without restoring a backup.

Flashback Transaction Query The Flashback Transaction Query capabilityenables you to examine changes to the database at the transaction level. Using thetransaction history, you can diagnose problems, perform analysis, and audit transactions.

FLASHBACK_TRANSACTION_QUERY The FLASHBACK_TRANSACTION_QUERY view contains all the SQL statements that help youundo the changes made by specific transactions, using the Flashback TransactionQuery feature.

Flashback Versions Query The Flashback Versions Query feature lets youview changes to one or more rows, along with all the metadata of the changes.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 606: OCA OCP - Oracle10G New Features For Administrators Exam Guide

INSTANCE_TYPE 15

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

flushing the buffer cache Oracle Database 10g lets you flush the buffer cacheby using the following command:

ALTER SYSTEM FLUSH BUFFER_CACHE;

global scripts Global scripts, an enhanced Recovery Manager (RMAN) feature,are scripts that can be used by any database connecting to the target database.

grid computing Grid computing is the coordinated use of a large number ofservers and storage acting as one computer. Grid computing lets you automaticallyprovision for spikes on demand, and you’ll have computing power available whenyou need it. Grids are built with low-cost modular components, so you can startsmall and preserve your investment as your business needs grow.

Grid Control The Grid Control is the centralized version of Oracle EnterpriseManager, which lets you manage several databases and hosts simultaneously. Youmust install the Grid Control separately from the database.

guaranteed undo retention When you enable guaranteed undo retention byusing the RETENTION GUARANTEE clause either during the creation of the undotablespace or by altering it later, the database never overwrites unexpired undo data.

hash-partitioned global indexes In a hash-partitioned global index, eachpartition contains the values determined by a hash function, which is based on thepartitioning key and the number of partitions. These indexes improve performanceby spreading contention when the index is monotonically growing, because most ofthe index insertions occur only on the right edge of an index.

idle timeouts You can set up maximum idle timeouts for a resource plan usingthe DBMS_RESOURCE_MANAGER package. When a session exceeds the MAX_IDLE_TIME parameter value specified in the CREATE_PLAN_DIRECTIVEprocedure, the Process Monitor (PMON) will kill the session.

INCLUDE The INCLUDE Data Pump parameter lets you require that onlyspecified object types and objects be included in an export or import job.

INSTANCE_TYPE The INSTANCE_TYPE initialization parameter is usedin connection with an Automatic Storage Management (ASM) instance to specifywhether the instance is a database instance or an ASM instance.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 607: OCA OCP - Oracle10G New Features For Administrators Exam Guide

16 Glossary

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

job A job is a user-defined task that is scheduled to run one or more times. A jobcontains information about the task (the action) to be run and when it should run(the schedule). You can specify the action and schedule when creating the job,or the job can refer to an existing program and schedule.

job class A job class is a group of jobs that have similar characteristics andbehavior. A job class is a way of grouping jobs into larger entities, thus enablingyou to prioritize among the job classes.

job priority Job priority helps you prioritize the jobs in your database. There aretwo levels at which you can prioritize a job: at the class level, using resource plans,and within the class, using the job priority attribute of the job. The default priorityof a job is 3.

locally managed tablespaces Locally managed tablespaces track all extentinformation in the tablespace itself by using bitmaps. The DBMS_SPACE_ADMINpackage provides procedures for administering locally managed tablespaces.

locking statistics You can lock representative statistics when a table’s datakeeps changing continuously. You can lock a table with or without any statistics.

logging level You can set the logging level of the Scheduler by using theLOGGING_LEVEL parameter. You can set this parameter to either DBMS_LOGGING_ FULL or DBMS_SCHEDULER.LOGGING_RUNS at either thejob class or the individual job level.

MANAGE SCHEDULER MANAGE SCHEDULER is a Scheduler-associatedsystem privilege, which lets a user perform all Scheduler administration tasks. TheSCHEDULER_ADMIN role has all the privileges of the MANAGE SCHEDULERprivilege along with the WITH ADMIN OPTION clause. The DBA role includes theSCHEDULER_ADMIN role by default.

Manageability Monitor (MMON) The Manageability Monitor (MMON)background process performs various manageability-related background tasks,including issuing alerts whenever a given metric violates its threshold value andtaking snapshots for the Automatic Workload Repository (AWR) feature. TheMMON wakes up every minute to compute metric values. The MMON also verifiesthe thresholds for all the metrics you define and generates the alerts, if necessary.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 608: OCA OCP - Oracle10G New Features For Administrators Exam Guide

materialized view decomposition Materialized view decomposition refersto the breaking up of a nonrefreshable materialized view into submaterialized viewsreferenced by the original materialized view. The automatic materialized viewdecomposition mechanism handles cases where the materialized view-defining queryhas subqueries, set operators, or inline views. Each of the submaterialized views willbe refreshable.

Memory Manager (MMAN) The new Memory Manager (MMAN)background process manages automatic shared memory. MMAN serves as theSystem Global Area (SGA) memory broker and coordinates the sizing of theindividual memory components. It tracks the size of the memory componentsand monitors memory-resizing operations.

MERGE The MERGE command performs conditional update and insert operations.You may also use an optional DELETE clause with a MERGE command.

metrics Metrics are secondary statistics that the database derives from basestatistics. Metrics track the rate of change of a variable. An example of a databasemetric is the number of physical reads in the database in the past 60 minutes.

MMAN See Memory Manager.

MMNL The MMNL (Manageability Monitor Process Light; shown as theManageability Monitor Process 2 in a query of the V$BGPROCESS view) performsfrequent and lightweight manageability-related tasks, such as session history captureand metrics computation. If the Automatic Session History (ASH) buffer fills beforeMMON flushes it, MMNL will flush the data to disk.

MMON See Manageability Monitor.

MODEL See SQL MODEL clause.

network mode export By using the NETWORK_LINK export parameter, youcan perform a network export, provided you also specify the name of a valid databaselink. A network export moves data from a remote database to a dump file set local tothe instance running the Data Pump job.

network mode export 17

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 609: OCA OCP - Oracle10G New Features For Administrators Exam Guide

network mode import By using the NETWORK_LINK import parameter,you can initiate a network import. The impdp client will initiate the importrequest, and the server contacts the remote source database referenced by source_database_link. The server retrieves and writes the data directly to the targetdatabase tables. Since the entrie import is directly via the network, dump files aren’tnecessary.

nonthreshold alerts Some server-generated alerts refer to specific databaseevents such as ORA-1555 (snapshot too old) errors. These are not based on anythresholds, so they are called nonthreshold alerts, or stateless alerts. These alerts godirectly to the history table, without ever appearing in the DBA_OUTSTANDING_ALERTS view.

online segment shrink The online segment shrink feature shrinks segmentsonline and in-place (tables, indexes, and materialized views) that have free spacein them, thereby enhancing efficiency of space utilization.

Partition Change Tracking (PCT) Partition Change Tracking (PCT)is the ability to identify which rows in a materialized view are affected by a detailtable partition.

partition outer join Partitioned outer joins are extensions to the outer joinsyntax, and they are used primarily to improve performance and simplify SQLqueries for time-based calculations.

PCT See Partition Change Tracking.

PCT refresh When a materialized view is partitioned on the partitioning keycolumn or join-dependent expressions of the detail table, it is better to truncate oneor more partitions during a materialized view refresh, and then populate the partitionwith new data. This variant of the fast refresh is known as a PCT refresh.

PLSQL_OPTIMIZE_LEVEL PLSQL_OPTIMIZE_LEVEL specifies theoptimization level that Oracle will use to compile PL/SQL library units. The higherthe setting of this parameter, the more effort the compiler makes to optimize PL/SQLlibrary units. Oracle claims that setting this parameter to 1 or 2 will make PL/SQLprograms run considerably faster.

18 Glossary

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 610: OCA OCP - Oracle10G New Features For Administrators Exam Guide

policy framework The policy-based database framework lets you monitor alltargets to see if their configuration conforms to recommended policy configurationsettings. These policies are based on Oracle’s best practice configurationrecommendations. The database configuration framework is built on top of theconfiguration and metric collection facility of the Oracle Enterprise Manager.

policy function Fine-grained access control enables you to implement securitypolicies with policy functions and to associate these policies with tables or views.The security policy function generates a WHERE condition that is appended torelevant SQL statements, thereby restricting user access to rows of data in the tableor view.

Post-Upgrade Status Tool The Post-Upgrade Status Tool is invoked byrunning the utlu101s.sql script located in the $ORACLE_HOME/rdbms/admindirectory, after you upgrade a database to the Oracle Database 10g release. The scriptwill tell you if the individual components of the new database have been successfullyupgraded.

POWER The POWER clause is used when you rebalance an Automatic StorageManagement (ASM) disk group and specifies the power level of a disk rebalancingjob. By using the POWER clause in a rebalance disk group command, you canoverride the setting of the default speed set by using the initialization parameterASM_POWER_LIMIT.

proactive tablespace management The Tablespace Advisor gathers andreports historical data about each tablespace’s disk space usage and notifiesadministrators when tablespaces run low on available space.

program A program is a collection of metadata about what task the Schedulerwill run.

projected columns When dealing with external table files, which contain rowsof data that may be rejected due to errors, the projected column feature enables youto get a consistent result set, independent of the columns referenced by the SQLstatement accessing the data. Prior to Oracle Database 10g, only the columns referencedby the SQL statement were projected out by the access driver, and some rows wererejected due to conversion errors or data format errors.

projected columns 19

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 611: OCA OCP - Oracle10G New Features For Administrators Exam Guide

20 Glossary

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

PURGE You need to use the PURGE clause when you drop a database table if youwant Oracle to remove the table permanently. Otherwise, Oracle will save the tablein the Recycle Bin. Using the DROP TABLE PURGE command is equivalent to usingthe old DROP TABLE command.

RATIO RATIO refers to the new resource allocation method for specifying howmuch CPU each consumer group or subplan gets, when you use the Database ResourceManager. The RATIO method for specifying CPU allocation is for single-level plansthat use ratios to specify how CPU is distributed among consumer groups. EMPHASIS,the default method, is for multilevel plans that use percentages to specify how CPUis distributed.

RBAL The RBAL background process coordinates rebalancing activity for diskgroups in an Automatic Storage Management (ASM) instance.

rebalance Rebalance is an Automatic Storage Management (ASM) term thatrefers to the automatic rebalancing of disk groups when you add or remove disks.ASM performs the rebalancing to maintain balanced I/O across all the disks in adisk group.

Recycle Bin The Recycle Bin is actually a data dictionary table containinginformation about dropped objects. Dropped tables and any associated objects—such as indexes, constraints, and nested tables—are renamed. You can use theFLASHBACK TABLE … TO BEFORE DROP command to recover a dropped tablefrom the Recyle Bin.

Redo Logfile Size Advisor The Redo Logfile Size Advisor recommends theoptimal size of redo log files.

remapping Remapping is a Data Pump concept that refers to the ability toapply transformation during an import operation. You can remap datafiles usingthe REMAP_DATAFILE parameter, tablespaces using the REMAP_TABLESPACEparameter, and schemas using the REMAP_SCHEMAS parameter.

renaming tablespaces Oracle Database 10g provides the ability to renametablespaces. You no longer need to create a new tablespace, copy the contents fromthe old tablespace, and drop the old tablespace.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 612: OCA OCP - Oracle10G New Features For Administrators Exam Guide

segment shrinking 21

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

RESUMABLE_TIMEOUT The RESUMABLE_TIMEOUT initializationparameter enables or disables resumable statements. You can also use this parameterto specify a resumable timeout at the system level.

REWRITE_OR_ERROR The REWRITE_OR_ERROR hint will issue an error ifa query fails to rewrite. Using the REWRITE_OR_ERROR hint in a query causes thefollowing error if the query failed to rewrite:

ORA-30393: a query block in the statement did not rewrite

RUN_TO_COMPLETION RUN_TO_COMPLETION is a new value that youcan use for the CPU_MTH parameter when you create a resource consumer group. Itspecifies that sessions with the largest active time are scheduled ahead of other sessions.The CPU_MTH parameter specifies the distribution of CPU among sessions in aconsumer group. The default value is ROUND_ROBIN, which uses a round-robinschedule to ensure that sessions are executed fairly.

schedule A schedule indicates when a job should run. It has a start date thatspecifies the date and time when the schedule starts, an end date that indicates thedate and time when the schedule expires, as well as a repeat interval that indicateshow often it will repeat.

Scheduler The Scheduler is Oracle’s new scheduling feature that gives you theability to schedule a job to run at a particular date and time. It also provides you theability to create libraries of sharable Scheduler objects You can group jobs that sharecommon characteristics into larger entities called job classes, which can be prioritizedby controlling the system resources allocated to each of them.

Segment Advisor The Segment Advisor gives advice on whether an objectis a good candidate for the new online shrink operation, based on the amount offragmentation within segments. The Segment Advisor also reports on the historicalgrowth trend of segments.

segment resource estimation The new segment resource estimation featurefacilitates space management by giving a size estimate of the size of a new table orindex, so you can ensure that sufficient space is available.

segment shrinking Segment shrinking is the ability to shrink a segment inorder to eliminate fragmentation within the segment. Shrinking a segment can alsolower the high-water mark (HWM) of space usage for that object.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 613: OCA OCP - Oracle10G New Features For Administrators Exam Guide

22 Glossary

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

server-generated alerts Server-generated alerts are alerts that the databasewill proactively send to administrators when a problem is anticipated or any of theuser-selected metrics exceeds a defined threshold.

Server Manageability Suite The Server Manageability suite of Advisors is aset of expert systems that helps you identify and resolve various performance problemsin your database. These expert systems are the SQL Tuning Advisor, the SQL AccessAdvisor, the Undo Advisor, the Segment Advisor, and the various memory advisors.

SGA_TARGET The SGA_TARGET initialization parameter specifies the totalsize of all SGA components. If SGA_TARGET is specified, the following SGAmemory pools are automatically sized: buffer cache (DB_CACHE_SIZE), sharedpool (SHARED_POOL_SIZE), large pool (LARGE_POOL_SIZE), and Java pool(JAVA_POOL_SIZE).

shared policies Shared policies apply to Virtual Private Directory (VPD). Theylet you apply the same policy to several objects. You can have both shared static andshared context-sensitive policy types.

SKIP_UNUSABLE_INDEXES The SKIP_UNUSABLE_INDEXESinitialization parameter enables or disables the use and reporting of tables withunusable indexes or index partitions.

smallfile tablespace In Oracle Database 10g, you can have two types oftablespaces: bigfile and smallfile. Smallfile is the default tablespace type, andit is the same as the standard tablespaces used in previous Oracle versions.

snapshot The Automatic Workload Repository (AWR) automatically collectsperformance data (by default, on an hourly basis). These statistics are known assnapshots. You can also manually create snapshots.

snapshot baseline Baselines are defined on a pair of snapshots, and serve totag sets of snapshot data to compare performance against. Baselines help you retainsnapshot data belonging to a representative period in the past to compare againstthe current database behavior.

sorted hash cluster Sorted hash clusters are new data structures that let youretrieve data faster in applications where data is requested in the order in which itwas inserted.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 614: OCA OCP - Oracle10G New Features For Administrators Exam Guide

SQL Tuning Set (STS) 23

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

sparse data Sparse data refers to data with gaps, where no row exists for acertain combination of dimensions.

SQL Access Advisor The SQL Access Advisor identifies and helps resolveperformance problems relating to SQL statement execution by recommendingwhich indexes or materialized views to create, drop, or retain.

SQL MODEL clause The SQL MODEL clause provides a powerful building blockfor complex calculations such as forecasts and budgets. Using the MODEL clause, youcan treat relational tables as n-dimensional arrays and specify interrow referenceswithout complex SQL joins and unions. With the MODEL clause, you can define amultidimensional array on query results, and then apply sophisticated rules on thearray to calculate new values. By integrating advanced calculations into the database,performance, scalability, and manageability are enhanced significantly compared toperforming the calculations using external products.

SQL profile The Automatic Tuning Optimizer (ATO) creates profiles of SQLstatements, which are called SQL profiles, consisting of auxiliary statistics specificto that statement. SQL profiles address the problem of the query optimizer sometimesusing incorrect statistics, by collecting additional information using sampling andpartial execution techniques to verify and, if necessary, adjust the optimizer estimates.

SQL regular expressions Regular expressions enhance search-and-replacecapabilities. This functionality is implemented through new functions that areregular expression extensions to existing Oracle functions such as LIKE, REPLACE,and INSTR.

SQL Tuning Advisor The SQL Tuning Advisor is a new database advisor thateliminates manual tuning of SQL statements. It provides tuning advice in the formof precise actions along with their expected performance benefit. You can use thisfeature for SQL tuning of packaged applications, without requiring any modificationto the application code.

SQL Tuning Set (STS) A SQL Tuning Set (STS) is a new database object usedfor capturing SQL workload information and includes one or more SQL statements,a list of bind values, and basic execution statistics such as elapsed time, CPU time,and so on. SQL Tuning Sets provide the basic framework for capturing, managing,and tuning a representative SQL workload. SQL Tuning Sets allow selective, on-demand tuning of custom workloads. You can capture any SQL statements ofinterest and store them in an STS for future tuning without having to build andmaintain SQL scripts for tuning purposes.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:41 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 615: OCA OCP - Oracle10G New Features For Administrators Exam Guide

24 Glossary

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

SQLTUNE_CATEGORY The SQLTUNE_CATEGORY initialization parameterspecifies the category name that sessions can use to look up SQL profiles during SQLcompilation. By default, all profiles are created in the default category. This meansthat all user sessions where the SQLTUNE_CATEGORY initialization parameter is setto DEFAULT can use the profile.

STARTUP UPGRADE STARTUP UPGRADE is the new way to start a databasebefore you run the upgrade script. This command will start the database in theupgrade mode and sets system initialization parameters to values required to let thedatabase upgrade scripts run. You need to use this mode only when you first start anolder version of an Oracle database with a newer version (Oracle Database 10g) ofthe Oracle Database Server.

static policies Static policies apply to the Virtual Private Database (VPD)concept. Static policies enforce an unchanging policy. Previously, all VPD policieswere dynamic by default, which meant that Oracle executed the function for eachDML statement. Static policies enforce the same predicate for access control,regardless of the user, thus ensuring the same policy predicate for all users. Thenew static policies improve performance, since they don’t always reexecute policyfunctions for each DML statement.

STATISTICS_LEVEL The STATISTICS_LEVEL initialization parameterspecifies the level of collection for database and operating system statistics, whichthe database needs for many purposes, including making self-management decisions.The default value is TYPICAL. The other possible values are BASIC and ALL.Oracle recommends that you use the default value of TYPICAL to get the statisticsnecessary for most database management tasks, including using the various advisors.

SWITCH DATABASE SWITCH DATABASE is a new Recovery Manager(RMAN) backup command that enables you to perform a fast restore of yourdatabase. Unlike a normal restore, this command doesn’t copy any database files.Instead, it merely points the datafile pointers in the control file to the backup filelocation and begins recovery.

SYSAUX tablespace SYSAUX is a new, mandatory Oracle Database 10gtablespace. It provides a centralized location for all auxiliary database metadatathat isn’t a part of the SYSTEM tablespace and reduces the number of tablespacescreated by default.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:42 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 616: OCA OCP - Oracle10G New Features For Administrators Exam Guide

UNCATALOG 25

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

table monitoring Table monitoring refers to the tracking of changes to tablesto determine if statistics collection is necessary. In Oracle Database 10g, tablemonitoring is enabled by default. The database will collect optimizer statisticsautomatically by determining which objects have stale statistics or no statistics.

temporary tablespace group A temporary tablespace group lets you usetemporary space from multiple tablespaces. Using a tablespace group helps reducethe contention for temporary tablespace when the database is performing huge sorts.

threshold-based alerts Server-generated alerts can be threshold-based onnonthreshold-based. Threshold-based alerts include alerts for events like CPU timeper service call, for which you might specify warning and critical thresholds. Youcan use the SET_THRESHOLDS procedure of the DBMS_SERVER package to setthresholds for various events.

time model statistics Time model statistics indicate the amount of DB timeassociated with a process from the V$SESS_TIME_MODEL and V$SYS_TIME_MODEL views. Time model statistics help the database keep track of the time spentin performing internal operations such as parse, execute, input/output, and so on.The database uses this information for making self-tuning decisions and to diagnoseperformance problems.

TRANSFORM The TRANSFORM parameter applies to Data Pump import. Itlets you change the DDL statements for an object, by letting you exclude either orboth segment attributes, as well as the storage clauses of objects.

trcsess The trcsess command-line utility consolidates information fromseveral trace files into a single file, to enable meaningful, session-based tracing.

TUNE_MVIEW The TUNE_MVIEW procedure of the DBMS_ADVISOR packageshows you how to optimize your materialized view creation statements. It also suggestsways to ensure a fast refresh and general query rewrite of materialized views.

UNCATALOG You use the UNCATALOG command in the Recovery Manager(RMAN) to remove backup pieces from the recovery catalog, as shown here:

RMAN> change backuppiece 'file_name' UNCATALOG;

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:42 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 617: OCA OCP - Oracle10G New Features For Administrators Exam Guide

26 Glossary

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

Undo Advisor The Undo Advisor is part of the advisory framework. It helpsdatabase administrators in sizing the undo tablespace and in setting the size of theUNDO_RETENTION parameter.

UNDO_RETENTION The UNDO_RETENTION parameter specifies (inseconds) the minimum time for which Oracle retains undo information.

uniform audit trail Oracle tracks a set of identical fields for both standard andfine-grained auditing to enable you to easily analyze database activity. This trackingof identical information is called the uniform audit trail. There is a new audit trailview, DBA_COMMON_AUDIT_TRAIL, which combines standard and fine-grainedaudit records.

Upgrade Information Tool The new Upgrade Information Tool, invoked byrunning the utlu101i.sql script, provides information before a database upgrade byperforming some preliminary checks on the existing database. For example, it checkswhether there is enough space and whether there are any obsolete initializationparameters.

user-specified quoting character Database programmers can now chooseany convenient delimiter and define it as the quoting character, using the new quoteoperators.

UTL_COMPRESS The UTL_COMPRESS package provides a set of datacompression utilities that have the familiar functionality of the zip and unzip (gzipand gunzip) utilities in a PL/SQL environment. This package also handles LOBs andhas features to add and later extract several pieces into a single archive.

UTL_MAIL The UTL_MAIL package is a utility for managing e-mail. It includescommonly used e-mail features, such as attachments, CC, BCC, and return receipt.

VPD See Virtual Private Database.

Virtual Private Database Virtual Private Database (VPD) enables you toenforce fine-grained security by applying security policies directly to tables, views,or synonyms. When a user accesses a table, view, or synonym that is protected witha VPD policy, the database dynamically modifies the user’s SQL statement, usingany condition that can be expressed in or returned by a function. You can applyVPD policies to SELECT, INSERT, UPDATE, INDEX, and DELETE statements.

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:42 PM

Color profile: Generic CMYK printer profileComposite Default screen

Page 618: OCA OCP - Oracle10G New Features For Administrators Exam Guide

window A window is a time duration for which you can specify certain resourceallocations. Like a schedule, it has a start date when the window becomes active oropens and a duration that specifies how long the window will be open, as well as anend date. It may also have a repeat interval that specifies how often the window willopen. You generally associate a resource plan with a window in order to specify howresources should be allocated among the job classes.

window group A window group represents a list of windows and facilitatesmanagement of windows. For example, you can combine the weekend and holidaywindows into a single downtime window group.

window priority Window priorities are relevant when you are dealing withoverlapping windows. If two windows with the same priority overlap, the activewindow stays open. If two windows with different priorities overlap, the higherpriority window will open, and the lower priority window will close.

window priority 27

CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary

P:\010Comp\CertPrs8\862-4\glossary.vpTuesday, September 07, 2004 3:07:42 PM

Color profile: Generic CMYK printer profileComposite Default screen