Beruflich Dokumente
Kultur Dokumente
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
Blind Folio 1:1
1
Installation, Server
Configuration, and
Database Upgrades
CERTIFICATION OBJECTIVES
1.01 Installation New Features Support 1.06 Using New Utility to Perform
Pre-Upgrade Validation Checks
1.02 Performance Enhancements
to the Installation Processs 1.07 Using the Simplified Upgrade Process
1.03 Simplified Instance Configuration 1.08 Starting Up the Database Using
a New Mode When Upgrading
1.04 Viewing Database Feature Usage Statistics
1.05 Supported Upgrade Paths to Oracle
✓ Two-Minute Drill
Database 10g Q&A Self Test
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:43 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
The database server I use in this book is the Oracle Database 10g Enterprise
Edition Release 10.1.0.2.0. I use both a UNIX platform and a Windows platform
for most of the examples in this book. You can probably replicate several examples
in this book using a different version of the Oracle software, but you can get the
Enterprise Edition software free from Oracle, so there isn’t any reason for not using
that version. Practicing using the new features is essential not only for passing the
test, but also for learning the features well enough to implement them in your
databases. 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 companies
talking about their own visions of grid computing. Regardless of what a particular
company 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 less
computing 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 on
changing needs
■ Pooling of resources to maximize availability and utilization
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:43 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
Please refer to the Oracle Database 10g documentation for complete details
on a given feature. This book is intended to provide the information you
need for upgrading your Oracle OCP certification from Oracle9i to Oracle
Database 10g. (The complete name of the test required for upgrading your
certification 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 at
some interesting changes in the installation process.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:43 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
Let’s look at each of these installation new features, starting with enhancements
in database management choices.
■ 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 10g
server software.
The OEM Database Control is a web-based application that you can use to manage
a single Oracle 10g database. The Database Control simply lets you monitor and
manage a single database. You can access the Database Control by using a web
browser; no configuration is necessary to start using the Database Control. Oracle
automatically installs the OEM Database Control in the same Oracle Home as your
Oracle database.
Alternatively, you can install the OEM Grid Control tool, which lets you
monitor and manage several databases and servers at once. In order to use the OEM
Grid Control, you need to configure and start the Oracle Management Agent on
each of the nodes you wish to monitor.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:43 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
If you are managing a single database, the simple stand-alone OEM Database
Control is adequate. On the other hand, if you are in charge of several databases
on several hosts, you’ll need to install and use the OEM Grid Control. The
Grid Control includes the Oracle Management Agent, Oracle Management
Service, the Oracle Management Repository, and the Grid Control console.
It is through the console that you perform all monitoring, configuration, and
management tasks for not only databases, but also for the various hosts
and other services.
In Oracle9i databases, there was only one kind of OEM, and you had the
option of configuring it with or without Management Agents and the Management
Repository. Now, Oracle is making a formal distinction between a local and centrally
managed OEM.
The OEM Database Control runs with the help of a HTTP server, and you use a
regular Internet browser to see the OEM interface. The default URL for the OEM
Database 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 correct
port number for your database by looking at the portlist.ini file, which you
can find in the $ORACLE_HOME/install directory.
In order to run the OEM Database Control, you must first start the database
from which the Database Control is running. Let’s say your database name
is nina. You then need to make sure that the service (on a Windows server)
OracleServiceDBConsoleNina is running, before you try to access the OEM Database
Control interface through your web browser.
When you choose local management using the Database Control, the installer
also gives you the choice of configuring default backup strategies administered by
the Recovery Manager (RMAN). In addition, choosing the Database Control also
enables you to configure the sending of automatic e-mail alerts to warn you about
space 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 HTTP
Server, but as part of the supplemental product CD-ROM.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:43 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
■ Correct operating system version and compatibility level The first thing
that Oracle checks before you start the installation process is whether you
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:43 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
are running the current operating system version. For example, on a HP-UX
system, 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 of
UnitedLinux 1.0, Red Hat 2.1, or Red Hat 3.0 versions before you can
proceed further with the installation. In addition, if you have a 32-bit
operating system, you cannot install the 64-bit version. Oracle will also
ensure that you have set the database compatibility level to 9.2.0 or higher.
■ Operating system patches Oracle automatically checks to make sure you
have installed all the necessary operating system patches.
■ Kernel parameters Oracle checks to make sure that operating system kernel
parameters like SHMMAX and SHMMIN are set appropriately.
■ Sufficient memory and file space Oracle checks the amount of swap space
and the minimum space in the temporary tablespace that are required during
the installation process. Oracle will also ensure that your redo logs are sized
sufficiently.
■ Oracle Home Your Oracle Home must be either empty or belong to a
supported release that permits the installation of Oracle 10g server software.
Only after you pass all the preinstall validations will the OUI proceed with the
installation of the Oracle software.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:43 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
system may already have, like Veritas, for example. This means that you no
longer 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 database
automatically stripes and mirrors your data across the available disks in
the disk groups. You can also add or remove disks while the database is
up and running.
■ Raw Devices You need to think about using raw devices only if you are
considering using Oracle Real Application Clusters. If you use RAC, and a
Clustered File System (CFS) is available on your operating system, Oracle
recommends using either CFS or ASM for your file storage. If a CFS is
unavailable, Oracle recommends that you use raw, or “uncooked,” file
systems or ASM.
■ File Systems Choosing this option will mean that you are using the traditional
operating system files and directories for your database storage. Of course,
you should organize your directories and files according to the well-known
Optimal Flexible Architecture (OFA) guidelines.
If you choose to enable automatic backups, you must also specify the location in
which you want the backups to reside. In addition, you need to provide the
credentials—name and password—for the user who will be performing the backups.
You can enable the automated backups after you’ve finished the server
software installation.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:44 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
will leave the passwords for these four usernames unlocked and unexpired. During
installation, you’ll be asked to furnish passwords for these four accounts, and you can
use the same password for all of them if you wish.
All other preloaded Oracle schemas will have passwords that are expired and
locked when you create any new database. It’s your job to unlock these standard user
accounts and set new passwords for them.
In Oracle9i, you had to change the SYS and SYSTEM passwords twice: once
during the installation of the software and once during database creation. In
Oracle 10g, you need to provide this information only once, during the installation
of the software.
You can invoke the OUI from any node on a cluster that is part of an
installation. You can not only install new software, but also perform
upgrades and apply patches from any node in a cluster
Let’s briefly look at how you can perform these tasks in your enterprise.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:44 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
The OEM maintains a detailed configuration inventory of all the databases and
servers in its domain.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:44 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
MetaLink Integration
Probably every Oracle DBA knows and relies on the OracleMetaLink service to some
extent during the performance of his or her duties. In Oracle 10g, you can directly link
the OEM to the OracleMetaLink service. Through this built-in MetaLink integration,
OEM can then automatically track any new software patches for you. You can arrange
to receive alerts whenever the OEM spots new patches. The OEM can even tell you
which systems need the new patches. Using the OEM OracleMetaLink link, you can
search for appropriate patches and download them, receive critical patch alerts, and
stage and apply patches on your system.
How does Oracle keep track of the exact software version that you are using, if
you are constantly downloading and uploading patches? Whenever you apply a
patch, Oracle immediately updates the OUI’s inventory, so it has the correct record
of your latest patch level. Exercise 1-1 shows how to use the OEM Database Control
to download Oracle software patches.
EXERCISE 1-1
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:44 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
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 with
an existing account. Once logged in, you can search for patches, download
patches, and so on.
The OEM automatically alerts you to any new crtical patches that become
available. In addition, you can use the OEM Patch Wizard to find out what interim
patches are available for your system. You can now study patch details and README
notes directly from your OEM interface. Using the Patch Wizard, you can download
available patches from Metalink into the OEM patch cache, so you can propagate
these patches across your system at your convenience.
Database Cloning
Using the OEM, you can now easily clone databases. OEM performs database cloning
by using RMAN. You use the OEM Clone Database wizard, also known as the Clone
Database Tool, to perform the various steps in a database cloning operation. To create
a duplicate of an existing database, from the home page of the OEM Database Control,
choose Maintenance | Deployments | Clone Database. OEM will back up the source
database’s datafiles as well as archive logs, and automatically restore and recover these
in the target location. The OEM also creates the necessary password files, initialization
files, 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
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:44 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
be up-to-date with the old one until the time the archived logs of the original
databases were backed up by the OEM.
Performance Enhancements
to the Installation Process
Oracle has implemented several changes to make the installation process more streamlined
and faster than in previous versions. You can literally install the entire Oracle 10g
software in less than half an hour, using just one CD. Moreover, during the installation
process, 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 Installation
Although the Oracle Database 10g server software comes in a pack of CD-ROMs, you
need only a single 650MB CD to complete your Oracle 10g server installation. It takes
only about 20 minutes to complete the entire installation. The label on this main
database server software CD is Oracle Database 10g CD. Several older components are
now available on separate CDs. Along with the Oracle Database 10g CD, the following
CDs 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 10g
Companion CD. The Companion CD includes two products: the HTTP Server and
the new HTML DB feature.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:44 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
The Database 10g Products CD includes the Oracle database examples, the Oracle
Workflow Server, and the Legato Single Server Version (LSSV).
The original installation includes only the new OEM Database Control, which
enables you to monitor just the database itself. The OEM Grid Control, which enables
the monitoring of your entire system, is available on the Oracle Enterprise Manager CD.
■ Memory You need 256MB for the basic database, and 512MB if you are
using the stand-alone version of the OEM (the OEM Database Control).
If you need to, you can run both the database and Database Control with
256MB or even less memory, say, for testing purposes. However, the more
memory you have, the easier it is to use the memory-hungry, Java-based
OEM tool.
■ Disk space You need a maximum of about 2.5GB of disk space for the
Oracle software. In addition, you need 1GB of swap space and about 400MB
of disk space in the /tmp directory. The OUI uses a more sophisticated
algorithm to estimate your disk space needs now, so there is less chance of
running out of disk space during the installation process.
■ 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.vp
Thursday, September 02, 2004 12:50:44 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
1. First, shut down all databases and ASM instances running under the Oracle
Home you want to remove, and then remove the databases (remove all
directories with database files).
2. Stop all the relevant processes running under this Oracle Home, by running
the 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.
Don’t remove any Oracle Home directories without first using the OUI
to remove the Oracle software.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:44 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
The following are the new Oracle 10g improvements in the response file, which
help 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 a
character 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 of
installing software.
■ DBCA enhancements
■ Policy-based database configuration framework
■ Simplified initialization parameters
■ Irreversible datafile compatibility
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:44 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
about all the important options, rather than needing to remember them and perform
them all manually.
EXERCISE 1-2
1. Create the instance before you try creating the database. On a Windows
system, first run the command oradim –new –sid my_sid. Make sure
you 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 any
datafiles, 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 in
the 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 the
database. On a Windows system, first run the command oradim –new
–sid my_sid. Make sure you create a simple init.ora file with just one
parameter—the instance name. Next, log in as sysdba and use the command
‘create database my_sid. Now, you can answer the exercise questions.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:45 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
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 the
following files:
■ All datafiles
■ All redo log files
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:45 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
If you want to manually define a flash recovery area, you can do so using the new
flash 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 initialization
parameters. You can find out details about the flash recovery area’s contents by using
the V$FLASH_RECOVERY_FILE_DEST view, as shown here:
SQL> SELECT name, space_limit, space_used,
space_reclaimable, number_of_files
FROM v$recovery_file_dest;
Management Options
As in the case of the starter database described earlier in this chapter, the DBCA gives
you a choice between two kinds of database management: local and central. If you
want 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, you
need to manage several databases and several nodes, use the new Grid Control. The
Grid Control doesn’t come automatically with the database; you need to install this
tool 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 is
complete. You don’t need to perform any configuration to start using the DB
Console (Database Control) to start managing a single database, including alert
notification, job scheduling, and software management.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:45 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 client
browser. For example, to access the OEM Database Control, just open Internet
Explorer 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, and
default_port_number is the port number that Oracle allocated to the Database Control
during 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 (with
the SYSDBA password). This will take you to the home page of the OEM Database
Control utility.
Note that you’ll need Oracle licensing for the following three premium components
of OEM Database Control (technically speaking, you’ll be in violation of your
Oracle 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
Database Diagnostics Pack Tuning Pack Configuration Management Pack
Performance Monitoring (database SQL Access Advisor Database and Host Configuration
and host)
Automated Database Diagnostic SQL Tuning Advisor Deployments
Monitor (ADDM)
Automatic Workload Repository SQL Tuning Sets Patch Database and Patch Staging
Event Notifications: Notification Object Reorganization Clone Database and Clone Oracle Home
Methods, Rules, and Schedules;
Notification Blackouts
Event history/metric history Search and Compare Configuration Policies
(database and host)
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:45 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
are any violations of the predetermined configuration policies. Oracle collects these
configuration metrics for databases, host machines, and listener services.
The OEM Database Control provides an easy way to monitor the adherence of your
system to the predetermined policies. On the Database Control home page, there
is a section called Diagnostic Summary, which shows you if there are any policy
violations anywhere. If you drill down, using the All Policy Violations button, you
can get to the Policy Violations page, which summarizes all policy violations in
your databases and hosts. If you wish, you can disable a policy by going to the
Manage Policy Library page.
Here are a few examples of some typical policy rules:
■ The policy rule “critical patch advisories for Oracle Homes” checks for
missing Oracle patches.
■ The policy rule “insufficient number of control files” checks for the use of
a single control file.
■ The “listener password policy rule” checks for password-protected listeners.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:45 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
EXERCISE 1-3
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:46 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
initialization parameter in your init.ora (or SPFILE) file. Thus, the COMPATIBILE
initialization parameter is now irreversible. This section provides the new details on
the compatibility feature.
The minimum value of the compatibility setting is now 9.2.0. That is, if you set
the COMPATIBLE initialization parameter to 9.2.0., your datafile formats will be
compatible with the Oracle9i Release 2 version. This means that if you wish, you
can always downgrade your new Oracle 10g database to a 9.2.0 version, as long as
you have installed the Oracle9i Release 2 (9.2.0.3) or later executables on your
system along with the Oracle 10g server software. If you set the COMPATIBILE
initialization parameter to 9.2, however, you can take advantage of only a subset of
the new Oracle 10g features. Therefore, use the 9.2 compatibility setting only if you
think 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 the
COMPATIBLE 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. This
means that you won’t be able to downgrade the Oracle 10g database to a prior
release. 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 point
in time that was before you advanced the compatibility level.
To check the current compatibility level of your database, which is set by the value
you chose for the COMPATIBLE initialization parameter, use the following statement.
SQL> SELECT name, value, description FROM v$parameter
WHERE name = 'compatible';
■ How you are using the various features of your Oracle database, including
whether the database is currently using a given feature, as well as the first
and last times it used a given feature.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:46 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
■ The high-water mark (HWM) statistics for important database attributes. The
HWM 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:
Let’s briefly look at how the Oracle database collects these statistics.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:46 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
LAST_USAGE_DATE DATE
AUX_COUNT NUMBER
FEATURE_INFO CLOB
LAST_SAMPLE_DATE DATE
LAST_SAMPLE_PERIOD NUMBER
SAMPLE_INTERVAL NUMBER
DESCRIPTION VARCHAR2(128)
In this section, I have shown how you can query various data dictionary views to
track the database feature usage and HWM statistics. However, there’s an easier way
to monitor these statistics: just use the OEM Database Control to quickly check
the statistics. The next section describes how to use the OEM Database Control to
monitor database usage statistics.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:46 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
features and how the database is using those features. These usage patterns include
the frequency of usage, the first time the database used a certain feature, and the most
recent time the database used a certain feature. Following are the steps to viewing
database usage statistics in the OEM Database Control:
1. Go the Database Control home page. Click the Administration link and
go to the Configuration Management group. Click the Database Usage
Statistics link.
2. You’ll now be in the Database Usage Statistics property sheet. This property
sheet leads to two pages: the High Water Mark page and the Feature Usage
page. The Feature Usage page lists all the available database features by
name. You can also see if the database is currently using a certain feature, as
well as the first usage and last usage timings. To view details about the usage
statistics of any feature, just click the associated link on this page. Figure 1-1
shows 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 in
the Database Usage Statistics property sheet. This will take you to the High
Water Marks page. Here, you can see the HWM attained for each database
object, as well as the last sampled value for each feature and the version of
the database feature. Figure 1-2 shows the High Water Marks page of the
Database Usage Statistics property sheet.
FIGURE 1-1
The Feature
Usage page of
the Database
Usage Statistics
property sheet
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:46 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
FIGURE 1-2
■ 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, or
8.1.6, you can’t directly upgrade to Oracle Database 10g. You’ll need to first
upgrade 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 directly
upgrade to Oracle Database 10g.
You can migrate directly to the Oracle Database 10g version only if your
database is one of the following versions: 8.0.6, 8.1.7, 9.0.1, or 9.2.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:46 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 or
by using the Database Upgrade Assistant (DBUA), a tool that automates the upgrade
process. The DBUA is a refined version of the old Oracle Data Migration Assistant used
in previous versions. Note that you can also use the traditional export and import
utilities 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 the
manual method, is somewhat automatic. As you’ll see in the following sections,
the manual process invokes the startup upgrade command, after which you need
to run the main upgrade script, which performs all the necessary upgrades in the correct
dependency order. Oracle will determine the upgrade order of the various components,
by querying the new DBA_SERVER_REGISTRY data dictionary view. Oracle uses this
view 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 the
main upgrade script finishes running. The DBMS_SERVER_REGISTRY is also the basis
for the new Post-Upgrade Status Tool, which you’ll learn about in a later section.
Traditionally, Oracle DBAs have needed to run a number of scripts during the
database 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 a
single upgrade script provided by Oracle. For example, to migrate from an Oracle
8.1.7.4 version database to the Oracle Database 10g version, you’ll need to run the
u0801070.sql script. You’ll see a detailed example of the execution of this script in
the “Steps in the Manual Upgrade Process” section later in this chapter.
In the following sections, I’ll briefly explain the upgrade process using both the
available methods.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:47 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 entire
upgrade process. Of course, the drawbacks of a manual method are that you must
perform a backup of the database yourself before the upgrade, remove or add all
necessary initialization parameters, and ensure that the SYSTEM tablespace has
adequate free space.
The DBUA is a GUI tool, but you can also run it in the silent mode, by
using the following command at the operating system level: dbua.
To begin with, you need to analyze your existing system to see what changes may
be necessary. Fortunately, Oracle provides an excellent script called the Upgrade
Information Tool, which will ferret out this information for you automatically. We’ll
look at this new tool in the following section.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:47 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
Too often, as you are aware, you might need to restart an upgrade process, owing to
incompatible initialization features or inadequate tablespace sizes.
As you can see, running the Upgrade Information Tool prior to your manual
upgrade process does a lot of the manual work for you! As long as you read the log
file of the Upgrade Information Tool carefully and implement the recommended
changes, you are well set to upgrade to Oracle Database 10g.
Both the manual upgrade process and the DBUA can use the Upgrade
Information Tool. If you are performing a manual upgrade, you need
to invoke the tool by running the SQL script utlu101i.sql. The DBCA
automatically runs it as part of the pre-upgrade check.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:47 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
You can restart a failed database upgrade job from the point where you failed.
■ 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 components
after the upgrade process is completed (such as the appropriate script names
to run)
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:47 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 script
to invoke the Post-Upgrade Status Tool. This script is the utlu101s.sql script, located
in the $ORACLE_HOME/rdbms/admin directory on your server.
if you use the DBUA to upgrade, the utlu101s.script runs automatically. If you
are performing a manual upgrade, you need to run the script yourself, after
the upgrade process is finished.
Both the manual upgrade and the DBUA upgrade process perform the same set
of steps: performing pre-upgrade checks to ensure that the database meets all the
requirements, running the Oracle-supplied upgrade script, and so on. However, the
DBUA 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 the
database upgrading business. If you are a veteran Oracle DBA, going through
the manual process may be the best way to go, in my opinion.
Note that some of the material regarding the database upgrade process in the
following sections may be more detailed than what’s necessary to merely pass the
certification exam. However, the review would come in handy when you are
upgrading your databases to Oracle Database 10g.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:47 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
As you have seen, the upgrade process isn’t really a horrendous process, even
when you do it using the manual method. With the DBUA, upgrading becomes
even easier. As you know by now, the DBUA incorporates all three steps of the
upgrade 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 Startup
You can start the DBUA by selecting Programs | Oracle | Configuration and Migration
Tools | Database Upgrade Assistant. Figure 1-3 shows the Welcome screen of the
DBUA. If you are on a UNIX system, simply type dbua (after logging in as the Oracle
user) 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 simply
doing a silent upgrade using the DBUA. This means you won’t be prompted for
anything—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 command
for the silent invocation of the DBUA (assuming your database name is nina):
$ dbua -silent –dbName nina
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:47 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
FIGURE 1-3
The Welcome
Screen of the
Database
Upgrade
Assistant
This command is all you need to migrate your current database to Oracle Database 10g.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:47 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
■ Choose the option to recompile invalid objects. The next screen gives you
the option of automatically recompiling any invalid database objects after the
database upgrade is completed. Let Oracle recompile objects that are invalid.
Letting Oracle recompile all invalid objects at the end of the upgrade is
equivalent 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 cold
backup of your database, if you haven’t already done so. If you (as any sane
DBA would) have already done your backups, choose the I Have Already
Backed Up My Database option.
■ Choose the OEM configuration. The next screen is the Management
Options screen, which provides options to configure the OEM, as well as
backups. You can choose either the Grid Control or Database Control
version of the OEM to manage your upgraded database. As noted previously
in this chapter, the Database Control component comes with your database
installation software, and Oracle automatically installs it when you install
Oracle Database 10g, but you must install the Grid Control from separate
software. Grid Control assumes that you have already created a Management
Service on one of the servers in your grid. If you haven’t already installed
the Grid Control software, it may be best to choose the Database Control
at this early stage in the game.
■ Define the Flash Recovery Area. The DBUA then asks you to choose a
flash recovery area, which, as described earlier in this chapter, is used as
the default area for your backup and recovery-related operations.
■ Choose database passwords. In the Database Credentials screen, the DBUA
asks you to choose passwords for users like SYSMAN and DBSNMP, which
are 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 database
versions. 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 upgrade
time. Click Finish to start the upgrade process. Figure 1-4 shows the upgrade
progress screen of the DBUA.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
FIGURE 1-4
The DBUA
upgrade progress
screen
■ Accept upgrade results or restore from backup. Finally, after the upgrade
is completed, the DBUA shows you the results in the Upgrade Results
screen, as shown in Figure 1-5. You can do three tasks using the Upgrade
Results screen:
■ Check the upgrade details.
■ Manage passwords in the database.
■ If you wish, restore the pre-upgrade database.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
FIGURE 1-5
The DBUA
Upgrade Results
Screen
What if you chose not to restore the database to the pre-upgrade status, and later
found that you had made a terrible mistake in turning down the kind offer of the
DBUA 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 by
Oracle when you choose to back up the database during the beginning part of the
upgrade process. Here’s how I ran the script on my Windows machine to undo an
Oracle Database 10g upgrade (Note that finance is the name of my recently upgraded
database.)
SQL> @C:\oracle\product\10.1.0\admin\finance\backup\FINANCE_restore.bat
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
To review the results of this pre-upgrade check, turn spooling off using the
following command:
SQL> spool off
Here’s the partial output from a test I ran on my Windows server. Note that I am
upgrading an Oracle 8.17 database to the Oracle Database 10g version.
*************************************************************************
Database:
–> name: FINANCE
–> version: 8.1.7.0.0
–> compatibility: 8.1.0
WARNING: 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 MB
Please create the new SYSAUX Tablespace AFTER the Oracle Database
10.1 server is started and BEFORE you invoke the upgrade script.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
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 query
demonstrates this:
SQL> select * from v$version;
BANNER
––––––––––––––––––––––––––––––––
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 – Prod
PL/SQL Release 10.1.0.2.0 – Production
CORE 10.1.0.2.0 Production
TNS for 32-bit Windows: Version 10.1.0.2.0 – Production
NLSRTL Version 10.1.0.2.0 – Production
SQL>
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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
The u0801070.sql upgrade script calls several other scripts to manage the upgrade
process. 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, packages
call c0801070.sql:
This performs all necessary dictionary upgrades to bring the db from 8.1.7 to
the 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 loaded
into the database. The script uses procedures from the DBMS_REGISTRY package
to execute various component upgrades.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
Just to make sure that there aren’t any more invalid objects left, run the following
query again:
SQL> select count(*) from dba_objects
2 where status = 'INVALID';
COUNT(*)
–––––
0
1 row selected.
SQL>
Besides validating all remaining invalidated database objects, the utlrp.sql script
also checks for the validity of each individual component in the database. As you
have seen earlier in this chapter, the DBA_SERVER_REGISTRY view will contain
information 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.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
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 using
either of the two methods mentioned here requires that you enabled the
DBUA to perform a backup of your database (with the RMAN). If you chose
not to have the DBUA perform a pre-upgrade backup, you can still revert to
your old pre-Oracle 10g version database by simply restoring from your own
backups. The key here is to ensure that you have a backup, either made by
you or created by the DBCA, before you start the upgrade process.
Where does the Upgrade Status Tool get its information about the various
components? The tool simply queries the DBA_SERVER_REGISTRY table to
determine the upgrade status of each individual component. You can get the same
output as that produced by the utlu101s.sql script, by running the following query:
SQL> select comp_id, comp_name, version, status
from dba_server_registry;
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:49 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
Based on the outcome of your database upgrade, the Upgrade Status Tool will
tell you one of the following: all the database components have been successfully
upgraded (Normal Successful Completion), or some of the components haven’t been
cleanly upgraded. If a component hasn’t been cleanly upgraded, the Upgrade Status
Tool will tell you the corrective action to take to fix the problem, as shown in the
following example.
SQL> @C:\oracle\product\10.1.0\Db_1\rdbms\admin\utlu101s.sql TEXT
PL/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) detected
WARNING: ––> 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 completion
PL/SQL procedure successfully completed.
SQL>
Don’t try to start your newly upgraded database under your old Oracle Home
for any reason—this will corrupt your database.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:49 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
The exam contains questions about tracking You must understand the COMPATIBLE
Oracle Database 10g feature usage. Pay initialization parameter accurately for the test.
particular attention to tracking feature usage The exam tests your knowledge of the DBCA
through OEM as well as the DBA_FEATURE_ tool in creating a new database. Please look at
USAGE_STATISTICS view. Something else the various DBCA screens carefully. What
that the test might focus on are the high-water management options does the DBCA enable
mark statistics for various database objects. you to configure?
Which database objects does Oracle collect The exam will include a question or
high-water mark statistics for? two about the upgrade process. You must
The test expects you to know the new understand how to use the Pre-Upgrade
Oracle Policy Framework. How do you Information Tool and the Post_Upgrade
prioritize policy violations along various Status Tool. What scripts start these tools?
categories? The test may include a question You must also understand the role of the
about the new Database Cloning Tool DBA_SERVER_REGISTRY during a
(OEM Database Cloning wizard). What are database upgrade. How do you recompile
the various features of the source and target invalid objects?
databases during a cloning operation?
CERTIFICATION SUMMARY
This chapter provided you with a summary of Oracle 10g’s innovations in the software
installation and database upgrade areas. First, you looked at the support of new installation
features in Oracle 10g. These included the changes to the Oracle Enterprise Manager
(OEM) tool. You learned the difference between local and central installation of the
OEM. Other installation new features include the file storage options and backup and
recovery options. You also learned about the changes in the response file installation,
as well as the new irreversibility factor relating to the COMPATIBLE initialization
parameter.
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 provides
you both pre-installation and post-installation support tools to ensure easy software
installation. Next, you learned about the new easier and cleaner Oracle software
deinstallation process.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:49 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
The Database Creation Assistant (DBCA) has many changes, and this chapter
reviewed all of them. These include the mandatory creation of the SYSAUX
tablespace, the creation of the flash recovery area, and the Automatic Storage
Management (ASM) storage option. Management options include a choice between
the OEM Database Control and the OEM Grid Control. You also saw how the OEM
can now be used to link with OracleMetaLink service, perform database cloning, and
enforce 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 feature
both manually as well as through the OEM Database Control.
In the database upgrade section, you first reviewed the supported upgrade paths
to the new Oracle Database 10g version. I then took you step-by-step through both
a manual and a DBUA database upgrade. You learned about the Oracle pre-upgrade
checks and the post-upgrade validation as well.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:49 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
✓ 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-installation
checks 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 management
using the OEM Grid Control. With the Database Control, you can manage
only a single database. With the Grid Control, you can manage several nodes
at 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 file
systems, Automatic Storage Management (ASM), and raw devices.
❑ You need to specify database user (SYS and SYSTEM, for example) passwords
during database creation time.
❑ You can invoke the OUI from any node on a cluster that is part of an
installation.
❑ The Oracle 10g installer supports the installation of Cluster Ready Services
(CRS).
❑ You can use the OEM Grid Control to perform enterprise-wide configuration
changes.
❑ 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
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:49 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
Two-Minute Drill 49
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:49 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:50 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
Two-Minute Drill 51
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:50 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:50 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
Self Test 53
SELF TEST
The following questions will help you measure your understanding of the material presented in this
chapter. Read all the choices carefully because there might be more than one correct answer. Choose
all correct answers for each question.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:50 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
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 does
Oracle launch for you?
A. OEM Management Agent
B. OEM Database Control
C. OEM Grid Control
D. OEM Management Agent and OEM Database Control
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:50 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
Self Test 55
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:50 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:50 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
Lab Questions 57
upgrade details. You suddenly realize that you made a mistake, and you would like to revert to
the 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.
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?
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:50 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
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 no
OEM-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.
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:50 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:51 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:51 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:51 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 will
perform the restore for you. D is incorrect because you can restore to 8.1.7 either through
the DBA or through a manual restore, if necessary.
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:
P:\010Comp\CertPrs8\862-4\ch01.vp
Thursday, September 02, 2004 12:50:51 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
Lab Answers 63
Lab 3
To manually create a SYSAUX tablespace with a size of 1GB:
SQL> CREATE TABLESPACE sysaux DATAFILE 'sysaux01.dbf'
SIZE 1000M REUSE
EXTENT MANAGEMENT LOCAL
SEGMENT SPACE MANAGEMENT AUTO
ONLINE;
Lab 4
The 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 the
following 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 you
log in as the SYS user or some other user with SYSDBA privileges.
Lab 5
You must use RMAN to perform backups. You can use the Clone Database wizard (also referred to
as the Clone Database Tool) to create a clone of an existing database. Following is a brief summary
of the cloning process:
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.vp
Thursday, September 02, 2004 12:50:51 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
Blind Folio 2:1
2
Loading and
Unloading Data
CERTIFICATION OBJECTIVES
2.01 Introduction to the Data Pump 2.05 Defining Your External Table Properties
Architecture
2.06 Transporting Tablespaces Across
2.02 Using Data Pump Export and Import Different Platforms
2.03 Monitoring a Data Pump Job ✓ Two-Minute Drill
2.04 Creating External Tables for Q&A Self Test
Data Population
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
A lmost every Oracle DBA is familiar with the traditional Oracle data-loading utilities:
export and import. In Oracle Database10g, you now have a newer and more
refined 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 Oracle
Database 10g, but Oracle would prefer you to use the Data Pump technology, because it offers
you more sophisticated features than the old export/import technology.
While the Data Pump export and import utilities look quite similar to the traditional
export and import utilities, the new technology is vastly superior in many ways. For
example, you can now interrupt export/import jobs in the middle, and then resume
them. You can even restart failed export and import jobs. You can also remap object
attributes to modify the objects. You can easily monitor your Data Pump jobs from a
different session, and you can even modify job attributes on the fly, during the course
of a job. It is easy now to move massive amounts of data quickly, using parallelization
techniques. Because Oracle provides you the Application Programming Interfaces
(APIs) for the Data Pump technology, you can now easily incorporate export/import
jobs within PL/SQL programs.
The Data Pump export and import jobs need more startup time than the
old export and import utilities. Therefore, you may still want to use the old
export 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 in
Oracle9i. In Oracle Database 10g, you can now write to external tables, instead of being
merely be able to read from them.
Let’s start this very important chapter with a brief introduction to the new Data
Pump technology.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
The new Data Pump technology lets you export data only to disk. You cannot
use a tape drive when performing a Data Pump export.
Oracle Data Pump technology consists of two components: the Data Pump export
utility, to unload data objects from a database, and the Data Pump import utility, to
load data objects into a database. You access the two Data Pump utilities through a
pair of clients called expdp and impdp. As their names indicate, the first of these
corresponds to the traditional export utility and the latter to the import utility. You
can 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)
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 traditional
export and import utilities. In this mode, you enter your choices in response to various
prompts. 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 an
interactive operation. Unlike in the old export and import utilities, Data Pump
utilities have a set of parameters you can use at the command line and a set of special
commands 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 following
sections. You can also get a quick summary of all Data Pump parameters and commands
by 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 known
as dump files. It writes to these files in a proprietary format, which only the Data Pump
import utility can understand while loading the data in the dump files into the same
or another Oracle database. You can take Data Pump export dump files from an
operating system and import them into a database running on a different type of
platform, as is the case with the older export/import utilities.
The original export and Data Pump dump files aren’t compatible. You can’t
read export dump files with Data Pump and vice versa. The new features of
Oracle Database 10g aren’t supported in the original export utility, which
you’ll still have access to in Oracle Database 10g.
In addition to expdp and impdp, you can have other clients perform Data Pump
export 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. Through
this package, you can programmatically access the Data Pump export and import
utilities. This means that you can create powerful custom data-movement utilities
using the Data Pump technology.
The traditional export utility is a normal user process that writes data to its local
disks. The old export utility fetches this data from a server process as part of a regular
session. By contrast, the Data Pump expdp user process launches a server-side process
that writes data to disks on the server node, and this process runs independently of
the session established by the expdp client.
The Data Pump technology is remarkably different from the traditional export
and import utilities. In the following sections, you’ll learn about those differences
as we cover the following topics:
■ Benefits of Data Pump technology
■ Data Pump components
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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
■ Ability to restart data pump jobs You can now easily restart jobs that either
have stalled due to lack of space or have failed for various reasons. You may
also voluntarily stop and restart jobs.
■ Parallel execution capabilities By simply specifying a value for the
PARALLEL parameter, you can now choose the number of active execution
servers for each export job.
■ Ability to attach to running jobs You now have the amazing capability to
attach to a running Data Pump job from a different screen or location. This
enables 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, it
doesn’t need a client to run once it starts a job.
■ Network mode of operation Once you create database links between two
databases, you can perform exports from a remote database straight to a dump
file set. You can also perform direct imports via the network using database
links, without using any dump files. The network mode is a means of transferring
data from one database directly into another database via SQLNET with the
help of database links, without needing to stage it on disk at all.
■ Fine-grained data import capability Oracle9i offered only one parameter
that gave you the ability to perform data loads at a fine-grained level. This
parameter was QUERY, which enabled you to specify that the export utility
extract only a specified portion of a table’s rows. Now with Data Pump, you
have access to a vastly improved fine-grained options arsenal, thanks to new
parameters like INCLUDE and EXCLUDE.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
■ Remapping capabilities During a data pump import, you now have the
ability to remap schemas and tablespaces, as well as filenames, by using the
new REMAP_ * parameters. Remapping capabilities enable you to modify
objects during the process of importing data, by changing old attributes to
new values. For example, the REMAP_SCHEMA parameter enables you to
map all of user HR’s schema to a new user, OE. The REMAP_SCHEMA
parameter is similar to the TOUSER parameter in the old import utility.
■ Ability to estimate space requirements In a Data Pump job, you can now
estimate the space requirements of a job by using either the ESTIMATE or
the ESTIMATE_ONLY parameter.
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 and
import utilities. In traditional export/import, Oracle uses normal SQL to take the
data in the export dump files and inserts it sequentially into the database tables
during the import process. In the Data Pump technology, the DBMS_DATA PUMP
package 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_METADATA
package, which has been available since the Oracle9i version. In traditional export
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
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 extract
the 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 programs
to load and unload data, without accessing the expdp and impdp clients.
Data-Access Methods
A 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 and
imports lead to improved performance, since the direct path internal stream
format is the same format as the data stored in Oracle dump files. This leads
to a reduced need for data conversions.
■ External tables The external tables feature lets Oracle read data from and
write data to operating system files that lie outside the database.
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. Under
some 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 use
of direct-path access, so Data Pump will use external tables. On the other hand, if
your table has any LONG data, you must use the direct-path access.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
The datafile format is can easily export data with one method
identical in external tables and the and import it with the other method,
direct-access method. Therefore, you if you wish.
■ Dump files These hold the data for the Data Pump job.
■ Log files These are the standard files for logging the results of Data Pump
operations.
■ SQL files Data Pump import uses a special parameter called SQLFILE,
which will write all the Data Definition Language (DDL) statements it will
execute during the import job to a file. Data Pump doesn’t actually execute
the SQL, but merely writes the DDL statements to the file specified by the
SQLFILE parameter. You use SQL files only to hold the output of the SQLFILE
command 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 and
import utilities. The following sections explain how to use directory objects.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:42 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
the /u01/app/oracle/admin/export directory on the server. You can then access the
export directory by simply using the dpump_dir1 directory object name. Here’s how
you create a directory object:
To create a directory, a user must have the DBA role or have the CREATE ANY
DIRECTORY privilege.
In order for a user to use a specific directory, the user must have access privileges
to the directory object. For example, in order to grant user SALAPATI privileges on
the new directory dpump_dir1, you need to grant the following privileges:
You’ll need the write privilege on all files for Data Pump export. During an
import, you’ll need read access to the export dump file. You’ll also need write
privileges 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 export
and import jobs can use the DIRECTORY parameter to specify the name of the
directory object (DIRECTORY=dpump_dir1). This way, the DIRECTORY
parameter will indirectly point to the actual operating system directories and files.
Here’s an example:
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:42 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
Using the DIRECTORY Parameter Earlier in this section, you learned how to
create a directory object. During a Data Pump export job, you can specify the directory
object 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 directory
object without using the DIRECTORY parameter. You can do this by specifying the
directory object’s name as part of the value for a specific Data Pump file (the dump
file, log file, or SQL file). You may then use the specific directory object for a log file
in the following manner:
$ expdp LOGFILE=dpump_dir2:salapati.log …
Note that the colon (:) separates the directory and filenames in the log file
specification. In this example, dpump_dir2 is the name of the directory object.
The Data Pump filename is salapati.log.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:42 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 system
environment, you don’t need to specify the actual directory name (dump_dir2)
explicitly (by using the DIRECTORY parameter) when you invoke a Data Pump
export, as shown in the previous example. You merely need to specify the name, not
the location, for the DUMPFILE parameter.
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, the
directory object is separated from the filename by a colon (:).
2. Oracle’s second choice would be to use the directory objects assigned to the
DIRECTORY parameter during the export or import job. If you explicitly
specify the DIRECTORY parameter, you don’t need to use the directory
name as part of the file parameter.
3. Finally, Oracle looks to see if there is a default server-based directory object
named DATA_PUMP_DIR. You must have explicitly created this directory
object beforehand. Note that the default DATA_DUMP_DIR object is
available only to DBAs and other privileged users.
The directory object name resolution simply means that Oracle knows which
directory it should be using to read or write datafiles. However, you must have
already granted the database read/write privileges at the operating system level,
in order to enable the database to actually use the operating system files.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:42 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
The master process uses a special table called the master table to log the location
of the various database objects in the export dump file. The master table is at the
heart of every Data Pump export and import job. The master process maintains the
job state and restart information in the master table. Oracle creates the master table
in the schema of the user who is running the Data Pump job at the beginning of every
export job. The master table contains various types of information pertaining to the
current job, such as the state of the objects in the export/import job, the location
of the objects in the dump file set, the parameters of the job, and the status of all
worker 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. At
the very end of the export, as the last step in the export job, it writes the contents
of the master table to the export dump file and automatically deletes the master
table 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 for
some reason, the master table isn’t deleted from the database. (Data Pump job
commands are described in the “Data Pump Export Parameters” section later in
this chapter.) When you restart the export job, it will then use the same master
table. Since the master table tracks the status of all the objects, Data Pump can
easily tell which objects are in the middle of an export and which have been
successfully exported to the dump files.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:42 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
The master process will re-create the master table saved by the export utility in the
dump file, in the schema of the user who is performing the import. This is the first step
in any Data Pump import job. (Note that you don’t need to create any tables, because
the import utility will automatically do this for you.) The Data Pump import utility
reads the contents of the master
table to verify the correct
sequence in which it should
import the various exported
database objects. As in the case The master table contains
of Data Pump export, if the all the necessary information to restart
import job finishes successfully, a stopped job. It is thus the key to Data
Oracle will automatically Pump’s job restart capability, whether the
delete the master table. job stoppage is planned or unplanned.
Shadow Process
When a client logs in to an Oracle server, the database creates an Oracle foreground
process to service Data Pump API requests. This shadow process creates the job consisting
of the master table as well as the master process. Once a client detaches, the shadow
process automatically disappears.
Client Processes
The client processes call the Data Pump’s API. You perform export and import with the
two clients, expdp and impdp. Later in this chapter, you’ll learn about the various
parameters you can specify when you invoke these clients.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:42 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
As you can see, the command-line option would quickly get tiring if you were
doing anything but the simplest type of exports.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:43 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
For example, you could create a small file called myfile.txt, with the following
export parameters:
userid=system/manager
directory=dpump_dir1
dumpfile=system1.dmp
The file myfile.txt will be your export parameter file. Now, all you need to do in
order to export the system schema is invoke expdp with just the PARFILE
parameter, as follows:
$ expdp parfile=myfile.txt
You can use all command- parameter file. The only exception is
line export parameters in an export the parameter PARFILE itself!
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:43 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
In Data Pump, the import) prompt. You can enter the special
interactive mode means that the export interactive commands at this point. Note
or import job stops logging its progress that the export or import job keeps running
on the screen and displays the export (or throughout, without any interruption.
You can also perform Data Pump export and import operations easily through
the OEM Database Control interface. To use this feature, start the Database Control
and go to the Maintenance | Utilities page. On that page, you can see the various
choices 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.
■ Full export mode You use the FULL parameter when you want to export
the 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 export
all the tables in one or more tablespaces. If you use the TRANSPORT_
TABLESPACES parameter, you can export just the metadata of the objects
contained in one or more tablespaces. You may recall that you can export
tablespaces between databases by first exporting the metadata, copying the
files of the tablespace to the target server, and then importing the metadata
into 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 previous
versions of Oracle.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:43 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
You can use all the following parameters at the command line or in parameter
files, except those listed in the “Interactive Mode Export Parameters” section.
DUMPFILE The DUMPFILE parameter provides the name of the dump file to
which the export dump should be written. The DUMPFILE parameter replaces the
FILE parameter in the old export utility. You can provide multiple dump filenames
in 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 single
export job.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:43 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
If you specify the %U notation to indicate multiple dump files, the number
of 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 name
expdat.dmp for the export dump file, just as it does when you use the traditional
export utility.
FILESIZE The FILESIZE parameter is purely optional, and it specifies the size
of the dump file. If you don’t specify this parameter, the dump file has no limits on
its size. If you use the FILESIZE parameter by specifying, say 10MB as the maximum
dump file size, your export will stop if your dump file reaches its size limit, and you
can restart it after correcting the problem.
PARFILE The PARFILE parameter stands for the same thing it did in
traditional export utility: the parameter file, wherein you can specify export
parameters in a file, instead of entering them directly from the command line.
LOGFILE and NOLOGFILE You can use the LOGFLE parameter to specify
a log file for your export jobs. Here’s what you need to remember regarding this
parameter:
If you just specify the parameter without the directory parameter, Oracle will
automatically create the log file in the location you specified for the DIRECTORY
parameter.
■ If you don’t specify this parameter, Oracle will create a log file named
export.log. A subsequent export job will overwrite this file, because Oracle
always 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, but
Oracle suppresses the writing of a separate log file for the job.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:43 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
CONTENT By using the CONTENT parameter, you can filter what goes into the
export 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:
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:44 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
Simply put, the EXCLUDE parameter helps you omit specific database object types
from 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 the
EXCLUDE 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 a
SQL function to filter named objects.
Here’s a simple example that excludes all tables that start with EMP:
EXCLUDE=TABLE:"LIKE 'EMP%'"
You can also use the EXCLUDE parameter to exclude an entire schema, as shown
in the following example.
EXCLUDE=SCHEMA:"='HR'"
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:44 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
The first example is telling the Data Pump job to only include two tables: employees
and departments. In the second example, the INCLUDE parameter specifies that
only procedures should be
included in this export job.
The third example shows
how you can specify that
The EXCLUDE and
only those indexes that
INCLUDE parameters are mutually
start with EMP should be
exclusive. You can use one or the other,
part of the export job.
not both simultaneuously in the same job.
QUERY The QUERY parameter stands for the same thing as it does in traditional
export: 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 to
qualify the SQL statement with a table name, so that it applies only to a particular
table. 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 than
100000 are exported.
Estimation Parameters
Two interesting parameters enable you to estimate how much physical space your
export job will consume. Let’s look at both these parameters in detail.
ESTIMATE The ESTIMATE parameter will tell you how much space your new
export job is going to consume. The space estimate is always in terms of bytes. By
default, Oracle will always estimate the space requirements in terms of blocks. It
simply takes your database block size and multiplies it with the amount of blocks all
the 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_DATA
Total estimation using BLOCKS method: 654 KB
Since the space estimation in terms of blocks is the default behavior, you don’t
need to specify the ESTIMATE parameter during the export. However, if you have
analyzed all your tables recently, you can ask the Data Pump export utility to
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:44 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
estimate the space requirements by using the statistics the database has already
calculated for each of the tables. In order to tell the database to use the database
statistics (rather than use the default BLOCKS method), you need to specify the
ESTIMATE parameter in the following manner:
ESTIMATE=statistics
Here’s what you’ll see in your log file when you use the ESTIMATE=statistics
parameter:
Estimate in progress using STATISTICS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. estimated "SYSTEM"."HELP" 35.32 KB
Total estimation using STATISTICS method: 65.72 KB
Although the log indicates that the export job “completed successfully,” all the
job really did was to estimate the space that you will need for the export job.
In the example, the NETWORK_LINK parameter must have a valid database link as its
value. This means that you must have created the database link ahead of time. You are
exporting data from the finance database on the prod1 server.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:44 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / 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-only
database. This is because Data Pump can’t create the necessary master table
or 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 dump
files on server B, where Data Pump is running.
■ You can use the CONTROL-C keyboard combination during a Data Pump
export job, if you want to enter the interactive mode from the same session
where 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 yourself
to 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 start
another session, and then “connect” to the running job and monitor it by simply
using the ATTACH command. When you do this, the running job does not pause.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:44 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
Instead, it opens an interactive window into the running session, so you can change
some parameters to hasten the crawling export job by running one of a special set
of interactive Data Pump export commands. Here’s an example of the usage of the
ATTACH parameter:
C:\>expdp salapati/sammyy1 attach=SALAPATI.SYS_EXPORT_SCHEMA_01
Export: Release 10.1.0.2.0 - Production on Saturday, 17 April, 2004 11:47
…
State: EXECUTING
…
Export>
Once you attach yourself to a running job by using the ATTACH command or
by 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 is
awaiting your interactive commands. From the interactive prompt, you can use
several interesting parameters to influence the progress of the currently executing
Data Pump job. Here are some examples of interactive commands:
Export> parallel=4
Export> kill_job
Export> stop_job
Export> continue_client
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:45 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
You can restart any job or due to a system crash, as long as you
that is stopped, whether it’s stopped have access to the master table and an
because you issued a STOP_JOB command uncorrupted dump file set.
Other Interactive Parameters From the interactive prompt, you can use
the ADD_FILE parameter to add a dump file to your job. You can also use the HELP
and STATUS parameters interactively, and both of these parameters function the
same way as their command-line counterparts.
Job-Related Parameters
Several 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 job
name 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, Data
Pump 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
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:45 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 the
Data Pump job. EXPORT tells you it’s an export, not an import job. FULL indicates
that this is full database export. The last part of the job name is a number, indicating
the sequence number of the job. This was my first job in a new database, so my job
number happens to end with 01.
Remember that Oracle gives the master table, which holds critical information
about 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 it
provides you with an updated status at intervals that you can specify. The parameter
takes 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 export
job. Here’s what you need to do to get your reassuring minutely updates:
$ expdp system/manager status=60 …
…
Worker 1 Status:
State: EXECUTING
Object Schema: SYSTEM
Object Name: SYS_EXPORT_SCHEMA_01
Object Type: SCHEMA_EXPORT/TABLE/TABLE_DATA
Completed Objects: 1
Total Objects: 65
. . exported "SYSTEM"."REPCAT$_SITES_NEW"
Job: SYS_EXPORT_SCHEMA_01
Operation: EXPORT
Mode: SCHEMA
State: EXECUTING
Bytes Processed: 69,312
Percent Done: 99
Current Parallelism: 1
Job Error Count: 0
Dump File: C:\ORACLE\PRODUCT\10.1.0\ADMIN\EXPORT\EXPDAT6.DMP
bytes written: 1,748,992
…
The STATUS parameter shows the overall percentage of the job that is
completed, the status of the worker processes, and the status of the current
data objects being processed.
PARALLEL PARALLEL is the mighty parameter that lets you specify more
than a single active execution thread for your export job. Note that the Data Pump
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:45 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 specify
anything more than 1 as the value for the PARALLEL parameter, you also should
remember to specify the same number of dump files, so the multiple execution threads
can simultaneously write to the multiple dump files. Here’s an example that shows
how you can set the level of parallelism to 3, forcing the export job to write in
parallel 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 same
number of dump files as the degree of parallelism. The higher the degree
of parallelism, the higher will be the memory, CPU, and network bandwith
usage as well.
In the previous example, the DUMPFILE parameter uses the substittion varable %u
to 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 parameter
is 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 multiple
dump 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 3
DUMPFILE=(par_exp01.dmp,par_exp02.dmp,par_exp03.dmp)
If you don’t have sufficient I/O bandwidth, you may actually experience a
degradation in Data Pump performance with the PARALLEL parameter.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:45 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 to
use the CONTENT and EXCLUDE parameters. The CONTENT=DATA_ONLY
specification means you are exporting just rows of data and excluding all object
definitions (metadata). The EXCLUDE parameter requries that the countries,
locations, and regions tables be omitted from the export. The QUERY parameter
stipulates that all the data in the employees table, except that belonging to
location_id 20, be exported. The parameter file, exp.par, has the following
information:
DIRECTORY=dpump_dir1
DUMPFILE=dataonly.dmp
CONTENT=DATA_ONLY
EXCLUDE=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 any
mention 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.dmp
LOGFILE=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 the
PARALLEL, FILESIZE, and JOB_NAME parameters. It also illustrates the use
of the DUMPFILE parameter when there are multiple dump files.
$ expdp hr/hr FULL=y DUMPFILE=dpump_dir1:full1%U.dmp, dpump_dir2:full2%U.dmp
FILESIZE=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 to
look at the Data Pump import features.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:46 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:46 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
extract the DDL from the export dump file. The SQLFILE parameter enables
you to do this easily, as shown in the following example.
$ impdp salapati/sammyy1 DIRECTORY=dpump_dir1 DUMPFILE=finance.dmp
SQLFILE=dpump_dir2:finance.sql
In this example, the SQLFILE parameter instructs the Data Pump import job to write
the DDL to the finance.sql file, located in the directory dpump_dir2. Of course, you
must have created dpump_dir2 prior to this, using the CREATE DIRECTORY AS
command. The DIRECTORY=dpump_dir1 parameter value tells Data Pump import
where to find the dump file finance.dmp. This example also shows how you can use
multiple directories in a single Data Pump job.
It’s important to remember that the SQLFILE parameter just extracts the SQL
DDL to the specified file—no actual data import whatsoever takes place. By using
this parameter, you can extract a SQL script with all the DDL from your export
dump 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_DATAFILES
parameter. This parameter tells Data Pump whether it should use existing datafiles
for creating tablespaces during an import. If you specify REUSE_DATAFILES=y,
the import utility will write over your existing datafiles.
Filtering Parameters
You use the CONTENT parameter, as in the case of a Data Pump export, to determine
whether 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, you
cannot use either the EXCLUDE or INCLUDE parameter during an import.
You can use the QUERY parameter during import as well, in order to filter data
during an import. In the older export/import utilities, you could use the QUERY
parameter only during an export. You can use the QUERY parameter to specify an
entire schema or a single table. Note that if you use the QUERY parameter during
import, Data Pump will use only the external table data method, rather than the
direct-path method, to access the data.
What will Data Pump import do if there is a table creation script in the export
dump file, but the table already exists in the target database? You can use the
TABLE_EXISTS_ACTION parameter to tell Data Pump what to do when a table
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:46 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
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 the
export dump file.
■ The REPLACE value drops the table if it exists, re-creates, and reloads it.
Job-Related Parameters
The JOB_NAME, STATUS, and PARALLEL parameters carry identical meanings
as 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 in
the Data Pump import section.
Remapping Parameters
The remapping parameters are brand-new features in the Oracle Database 10g Data
Pump import utility, and they clearly mark the superiority of this utility over the
traditional import utility. Let’s briefly discuss each of these three parameters: REMAP_
SCHEMA, REMAP_DATAFILE, and REMAP_TABLESPACE.
In this example, HR is the source schema, and Data Pump import will import all of
user HR’s objects into the target schema OE. The import utility can even create the
OE schema, if it doesn’t already exist in the target database. Of course, if you want to
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:46 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
just import one or more tables from the HR schema and import them into the OE
schema, you can do that as well, by using the TABLES parameter.
In this example, finance@prod1 is the network link. It is a valid database link, created
by you beforehand using the CREATE DATABASE LINK command. Thus, the database
shown in the database link is your source for the import job. Data Pump will import
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:47 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
the table employees from the remote database finance to your instance where you
run the Data Pump import job. In a network import, the Metadata API executes on
the remote instance, and extracts object definitions and re-creates necessary objects
in your local instance. It then fetches data from the remote database tables and loads
them in your local instance, using the INSERT AS SELECT command, as follows:
insert into employees(emp_name,emp_id) … select (emp_name,emp_id) from
finance@remote_service_name
Note that a Data Pump network import doesn’t involve a dump file, as Data Pump
will import the table from the source to the target database directly.
EXERCISE 2-1
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:47 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
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 old
CONSISTENT parameter in the traditional import utility.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:47 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
Since the dynamic DBA_DATA PUMP_JOBS view shows only the active jobs, you
can easily find the JOB_NAME value for any job that is running right now. As you
know, you’ll need to know the job name for a job if you want to attach to a running
job in midstream.
Because the name of the master table is the same as the JOB_NAME value, you
can thus determine the name of the master table through this view.
The JOB_MODE column can take the values FULL, TABLE, SCHEMA, or
TABLESPACE, 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 execute
your query. The Data Pump job enters the NOT RUNNING state immediately before
it 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.vp
Monday, August 30, 2004 2:09:47 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
Here’s a typical SQL script that you can run to show how much longer it will take
for your Data Pump job to finish:
SQL> select sid, serial#, sofar, totalwork
from v$session_longops
where opname = 'MY_EXPORTJOB1'
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 outside
the database.
External tables aren’t a new feature of Oracle Database 10g. Oracle9i first introduced
the concept of external tables. However, in Oracle9i, you could only read from
external 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 following
sections:
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 select
between two types of external tables: the ORACLE_LOADER type and the
ORACLE_DATAPUMP type. Each of these external tables comes with its own
access driver. In Oracle9i, you used the ORACLE_LOADER access driver to create
external tables; however, the ORACLE_LOADER access driver can load data only
into an external table; that is, it can extract data from external flat files to load an
Oracle (external) table. The ORACLE_LOADER access driver is the default access
driver in Oracle Database 10g.
The ORACLE_DATAPUMP access driver is new to Oracle Database 10g. The
ORACLE_DATA PUMP access driver can load as
well extract data; that is, it can both load an
external table from a flat file and extract data
If you want to create from a regular database table to an external flat
indexes on a staging table, you are better file. This external flat file data is written in a
off using the SQL*Loader utility to load proprietary format, which only the ORACLE_
data into the table. You cannot index an DATA PUMP access driver can read. You can then
external table! use this newly created file to create an external
table 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 drivers
to perform data loads. You can use only the new ORACLE_DATA PUMP
access 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.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
There are several important components of this CREATE TABLE statement that
you need to be aware of:
■ Loading data means reading data from an external table and loading it into
a regular Oracle table. Oracle first reads the data stream from the files you
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
specify. Oracle will then convert the data from its external representation to
an Oracle internal datatype and pass it along to the external table interface.
■ Unloading data means reading data from a regular Oracle table and putting it
into 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 an
external table population (unloading data). Why is the new functionality (unloading
data into external tables) important? Following are some of the benefits of this new
Oracle Database 10g feature:
■ Loading table data into flat files means that you can now store data or move
it to different databases easily. If you want to move large volumes of data
across platforms, external tables provide a means of doing so, since the
external files are platform-independent.
■ During the population of data warehouses, there are many situations where
you need to perform complex ETL jobs. You can use SQL transformations to
manipulate the data in the external tables before reloading them into the
same or other databases.
■ Once you create an external table and populate it using the CTAS
statement, you can move the text files containing data and create new
external tables in the same or a different database.
Note that when you talk about to writing to external tables, you are really referring
to writing to an external file. You use a SELECT statement to extract table data to
this operating sytem file. The ORACLE_DATA PUMP access driver writes data to this
file in a binary Oracle-internal Data Pump format. You can then use this file to load
another external table on a different database.
The following example shows how you can create an external table and populate it
with data from an external flat file. The only difference between this example and the
preceding external table creation statement is that it uses the ORACLE_DATAPUMP
access driver rather than the ORACLE_LOADER driver.
SQL> CREATE TABLE inventories_xt2
2 (
3 product_id NUMBER(6),
4 warehouse_id NUMBER(3),
5 quantity_on_hand NUMBER(8)
6 )
7 ORGANIZATION EXTERNAL
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
8 (
9 TYPE ORACLE_DATA PUMP
10 DEFAULT DIRECTORY def_dir1
11 LOCATION ('inv_xt.dmp')
12 );
Table created.
SQL>
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 the
DEPT table. You can then use this dump file in the same database or a different
database 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 are
creating the external table dept_xt as an external table. The table structure and
data both come from the regular Oracle DEPT table. The CTAS method of table
creation will load the data from the DEPT table into the new external table dept_xt.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:48 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 answer
something like “in a table segment”! Since the dept_xt table is defined as an external
table, the CTAS command simply stores the table data in the external file called
dept_xt_dmp. Thus, the external table is really composed of proprietary format,
operating system-independent flat files.
When you use the external metadata using external tables. If you wish
tables feature to extract table data to a file, to extract the metadata for any object, just
you export only the data. You can’t export use DBMS_METADATA, as shown here:
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:49 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
The default value for the PROPERTY column for all external tables is ALL. This
tells the access driver to always process all the columns of an external table, not just
some. This means that, regardless of which columns you select in a query, the access
driver will process all column values. The access driver will validate only those columns
without data errors. The access driver will also eliminate any rows that have erroneous
column values, even if those columns aren’t a part of the SELECT query.
If the PROPERTY column shows the value REFERENCED, this means that only
those 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.vp
Monday, August 30, 2004 2:09:49 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 fields
and expect no data rejections due to data format errors. For example, you may have
a column called emp_id, which you define as a number(5) column. When Oracle
encounters a row in the datafile where the emp_id has six digits, it would normally
reject this row, since the default value for the property is ALL. This means that even
if you issue a query that selects a different column, say social_security_num from the
employee 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 to
REFERENCED? Say that you want to change this property for your external table
dept_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_xt
2 project column referenced;
Table altered.
SQL> select table_name,property from dba_external_tables;
TABLE_NAME PROPERTY
------------------------------ ----------
DEPT_XT REFERENCED
SQL>
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:49 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
course, to perform the job. However, there is a much faster way to perform the data
transfer: use transportable tablespaces. Transportable tablespaces simply involve moving
tablespaces from one database to another. All you really need to do is to copy the
datafiles (containing tables, indexes, and other Oracle database objects) that comprise
the tablespace, from the target to the source server (if the two databases reside on
different servers) and just import the metadata of the objects in the tablespace to the
target database.
Transportable tablespaces are ideal for moving large amounts of data quickly
between two databases. The transportable tablespaces feature, of course, has been
available for a while now, but both the source and target databases needed belong
to the same operating system platform. In Oracle Database 10g, for the first time,
you can transport tablespaces between different platforms. Now the onerous requirement
of identical operating system platforms is gone, and you can easily transport a
tablespace from pretty much any platform to any other. This is a great feature, as
it enables you to take tablespaces from a data warehouse and plug them into data
marts, even though your data warehouse runs on an UNIX platform and the data
marts are located on smaller Windows servers. As you have probably already figured
out, the key here is Oracle Database 10g’s ability to convert one set of datafiles from
one operating system format to another, so the target database can read the source
database files.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:49 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
Following are the general requriements for transporting tablespaces between two
databases:
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:49 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
4
HP-UX IA (64-bit) Big
11
Linux IA (64-bit) Little
15
HP Open VMS Little
8
Microsoft Windows IA (64-bit) Little
9
IBM zSeries Based Linux Big
13
Linux 64-bit for AMD Little
16
Apple Mac OS Big
12
Microsoft Windows 64-bit for A Little
MD
15 rows selected.
SQL>
The V$TRANSPORTABLE_
PLATFORM view shows all
platforms supported for
transporting tablespaces. The In order to transport
PLATFORM_NAME column tablespaces across different platforms,
shows all the platforms that are the character sets in both databases
eligible for transporting across should be identical.
platforms. If both your source
and target platforms are in this list, you can conduct the transportable tablespaces
operation between the databases running on those platforms.
You can find out your own platform name, in case you aren’t sure, by running the
following 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 headers
can 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, you
need to first advance the compatibility level to 10.0.0 before you can transport any
tablespaces for this database.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:49 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
Endian format refers to byte ordering in the datafiles of a given platform. Byte
ordering affects the way data is written and read in different platforms. There are
only two types of endian formats: little or big. In order for the datafiles between
two compatible platforms to be transported directly from one another, their endian
format (also known as endianness) should be the same. Both the source and target
platforms should have an identical endian format—either both are in the big format
or 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 belonging
to the tablespaces that you are exporting, using the RMAN utility.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:49 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:50 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
In this example, I show how you can use the FORMAT parameter to tell Oracle
what format the newly converted file should be and in which directory to put it. But
as you can see, Oracle gives the file a name. If you want to specify the datafile name
youself, perform the conversion using the DB_FILE_NAME_CONVERT clause, as
follows. (Remember that you use the following command when you convert the files
directly on the source system, before transporting them.)
RMAN> convert tablespace today
2> to platform 'HP-UX (64-bit)'
3> db_file_name_convert = 'c:\oracle\test02.dbf','c:\temp\test02.dbf';
Starting backup at 10-MAY-04
using target database controlfile instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=151 devtype=DISK
channel ORA_DISK_1: starting datafile conversion
input datafile fno=00011 name=C:\ORACLE\TEST02.DBF
converted datafile=C:\TEMP\TEST02.DBF
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:16
Finished backup at 10-MAY-04
RMAN>
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:50 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 system
platform and convert it into a Windows platform:
RMAN> convert datafile
2> '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 source
sytem, you may use the DB_FILE_NAME_CONVERT clause when performing the
data file conversion on the target system. Your datafile conversion statement would
then 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.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:50 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
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 stored
in the UCS2 format, which is endian-dependent, but Oracle Database 10g stores
them as AL16UTF16, which is endian-independent. However, big-endian UCS2
is the same as AL16UTF16. So if your source system was big-endian, there isn’t any
difference. If it wasn’t, Oracle will convert the datafiles on demand.
The exam will test your knowledge of the new Path API. You can expect some questions
Data Pump import and export parameters. You on the DBMS_DATAPUMP and the DBMS_
must understand the new parameters like the METADATA packages. You must understand
remapping parameters of Data Pump import. the importance of the master table.
What are the different levels at which you can There will be questions on the external
perform transformations during an import? Pay table population feature. You must remember
particular attention to the new parameters like the syntax for performing an external table
ESTIMATE, ESTIMATE_ONLY, NETWORK_ population (CREATE TABLE AS SELECT).
LINK, INCLUDE, and EXCLUDE. You must Review the parallel feature, putting special
know the levels at which you can perform emphasis on the relationship between the degree
Data Pump import and export. of parallelism and the number of dump files.
You can expect questions on the interactive The test will contain questions on the new
import and export commands. How do you features related to transportable tablespaces.
attach to a running job? What happens to a What is an endian format, and what role does
job and a client session when you stop a job? it play in transporting tablespaces across
Review the Data Pump dictionary views like platforms? You must remember the RMAN
DBA_DATAPUMP_JOB_STATISTICS and commands to convert the endian formats of
DBA_DATAPUMP_JOBS. files. What is the difference in the file
There will be a question on the Data Pump conversion commands when you convert files
architecture. You must know the difference on the target platform and when you convert
between the External Table API and Direct them on the source platform?
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:50 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
CERTIFICATION SUMMARY
This 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 import
jobs faster, while offering exceptional data-filtering techniques. You also learned about
the powerful interactive Data Pump features. You learned how to monitor your Data
Pump jobs.
You learned how to populate external tables. You also saw how the new options
you have in Oracle Database10g regarding external table properties. You learned
how to transport tablespaces across server platforms, even when the file semantics
are different between two operating sytem platforms.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:50 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
Two-Minute Drill 55
✓ 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 in
Oracle 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 Data
Pump import utility imports data into a database.
❑ There are two kinds of parameters: a set of command-line parameters and a
special set of interactive commands in both the Data Pump import and
export utilities.
❑ The Oracle-supplied package DBMS_DATA PUMP is used to implement the
Data Pump API.
❑ The clients for the Data Pump export and import utilities are expdp and
impdp, respectively.
❑ DBMS_METADATA, an older Oracle-provided package, is used to extract and
modify data dictionary metadata.
❑ Data Pump export can access data in two ways: direct-path access using the
Direct Path API or through external tables. Data Pump itself makes the
decision 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 some
conditions, Oracle cannot use the direct-path method, and it must use the
external tables access method.
❑ You can export data using either direct path or external tables and import the
data 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 system
directory.
❑ Once you create a directory, you can access that file system by simply
referring to the dirctory name.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:51 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 a
directory, you must have the appropriate read and/or write privileges on the
directory.
❑ DATA_PUMP_DIR is the default directory object for Data Pump jobs. Only
privileged users can use this default directory object.
❑ The order of precedence for file locations is the following: the directory name
as part of a file parameter name, the value assigned to the DIRECTORY
parameter, the directory name specified by DATA_PUMP_DIR environemnt
variable, and finally, the default value for the DATA_PUMP_DIR object.
❑ All Data Pump jobs consist of a master and several worker processes. The
master process controls jobs and the worker processes as well. The master
process 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 completes
successfully, the master table is automatically deleted from the database.
❑ During Data Pump import, the master table is consulted to verify the correct
sequencing of objects during import.
❑ If you choose the PARALLEL option, the worker processes become parallel
execution 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 to
estimate space requirements, fine-grained export and import capabilities, and
remapping capabilities.
❑ You can perform both network mode exports and imports.
❑ You can perform Data Pump export/import from the command line or with
the help of parameter files.
❑ In Data Pump export/import, you use the interactive mode to intervene
during a running job. There are several special commands you can use in
this 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.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:51 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
Two-Minute Drill 57
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:51 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:51 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
Two-Minute Drill 59
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:51 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
SELF TEST
The following questions will help you measure your understanding of the material presented in
this chapter. Read all the choices carefully because there might be more than one correct answer.
Choose all correct answers for each question.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:51 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
Self Test 61
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:52 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
10. Which is the sequence of commands you must use if you want to suspend and then resume your
Data 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 file
B. Username and password, job name
C. Username and password onl
D. 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 job
B. What percentage of the job has been completed thus far
C. What percentage of the job remains to be done
D. The estimated number of megabytes left to be transferred
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:52 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
Self Test 63
15. Why should you use the NETWORK_LINK export parameter when you perform a Data Pump
export 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 export
D. 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 that
you 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.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:52 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 same
results.
B. Using the REFERENCED value for the PROJECT COLUMN attribute always provides the
same results.
C. Using the default value for the PROJECT COLUMN attribute always provides the same
results.
D. Using the ALL value for the PROJECT COLUMN attribute always provides different
results.
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.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:52 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
Lab Question 65
23. To find out if two databases are cross-transportable compliant, which data dictionary view do
you 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 system
platforms in the V$TRANSPORTABLE_TABLESPACES view?
A. Automatically transport tablespaces between the two platforms
B. Transport tablespaces only after you perform a mandatory file conversion first
C. Transport tablespaces between the two platforms only if their endian format is different
D. Transport tablespaces between the two platforms, provided you always perform a file
conversion first if the file endian formats are different
LAB QUESTION
Start a Data Pump export job as the user SYSTEM. Export the entire database. Show the commands
you 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.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:52 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:52 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 is
incorrect 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 already
running. 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 in
interactively. D is wrong since the Data Pump job must be running for you to log in interactively.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:52 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 the
form of external tables.
ý A and D are clearly wrong since unloading of data involves writing of data, not reading
of 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-only
database, 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_LINK
parameter. C is incorrect because you do need to create an export dump file, no matter what
parameters you specify. D is wrong because you can export a read-only database using the
traditional export utility.
16. þ B and C. B is correct because Oracle will set the degree of parallelism to the number of
files. 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 files
is different from the degree of parallelism. B is incorrect since Oracle doesn’t adjust the degree
of parallelism to match the number of datafiles. D is wrong since the parallel execution server
will not write to multiple files simultaneously.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:53 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 selected
columns 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 you
choose the ALL value for the PROPERTY column. C is incorrect since ALL forces the parsing
and conversion of all columns; it isn’t better than using the REFERENCED value for the
PROPERTY column. D is incorrect since REFERENCED means that Oracle doesn’t parse
and convert all columns.
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.vp
Monday, August 30, 2004 2:09:53 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 2
To stop the running job, you issue the following command at the expdp prompt (if you want
an immediate rather than an orderly stoppage of the export job, you can use the command
STOP_JOB=IMMEDIATE):
expdp> STOP_JOB
■ The name of the master table is always the same as the job name. In this case, it is
SYS_EXPORT_SCHEMA.
■ Once you attach to the running export session, you can issue various comamnds at the
operating system prompt. To make your export session perform an export to four dump
files 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 attaching
to 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.
P:\010Comp\CertPrs8\862-4\ch02.vp
Monday, August 30, 2004 2:09:53 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
Blind Folio 3:1
3
Automatic
Database
Management
CERTIFICATION OBJECTIVES
3.01 Use Automatic Database Diagnostic 3.03 Use Automatic Optimizer Statistics
Monitor Collection
3.02 Use Automatic Shared Memory 3.04 Use Automatic Undo Retention Tuning
Management
✓ Two-Minute Drill
Q&A Self Test
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:08 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
Y ou have probably heard a lot of talk about Oracle Database 10g being a self-managing
database. Far from being hype, Oracle Database 10g offers you a dazzling array of
self-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 causing
a performance problem. Accurate and quick diagnosis of performance issues is critical to the
success of any Oracle database professional. Oracle DBAs routinely undertake tuning exercises
that involve running SQL scripts, poring over extended trace results, using the EXPLAIN PLAN
statement, using the TKPROF utility, and/or employing other tuning aids.
For the first time, Oracle Database 10g helps you automatically diagnose performance
problems. Diagnosing and fixing performance problems may be as simple as going
to 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 already
occurred. Do you recall how often the OracleMetaLink service asks you to see if you
can “reproduce” a performance problem? In Oracle Database 10g, the database collects
and saves all the statistical data you need for a performance diagnosis in the Automatic
Workload Repository (AWR).
A new diagnosis tool, the Automatic Database Diagnostic Monitor (ADDM) analyzes
this data regularly, to provide you with detailed information about the root cause of
performance problems, as well as recommendations for how to fix the problem. The
ADDM relies on years of Oracle Corporation’s performance methods, thus making
it a sort of an expert system or a self-diagnostic engine that is built right into Oracle
Database 10g. Since the performance statistics collection mechanism relies on the
Oracle System Global Area (SGA), it is very accurate and efficient. The ADDM
uses a new statistics collection method, where statistics are read directly from the
SGA structures by a new background process called the Manageability Monitor
process (MMON). Hence, there is none of the performance overhead of a session
populating a V$ view.
Previous versions of Oracle provided you with ways to manage the critical SGA
on a dynamic basis. The ability to dynamically modify SGA component sizes means
that you don’t need to restart an instance after you make the changes. Now, Oracle
has gone a step further and provides you with the option of using Automatic Shared
Memory Management. With automatic SGA management, you can realize the twin
tasks of conserving memory while improving database performance by automatically
provisioning SGA memory based on database workload, not tedious guesswork.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:08 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
Practicing Oracle DBAs know how critical it is to collect timely database statistics
so the Oracle optimizer performs efficiently. In Oracle Database 10g, there is a new
feature, the automatic optimizer statistics collection, in which Oracle itself automatically
schedules the statistics collection, using the new database Scheduler feature. DBAs
have 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 Oracle
Database 10g, there are enhancements to this feature, including the interesting new
option of guaranteed undo retention. Using this new undo feature, you can virtually
rule out any ORA-1555 (snapshot too old) errors.
In this chapter, our focus is on the exciting automatic management features
introduced in the Oracle Database 10g Server. Let’s start our discussion of Oracle
Database 10g’s automatic management features with a description of the ADDM
feature.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:08 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:08 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
connected to the database and you’re idle for 28 of those minutes, then DB time is
only 2 minutes.
If a problem is contributing to inappropriate or excessive DB time, the ADDM
automatically flags it as an issue that needs your attention. If there is a problem
in your system, but it doesn’t contribute significantly to the DB time variable, the
ADDM will simply ignore the problem. Thus, the entire functioning of the ADDM
revolves around the single mantra: reduce DB time. By relentlessly focusing on the
reduction of database time (DB time), the ADDM’s aim is to increase the throughput
of your database, thus serving more users with the same amount of resources.
■ 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 STATSPACK
utility to gather performance-related data. For one thing, STATSPACK has too
much information, not all of which is critically important to fixing critical performance
problems that are occurring right now. The ADDM uses a sophisticated, new time
statistics model in Oracle Database 10g, which is highly effective in determining
where time is spent in the database. This new time statistics model enables Oracle to
focus on only the most critical performance problem areas. DB time is the key metric
against which the ADDM judges all performance problems. If a problem exceeds the
threshold for DB time, the ADDM tags it as a top performance issue; otherwise, it
leaves it alone as nonproblem area.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:08 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:08 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
■ Hardware changes ADDM may recommend that you add more CPUs to
your system. It may also recommend that you change the way you configure
your I/O subsystem.
■ Database and application changes The ADDM may find, for example, that
your database is performing an excessive amount of parses due to the failure
to use bind variables. In a case like this, it may recommend that you change
your initialization parameter CURSOR_SHARING to a setting of FORCE,
rather than rewrite your application code. In some other cases, the ADDM
may recommend that you go ahead and rewrite the application code so you
use bind variables.
■ Space configuration changes The ADDM may sometimes make
recommendations like switching to the new Automatic Storage Management
(ASM) to fix certain performance problems.
■ Using management advisors The ADDM may recommend several changes
that you can implement immediately to improve database performance.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:08 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:08 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
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 several
important types of performance statistics.
You can control the amount of statistics collected by the AWR by adjusting either
or both of two variables:
You can modify the length of the snapshot interval and snapshot retention by using
the INTERVAL and the RETENTION parameters of the MODIFY_SNAPSHOT_
SETTINGS of the DBMS_WORKLOAD_REPOSITORY package. Chapter 4 provides
examples showing you how to manage AWR historical data retention by modifying
the INTERVAL and RETENTION parameters.
The ADDM runs automatically after each AWR snapshot. If you don’t like the
default (60-minute) interval, you can change it.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:09 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
4* AND parameter_name='DBIO_EXPECTED';
PARAMETER_VALUE
----------------
10000
SQL>
What do you do if you think your I/O subsystem is fast, and performs a database
block 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 to
Manage the ADDM” section.
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 choosing
ADDM. Once you reach the ADDM page, you can view the latest performance findings
or start a new ADDM task.
Oracle runs the ADDM choose. You may want to run the ADDM
automatically every hour, following the manually either because an alert recommends
AWR snapshot collection. You may, that you do so or because you want an
however, run it manually whenever you ADDM analysis across multiple snapshots.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:09 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
You can also obtain complete ADDM reports by running the Oracle-provided
SQL script addmrpt.sql, which you’ll find in your ORACLE_HOME/rdbms/admin
directory. As explained earlier, the AWR will take snapshots of database performance
at specified intervals. Assuming the default of one-hour intervals, you’ll have as
many snapshots in the AWR as the number of hours since you started the database
instance.
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 a
snapshot captured at 9:57 A.M., but I brought down the database after that. You can
compare two snapshots only if you don’t shut down the database in between. Why
is this so? The AWR holds only cumulative database statistics. Obviously, once you
shut 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 between
10:00 A.M. and 1:00 P.M. To do so, I need to specify the snapshot numbers pertaining
to the 10:00 A.M. and 1:00 P.M. snapshot collection times. The addmrpt.sql script
provides this information. In the script, notice that the snapshot IDs 258 (captured
at 10:00 A.M.) and 261 (captured at 1:00 P.M.) will contain the performance statistics
for the period between 10:00 AM and 1:00 PM. Therefore, I provide the snapshot IDs
258 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.sql
DB 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> without
specifying a number lists all completed snapshots.
Listing the last 3 days of Completed Snapshots
Snap
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
nina NINA 257 21 Apr 2004 09:27 1
258 21 Apr 2004 10:00 1
259 21 Apr 2004 11:00 1
260 21 Apr 2004 12:00 1
261 21 Apr 2004 13:00 1
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 258
Begin Snapshot Id specified: 258
Enter value for end_snap: 261
End Snapshot Id specified: 261
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:09 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
For space reasons, I am not showing the entire ADDM report. The textual report
that the addmprt.sql generates is identical to the detailed report that you can get
using the OEM Database Control’s ADDM page. You’ll see this report later in this
chapter, in the section “Viewing Detailed ADDM Reports.”
The ADDM doesn’t always offer you a direct recommendation for a performance
problem that it encounters. A key aspect of an ADDM analysis is that. In many
cases, it recommends that you use one of Oracle’s built-in advisors, like the
SQL Tuning Advisor, to analyze a complex performance situation.
By navigating to the Performance Details page of the ADDM using the OEM
Database Control, you can see all the problems and the recommendations for fixing
them. For each problem in the report, ADDM displays each of its performance findings
in the form of three columns: the Impact column, the Finding column, and the
Recommendations column.
The Impact column lists the performance problems in the order of their impact on
their system. The Impact column is thus very important, because you can start working
on fixing the most serious problem that is affecting current database performance. You
may think parsing issues are more serious than, say I/O-related issues, but if the Impact
column ranks I/O problems as number one, you should attend to the I/O problems first.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:09 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
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 simply
setting the STATISTICS_LEVEL parameter to BASIC. However, remember
that this step will also disable many automatic performance tuning and statistics
gathering activities of Oracle Database 10g.
Let’s look at a typical ADDM problem analysis and list of recommendations. This
analysis is from the OEM Database Control’s ADDM page.
Problem Recommendation
The buffer cache was Increase SGA target by increasing the value of parameter SGA_TARGET
undersized causing significant by 256M.
additional read I/O.
The throughput of the I/O Consider increasing the throughput of the I/O subsystem. Oracle’s recommended
subsystem was significantly solution is to stripe all datafiles using the same methodology. You might also
lower than expected. need to increase the number of disks for better performance. Alternatively,
consider using Oracle’s ASM solution.
Hard parsing of SQL Here, the ADDM did not make any recommendations. By clicking the
statements was consuming Additional Information button, I found that ADDM didn’t see any reason
significant database time. to tinker with the parsing issue, for the following reasons:
Hard parses due to cursor environment mismatch were not consuming
significant database time.
Hard parsing SQL statements that encountered parse errors was not consuming
significant database time.
Parse errors due to inadequately sized shared pool were not consuming
significant database time.
Hard parsing due to cursors getting aged out of shared pool was not consuming
significant database time.
Hard parses due to literal usage and cursor invalidation were not consuming
significant database time.
Database writers (DBWR) Consider increasing the number of database writers (DBWR) by setting the
were unable to keep up with parameter DB_WRITER_PROCESSES.
the demand for free buffers.
Time spent on the CPU by Tune the PL/SQL block with SQL_ID “2b064ybzkwf1y.” Refer to the
the instance was responsible “Tuning PL/SQL Applications Chapter of Oracle’s “PL/SQL User’s Guide
for a substantial part of and Reference.”
database time.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:09 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:09 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
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 the
ADDM, but also to all the other database advisors.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:09 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
The possible values for the TYPE parameter are TEXT, XML, and HTML. The
possible values for the LEVEL parameter, which stands for the initialization
parameter STATISTICS_LEVEL, are TYPICAL, ALL, and BASIC. Remember
that setting the STATISTICS_LEVEL parameter to BASIC will mean that you
can’t use the ADDM tool.
Here’s an example that shows how to use the GET_TASK_REPORT procedure to
obtain 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 use
of SQL scripts):
SQL> select DBMS_ADVISOR.GET_TASK_REPORT('ADDM:877021568_1_252')
2 from dba_advisor_tasks
3 where task_id = (select max(t.task_id)
4 from dba_advisor_tasks t,
5 dba_advisor_log l
6 where t.task_id = l.task_id AND
7 t.advisor_name='ADDM' AND
8* 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/1
The analysis of I/O performance is based on the default assumption that the
average 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. How
then, 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.vp
Thursday, September 02, 2004 4:49:09 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
Remember that there are (by running the addmrpt.sql script), or the
three ways to retrieve an ADDM analysis DBMS_ADVISOR package (by running
report: you can use the OEM Database the GET_TASK_REPORT procedure).
Control interface, the SQL*Plus interface
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:10 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
In Oracle Database 10g, for the first time, you can make the often-tricky issue of
shared memory management completely automatic. This is one of the more significant
enhancements of Oracle Database 10g, and it contributes significantly to Oracle’s
goal of automatic database self-management. Oracle will automatically allocate and
deallocate 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 allocate
memory among the SGA components. Automatic Shared Memory Management
provides you the following benefits:
Before we delve into the new Automatic Shared Memory Management feature of
Oracle Database 10g, let’s quickly review the manual memory management feature,
which is still available for you to use.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:10 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
the actual size of all the SGA components. If you set the SGA_MAX_SIZE to a
value smaller than the sum of all the SGA components, Oracle will automatically
bump up the SGA_MAX_SIZE parameter’s value to the sum of the memory assigned
to all the components.
The new Oracle Database 10g background process MMAN performs all the memory
resizing necessary for the Automatic Shared Memory Management feature. The MMAN
process constantly monitors the workload of the database and adjusts the size of the
individual memory components accordingly.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:10 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
Note that in addition to the automatic and manual components, Oracle also assigns
a certain amount of memory to the fixed SGA, which contains database and instance
state information useful to the background processes. The fixed SGA doesn’t contain
any user data.
It is important to understand that the SGA_TARGET parameter shows the sum
of all SGA components, not just the automatically managed memory components.
Interestingly, even under Automatic Shared Memory Management, the manually
sized components get the first crack at the SGA allocated by the SGA_TARGET
parameter. Oracle will first subtract the total value of all the manually sized memory
components from SGA_TARGET, and then allocate the remainder of the memory
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:10 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:10 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
(900 – 400) of SGA left for the other three auto-tuned parameters (of course, if you
assign any memory for the manually tuned parameters, you’ll be left with even less
than 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 assign
for the auto-tuned parameters.
■ Oracle cannot change the values of the manually sized components.
Once you start the instance with a certain value for SGA_TARGET, you can
increase 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_SIZE
parameter sets an upper bound on the value of the SGA_TARGET parameter. If
you haven’t specified an SGA_MAX_SIZE value, you can increase the value of the
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:10 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
Oracle recommends that you do not manually set any of the (four)
automatically sized components, since it reduces the database’s ability
to adapt to database workload changes.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:10 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 can
lower the SGA_TARGET value, but the DB_CACHE_SIZE value cannot go below
128M, since that is the minimum value for this parameter. That is, you can reduce
the SGA_TARGET value until one or more of the auto-tuned SGA components
reach their minimum size.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:10 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
As you can see, Oracle assigns initial values for all four auto-tuned parameters
using the SGA_TARGET value of 125M. You can also see that all manually sized
components have a value of zero (since no allocations have been made for these
components 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 the
various 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 these
parameters, 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 Automatic
Shared Memory Management.
■ You can increase the size of the SGA_TARGET parameter until you reach
the SGA_MAX_SIZE parameter’s value.
■ If you increase the size of SGA_TARGET, you can allocate the additional
memory only among the auto-tuned parameters.
■ If you decrease the size of SGA_TARGET, Oracle will reduce the size of one
or more of the auto-tuned parameters. Oracle will not change the size of the
manually tuned SGA components.
■ You can reduce the SGA_TARGET parameter’s size until you reach the minimum
size 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 are
higher than any manually set minimums, the current values, not the minimum
values set in the initialization files, will prevail.
■ If you assign a minimum value for the auto-tuned components, that will act
as the lower bound for the SGA_TARGET parameter.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:10 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:11 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
Use the SPFILE (rather than the init.ora file) if you want Oracle to remember
the sizes of the automatically tuned memory components across an instance
shutdown.
Figure 3-1 shows the Database Control page for modifying the SGA management
options.
FIGURE 3-1 Using the Database Control for specifying SGA management options
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:11 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
Oracle recommends that you let the database collect optimizer statistics
automatically.
The optimizer relies on details about various objects to figure out the best plan
of execution, which usually is the execution plan with the least cost (I/O and CPU
cost mostly). The statistics that the Oracle optimizer relies on are called optimizer
statistics, 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’s
use. Since tables and indexes may change constantly in terms their data and other
properties, it is essential that you regularly refresh the optimizer statistics so they do
not become stale, and thus misleading.
Prior to Oracle8i, DBAs relied on the analyze table statements to gather
statistics for the Oracle optimizer. In Oracle8i, you had access to the new DBMS_STATS
package, which made the job of collecting statistics easier and more comprehensive.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:11 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
You used the DBMS_STATS package to collect the latest statistics for cost-based
optimization. Even with the availability of the DBMS_STATS package, it was still
your responsibility, as a DBA, to schedule the statistics collection jobs.
As you are aware, the Oracle optimizer cannot function correctly if you don’t feed
it correct and up-to-date statistics. Poor statistics mean nonoptimal execution plans,
leading to degradation in query performance. In Oracle Database 10g, for the first
time, you can automate the optimizer statistics collection process by allowing Oracle
to collect the statistics for you.
Before we go into the details of how automatic statistics collection works, remember
that statistics collection is just one part of query optimization. The choices you make
regarding the optimizer mode and any optimizer hints that you may use have a
significant bearing on the query optimizer’s
behavior. Thus, you need to focus on three
things—the optimizer mode, optimizer hints,
If you set the initialization and the collection of optimizer statistics—in
parameter STATISTICS_LEVEL to BASIC, order to set up efficient query optimization.
you disable the monitoring feature, and Let’s first quickly review the concepts of optimizer
thus turn off the automatic collection of mode and optimizer hints, before going on to
optimizer statistics. discuss how Oracle automatically collects the
optimizer statistics for you.
■ ALL_ROWS This is the default value. Using the ALL_ROWS goal will
ensure the best throughput, which means it will minimize resource use.
When you use the ALL_ROWS setting, Oracle uses a cost-based strategy
for 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 that
will return the full result set quickly.
■ FIRST_ROWS_n This value will ensure the minimization of response time
for returning the first n rows in the query output. Oracle uses a cost-based
approach regardless of the presence of optimizer statistics.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:11 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
FIRST_ROWS_n will get something back quickly, although it may take longer
to retrieve the full set of data. Therefore, the FIRST_ROWS setting will favor
the use of indexes.
The OPTIMIZER_MODE settings determine the way the query optimizer will
perform optimization throughout the database. However, at times, due to lack of
accurate statistics, the optimizer can be mistaken in its estimates, leading to poor
execution plans. In cases like this, you can override this database optimization
setting at the individual SQL statement level, by using optimizer hints. Oracle
Database 10g also provides the new SQL profile feature, which enables you to collect
auxiliary information using sampling and partial execution techniques, thereby avoiding
the 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 a
discussion of the last factor that determines how a query optimizer works—optimizer
statistics collection.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:11 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
■ 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 and
12:00 A.M. Monday.
Together, the weeknight and the weekend windows are known as the maintenance
window. Of course, you can change the default timings of the maintenance window
as necessary. Oracle automatically schedules the GATHER_STATS_JOB job to run
when the maintenance window opens. Even if the job doesn’t complete before the
maintenance window is over, the job will run to completion.
If you want to stop the automatic gathering of statistics, you may do so by disabling
GATHER_STATS_JOB, as shown here:
SQL> begin
2 dbms_scheduler.disable('gather_stats_job');
3 end;
4 /
PL/SQL procedure successfully completed.
SQL>
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:12 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
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 the
weekend window timings.
Figure 3-2 shows the Scheduler Windows page of the Database Control, where
you can modify your operating windows for the Scheduler utility.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:12 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
FIGURE 3-2 The Scheduler Windows page of the OEM Database Control
Table Monitoring
Oracle Database 10g uses an automatic table-monitoring mechanism (enabled by
default when STATISTICS_LEVEL is set to TYPICAL or ALL) to determine
whether a database object needs fresh statistics. Suppose that there are no changes
in any table data in your database over a certain period. In this case, all the previously
collected table statistics are still up-to-date, and you don’t need to collect statistics
again 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 said
to 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 table
monitoring on and off at the database and schema level, respectively, because these
subprograms are deprecated in Oracle Database 10g. Oracle now automatically performs
the functions previously taken care of by these subprograms.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:12 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
Let’s look at how you can use the DBMS_STATS package to perform several tasks
involving the collection and management of optimizer statistics.
Here’s a simple example showing how to use the DBMS_STATS package to collect
an entire schema’s statistics:
EXECUTE DBMS_STATS.GATHER_SCHEMA_STATS ('SALAPATI', DBMS_STATS.AUTO_SAMPLE_SIZE);
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:12 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
or GATHER_AUTO, you can ensure that Oracle collects new statistics whenever it
encounters stale statistics for objects. (Note that GATHER_AUTO is the same as
GATHER_EMPTY plus GATHER_STALE.)
You can also use the DBMS_STATS package to delete, import, restore, and set
optimizer 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 collect
statistics at relatively longer intervals, say weekly or monthly. However, if your
database objects go through constant change on a daily basis, you need to schedule
the 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 of
GATHER_AUTO, AUTO_SAMPLE_SIZE, and scheduled GATHER_DATABASE_
STATS_JOB procedure, you can just let Uncle Oracle decide what and how much
to analyze, analyzing the important objects first.
■ LOCK_TABLE_STATISTICS
■ UNLOCK_TABLE_STATISTICS
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:12 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
■ 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 to
first delete any existing statistics, and then lock the table. Here’s how to do this:
BEGIN
DBMS_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 the
statistics NULL (no collection of statistics will take place after deleting the
current statistics).
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:12 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
Overriding Statistics Locking In some cases, you may want Oracle to override
any existing locks you have imposed on the optimizer statistics. You can do so by using
the 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:
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:12 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
OPERATION END_TIME
gather_database_stats(auto) 19-APR-04 10.04.59.321000 PM -05:00
set_system_stats 19-APR-04 01.44.53.098000 PM -05:00
set_system_stats 19-APR-04 01.44.53.769000 PM -05:00
set_system_stats 19-APR-04 01.44.53.832000 PM -05:00
SQL>
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:12 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
Until the Oracle9i database, Oracle used rollback segments to manage undo
information. Rollback segments are complex to administer, with segments encountering
the dreaded ORA-1555 (snapshot too old) errors on a regular basis during long
transactions. While Oracle Database 10g still enables you to use traditional rollback
segments, that feature has been deprecated in this version. In Oracle Database 10g,
you can use either a manual mode of undo
management (involving rollback segments), or
Automatic Undo Management (AUM). Oracle
If you don’t specify the recommends, however, that you use the AUM
mode of undo management, you will be feature, wherein Oracle will be in charge of
using manual undo management, with maintaining the undo segments. You don’t have
the help of rollback segments. This is the headaches of managing rollback segments
because the default undo management anymore. In addition, you can now control the
mode is manual. amount of time the database retains important
undo information before it overwrites the data.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:13 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
(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 be
correspondingly long.
You can use the Undo Advisor to help you configure the optimal undo retention
time and your undo tablespace size. The Undo Advisor bases its undo management
recommendations on the following criteria:
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:13 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
■ 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 on
tablespace and other alerts, see Chapter 4).
■ Oracle alerts you if your system has long-running queries that may result in
the ORA-1555 (snapshot too old) error.
■ If your undo tablespace has enough space, Oracle will retain undo data for
at least 900 seconds.
■ If your undo tablespace doesn’t have enough free space, Oracle may choose
not to retain the undo information for 900 seconds; that is, Oracle will let
new undo records write over the older records, even before the older records
are 900 seconds old.
Why does Oracle behave in this way? It will shorten the retention interval when
there are new DML operations in the database and there isn’t enough free space in the
undo tablespace to accommodate these new DML operations. Rather than cause the
DML operations to fail due to the lack of undo space, Oracle simply chooses the “lesser
evil” of overwriting some of the old redo information.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:13 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
You can check the current retention setting for your undo tablespace by issuing
the following query:
SQL> select tablespace_name,retention
2 from dba_tablespaces;
TABLESPACE_NAME RETENTION
-------------------------------------------
SYSTEM NOT APPLY
UNDOTBS1 NOGUARANTEE
SYSAUX NOT APPLY
…
SQL>
The NOGUARANTEE value under the retention column for the UNDOTBS1
tablespace shows the default value of the UNDO_RETENTION parameter. By default,
there is no guarantee of undo retention. You can guarantee undo retention for the
UNDOTBS1 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_undo
datafile ‘C:\oracle\product\10.1.0\data\new_iundo_01.dbf'
size 10M autoextend on
retention guarantee;
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:13 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
In the Automatic Shared Memory Management understand the new time model and the
section, you must clearly understand which are importance of the DB time metric. What
the automatically tunable and the manually are the different ways in which you can get
tunable SGA components. You must also know an ADDM report? How do you get ADDM
the background process that coordinates the reports for custom intervals? What does an
sizing of the memory components. What is ADDM report contain?
the difference between the behavior of the Expect a question regarding the automatic
SHARED_POOL_SIZE component in collection of optimizer statistics by Oracle.
Oracle Database 10g and in the older How does Oracle prioritize its statistics
versions of Oracle? collection? What procedure do you use
There will be a couple of questions to restore older optimizer statistics?
on the AWR and the ADDM. You must
If you specify the RETENTION GUARANTEE clause, you run the risk of your
DML operations failing due to lack of undo space. Therefore, don’t use this
clause unless you must guarantee the availability of undo data (for example,
for the flashback query feature).
CERTIFICATION SUMMARY
In 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 the
ADDM uses these snapshots to automatically analyze database performance and
make recommendations to improve it if necessary.
The chapter introduced you to the new Automatic Shared Memory Management
feature and the use of the SGA_TARGET initialization parameter. You learned about
how Oracle can automatically manage the four auto-tuned parameters.
You learned about how Oracle Database 10g can automatically gather key optimizer
statistics for you. You reviewed the Automatic Undo Management feature and learned
the role of the parameters UNDO_TABLESPACE and UNDO_RETENTION. Finally,
you learned about the new undo retention guarantee feature, which lets you ensure
the retention of undo data.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:13 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
✓ 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 them
for 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 the
time statistics on a system and session level, respectively.
❑ The key time model metric, DB time, covers the actual time spent processing
user 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 just
symptoms.
❑ The AWR automatically purges the old snapshots after the default interval
of seven days.
❑ The ADDM may recommend changes in I/O or memory, as well as database
and application configuration.
❑ The ADDM may also recommend the invocation of other management
advisors in order to analyze a problem in depth.
❑ The MMON background process helps manage the ADDM and schedules
the 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 data
retention 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 the
DBIO_EXPECTED parameter.
❑ You can view the ADDM analysis reports in three different ways: through the
Database Control, through SQL statements, and with the help of database
packages.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:13 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
Two-Minute Drill 45
❑ The easiest way to view the ADDM reports is through the OEM Database
Control.
❑ You can obtain ADDM reports by using the SQL script addmrpt.sql.
❑ The ADDM reports have three main components: impact, findings, and
recommendations.
❑ 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 package
enables you to produce ADDM reports.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:13 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:14 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
Self Test 47
SELF TEST
The following questions will help you measure your understanding of the material presented in this
chapter. Read all the choices carefully because there might be more than one correct answer. Choose
all correct answers for each question.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:14 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:14 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
Self Test 49
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:14 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
LAB QUESTION
You are currently using manual shared memory management. Your init.ora parameter file looks like this:
db_cache_size=80M
java_pool_size=10M
large_pool_size=10M
shared_pool_size=100M
What do you need to do to switch to Automatic Shared Memory Management? Ensure that your
SGA allocation is the same size as before. Show the answer using the manual SQL*Plus method.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:14 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:14 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 default
value of the parameter is zero anyway. Setting the SGA_TARGET parameter to zero means you
can’t use Automatic Shared Memory Management.
7. þ D. The value of the SGA_MAX_SIZE parameter will be bumped up to the value of the
SGA_TARGET parameter.
ý A is incorrect since the instance will start without any problem. B is incorrect because it
implies that the value of the SGA_TARGET parameter will be lowered to match the size of the
SGA_MAX_SIZE parameter. Actually as answer D indicates, it’s the other way around—the
SGA_MAX_SIZE parameter’s value will be raised to match the SGA_TARGET parameter’s
value. C is incorrect since the database doesn’t ignore the higher SGA_TARGET parameter
value, but uses it.
8. þ B. If you set the SGA_TARGET parameter value to zero, you’ll disable automatic memory
management.
ý 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 the
sum of manually sized parameters from the SGA_TARGET parameter. Oracle can assign only
the remaining memory to the auto-tuned parameters.
ý A and B are wrong, based on the analysis for the correct answer. D is wrong because you
won’t prevent Oracle from assigning memory to the auto-tuned parameters when you set the
size of one or more manually tuned memory parameters.
10. þ B. Even under Automatic Shared Memory Management, you can set the sizes of the
individual auto-tuned components. Oracle will treat this as the minimum values for these
parameters, 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 you
set the sizes for one or more auto-tuned parameters. C is wrong because, as the correct answer
explains, 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 you
use manual shared memory management.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:14 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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_JOBS
view 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 extremely
volatile.
ý 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 for
the 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 can
always 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 since
the procedures don’t override current statistics. D is wrong because the procedures lock the
current statistics, not those from a previous period.
16. þ A and D. A is correct because the RETENTION GUARANTEE clause guarantees that you’ll
never overwrite unexpired data in the undo segments. D is correct because you won’t overwrite
data more recent than the undo retention period.
ý B is wrong because Oracle may very well overwrite expired undo data, whether or not you
use the RETENTION GUARANTEE clause. C is wrong because there is no guarantee that Oracle
won’t overwrite data older than the data retention period.
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:15 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 3
LAB ANSWER
First, 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 have
set minimum values for all four auto-tuned SGA parameters in your init.ora file, Oracle can’t modify
the 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>
P:\010Comp\CertPrs8\862-4\ch03.vp
Thursday, September 02, 2004 4:49:15 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Blind Folio 4:1
4
Manageability
Infrastructure
CERTIFICATION OBJECTIVES
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
In this chapter, you’ll learn more about the Automatic Workload Repository
(AWR), which lies at the foundation of Oracle Database 10g’s self-management
capabilities. 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, in
Oracle Database 10g, you have an altogether new server-generated alert mechanism
to help you manage the database. These server-generated alerts include both
threshold-based and event-based warnings.
The chapter also discusses the new automated tasks feature. You’ll also get an
introduction to the new set of management advisors that comes with the Oracle
Database 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 like
memory, space, and SQL statement tuning.
The chapter contains the following major sections:
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
statistics at the system and session levels (wait statistics, segment usage statistics, and
so on), these statistics include operating system statistics (CPU statistics, disk usage
statistics, 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 you
collect the statistics. Let’s briefly look at the various types of performance statistics
you can collect in Oracle Database 10g.
Cumulative Statistics
Cumulative statistics are the accumulated total value of a particular statistic since
instance startup. The statistic total logons, for example, is a cumulative statistic. Oracle
collects cumulative statistics for just about every variable for which it collects statistics.
Oracle collects several types of cumulative statistics, including statistics for segments
and SQL statements, as well as session- and system-wide statistics. By comparing the
delta values—the rates of change of the cumulative statistics between a beginning and
an ending period—Oracle analyzes database performance during a specific interval
of time.
You are familiar with the important dynamic performance views V$SYSSTAT
and V$SESSSTAT. These two views hold many of the important cumulative
statistics for the Oracle database. Dynamic performance views are very useful in
judging database performance, but unfortunately, when you shut down the database,
the data in the dynamic performance views disappears completely! If you wish to
track database performance over time, or if you wish to compare the performance
impact 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 periods
and stores this information in its repository. This difference between two periods is
called an AWR snapshot. By default, the database will take a performance snapshot
every hour, but you can customize this interval.
Database Metrics
Database metrics are another important type of Oracle performance statistics. You can
define metrics as statistics that measure the rate of change in a cumulative performance
statistic.
In previous Oracle versions, you needed to compute metrics for various performance
statistics by collecting data at various periods, to calculate the rate of change of various
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
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 during
peak time. Dynamic performance views hold these metrics, and the AWR can also
store them in its repository. All the Oracle management advisors use database
metrics for diagnosing performance problems and making tuning recommendations.
You can look at statistics such as the number of user transactions and the number
of physical reads in the system as the base statistics from which you derive database
metrics. Thus, database metrics are derived statistics. The background process MMON
(Manageability Monitor) updates metric data on a minute-by-minute basis, after
collecting the necessary fresh base statistics.
Sample Data
The new Automatic Session History (ASH) feature now automatically collects session
sample data, which represents a sample of the current state of the active sessions. ASH
collects the data in memory, where you can view it with the help of V$ views. The
AWR helps save the ASH data permanently, by collecting it as part of its regular
snapshots. I discuss the ASH feature in detail later in this chapter, in the “Automatic
Session History” section.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Baseline Data
A good way to evaluate database performance is by comparing database performance
statistics 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 baseline
data. By comparing the current performance with the base period’s performance, you
can see if the database is faring better or worse. You could also compare individual
statistics to see which database component may be the source of your problems.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
■ Base statistics that are also collected in the V$SYSSTAT and V$SESSSTAT
views
■ New SQL statistics that aid in the identification of resource-intensive SQL
statements
■ Database object usage statistics that inform you about how the database is
currently accessing various objects
■ Time statistics, which tell you how much time each database activity is
taking
■ Wait statistics, which provide information about session waits (in previous
versions, you needed to join the V$SESSION view with the V$SESSION_
WAIT view to gather information on session waits; now several columns have
been added to the V$SESSION view, so you can query the view directly)
■ Active Session History (ASH) statistics, which are flushed to the AWR on
a regular basis
■ Database feature usage statistics that tell you if and how intensively your
database is utilizing various features
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
It is important to understand that the AWR isn’t a repository where Oracle stores
all the data for the various performance indicators that it covers. The AWR stores
only a part of the statistics that it collects in memory. Whenever AWR collects a
snapshot, it transfers part of the huge amount of data it holds in memory (SGA)
to disk.
■ Data-retention period The longer the retention period, the more space used
■ Snapshot interval The more frequent the snapshots are taken, the more
space used
■ Number of active sessions The higher the number of user sessions, the
more data collected by the AWR
By default, the AWR saves the data for a period of seven days, but you can modify
this period. Oracle recommends that you retain the AWR data to cover at least one
complete workload cycle.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
In order to use the AWR feature well, you need to select a truly representative
baseline, which is a pair or range of AWR snapshots. When database performance is
slow, you can compare the baseline snapshot statistics with current performance
statistics and figure out where the problems lie.
You can manage the AWR snapshots either with the help of the OEM Database
Control or with the Oracle-supplied DBMS_WORKLOAD_REPOSITORY package.
Let’s first look at how you can use this package to manage AWR snapshots.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
begin
dbms_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 collecting
snapshot data.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
If you want to change the general settings of the AWR, you can do so by clicking
the Edit button in the General section. This will take you to the Edit Settings page,
where you can modify the following:
Click the Manage Snapshots and Preserved Snapshot Sets button to get to
the Manage Snapshots page. The Manage Snapshots page lists all the snapshots
in the AWR. You can click an individual snapshot to view complete details about
it, including the capture time and the collection level. If you have established a
baseline, you’ll also see whether a particular snapshot falls within that baseline.
From the Manage Snapshots page, you can do the following:
The range of snapshots you use for a baseline is the same as a preserved
snapshot set.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
begin
dbms_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-generated
identifier.
You can drop a snapshot baseline by using the DROP_BASELINE procedure of
the DBMS_WORKLOAD_REPOSITORY package:
begin
dbms_workload_repository.drop_baseline (baseline_name => 'peak_time
baseline',
cascade => FALSE, dbid => 2210828132);
end;
If your SYSAUX tablespace runs out of space, Oracle will automatically delete
the oldest set of snapshots, to make room for new snapshots.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
In addition to the number of active user sessions, two parameters affect the total
statistics retained in the SYSAUX tablespace:
■ RETENTION As you know, the default retention period for AWR statistics
is seven days. The minimum retention period is one day. The longer the
retention period, the more space the AWR will need in the SYSAUX
tablespace.
■ INTERVAL By default, the AWR collects data every 60 minutes and the
minimum interval value is 10 minutes. You can’t collect statistics more
frequently than in 10-minute intervals. The more frequently you schedule
the AWR, the more data the AWR will collect. And the more infrequent the
AWR snapshots, the greater the chance that you may miss short bursts in disk
or memory usage that may occur in your database.
Oracle recommends that you make the retention period the same as your database
workload cycle. If your database is like many typical OLTP databases, you probably
have OLTP transactions throughout the weekdays, with batch jobs scheduled during
nights 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.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
If you set the value of the RETENTION parameter to zero, you disable
the automatic purging of the AWR. If you set the value of the INTERVAL
parameter to zero, you disable the automatic capturing of AWR snapshots.
■ 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
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Note that not all the extra statistics in Oracle Database 10g described in this
chapter will have a detrimental affect on performance, since the statistics
mostly come directly from the SGA, via background processes. The ASH
feature uses about 2MB of SGA memory per CPU.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 ASH
samples 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 whether
a session is active. The SESSION_STATE column can take two values: ON CPU
or 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 to
perform a database chore.
■ The session state is WAITING, but the EVENT column indicates that the
session 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 active
session history. Thus, in a busy database, older information is frequently overwritten,
since ASH collects data every second from the V$SESSION view. ASH stores its
data in V$ACTIVE_SESSION_HISTORY, but this view will contain only session
samples of the most recent active sessions, because the ASH statistics are
overwritten in memory.
■ During the course of the regular (by default, hourly) snapshots performed
by the AWR, the MMON background process flushes the ASH data to the
AWR. By default, the MMON process performs this data transfer on an
hourly basis.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Server-Generated Alerts
Oracle DBAs generally use SQL scripts to alert them when abnormal conditions
occur. 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 certain
problems occur in the database.
Oracle Database 10g uses a set of indicators called metrics, which show you the
rate of change of a cumulative statistic. A typical example of an Oracle metric is
the 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 database
metrics are an important part of server-generated alerts, let’s first take a look at how
you monitor database metrics.
Introduction to Metrics
Metrics are indicators of the health of various database targets. The set of metrics
depends on the target you are measuring. For example, key metrics help you decide if
the host is healthy and if resources like CPU, memory, and I/O are performing at an
acceptable level.
The OEM Database Control’s All Metrics page, shown in Figure 4-2, offers an
excellent way to view the various metrics. To access this page, from the Database
Control 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 link
in the left corner of the page. If you want the drill down to the details of any specific
metric, just click it.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Server-Generated Alerts 17
Table 4-1 lists the basic metric groups in Oracle Database 10g.
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 Metrics collected at the session level; for example, BLOCKED_USERS
(Long) Duration
System Metrics Short Metrics collected at the system level
(Long) Duration
Tablespace Metrics Long Metrics collected at the tablespace level; for example, TABLESPACE_
Duration PCT_FULL.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Server-Generated Alerts 19
You can view the current values of any metric by using the V$ views, such as the
V$METRICNAME and V$SERVICEMETRIC views. The MMON process regularly
computes these metrics for you. However, the various performance metrics
stay in the SGA for only an hour. MMON will automatically flush the metric
data from the SGA to the DBA_HISTORY_* views on disk. These history views
maintain a permanent record of the various metrics. Examples of the history
views are DBA_HIST_SUMMARY_HISTORY, DBA_HIST SYSMETRIC_HISTORY,
and DBA_HIST_METRICNAME. Each of these views contains snapshots of the
corresponding V$ view. For example, the DBA_HIST_SYSMETRIC_HISTORY
view contains snapshots of the V$SYSMETRIC_HISTORY view.
Database Alerts
A database alert tells you that there is a potential problem in your database. The potential
problem can occur when a threshold value for a monitored metric is crossed or a database
target simply becomes unavailable. For example, an undo tablespace may trigger the
Long Query Warning alert, thus alerting the DBA about a long-running query that
may fail because the system is running out of free space in the undo tablespace. Oracle
calls the threshold alerts stateful alerts. Oracle calls the types of alerts issued when a
target becomes unavailable stateless alerts.
We can refer to the first two types of the alerts as threshold-based alerts and the
third 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 certain
predetermined event (usually bad) occurring in the database.
Threshold-based alerts are based on thresholds for certain objects or events in the
database; for example, a tablespace may be reaching 95 percent of its total allocated
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
space. Threshold-based alerts thus are dependent on metrics, not events. The
threshold itself could be an internally set level, or you, the DBA, can set your own
alert threshold levels. When a metric crosses a threshold, Oracle automatically
generates an alert to you. In addition, the database can undertake remedial action
to fix the problem (or potential problem), if you specify a response action.
When you use threshold-based alerts, Oracle further makes a distinction between
a warning type alert (severity level 5) and a critical (severity level 1) alert. For
example, by default, the database will send you a warning alert when any tablespace
hits an 85 percent space use threshold. When the usage reaches the 97 percent level,
you get a critical alert.
In addition, Oracle automatically set thresholds on all metrics with the object
type SYSTEM.
The new database alert database cannot write an alert to the alert
system has really nothing to do with the queue, in which case, it records this
alert log of the database. The only time exception in the alert log.
the alert log may be involved is when the
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Server-Generated Alerts 21
Tablespace usage alerts are space usage for a warning alert and 97
based on the default values of 85 percent percent space usage for a critical alert.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Managing Alerts
Several new data dictionary views aid in managing both database metrics and server-
based alerts. The following sections explain using the various methods to manage
alerts. Let’s first look at how you can use the OEM Database Control for this purpose.
Setting Alert Thresholds It is very easy to set your own warning and critical
thresholds for any database metric. To set alert thresholds, from the Database
Control home page, click the Manage Metrics link, which you’ll find under the
Related Links group. On the Manage Metrics page, click the Edit Thresholds
button. You’ll see the Edit Thresholds page, as shown in Figure 4-3. For each
metric on the Edit Thresholds page, you can set the following:
Setting Notification Rules When the database needs to send you an alert, it
follows any notification rules that you’ve set up. Notification rules enable you to
choose 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 a
tablespace with 100GB allocated space has reached an 80 percent usage level.
On the other hand, you would surely want to know immediately when a 200MB
tablespace has crossed the critical 97 percent usage level.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Server-Generated Alerts 23
You can use the Database Control to set notification rules. These rules are set
through Preferences. From the Database Control home page, click the Preferences
link (at the very bottom of the page) to go to the Preferences page. Then click the
Rules 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:
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Here’s an example that sets up an automatic alert monitoring of CPU use by each
user 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');
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Server-Generated Alerts 25
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
I’ll describe a couple of the important views in more detail in the following
sections.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Server-Generated Alerts 27
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
EXERCISE 4-2
2. Set your tablespace alert thresholds as follows (warning alert at 75% full and
critical 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 will
set off an alert (because the ‘minextents 4’ clause for the new table will cause
the tablesapce to cross its warning threshold of 75% space full):
SQL> create table test_table (name varchar2(30))
tablespace test
storage (minextents 4);
Table created.
SQL>
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
5. You can clear the alert by increasing the size of the datafile that is part of the
tablespace named small and see what happens to the alert by querying the
DBA_OUTSTANDING_ALERTS view. You’ll find that the alert is gone from
that 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 selected
SQL>
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 that
view, by using the following query.
SQL> select reason,resolution from dba_alert_history;
REASON RESOLUTION
-------------------------------------------------------------------
Tablespace [TESTNEW] is [13 percent] full cleared
SQL>
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
start our discussion of the automated tasks feature by briefly looking at the
Scheduler.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
You can also use the Database Control interface to manage all aspects of the
Oracle Scheduler, including creating, deleting, and modifying jobs, job classes,
and windows.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
The Advisors
We can group the automatic advisors into the following groups: memory-related,
tuning-related, and space-related. In later chapters, you’ll see a complete discussion
of several of the management advisors. Let’s briefly look at the advisors that fall into
these three groups.
Memory-Related Advisors
Of the three memory-related advisors, two provide information about the SGA and
one provides PGA advice. The following are the memory-related advisors:
■ Buffer Cache Advisor This advisor tells you the benefits in increasing or
decreasing the memory allocation to the BUFFER_CACHE parameter. The
advisor shows the benefit as a decrease in disk I/O.
Obviously, if you are using Automatic Shared Memory Management, you don’t
need the Buffer Cache Advisor or the Library Cache Advisor to tell you how
to size these memory components. Oracle itself will do that for you.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
■ Library Cache Advisor This advisor shows you the impact of changing the
shared pool component of the SGA.
■ PGA Advisor This advisor provides recommendations on optimal allocation
of Program Global Area (PGA) memory, based on your database workload.
Space-Related Advisors
The two space-related advisors are new to Oracle Database 10g:
■ Segment Advisor This advisor allows you to perform growth trend analyses
on various database objects. This advisor also helps you perform object
shrinkage, 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. The
Undo Advisor facilitates Oracle’s Automatic Undo Management feature. It
helps you to correctly size your undo tablespace. It also helps you choose the
correct undo retention parameters.
Tuning-Related Advisors
The 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 and
performance-related advisors:
■ SQL Tuning Advisor This advisor analyzes complex SQL statements and
recommends ways to improve performance. The SQL Tuning Advisor bases
all its work on internal statistics and may include suggestions to collect new
statistics as well as SQL code restructuring.
■ SQL Access Advisor This advisor mainly provides you advice on creating
new indexes, materialized views, or materialized view logs. You provide the
advisor a representative workload in order to get the advice.
Most of the database alert messages in the OEM also contain a link to
specific management advisors. Thus, you can invoke a management advisory
directly from the alert message itself.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
The following are the steps you must follow in order to use the DBMS_ADVISOR
package to manage various advisors:
■ Create a task
■ Adjust task parameters
■ Perform the analysis
■ Review the advisor recommendations
Creating a Task The first step in using an advisor is creating a task. A task is
where the advisor stores all its recommendation-related information. You create a
task 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 is
to set the parameters for this task. The task parameters control the recommendation
process. The parameters you can modify belong to four groups: workload filtering,
task configuration, schema attributes, and recommendation options.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 the
SET_TASK_PARAMETER procedure:
SQL> EXECUTE DBMS_ADVISOR.SET_TASK_PARAMETER ( -
'TEST_TASK', 'VALID_TABLE_LIST', 'SH.SALES, SH.CUSTOMERS');
In this example, the RANK column shows how the four recommendations stack
up against each other. The BENEFIT column shows the decrease in the execution
cost for each of the four recommendations.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
■ DBA_ADVISOR_TASKS
■ DBA_ADVISOR_PARAMETERS
■ DBA_ADVISOR_FINDINGS
■ DBA_ADVISOR_RECOMMENDATIONS
■ DBA_ADVISOR_ACTIONS
■ DBA_ADVISOR_RATIONALE
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
The test looks at your knowledge of the add subscriber, and so on). The exam tests
Automatic Workload Repository (AWR) in your knowledge of the types of events that
depth. You must be aware of the in-memory set off server-generated alerts. What are the
and persistent portions of the AWR and the default tablespace usage alert settings? What
mechanism that records the AWR statistics on are the various nonthreshold, or stateless,
disk. How do you create an AWR report? alerts?
What are the options during the report The exam tests you on your knowledge
creation process? Be aware that the Active of the PL/SQL interface for alert threshold
Session History (ASH) is a component of the settings, which is the DBMS_SERVER_ALERT
AWR, and that it focuses on current session package. You must know exactly what each
activity. You must also understand the role of of the SET_THRESHOLD parameters stands
the background processes MMON and MMNL for. How do you set the critical and warning
clearly. thresholds to NULL? You must also know the
You must know all the default settings, like different components of the DBMS_ADVISOR
how long the AWR retains information and package that help you in creating an advisor
how often AWR snapshots occur. How do you tuning session (create task, adjust task
change these settings? parameters, perform analysis, and review the
You must be aware of the various pages of results). The test checks your knowledge of
the Database Control that you must traverse in important data dictionary views like DBA_
order to manage the automatic alerts in your OUTSTANDING_ALERTS (where outstanding
database. You can expect a question (or more) alerts are stored) and DBA_ALERT_HISTORY
about custom configuration of alerts using the (where cleared alerts go).
DBMS_AQADM package (create AQ Agent,
CERTIFICATION SUMMARY
This chapter introduced the new AWR feature, which is central to Oracle Database
10g’s performance tuning. You reviewed the different kinds of data stored in the AWR
and how to manage the AWR by using the DBMS_WORKLOAD_REPOSITORY package.
You learned how to create and manage AWR snapshots and baselines. The chapter
also explained the ASH statistics, which are a key part of the AWR.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
In the server-generated alerts section, you saw how Oracle generates automatic
alerts. You learned how to use the Database Control to manage server alerts. The
chapter showed you how to set alerts using the DBMS_SERVER_ALERT package.
The chapter introduced you the Oracle’s automated tasks feature using the
Scheduler. You also learned about the various Oracle management advisors.
You reviewed the use of the DBMS_ADVISOR package to manage the advisory
framework.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Two-Minute Drill 39
✓ 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 the
instance.
❑ Both the V$SYSSTAT and V$SESSTAT views show cumulative
performance 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 statistics
for recently modified objects.
❑ The MMNL background process captures ASH history data when the
memory 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 database
performance between two periods.
❑ If you set the STATISTICS_LEVEL parameter to BASIC, the AWR turns
off its statistics collection.
❑ If you set the STATISTICS_LEVEL parameter to ALL, the AWR collects
all available statistics.
❑ If you set the STATISTICS_LEVEL to TYPICAL, the AWR collects what
Oracle considers is a typically needed amount of statistics.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
❑ By default, the AWR collects new snapshots every 60 minutes, but you can
change 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; operating
system; and other statistics.
❑ Managing the AWR snapshots enables you to manage the AWR.
❑ You can view AWR snapshot data through V$ views or the
Database Control interface.
❑ The Manage Snapshots section of the AWR page in the Database Control
lets you manage snapshots.
❑ You can use the DBMS_WORKLOAD_REPOSITORY package to create and
drop snapshots, as well as to change the settings of the RETENTION and
INTERVAL parameters.
❑ A snapshot baseline consists of any pair of AWR snapshots.
❑ A preserved snapshot set shows the range of snapshots you use for an AWR
baseline.
❑ You can create and drop baselines using the DBMS_WORKLOAD_
REPOSITORY package’s CREATE_BASELINE and DROP_BASELINE
procedures.
❑ By default, the AWR retains snapshot data for seven days, before
automatically 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 oldest
set of AWR snapshots.
❑ The longer the AWR retention period, the larger you should make your
SYSAUX tablespace.
❑ The shorter the AWR snapshot interval, the larger you should make your
SYSAUX tablespace.
❑ Oracle recommends that you set your retention period according to the
length of your database workload cycle.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Two-Minute Drill 41
❑ If you set the value of the RETENTION parameter to zero, you disable the
automatic purging of the AWR.
❑ If you set the INTERVAL parameter to zero, you disable the automatic
snapshot collection by the AWR.
❑ Use the $ORACLE_HOME/rdbms/admin/awrrpt.sql script to produce AWR
reports.
❑ The AWR reports are very similar to the old STATSPACK reports.
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 preset
threshold value.
❑ Threshold alerts are also called stateful alerts.
❑ Error or problem alerts, which are issued because a service or target becomes
unavailable, are also called stateless alerts.
❑ When you fix the problems that prompted an alert, the alert is cleared
automatically.
❑ Threshold-based alerts are divided into warning and critical types.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Two-Minute Drill 43
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
SELF TEST
The following questions will help you measure your understanding of the material presented in this
chapter. Read all the choices carefully because there might be more than one correct answer. Choose
all correct answers for each question.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Self Test 45
Server-Generated Alerts
10. Stateful alerts are those alerts that pertain to thresholds. Stateless alerts pertain to problem
alerts. 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.vp
Monday, August 30, 2004 3:46:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Lab Question 47
LAB QUESTION
Use 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_ADVISOR
package.)
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
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 stateless
alerts—they aren’t recorded in the DBA_OUTSTANDING_ALERTS view.
A is wrong because stateful alerts go into the DBA_ALERT_HISTORY view only after
they 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 directly
written 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 flushes
metrics to disk on an hourly basis.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:42 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 is
wrong because the AWR doesn’t save metrics in the SGA—it saves them on disk.
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:42 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 4
Lab Answer 51
20. þ A and D. A is correct because the SQL Access Advisor advises you about the best access
to objects, including using indexes. D is correct since the ADDM can call any of the
management 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 ANSWER
First, define the bind variables:
SQL> VARIABLE taskname VARCHAR2(40)
SQL> VARIABLE taskid NUMBER
P:\010Comp\CertPrs8\862-4\ch04.vp
Monday, August 30, 2004 3:46:42 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
Blind Folio 5:241
5
Application Tuning
CERTIFICATION OBJECTIVES
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:17 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
O racle DBAs spend a considerable amount of their time tuning resource-guzzling SQL
statements, 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 recommendations
on the performance data gathered by the Automatic Workload Repository (AWR).
This chapter introduces you to the new SQL Tuning Advisor, which helps you
perform the new art of SQL profiling, whereby you help the Oracle optimizer generate
better-tuned execution plans.
There are several changes in the way you can collect optimizer statistics, and this
chapter explain these in detail. You’ll learn how to use the new SQL Access Advisor
to define better access structures like indexes. Finally, you’ll learn how to use the
Performance pages of the OEM Database Control to effortlessly perform your SQL
tuning exercises.
In the new database, there are several enhancements regarding the ability to skip
unusable indexes, and to create and maintain hash-partitioned global indexes. The
final part of this chapter discusses these and other issues, such as specifying storage
characteristics for index partitions.
Let’s start this important chapter with a summary of the changes in optimizer
statistics in Oracle Database 10g.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:17 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
Changes in the
DBMS_STATS Package
The DBMS_STATS package has several changes,
The automatic statistics including changes in the key GATHER_
gathering feature is enabled by default. If DATABASE_STATS and GATHER_SCHEMA_
you wish to disable it, you can do so by STATS procedures. There are new values for
executing the following: the GRANULARITY argument in both of these
DBMS_SCHEDULER.DISABLE('GATHER_STATS_JOB'); procedures. The GRANULARITY argument is
pertinent only if the underlying table is partitioned.
AUTO is the default value for this argument. If you specify AUTO as the granularity
level, Oracle collects global-, partition-, and subpartition-level statistics, if you use
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:17 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
Dynamic Sampling
You may, on occasion, encounter situations where you have database objects whose
statistics are suspect or are missing altogether. In cases like this, the database will
calculate if it is advantageous to estimate statistics using a small sample of the object’s
data. 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, dynamic
sampling may benefit that SQL statement, by yielding superior execution plans.
If you want to use automatic dynamic sampling in your database, set the
OPTIMIZER_DYNAMIC_SAMPLING initialization parameter to at least 2 (the
default 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 Monitoring
If you use either the GATHER AUTO or STALE settings when you use the DBMS_STATS
package, 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 statistics
collection. In previous versions, you had to specify the MONITORING keyword in the
CREATE (or ALTER) TABLE statement in order to enable the DBMS_STATS package
to automatically gather statistics for a table. In Oracle Database 10g, the MONITORING
and NO MONITORING keywords are deprecated. Oracle uses the DML change information
logged in the DBA_TAB_MODIFICATIONS view to determine which objects have
stale statistics. Just make sure that you set the STATISTICS_LEVEL parameter to
either the default TYPICAL or ALL setting.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:18 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
If you use the GATHER_ database objects that have changed enough
DATABASE_STATS or GATHER_DATABASE_ to warrant fresh statistics. Make sure you
STATS procedure of the DBMS_STATS haven’t set the STATISTICS_LEVEL
package with OPTIONS set to GATHER parameter to BASIC, because this turns
AUTO, you’ll be analyzing only those off the default table monitoring feature.
You must have the SYSDBA or ANALYZE ANY DICTIONARY system privilege
to analyze any dictionary objects or fixed objects.
If you wish, you can collect statistics for an individual fixed table by using the
standard DBMS_STATS procedures that enable table-level statistics collection. Then
you can collect statistics for a fixed table just as would for any regular database table.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:18 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
■ You may create a new SQL statement or set of statements as an input for
the SQL Tuning Advisor. Especially if you are working with a development
database, this may be your best source of questionable SQL statements.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:18 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
If you have a set of SQL statements that you want the advisor to tune, you can
create a SQL Tuning Set (STS), which is a set of multiple SQL statements, along
with their execution information like the average elapsed time and bind values.
Isolated SQL statements sometimes fail to capture the characteristics of your database
workload realistically. An STS not only captures a database workload’s information
effectively, 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.
Since it sometimes takes several minutes for the optimizer to work through its
analysis in the tuning mode, use it for fixing only your highly resource-intensive
SQL statements.
When you use the Oracle optimizer in the tuning mode, it’s referred to as the
Automatic Tuning Optimizer (ATO). In this mode, you aren’t really using the
optimizer to develop quick execution plans. Your goal is to see if the ATO can
improve on the usual optimizer execution plans. The ATO lies at the heart of the
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:19 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
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 improve
SQL performance.
■ Statistics analysis
■ SQL profiling
■ Access path analysis
■ SQL structure analysis
SQL Profiling
The ATO collects auxiliary information to improve the execution plans. The ATO’s
goal at this stage is to verify that its own estimates of factors like column selectivity
and cardinality of database objects are valid. It may use the following three verification
or validation methods to test to verify its initial estimates:
■ Dynamic data sampling Using a sample of the data, the ATO can check its
own estimates of various factors like cost and cardinality for the statement in
question. The ATO may decide to apply correction factors to the data, if the
sampling process reveals that its estimates are significantly off the mark.
■ Partial execution The ATO may partially execute a SQL statement, so it
can check if its original estimates are good enough. It compares the run-time
performance with the expected performance (based on the execution plan).
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:19 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
One of the biggest advantages of SQL profiles is that they provide you an
effective way to tune “code that you can’t touch.” Packaged applications are
usually hard to tune for DBAs, since there are limitations on accessing and
modifying code. Since the SQL profiles are saved in the data dictionary, you
can use them to tune even packaged applications.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:19 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:19 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
To use the DBMS_SQLTUNE package, you must have the ADVISOR privilege.
Performing Automatic SQL Tuning Following are the main steps in using
the DBMS_SQLTUNE package to tune SQL statements.
EXERCISE 5-1
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:19 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
Managing SQL Tuning Categories Suppose you have several profiles, all
somewhat different, for a SQL statement. How does Oracle know which profile to
use in a given case? All SQL profiles that you create for various SQL statements belong
to specific SQL tuning categories. When a user logs in to the database, Oracle assigns
each user to a specific tuning category, based on the value of the initialization parameter
SQLTUNE_CATEGORY. Thus, the category name qualifies the lookup of SQL profiles
by 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 in
to the database. After the user logs in, you can change the SQL tuning category for
all the users by using an ALTER SYSTEM command, or you can change a session’s
tuning category by using an ALTER SESSION command. For example, suppose that
you have already created the categories PROD and DEV. You can change the SQL
tuning category for all users with the following command:
SQL> alter system set SQLTUNE_CATEGORY = PROD;
Oracle will now apply all profiles under the category DEV, until you log out from that
session. When you log in again, the default tuning category will again determine the
profiles available to your session.
The ATO will build a create a SQL profile. Once you create a
SQL profile only if it generates auxiliary new SQL profile, Oracle automatically
information during the statistics analysis applies that profile to the SQL statement
and SQL profiling steps. If it builds a SQL when you next execute it.
profile, it will recommend that you actually
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:20 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
A session can change its SQL tuning category by using the ALTER SESSION
statement shown in this section. You may also use the DBMS_SQLTUNE.ALTER_
SQL_PROFILE procedure to change the SQL tuning category.
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 view
the advisor report and analyze the recommendations.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:20 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
■ Current and recent SQL activity, which includes statements from the SQL
cache (from the V$SQL view)
■ An STS stored in the AWR
■ A user-defined workload, which enables you to test a workload before an
application goes into production
■ An hypothetical workload you’ve created from specific schemas and tables
The three types of database materialized view logs. There are four
objects that the SQL Access Advisor may main sources of input for the advisor: SQL
recommend that you create, drop, or retain cache, user-defined workload, hypothetical
are indexes, materialized views, and workload, and STS from the AWR.
■ Storage constraints
■ Refresh time constraints
■ Full or partial workloads
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:20 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
Modes of Operation
You can operate the SQL Access Advisor in two modes:
You can also use workload filters to specify which kinds of SQL statements the
SQL Access Advisor should select for analysis, from the workload it has in front of
it. 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 the
scope of the SQL statements in the workload. The advisor applies these filters to
focus its tuning efforts, say, limiting its analysis to only those statements that touch
a certain set of tables.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:20 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
1. Create and manage a task, by using a SQL workload object and a SQL
Access 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 package
to quickly analyze a single SQL statement, without needing to go through all these
steps. You can create tasks, prepare workloads for the SQL statement, execute the
task, save the results, and finally implement the recommendations as well. Here’s a
quick 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);
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:21 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
■ Space Restrictions These options include setting space size limits that the
advisor’s recommendations can’t exceed. You may also limit the number of
indexes that the advisor can create.
■ Tuning Options These options prioritize the advisor’s access recommendations
by items like buffer gets, CPU time, disk reads, and elapsed time.
■ Default Storage Locations These options enable you to override the default
locations defined for the schema and the tablespaces.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:21 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
■ Host
■ Sessions waiting and working
■ Instance throughput
■ Average Run Queue This shows how hard the CPU is running. A high run
queue indicates that there is contention for CPU time. The run queue tells
you how many processes are ready to run but are unable to do so, due to a
CPU bottleneck.
■ Paging Rate This shows the rate at which the host server is writing memory
pages to the swap area on disk. Paging slows down your system because of the
extra I/O, and it indicates that your system is memory-bound.
Oracle recommends that you start investigating waits if the level of waits is at
twice the Maximum CPU line in the sessions graph.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:21 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:22 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
Indexing Enhancements
There are several index-related enhancements in Oracle Database 10g. Primary among
them are the following:
Let’s start our discussion in this section with a look at enhancements in the skipping
of unusable indexes.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:22 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:22 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
Hash-Partition Management
When you create a hash-partitioned index, you can specify each partition its own
tablespace, or you can specify the total number of partitions and use the STORE IN
clause to allocate the hash partitions among the available number of tablespaces. If you
skip the STORE IN clause, Oracle will place the hash partition in the user’s default
tablespace. All partitions in a hash-partitioned global index share identical physical
and storage attributes.
You use the following statement for creating a hash partitioned global index, if
you wish to specify each hash partition individually:
SQL> create index sales_hash
on sales_items (sales_id) global
partition by hash (sales_id) (
partition p1 tablespace tbs_1,
partition p2 tablespace tbs_2,
partition p3 tablespace tbs_3
partition p4 tablespace tbs_4);
You can also create a hash partitioned global index by specifying the number of hash
partitions (4 in our example) with the optional STORE IN clause, as shown here:
SQL> create index sales_hash
on sales_items (sales_id) global
partition by hash (sales_id)
partitions 4
store in (tbs_1,tbs_2,tbs_3,tbs_4);
P:\010Comp\CertPrs8\862-4\ch05.vp
Wednesday, September 15, 2004 1:09:29 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
indexes unusable by making Oracle automatically rebuild them, thus increasing the
availability of your database. Here’s an example of the usage of the UPDATE
INDEXES clause during partitioned table DDL:
SQL> alter table MY_PARTS
2 MOVE PARTITION my_part1 tablespace new_tbsp
3 UPDATE INDEXES
4 (my_parts_idx
5 (PARTITION my_part1 TABLESPACE my_tbsp);
Note that if you don’t specify the index name in the preceding statement, Oracle
will rebuild the indexes to put them back into a usable state.
You must be aware of the role of the GATHER_ On the exam, don’t be surprised to see a
STATS_JOB Scheduler job as well as the couple of questions about using the OEM
proper settings of the STATISTICS_LEVEL Database Control to manage database
parameter for optimizer statistics collection. performance. You must know the basic
The certification exam tests you knowledge of approach of the Database Control regarding
the SQL Access Advisor and the SQL Tuning performance management (CPU and waits,
Advisor rather thoroughly. You must know top SQL, and top sessions). You must practice
the particular types of Oracle objects about using the Database Control to locate statistics
which the SQL Access Advisor will make about CPU and waits, SQL, and sessions.
recommendations. You must remember all the What’s on the Database Control Database
possible sources of data for both of these advisors. Home page? What are the three sections of the
The exam focuses on the Automatic Tuning Database Performance page? How do you drill
Optimizer (ATO). What is the difference down to various contention areas? Where and
between the regular Oracle optimizer and the what are the Top Waiting SQL and the Top
ATO? You must understand each type of analysis Waiting Sessions charts? How do you drill down
the ATO performs as part of the SQL tuning to the Top SQL by Waits chart?
process. Review all four types of analyses Expect a question testing your knowledge of
carefully, paying attention to the various kinds the SKIP_UNUSABLE_INDEXES and/or the
of verification methods in the SQL profiling UPDATE INDEXES clause, both concerning
phase of the analysis. Know how to create a SQL Oracle Database 10g enhancements to the
profile, as well as how Oracle uses it. When does partitioning option. Review the benefits of
the ATO recommend a SQL profile? hash-partitioned global indexes.
P:\010Comp\CertPrs8\862-4\ch05.vp
Wednesday, September 15, 2004 1:09:30 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
CERTIFICATION SUMMARY
This chapter started with an overview of the enhancements and changes in the
optimizer statistics collection in Oracle Database 10g. You learned about the automatic
statistics collection process. The SQL Tuning Advisor takes away the drudgery involved
in tuning complex SQL code, and you learned how to manage this advisor using
PL/SQL packages as well as the Database Control.
You learned about the SQL Access Advisor and how you can get advice about
proper indexes and materialized views in your database.
You saw how you could use the Database Control’s Performance page to drill
down into any performance issue of interest. You learned about the innovations in
the skip unusable indexes feature. You saw how you could specify storage characteristics
for index partitions in the course of DDL statements. You were introduced to the
new hash-partitioned global indexes, which can reduce index contention in some
special circumstances.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:23 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 are
not supported in Oracle Database 10g, although you can still continue to
use them.
❑ The default value for the OPTIMIZER_MODE parameter is ALL_ROWS.
❑ Oracle prioritizes its automatic statistics collection, with preference given
to 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 collect
subpartition-level statistics.
❑ The DEFAULT setting for the DEGREE argument means that you’ll use a
system-based degree of parallelism.
❑ Use the OPTIMIZER_DYNAMIC_SAMPLING parameter to use automatic
dynamic sampling.
❑ Table monitoring is automatic in Oracle Database 10g.
❑ Oracle recommends that you collect optimizer statistics for data dictionary
tables, both fixed and real.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:23 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
❑ Use the optimizer in the tuning mode only for highly resource-intensive
statements.
❑ The fours steps of a SQL Tuning Advisor job are statistics analysis, SQL
profiling, access path analysis, and SQL structure analysis.
❑ You can manage the SQL Tuning Advisor by using the DBMS_SQLTUNE
package.
❑ 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.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:23 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
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 the
partitioning key column.
❑ Hash-partitioned global indexes increase concurrency, especially if the index
is on monotonically increasing sequence numbers.
❑ You can’t perform certain index maintenance operations on hash-partitioned
global indexes.
❑ You can use the UPDATE_INDEXES clause to set storage attributes as well as
to keep local indexes from being made unusable during a DDL operation.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:24 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
SELF TEST
The following questions will help you measure your understanding of the material presented in
this chapter. Read all the choices carefully, because there might be more than one correct answer.
Choose all correct answers for each question.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:24 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:24 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
Indexing Enhancements
14. When you have a monotonically increasing sequence number as an indexed column, which of
the 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.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:24 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
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 QUESTION
Use 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.
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:24 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:24 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
Indexing Enhancements
14. þ A. When you have monotonically increasing indexed column, hash-partitioned global
indexes are ideal, because they spread the column values more or less uniformly among the
partitions.
ý B is wrong since range-partitioned global indexes are the worst choice for this type of
indexed columns. C and D refer to local indexes, which aren’t really better than the global
indexes in this case.
15. þ A and B. By using the UPDATE INDEXES clause, you can specify storage attributes as
well 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.vp
Tuesday, September 14, 2004 3:23:25 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 5
LAB ANSWER
First, 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)
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;
/
P:\010Comp\CertPrs8\862-4\ch05.vp
Tuesday, September 14, 2004 3:23:25 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Blind Folio 6:1
6
Space and Storage
Management
Enhancements
CERTIFICATION OBJECTIVES
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:53 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
I n Chapter 4, you learned about the new automatic database alerts. In this chapter, you’ll
see 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 the
database. You need to run SQL scripts to find out the amount of free space, and
possibly move or re-create database objects to recover the excess space. Due to the
time these database-reorganizing efforts consume, quite often, the free space is never
reclaimed. 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 you
isolate candidates for shrinking and to track segment growth over time, so you
can plan your space requirements correctly. You’ll next learn how to use the Undo
Advisor and the Redo Logfile Size Advisor. This chapter also introduces you to the
new data structure called the sorted hash cluster, which helps you store data sorted
by nonprimary key columns.
You read about the new SYSAUX tablespace in Chapter 1. In this chapter, you’ll
get the details of creating and managing the SYSAUX tablespace. You’ll learn about
temporary tablespaces and assigning temporary tablespace groups to users. You’ll also
look at topics like renaming tablespaces and creating a default temporary tablespace.
Large databases need large datafiles. The new bigfile tablespaces address this need by
enabling the creation of large tablespaces with just a single data file. This chapter
concludes 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 management
in Oracle Database 10g.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:53 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
■ You can’t set alerts for dictionary-managed tablespaces. You can set alerts
only for locally managed tablespaces.
■ When you take a tablespace offline or make it read-only, you must turn
the alerting mechanism off (using the DBMS_SERVER_ALERT package).
You can turn the alerts back on after you change the status of the
tablespaces again.
■ For the undo tablespace, the active and unexpired extents together
constitute the used space in that tablespace. The same default warning
and critical thresholds (97 percent and 85 percent, respectively) apply
to the undo tablespace as well.
You can manage the tablespace usage alerts by setting or modifying the alert
thresholds. You can do this with the OEM Database Control or by using the PL/SQL
package DBMS_SERVER_ALERT. Let’s first learn how to manage the tablespace
space usage alert using Database Control.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:53 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
3. From the Edit Thresholds page, you can set thresholds for the Tablespace
Usage metric. Click the Specify Multiple Thresholds button. This will bring
you to the Specify Multiple Thresholds: Tablespace Used page. You can set
thresholds for a specific tablespace from here.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:53 AM
Color profile: Generic CMYK printer profile
Composite Default screen 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 space
in table or index segments was to move the object or redefine it. These reorganizations
sometimes could be very time-consuming.
In Oracle Database 10g, you can now use the new segment-shrinking capability to
make sparsely populated segments give their space back to their parent tablespace.
You can reduce the HWM, thus compacting the data within the segments. In Oracle
Database 10g, you can shrink the following types of segments:
■ You can’t shrink any segment that uses free lists. This means that you can
only shrink segments that use Automatic Segment Space Management.
■ You must enable row movement (for heap-organized segments). Enabling
row movement lets you specify whether Oracle can move a table row to
a different location. Oracle may need to move a row, for example, during
table compression or an update operation on partitioned data. During a
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:54 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
■ Compaction phase During the compaction phase, the rows in a table are
compacted and moved toward the left side of the segment. You thus make
the segment dense, but the HWM remains where it was. The recovered space
is not yet released to the tablespace. During this phase, you can issue DML
statements and queries on a segment while it is being shrunk. Oracle holds
locks on packets of the rows involved in the DML operations. If you have
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:54 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
any long-running queries, Oracle can read from all the blocks that have
technically been reclaimed during the shrinking operation. Of course, this
capability is dependent on the time interval you specified for your undo
retention parameter.
■ Adjustment of the HWM/releasing space phase During the second phase,
Oracle lowers the HWM and releases the recovered free space under the old
HWM to the parent tablespace. Oracle locks the object in an exclusive mode.
This implies that you can’t issue any INSERT, UPDATE, and DELETE
DML statements against the segment. During this phase, Oracle invalidates
any cursors referencing the segment as well. This second phase lasts for a very
short period.
During the compacting phase, the object is online and available, but during
the 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 the
space) 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 yield
the freed space to the tablespace.
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 the
space in the segment:
SQL> alter table test SHRINK SPACE COMPACT;
This way, during peak hours, the database will merely compact the space in the
segment. During off-peak hours, you can issue the ALTER TABLE test SHRINK
SPACE command, and this will finish the shrinking process by performing the
second phase.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:54 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:54 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:54 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Where does the Segment Advisor get the data for its recommendations? The
Automatic Workload Repository (AWR) collects all space-usage statistics during
its regular snapshot collection. The Segment Advisor, to estimate future segment
space 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 traces
past 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 produce
growth trend reports.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:55 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
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, specify
your column data types. Then click the Estimate Table Size button.
5. On the Estimate Table Size page, specify the estimated number of rows in the
new table, under Projected Row Count. Then click the Estimated Table Size
button. This will show you the estimated table size.
You can access the Undo Advisor through the Database Control, as follows:
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:55 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
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 of
undo segments to bring online when you start the instance. Oracle uses the same
AWR data to decide on the number of undo segments to bring online when you
switch undo tablespaces. In both cases, the ramp-up time for the database to bring
undo segments online is much lower than in previous versions.
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 online
redo log files you can use. This advisor recommends that you size your redo log files
to at least the recommended minimum size. A new column in the V$INSTANCE_
RECOVERY view, OPTIMAL_LOGFILE_SIZE, shows you the optimal size of the
redo log file for your FAST_START_MTTR_TARGET setting.
You can access the Redo Logfile Size Advisor through the Database Control,
as follows:
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:55 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Tablespace Enhancements 13
3. Select any redo log group, and then choose the Sizing Advice option from
the Action drop-down list.
4. Click Go to get the redo log file size advice.
Tablespace Enhancements
Oracle Database 10g includes several interesting enhancements pertaining to tablespaces.
These enhancements involve the management the SYSAUX tablespace, default
permanent tablespaces, temporary tablespace groups, and bigfile tablespaces. Let’s start
our discussion with the management of the new SYSAUX tablespace.
■ You have fewer tablespaces to manage, because you don’t need to create
a separate tablespace for many database components. You just assign the
SYSAUX tablespace as the default location for all the components.
■ There is reduced pressure on the SYSTEM tablespace, which is used as
the default tablespace for several features.
■ If you are using Real Application Clusters (RAC) with raw devices, you’ll
have fewer raw devices to manage, since every tablespace under RAC requires
at least one raw device.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:55 AM
Color profile: Generic CMYK printer profile
Composite Default screen 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 components
that you’ll store in it. Therefore, you should base your SYSAUX tablespace sizing
on the components and features that your database will use. Oracle recommends
that you create the SYSAUX tablespace with a minimum size of 240MB.
You can set only the datafile location when you create the SYSAUX tablespace
during database creation, as shown in the preceding example. Oracle sets all the
What happens if you omit Files (OMF), the datafile location will
the SYSAUX creation clause from the be dependent on the OMF initialization
CREATE DATABASE statement? Oracle parameters. If you include the DATAFILE
will create the SYSAUX tablespace anyway. clause for the SYSTEM tablespace, you
Oracle will create both the SYSTEM and must use the DATAFILE clause for the
SYSAUX tablespaces automatically, with SYSAUX tablespace as well, unless you
their datafiles in system-determined default are using OMF.
locations. If you are using Oracle Managed
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:55 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Tablespace Enhancements 15
other attributes, which are mandatory. You cannot later change the location or other
attributes with the ALTER TABLESPACE command.
Oracle requires that the SYSAUX tablespace have the following attributes:
■ Permanent
■ Read/write
■ Locally managed
■ Automatic segment space management
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:55 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
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 SYSAUX
tablespace’s space each of its occupants is currently using. The MOVE_PROCEDURE
column 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 can move occupants You must first find out which procedure you must
into and out of the SYSAUX tablespace. In use to move this occupant, since each of the
order to perform the move operation, you occupants of the SYSAUX tablespace may need
must have the SYSDBA privilege and ensure a separate procedure to allow this.
that tablespace is online. For each user of Here’s a simple query that demonstrates how
the SYSAUX tablespace, there is a specific to find out which procedure to employ for moving
move procedure to effect the move. an 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>
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:56 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Tablespace Enhancements 17
Once you find out the name of the correct procedure to employ in order to
move a SYSAUX occupant, you can perform the move itself, using the appropriate
procedure. For example, you can move the
occupant named WM in the following manner:
SQL> exec dbms_wm.move_proc('DRSYS')
You can’t relocate the
following occcupants of the SYSAUX This preceding MOVE statement will move
tablespace: STREAMS, STATSPACK, JOB_ the user WM from the SYSAUX tablespace
SCHEDULER, ORDIM, ORDIM/PLUGINS, to the DRSYS tablespace.
ORDIM/SQLMM, and SMC.
Renaming Tablespaces
In previous versions of Oracle, a major limitation concerning tablespaces was that you
couldn’t rename a tablespace once you created it. In Oracle Database 10g, you can rename
tablespaces easily by using a simple command (from users to users_new in this example):
SQL> alter tablespace users rename TO users_new;
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:56 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
For an undo tablespace, the name change has different implications, based on
whether you used the init.ora file or the SPFILE to start the instance. If you are
using the init.ora file, Oracle writes a message stating that you should change the
value (location) of the UNDO_TABLESPACE parameter in the init.ora file. If you
used the SPFILE to start the instance, Oracle will automatically write the new name
for the undo tablespace in your SPFILE, provided you specified the tablespace name
as the undo tablespace name in your SPFILE.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:56 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Tablespace Enhancements 19
The DEFAULT TABLESPACE clause isn’t mandatory. If you don’t use one, Oracle
will still create the database, with the SYSTEM tablespace set as the default tablespace,
as in previous versions. However, Oracle recommends that you specify the DEFAULT
TABLESPACE clause explicitly, so your users aren’t forced to use the SYSTEM
tablespace as their default tablespace.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:56 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
When you designate a default tablespace in this manner, all current users will
be assigned to the new default permanent tablespace. New users are automatically
allotted this tablespace as their default permanent tablespace as well.
■ SQL queries are less likely to run out of sort space, because the query can
now use several temporary tablespaces for sorting.
■ You can now specify multiple default temporary tablespaces at the database
level.
■ Parallel execution servers in a parallel operation will efficiently utilize
multiple temporary tablespaces.
■ A single user can simultaneously use multiple temporary tablespaces in
different 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 first
temporary tablespace to a tablespace group, you automatically create the temporary
tablespace group.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:56 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Tablespace Enhancements 21
The preceding SQL statement will create a new temporary tablespace, temp_now,
along with the new tablespace group named group1. Oracle creates the new tablespace
group 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 TABLESPACE
GROUP clause in an ALTER TABLESPACE command, as shown here:
SQL> alter tablespace temp_old
2 tablespace group group1;
Tablespace altered.
SQL>
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:56 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
In the preceding statement, since there wasn’t a prior temporary tablespace group
named group1, Oracle will create a new group with that name.
The preceding statement creates a temporary tablespace called temp_new, which is like the
traditional temporary tablespaces and doesn’t belong to a temporary tablespace group.
Use the TEMPFILE clause, not the DATAFILE clause, when you allocate
space to a temporary tablespace.
If you completely omit the TABLESPACE GROUP clause, you’ll create just a regular
temporary tablespace, which is not part of any temporary tablespace group, as shown in
the following example.
SQL> create temporary tablespace temp_new2
2 tempfile 'c:\oracle\tmp3.f' size 5M;
Tablespace created.
SQL>
Adding a Tablespace to
Temporary Tablespace Group
You add a temporary tablespace to group by using
If you specify the NULL
the ALTER TABLESPACE statement. You can
tablespace group (for example, CREATE
also change the group a temporary tablespace
TEMPORARY TABLESPACE GROUP …
belongs to in the same way. For example, you
GROUP ''), it is equivalent to the normal
can specify that your new tablespace temp_new
temporary tablespace creation statement
belong to the group named group1 by issuing the
(without any groups).
following command:
SQL> alter tablespace temp_new tablespace group group1;
Note that the database would create a new group with the name group1 if that
group did not already exist.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:57 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Tablespace Enhancements 23
This assigns all the tablespaces in group1 as the default temporary tablespaces for the
database.
Once you create a user, you can also use the ALTER USER statement to change
the temporary tablespace group of the user. Here’s the SQL statement to do this:
SQL> alter user sam temporary tablespace group2;
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:57 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
You can also use the DBA_USERS view to find out which temporary tablespaces
or temporary tablespace groups are assigned to each user. Here’s an example:
SQL> select username, temporary_tablespace from dba_users;
USERNAME TEMPORARY_TABLESPACE
------------------------------ -----------------------------
SYS TEMP
SYSTEM TEMP
SAM GROUP1
SCOTT TEMP
. . .
SQL>
Bigfile Tablespaces
Oracle Database 10g can contain up to 8 exabytes (8 million terabytes) of data. Don’t
panic, however, thinking how many milions of datafiles you need to manage in order
to hold this much data. You now have the option of creating really big tablespaces,
called, appropriately, bigfile tablespaces. A bigfile tablespace (BFT) contains only one
very large file. Depending on the block size, a bigfile tablespace can be as large as 128
terabytes.
In previous versions, you always had to juggle with the distinction between datafiles
and tablespaces. Now, using the bigfile concept, Oracle has made a tablespace logically
equal to a datafile, by creating the new one-to-one relationship between tablespaces
and datafiles. With Oracle Managed Files, datafiles are completely transparent to
you when you use a bigfile tablespace, and you can directly deal with the tablespace
itself in many kinds of operations.
Here’s a summary of the many benefits
offered by using bigfile tablespaces:
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:57 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Tablespace Enhancements 25
■ The database has a significant increase in storage capacity, because you don’t
reach the maximum files limitation quickly when you use bigfile tablespaces.
■ You can set the CREATE DATABASE clause MAXDATAFILES to a lower
size, and thus reduce the size of the control file. The MAXDATAFILES
parameter specifies the control file’s initial space allocation to datafile
information.
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
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:57 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
that shows how to set the default tablespace type in your database to bigfile from
now on:
SQL> alter database set default bigfile tablespace;
Once you set the default type of your tablespace, all the tablespaces you subsequently
create will be of the bigfile type, unless you manually override the default setting, as
shown in the next section.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:57 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Tablespace Enhancements 27
The AUTOEXTEND clause enables automatic file extension, again without referring
to 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 tablespace
level, not the file level. Thus, both of these clauses provide datafile transparency—you
deal directly with the tablespaces and ignore the underlying datafiles.
■ DBA_TABLESPACES
■ USER_TABLESPACES
■ V$TABLESPACE
All three views have the new column BIGFILE, whose value indicates whether
a tablespace is of the bigfile type (YES) or smallfile type (NO).
You can also use the following query to determine the default tablespace type for
your database:
SQL> select property_value
2 from database_properties
3* where property_name='DEFAULT_TBS_TYPE';
PROPERTY_VALUE
--------------
SMALLFILE
SQL>
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:57 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
The following query helps in finding out which of your tablespaces have bigfile
tablespaces:
SQL> select tablespace_name, bigfile FROM dba_tablespaces;
TABLESPACE_NAME BIG
----------------- --------
SYSTEM NO
RBS NO
USERS NO
TEMP NO
TOOLS NO
INDX NO
DRSYS NO
SYSAUX NO
BIG_TBS YES
9 rows selected.
SQL>
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:57 AM
Color profile: Generic CMYK printer profile
Composite Default screen 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 bigfile
tablespace, 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, the
database 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 new
input parameter TS_TYPE_IN, which informs Oracle whether the tablespace type
is bigfile or smallfile. The TS_TYPE_IN parameter can take the values BIGFILE
or SMALLFILE. It is a part of the DBMS_ROWID procedures ROWID_INFO, ROWID_
BLOCK_NUMBER, and ROWID_RELATIVE_FNO.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:57 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Oracle stores all rows for each department from both the employees and departments
tables in the same physical location (same data blocks). A cluster key value is the
value of the cluster key columns for a particular row. In our example, department_id
is your cluster key. Since you store related rows physically together, your disk I/O will
be less and disk-access times will be faster. You might gain substantially by clustering
tables that you frequently join in many of your queries.
A hash cluster groups data according to a hash function it applies to the cluster
key value of each row. Oracle then stores all rows with identical cluster key values
together on disk. Hash clusters are recommended when you frequently use equality
queries (for example, return all rows for dept_id=20). Oracle hashes the cluster key
value, and the hashed key value will point directly to the area on disk where the
rows are stored.
In a sorted hash cluster, rows corresponding to
individual values of the hash function are sorted
on specific columns. The rows are organized as
The selection of the order lists of sorted rows, with each list corresponding
key column for a sorted hash cluster to a separate value of the hash key column. Each
is important, since you would need list will then have its rows sorted in the order
additional sorting when you use an specified by the sort key columns. In other words,
ORDER BY clause on a suffix of the the table’s rows are already presorted by the sort
sort key columns. The same is true key column.
when you use nonsorted key columns. Here are some of the main features of sorted
hash clusters:
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:57 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
In the call_cluster cluster, the cluster key is call_number, and the combination of
call_time and call_duration is the sort key. SIZE indicates the space in bytes that is
necessary to store the cluster key metadata.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:58 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
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 column
representing the originating telephone number. The calls from each originating
number are processed during the preparation of customer bills. The idea is that by
storing 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_timestamp
and 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 sorted
hash cluster segment. This provides the sorted list of rows for that particular hash
key column.
Both the source and destination files should be of the same type, either
operating system files or ASM files.
■ The maximum file size is 2 terabytes, and the file must be in multiples of 512
bytes.
■ You can’t perform any character set conversion during the copy process.
■ All nonprivileged users of the database must have explicit privileges before
they can access a file created by using DBMS_FILE_TRANSFER.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:58 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Let’s see how you can use the DBMS_FILE_TRANSFER package to perform
various types of file-copy procedures.
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’s
the code:
begin
dbms_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 the
source directory and the WRITE privilege on the destination directory in
order to execute the DBMS_TRANSFER.COPY_FILE procedure.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:58 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
CERTIFICATION SUMMARY
This 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 as
well as perform other useful tasks. You also quickly reviewed the two space-related
advisors: 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 SYSAUX
tablespace, 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 when
you 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 you
to copy files directly through the database server.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:58 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
The certification exam asks you several questions temporary tablespace groups, as well as assign
about the new tablespace enhancements in and deassign temporary tablespaces to temporary
Oracle Database 10g. Expect at least one tablespace groups. Expect a question on the
question on the new SYSAUX tablespace, new bigfile tablespace type. Specifically, you
probably about the process of relocating must be aware of what the Oracle Database
occupants in and out of that tablespace. 10g default tablespace type is and how to
What are the special features (restrictions) change it.
of a SYSAUX tablespace, compared with a You must remember that you can now create
normal tablespace (you can’t rename, drop, a default permanent tablespace in Oracle
or transport a SYSAUX tablespace). Database 10g. The test may examine your
You must understand how to use the advisor understanding of the DEFAULT TABLESPACE
that will help you perform segment shrinking command to create a permanent default
(the Segment Advisor). You must also know tablespace during database creation. How do you
the prerequisites for a segment-shrinking alter the current default permanent tablespace?
operation. Of course, you are going to see a What is the default permanent tablespace when
question or two testing your knowledge of you create a new database using the Database
the difference between the SHRINK SPACE Configuration Assistant (DBCA)?
command with and without the COMPACT The tablespace renaming feature is new
option. When does Oracle compact space, and in Oracle Database 10g, and the exam may
when does it adjust the high-water mark and test your understanding of when you can and
release space held by a compacted object? cannot rename tablespaces. What are the best
The test focuses on the new temporary practices for tablespace renaming?
tablespace group concept. The test expects you You must also understand how to use the
to know the properties of temporary tablespace Redo Logfile Size Advisor to configure optimal
groups. You must also know how to create online redo log file sizes.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:58 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
✓ 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 manage
database thresholds.
❑ You can set alert thresholds for only locally managed tablespaces.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:58 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Two-Minute Drill 37
❑ You can run the Segment Advisor in the comprehensive or limited mode.
❑ To estimate future space needs, the Segment Advisor uses the growth trend
reports.
Tablespace Enhancements
❑ The SYSAUX tablespace is auxiliary to the SYSTEM tablespace and holds
data 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 tablespace
and makes it easier to manage the various database components.
❑ A SYSAUX tablespace must be read/write, permanent, locally managed, and
use ASSM.
❑ You can’t drop or rename the SYSAUX tablespace during normal tablespace
operations.
❑ You must use a specific “move procedure” to move an occupant of the SYSAUX
tablespace 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.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:58 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:58 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Two-Minute Drill 39
❑ Before you can create the tables that are part of a cluster, you must create the
cluster itself.
❑ If you want to retrieve data in ascending order, the ORDER BY clause isn’t
mandatory.
❑ Oracle recommends inserting hash cluster table data in the sort key column
order.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:59 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
SELF TEST
The following questions will help you measure your understanding of the material presented in this
chapter. Read all the choices carefully, because there might be more than one correct answer. Choose
all correct answers for each question.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:59 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Self Test 41
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.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:59 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:59 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Lab Questions 43
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.
LAB QUESTIONS
1. 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 default
database values?
5. How do you check the status of your threshold?
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:59 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:59 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
9. þ D. Optimally sized redo log files should be the smallest consistent with keeping the
checkpointing 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 to
specify it. The same is true of the SYSTEM tablespace.
ý A is wrong since database creation will succeed even when you don’t specify a SYSTEM
or 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 in
lieu of the SYSAUX tablespace. D is wrong since you can’t create the SYSAUX tablespace
after database creation—the SYSAUX tablespace is always created at database creation.
11. þ B. When you rename a default permanent tablespace, nothing really changes—the old
default permanent tablespace continues to be the default permanent tablespace, with a new
name.
ý A is wrong since you don’t need to create a new default permanent tablespace for the
users. C is wrong since the users continue to be assigned to the same permanent tablespace
throughout. 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 new
default 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 an
alternative default permanent tablespace for all the users.
13. þ C. It doesn’t matter what type of tablespace you create the database with. You can always
change 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 clause
and 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 use
AUTOALLOCATE. D specifies the correct option, UNIFORM, but turns out to be the wrong
answer, since it states that you should let Oracle choose the extent sizes.
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:44:59 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
LAB ANSWERS
1. On the USERS tablespace, use the following to set a warning threshold of 80 percent and
a critical threshold of 95 percent:
SQL> begin
dbms_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.vp
Friday, September 03, 2004 10:45:00 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 6
Lab Answers 47
2. Check the database-wide threshold values for the USERS tablespace as follows:
SQL> select warning_value, critical_value
from dba_thresholds
whre metrics_name = 'Tablespace Space Usage' AND
object_name = 'USERS'
/
3. Turn off the space-usage tracking for the USER tablespace as follows:
SQL> begin
dbms_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 database
values as follows:
SQL> begin
dbms_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;
P:\010Comp\CertPrs8\862-4\ch06.vp
Friday, September 03, 2004 10:45:00 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Blind Folio 7:1
7
The Oracle
Scheduler and
the Database
Resource Manager
CERTIFICATION OBJECTIVES
7.01 Simplifying Management Tasks Using 7.04 Viewing Information About the Scheduler
the Scheduler
7.05 Database Resource Manager
7.02 Managing the Basic Scheduler Enhancements
Components
✓ Two-Minute Drill
7.03 Managing Advanced Scheduler
Components
Q&A Self Test
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:34 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
O racle DBAs and developers frequently use the DBMS_JOB package to schedule
database jobs. The package is a commonly used scheduling utility that has been
around 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 the
Scheduler. In this chapter, you’ll learn first about the Scheduler framework and then how to
manage this brand-new Oracle 10g feature.
In the latter part of this chapter, you’ll learn about the Oracle Database 10g
enhancements to the Database Resource Manager. These include using the Resource
Manager to impose idle session limits, returning sessions automatically to their initial
consumer groups after their top call is over, creating mapping between sessions and
resource consumer groups, and using new methods of CPU allocation among resource
plans and resource groups.
Let’s start with an introduction to the new Scheduler and see how you can simplify
management tasks by using it.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:34 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Jobs
A job is a task that you schedule to run one or more times. A job contains information
about what it should execute and time of execution. A Scheduler job can execute a
PL/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 job
should execute and the time and frequency of the execution, or you can simply use
saved 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 one
job table for each database. When you execute a job, the database makes an entry in
the job log.
Schedules
A schedule is a specification of when and how frequently the database should execute a
job. The important thing to note here is that you can use the same schedule for several
jobs. Schedules are like any other database entities, and you store them just as you do
the other objects. Users can share schedules.
The schedule and program components of the Scheduler are purely optional.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:34 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Programs
A program contains information about the code, script, or executable that’s to be
executed as part of a job. The information contains a program name, the program
action (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 later
sections of this chapter.
Job Classes
A job class groups similar jobs into one large entity. The jobs that are part of a job class
share common characteristics like resource requirements. By helping you to classify
several jobs into related groups on the lines of functionality or shared attributes, job
classes facilitate the calibration of limited resources among different groups of jobs in
your database.
Job classes group jobs with common characteristics. The main purpose of
using a job class is to manage resource allocation among jobs. A job can
belong to only one job class.
■ Assign the job priority level for an individual job, with the priority values ranging
from 1 to 5. A higher-priority job always starts before a lower-priority job.
■ Specify common attributes such as the frequency of log purging.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:34 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Windows
A window represents an interval of time during which you can schedule jobs. The purpose
behind 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 window
is associated with a specific resource plan (created with the help of the Database Resource
Manager). By using a window in which to schedule a job, you ensure that the job will
only run during a certain time interval, when a certain resource plan associated with
that window is active. The concept of resource plan–based windows enables you to
ensure optimal use of your scarce resources.
Windows can overlap, and when they do, Oracle chooses the window with
the higher priority. The window with the higher priority opens, and the other
window will close.
Window Groups
Window groups are simply a collection of similar windows. Once you create a window
group, 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 can
then group both these windows into a single maintenance window, if you wish. The
key 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.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:34 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Scheduler Architecture
The Scheduler architecture consists primarily of the job table, job coordinator, and the
job workers (or slaves). Let’s look at each of these components in the following sections.
■ Update the job table, to indicate that the job has been completed
■ Update the job log table
■ Update the run count
Scheduler Privileges
Jobs, schedules, and programs are like any other database object when it comes to
ownership and privileges. Oracle creates all jobs, programs, and schedules in the current
user’s schema. However, Oracle creates all the advanced Scheduler components, like
job classes, windows, and window groups, at the database level, not the schema level,
and their owner is the SYS schema.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:35 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
■ Create, drop, and alter job classes, windows, and window groups. (You still
can’t create a job in a job class you create, unless you have a separate EXECUTE
privilege on that job class.)
■ Stop any job.
■ Start and stop windows prematurely.
By default, all Scheduler objects are in uppercase, unless you wrap the lowercase
names in double quotes, as in “test_job”.
You must have the CREATE JOB privilege to create the basic job, schedule, and
program components. In order to use the advanced Scheduler components like
windows, window groups, and job classes, you need the MANAGE SCHEDULER
system privilege.
Once you create a job or some other Scheduler component, it will be a part of
your own schema. You can assign other users the right to use one of your components
like a job, schedule, or program by giving them EXECUTE privileges on that
component. For example, you can grant the EXECUTE privileges for a certain
program or for a certain job class. Note that
■ The EXECUTE ANY PROGRAM privilege lets a user execute any program
under 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 the
following 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, job
classes, and windows. Once you have the CREATE JOB privilege, you can start
creating 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 any
privileges to specify the program.
■ If you specify a program owned by a different user, you must have the EXECUTE
privilege on that program, or the EXECUTE ANY PROGRAM system privilege.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:35 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
■ You can specify a schedule, whether owned by you or a different user, without
any 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 fully
qualify these components when you use them in your CREATE JOB or any
other statement.
■ If you wish to assign your new job to a job class, you must either have the
EXECUTE privilege on that class, or the more powerful EXECUTE ANY
CLASS system privilege.
All Scheduler objects are of the form [schema].name. All Scheduler names are
in uppercase, unless you surround them with double quotes.
Managing Jobs
Creating and managing jobs, of course, is at the heart of the Scheduler facility. As you’ll
learn, you can create and run jobs independently, or you can create a job using schedules
and programs. Use of saved programs and schedules enables you to eliminate the
redefinition of the program or schedule each time you create a new job. This reusability
of the Scheduler components is a highly useful feature, since users can customize schedules
and programs to meet their needs. Let’s start with the creation of Scheduler jobs.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:35 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Creating Jobs
You create a job using the CREATE_JOB procedure
of the DBMS_SCHEDULER package. You can
The parameter values you specify all the job execution details directly using
specify when you create a job will override the CREATE_JOB procedure. Programs and
the default values for the saved programs schedules, as you’ve seen earlier, are saved database
and schedules. objects that contain information pertaining to
jobs, 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 to
manage. Here’s a simple example that shows how to create a basic Scheduler job. Note
that there aren’t any programs or schedules in this job—this is the most straightforward
way to specify a job, with all pertinent information specified in the job creation statement
itself. More sophisticated examples later on show you how to embed most of the repetitive
information within saved schedules and windows.
SQL> begin
2 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 jobs
are disabled when they are created. You need to enable a job in order to use it.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:35 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
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.
start_date and end_date These parameters specify the date that a new job
should start and end. (Many jobs may not have an end_date parameter, since
they are ongoing jobs.)
repeat_interval This attribute tells the Scheduler how often it should execute
the 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 interval
in one of two ways:
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 system
scripts and executables in addition to PL/SQL code. Here’s an example that shows
how you can schedule a job on your server. The job runs the check_freespace.ksh
UNIX script every half an hour.
begin
dbms_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;
/
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:35 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
In the preceding set of examples, the BY* clause is the optional specifier
component, which provides additional information that the frequent and
repeat interval components can’t provide.
■ Using a PL/SQL expression You can also create more complex repeat
intervals than what the calendaring expressions enable you to do by using
PL/SQL expressions, with the proviso that all such expressions must evaluate
to a date or a timestamp datatype. When you use a date/time expression for
specifying the repeat interval, you end up with a date/time datatype as the
value of the interval. Look at the following example:
repeat_interval => 'SYSTIMESTAMP + INTERVAL '10' MINUTE'
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:35 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Administering Jobs
You can use the DBMS_SCHEDULER package to perform all the administrative tasks
associated with jobs. Let’s look at some of the main job-related administrative tasks in
the following sections.
Enabling and Disabling Jobs All jobs are disabled by default when you create
them. You must explicitly enable them in order to activate and schedule them. You
can enable a job by issuing the following command:
SQL> exec dbms_scheduler.enable ('TEST_JOB1');
PL/SQL procedure successfully completed.
Dropping a Job You can drop a job by using the DROP_JOB procedure,
as shown here:
begin
dbms_scheduler.drop_job (
job_name => 'test_job1');
end;
/
Running and Stopping a Job You can run a job manually (at other than the
regularly 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, it
runs in your own session, and the job coordinator and the job slave don’t enter the
picture.
You can stop a job immediately by using the STOP_JOB procedure, as shown here:
SQL> exec dbms_scheduler.stop_job('TEST_JOB1');
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:35 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
EXERCISE 7-1
Managing Programs
A program contains metadata, including the name and type of the program, and what
a job will execute, whether it is a PL/SQL procedure, a script, or an executable. When
you use programs, you can alter the job task, or what the job will actually do, without
directly 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 library
of programs, thus helping you avoid having to specify all the details of a program in
your job creation statement.
Let’s start by looking at how you can create programs. Later you’ll learn about
program-related administrative tasks.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Creating a Program
To create a new Scheduler program, use the CREATE_PROGRAM procedure of the
DBMS_SCHEDULER package, as shown here:
SQL> begin
2 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>
The program component has all the job details. Once you create a program in the
manner 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 name
of the program (TEST_PROGRAM) that already contains the specification of these
attributes. The program_type and program_action will provide the information
that the three job attributes provided in your first job creation statement. You can
begin to see why this type of a modular approach is beneficial—different jobs can
use 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> begin
2 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 avoid
specifying the job_type and job_action parameters in the CREATE_JOB
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
statement. You thus have a choice between specifying all job attributes directly in
the CREATE_JOB statement itself, or using a stored program to supply some of the
job attributes.
Administering Programs
You can enable, disable, drop, and modify Scheduler programs using various procedures
from the DBMS_SCHEDULER package.
Enabling and Disabling Programs You can enable a program in the following
manner, 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 Schedules
Let’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 you
need to modify some aspect of the schedule, all the jobs that use the schedule can
automatically inherit those changes. Let’s start by looking at how you create a schedule.
Creating a Schedule
You use the CREATE_SCHEDULE procedure of the DBMS_SCHEDULER package to
create a schedule, as shown here:
SQL> begin
2 dbms_scheduler.create_schedule(
3 schedule_name => 'TEST_SCHEDULE',
4 start_date => SYSTIMESTAMP,
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
The TEST_SCHEDULE schedule states that a job with this schedule will be
executed immediately and then be reexecuted every 12 hours, for a period of 30
days. Note the following things about the creation of the TEST_SCHEDULE
schedule:
Once you create the schedule TEST_SCHEDULE, you can simplify the job creation
process even further. Now you can use both TEST_PROGRAM and TEST_SCHEDULE
to simplify job creation, as shown here:
SQL> begin
2 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 both
a saved program as well as a saved schedule. The use of the saved schedule means
that you don’t have to specify the start_date, end_date, and the repeat_
interval attributes while creating TEST_JOB02, since TEST_SCHEDULE
already has all that information.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Administering Schedules
A schedule states when and how often a job should be run. You can save a schedule
as a database object and share it with other users. Let’s look at some of the basic
administrative tasks concerning schedules.
EXERCISE 7-2
Creating a Schedule
Create a simple schedule on the lines of the following example. In the example, the
repeat_interval attribute specifies that a job will execute every five minutes.
SQL> begin
dbms_scheduler.create_schedule (
scheduler_name => 'TEST_SCHEDULE',
start_date => SYSTIMESTAMP,
repeat_interval => 'FREQ=MINUTELY;INTERVAL=5',
comments => 'A test schedule.');
end;
/
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
if you have any jobs or windows that use the schedule you want to drop, your
procedure will fail, as shown here:
SQL> begin
2 dbms_scheduler.drop_schedule(schedule_name => 'TEST_SCHEDULE');
3 end;
4 /
begin
ERROR at line 1:
ORA-27479: Cannot drop "SAM.TEST_SCHEDULE" because other objects depend on it
ORA-06512: at "SYS.DBMS_ISCHED", line 615
ORA-06512: at "SYS.DBMS_SCHEDULER", line 1070
ORA-06512: at line 2
SQL>
When you drop a schedule by using the FORCE=TRUE attribute, you’ll drop the
schedule, even if there are jobs and windows that use the schedule. The Scheduler
first disables the dependent jobs/windows before dropping the schedule itself.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 of
the resources. Prioritizing jobs to ensure that they are guaranteed adequate resources to
perform along accepted lines is an essential requirement in production databases. The
Scheduler uses the concepts of job classes and windows to prioritize jobs.
Job Classes
You 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 allocate
resources when you run a job as an entity by itself. Job classes group all jobs with similar
characteristics and common resource requirements together. Using job classes helps
you prioritize jobs by allocating resources differently among the various jobs.
The Scheduler associates each job class with a resource consumer group, which lets
the Scheduler group jobs according to common resource requirements. Depending
on the resource consumer group a job class belongs to, the Scheduler will determine
the appropriate resource allocation. This ability to associate job classes with resource
consumer groups provides an efficient way to prioritize jobs in the database.
You use the CREATE_JOB_CLASS procedure of the DBMS_SCHEDULER to create
a job class. Unlike a job, a job class can’t be created in a user’s schema—no matter
who creates it, all job classes are created in the SYS schema. You can create a job
class only if you have the MANAGE SCHEDULER privilege.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
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 the
database will retain the logs before purging them. Oracle will automatically
create a daily job called the PURGE_LOG, which cleans the log entries. The
following query shows that this job exists:
SQL> select job_name
2 from dba_Scheduler_jobs;
JOB_NAME
------------------------------
GATHER_STATS_JOB
PURGE_LOG
…
SQL>
If you want to clear the logs manually, you can do so by using the DBMS_
SCHEDULER.PURGE_LOG procedure.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 in
the SYS schema, and the same is true of any other job class that you might create
in the database. Any user in the database can create a job in the ADMIN_JOBS job
class, provided they have the EXECUTE privilege on that specific job class, or they
have the EXECUTE ANY JOB CLASS privilege.
You can’t change any attributes of the default job class, which is named, well,
the DEFAULT_JOB_CLASS.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
If you want to drop a job and moved to the default job class in your
class with jobs in it, you must specify the database. If the job is already running when
FORCE=TRUE option in your DROP_JOB_ you drop its job class, the job will run to
CLASS procedure. When you do this, the completion anyway.
jobs in the dropped job class are disabled
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:36 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Resource Plan How you allocate resources among the various resource consumer
groups is your resource plan. For example, a resource plan may allocate 50 percent
of the CPU resources to the Finance Group, 30 percent to the Sales Group, and
20 percent to the Administration Group of users.
Resource Plan Directive You can assign a resource consumer group to a resource
plan, thus deciding what resources each resource consumer group gets. Plan directives
also enable you to specify the parameters for each resource allocation method. For
example, you may limit the degree of parallelism of all users in the Administrative
Group to 2, instead of using the default value, which is an unlimited number of
parallel sessions.
With this brief review of the Database Resource Manager behind us, let’s move on
to see how you can use the concept of a time window to activate different resource
plans at different times.
The basic purpose of a window is to switch the active resource plan during a
certain time frame. All jobs that run during this window will be controlled by
the resource plan that’s in effect during that window. Without windows, you’ll
have to manually switch the resource manager plans.
A window is an interval with a specific begin and end time, for example, “from 12
midnight to 6:00 A.M.” However, a window is not merely a chronological device like
a schedule, specifying when a job will run; every window is associated with a resource
plan. When you create a window, you specify a resource plan as a parameter. This
ability to activate different resource plans at different times is what makes a window
a special scheduling device that enables you to set priorities.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
All windows, like job classes, ■ Schedules, which are the times when the
are created in the SYS schema, no matter window is in effect
which user creates them. To create a ■ Duration, which determines the length
window, you must have the MANAGE of time a window stays open
SCHEDULER system privilege. ■ Resource plan, which determines the resource
priorities among the job classes
Note that schedules and duration are part of all Scheduler schedules; the resource
plan sets a Scheduler window apart from a simple schedule. Each time a window is
open, a specific active resource plan is associated with it. Thus, the same job will be
allocated different resources if it runs under different windows.
You can specify what resources you want to allocate to various job classes during
a certain time period (say midnight to 6:00 A.M.) by associating a resource plan
with the window you create for this period. When the window opens, the database
automatically switches to the associated resource plan, which becomes the active
resource plan. The systemwide resource plan associated with the window will control
the resource allocation for all jobs and sessions that are scheduled to run within this
window.When the window finishes, there will be another switch to the orginal resource
plan 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’t
be able to switch the resource plans. In this case, the window will continue to open
as scheduled and run the jobs that have been assigned for that window. Thus, the
window in this case serves only as a basic schedule component.
You can see which window is currently active and the resource plan associated with
that window by using the following query:
SQL select window_name, resource_plan from dba_scheduler_windows
where active='TRUE';
WINDOW_NAME RESOURCE_PLAN
------------------------------ --------------------------
TEST_WINDOW TEST_RESOURCEPLAN
SQL>
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Creating a Window
You create a window by using the CREATE_WINDOW procedure. Let’s look at two
examples using this procedure, one with an inline specification of the start and end
times and the repeat interval, and the other where you use a saved schedule instead
to provide these three scheduling attributes. In the first example, the window creation
statement specifies the schedule for the window.
begin
dbms_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;
/
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Since the Scheduler doesn’t check to make sure that there are prior windows
for any given schedule, you have the possibility of overlapping windows. Note
that Oracle doesn’t recommend overlapping windows.
In the second example, shown here, you see how you can create a window using
a saved schedule. Obviously, it is much simpler to create a window this way.
begin
dbms_scheduler.create_window (
window_name => 'TEST_WINDOW',
schedule_name => 'TEST_SCHEDULE',
resource_plan => 'TEST_RESOURCEPLAN',
duration => interval '160' minute,
comments => 'Test Window');
end;
/
Once you create a window, you must associate it with a job or job class, so the
jobs can take advantage of the automatic switching of the active resource plans.
Managing Windows
You can open, close, alter, enable/disable, or drop a window using the appropriate
procedure of the DBMS_SCHEDULER package. You need the MANAGE SCHEDULER
privilege to perform any of these tasks. Note that since all windows are created in the
SYS schema, you must always use the [SYS].window_name syntax when you reference
any window.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Look at the duration attribute in the preceding statement. When you specify
the duration, you can specify days, hours, minutes, seconds, in that order. Thus, the
setting means 0 days, 12 hours, 0 minutes, and 0 seconds.
Note that you can open an already open window. If you do this, the duration of
the window will last a time period equal to its duration attribute. That is, if you
open a window that has been running for 30 minutes and its duration is 60 minutes, your
window will last a total of the initial 30 minutes plus an additional 60 minutes, for a
total of 90 minutes.
You must have the MANAGE SCHEDULER system privilege in order to open,
close, disable, or drop a window.
If a job is running when you close a window, the job will continue to run to its
completion. However, a running job may close upon the closing of its window if
you 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 the
SET_ATTRIBUTES procedure.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
You can only disable a window if no job uses that window or if the window isn’t
open. If the window is open, you can disable it by using the DISABLE program with
the FORCE=TRUE attribute.
Prioritizing Jobs
As you are aware, all database jobs are collected into job classes. You then map each
job class to a specific resource consumer group. A resource plan is assigned to a resource
consumer group and thus indirectly to each job class as well, by the Database Resource
Manager. The active resource plan (as determined by the currently open window) will
apportion 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 resource
allocation to the jobs. The Scheduler will start a job only if there are enough resources
to run.
To see which resource consumer group a session belongs to, you can use the
following query:
SQL> select sid, serial#,username,resource_consumer_group from v$session;
Within each Scheduler window, you can have several jobs running, with varying
degrees of priority. You can prioritize jobs at two levels—class and job. The prioritization
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
at the class level is based on the resources allocated to each resource consumer group
by the currently active resource plan. For example, the FINANCE_JOBS class might
rank higher than the ADMIN_JOBS class, based on the resource allocations dictated
by its active resource plan.
Within the FINANCE_JOBS and ADMIN_JOBS classes, there will be several
individual 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 procedure
to change the job priority of any job, as shown here:
begin
dbms_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 3
ADV_SQLACCESS5858921 3
GATHER_STATS_JOB 3
PURGE_LOG 3
TEST_JOB03 3
TEST_JOB1 3
6 rows selected.
SQL>
When you have more than one job within the same class scheduled for the same
time, the job_priority of the individual jobs determines which job starts first.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Window Priorities
Since windows might have overlapping schedules, you may frequently have more than
one 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 the
window 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 for
the same time period, the window that has the highest percentage of time
remaining will open.
Window Groups
A window group is a collection of windows, and is part of the SYS schema. Window
groups are optional entities, and you may make a window a part of a window group
when you create it, or add windows to the group at a later time.You can specify either
a 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 have
similar characteristics—for example, some night windows and a holiday window—
and club them together to create a “downtime window group.” The concept of a
window group is for convenience only, and its use is purely optional.
You can retrieve the attributes of any Scheduler component with the GET_
SCHEDULER_ATTRIBUTE procedure of the DBMS_SCHEDULER package.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
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 turn
on full job logging at the job level:
execute dbms_scheduler.set_attribute ('TESTJOB',
'LOGGING_LEVEL', dbms_Scheduler.LOGGING_FULL);
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:37 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
As a DBA, you can set turn off logging at the job level, yet the
logging at the job class level in order to Scheduler will log the job run information.
audit Scheduler jobs. Once you set the A user, however, can increase the logging
logging at the class level, an individual user level to LOGGING_FULL for a job, thus
can only increase the amount of logging. raising the level of logging from the LOGGING_
For example, if you set LOGGING_RUNS at RUNS level you set to a higher logging level.
the job class level, the creator of a job may
You can modify the retention period (the default is 30days) of the logs for a job
class 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 retention
period to seven days.
In order to clear all window and job logs, use the following command:
execute dbms_scheduler.purge_log();
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
In the preceding example, the maximum time a session can remain idle is capped
at 600 seconds by the MAX_IDLE_TIME attribute. After this time, if a session continues
to sit idle, without executing or waiting for I/O, the PMON process kills the session
and cleans up after it. The MAX_IDLE_BLOCKER_TIME ensures that the PMON
also kills any session that is idle for more than 300 seconds and is blocking another
session. The PMON process grabs the offending sessions during its regular database
checks, which it conducts on a minutely basis.
The ability to switch sessions back to their initial consumer group at the end of
their top call is a huge enhancement because it means that you can now use the
Resource Manager in the web environment, with connection pooling from the
middle tier. Previously, if you downgraded a connection because one web client
issued a horrific statement, it would stay downgraded for any subsequent jobs, even
if they came from other web clients.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Let’s first look at how you can assign consumer groups to sessions.
Session Attributes These are the key elements in the mapping of sessions and
consumer resource groups. As mentioned in the previous section, there are two types
of session attributes—run-time and login. Following are the login attributes:
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
In the previous listing, a user with the operating system name SAM can log in as
the 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’, based
on the CLIENT_OS_USER attribute.
execute dbms_resource_manager.set_consumer_group_mapping -
(DBMS_RESOURCE_MANAGER.CLIENT_OS_USER, 'SAM', 'prod_group');
■ When you first log in, you are mapped to the initial resource group based on
the attribute being mapped.
■ If you change a run-time attribute later, you are switched automatically to a
different consumer group.
■ It is possible to be switched to the same consumer group you are currently in.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
All the priority levels you see in the preceding listing are the default priority
levels of each of the session attributes, which you may change with the SET_
CONSUMER_GROUP_MAPPING procedure.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Usually, you would give batch and large data warehouse-type jobs a low priority
to avoid impacting your OLTP operations. But the RUN_TO_COMPLETION
CPU allocation method accords top priority to large jobs run by a particular
group.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
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 ratio
method. You must also use the CREATE_PLAN_DIRECTIVE procedure and set the
CPU_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);
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:38 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
You must understand that consumer groups. The RATIO and the old
the RUN_TO_COMPLETION and the old EMPHASIS allocation methods, on the other
ROUND_ROBIN allocation methods are hand, are used with the CREATE_PLAN
part of the CREATE_CONSUMER_GROUP procedure and apply to resource plans.
procedure, and they apply to resource
The exam has questions that test your expressions that set repeat intervals like once
familiarity with the logging and purging of a week and every five minutes.
Scheduler jobs. Know the default purging You must know the DBMS_SCHEDULER
procedure for jobs and the various logging package very well. Understand the different
levels. Which logging level gives you the parameters like start_date, end_date,
most information? repeat_interval, and duration. How
You must remember the names and and which Scheduler attributes can you set at
functions of the basic and advanced the global level? The exam will test your
Scheduler components. What is the knowledge of the DBA_SCHEDULER_JOB_
purpose of using advanced components like RUN_DETAILS and DBA_SCHEDULER_
job classes, windows, and window classes? JOB_LOG views.
What privileges do you need to manage each The exam tests your knowledge of the new
of these components? The test will most likely resource allocation methods when you use the
probe your knowledge of job priorities. Know DBMS_RESOURCE_MANAGER package. What
the difference between inter-job class and do the RATIO and the RUN_TO_COMPLETION
intra-job class priorities. When windows resource allocation methods do? Know how to
overlap, how does the Scheduler determine assign priorities using the DBMS_RESOURCE_
window priorities? MANAGER package, and how mappings are
You must know how to set repeat intervals created between session attributes and specific
for jobs. Pay particular attention to calendaring consumer resource groups.
expressions. Practice with calendaring
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
CERTIFICATION SUMMARY
The chapter started with an introduction to the all-new Oracle Scheduler feature.
You learned about the basic building blocks of the Scheduler—jobs, programs, and
schedules. 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 with
resource consumer groups. You also learned how you can control resource allocation
by associating resource plans with Scheduler windows.You learned how to query the
main data dictionary view concerning the Scheduler.
In the last part of this chapter, you learned about the advancements in the Database
Resource 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 automatic
assignment 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.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Two-Minute Drill 43
✓ TWO-MINUTE DRILL
Simplifying Management Tasks by Using the Scheduler
❑ The Scheduler replaces DBMS_JOB as the main scheduling facility in
Oracle Database 10g.
❑ Use the DBMS_SCHEDULER package to manage the Scheduler.
❑ You can schedule PL/SQL programs, Java programs, native binary
executables, 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 the
running 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 MANAGE
SCHEDULER system privilege.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Two-Minute Drill 45
❑ Window priorities are resolved by checking which window has the higher
priority level, or whichever window opened first, if the window priorities are
the same.
❑ You can use the SET_ATTRIBUTE_NULL procedure to set a Scheduler
component’s attributes to NULL.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
SELF TEST
The following questions will help you measure your understanding of the material presented in
this chapter. Read all the choices carefully because there might be more than one correct answer.
Choose all correct answers for each question.
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Self Test 47
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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_LEVEL
parameter. 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 class
she 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 program
B. An interval
C. A resource plan
D. A resource consumer group
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Self Test 49
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:39 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 many
consumer resource groups can a single session map to?
A. Only one consumer resource group
B. At most two resource consumer groups
C. As many resource consumer groups as there are session attributes
D. 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 blocking
other 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.vp
Tuesday, September 07, 2004 4:38:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Lab Answers 53
LAB ANSWERS
Lab 1
To kill idle sessions that go over a set idle time limit, use the DBMS_RESOURCE_MANAGER package
in 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> begin
dbms_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;
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 7
Lab 2
1. Create the program.
SQL> begin
dbms_scheduler.create_program (
program_name => 'DAILY_GATHERING',
program_action => 'DAILY_DATA_GATHERING',
program_type => 'STORED_PROCEDURE',
enabled => 'TRUE');
end;
3. Create the job using the program and schedule you created in the previous two steps.
SQL> begin
dbms_scheduler.create_job (
job_name => 'DAILY_GATHERING_JOB',
program_name => 'DAILY_GATHERING',
schedule_name => 'TEST_SCHEDULE');
end;
P:\010Comp\CertPrs8\862-4\ch07.vp
Tuesday, September 07, 2004 4:38:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
Blind Folio 8:1
8
Backup and
Recovery
Enhancements
CERTIFICATION OBJECTIVES
8.01 Using the Flash Recovery Area 8.04 Miscellaneous Backup and Recovery
Enhancements
8.02 Using Incremental Backups
8.03 Enhanced RMAN Commands
✓ Two-Minute Drill
Q&A Self Test
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:55 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
O racle Database 10g contains several interesting innovations in the backup and recovery
area. You can now store all recovery-related files, such as archive logs and database
backups, 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 backup
files. Oracle Database 10g contains new methods for making faster incremental
backups. 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 perform
a hot recovery without needing to restore backup files first, by using the SWITCH
DATABASE command. This capability will enable you to implement a faster database
recovery.
You can also create compressed backup sets in Oracle Database 10g to save on
storage 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 the
DROP DATABASE command. You’ll review the new features that let you specify limits
on your backup windows.
Let’s start with a detailed look at the interesting and very useful flash recovery
area feature.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:55 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
To enable this feature, you simply designate sufficient disk space as the flash
recovery area, specify the area’s maximum size, and let Oracle know how long you
want to retain the backup-related information. Oracle will then manage the backup
of related files, including archive log files, control files, and other files. Oracle will
delete the files that your database no longer needs because the files have become
obsolete or they have been backed up to tape. Thus, your main tasks will be provisioning
adequate space for the flash recovery area and selecting the appropriate retention
period for keeping the related files.
Once you create the flash recovery area, you can direct all you backup files, including
the 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 backup
retention interval. In order to automatically delete unwanted files, the flash recovery
area concept relies on the Oracle Managed Files (OMF) system. OMF automates file
management in Oracle databases by automatically creating and managing the operating
system files that you allocate for your database. All you need to do to get an OMF
file system going is to configure a couple of OMF-related initialization parameters:
DB_CREATE_FILE_DEST and DB_CREATE_ONLINE_LOG_DEST_n. As you
are aware, OMF has the capability to automatically create and delete Oracle files,
without the DBA’s intervention. The RMAN capitalizes on this capability of the
OMF file system to perform its backup- and recovery-related functions through using
the flash recovery area.
You can also use a flash recovery area on top an ASM file system (see Chapter 10
for a discussion of ASM file systems). ASM file systems consolidate disks into easily
manageable disk groups, and provide striping and mirroring capabilities based on the
Oracle database itself.
The flash recovery area provides the following benefits:
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:55 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
All files that you need to by using the files in the flash recovery area.
recover from a media failure are part of In addition to these recovery files, you may
your flash recovery area. You should be also store other database files in the flash
able to completely recover your database recovery area.
■ Datafile copies You can make copies of the database datafiles using the new
RMAN command BACKUP AS COPY. You can use this command to create
image copies of all datafiles, which the RMAN will automatically store in the
flash recovery area.
■ Control file autobackups The flash recovery area serves as the default
location for all control file autobackups made by the RMAN. The database
places any control file backups it generates in the flash recovery area.
■ Archived redo log files Since Oracle automatically deletes all obsolete files
and files that have been transferred to tape, the flash recovery area is an ideal
location for archived redo log files. You don’t need to manually delete the old
archived redo log files, because Oracle will automatically delete the files if
you store them in the flash recovery area.
■ Online redo log files Oracle recommends that you save a multiplexed copy
of your online redo log files in the flash recovery area. Oracle will generate its
own names for the online redo log files. The default size of an online redo file
that’s created in the flash recovery area is 100MB. The following statements
can create online redo logs in the flash recovery area: CREATE DATABASE,
ALTER DATABASE ADD LOGFILE, ALTER DATABASE ADD STANDBY
LOGFILE, and ALTER DATABASE OPEN RESETLOGS.
■ Current control files Oracle also recommends that you store a multiplexed
current control file in the flash recovery area.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:55 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 using
the DB_RECOVERY_FILE_DEST initialization parameter, the RMAN
will, 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 the
RMAN in the flash recovery area as well.
■ Flashback logs Oracle stores all flashback logs in the flash recovery area. If you
enable the flashback database feature (discussed in Chapter 9), Oracle copies
images of each altered block in every datafile into flashback logs stored in the
flash recovery area. The database will use these flashback logs to reconstruct
the 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 recovery
area permanent files, since they should never be deleted and are part of the live
database. Oracle terms all the other files in the flash recovery area (recovery-
related files) transient files, since Oracle will delete them eventually after they
have become obsolete or have already been copied to tape.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:55 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 the
database, which is the C:\Oracle\Product\10.1.0\flsh_recovery_area\nina\ directory
on my Windows XP server.
Note that this list includes both online redo log files and control files. Oracle
recommends that you save both a duplexed redo log file and a current control file in
your flash recovery area, along with all the other recovery-related files (database file
copies and the archived redo log files).
At the minimum, Oracle recommends that you keep the archived logs not yet
saved to tape in the flash recovery area.
The size of your database, of course, will be the main determinant of the size
of the flash recovery area. The size of the flash recovery area also depends on the
following factors:
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:56 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
■ You can configure the flash recovery area during database creation using the
Database Creation Assistant (DBCA).
■ You need to configure two initialization parameters to configure a flash
recovery area. Since these initialization parameters are dynamic, you can
also create a flash recovery area while the database is running.
■ Of course, you can also use the OEM Database Control to configure a flash
recovery area.
When you use the DB_ destination. Oracle will actually let you use
RECOVERY_FILE_DEST parameter to a file server device for the flash recovery
specify the destination of your flash area, provided that it is one that has
recovery area, you can use a directory, been verified by the Oracle Storage
file system, or ASM disk group as your Compatibility Program.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:56 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:56 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
Note that even after you disable the flash recovery area, the RMAN will continue
to 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 features
of the flash recovery area.
Control Files
If you set the CONTROL_FILE parameter manually in your initialization file before
starting the instance to create a new database, Oracle will create the control files in
that location. If you haven’t set the CONTROL_FILES parameter, Oracle will create
the control files in various default locations, according to the following rules:
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:56 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
■ Image copies These are identical to your normal operating system file copies.
Image copies are byte-by-byte copies of Oracle database files. However, the
big difference between the copies made by the operating system and the RMAN
image copies is that the RMAN records information about its image copies
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:56 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 of
the RMAN recovery catalog, you can’t use normal operating system backup
copies inside RMAN.
■ Backup sets These are logical entities, consisting of individual components
(files) called backup pieces. Backup pieces store the contents of one or several
Oracle database files. You can’t access the backup pieces on an individual
basis; you must access them as part of a backup set.
You can back up the flash recovery area itself by using simple RMAN backup
commands. In order for the commands to work, you must set CONFIGURE BACKUP
OPTIMIZATION to ON. You can back up the flash recovery area only to a tape
device using these backup commands.
The RMAN command BACKUP RECOVERY AREA backs up all flash recovery
files in the current or previous flash recovery area destinations. This command will
back up only those files that have never been backed up to tape before. The files
that the command will back up include full backups, incremental backups, control
file autobackups, archive logs, and datafile copies.
The RMAN command BACKUP RECOVERY FILES command backs up all the
files that the BACKUP RECOVERY AREA command does, but from all areas on your
file system, not just from the flash recovery area.
Neither of the two area, such as the current control file and
commands, BACKUP RECOVERY AREA or the current redo log file. These commands
BACKUP RECOVERY FILES, will back up will also not back up the flashback logs.
any permanent files in the flash recovery
You can use the RMAN command BACKUP RECOVERY FILE DESTINATION
to move disk backups created in the flash recovery area to tape.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:57 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
Space Management
Once you create the flash recovery area, Oracle will start storing recovery-related files
in 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 updates
its list of backup files that are candidates for deletion. This list consists of those files
that 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 new
recovery-related files.
When the flash recovery area runs low on space and it can’t delete any files to
relieve the space pressure, Oracle issues an automatic warning alert, once the flash
recovery are is 85 percent full. When the area uses up 97 percent of its space, Oracle
will send a critical alert. Oracle sets these warning and critical thresholds, and you
can’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 to
place new recovery-related files in the flash recovery area, until it hits the 100 percent
space usage barrier, at which point it will issue an error stating that your flash recovery
area is out of room.
If you ever receive the out-of-space warning and critical alerts because of space
pressure 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 to
allocate more space to your current flash recovery area.
■ Use the BACKUP RECOVERY AREA command in the RMAN to back up the
contents of the flash recovery area to a tape device.
■ Use the RMAN to delete unnecessary backup files. The RMAN commands
CROSSCHECK and DELETE EXPIRED come in handy during this deletion
process.
Note that if the database can’t archive any redo log files because the flash
recovery area is full, the database will hang, as it always does when your traditional
archive destination fills up.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:57 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
Oracle will immediately start creating all the new flash recovery area files in your
new flash recovery area location.
You can leave the permanent files (control files and online redo log files), flashback
logs, and transient files in their original location. Eventually, Oracle will delete all
the transient files from the previous flash recovery area location, when each of them
become eligible for deletion. However, if you want to move your current permanent
files, transient files, or flashback logs to the new flash recovery area, you can do so by
using the standard file-moving procedures.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:57 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
1. Apply the incremental backups to datafile image copies. Use the RECOVER
COPY OF DATAFILE command of the RMAN to perform the recovery. This
will update all of your datafile image copies, all the way up to the system change
number (SCN) in the latest incremental backup. The RMAN will treat this
updated datafile image copy as a normal datafile image copy.
2. Then apply the archive logs since the last incremental backup only. Apply
these archive logs to the updated datafile image copies. Note that here is where
the incrementally updated backups provide their value, since you don’t need
to apply all the archive logs since the last backup, but only those logs since the
last incremental backup! You don’t need to perform a full image copy after
incrementally restoring your database files.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:57 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
Incremental backups help only data block changes, and that is always
restore datafiles by applying changes at the much faster than applying individual
database block level. Archived redo logs transactions. Thus, Oracle prefers that
apply changes at the transaction level. you use incremental backups over archived
Incrementally updated backups lead to a logs during a recovery, whenever you have
faster recovery, since you need to apply a choice.
If you have incremental backups available, along with the archived redo logs,
the RMAN will always choose incremental backups over archived redo logs during
recoveries, because it is a much faster way to recover your database. However, note
that for a level 0 incremental backup, Oracle may not choose incremental backups
over 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 all
of these backups on disk. You can then perform a quicker full database or
point-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 applying
the incremental backup files to the datafile image copies. If you have multiple versions
of an image copy in the RMAN catalog, the RMAN will automatically use the latest
version. If there are overlapping incremental backups, the RMAN will choose the one
covering the longer period.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:57 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
If you store the change tracking file along with you database files, the file will be
deleted automatically when you disable block change tracking. You can rename or
relocate a change tracking file by using the ALTER DATABASE RENAME FILE
command, as shown here:
SQL> alter database rename file
2 '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 can
rename 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>
The change tracking file increments. The file’s size depends on your
contains the physical location of all database size, number of instances in an
database changes. The minimum size is RAC, and the number of old backups the
10MB. Oracle creates the file automatically file maintains.
and allocates additional space in 10MB
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:57 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
You can use the V$BACKUP_DATAFILE view to see how the block change
feature is helping you minimize the file scanning done by the incremental backup
process. You can use the ratio between the value of the BLOCKS_READ column
and the DATAFILE_BLOCKS column to figure out the percentage of blocks Oracle
is reading in order to perform its incremental backups. If the BLOCKS_READ/
DATAFILE_BLOCKS ratio is too high, you may need to take more frequent
incremental backups to reduce the ratio.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:58 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 BACKUP
AS 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 RMAN
configuration command:
RMAN> configure device type disk
2> 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 stored
released channel: ORA_DISK_1
RMAN>
To create a backup set, rather than an image copy, you can use the following
command:
RMAN> backup as backupset database;
Performing Backups
You can back up various database elements as follows:
■ Entire database backup You can now perform an image file backup of the
entire database, by using the following command:
RMAN> backup database;
■ Previous database image copy If you wish to back up a previous image copy
of all the database files and control files in your database, use the following
command:
RMAN> backup copy of database;
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:58 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
■ Current control file To back up a current control file, use the following
command (equivalent to the SQL command ALTER DATABASE BACKUP
CONTROLFILE):
RMAN> backup current controlfile;
■ Previous control file copies In order to copy all the previously made control
file copies, use the following command.
RMAN> backup controlfilecopy all;
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:58 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
Instead of the keyword BACKUPPIECE, you can use the keyword DATAFILECOPY, if you
are 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 copy
datafile copy
filename= C:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\
NINA\DATAFILE\01_MF_SYSAUX_OGOGDVDC_.DBF recid=4 stamp=530016304
RMAN>
You can also use the reverse command, UNCATALOG, to get rid of a backup piece
from the RMAN catalog, as shown here:
RMAN> change backuppiece 'file_name' uncatalog;
The following example uncatalogs the datafile copy cataloged in the previous
example:
RMAN> change datafilecopy
"C:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\
NINA\DATAFILE\01_MF_SYSAUX_OGOGDVDC_.DBF" UNCATALOG;
Uncatalogued datafile copy
datafile copy
filename= C:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\
NINA\DATAFILE\01_MF_SYSAUX_OGOGDVDC_.DBF recid=4 stamp=530016304
Uncatalogued 1 objects
RMAN>
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:58 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
FLASH_RECOVERY_AREA\NINA\DATAFILE
List of Files Unknown to the Database
=====================================
File Name: C:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\NINA\DATAFILE\
O1_MF_SYSAUX_0G0GDVDC_.DBF
Do you really want to catalog the above files (enter YES or NO)? YES
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: C:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\NINA\DATAFILE\
O1_MF_SYSAUX_0G0GDVDC_.DBF
RMAN>
The CATALOG START WITH command comes in very handy if you happen to
lose your RMAN recovery catalog. In earlier releases, there was no way to tell the
RMAN about a backup set. This was a complete showstopper for many DBAs. If
your recovery catalog was destroyed, even though all the backup sets were perfect
and you knew exactly where they were and what was in them, there was no way to
tell a newly created catalog to use them. Now you can just point it at the tape library
and let it find everything. This is an important and long overdue enhancement.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:58 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
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;
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:58 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
■ 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 (flash
recovery area) parameter
If you don’t use any of these alternatives, the backup files will go into an operating
system-specific default directory.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:59 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 the
fast recovery process with the SWITCH DATABASE command.
Since you don’t need to copy any files, only rename the recovery files, the recovery
process is very fast. However, it comes with a price: you need to make sure that you
have additional backups made as soon as possible, to make up for the fact that you have
used up one of your backups to recover your database.
Compressed Backups
Oracle 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 you
use compressed backup sets, since there is now the additional step of uncompressing the
backup sets before starting the recovery. Nevertheless, all recovery procedures remain
the same when you use a compressed backup set. The compression factor will depend
on the nature of the data in your datafiles. Oracle recommends using this in preference
to an external compression utility, and you certainly shouldn’t use both utilities together.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:59 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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;
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:59 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
distinguish the archived redo logs from several database incarnations, Oracle
Database 10g uses a new format for the archived redo log files. The initialization
parameter LOG_ARCHIVE_FORMAT uses a text string and a set of variables to
specify the default archive log format. Oracle applies the string generated by using
this format to the string generated from the LOG_ARCHIVE_DEST parameter to
come up with the complete path and filename for archived redo log files.
Previously, you used the following format for the LOG_ARCHIVE_FORMAT
parameter 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 variable
s 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"
Dropping a Database
Sometimes, you may want to drop test database or drop your old database after you
successfully migrate to a new version of Oracle. It’s very easy to drop an Oracle
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:59 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
Database 10g database. You can use the new command DROP DATABASE to remove
a database, in both the RMAN as well as the SQL*Plus interface. You may also use
the DBCA to drop the database.
Here is how you drop a database in the RMAN:
RMAN> drop database;
Your database must be mounted EXCLUSIVE and not be open in order to use
the DROP DATABASE command, whether you’re using the RMAN or SQL*Plus
interface to drop a database. In addition, you must have SYSDBA privileges.
■ Oracle will drop all control files and datafiles automatically, whether you use
the 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.
After you drop a database, database, you need to use the following
no matter which one of the three methods RMAN command to wipe out all traces
you use (RMAN, SQL*Plus, or DBCA), of the dropped database from the RMAN
the RMAN catalog continues to list the registry:
dropped database information. Regardless
RMAN> unregister database;
of which method you use to drop a
The DROP DATABASE command removes all datafiles and control files. Oracle
doesn’t remove any backups or archived redo log files when you drop a database.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:59 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
To make the RMAN remove all database backup copies as well as the archived redo
log files, you can add the INCLUDING BACKUPS clause to your DROP DATABASE
command in the RMAN, as shown here:
RMAN> drop database including backups;
■ PARTIAL Normally, when your database backup jobs run past the time
interval you specify through the DURATION parameter, the RMAN job errors
out and the backup is canceled. This is the RMAN’s default behavior when
it runs past any specified duration. You can override this default behavior by
specifying the PARTIAL clause, which will prevent the issuing of any RMAN
error messages.
■ MINIMIZE TIME This option tells the RMAN to “hurry up” and finish as
fast as it can.
■ MINIMIZE LOAD This option tells the RMAN to “slow down” if it is well
within its allotted time for a backup job.
You must use disks if you want to use the MINIMIZE TIME option, since you
generally want a tape backup to end as quickly as possible.
Here is a simple example illustrating the use of this very interesting clause during
a database backup:
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:09:59 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
Remember that the limit. The MINIMIZE TIME option gets the
DURATION clause’s PARTIAL option leads job done the fastest. The MINIMIZE LOAD
to an error if the backup exceeds its time option minimizes resource use.
You need to place the datafiles in an online backup mode only if you are
performing a user-managed recovery, in order to guarantee that any fractured
blocks can be recovered (assure consistency). You don’t need this command in
the RMAN, since an RMAN backup does not contain any fractured blocks.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:10:00 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
If the backup process encounters any nonexistent, read-only, or offline files, Oracle
skips them, and the backup will continue. No errors are issued.
If you encounter any of the following situations, your attempt to start an online
backup will fail, with a “cannot start online backup error” message.
■ Offline files will cause a warning message, but the END BACKUP command
itself 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 through
an RMAN backup.
Since you are creating your auxiliary instance in the same location as your
primary database, you need to be aware of the possibility of some performance
degradation during the TSPITR operation.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:10:00 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 it
can create the instance. Here are the various ways in which you can submit the auxiliary
file 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 argument
to provide the file locations for a RECOVER TABLESPACE operation.
The exam will certainly query your knowledge Expect a question on the new recovery
of the flash recovery area. You must know the technique that uses incrementally updated
relevant initialization parameters for creating backups. What command do you use to
the flash recovery area and the kinds of files recover with an incrementally updated
you can store in it. What are the differences backup? Expect some questions on the new
between recovery-related files and other files fast incremental backup feature and how you
in the flash recovery area? You may also see a enable it (by enabling block change tracking).
question on how control file and redo log file What is the change tracking file? What does
placement will depend on the combination the new CTWR background process do?
of the flash recovery area and the OMF file Know the details of the new compressed backups
destination parameters (DB_CREATE_ feature. You most certainly will face questions
ONLINE_DEST_n and DB_CREATE_ on using the simplified recovery process through
FILE_DEST). RESETLOGS. What changes in the initialization
You must understand the new RMAN parameters make this possible? You must
commands like BACKUP AS COPY and remember the commands that enable you to
RECOVER COPY OF DATAFILE. What is implement a fast recovery (SWITCH DATABASE
the new RMAN command to back up an TO COPY).
entire database? What is the command to Know the steps in dropping a database.
implement a fast recovery using RMAN? What files are removed by Oracle when you
What do the DURATION clause and issue the DROP DATABASE command?
the PARTIAL, MINIMIZE LOAD, and
MINIMIZE TIME options mean during
a backup command?
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:10:00 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
CERTIFICATION SUMMARY
This chapter dealt with several interesting enhancements related to backup and recovery.
You were introduced to the new flash recovery area concept, which helps centralize
all your recovery-related storage efforts. You then looked at the new techniques to
reduce your incremental backup times. You also learned how to recover faster by
applying incremental backups to datafile image copies.
Several new RMAN commands were explained in this chapter, including the
BACKUP AS COPY and CATALOG commands. You also learned about the new
scripting enhancements in the RMAN.
You learned about the new SWITCH DATABASE command, which helps you cut
back on restore/recovery times in a crisis. You also learned how to compress your
RMAN backups. You learned about the enhancements that let you avoid needing
to back up your databases after a RESETLOGS operation. You also learned how you
can use archived redo logs from a previous database incarnation. You learned how to
drop the database with the DROP DATABASE command. You saw how you could use
the DURATION option to control backup windows during certain times. You also saw
how Oracle Database 10g can help you during a TSPITR operation, by automatically
creating and removing the auxiliary instance.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:10:00 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
Two-Minute Drill 33
✓ TWO-MINUTE DRILL
Using the Flash Recovery Area
❑ The flash recovery area is the default storage location for all recovery-related
files.
❑ You may use an Oracle-managed directory, operating system file system, or an
ASM disk group for your flash recovery area.
❑ Oracle automatically deletes obsolete files and files that have been backed up
to tape.
❑ If you don’t use OMF files, Oracle can’t automatically delete unnecessary
recovery 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 log
files and the current control file in your flash recovery area.
❑ The size of the flash recovery area should be greater than the sum of the
database size, any incremental backups, and all the archived logs on disk.
❑ The size of the flash recovery area also depends on your RMAN retention
policy.
❑ You use the two initialization parameters DB_RECOVERY_FILE_DEST and
DB_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 before
you 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 BACKUP
RECOVERY AREA, using the RMAN interface.
❑ The BACKUP RECOVERY FILES command in the RMAN backs up all
recovery files, irrespective of their location.
❑ Oracle sends you both warning and critical alerts when the flash recovery
area space starts to fill up.
❑ The V$RECOVERY_FILE_DEST view is your main source for information
regarding the flash recovery area.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:10:00 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:10:00 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
Two-Minute Drill 35
❑ Using the SWITCH DATABASE command, you can recover directly from
backup files, without restoring them first.
❑ You can recover a datafile even if you don’t have a backup for it, as long as
you 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 RESETLOGS
identifier 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 the
SPFILE automatically.
❑ Oracle doesn’t automatically remove the archived redo logs and backup files
when you drop a database.
❑ No matter which method you use to drop the database, you must use the RMAN
command UNREGISTER DATABASE to remove database information from the
RMAN catalog.
❑ Using the DURATION clause, you can set limits on your backup job duration.
❑ The PARTIAL option of the DURATION clause prevents errors when you
cross the time interval for a backup.
❑ The MINIMIZE TIME option of the DURATION clause will speed up your
backups.
❑ The MINIMIZE LOAD option of the DURATION clause may slow down
your backups.
❑ You can put all datafiles in the backup mode simultaneously with the command
ALTER DATABASE BEGIN BACKUP.
❑ The RMAN can now automatically create and remove the auxiliary instance
necessary during a TSPITR operation.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:10:01 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
SELF TEST
The following questions will help you measure your understanding of the material presented in this
chapter. Read all the choices carefully, because there might be more than one correct answer. Choose
all correct answers for each question.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:10:01 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
Self Test 37
A. Create an OMF control file in both locations specified by the two parameters
B. Create an OMF control file in the flash recovery area only
C. Create an OMF control file in the system-specified default location
D. Create an OMF control file in the location specified by the DB_RECOVERY_FILE_DEST
parameter only
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:10:01 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:10:01 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
Lab Questions 39
LAB QUESTIONS
1. 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.vp
Wednesday, September 08, 2004 1:10:01 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:10:01 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
7. þ C and D. To apply incremental backups, you use the RECOVERY COPY OF DATAFILE or
RECOVERY 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 is
wrong since it is the Oracle block level, not the operating system block level, that Oracle
applies changes to the datafiles. D is wrong since changes aren’t applied at the granularity
of 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 wrong
since the CTWR process doesn’t apply block level changes—it merely records them. D is
wrong 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, by
using the ENABLE BLOCK CHANGE TRACKING command.
ý B is wrong since Oracle disables block change tracking by default. C and D are wrong
because you don’t need to create any files to enable block change tracking. It is the job of
Oracle to create the change tracking file automatically when you enable block change
tracking.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:10:02 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
14. þ A. The BACKUP CONTROLFILE ALL command backs up all previously made control file
copies.
ý B and C are wrong since the command doesn’t back up the current control files, even if
they have never been backed up before. D is wrong because the command has nothing to do
with tape backup.
15. þ B. When you remove all backup pieces for a backup set, the RMAN will remove the
backup set as well from its recovery catalog.
ý A is wrong since RMAN never removes the catalog automatically. C is wrong because you
can remove all the backup pieces from the catalog. D is wrong since RMAN doesn’t replace
any backup sets with image copies.
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:10:02 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 8
Lab Answers 43
20. þ D. The MINIMIZE LOAD option tells the database to slow down if it appears that its
going to make its target interval of time.
ý A and B are wrong since MINIMIZE PARTIAL and MAXIMIZE LOAD are nonexistent
options. C is wrong because MINIMIZE TIME tells the database to work harder.
LAB ANSWERS
1. To drop a database using the RMAN, follow this procedure:
Connect to the target database through the RMAN, making sure you are using the recovery
catalog:
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 recovery
area
RMAN> catalog start with '/u09/app/oracle/arch_dest2'; # second archive
dest
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 provide
the 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;
P:\010Comp\CertPrs8\862-4\ch08.vp
Wednesday, September 08, 2004 1:10:02 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Blind Folio 9:1
9
Flashback
Technology
Enhancements
CERTIFICATION OBJECTIVES
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:37 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
T his chapter reviews Oracle’s flashback technology, which operates at many levels,
serving a varied list of objectives. The flashback features of Oracle let you undo
logical 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 without
having to resort to time-consuming point-in-time recovery strategies using backups and archived
redo logs. Several of the flashback recovery features rely on the familiar undo data, since they
all need information from the past to recover from logical errors. In Oracle Database 10g, a
new type of recovery log, called a flashback log, enables the flashback database feature. You can
use the flashback features of Oracle Database 10g to perform queries that return past data, to
perform queries that show the history of changes to table data, to undo undesirable changes to
table data, and to recover table(s) or even an entire database to a previous point in time.
■ Flashback database enables you to take the entire database to a past point in
time (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 (using
the recycle bin). Example: useful when you accidentally drop a table. This
feature 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 WHERE
clause.
■ Flashback query lets you query and restore data rows to a point in time (using
undo data). Examples: you want to compare current data against past data, or
you want to undo the effect of incorrectly run DML statements.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:38 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
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. Only
the flashback database feature uses the flash recovery area and flashback logs.
The flashback drop feature relies on the new recycle bin concept. All the
flashback query features rely on undo data.
We’ll look at the various Oracle Database 10g flashback features in detail in this
chapter. Let’s start with a review of the building blocks that enable Oracle to offer
you all the amazing and painless recovery techniques.
If you have a damaged disk drive, or if there is physical corruption (not logical
corruption due to application or user errors) in your database, you must still
use the traditional methods of restoring backups and using archived redo logs
to perform the recovery.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:38 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:38 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
You can also use the ALTER TABLESPACE command to tell Oracle to guarantee
undo retention in your database, as shown here:
SQL> alter tablespace test1
retention guarantee;
Tablespace altered.
SQL>
You can use the RETENTION NOGUARANTEE clause to turn off the guaranteed
retention of undo information.
Use Oracle’s Undo Advisor to get approximate undo parameter values as well
as suggestions regarding the sizing of your undo tablespace to successfully
support flashback for a specified time.
SCN_TO_TIMESTAMP
The SCN_TO_TIMESTAMP SQL function lets you convert an SCN to a calendar
time (TIMESTAMP) value. Here’s an example:
SQL> SELECT current_scn, SCN_TO_TIMESTAMP(current_scn)
2 FROM v$database;
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:39 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
CURRENT_SCN SCN_TO_TIMESTAMP(CURRENT_SCN)
------------- -----------------------------------
5956956 03-JUL-04 09.37.16.000000000 AM
SQL>
TIMESTAMP_TO_SCN
The TIMESTAMP_TO_SCN function is the inverse of the SCN_TO_TIMESTAMP
function. It converts a timestamp to its corresponding SCN.
Flashback Database
When you discover a major logical corruption in your database, the usual recourse is
to perform a point-in-time recovery. This type of recovery involving the use of datafile
backup copies and archived redo logs is very cumbersome and time consuming. Flashback
database does the same job as a traditional point-in-time recovery: it takes the database
back 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, at
the most, just a fraction of the archived redo log information. Consequently, a flashback
database operation lets you recover from logical corruptions much faster than with the
usual point-in-time incomplete database recoveries.
You must understand that flashing back a database is possible only when there is
no media failure. If you lose a datafile, you’ll have to recover using a restored datafile
from backups. You must have all the datafiles and they must all be uncorrupted in
order 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 application
of archived redo logs. With flashback database, the extent of time taken for recovery
directly depends on the amount of changes that you need to undo. Thus, the size of
the error, not the size of the database, determines the time it takes to recover.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:39 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Flashback Database 7
datafiles from memory (flashback buffer) to the new flashback logs. Oracle logs
flashback data at infrequent intervals to reduce the I/O and CPU overhead. Oracle
stores these flashback logs in the flashback recovery area. That’s why the first step in
turning the flashback database feature on is to make sure you have configured a flash
recovery area.
The new memory buffer, flashback buffer, logs images of all altered data blocks in
the database. You can use these before images of data blocks to reconstruct a datafile
so you can back out any changes made after a specified target time and turn the file
back to a time in the past. In reality, however, the flashback database logs are used to
recover to a time just before the target time. Oracle uses traditional archive logs to
write changes for the short gap in time between the target recovery point in time
and the actual recovery time. A new background process, RVWR (Recovery Writer),
starts up automatically when you enable the flashback database feature. The RVWR
process 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 is
that there are no archived flashback database logs! Oracle stores all the flashback
database logs in the flash recovery area.
When you want to restore a database to a past target time using the flashback
database feature, Oracle will restore each data block to its state at the time immediately
before the target time that the flashback logs were written. For example, if you want
to flashback to 8:00 A.M., it may turn out that the flashback logs nearest to the target
time were written at 7:56 A.M. To cover this gap, you must apply the changes from
archived 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 and
archived redo log files, you must have redo logs available for the entire time period
spanned by the flashback logs.
Traditional point-in-time incomplete recovery involves the restoration of backup
data files first. After the restore, you apply the archive redo logs to advance the database
forward. In flashback database, you don’t use any backup data files. You simply apply
the flashback database logs to take the database back in time.
Oracle recommends that you set your redo log buffer for large databases to
at least 8MB. The flashback buffer size will be at least log_buffer times two,
thus ensuring that Oracle allocates the typical maximum memory possible
for your flashback buffer, which is about 16MB.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:39 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Always remember that Oracle doesn’t guarantee that you can flashback your
database to the flashback retention target that you set by using the FLASHBACK_
RETENTION_TARGET init parameter. Oracle stores the flashback logs you need for
a flashback database operation in the flash recovery area. If Oracle is running low on
free space in the flash recovery area for newly arriving archived redo log files, it will
remove some flashback logs to make room. That’s why it is absolutely essential to
monitor the flash recovery area size to ensure you don’t lose any critical flashback
logs necessary to recover your database.
■ All commands of the Flashback Database feature work the same in RMAN
as well as SQL*Plus. The only difference is that RMAN will automatically
retrieve the necessary archived redo logs.
■ If you’ve lost a datafile or for some reason can’t use a datafile, you can’t use
Flashback Database to recover. You must have all the datafiles to flashback
your database to a past period.
■ If a datafile was resized during the time span covered by the Flashback Database
operation, you can’t flashback that datafile. Instead, you must offline that
particular datafile before you start the flashback database operation.
■ If a control file has been restored or re-created during the time span you want
to flashback over, you can’t use the Flashback Database feature.
■ For good performance, Oracle recommends using fast file systems that don’t
use operating system file caching. Large flashback database logs add to your
overhead when using operating system file caching.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:40 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Flashback Database 9
If you want to undo the forward. Flashback Database rolls back the
effects of a Flashback Database operation, database. To undo it, you therefore must
you must recover the database by rolling it roll forward the database.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:40 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
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 bytes
Fixed Size 787728 bytes
Variable Size 95419120 bytes
Database Buffers 20971520 bytes
Redo Buffers 262144 bytes
Database mounted.
SQL>
6. Use the ALTER DATABASE OPEN command to open the database. To confirm
whether the flashback database feature is enabled, issue the following query:
SQL> select flashback_on from v$database;
FLA
---
YES
SQL>
You can find out if the finally, use the ALTER DATABASE FLASHBACK
flashback feature is enabled by querying ON command. You can turn the feature off
the V$DATABASE view. The three things by using the ALTER DATABASE FLASHBACK
you must do to configure the flashback OFF command. Make sure you restart the
database are as follows: configure the flash database in the MOUNT EXCLUSIVE mode
recovery area, set the DB_FLASHBACK_ before using this command.
RETENTION_TARGET parameter, and
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:40 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Flashback Database 11
When you disable the flashback database feature, Oracle deletes all flashback
database logs in the flash recovery area.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:41 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
If there isn’t sufficient data to perform a flashback all the way back to where
you want to take the database, you can use standard recovery procedures to
recover the database.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:41 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Flashback Database 13
If the query results indicate that you can’t wind back your database as far as you
would like, you must increase the size of your flash recovery area. You do this so the
flash recovery area can hold a larger amount of flashback database logs.
Just because you have set satisfy the retention target. If the flashback
your retention target at a high value recovery area gets full, Oracle will remove
doesn’t ensure that Oracle will guarantee the flashback database logs to make room
the retaining of flashback database logs to for new recovery files.
The database incurs an I/O overhead while logging the flashback data. The view
V$FLASHBACK_DATABASE_STATS helps you monitor the I/O overhead of
logging flashback data. Here’s the structure of the V$FLASHBACK_DATABASE_
STATS view:
SQL> desc v$flashback_database_stat;
Name Null? Type
----------------------------------------- -------- ----------
BEGIN_TIME DATE
END_TIME DATE
FLASHBACK_DATA NUMBER
DB_DATA NUMBER
REDO_DATA NUMBER
ESTIMATED_FLASHBACK_SIZE NUMBER
SQL>
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:41 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
■ BEGIN_TIME and END_TIME stand for the beginning and ending hourly
time intervals for which the view’s statistics were collected. Oracle collects
flashback data on an hourly basis for a maximum of 24 hours. If you issue a
query on the table, however, it may return 25 rows, the 25th row being for the
most 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 written
during the interval.
■ DB_DATA stands for the number of bytes of database data read and written
during the interval.
■ REDO_DATA stands for the number of bytes of redo data written during
the interval.
■ ESTIMATED_FLASHBACK_SIZE is identical to the value of
the ESTIMATED_FLASHBACK_SIZE column in the V$FLASHBACK_
DATABASE_LOG view.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:42 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Flashback Database 15
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 current
number 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 was
32768. I can do this easily by flashing back to the SCN 5965123. To use any flashback
feature, 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:
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:42 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Note that TO SCN takes the database back to its state at that SCN. You can also
take a database back to its state just before an SCN by using the TO BEFORE SCN
clause. Alternatively, you may use the TO_TIMESTAMP or TO BEFORE TIMESTAMP
to revert the database to a specified timestamp, or one second before the specified
timestamp.
In order to query the persons table, I must first open the database, which I try to
do 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 the
database. 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 may
first want to use the ALTER DATABASE OPEN READ ONLY statement. Once you
confirm that you have flashed the database back to the correct point in time or
the correct SCN, you can finalize matters by using the ALTER DATABASE OPEN
RESETLOGS statement. If after the initial check (in the read-only mode), you
decide to go back further in time, you can flashback the database again. If you
determine that you flashed back too far into the past, you can use redo logs to roll
forward. The ALTER DATABASE OPEN RESETLOGS statement should be used
only 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 following
query on the persons table:
SQL> select count(*) from persons;
COUNT(*)
-----------
32768
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:42 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Flashback Drop 17
In the previous example, I used an SCN to tell the database how far back it
should flashback. However, you may use an archived log sequence, or a prior time as
well, to specify the flashback point. Here are some examples using time and log
sequence numbers:
SQL> flashback database to sequence 12345; /* will flashback
the database to the log sequence numbered 1234) */
SQL> flashback database to timestamp (SYSDATE -1/24); /* will flashback the database to an hour ago */
Once you flashback the the database forward, after the flashback
database to a certain point in time, you can operation. If you want to completely undo
flashback the database to a different time the effects of the flashback database
if you think you used the wrong flashback operation, just use the command RECOVER
target time the first time around. If you DATABASE to perform a complete recovery
want, you can perform a recovery to roll of the database.
EXERCISE 9-1
Flashback Drop
One of the biggest occupational hazards of a DBA’s job is the fact that you could
inadvertently drop a key production table. There are countless stories of how DBAs
have dropped or truncated the wrong table in the wrong database, with disastrous
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:42 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
In an Oracle 10g database, when you drop a table, Oracle doesn’t automatically drop
the space allocated to the table. It simply renames and stores the table and its dependent
objects in the database’s recycle bin. Using the Flashback Drop operation as shown in
the previous example, you then recover the dropped table from the recycle bin.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:43 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Flashback Drop 19
them from the recycle bin—and therefore, from the database—when either a user
purges them or Oracle automatically reclaims the space. To summarize:
■ You remove a table permanently with a PURGE command. You can use the
PURGE command as an option with the DROP TABLE (or INDEX) command.
You may also use the command to drop an object currently saved in the
recycle bin.
Or
■ Oracle automatically removes the dropped objects in the recycle bin because
of space pressure. Space pressure is said to occur when there isn’t enough free
space in a tablespace when you need to create a new object or extend more space
to an existing object. Oracle first allocates all the available free space in the
tablespace to the new object. When it runs out of available free space, Oracle
will start automatically purging the occupants of the recycle bin to make room
in the tablespace.
There could be several about the recycle bin owned by the current
recycle bins, each owned by the person user. The DBA_RECYCLEBIN view displays
who dropped an object. The USER_ information about all recycle bins in the
RECYCLEBIN view displays information database.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:43 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
The SHOW RECYCLEBIN command shows only those objects that you can
undrop.
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 the
table. The reason is that as long as the dropped table is still in the recycle bin, you
can recover it by using the FLASHBACK TABLE command.
How can you tell by looking at the DBA_TABLES view which of your tables are
in the recycle bin with system given names, and which are not? A simple query on
DBA_TABLES will resolve this issue, as shown here:
SQL> select table_name, dropped from dba_tables;
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:43 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Flashback Drop 21
Valerie alapati
sam alapati
nina alapati
nicholas alapati
shannon alapati
SQL>
You can use the SELECT bin. You can’t use INSERT, UPDATE, and
command to query the objects in the recycle DELETE commands on these objects.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:44 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
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 dropped
table upon recovery, using the following command. (You may use the same command
with the original name of the table in the first line, instead of the system-generated
name.)
SQL> flashback table "BIN$ksisyyg0TxKnt18rqukpQA==$0"
to before drop
rename to NEW_PERSONS;
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:44 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Flashback Drop 23
want to drop a sensitive table and don’t want it to appear in the recycle bin for security
purposes. 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 TABLE
command in previous versions of Oracle. Using the PURGE clause is equivalent
to first dropping the table and then purging it from the recycle bin.
■ PURGE TABLE or INDEX will remove the table or index. You can also use
the DROP TABLE … PURGE command, but that command applies to objects
that aren’t a part of the recycle bin. You may also drop an object by using the
recycle 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, the
PURGE 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,
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:44 PM
Color profile: Disabled
Composite Default screen 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 removed
as 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;
EXERCISE 9-2
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:45 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Flashback Table 25
■ 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 when
you 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 Private
Database policies defined on it.
The table that you want the dependent objects of that table can
to flashback must be in a non-SYSTEM, be in a dictionary or locally managed
locally managed tablespace. However, tablespace.
Flashback Table
Oracle’s Flashback Table feature lets you perform an online, point-in-time recovery
on one or more tables. The FLASHBACK TABLE statement lets you restore an earlier
state of a table to recover from human or application errors. For example, you may
need to perform a point-in-time recovery on a table when a user mistakenly applies
an update statement with the wrong WHERE clause. The Flashback Table feature
relies 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
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:45 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
First, make sure you have all the privileges necessary to perform the Flashback
Table operation. You must have either the FLASHBACK ANY TABLE or the more
specific 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 flashback
operation doesn’t preserve Oracle ROWIDs when it restores rows in the changed
data 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 the
table to any time in the past, or any SCN in the past. Here’s an example that shows
how to flashback a table to a past SCN:
SQL> flashback table persons to scn 6039341;
Flashback complete.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:45 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Flashback Table 27
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 Flashback
Table operation. The restore is an in-place, online operation and thus doesn’t involve
any offlining of the datafiles or tablespaces, a procedure that’s common during
traditional point-in-time recovery. However, Oracle disables all relevant triggers by
default and reenables them upon completing the table recovery. You may simply
append the ENABLE TRIGGERS clause to your FLASHBACK TABLE command if
you 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;
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:46 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:46 PM
Color profile: Disabled
Composite Default screen 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 you
to perform queries on the database at a target time in the past. For example, if a user
accidentally deletes data rows during data entry, you can query the table using Flashback
Query to retrieve the lost rows and reinsert them in the table. All the changes are made
using 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 the
past 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 AS
OF clause. You may use SCN numbers or timestamps for this purpose. The AS OF
clause ensures that Oracle returns the committed data in the table as of a previous
SCN or timestamp. If you omit the AS OF clause, Oracle will retrieve data as of the
current SCN or a specific SCN or clock time if you have specified either one. Here’s
a simple example that illustrates how you can query the past state of a table:
SQL> select * from persons as of timestamp
to_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 the
data entry, you may undo the damage by simply inserting the correct rows, again with
the help of the SELECT … AS OF construct, this time in a subquery, as shown here:
SQL> insert into employee
(SELECT * FROM employee AS OF TIMESTAMP
TO_TIMESTAMP('2004-07-04 08:05:00', 'YYYY-MM-DD HH:MI:SS')
where name = 'ALAPATI');
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:47 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
The Flashback Versions Query feature enables the retrieval of all committed
versions of the same table row between two time points. If you’ve updated the row
ten 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 part
of your normal SELECT statement, with an optional BETWEEN clause appended
to it. Optionally, you can specify the SCN or
TIMESTAMP clauses. You must specify the start
and end expressions, which indicate the start
The Flashback Versions time and end time of the interval for which you
Query feature retrieves only committed are seeking the different row versions.
transactions. Remember that the query The output of a Flashback Versions Query
retrieves both deleted and subsequently is unlike the output of your typical SELECT
reinserted rows. statement. In addition to the column values
you specify in the SELECT statement, for each
version of the row, Oracle will provide you with values for a set of pseudocolumns for
each row version. It is these pseudocolumns that tell you the story of when exactly a
row change took place, and what exactly was done to the row at that time. Here is a
brief explanation of each pseudocolumn that will be part of the flashback versions
query output:
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:47 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
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 versions
of the row existed at this SCN. The query asks for the empname, salary and othr
information for emno 111. The empno 111 is orginally to a new employee and if that
employee is deleted, may be reassigned to a different employee. Thus, you may see
different employee names for the same empno valuye over time. Although you see
three 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 the
START_SCN and the END_SCN columns. As you know, the START_SCN
pseudocolumn tells you when a row was created. The END_SCN tells you when
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:47 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
a row expired. All rows will have a START_SCN, but may have a NULL value for
the 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 the
latest version of the row. Since the END_SCN is NULL for the first row, you know
that 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, you
see the letter D, indicating that the middle row
was deleted. The bottom or third row has an
You must know how to tell END_SCN number, so clearly this row expired
the current, or live, version of a row when at SCN 113564.
you use the Flashback Versions Query Note that you could have substituted the
feature. You must understand when a row VERSIONS BETWEEN TIMESTAMP … for
expires and how an END_SCN of NULL the VERSIONS BETWEEN SCN nn AND nn
for a deleted row means that the row no clause, if you decided to use timestamps instead
longer exists. of SCNs to specify the time interval for retrieving
the various versions of the row.
If you want to query past data at a precise time, you must use an SCN. If you use
a timestamp, the actual time queried might be up to three seconds earlier than
the time you specify. Internally, Oracle Database uses SCNs, which are mapped
to timestamps, with a granularity of three seconds. This time-to-SCN mapping
gap may throw you off if you’re trying to flashback to an exact time in the past
that’s immediately after a DDL operation. Your entire table might be gone, and
you’ll get a major error instead of the Flashback Versions Query results!
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:48 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
If you omit the AS OF clause clock time or SCN if you have specified
in a Flashback Versions Query, data is either one.
retrieved as of the current SCN, or the
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:48 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
undo statements necessary to retrieve the original row. Here’s the structure of the
FLASHBACK_TRANSACTION_QUERY view:
SQL> desc FLASHBACK_TRANSACTION_QUERY
Name Null? Type
----------------------------------------- -------- ----------
XID RAW(8)
START_SCN NUMBER
START_TIMESTAMP DATE
COMMIT_SCN NUMBER
COMMIT_TIMESTAMP DATE
LOGON_USER VARCHAR2(30)
UNDO_CHANGE# NUMBER
OPERATION VARCHAR2(32)
TABLE_NAME
VARCHAR2(256)
TABLE_OWNER VARCHAR2(32)
ROW_ID VARCHAR2(19)
UNDO_SQL
VARCHAR2(4000)
You must have the SELECT ANY TRANSACTION system privilege to query
the FLASHBACK_TRANSACTION_QUERY view.
In the preceding description, the various columns stand for the following items:
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:49 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
In our simple example, there is only a single delete operation that you need to
perform, 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 apply
the undo changes in the sequence that the query returns them in order to correctly
recover the data to its original state.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:49 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
(the what) of a row, along with their unique version IDs and other information such as
the timestamps and SCNs when the row versions were created. However, this feature
doesn’t have all the necessary information to correct the changed row data using
appropriate SQL statements to undo an undesirable change. The Flashback Transaction
Query feature provides you with the necessary information to identify not only the
type of operations performed on each version of a row, but also the necessary undo
SQL (the how) to put the rows back in their original state.
Let’s use a simple example to demonstrate how you can combine the Flashback
Versions Query and the Flashback Transaction Query features to undo undesirable
changes to your data.
First, let’s use the Flashback Versions Query feature to identify all the row versions
in a certain table that have changed in a certain time period. The following query lets
you 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 MAXVALUE
where empno = 111;
XID START_SCN END_SCN OPERATION EMPNAME SALARY
---------------- ---------- --------- ---------- ---------- ----------
0004000700000058 113855 I Tom 927
000200030000002D 113564 D Mike 555
000200030000002E 112670 113564 I Mike 555
3 rows selected
SQL>
In the previous query, let’s say we identified the second row, which indicates a
delete operation (D) as the culprit. By mistake, one of our users has incorrectly deleted
the row. All you need to do in order to extract the correct SQL to undo this delete
operation is to take the transaction ID (XID) from the Flashback Versions Query
shown 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_query
WHERE 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';
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:49 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
It is important for you to understand the flashback technique would you use when you
mechanism behind the various flashback drop a table accidentally? Which technique is
features. Understand that you rely on the flash best when you truncate a large table or apply
recovery area (Flashback Database), undo data partial changes in a large table? How about
(Flashback table, Flashback Transaction Query, when you use the wrong WHERE clause to
and Flashback Versions Query). What feature update a table? Know how and why you can
enables you to recover a dropped table (the use the Flashback Transaction Query and the
recycle bin)? Flashback Versions Query features together.
The test will contain questions relating The exam will contain questions relating to
to the flash recovery area. How do you the recycle bin. Know the difference between
configure the flash recovery area? How do the DROP TABLE and DROP TABLE
you monitor and size the flash recovery area? …PURGE commands. The test will probe your
You must know when to use each of the knowledge of the recycle bin object naming
flashback techniques. For example, what conventions. How can you flashback a table
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:49 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
more than once? When does the database flashback operation. Can you roll back a flashback
reclaim the space belonging to a dropped operation?
object? (Either use the PURGE command, The test will contain questions on flashback-
or the database must suffer space pressure.) related views like V$FLASHBACK_DATABASE_
What happens to the recycle bin contents LOG and V$FLASHBACK_DATABASE_STAT.
when you issue commands to drop a tablespace What do these two views help you do? (They
or a user? Know how to query objects in the help you size the flashback area and set the
recycle bin. What commands help you bypass flashback retention target.) How do you find
the recycle bin? out the flashback status for a database?
You must understand why you need
to enable row movement before a certain
CHAPTER SUMMARY
Oracle offers you the point-in-time recovery technologies to help you go back to a past
point in time in the event of a logical error. However, performing a point-in-time
recovery is time consuming, and the new flashback technology offers ways to undo
logical errors by simply “rewinding” the database or a table to a previous time. This
chapter introduced you to the new Oracle Database 10g flashback techniques that
enable 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 flashback
technology.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 database
tables and their dependent objects.
You also learned how to use the Flashback Versions Query feature to discover all the
versions of a given row. You then learned how to use the Flashback Transaction Query
feature, which enables you to see the changes made by particular transactions and also
to undo any undesirable changes. You can use this feature to audit certain transactions
or to recover from logical errors.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:50 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Two-Minute Drill 39
✓ 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 several
flashback features that rely on undo data.
❑ If you have a damaged disk or some physical corruption, you must still use the
traditional recovery techniques.
❑ Flashback technology uses undo data to query past data as well as to recover
from 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 guaranteed
undo retention, either when you create a tablespace, or later, by using the
ALTER TABLESPACE command.
❑ You can use either a system change number or regular clock time to tell Oracle
the 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 you
specify.
❑ The SCN_TO_TIMESTAMP SQL function converts an SCN to a calendar
time.
❑ The TIMESTAMP_TO_SCN function converts a timestamp to its
corresponding 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 backup
files and archived redo logs.
❑ The size of the logical error, not the size of the database, determines recovery
time when you use the flashback database feature.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:50 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
❑ 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 contents
of 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 RMAN
and SQL*Plus.
❑ If you’ve lost a datafile, or if you have resized a datafile during the relevant
period, you can’t use the Flashback Database feature.
❑ Since flashing back a database involves the rolling back of data to undo its
effects, you must roll forward the database using redo logs.
❑ To configure the Flashback Database feature, you must first set up your flash
recovery area and then set your retention target using the DB_FLASHBACK_
RETENTION_TARGET parameter. You can then turn the Flashback Database
feature on, with the ALTER DATABASE FLASHBACK ON command.
❑ You can turn the Flashback Database feature off with the ALTER
DATABASE FLASHBACK OFF command.
❑ If you disable the Flashback Database feature, Oracle deletes all the Flashback
Database 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 data
needed to satisfy your retention target.
❑ The FLASHBACK_SIZE column of the V$FLASHBACK_DATABASE_LOG
view shows the current size of flashback data.
❑ The V$FLASHBACK_DATABASE_STATS view helps you monitor the I/O
overhead of logging flashback data.
❑ You can turn flashback data collection off for individual tablespaces after taking
the tablespaces offline first.
❑ You can flashback a database using a log sequence number, an SCN, or a time
specified by TIMESTAMP .
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:51 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Two-Minute Drill 41
Flashback Drop
❑ The DROP TABLE command doesn’t drop a table right away, as in previous
versions.
❑ Oracle saves a table in the recycle bin after you issue the normal DROP TABLE
command.
❑ You can retrieve a dropped table by using the Flashback Drop feature.
❑ The command to retrieve a table is FLASHBACK TABLE table_name TO
BEFORE DROP.
❑ The DBA_FREE_SPACE view shows additional free space when you drop a
table, but Oracle doesn’t actually reclaim this space immediately.
❑ Oracle reclaims the space occupied by an object only after either the user or
the 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_RECYCLEBIN
and USER_RECYCLEBIN views, or the SHOW RECYCLEBIN command.
❑ The SHOW RECYCLEBIN command only shows those objects that you can
undrop.
❑ 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 it
stores in the recycle bin.
❑ In the FLASHBACK TABLE … TO BEFORE DROP command, you can give
the original name of the object or its system-given name after it is stored in
the recycle bin.
❑ The PURGE option of the DROP TABLE command will remove a table
permanently from the database or from the recycle bin, if the object is being
stored there after renaming it.
❑ If there are several identically named tables in the recycle bin, the PURGE
command will remove the first table that you dropped.
❑ The PURGE TABLESPACE command removes a tablespace from the recycle bin.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:51 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Flashback Table
❑ Using the Flashback Table feature, you can restore a table back to a point
in 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 back
will 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 object
privileges on the table.
❑ You must also have the ALTER, INSERT, UPDATE, and DELETE privileges
on the table.
❑ You must enable row movement before you can flashback a table.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:52 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Two-Minute Drill 43
❑ You can flashback a table using a past SCN or a past time period, using the
TIMESTAMP function.
❑ You can undo a Flashback Table operation by simply using the FLASHBACK
TABLE command again.
❑ You can’t flashback a system or remote table.
❑ The flashback operation is a single transaction, so either the entire operation
succeeds, or the whole operation will fail.
❑ If you shrink a table or change any nonstorage attributes of a table, you can’t
flashback a table to a time before you made these changes.
❑ Oracle doesn’t flashback statistics of recovered tables and indexes.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:53 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:53 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Self Test 45
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 file
B. Recovery from physical and logical corruption of a data file
C. Recovery from logical corruption of a data file
D. 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 tablespace
B. To specify the length of time Oracle must retain undo data in the flash recovery area
C. To specify the length of time Oracle must retain undo data in the data files
D. 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.vp
Monday, August 30, 2004 4:26:53 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
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 view
B. V$FLASHBACK_DATABASE_STATS view
C. 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,
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:54 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Self Test 47
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 user
B. When you truncate a table
C. When you drop a table
D. 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 TABLE
B. FLASHBACK ANY TABLE
C. 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 flashback
operation doesn’t preserve Oracle ROWIDs.
B. You must disable row movement in the table you are flashing back, because the flashback
operation doesn’t preserve Oracle ROWIDs.
C. You must disable row movement in the table you are flashing back, because the flashback
operation preserves Oracle ROWIDs.
D. You must enable row movement in the table you are flashing back, because the flashback
operation preserves Oracle ROWIDs.
16. What is the most likely outcome if Oracle violates any constraints during a flashback table
operation?
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:54 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
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.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:54 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Lab Question 49
LAB QUESTION
Create a table with an index, constraint, primary key, materialized view log, and a trigger. Drop the
table. Recover the table and its objects using the appropriate flashback techniques. Verify the results
to make sure you recovered all the objects of the table.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:54 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Flashback Database
5. þ D. When flashing back a database, the Flashback Dtabase logs you must apply will take
you to a point that’s a little bit before your target time. You must apply archive logs to roll
forward 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 since
there is no guarantee that a single archived log will be sufficient. The number of archived logs
you need will depend on the size of the archived logs and the amount of DML changes in your
database. C is wrong because you don’t have to apply any of the logs produced during the flashback
operation.
6. þ B and C. You must start the database in the MOUNT EXCLUSIVE mode before you can
configure the flashback database feature. If you have a single instance, the STARTUP MOUNT
command is sufficient. If you have a Real Application Cluster, you’ll have to use the analogous
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:55 PM
Color profile: Disabled
Composite Default screen 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 single
instance 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 the
flashback feature on.
7. þ A. Oracle will immediately delete all Flashback Database logs once you disable the flashback
database feature.
ý B is incorrect since Oracle never archives Flashback Database logs. C is wrong because Oracle
doesn’t clear the flashback buffer area when you disable the Dlashback Database feature. D is wrong
because Oracle deletes the Flashback Database logs immediately and doesn’t wait until it is under
space 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 views
that 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 DROP
TABLE 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 is
wrong because the Oracle Database 10g DROP TABLE command doesn’t drop a table right
away 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 objects
you can undrop. C is correct because the DBA_RECYCLEBIN view shows all the objects you
can 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 because
the 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 SELECT
statements 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 be
several 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 original
name. D is wrong since you can query after you drop it, provided it’s in the recycle bin and you
address it by its new, system-generated name.
12. þ B. When you use the PURGE RECYCLEBIN command (or the PURGE USER_RECYCLEBIN
command), 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.vp
Monday, August 30, 2004 4:26:55 PM
Color profile: Disabled
Composite Default screen 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 current
user, not just tables. D is wrong because you must have the SYSDBA privilege only to use the
PURGE DBA_RECYCLEBIN command.
Flashback Table
13. þ D. You can use the Flashback Table feature to take the table back to a previous point in
time. Therefore, it is ideal in situations where you’ve updated a table with the wrong WHERE
clause.
ý A is wrong because when you drop a user (and the user’s objects), you need to flashback
the entire database. B is wrong because when you truncate a table, you are better off
performing a flashback database operation. C is incorrect since you can use the flashback drop
feature 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 perform
the operation on any table in any schema. D is also correct since the FLASHBACK TABLE
privilege 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 operation
because Oracle doesn’t preserve ROWIDs during the operation.
ý B and C are wrong since you must enable, not disable, row movement. D is wrong since
Oracle doesn’t preserve ROWIDs.
16. þ C. If Oracle encounters any constraint violations, it abandons the flashback process and
leaves 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 leaves
the table in its original state, not the current state. D is wrong since you don’t have to disable all
constraints before you start the flashback table operation. You may leave them in an enabled state.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:56 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 9
Lab Answer 53
ý C and D are wrong since the flashback versions query doesn’t provide any information
about undoing changes; it is the flashback transaction query that provides you with the undo
information.
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 audit
transactions and to correct logical transaction errors.
ý B is wrong since FLASHBACK_TRANSACTION_QUERY is a view, not a procedure. C is
wrong since you can use the two features together.
20. þ C. The XID column belongs to the FLASHBACK_TRANSACTION_QUERY, and it maps
to 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 ANSWER
A 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 sysdba
SQL> alter system set db_flashback_retention_target = 1440; -- Ex: for two days.
SQL> alter database flashback on;
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:56 PM
Color profile: Disabled
Composite Default screen 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 loop
insert 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_name
from user_constraints
/
7. Again, display all the objects and constraints that belong to you. You can see that all the deleted
objects were renamed and still belong to you. Also, notice that Oracle has dropped and renamed
all of the table’s constraints as well..
SQL> select object_name, object_type
from user_objects ;
SQL> select constraint_name, constraint_type, table_name
from user_constraints;
8. Connect as SYSDBA and use the FLASHBACK TABLE command to recover a table and all its
possible dependent objects from the recycle bin.
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 the
constraints, were recovered successfully. The flashback procedures can’t recover materialized view logs.
P:\010Comp\CertPrs8\862-4\ch09.vp
Monday, August 30, 2004 4:26:56 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
Blind Folio 10:1
10
Automatic Storage
Management
CERTIFICATION OBJECTIVES
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:17:59 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
A utomatic Storage Management (ASM) is one of Oracle Database 10g’s most important
and revolutionary enhancements. The Oracle Managed Files (OMF) feature, which
has 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 management
tasks. ASM even enables you to bypass using a third-party Logical Volume Manager, mirroring
and striping your disks directly from within Oracle.
This chapter introduces you to ASM by first exploring its architecture. The
chapter 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.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:17:59 AM
Color profile: Generic CMYK printer profile
Composite Default screen 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 can
continue 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 single
database.
Benefits of ASM
ASM enables you to manage data by selecting the desired reliability and performance
characteristics for classes of data, rather than interacting with large storage systems on
a per-file basis. ASM file systems offer several benefits, including the following:
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:17:59 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
ASM Architecture
ASM has three important components: the ASM instance, disk groups, and ASM
files. ASM runs as a tiny enterprise of its own, with its own instance and background
processes, helping Oracle Database 10g manage its files.
ASM files are at the core of all ASM activity. You use ASM so you can use its
files for your database. Unlike in the case of normal Oracle operating system-based
database files, you don’t directly access ASM files. ASM files are part of larger entities
called ASM disk groups, which act as the default location for all your database files. You
use ASM disk groups to get to the ASM files. When you use ASM files, you don’t need
to 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 you
switch 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 logical
concepts 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-one
mapping 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 ASM
file can belong to only one disk group.
■ ASM allocates disk space in units called allocation units. All ASM disks are
partitioned in allocation units of 1MB.
In order to use an ASM file system, you must first start an ASM instance, which
is somewhat like a small database instance (without its own database files). The ASM
instance manages the disk groups, and its main purpose is to help the database access
the ASM files. The Oracle database contacts the ASM instance for information
about the ASM datafiles, and then accesses those files directly on its own. Let’s look
at the ASM instance in detail in the following section.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:17:59 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
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 operating
system authentication as SYSDBA or SYSOPER, or by using a password file, if you’re
connecting remotely.
Here’s a summary of the ASM instance’s functions:
Creating an Instance
To create an ASM instance, you must have the SYSDBA privilege. You can perform
most managing tasks (except creating the instance and a few others) with just the
SYSOPER privilege. Of course, you must also belong to an operating system group that
has the privileges to connect as a SYSDBA, a group like the typical dba group. If you
connect as a SYSDBA, you’ll have complete administrative privileges in an ASM
instance. If you connect as a user with the SYSOPER privilege, you’ll have the ability
to execute the following commands:
■ STARTUP/SHUTDOWN
You must issue all disk ■ ALTER DISKGROUP CHECK
group management commands from within ■ ALTER DISKGROUP MOUNT/DISMOUNT
an ASM instance. You database has no /REMOUNT
direct connection to ASM disk groups.
■ ALTER DISKGROUP OFFLINE
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:17:59 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
An ASM instance takes up about 100MB of space. Most ASM instances should
need no more than 64MB of SGA.
The following are the key initialization parameters that you must configure for
your ASM instance.
■ INSTANCE_TYPE You must set the
INSTANCE_TYPE parameter to ASM.
■ DB_UNIQUE_NAME You normally won’t
If you don’t explicitly set need to set this parameter, as it applies only
the INSTANCE_TYPE parameter to ASM, to ASM within a cluster or on a node. The
your ASM instance will fail to start. The parameter shows the unique name for a group
default value for this parameter is RDBMS, of ASM instances in a cluster or on a node.
which is applicable to normal Oracle The default value for this parameter is +ASM.
databases. Change this only if you think you’re going to
have more than one ASM instance running
on the same node.
■ ASM_POWER_LIMIT This parameter indicates the maximum speed to be
used by this ASM instance during a disk rebalance operation. When you add
or delete individual disks, ASM moves around an amount of data equal to the
storage you are adding or reducing from a disk group. ASM does this so it can
evenly redistribute the datafiles and balance I/O load across the disks. The
default for this parameter is 1, and the range is 1 to 11 (1 is slowest and 11
fastest). You have the option of specifying the rebalance speed by using the
POWER clause in the disk REBALANCE command, as in this example:
ALTER DISKGROUP dgroup1 REBALANCE POWER 4;
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:17:59 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
■ ASM_DISKGROUPS This parameter lets you specify the name of any disk
group that you want the ASM instance to automatically mount at instance
startup. The default value for this parameter is NULL. If you use an init.ora
text file, you must make sure to add the names of any disk groups that you
want to mount when the instance starts up. On the other hand, if you use an
SPFILE, Oracle will automatically make the necessary additions and deletions
to the SPFILE when you create, add, or drop a disk group.
The ASM instance uses the LARGE_POOL memory buffer. You should allocate
at least 8MB to this parameter, so it can serve the ASM instance effectively.
EXERCISE 10-1
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:00 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
Now, export your new ASM instance name and run the following commands:
$ export ORACLE_SID=ASM
$ sqlplus /nolog
SQL> connect / AS sysdba
Connected to an idle instance.
SQL> startup
ASM instance started
Total System Global Area 147936196 bytes
Fixed Size 324548 bytes
Variable Size 96468992 bytes
Database Buffers 50331648 bytes
Redo Buffers 811008 bytes
ASM diskgroups mounted
Using the Database Configuration Assistant (DBCA) makes it very easy to create
an 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 ASM
file 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 aready
exists on your server. If it does, the DBCA will then show you the disk groups being
managed by that ASM instance and ask you to choose the disk groups for your new
Oracle database.
If you choose ASM as your storage mechanism and you haven’t already configured
an ASM instance, the DBCA will automatically create one for you, after asking you
to 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, so
the operating sytem is aware of the new instance. On Windows systems, the DBCA
creates the Oracle service and makes the appropriate Windows Registry entries. The
DBCA also creates a parameter file and a password file for the new ASM instance.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:00 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
FIGURE 10-1 Using the DBCA to configure ASM during database creation
Master (RBAL) and ASM Rebalance (ARBn). Here’s what the two background
processes do:
In addition to the ASM instance background processes RBAL and ARBO, any
Oracle database instance that uses an ASM instance will have two new ASM-related
background processes, the RBAL and the ASM Background (ASMB) processes. This
is 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 ASM
instance. Remember that the ASM instance must be in operation in order for
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:00 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:00 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
When you issue a STARTUP FORCE command, the ASM instance is shut down
with a STARTUP ABORT command before restarting it. If you use the STARTUP
RESTRICT command, it prevents any client Oracle database instances from connecting
to the ASM instance.
There are some caveats, however, in using the SHUTDOWN command in the case
of an ASM instance. The up and down status of all Oracle databases connected to
an ASM instance critically depend on the ASM instance’s status. If you shut down an
ASM instance, all Oracle databases currently connected to it will also shut down. When
you issue a SHUTDOWN command to an ASM instance, it forwards the SHUTDOWN
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:00 AM
Color profile: Generic CMYK printer profile
Composite Default screen 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 ASM
instance.
When an Oracle database instance will also apply, in the same mode,
uses ASM files by connecting to an ASM to all connected databases. For example,
instance, it will stay open only as long if you shut down the ASM instance with |
as its connection to the ASM instance is the SHUTDOWN IMMEDIATE comamnd,
intact. If the connection terminates, the all databases connected to that instance
Oracle instance will terminate as well. Any will also shut down in the SHUTDOWN
SHUTDOWN command you use in the ASM IMMEDIATE mode.
If you shut down an ASM instance in the NORMAL mode (use the SHUTDOWN
NORMAL command or just the SHUTDOWN command), the ASM instance waits for
all connected Oracle database instances to terminate their ASM connections before
shutting down. In the IMMEDIATE (and TRANSACTIONAL) mode, an ASM instance
waits until all currently executing SQL in the dependent databases completes, but
doesn’t wait for the database instances to disconnect.
If you issue the SHUTDOWN ABORT command, the following events occur:
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:00 AM
Color profile: Generic CMYK printer profile
Composite Default screen 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.
ASM can perform both striping and mirroring tasks better than a third-party
LVM, because it understands the Oracle file types and uses an appropriate
strategy for each type.
ASM provides both performance and redundancy, the first through striping and
the second through the mirroring of data on the disk drives. Let’s look at these two
features in the following sections.
ASM Striping
ASM systems use disk groups and disks, with your database files being stored on the ASM
disks. The way you place (or write) your database files over ASM disks plays a critical
role 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:
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:00 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
all 20 of the disks. Thus, when you perform I/O operations, you can access your
file data in parallel, thus improving performance. You may want to use fine
striping for control files, online redo log files, and flashback files.
ASM Mirroring
Disk mirroring provides data redundancy. If you lose a disk, you can use its mirror disk
to continue operations without missing a beat. ASM mirroring is not the same as an
operating sytem-level mirroring scheme, although the goal of both is to provide
redundancy. Operating system-based LVMs mirror entire disks. ASM mirrors extents.
Whenever ASM allocates an extent (also called the primary extent, as opposed to a
mirrored extent), it simultaneously allocates a mirror copy of the extent to one of the
disks in the same disk group. A disk could have its mirror extents on one or several disks
in the disk group.
When any disk in a disk group fails, ASM reconstructs the failed disk on the fly by
using the mirrored extents from the other disks in the disk group. What’s the advantage
to mirroring extents rather than mirroring disks? When ASM is reconstructing a lost
disk, your storage system will take a smaller I/O hit, because several disks are sharing
the I/O necessary to reconstruct the failed disk device.
Failure Groups You can lose the services of a disk not only when the disk drive
fails, but also if a shared resource such as a disk controller bites the dust. When a
SCSI disk controller fails, all the disks connected to it will be inaccessible. A set of
disks 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 on
the 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 their
extents from disks that are outside the disk’s failure group.
Types of ASM Mirroring ASM supports three types of disk mirroring, each
providing a different level of data redundancy. When you create a new ASM disk
group, you need to decide the level of disk mirroring you need:
■ External redundancy This type really doesn’t provide any mirroring. You
choose this level of mirroring when you are using operating system storage
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:01 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
array protection. Disk groups under this redundancy level don’t have any
failure groups.
■ Normal redundancy This type provides two-way mirroring. Since you mirror
through the creation of failure groups, you must have two failure groups, each
group relying on a separate disk controller. Two-way mirroring means that
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 a disk in failure
group Group B. Thus, to support a normal redundancy level, you must create
at least two failure groups.
■ High redundancy This type provides three-way mirroring, which means you
should 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 in
Group B and a disk in Group C. Thus, to support a normal redundancy level,
you must create at least three failure groups.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:01 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
Oracle uses the search string of the format /devices/diska1 to find the disks
on your system. The use of the FAILGROUP and REDUNDANCY keywords is purely
optional. If you don’t specify the FAILGROUP keyword, each disk in the disk group
will be in its own failure group.
Here are the implications of using the HIGH REDUNDACY setting for the new
disk 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, it
also writes those extents to disks in the other two failure groups, GroupB
and GroupC.
When you create a new disk of the disk group in the inita.ora file, Oracle
group, ASM will automatically mount it. will automatically mount it the next time
Don’t forget to add the diskgroup’s name to you start the instance. Of course, if you’re
your init.ora text file, if you don’t already using an SPFILE instead, Oracle will
have it there when you start the database automatically write the new disk group’s
in the NOMOUNT mode. If you put the name name in the SPFILE.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:01 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
EXERCISE 10-2
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:01 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
You can use the UNDROP clause to keep a pending DROP DISK command from
taking place. If you’ve already dropped the disk, you can’t retrieve it with the UNDROP
clause. If you’ve used the optional FORCE clause when you dropped a disk, or if you’ve
issued a DROP DISKGROUP command, you can’t use the UNDROP clause. Here’s an
example demonstrating how to use the UNDROP clause in an ALTER DISKGROUP
command:
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;
The POWER clause specifes the parallelization level for the REBALANCE command.
In other words, the POWER clause controls the speed of a rebalance operation. The
higher the POWER clause value, the faster ASM will complete the disk rebalancing
operation. The default for POWER is 1 (the default value for the ASM_POWER_LIMIT
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:01 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
You can’t use ASM to create alert, trace, binary, and password files.
In the previous command, the DATAFILE clause specifies a file type, indicating
that the file is going to be used as a datafile (rather than as a control file or online
redo log file, for example). The CREATE TABLESPACE command addresses a disk
group (test_group1), not a specific disk in the group. Indeed, there is no reference
to any specific datafile either.
ASM does create a datafile, but it is meaningless to compare it with datafiles that
you now use in your Oracle databases. The new ASM datafile will be spread over all the
disks in the disk group test_group1. Thus, you can’t back up a single disk to copy
the datafile. Unlike conventional database files, Oracle always creates every ASM file
with a specfic redundancy level and striping policy. These redundancy and striping
policies are set permanently for the files, and you specify the attributes when you create
disk groups, as you’ve seen earlier in this chapter.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:01 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
Any database files that considers them ready for deletion), since they
you create by providing a user alias aren’t aren’t deemed OMF files. Only files created
automatically deleted by ASM (when Oracle by ASM will be automatically deleted.
All ASM files are OMF files, and Oracle will automatically delete them when you
don’t need them any longer. However, if you specify a user alias for an ASM file, that
file 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.
You can’t use an ASM file system for administrative files like trace files, audit
files, alert logs, backup files, export files, tar files, and core files. Oracle stores
the ASM filenames in the control files and the RMAN recovery catalog, just as
it 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 creating
a file or referencing an already existing file. The naming convention may also depend
on whether you creating a single files or multiple files at once. The four main ASM
filenaming conventions are fully qualified ASM filenames, numeric ASM filenames,
alias ASM filenames, and incomplete ASM filenames. Here is an overview of how
they work:
■ You use fully qualified ASM filenames only for referencing existing ASM files.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:01 AM
Color profile: Generic CMYK printer profile
Composite Default screen 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 referring
to existing ASM files. You use alias filenames with templates only for creating
new ASM files.
■ You use incomplete filenames (with or without an alias) only for file creation
operations.
where:
You can’t supply a fully qualified ASM filename while creating a new file.
Realize that no matter what naming convention you use for an ASM file, Oracle will
always automatically generate a fully qualified ASM filename when you create a file.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:01 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
Oracle also refers to a fully qualified ASM filename as a system alias. This is
because ASM will create and maintain these aliases, and you can’t modify them.
Here is an example of a numeric ASM filename (the file number is 251 and the
incarnation number is 8675309).
+dgroup2.251.8675309
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:01 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
You may also use a template while using an incomplete ASM filename, as shown
in the following example.
+dgroup1(datafile)
When you use an incomplete and striping characteristics for that file. For
ASM filename, the use of a template is example, when creating a datafile for a
optional. However, if you omit the template, tablespace, ASM will use the default template
ASM will use the default system template for a datafile file type if you don’t provide
for that file type to decide the redundancy a specific template in the filename.
Once you create the directory dgroup1/mydir as shown in the example, you can use
it to create alias ASM filenames, such as +dgroup1/mydir/control_file1
for a control file.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:02 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
Here’s an example of an alias ASM filename with a template (where the template
name is SPFILE):
+dgroup1(spfile)/config1
Adding Aliases
If you don’t use an alias for a file at the file creation time, you can always modify a
filename later to add an alias for the file. You can add a filename alias or rename an
existing alias name, using the ADD ALIAS or RENAME ALIAS clause of the ALTER
DISKGROUP statement. Here’s an example that shows how you can replace a fully
qualified 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 ALTER
DISKGROUP statement.
If you just drop a file alias, Oracle won’t drop the file. If you drop a file using
the DROP FILE command, however, Oracle drops both the file and its alias.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:02 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
■ For referring to an existing file, you can use a fully qualified filename, a numeric
filename, or an alias filename (but not an alias name with a template or an
incomplete filename with or without a template).
■ For creating a single file, you can use any kind of filename, with the exception
of a fully qualified filename.
■ For creating multiple files, you use only an incomplete filename or an incomplete
filename with a template.
Since the very purpose in using ASM is to eliminate the need to specify filenames
when managing database files, you must avoid using the ASM filenames as much as
possible, even though most SQL commands will let you use them just like normal
filenames. 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 archivelog
maxlogfiles 16
maxlogmembers 2
maxdatafiles 30
maxinstances 1
maxloghistory 226
logfile
group 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 use
the fully qualified ASM filenames for the datafiles. As you know, fully qualified ASM
filenames can’t be used to create an ASM file—they can be used only to refer to
ASM files. The RESETLOGS option will re-create (reinitialize) the redo log files, so
you can use the incomplete ASM filename format for the redo log files. You can use
incomplete filenames only to create new ASM files, as shown earlier in this chapter.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:02 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
Your tablespace datafile will then inherit the default attributes of a DATAFILE
template (such as the coarse striping level).
You may alter the attributes of a default system template or create you own unique
templates, if you wish. However, you may not delete the default system templates.
The following example shows how you can create your template, called
PRODUCTION, using the ALTER DISKGROUP command.
SQL> alter diskgroup test_group1 add template production attributes (mirror fine)
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:02 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
Once you create the production template, you can create an ASM datafile using
that template. The datafile you create will inherit the attributes you specified for your
new PRODUCTION template (two-way mirroring and fine striping). Here’s how you
would create your new datafile using the PRODUCTION template (the disk group
test_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;
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:02 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
■ 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
Oracle will create a SYSTEM tablespace and a SYSAUX tablespace in the disk
group dgroup1. An undo tablespace will also be created in dgroup1, if you’ve configured
automatic undo space management. A multiplexed redo file log group and a control
file will be created in both group1 and group2.
Adding datafiles is very easy in an ASM-based Oracle database, since you don’t
need to specify the datafiles. In the test database, you can use the following commands
to 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.vp
Tuesday, August 31, 2004 10:18:02 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
5. The RMAN script will back up the database and switch current datafiles
to the backups. The script also renames all current online redo log files
and re-creates all temporary files for the temporary tablespace.
6. Delete all the old Oracle database files.
When you migrate to an rename the existing redo log files and
ASM database, Oracle will automatically re-create all the temporary files for
create the control files for you. Oracle will the temporary tablespace.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:02 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
V_ASM_DISKGROUP
■ In an ASM instance, this view provides information about a disk group. In
a database instance, this view contains one row for every ASM disk group
mounted by the ASM instance.
V_ASM_CLIENT
■ In an ASM instance, this view identifies all the client databases using various
disk groups. In a Database instance, the view contains one row for the ASM
instance if the database has any open ASM files.
V$ASM_DISK
■ In an ASM instance, this view contains one row for every disk discovered by
the ASM instance. In a database instance, the view will only contain rows for
disks in use by that database instance.
V$ASM_FILE
■ The V$ASM_FILE view contains one row for every ASM file in every disk
group mounted by the ASM instance.
V$ASM_TEMPLATE
■ This view contains one row for every template present in every disk group
mounted by the ASM instance.
V$ASM_OPERATION
■ The V$ASM_OPERATION view provides information about any active
long-running operations in the ASM instance. Several ASM commands like
REBALANCE and RESIZE, take considerable time to complete. The command
prompt may return right away when you use these commands, however. You
can use the V$ASM_OPERATION view to monitor these types of long-running
operations.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:02 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
The exam concentrates evenly on all aspects an ASM instance? Rebalancing of disks in
of using ASM. From a conceptual point of a disk group is a significant ASM detail,
view, you need to understand the relationship and expect a question regarding rebalancing
between ASM files and disk groups on one operations or parameters.
hand, and Oracle database files on the other. You must understand how to refer to ASM
You must be able to answer questions on what files in different situations (for example, while
types of Oracle files you can store in an ASM creating a new control file). File aliases and
storage system. Pay particular attention to the file templates are also bound to show up in one
ASM instance parameter file and know the or more questions. Know how you use different
importance of each of the initialization filenaming syntax for various purposes (creating
parameters. The test focuses on the new and referring to files). What are file templates,
background processes in ASM-based systems, what do you define them on, and why do you
as well as the relationship between disk groups use them?
and failure groups. The test may also contain questions regarding
The test will probe into your knowledge migrating your current database to an ASM-
of the various startup and shutdown commands based system. You must clearly understand the
in an ASM-based system. Know the relationship steps of the migration process. Important points
between shutting down an ASM instance to remember are how Oracle handles the control
and the running of the connected Oracle file redo log files and datafiles for the newly
instances. For example, what happens to converted database. In other words, how does
the connected Oracle instances if you abort the database create the new files?
CHAPTER SUMMARY
This chapter reviewed the new Automatic Storage Management (ASM) feature of
Oracle Database 10g. ASM builds on the OMF files concept and now makes it possible
to manage large databases without needing to worry about naming database files. The
chapter showed you how managing disk groups is a far more efficient way of managing
storage than handling storage at the operating system file level.
You also learned how ASM rebalances files automatically when you add or remove
disks from disk groups. You learned how to configure and manage an ASM instance.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:02 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
You then learned how to create and manage disk groups. ASM files use special naming
conventions, 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 also
learned how to migrate your current databases to an ASM-based storage system.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:02 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
Two-Minute Drill 33
✓ 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 disk
groups, 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.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:03 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
❑ The Oracle instance using ASM will have two new processes: RBAL and
ASMB.
❑ The ASMB process is the link between the Oracle database instance and
the 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 the
instance will terminate as well.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:03 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
Two-Minute Drill 35
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, for
all 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 ASM
operations.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:03 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
SELF TEST
The following questions will help you measure your understanding of the material presented in this
chapter. Read all the choices carefully, because there might be more than one correct answer. Choose
all correct answers for each question.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:03 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
Self Test 37
B. Managing database files and communicating file metadata to the ASM instance using
ASM files
C. Managing disk groups and communicating file metadata to the RMAN
D. 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_TYPE
C. ASM_POWER_LIMIT
D. 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 activity
B. Performs disk rebalance work
C. Coordinates disk rebalance work
D. Manages the RBAL process
9. When you start an ASM instance in the MOUNT mode, what does the instance mount?
A. Oracle database files
B. Individual ASM disks that belong to a particular database
C. Disk groups specified by the ASM_DISKGROUPS parameter
D. The instance doesn’t have any database files, so it doesn’t mount anything
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:03 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:03 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
Lab questions 39
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, what
will 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 your
redo log files?
A. Rename them to ASM disk groups
B. Reinitialize the current online redo logs
C. Oracle will automatically copy them when you migrate to an ASM-based database
D. 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 operations
B. Monitor long-running operations
C. Monitor the migration to an ASM instance
D. Monitor all disk groups to see if disk rebalancing is necessary
LAB QUESTIONS
1. 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.vp
Tuesday, August 31, 2004 10:18:03 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:04 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
ý A, C, and D are wrong because none of these parameters are necessary to start an ASM
instance. 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. If
you don’t specify a value for this parameter, the disk-discovery process undertaken by ASM
instance will take a longer time, since it will look in all directories to which the ASM instance
has read/write access.
ý A is wrong because the ASM instance will start, even when you don’t specify a value for
the ASM_DISKSTRING parameter. B is wrong because the ASM instance will communicate
normally with the Oracle database. D is wrong because ASM will perform the disk-discovery
process, 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 ASM
instance.
ý A and C are wrong since it is the RBAL background process that coordinates the disk
activity, 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 specify
by using the ASM_DISKGROUPS initialization parameter.
ý A is wrong because ASM instances don’t mount Oracle database files. B is wrong since an
ASM instance mounts disk groups, not individual disks that are part of the disk group. D is wrong
since the ASM instance does mount disk groups.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:04 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
Migrating to ASM
18. þ A and D. A is correct because Oracle will create non-OMF files in that directory. D is
correct 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 Oracle
will use that directory.
19. þ A. When you migrate your database to ASM files, you must individually rename each of
your 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 since
you 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 monitor
long-running ASM operations.
ý A, C, and D are wrong since the V$ASM_OPERATION doesn’t help you monitor any of
these things.
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:04 AM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 10
Lab Answers
1. To add a disk to an existing disk group, use the following:
SQL> alter diskgroup dgroup1
add failgroup controller1
‘/dev/rdsk/c0t3d0s2’ NAME a5;
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_written
from 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, striped
from v$asm_file;
P:\010Comp\CertPrs8\862-4\ch10.vp
Tuesday, August 31, 2004 10:18:04 AM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
Blind Folio 11:1
11
Enhancements in
Analytical SQL and
Materialized Views
CERTIFICATION OBJECTIVES
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:46 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
T his chapter deals with analytical SQL enhancements to support data warehousing
applications and enhancements to several materialized view features. You’ll start off
with a review of the analytical SQL enhancements in Oracle Database 10g. The MERGE
statement is now enhanced, with support for conditional statements. The new partitioned
outer joins help in the densification of data, which will yield better calculation performance for
several analytical queries, especially those dealing with time-series data. The brand-new MODEL
SQL clause provides spreadsheet-like array computations that are highly scalable, directly from
within your Oracle database.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:47 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
has enhanced the MERGE statement in Oracle Database 10g. Let’s review the MERGE
statement prior to Oracle Database 10g, and then cover its new capabilities in the
following sections.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:47 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
The preceding MERGE statement will first update the prod_list_price and the
prod_status columns of the product table wherever the join condition is true. The
join condition (d..prod_id = s.prod_id) joins the two tables, product (the source
table) 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 MERGE
statement.
■ The MERGE statement will delete only the rows included in the join condition
specified by the ON clause.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:48 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
Oracle Database 10g provides an extension of the SQL outer join concept to
improve the performance of analytical functions when they encounter data with
missing values for some combinations of dimension values. In the following sections,
I’ll introduce you to some basic data warehousing concepts and analytical processing
features, before explaining how to use partitioned outer joins to handle problems
caused by sparse data (data with missing values).
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:48 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:48 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
Data Densification
The concept of data densification has to do with the fact that you may view your
data in two different forms:
■ Dense data is when you have rows for all possible combinations of dimension
values, 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 of
dimension 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 number
of rows for groups of dimensions. This makes it harder for you to use some SQL
analytical functions such as the lag and lead functions, which help you compute
period-to-period changes. These functions perform slowly, and the report formatting
would be uneven. Performance takes a big hit when you don’t have a row for each
combination of the dimensions.
Partitioned outer joins help turn sparse data into
dense data, thus helping you avoid the drawbacks
of using sparse data for analytical computations.
The partitioned outer join When you use a partitioned outer join, Oracle
is ideal for time dimensions, but it can be replaces the missing values along any dimensions.
used for any kind of dimensions. You thus have faster performance and a better
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:49 PM
Color profile: Disabled
Composite Default screen 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 partitioned
outer joins work after a quick review of Oracle’s join methods.
■ Natural joins A natural join is based on all columns that have the same
name in the two tables. It selects rows from the two tables that have equal
values in the relevant columns.
■ Inner joins An inner join (also called a simple join) is a join of two or more
tables that returns only those rows that satisfy the join condition. An inner
join is the default join type for a join operation.
■ Outer joins An outer join extends the result of an inner join. An outer join
returns all rows that satisfy the join condition and also returns some or all of
those rows from one table for which no rows from the other satisfy the join
condition.
■ A left outer join performs an outer join of tables A and B and returns all
rows from table A. For all rows in table A that have no matching rows in
table B, Oracle returns NULL for any SELECT list expressions containing
columns of table B.
■ A right outer join performs an outer join of tables A and B and returns all
rows from table B. For all rows in table B that have no matching rows in
table A, Oracle returns NULL for any SELECT list expressions containing
columns 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.vp
Tuesday, August 31, 2004 1:57:49 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
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 following
condition:
partition by product order by time_id
The query output will be partitioned into groups by the product column. If there were
two products—bottles and cans—there would be two partitions. Once Oracle logically
partitions 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 outer
joins, consisiting of a join of each of the logical partitions with the other table in the
join. In the example, the bottle and can partitions are joined to the other table by
using the time_id column.
Sparse Data
Let’s look at a typical set of sparse data by using the following example, which shows the
weekly 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) sales
from sales s, times t, products p
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:49 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
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 28
in the year 2005.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:50 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
SUM(amount_sold) sales
from sales s, times t, products p
where s.time_id = t.time_id and s.prod_id = p.prod_id and
p.prod_name in ('Bounce') and
t.calendar_year in (2004,2005) and
t.calendar_week_number between 20 and 30
group by p.prod_name, t.calendar_year, t.calendar_week_number) v
partition by (v.product_name)
right outer join
(select distinct calendar_week_number week, calendar_year year
from times
where calendar_year IN (2004, 2005) and
calendar_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 801
Bounce 2004 21 4062.24
Bounce 2004 22 2043.16
Bounce 2004 23 2731.14
Bounce 2004 24 4419.36
Bounce 2004 25 0
Bounce 2004 26 0
Bounce 2004 27 2297.29
Bounce 2004 28 1443.13
Bounce 2004 29 1927.38
Bounce 2004 30 1927.38
Bounce 2005 20 1483.3
Bounce 2005 21 4184.49
Bounce 2005 22 2609.19
Bounce 2005 23 1416.95
Bounce 2005 24 3149.62
Bounce 2005 25 2645.98
Bounce 2005 26 0
Bounce 2005 27 2125.12
Bounce 2005 28 0
Bounce 2005 29 2467.92
Bounce 2005 30 2620.17
For the four added rows that had no sales data, the NVL function transformed the
NULL values to 0. This is how partitioned outer joins convert sparse data into a
dense form. You may also choose to replace the NULL values with the most recent
non-NULL values. To do this, you can add the IGNORE NULLS clause to the Oracle
LAST_VALUE and FIRST_VALUE functions.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:50 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:50 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
multidimensional array and applies your business rules to the individual elements of
the array. From the application of various user-specified business rules, Oracle derives
updated as well as newly created data. However, you won’t actually see an array as
your final form of the output, since Oracle will format the new and updated data
into 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.
The next section looks at how the MODEL feature uses rules to modify your
multidimensional array data.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:51 PM
Color profile: Disabled
Composite Default screen 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 the
MODEL clause must apply to its multidimensional array data. For example, you could
specify 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 the
sales of Kleenex in the years 2003 and 2004.
When you specify the RULES keyword, you may also want to indicate whether the
rules you are specifying will be transforming existing data or inserting new rows of
data. By default, the RULES keyword operates with the UPSERT specification. That
is, 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 UPSERT
sales (‘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 for
Kleenex in the year 2005, Oracle will update that row with the values derived from
applying the rule formula. If there is no such row, Oracle will create a new row to show
the 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 UPDATE
option for all the rules, as shown here:
MODEL
…
RULES UPDATE
Sales (‘Kleenex, 2005) = sales (‘Kleenex, 2003’) + sales (‘Kleenex, 2004)
…
(MORE RULES HERE)
The previous two examples demonstrated how to apply different rule options at
the MODEL clause level. You may also specify rule options at the individual rule
level, as shown here:
RULES
(UPDATE sales (‘Kleenex, 2005) = sales (‘Kleenex, 2003’) + sales (‘Kleenex, 2004)
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:51 PM
Color profile: Disabled
Composite Default screen 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.
If you specify a rule option level, the MODEL level option applies to all
at the rule level, it will overrirde the RULES the rules. If you don’t specify an option
specification at the MODEL clause level. If at the MODEL level, the default UPSERT
you don’t specify a rule option at the rule option will prevail.
You can specify that Oracle should evaluate the rules in either of the following
two ways:
When I say that the MODEL doesn’t update or insert rows into the table
clause will create or update rows, I strictly or views. To change the base table data, you
mean that the changes are shown in the must use the traditional INSERT, UPDATE,
MODEL clause output. The MODEL clause or MERGE statements.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:51 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
Sales units are the measure in this example. The query partitions the data by country
and form the measure cells consists of product and year combinations. The three rules
specify the following:
■ Total sales of Kleenex in 2005 are forecast as the sum of Kleenex sales in
the years 2003 and 2004.
■ Total sales of Pampers in the year 2005 are forecast to be the same as the
sales in 2004.
■ Total product sales in 2005 are computed as the sum of the Kleenex and
Pampers sales in 2005.
Here’s the output generated by using the preceding SQL statement with the MODEL
clause (the new data created by the MODEL clause is shown in boldface here):
COUNTRY PRODUCT YEAR SALES
-------------------- --------------- ---------- ----------
Mexico Kleenex 2002 2474.78
Mexico Kleenex 2003 4333.69
Mexico Kleenex 2004 4846.3
Mexico Kleenex 2005 9179.99
Mexico Pampers 2002 15215.16
Mexico Pampers 2003 29322.89
Mexico Pampers 2004 81207.55
Mexico Pampers 2005 81207.55
Mexico All_Products 2005 90387.54
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:52 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
The SELECT clause first retrieves the product, year, and sales data for the two
countries (Mexico and Canada) and feeds it into the MODEL clause. The MODEL
clause takes this raw data and rearranges it into a multidimensional array, based on
the values of the PARTITION BY (country) and DIMENSION BY (product and
year) clauses. After the MODEL clause creates the array, it applies the three formulas
listed 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 the
new data that the MODEL clause has calculated from the three rules supplied in the
MODEL clause. The MODEL clause applies the rules within each partition of data.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:52 PM
Color profile: Disabled
Composite Default screen 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 you
design and evaluate materialized views.
Once you create a materialized view, you have two main concerns:
In the next two sections, we’ll look at the fast refresh feature and query rewriting
mechanisms, and then look at the new Oracle Database 10g procedure that helps
you optimize your materialized views.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:52 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
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 also
be a part of the SELECT list.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:53 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
The SQL Access Advisor can help you by suggesting ideal materialized views for
the detail tables in a query, and this advisor can also help you create the materialized
views. Once you create the materialized views, you can use various procedures of
the DBMS_MVIEW package to optimize your materialized views. Here is a summary
of the two key procedures of the DBMS_MVIEW package that help in understanding
the capabilities of materialized views and potential materilaized views, especially
concerning rewrite availability:
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:53 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
MATERIALIZED VIEW as its input and performs the following materialized view
tuning functions:
■ Redefine materialized views so they refresh fast as well as use query rewrite, if
the materialized views are currently not using these features for some reason.
■ Fix materialized view log problems that may be keeping the view from using
the fast refresh mechanism. These problems include verifying that a materialized
view log exists in the first place. If the materialized view log exists, it may have
problems, like missing columns, which prevent its use by a materialized view.
■ If a materialized view turns out to be nonrefreshable, break it up into
submaterialized views that are eligible for a fast refresh. The parent materialized
view can then reference the submaterialized views, thus getting around its
inability to refresh fast.
If a materialized view isn’t fast refreshable, the data in the materialized view will
become stale, thus making your queries progressively worthless. When you find that
a materialized view isn’t fast refreshable, it’s usually because one or more of the fast
refresh restrictions aren’t satisfied. The DBMS_ADVISOR.TUNE_MVIEW procedure
provides you with the necessary SQL statements that you need to implement to ensure
that you can fast refresh your materialized views.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:53 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
The preceding code will populate the new DBA_TUNE_MVIEW view, which you must
query to see how you can change your materialized view to make it fast refreshable as
well as capable of using query rewrite. The DBA_TUNE_MVIEW view has the following
structure:
SQL> desc dba_tune_mview
Name Null? Type
----------------------------------------- -------- -------------
OWNER VARCHAR2(30)
TASK_NAME VARCHAR2(30)
ACTION_ID NOT NULL NUMBER
SCRIPT_TYPE VARCHAR2(14)
STATEMENT CLOB
SQL>
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_NAME
variable that I highlighted in the previous PL/SQL code block.) The ACTION_ID
column shows the command order number. The SCRIPT_TYPE column can take
values of CREATE or DROP (or UNKNOWN). The CREATE value is for the new
materialized view recommendation. The DROP value shows the materialized view
that the TUNE_MVIEW procedure wants you to drop. The STATEMENT column of
the view shows the recommended materialized view changes that make your materialized
view 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 a
text file.
Here’s the basic syntax of a query on the DBA_TUNE_MVIEW view:
SQL> select statement
from dba_tune_mview
where task_name = :task_name
order 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 your
materialized view. In this case, the DBMS_ADVISOR.TUNE_MVIEW procedure
might recommend the following changes to make your materialized view eligible
for a fast refresh of its materialized view logs. (Note that the new materialized view
recommendation replaces the DISTINCT clause in the original materialized view
with the COUNT(*) and GROUP BY clauses.)
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:54 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
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 recalcitrant
materialized view.
The third line shows how you can use the ROWIDs to modify the materialized
view. This materialized view will now be eligible for query rewrite, as long as you
make sure that you create the following pair of materialized view logs, one for each
of the tables in the materialized view.
SQL> create materialized view log onemployees
with sequence, rowid
including new values;
SQL> create materialized view log on departments
with sequence, rowid including new values
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:54 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
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 materialized
view in order to make it eligible for the fast refresh feature. The following types of situations
call for a materialized view decomposition:
Any time you change a base table’s partition scheme, the relevant
materialized view rows become stale.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:55 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
Join Dependency
You can now use a PCT-based refresh if your MV
Oracle Database 10g contains a join-dependent expression of one of its
extends the use of PCT to list-partitioned tables. A table is a join-dependent table if you
tables, enables the use of ROWID columns equijoin it with a partitioned base table on its
as partition markers, and lets you use a partioning key column. An expression consisting
PCT refresh if a materialized view contains of columns from the resulting equijoin is a join-
a join-dependent expression. dependent expression.
■ You are limited to range partitioning only (for both the base tables and
the materialized view), and the partitioning bounds must be the same for the
materialized 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 Refresh
The PCT feature automatically refreshes your materialized view when there are partition
maintenance operations in the underlying base tables. However, you may sometimes wish
to manually use a PCT-based refresh, even in the absence of any base table partitioning
scheme 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’)
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:55 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
Instead of running the original query, the hint throws the following error and
stops the execution of the SQL statement.
ORA-30393: A query block in the statement did not rewrite
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:56 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
To obtain the output into a table, you must run the utlxrw.sql script (located
in the $ORACLE_HOME/rdbms/admin directory) before calling EXPLAIN_
REWRITE. This script creates a table named REWRITE_TABLE in the current
schema.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:56 PM
Color profile: Disabled
Composite Default screen 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)
■ JOIN_BACK_TBL provides the name for the table with which a join back
operation was performed in the materialized view.
■ JOIN_BACK_COL provides the name of the column involved in the join
back 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.
■ If the materialized join view contains a self join in its FROM clause, you must
include the ROWID columns for each instance in the SELECT list. The
materialized join view log must contain all the ROWID coumns as well.
■ If the materialized join view has an inline view (or a named view), the
database must be able to perform complete view merging. Once the view
merging is done, the SELECT list must have the ROWID columns for all the
tables in the FROM clause.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:56 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
■ If you are dealing with remote tables in materialized join views, make sure
that all of the tables are on the same site. The SELECT list must have the
ROWID columns for all the tables in the FROM clause.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:57 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
The exam will test your knowledge of the The MODEL clause is too important not to
enhancements to the DBMS_ADVISOR be touched by the exam. You must thoroughly
package. You must understand how the new understand the concepts of partitions, measures,
TUNE_MVIEW procedure helps fast refresh and dimensions. What role do rules play in a
and query rewrite when you use materialized MODEL clause? What are the default semantics
views. You must remember the specific ways of rules in a MODEL clause (UPSERT)? What
in which the TUNE_MVIEW procedure can is the difference between sequential order and
help in tuning materialized views (decomposition automatic order when you are evaluating a set
of nonwritable materialized views, for example). of rules?
Under what conditions is it good to decompose Expect a question about the PCT feature
a materialized view? How does the TUNE_ on the exam. What enhancements has Oracle
MVIEW procedure contributein promoting introduced for PCT in Oracle Database 10g?
a fast refresh of a query? You must also be What are the preconditions for using the
conversant with the important procedures of TRUNCATE PARTITION command when
the DBMS_MVIEW package. What does the you are performing PCT operations?
EXPLAIN_MVIEW procedure help you do? You must know how to enable the automatic
The exam will test your knowledge of the query rewriting feature in Oracle Database 10g
MERGE statement enhancements. Exactly (hint: it is automatic!). What hint will stop
what rows will the DELETE clause delete in query execution if the query fails to rewrite?
a MERGE statement? Expect a query on materialized join views as
You most likely are going to encounter a well. What are the conditions under which
question on the new partitioned outer join Oracle supports fast refresh for materialized
feature. Know that it is simply an extension join views?
of the outer join feature in previous versions.
CHAPTER SUMMARY
This chapter started by reviewing the two new enhancements to the MERGE command
in a SQL statement. You then learned about the difference between dense and sparse
data, and how to densify data using the new partitioned outer join enhancement.
The SQL MODEL clause offers you tremendous analytical capabilities when dealing
with interrow calculations in a data warehouse setting. This chapter provided a basic
review of the MODEL clause enhancement, after first reviewing some essential data
warehousing concepts.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:57 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:57 PM
Color profile: Disabled
Composite Default screen 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’s
UPDATE or INSERT clause to conditionally update or insert data.
❑ In addition to the INSERT and UPDATE clauses, you can now use a DELETE
clause in a MERGE statement.
❑ The DELETE clause in a MERGE statement will delete only rows included in
join condition (specified by the ON clause).
❑ The DELETE clause of the MERGE statement evaluates only the post-updated
values of rows.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:58 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
Two-Minute Drill 33
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:58 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:57:59 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
Two-Minute Drill 35
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:58:00 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
SELF TEST
The following questions will help you measure your understanding of the material presented in this
chapter. Read all the choices carefully because there might be more than one correct answer.
Choose all correct answers for each question.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:58:00 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
Self Test 37
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:58:01 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
C. The way the MODEL clause addresses the individual cells of an array
D. The way the MODEL clause addresses the rules
10. What can you derive by using a MODEL clause?
A. Both updated and deleted data
B. Both updated and newly created data
C. Only updated data
D. Only newly changed data
11. By default, the RULES keyword operates with which specification?
A. UPDATE specification
B. INSERT specification
C. UPDATE and UPSERT specifications
D. UPSERT specification
12. What will the RETURN UPDATED ROWS keyword in a MODEL clause do?
A. Return only the new rows, not the updated rows
B. Return only the updated rows, not the new rows
C. Return both the updated and the new rows
D. Return all rows that are going to be deleted
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:58:01 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
Self Test 39
A. EXPLAIN_REWRITE procedure
B. TUNE_MVIEW procedure
C. MVIEW_EXPLAIN procedure
D. EXPLAIN_MVIEW procedure
16. What does the TUNE_MVIEW procedure do?
A. Automatically creates any necessary materialized view logs
B. Recommends the creation of any necessary materialized view logs
C. Automatically creates the materialized view
D. 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 procedure
B. The output of the CREATE_MVIEW procedure
C. The output of the EXPLAIN_MVIEW procedure
D. 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 variable
B. The STATEMENT_ID column
C. The VIEW_ID column
D. The TASK_NAME variable
19. What does the REWRITE_OR_ERROR hint do?
A. Rewrites the query if it doesn’t lead to any errors
B. Stops executing a query if it can’t rewrite it
C. Sends out a report of all the rewrite errors
D. 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 tracking
feature?
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.vp
Tuesday, August 31, 2004 1:58:01 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
LAB QUESTION
Compare 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 Oracle
software.
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.vp
Tuesday, August 31, 2004 1:58:01 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:58:02 PM
Color profile: Disabled
Composite Default screen 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 missing
values. D is wrong because you don’t provide the values for the missing data—you use the
partitioned outer joins to do that job for you.
8. þ D. The PARTITION BY clause will partition the rows in the output based on the
expression you provide inside the PARTITION BY clause.
ý A and C are wrong because the PARTITION BY clause doesn’t actually partition the
tables. B is wrong because the output isn’t partitioned into equal segments, but rather is
partitioned on the basis of the expression you provide within the PARTITION BY clause.
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:58:03 PM
Color profile: Disabled
Composite Default screen 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 view
will or won’t rewrite a query. B is wrong because the TUNE_MVIEW procedure helps you in
making 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 of
necessary materialized view logs, to make a query fast refreshable.
ý A, B, and D are wrong since the TUNE_MVIEW procedure doesn’t automatically create
any views, logs, or a fast refresh of a materialized view. It’s a purely advisory view. You can
implement 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_MVIEW
view (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 an
automatic error.
ý A is wrong because the hint doesn’t rewrite the query if it doesn’t have errors. C is wrong
since the hint doesn’t send a report of the errors—it merely sends a single error message when
a query fails to rewrite. D is wrong since the hint does not force a query rewrite when there are
errors—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 based
on list-partitioned tables.
ý A is wrong because you could use the PCT feature with partitioned tables in earlier versions
of Oracle. Similarly, B and C are wrong since you could use the PCT feature in both rule- and
hash-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 as
2 select distinct time_id, prod_id, quantity_sold
3 from sales
4 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.vp
Tuesday, August 31, 2004 1:58:04 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
2. Create a second table with four rows in it, one for each day of January 2005, and check the
data in the table after creating it, as in this example:
SQL> begin
2 for i in 0..3 loop
3 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-2005
03_JAN-2005
04_JAN-2005
05_JAN-2005
3. Create a regular outer join between tables s1 and t1. The following example uses the Oracle
function CUMULATIVE, to produce cumulative values for each day, from the quantity_sold
column values. The regular outer join will show a day, even if there aren’t any matching values
for it in the s1 table. This query shows a row for the 05-Jan-2005 date, even though there are
no product sales for that date (shown in table s1).
SQL> select prod_id, time_id, quantity_sold,
2 sum(quantity_sold) over
3 (partition by prod_id
4 order by time_id)
5 as cumulative
6 from s1
7 right outer join t1
8 using (time_id)
9 order by prod_id, time_id;
PROD_ID TIME_ID QUANTITY_SOLD CUMULATIVE
---------- ----------- ------------- ----------
13 02_JAN-2005 1 1
13 04_JAN-2005 1 2
14 02_JAN-2005 1 1
14 03_JAN-2005 1 2
05_JAN-2005
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:58:04 PM
Color profile: Disabled
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 11
4. Finally, use a partitioned outer join, to see how you can improve over the results obtained with
just a regular outer join. The partitioned outer join in this example partition-joins the data by
the prod_id column, and shows rows for each day one of the products wasn’t sold. Product ID 13
didn’t sell on the third and fifth of January 2005. Product ID 14 didn’t sell on the fourth and
fifth. However, the partitioned outer join ensures that you see rows for both the products, for
all the days.
SQL> select prod_id, time_id, quantity_sold,
2 sum(quantity_sold) over
3 (partition by prod_id
4 order by time_id)
5 as cumulative
6 from s1
7 partition by (prod_id)
8 right outer join t1
9 using (time_id)
10* order by prod_id, time_id;
PROD_ID TIME_ID QUANTITY_SOLD CUMULATIVE
---------- ----------- ------------- ----------
13 02_JAN-2005 1 1
13 03_JAN-2005 1
13 04_JAN-2005 1 2
13 05_JAN-2005 2
14 02_JAN-2005 1 1
14 03_JAN-2005 1 2
14 04_JAN-2005 2
14 05_JAN-2005 2
8 rows selected
SQL>
P:\010Comp\CertPrs8\862-4\ch11.vp
Tuesday, August 31, 2004 1:58:04 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
Blind Folio 12:1
12
Miscellaneous
New Features
CERTIFICATION OBJECTIVES
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:27 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
T he first part of this chapter deals with enhancements in Oracle’s VPD (Virtual Private
Database) feature. You’ll learn about new VPD features like applying column-level
security 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 Oracle
Database 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. The
exciting new topic of regular expressions provides POSIX-like regular expression
capabilities that help you write more powerful SQL search statements. You’ll also
learn 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 Private
Database and auditing areas.
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:27 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
Column-Level VPD
Oracle 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 policy
functions) only when you access certain security-relevant columns. For example, if you
define salary as a security-relevant column in table emp, then employees can continue
to freely access information in all the other columns. However, Oracle will dynamically
modify any SQL statements that refer to the salary
column in order to protect sensitive data. Since
Oracle already provides row-level access control
A column-level VPD policy (FGAC), this new column-level access control
applies only to tables and views and not to extends access control to the individual data item
synonyms. You may apply a policy function level in a table. Note that Oracle will rewrite a
to queries as well as DML statements. SQL statement only if a SQL query accesses the
security-relevant columns.
Types of Behavior
You 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 with
the sec_relevant_cols parameter of this package. When you use column-level
VPD, you have a choice of two types of behavior by the policy—default behavior and
column-masking behavior. Default behavior will restrict the number of rows returned by
any query that contains the security-relevant columns(s). Column-masking behavior, on
the other hand, will return all the rows, but show null values for the security-relevant
columns in those rows.
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:27 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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;
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 not
part of department 5.
create or replace function test_function (objowner IN 2, varchar2
objname IN varchar2)
return varchar2 as
con varchar2 (200);
begin
con := 'deptno = 5';
return (con);
end test_function;
/
Create the VPD Once you create the test_function policy function, you
can create the VPD by applying it to a table, as shown here:
begin
dbms_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;
/
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:28 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 10000
5 7566 JONES MANAGER 2975
5 7788 SCOTT ANALYST 3000
5 7876 ADAMS CLERK 1100
5 7902 FORD ANALYST 3000
5 rows selected.
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:28 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
You can grant the privilege GRANT EXEMPT ACCESS POLICY to a user
so that he or she may bypass a security policy, as shown here:
Static Policies
Oracle Database 10g lets you configure static policies. The database executes a static
policy function just once, and caches the predicate resulting from the policy evaluation
in 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 policy
predicate, you might want to configure a static policy.
A static policy is one that will always return the same WHERE clause, such as
deptno=something so that even though the “something” may be different for
each statement executed against the table, the actual SQL doesn’t change (a bit like
a bind variable). But a dynamic policy is one that could generate a different WHERE
clause. For instance, the function could query usercontext and, depending on the
result, generate different WHERE clauses. Thus, some users would get deptno=…,
and others would get mgr=…, for example. So flagging a policy as static is simply
telling Oracle that the function can only return one value (possibly containing a
variable) no matter who executes it, whereas a dynamic policy is based on a function
that has several different return values. If you tell Oracle that the policy will always
get 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, as
shown here:
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:28 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
begin
dbms_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.static
sec_relevant_cols=>'salary , commission');
end;
In the preceding example, the highlighted line shows how you specify a static policy
type. The default policy type in Oracle Database 10g is dynamic.
If you want to allow the sharing of the same static policy function over different
database objects, you can set the POLICY_TYPE parameter to the following value:
POLICY_TYPE => DBMS_RLS.SHARED_STATIC
The default Oracle policy the same business policy over several
type in Oracle Database 10g is dynamic, database objects, you can do so by
but you can configure static and context- sharing either a static or a context-
sensitive policies. If you want to enforce sensitive policy.
Context-Sensitive Policies
You may sometimes want to configure a policy such that it will change based on
any session context changes. That is, each time certain context attributes within a user’s
session change, you want the policy function to automatically change as well. In cases
like this, you can use the new context-sensitive policies. When you use a context-sensitive
function, 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 application
context change. Here’s our DBMS_RLS example, this time with a context-sensitive
policy type.
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:28 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
begin
dbms_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_sensitive
sec_relevant_cols=>'sal,comm');
end;
If you want to allow the sharing of the same context-sensitive policy function over
different database objects, you can set the POLICY_TYPE parameter to the following
value when you use the DBMS_RLS.ADD_POLICY procedure:
POLICY_TYPE => DBMS_RLS.SHARED_CONTEXT_SENSITIVE
Auditing Enhancements
Oracle databases provide several auditing mechanisms. You have the option to audit
database 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 creates
audit records based on the specific query and the data that the SQL statement accesses.
In Oracle Database 10g, enhancements to auditing features include uniform audit
trails for standard auditing and FGA, enhanced auditing of enterprise users, and several
FGA enhancements. Let’s review Oracle Database 10g auditing enhancements by
looking at uniform audit trails for standard and fine-grained auditing.
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:28 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
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 columns
of this view.
In addition, the following attributes are common to both standard and FGA audit
trails:
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:28 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
■ Oracle Database 10g will audit a DML statement with an FGA policy defined
on 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 will
be audited only if it references the column(s) and the data meets the FGA
policy requirements.
■ Oracle always audits a qualified DELETE statement, regardless of whether
you have specified relevant columns or not.
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:28 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
■ Client identifier
■ Service name
■ Combinations of service name, module name, and action name
These three new dimensions for collecting statistics offer you new and powerful
means of monitoring problems in multitier architectures. The new statistics focus on
the clients and services, rather than database sessions and SQL statements. With the
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:28 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
help of metrics and statistics for these new dimensions, you can improve performance
monitoring 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 to
trace a client’s work on an end-to-end basis. The middle tier would frequently transfer
the same client to different sessions, making tracing of the client extremely difficult.
In Oracle Database 10g, the new variable CLIENT_IDENTIFIER enables you to trace
the 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 application
server.
You can see the value of the CLIENT_IDENTIFIER variable in two ways. You can
use the V$SESSION view (CLIENT_IDENTIFIER column) or use the following
query, which makes use of the system context.
SQL> select sys_context('USERENV', 'CLIENT_IDENTIFIER')
2 from dual;
SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER')
------------------------------------------
salapati
SQL>
Client-Level Statistics
You use the CLIENT_ID_STAT_ENABLE procedure to enable the collection of
statistics for a client identifier, as shown here:
SQL> execute dbms_monitor.client_id_stat_enable(<client_id>);
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:28 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 Statistics
You use the SERV_MOD_ACT_STAT_ENABLE procedure to enable the collection of
statistics 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.
Client Identifier Tracing You use the following procedures to enable and disable
tracing for client identifiers:
Service, Module, and Action Tracing You use the following procedures to
enable and disable tracing for combinations of service names, module names, and
action names on a global basis.
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:29 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:29 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
UTL_COMPRESS Package
Oracle Database 10g provides the new UTL_COMPRESS package to compress and
uncompress data, with the compressed output compatible with the output of the familiar
GZIP and GUNZIP compression utilities. You may want to compress data to save on
storage 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 is
an inverse relationship between speed and quality of the compression job.
UTL_MAIL Package
In 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 simple
email notes. In addition, you had to understand the underlying SMTP protocol features
to 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 using
simple PL/SQL API. You use simple parameters to specify email components such as
sender, receiver, copies, blind copies, subject, and so on.
In order to use the UTL_MAIL package to send email, you must first execute the
utlmail.sql script located in your ORACLE_HOME/rdbms/admin directory.You must
also execute the prvtmail.plb script located in the same directory. Here’s a simple
example that shows how to send an email using the UTL_MAIL package:
SQL> execute utl_mail.send -
> (sender => 'salapati@netbsa.org', -
> recipients => 'mpotts@netbsa.org', -
> subject => 'testing 10g Packages',
> message => 'No attachements with this note');
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:29 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
Regular Expressions
Oracle provides several operators to help you with string manipulation and searching.
Operators such as the SQL LIKE, REPLACE, SUBSTRING and INSTRING are old
standbys in many a search expression. However, these older operators have serious
limitations when it comes to searching and manipulating complex patterns in data. You
would have to write numerous lines of SQL and PL/SQL code to search for complex
expressions. Oracle Database 10g enhances your ability to perform convenient searches
and string manipulation by adding regular expression support to both SQL and PL/SQL
programming. Oracle’s regular expression features follow the syntax and semantics
of the operators defined by the POSIX regular expression standards. You use special
regular 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 for
the search value. The source character string can be one of the CHAR, VARCHAR2,
NCHAR, or NVARCHAR2 datatypes. The regular expression function can be one
of the following:
REGEXP_LIKE
REGEXP_REPLACE
REGEXP_INSTRING
REGEXP_SUBSTRING
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:29 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
LIKE condition, except that REGEXP_LIKE will perform regular expression matching
instead of the simple pattern matching performed by the LIKE function.
To match characters and to indicate the beginning and end of lines, regular
expression features use characters such as ., *, ^, and $, which are common in UNIX
and Perl programming. The character ^, for example, tells Oracle that the characters
following it should be at the beginning of the line. Similarly, the character $ indicates
that a character or a set of characters must be at the very end of the line. Here’s an
example using the REGEXP_LIKE function. (The query picks up all names with
consecutive vowels in their names.)
SQL> select last_name
from employees
where regexp_like (last_name, '([aeiou])\1', 'i');
LAST_NAME
-----------
De Haan
Greenberg
Khoo
Gee
Lee
……
EXERCISE 12-1
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:29 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
In the previous example, the name of the NLS_SORT is FRENCH_M. The optional
suffix AI indicates this is an accent-insensitive (and case-sensitive) sort.You can
indicate a case-insenstitive sort by using the suffix CI.
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:29 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
Miscellaneous Enhancements 19
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 to
avoid using escape characters for single quotation marks in text literals:
SQL> select cust_address FROM oe.customers
where cust_last_name = q'X 'John's Bait Shop' X'
Miscellaneous Enhancements
There are several enhancements in Oracle Database 10g that don’t fit within the topics
of any of the earlier chapters in this book. I summarize these enhancements in the
following sections.
connect username/password@[//]host[:port][/service_name]
In the new easy connect method, there are four different things you need to focus
on: host, the // notation, port number (default port = 1521), and service name. Of
these four things, only the host name is mandatory. For example, you can connect to
the 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 the
keword CONNECT with SQLPLUS):
C:\>sqlplus appowner/password@hp50:1521/dev1
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:29 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 to
use the new configuration-less client connect method. The NAMES.DIRECTORY_
PATH parameter in the sqlnet.ora file shows all connect methods. The new easy connect
method is referred to as EZCONNECT in a sqlnet.ora file. Look at the following
sqlnet.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.org
SQLNET.AUTHENTICATION_SERVICES = (NTS)
NAMES.DIRECTORY_PATH = (TNSNAMES,EZCONNECT)
The last line shows you the connect methods that Oracle Net will use to resolve
connect identifiers to connect descriptors. In this example, TNSNAMES is the first
option, so Oracle NET will use the tnsnames.ora file first by default. If it can’t connect
using 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 Oracle
Net Manager to reconfigure the sqlnet.ora file so your NAMES.DIRECTORY_PATH
will be as follows. (You may manually change the sqlnet.ora file as well.)
NAMES.DIRECTORY_PATH = (EZCONNECT, TNSNAMES)
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:29 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
Miscellaneous Enhancements 21
LogMiner Enhancements
There are three important changes in the LogMiner tool. Let me summarize the changes
briefly here.
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:29 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:29 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
Miscellaneous Enhancements 23
You can expect some type of question on the The exam will test your knowledge of the new
new column-level VPD policies. The exam CLIENT_IDENTIFIER, SERVICE_NAME,
tests your expertise in customized VPD policy MODULE_NAME, and ACTION_NAME
types. What are the five VPD policy types, and attributes. What are these attributes useful for?
when do you use them? Be sure to understand Please look up the DBMS_MONITOR package and
how to use shared policy functions. The exam study the CLIENT_ID_TRACE_ENABLE
will contain questions on the new auditing and the SERV_MOD_ACT_TRACE_ENABLE
features. Understand what the new AUDIT_ procedures. Also look up the procedures that
TRAIL=DB_EXTENDED specification will enable and disable statistics collection for the
help you do. You must be familiar with the new attributes. You must know how to enable
DBA_COMMON_AUDIT_TRAIL view and and disable end-to-end tracing using the new
its important columns. attributes.
You are going to see questions on fine- Among the miscellaneous SQL and PL/SQL
grained auditing enhancements, including topics, focus on regular expressions and the new
topics like support for DML statements (and packages to send email and compress data. Know
the MERGE statement), multicolumn FGA the Oracle Database 10g enhancements in
policies, and NULL FGA policy predicates. CLOB to NCLOB conversions, the new quote
How does Oracle audit MERGE statements? operator, and how to perform case- and accent-
Look up the DBMS_FGA package and study insensitive querying and sorting. The exam
the ADD_POLICY procedure carefully, also may have questions on the new resumable
with particular emphasis on the AUDIT_ statement parameter, the easy connect naming
COLUMN, AUDIT_COLUMN_OPTS, method, and the easy configuration of shared
and the AUDIT_TRAIL columns. servers.
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:30 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
CHAPTER SUMMARY
You reviewed the new column-level VPD policies in this chapter. You learned how to
create a VPD with security-relevant columns.You also learned about the new static and
context-sensitive policies and how you can share them across objects.The chapter
covered the Oracle Database 10g enhancements in the auditing area, including the new
uniform audit trail for standard and fine-grained auditing .You learned about the new
enterprise user auditing enhancements as well as other FGA enhancements.
The new attributes—client identifier, service name, module name, and action
name—enhance your ability to perform end-to-end tracing as well as monitor your
database workload. You learned how to enable and disable client- and service-level
tracing and statistics collection.
The chapter introduced you to the new UTL_MAIL and the UTL_COMPRESS
PL/SQL packages. You had an introduction to the powerful regular expressions feature.
The chapter also reviewed the new case- and accent-insensitive sorting techniques
as well as user-specified delimiters.
Under miscellaneous enhancements, you briefly reviewed the new easy connect
naming method, simpler shared server configuration, the new resumable space
allocation initialization parameter, and enhancements to the LogMiner tool and real-
time transaction monitoring.
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:30 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
Two-Minute Drill 25
✓ 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 not
to 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 the
security-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 order
to see bind variables and the complete SQL text of the audited statements.
❑ There are several enhancements in the enterprise user auditing in Oracle
Database 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 auditing
policy predicates.
❑ Oracle will always audit a qualified DELETE statement under FGA.
❑ Oracle’s FGA feature audits MERGE statements by viewing them as consisting
of individual UPDATE and INSERT statements.
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:30 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
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 the
SHARED_SERVER parameter. The dispatcher process starts automatically
with instance startup.
❑ The new initialization parameter RESUMABLE_TIMEOUT enables the
resumable 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 rollback
and recovery.
❑ In Oracle Database 10g, you can let the database automatically tune database
checkpointing.
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:30 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
Self Test 27
SELF TEST
VPD and Auditing Enhancements
1. Which of the following does a column-level VPD policy apply to?
A. Tables
B. Synonyms
C. Views
D. Materialized views
E. Indexes
2. Which of the following type of SQL statements may you apply a policy function to?
A. DDL statements
B. SELECT statements only
C. Queries and DML statements
D. INSERT and DELETE statements only
E. 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.STATIC
B. POLICY_TYPE=DBMS_RLS.DYNAMIC
C. POLICY_TYPE=DBMS_RLS.SHARED
D. 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.
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:30 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:30 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
Self Test 29
A. Implicit conversion of SQL IN and OUT bind variables in queries and DML statements
B. Explicit conversion of SQL IN and OUT bind variables in queries and DML statements
C. Implicit conversion of SQL IN and OUT bind variables in queries only
D. 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 functionality
B. Case-sensitive functionality
C. Accent-sensitive functionality
D. Accent-insensitive functionality
15. The output of the UTL_COMPRESS compressed data is compatible with which of the
following?
A. GZIP only
B. GZIP and GUNZIP
C. GUNZIP only
D. Neither GZIP nor GUNZIP
Miscellaneous Enhancements
16. Which two of the following statements will work if your goal is to enable resumable statements
in 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.vp
Tuesday, August 31, 2004 1:48:30 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 shared
server?
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 name
B. Database name
C. Service name
D. 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 QUESTION
Given the following statement, use regular expressions to search for a comma followed by a space. You
must 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.vp
Tuesday, August 31, 2004 1:48:31 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:31 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:31 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 12
Lab Answer 33
Miscellaneous Enhancements
16. þ C and D. C is correct since this statement was valid in Oracle9i and continues to work the
same way in Oracle Database 10g. D shows how you can enable resumable statements with the
new 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 the
ALTER 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 automatic
checkpoint 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 STARTTIME
parameter 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 ANSWER
The 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>
P:\010Comp\CertPrs8\862-4\ch12.vp
Tuesday, August 31, 2004 1:48:31 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Chapter 1
Blind Folio 1:1
Glossary
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
2 Glossary
ALERT_QUE You can subscribe to the ALERT_QUE and read the ALERT_QUE
if you wish to create your own tool to display database alerts, rather than using the
Oracle Database 10g Database Control.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
ASM_POWER_LIMIT 3
ASM file templates Automatic Storage Management (ASM) files are named
collections of attributes that you apply to a file during its creation. Templates simplify
file creation. Templates are applied to a file, but are actually associated with a disk group.
ASM files Automatic Storage Management (ASM) files are Oracle database files
stored in ASM disk groups. All ASM files are Oracle Managed Files (OMF), and you
must back up them with the Recovery Manager (RMAN). ASM doesn’t manage
binary files, alert logs, trace files, or password files.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
4 Glossary
ASMB ASMB is a background process that exists in each database that uses
Automatic Storage Management (ASM). When you start the database, the ASMB
process connects to the ASM process and a foreground process, and conducts all
communication between the database and the ASM instance.
automatic channel failover When you backup your database with the
Recovery Manager (RMAN), one of the channels may fail during the process.
Automatic channel failover is the new feature whereby RMAN will attempt to
complete the backup on another channel.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
Automatic Tuning Optimizer (ATO) The SQL Tuning Advisor calls the
Automatic Tuning Optimizer (ATO) to perform four types of analysis: statistics
analysis, SQL profiling, access path analysis, and SQL structure analysis.
automatic undo retention tuning Oracle Database 10g automatically tunes the
initialization parameter UNDO_RETENTION to control retention of undo information
in rollback segments.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
6 Glossary
base statistics Base statistics refer to raw performance statistics, such as the number
of physical reads since instance startup. Metrics are derived from base statistics.
block change tracking Oracle tracks the physical location of database changes
in a new file called the change-tracking file. The Recovery Manager (RMAN) uses
the change-tracking file to determine which data blocks to read during an incremental
backup, thus making incremental backups faster by avoiding the reading of entire
datafiles.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
compressed backups 7
compressed backups You can now use binary compression to reduce the size
of your backup sets. You must have the compatibility set to at least 10.0.0 and use
the following Recovery Manager (RMAN) command:
BACKUP AS COMPRESSED BACKUPSET DATABASE;
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
8 Glossary
CTWR The CTWR is the new Oracle background process that writes database
change information to the change-tracking file.
Data Pump The Data Pump export and import utilities provide high-speed
movement of data from one database to another. These utilities offer several
advantages over the original Oracle export and import utilities, including the ability
to completely restart export and import jobs, detach and reattach to long-running
jobs, estimate how much disk space an export job would consume, and perform
export and import operations over the network. The Data Pump utilities also
support fine-grained object selection.
Data Pump direct path Direct path is one of two access methods that Data
Pump supports to load and unload table data. If it is possible, Data Pump tries to use
the direct-path access method to load and unload data. The other access method is
external tables.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
DBA_DATAPUMP_JOBS 9
database wait model The database wait model enables you to determine what
sessions are waiting for, keeps a history of waits and wait durations per session, and
maintains wait statistics for SQL statements in a dynamic performance view.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
10 Glossary
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
DURATION 11
dense data Dense data is data where there is a row for each combination of the
various dimensions.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:40 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
12 Glossary
endian format Endian format is the byte ordering of files. When you transport
tablespaces across platforms, you must ensure that the endian format is identical on
both platforms. If not, you need to convert the datafiles to ensure that they are the
same on the source and target platforms.
external table access driver Data Pump provides an external table access
driver (ORACLE_DATAPUMP) that reads and writes files to enable high-speed
loading and unloading of database tables.
external table population External table population is the ability to load data
into platform-independent, Oracle proprietary flat files from a database table.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
external tables External tables enable you to use external data as a virtual table
that you can view and join to other tables, without needing to load the data in
actual database tables. External tables are read-only (no DML activity is possible).
fast ramp-up Fast ramp-up is the new feature wherein the database uses
Automatic Workload Repository (AWR) statistics to decide the number of undo
segments to bring online when you start an instance or when you switch an undo
tablespace.
flash recovery area The flash recovery area is an unified storage location for
backups, archive logs, and any other files needed for Oracle recovery. The backup
files are automatically deleted after they are backed up by the Recovery Manager
(RMAN). The flash recovery area is also the location for saving the Flashback
Database logs.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
14 Glossary
Flashback Database The Flashback Database feature lets you quickly bring your
database to a prior point in time by undoing all the changes that have taken place
since that time. You enable the Flashback Database feature after you first configure
a flash recovery area, and then set the retention target with the DB_FLASHBACK_
RETENTION_TARGET initialization parameter. The flashback time interval will
actually depend on the number of flashback database logs stored in the flash
recovery area.
Flashback Database logs Flashback Database logs are a new type of database
log files, which are analogous to redo logs. When you turn on the Flashback Database
feature, 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 automatically
created and managed in the flash recovery area. The new background process RVWR
(recovery writer) writes the Flashback Database data from the flashback buffer to the
Flashback Database logs.
Flashback Drop The Flashback Drop feature lets you undo the effects of a
DROP TABLE statement. The dropped tables are saved in the Recycle Bin. The
command you actually use to flashback a table is of the format FLASHBACK TABLE
table-name TO BEFORE DROP.
Flashback Query The Flashback Query feature lets you query a database as of
a certain clock time or a system change number.
Flashback Table The Flashback Table feature lets you recover a table to a point
in time in the past without restoring a backup.
Flashback Versions Query The Flashback Versions Query feature lets you
view changes to one or more rows, along with all the metadata of the changes.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
INSTANCE_TYPE 15
flushing the buffer cache Oracle Database 10g lets you flush the buffer cache
by using the following command:
ALTER SYSTEM FLUSH BUFFER_CACHE;
Grid Control The Grid Control is the centralized version of Oracle Enterprise
Manager, which lets you manage several databases and hosts simultaneously. You
must install the Grid Control separately from the database.
idle timeouts You can set up maximum idle timeouts for a resource plan using
the DBMS_RESOURCE_MANAGER package. When a session exceeds the MAX_
IDLE_TIME parameter value specified in the CREATE_PLAN_DIRECTIVE
procedure, the Process Monitor (PMON) will kill the session.
INCLUDE The INCLUDE Data Pump parameter lets you require that only
specified object types and objects be included in an export or import job.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
16 Glossary
job A job is a user-defined task that is scheduled to run one or more times. A job
contains 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 and
behavior. A job class is a way of grouping jobs into larger entities, thus enabling
you to prioritize among the job classes.
job priority Job priority helps you prioritize the jobs in your database. There are
two 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 priority
of a job is 3.
locking statistics You can lock representative statistics when a table’s data
keeps 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 the
LOGGING_LEVEL parameter. You can set this parameter to either DBMS_
LOGGING_ FULL or DBMS_SCHEDULER.LOGGING_RUNS at either the
job class or the individual job level.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
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 base
statistics. Metrics track the rate of change of a variable. An example of a database
metric is the number of physical reads in the database in the past 60 minutes.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
18 Glossary
online segment shrink The online segment shrink feature shrinks segments
online and in-place (tables, indexes, and materialized views) that have free space
in them, thereby enhancing efficiency of space utilization.
partition outer join Partitioned outer joins are extensions to the outer join
syntax, and they are used primarily to improve performance and simplify SQL
queries for time-based calculations.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
projected columns 19
policy framework The policy-based database framework lets you monitor all
targets to see if their configuration conforms to recommended policy configuration
settings. These policies are based on Oracle’s best practice configuration
recommendations. The database configuration framework is built on top of the
configuration and metric collection facility of the Oracle Enterprise Manager.
POWER The POWER clause is used when you rebalance an Automatic Storage
Management (ASM) disk group and specifies the power level of a disk rebalancing
job. By using the POWER clause in a rebalance disk group command, you can
override the setting of the default speed set by using the initialization parameter
ASM_POWER_LIMIT.
projected columns When dealing with external table files, which contain rows
of data that may be rejected due to errors, the projected column feature enables you
to get a consistent result set, independent of the columns referenced by the SQL
statement accessing the data. Prior to Oracle Database 10g, only the columns referenced
by the SQL statement were projected out by the access driver, and some rows were
rejected due to conversion errors or data format errors.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
20 Glossary
PURGE You need to use the PURGE clause when you drop a database table if you
want Oracle to remove the table permanently. Otherwise, Oracle will save the table
in the Recycle Bin. Using the DROP TABLE PURGE command is equivalent to using
the old DROP TABLE command.
RATIO RATIO refers to the new resource allocation method for specifying how
much CPU each consumer group or subplan gets, when you use the Database Resource
Manager. The RATIO method for specifying CPU allocation is for single-level plans
that 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 CPU
is distributed.
RBAL The RBAL background process coordinates rebalancing activity for disk
groups in an Automatic Storage Management (ASM) instance.
Recycle Bin The Recycle Bin is actually a data dictionary table containing
information about dropped objects. Dropped tables and any associated objects—
such as indexes, constraints, and nested tables—are renamed. You can use the
FLASHBACK TABLE … TO BEFORE DROP command to recover a dropped table
from the Recyle Bin.
Redo Logfile Size Advisor The Redo Logfile Size Advisor recommends the
optimal size of redo log files.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
segment shrinking 21
schedule A schedule indicates when a job should run. It has a start date that
specifies the date and time when the schedule starts, an end date that indicates the
date and time when the schedule expires, as well as a repeat interval that indicates
how often it will repeat.
Scheduler The Scheduler is Oracle’s new scheduling feature that gives you the
ability to schedule a job to run at a particular date and time. It also provides you the
ability to create libraries of sharable Scheduler objects You can group jobs that share
common characteristics into larger entities called job classes, which can be prioritized
by controlling the system resources allocated to each of them.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
22 Glossary
shared policies Shared policies apply to Virtual Private Directory (VPD). They
let you apply the same policy to several objects. You can have both shared static and
shared context-sensitive policy types.
smallfile tablespace In Oracle Database 10g, you can have two types of
tablespaces: bigfile and smallfile. Smallfile is the default tablespace type, and
it is the same as the standard tablespaces used in previous Oracle versions.
sorted hash cluster Sorted hash clusters are new data structures that let you
retrieve data faster in applications where data is requested in the order in which it
was inserted.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen 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 a
certain combination of dimensions.
SQL Access Advisor The SQL Access Advisor identifies and helps resolve
performance problems relating to SQL statement execution by recommending
which indexes or materialized views to create, drop, or retain.
SQL MODEL clause The SQL MODEL clause provides a powerful building block
for complex calculations such as forecasts and budgets. Using the MODEL clause, you
can treat relational tables as n-dimensional arrays and specify interrow references
without complex SQL joins and unions. With the MODEL clause, you can define a
multidimensional array on query results, and then apply sophisticated rules on the
array to calculate new values. By integrating advanced calculations into the database,
performance, scalability, and manageability are enhanced significantly compared to
performing the calculations using external products.
SQL profile The Automatic Tuning Optimizer (ATO) creates profiles of SQL
statements, which are called SQL profiles, consisting of auxiliary statistics specific
to that statement. SQL profiles address the problem of the query optimizer sometimes
using incorrect statistics, by collecting additional information using sampling and
partial execution techniques to verify and, if necessary, adjust the optimizer estimates.
SQL Tuning Advisor The SQL Tuning Advisor is a new database advisor that
eliminates manual tuning of SQL statements. It provides tuning advice in the form
of precise actions along with their expected performance benefit. You can use this
feature for SQL tuning of packaged applications, without requiring any modification
to the application code.
SQL Tuning Set (STS) A SQL Tuning Set (STS) is a new database object used
for 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 of
interest and store them in an STS for future tuning without having to build and
maintain SQL scripts for tuning purposes.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:41 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
24 Glossary
static policies Static policies apply to the Virtual Private Database (VPD)
concept. Static policies enforce an unchanging policy. Previously, all VPD policies
were dynamic by default, which meant that Oracle executed the function for each
DML statement. Static policies enforce the same predicate for access control,
regardless of the user, thus ensuring the same policy predicate for all users. The
new static policies improve performance, since they don’t always reexecute policy
functions for each DML statement.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:42 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
UNCATALOG 25
time model statistics Time model statistics indicate the amount of DB time
associated 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 spent
in performing internal operations such as parse, execute, input/output, and so on.
The database uses this information for making self-tuning decisions and to diagnose
performance problems.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:42 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
26 Glossary
Undo Advisor The Undo Advisor is part of the advisory framework. It helps
database administrators in sizing the undo tablespace and in setting the size of the
UNDO_RETENTION parameter.
uniform audit trail Oracle tracks a set of identical fields for both standard and
fine-grained auditing to enable you to easily analyze database activity. This tracking
of identical information is called the uniform audit trail. There is a new audit trail
view, DBA_COMMON_AUDIT_TRAIL, which combines standard and fine-grained
audit records.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:42 PM
Color profile: Generic CMYK printer profile
Composite Default screen CertPrs8 / OCP Oracle Database 10g Exam Guide / Alapati / 225862-4 / Glossary
window priority 27
window A window is a time duration for which you can specify certain resource
allocations. Like a schedule, it has a start date when the window becomes active or
opens and a duration that specifies how long the window will be open, as well as an
end date. It may also have a repeat interval that specifies how often the window will
open. You generally associate a resource plan with a window in order to specify how
resources should be allocated among the job classes.
window priority Window priorities are relevant when you are dealing with
overlapping windows. If two windows with the same priority overlap, the active
window stays open. If two windows with different priorities overlap, the higher
priority window will open, and the lower priority window will close.
P:\010Comp\CertPrs8\862-4\glossary.vp
Tuesday, September 07, 2004 3:07:42 PM