Você está na página 1de 482

Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
ans
n - t r
a no
Oracle Databaseh a s 11g:ฺ New
r ) e
Features
m uid
ฺa forGAdministrators
n ฺ co ent
@ ao Stud
z i l le thVolume
is III • Student Guide
c e loฺ use
a r to
m e
i l l e ( icens
e loZ l
Marc

D50081GC21
Edition 2.1
September 2010
D63699
Authors Copyright © 2009, 2010, Oracle and/or it affiliates. All rights reserved.

Christian Bauwens Disclaimer


Maria Billings
This document contains proprietary information and is protected by copyright and
Mark Fuller other intellectual property laws. You may copy and print this document solely for your
Peter Fusek own use in an Oracle training course. The document may not be modified or altered in
Richard Green any way. Except where your use constitutes "fair use" under copyright law, you may
Christine Jeal not use, share, download, upload, copy, print, display, perform, reproduce, publish,
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

license, post, transmit, or distribute this document in whole or in part without the
Donna Keesling express authorization of Oracle.
Deidre Matishak
James Spiller The information contained in this document is subject to change without notice. If you
Jenny Tsai find any problems in the document, please report them in writing to: Oracle University,
500 Oracle Parkway, Redwood Shores, California 94065 USA. This document is not
Jean-Francois Verrier warranted to be error-free.
James Womack
Marcie Young Restricted Rights Notice

If this documentation is delivered to the United States Government or anyone using


Technical Contributors
and Reviewers
the documentation on behalf of the United States Government, the following notice is
ble
applicable:
fe r a
Maqsood Alam U.S. GOVERNMENT RIGHTS
an s
Kalyan Bitra
John Boyle n - t r
The U.S. Government’s rights to use, modify, reproduce, release, perform, display, or
disclose these training materials are restricted by the terms of the applicable Oracle
o
an
license agreement and/or the applicable U.S. Government contract.
Harald Van Breederode
Sharath Bhujani Trademark Notice s
ha deฺ
Immanuel Chan
Timothy Chien
r )
ฺa Gui
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names
Edward Choi m
co ent
may be trademarks of their respective owners.

n ฺ
Jacco Draaijer
Al Flournoy
@ ao Stud
Steve Fogel
z i l le this
Andy Fortunak
c e loฺ use
Gerlinde Frenzen
a r to
Greg Gagnon m e
GP Gongloor
i l l e ( icens Technical Contributors

oZ
Joel Goodman
e l
Hansen Han
l and Reviewers

arc
Tim Shetler
Uwe Hesse Eric Siglin
M Sunil Hingorani Ranbir Singh
Magnus Isaksson Jeff Skochil
Susan Jang George Spears
Martin Jensen Kesavan Srinivasan
Dominique Jeunot Birgitte Taagholt
Pete Jones Glenn Tripp
Yash Kapani Branislav Valny
Pierre Labrousse Anthony Woodell
Richard.W.Lewis
Hakan Lindfors Editors
Russ Lowenthal
Aju Kumar
Kurt Lysy
Amitha Narayan
Isabelle Marchand
Silvia Marrone
Publishers
Heejin Park
Srinivas Putrevu Sujatha Nagendra
Jagannath Poosarla Michael Sebastian Almeida
Surya Rekha Jobi Varghese
Contents
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

I Introduction
Overview I-2
Oracle Database Innovation I-3
Enterprise Grid Computing I-4
Oracle Database 11g: Focus Areas I-5
Management Automation I-7
Self-Managing Database: The Next Generation I-8 ble
Suggested Additional Courses I-9 fe r a
ans
Further Information I-10
n - t r
Suggested Schedule I-11 o
s an
1 Oracle Grid Infrastructure r ) ha deฺ
Objectives 1-2 m ฺa Gui
Oracle Grid Infrastructure 1-3 n ฺ co ent
Automatic Storage Management Technology
@ ao Stack S tud1-4
z
Oracle Grid Infrastructure and i l le Database
Oracle t h is Installation: System
Requirements 1-5cel
oฺ use
a r System
to 1-6
Preparing the Operating
m e
l l e ( iceVariables
Setting iEnvironment ns 1-7
Z l
lo the System Requirements 1-8
r c eChecking
Ma Defining Ownership of OS Devices for ASM 1-9
Installation Scenario 1-10
Part One: Installing the Oracle Grid Infrastructure for Stand-Alone Server 1-11
Selecting Product Languages 1-12
Creating an ASM Disk Group 1-13
Defining ASM Passwords 1-14
Defining Privileged Operating System Groups 1-15
Specifying Installation Location 1-16
Creating Inventory 1-17
Performing Prerequisite Checks 1-18
Verifying Installation Summary Data 1-19
Monitoring Installation Progress 1-20
Executing root Configuration Scripts 1-21
Executing Configuration Assistants 1-22
Finishing the Installation 1-23

iii
Configuring the FRA Disk Group 1-24
Oracle Local Registry 1-25
Quiz 1-27
Practice 1-1: Overview 1-28
ASM Files and Volumes 1-29
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ASM Dynamic Volume Manager (ADVM) Concepts 1-30


ASM Dynamic Volume Striping 1-31
ADVM Restrictions 1-32
Creating an ASM Dynamic Volume 1-33
Managing ASM Dynamic Volumes 1-35
Using SQL to Manage ASM Dynamic Volumes 1-36
Extending ASMCMD for ASM Dynamic Volumes 1-38
ble
ASM Cluster File System (ACFS) 1-39 fe r a
ACFS Architecture 1-40 ans
n - t r
Using Enterprise Manager to Manage ACFS 1-41 o
Linux/UNIX File System APIs 1-42
s an
Linux/UNIX Extensions 1-43
r ) ha deฺ
Windows File System APIs 1-44
m ฺa Gui
Windows Extensions 1-45
n ฺ co ent
ao Stud
ACFS Platform-Independent Commands 1-46
@
i l le this
ASM Cluster File System Limitations 1-47
z
c e loฺ use
Creating an ASM Cluster File System 1-48
a
ACFS Snapshots 1-49r to
m e
i l l e ( icens
Administering Oracle ACFS Snapshots 1-50

e oZ
Quiz 1-51
l l
Marc Summary 1-52
Practice 1-2: Overview 1-53

2 Installation Enhancements
Objectives 2-2
Oracle Database 11g Installation: Changes 2-3
Part Two: Installing the Oracle Database Software 2-6
Choosing the Type of Installation 2-7
Choosing Grid Installation Options 2-8
Choosing Language Settings 2-9
Choosing the Database Edition 2-10
Specifying Installation Location 2-11
Choosing Operating System Groups 2-12
Performing Prerequisite Checks 2-13
Installation Summary Page 2-14
Install Product Page 2-15

iv
Installation Finish Page 2-16
Quiz 2-17
Practice 2-1: Overview 2-18
Oracle Database 11g Release 2 Upgrade Paths 2-19
Deprecated Features in Oracle Database 11g Release 1 and Release 2 2-20
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Initialization Parameter Information 2-21


Practice 2-2: Overview 2-23
Practice 2-3: Overview 2-24
Direct NFS Client: Overview 2-25
Direct NFS Configuration 2-27
Monitoring Direct NFS 2-29
Online Patching: Overview 2-30
ble
Installing an Online Patch 2-31 fe r a
Benefits of Online Patching 2-32 ans
n - t r
Conventional Patching and Online Patching 2-33 o
Online Patching Considerations 2-34
s an
Quiz 2-36
r ) ha deฺ
Summary 2-37
m ฺa Gui
Practice 2-4: Overview 2-38
n ฺ co ent
@ ao Stud
3 Oracle Restart
z i l le this
Objectives 3-2
c e loฺ use
Oracle Restart 3-3 a r to
m e
Oracle Restart
i l l e ( Process
i c e s
nStartup 3-5
l o Z
Controlling l
Oracle Restart 3-6
e
rc Choosing the Correct SRVCTL Utility 3-8
Ma Oracle Restart Configuration 3-9
Using the SRVCTL Utility 3-10
Obtaining Help for the SRVCTL Utility 3-11
Starting Components by Using the SRVCTL Utility 3-12
Stopping Components by Using the SRVCTL Utility 3-13
Viewing Component Status 3-14
Displaying the Oracle Restart Configuration for a Component 3-15
Manually Adding Components to the Oracle Restart Configuration 3-16
Quiz 3-17
Summary 3-18
Practice 3-1: Overview 3-19

4 ASM Enhancements
Objectives 4-2
Without ASM Fast Mirror Resync 4-3

v
ASM Fast Mirror Resync: Overview 4-4
Using Enterprise Manager to Perform Fast Mirror Resync 4-5
Setting Up ASM Fast Mirror Resync 4-7
ASM Preferred Mirror Read: Overview 4-9
ASM Preferred Mirror Read: Setup 4-10
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Enterprise Manager ASM Configuration Page 4-11


ASM Preferred Mirror Read: Best Practice 4-12
Quiz 4-13
ASM Scalability and Performance Enhancements 4-14
ASM Scalability in Oracle Database 11g 4-16
SYSASM Privilege 4-17
Using Enterprise Manager to Manage ASM Users 4-18 ble
ASM Disk Group Compatibility 4-19 fe r a
ASM Disk Group Attributes 4-21 ans
n - t r
Using Enterprise Manager to Edit Disk Group Attributes 4-22 o
Enhanced Disk Group Checks 4-23
s an
Restricted Mount Disk Group for Fast Rebalance 4-24
r ) ha deฺ
Mount Force Disk Group 4-25 m ฺa Gui
Forcing Disk Group Drop 4-27 n ฺ co ent
ao Stud
ASMCMD Extensions in Oracle Database 11g Release 1 4-28
@
ASMCMD Command Extensions 4-30
z i l le this
c e loฺ use
ASMCMD Extensions: Example 4-31
Quiz 4-32 a r to
m e
l e ( icens
ASM ACLs 4-33
i l
e oZ l
ASM ACLs Prerequisites 4-34
l
Marc Managing ASM ACLs by Using SQL Commands 4-36
Managing ASM ACLs by Using SMCMD Commands 4-37
Managing ASM ACLs by Using Enterprise Manager 4-38
ASM Intelligent Data Placement 4-40
Managing ASM Intelligent Data Placement Examples 4-41
Managing ASM Intelligent Data Placement 4-42
ASM Intelligent Data Placement Best Practices 4-44
Viewing ASM Intelligent Data Placement Information 4-45
Quiz 4-47
Summary 4-48
Practice 4: Overview 4-49

5 Storage Enhancements
Objectives 5-2
Supporting 4 KB Sector Disks 5-3

vi
Using 4 KB Sector Disks 5-4
Specifying the Disk Sector Size 5-5
Using the SECTOR_SIZE Clause 5-6
Creating a Database with 4 KB Sector Disks 5-7
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Specifying BLOCKSIZE 5-8


Determining Your Log File Block Size 5-9
Performing an Offline Migration to 4 KB Disks 5-10
Quiz 5-12
Table Compression: Overview 5-13
Table Compression Concepts 5-14
Compressing Table Data 5-15
Using OLTP Compression 5-17 ble
Using the Compression Advisor 5-18 fe r a
ans
Viewing Table Compression Information 5-19
n - t r
SQL Access Advisor: Overview 5-20 o
SQL Access Advisor: Usage Model 5-21 s an
Possible Recommendations 5-22
r ) ha deฺ
Using SQL Access Advisor 5-23 m ฺa Gui
ฺ co ent
SQL Access Advisor: PL/SQL Procedure Flow 5-24
n
ao Stud
SQL Access Advisor: PL/SQL Example 5-25
@
i
Temporary Tablespace Shrink 5-26
z l le this
e
DBA_TEMP_FREE_SPACE 5-27
c loฺ use
a r to
Tablespace Option for Creating Temporary Table 5-28
m e
l l e ( icens
Segment Creation on Demand 5-29
i
e loZ l
Creating Tables Without Segments 5-30

Marc Controlling Deferred Segment Creation 5-31


Restrictions and Exceptions 5-32
Additional Automatic Functionality 5-33
Quiz 5-34
Summary 5-35
Practice 5: Overview 5-36

6 Data Warehouse and Partitioning Enhancements


Objectives 6-2
Preprocessing Data for ORACLE_LOADER Access Driver in External Tables 6-3
Windows Example 6-4
Example of Preprocessing 6-5
EXECUTE Privilege for Directory Objects 6-7
Security Implications 6-8
Securing the ORACLE_LOADER Access Driver 6-10

vii
Considerations and Usage Notes 6-12
Quiz 6-13
Review: Degree of Parallelism (DOP) 6-14
Review: PARALLEL Clause 6-16
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Goal: Simplifying Parallel Execution 6-17


Automatic Degree Of Parallelism Determination 6-18
Summary of Changes to Parameters 6-19
Using PARALLEL_MIN_TIME_THRESHOLD 6-20
Using PARALLEL_DEGREE_POLICY 6-21
Using PARALLEL_DEGREE_LIMIT 6-23
Using PARALLEL_FORCE_LOCAL 6-25
Changes to Existing Parameters 6-26 ble
fe r a
Parallel Hints Are Now at the Statement Level 6-27 s
Implication of Statement-Level Parallel Hints 6-28
- t r an
EXPLAIN PLAN Enhancements 6-29 o n
Enhanced Explain Plan Example 6-30 s an
In-Memory Parallel Query 6-31 r ) ha deฺ
Quiz 6-32 m ฺa Gui
Oracle Partitioning 6-33 n ฺ co ent
Partitioning Enhancements 6-34 @ ao Stud
Interval Partitioning 6-35 z i l le this
c e loฺ use
Interval Partitioning: Example 6-36
a r to
m e
Moving the Transition Point: Example 6-37
i l l e ( icens
System Partitioning 6-39
e loZ l
System Partitioning: Example 6-40

Marc System Partitioning: Guidelines 6-41


System-Managed Indexes for List Partitioning 6-42
Virtual Column–Based Partitioning 6-43
Virtual Column–Based Partitioning: Example 6-44
Reference Partitioning 6-45
Reference Partitioning: Benefit 6-46
Reference Partitioning: Example 6-47
Composite Partitioning Enhancements 6-48
Range-Range Partitioning: Example 6-49
Summary 6-50
Practice 6: Overview 6-51

7 Oracle SecureFiles
Objectives 7-2
Managing Enterprise Information 7-3

viii
Issues with Existing LOB Implementation 7-4
Oracle SecureFiles 7-5
Enabling SecureFiles Storage 7-6
SecureFiles: Storage Options 7-7
SecureFiles: Advanced Features 7-8
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Creating SecureFiles 7-9


Creating SecureFiles Using Enterprise Manager 7-10
Shared I/O Pool 7-11
Altering SecureFiles 7-12
Quiz 7-13
What Is SecureFile Compression? 7-14
Compression Modes 7-15
ble
Creating a SecureFile LOB with LOW Compression 7-16 fe r a
Configuration Parameters 7-17 ans
n - t r
Quiz 7-18 o
Accessing SecureFiles Metadata 7-19
s an
Migrating to SecureFiles 7-20
r ) ha deฺ
SecureFiles Migration: Example 7-21 m ฺa Gui
SecureFiles Monitoring 7-22 n ฺ co ent
Summary 7-23
@ ao Stud
Practice 7: Overview 7-24
z i l le this
c e loฺ use
a
8 Security and Networkingr to
Enhancements
m
( ens e
Objectives
i l l e 8-2
o Z PasswordlicSupport 8-3
Secure
l
rceAutomatic Secure Configuration 8-4
Ma Password Configuration 8-5
Enable Built-in Password Complexity Checker 8-6
Managing Default Audits 8-7
Audited Privileges 8-8
Setting Security Parameters 8-9
Setting Database Administrator Authentication 8-11
Quiz 8-12
Transparent Data Encryption 8-13
Hardware Security Module 8-14
Using Tablespace Encryption 8-15
Tablespace Encryption New Features 8-16
Tablespace Master Key Re-Key 8-17
Quiz 8-18
Enterprise Manager Security Management 8-19
Using RMAN Security Enhancements 8-20

ix
Managing Fine-Grained Access to External Network Services 8-21
Supporting IPv6 Address Notification 8-23
Connecting to the Oracle Database 8-24
IPv6 Supported in Java Interfaces 8-25
Summary 8-26
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Practice 8: Overview 8-27

9 SQL Performance Analyzer


Objectives 9-2
Challenges Faced by DBAs When Performing Changes 9-3
Change Is the Only Constant 9-4
Change Management in Oracle Database 11g 9-5
ble
Lifecycle of Change Management 9-6 fe r a
SQL Performance Analyzer: Overview 9-8 ans
n - t r
SQL Performance Analyzer: Use Cases 9-9 o
Using SQL Performance Analyzer 9-10
s an
Step 1: Capture SQL Workload 9-11
r ) ha deฺ
Step 2: Transport to a Test System 9-12
m ฺa Gui
ฺ co ent
Step 3: Build Before Change Performance Data 9-13
n
ao Stud
Step 4: Implement Planned Change and Step 5: Build After-Change
@
Performance Data 9-14
z i l le this
c e loฺ use
Step 6: Compare and Analyze Performance and Step 7: Tune Regressed SQL 9-15
Quiz 9-16 a r to
m e
i l l e ( icens
Accessing SQL Performance Analyzer 9-17

e oZ l
Using Enterprise Manager to Access SQL Performance Analyzer 9-18
l
Marc SQL Performance Analyzer: PL/SQL Example 9-19
Tuning Regressed SQL Statements 9-21
Testing Database Upgrades: Oracle9i Database and Oracle Database 10g
Release 1 9-22
Testing Database Upgrades: Oracle Database 10g Release 2 and
Later Releases 9-25
SQL Performance Analyzer: Data Dictionary Views 9-28
Summary 9-29
Practice 9: Overview 9-30

10 SQL Plan Management


Objectives 10-2
SQL Plan Management: Overview 10-3
SQL Plan Baseline: Architecture 10-4
Loading SQL Plan Baselines 10-6
Evolving SQL Plan Baselines 10-7

x
Viewing Important Baseline SQL Plan Attributes 10-8
Important Baseline SQL Plan Attributes 10-9
SQL Plan Selection 10-10
Quiz 10-12
Possible SQL Plan Manageability Scenarios 10-13
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL Performance Analyzer and SQL Plan Baseline Scenario 10-14


Loading a SQL Plan Baseline Automatically 10-15
Purging SQL Management Base Policy 10-16
Enterprise Manager and SQL Plan Baselines 10-17
Using the MIGRATE_STORED_OUTLINE Functions 10-18
Summary 10-19
Practice 10: Overview 10-20 ble
fe r a
11 Database Replay ans
n - t r
Objectives 11-2 o
Why Use Database Replay? 11-3
s an
Using Database Replay 11-4
r ) ha deฺ
The Big Picture 11-5 m ฺa Gui
System Architecture: Capture 11-6 n ฺ co ent
ao Stud
System Architecture: Preprocessing the Workload 11-7
@
i
System Architecture: Replay 11-8
z l le this
c e loฺ use
Prechange Production System 11-9
a r
Supported Workloads 11-10 to
m e
l e ( icens
Capture Considerations 11-11
i l
e oZ l
Replay Considerations 11-12
l
Marc Replay Options 11-14
Workload Replay Filters 11-16
Replay Analysis 11-18
Quiz 11-20
Database Replay Workflow in Enterprise Manager 11-21
Accessing Database Replay 11-22
Packages and Procedures 11-23
Database Replay: PL/SQL Example 11-24
Data Dictionary Views: Database Replay 11-26
Calibrating Replay Clients 11-27
Summary 11-28
Practice 11: Overview 11-29

12 Automatic SQL Tuning


Objectives 12-2
SQL Tuning in Oracle Database 10g 12-3

xi
Automatic SQL Tuning in Oracle Database 11g 12-4
Summary of Automation in Oracle Database 11g 12-5
Selecting Potential SQL Statements for Tuning 12-6
Maintenance Window Timeline 12-7
Automatic Tuning Process 12-8
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Controlling the Automatic SQL Tuning Task 12-10


Example: Controlling the Automatic SQL Tuning Task 12-11
Automatic SQL Tuning Task 12-12
Configuring Automatic SQL Tuning 12-13
Automatic SQL Tuning Result Summary 12-14
Quiz 12-15
Automatic SQL Tuning: Fine Tune 12-16
ble
Using the PL/SQL Interface to Generate Reports 12-18 fe r a
Automatic SQL Tuning Considerations 12-19 ans
n - t r
Summary 12-20 o
Practice 12: Overview 12-21
s an
r ) ha deฺ
13 Intelligent Infrastructure Enhancements
m ฺa Gui
Objectives 13-2
n ฺ co ent
Using New and Enhanced Automatic Workload
@ tud Views 13-3
ao SRepository
Comparative Performance Analysis
z i l le withtAWR
h is Baselines 13-4
c e loฺ Baselines
Automatic Workload Repository
u se 13-5
a r
Moving Window Baseline to
13-6
m e
i l e ( iOptions
Baseline Display
l c e ns 13-7
Z Templates
Baseline
l o l 13-8
e
Marc Creating AWR Baselines 13-9
DBMS_WORKLOAD_REPOSITORY Package 13-10
Generate a Baseline Template for a Single Time Period 13-11
Creating a Repeating Baseline Template 13-12
Baseline Views 13-13
Quiz 13-14
Performance Monitoring and Baselines 13-15
Defining Alert Thresholds Using Static Baseline 13-17
Using Enterprise Manager to Quickly Configure Adaptive Thresholds 13-18
Practice 13-1: Overview 13-19
Maintenance Windows 13-20
Default Maintenance Plan 13-21
Automated Maintenance Task Priorities 13-22
Controlling Automatic Maintenance Tasks 13-23
Quiz 13-24
Important I/O Metrics for Oracle Databases 13-25

xii
I/O Calibration and Enterprise Manager 13-27
I/O Calibration and the PL/SQL Interface 13-28
I/O Statistics: Overview 13-30
I/O Statistics and Enterprise Manager 13-32
Practices 13-2 and 13-3: Overview 13-34
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Resource Manager Enhancements 13-35


Resource Manager Enhancements: Database Consolidation 13-36
Fixed Policy CPU Resource Management 13-37
Limiting CPU Utilization 13-38
Resource Manager Enhancements: Server Consolidation 13-39
Instance Caging 13-40
Instance Caging Examples 13-41
ble
Enabling Instance Caging 13-42 fe r a
Monitoring Instance Caging 13-43 ans
n - t r
Quiz 13-44 o
Resource Manager: Changes to DBMS_RESOURCE_MANAGER 13-45
s an
Resource Manager: New Enterprise Manager Interface 13-46
r ) ha deฺ
Resource Plans Created by Default 13-47 m ฺa Gui
Default Plan 13-48 n ฺ co ent
I/O Resource Limit Thresholds 13-49
@ ao Stud
i
Resource Manager Statistics 13-50
z l le this
Summary 13-51
c e loฺ use
a r to
m e
i l l
14 Diagnosabilitye ( Enhancements
c e ns
o Z 14-2li
Objectives
l
rceOracle Database 11g Fault Management 14-3
Ma Ease Diagnosis: Automatic Diagnostic Workflow 14-4
Automatic Diagnostic Repository 14-5
ADRCI: The ADR Command-Line Tool 14-7
V$DIAG_INFO 14-8
Location for Diagnostic Traces 14-9
Viewing the Alert Log Using Enterprise Manager 14-10
Viewing the Alert Log Using ADRCI 14-11
Quiz 14-13
Problems and Incidents 14-14
Incident Packaging Service (IPS) 14-17
Incident Packages 14-18
Enterprise Manager Support Workbench: Overview 14-20
Enterprise Manager Support Workbench Roadmap 14-21
View Critical Error Alerts in Enterprise Manager 14-22
Package and Upload Diagnostic Data to Oracle Support 14-23

xiii
Track the SR and Implement Repairs 14-24
Creating User-Reported Problems 14-25
Enterprise Manager Support Workbench for ASM 14-26
Invoking IPS Using ADRCI 14-27
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Quiz 14-29
Health Monitor: Overview 14-30
Running Health Checks Manually: Enterprise Manager Example 14-32
Running Health Checks Manually: PL/SQL Example 14-33
Viewing HM Reports Using the ADRCI Utility 14-34
SQL Repair Advisor: Overview 14-35
Accessing the SQL Repair Advisor Using Enterprise Manager 14-36
Viewing, Disabling, or Removing a SQL Patch 14-37 ble
Using SQL Repair Advisor from PL/SQL: Example 14-38 fe r a
ans
Using the SQL Test Case Builder 14-39
n - t r
Quiz 14-40 o
Summary 14-41 s an
Practice 14: Overview 14-42
r ) ha deฺ
m ฺa Gui
15 Real-Time SQL Monitoring n ฺ co ent
Objectives 15-2
@ ao Stud
SQL Monitoring 15-3 z i l le this

loDatabase e Release 2 15-5
s11g
SQL Monitoring in Oracle
c e
r Enterprise u
SQL Monitoring with
m a e to Manager Database Control 15-6
Monitored
i l l eSQL( Executions
c e ns 15-7
SQL
l o Z
Monitoring li 15-8
List
e
Marc Monitored SQL Execution Details 15-9
SQL Execution Details for Parallel Queries 15-10
Details for Parallel Execution 15-11
Activity Details for Parallel Execution 15-12
Viewing Session Details 15-13
SQL Details 15-14
Viewing the SQL Monitoring Report 15-15
Quiz 15-16
Summary 15-17
Practice 15-1: Overview 15-18

16 Performance Enhancements
Objectives 16-2
Using the DBMS_ADDM Package 16-3
Advisor Named Findings and Directives 16-6

xiv
Modified Advisor Views 16-7
New ADDM Views 16-8
Quiz 16-9
Review: Oracle Database 10g SGA Parameters 16-10
Review: Oracle Database 10g PGA Parameters 16-11
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Oracle Database Memory Advisors 16-13


Automatic Memory Management: Overview 16-15
Oracle Database 11g Memory Parameters 16-17
Automatic Memory Parameter Dependency 16-18
Enabling Automatic Memory Management 16-20
Monitoring Automatic Memory Management 16-21
DBCA and Automatic Memory Management 16-23
ble
Quiz 16-24 fe r a
DB Smart Flash Cache Overview 16-25 ans
n - t r
Using DB Smart Flash Cache 16-26 o
DB Smart Flash Cache Architecture Overview 16-27
s an
Configuring DB Smart Flash Cache 16-28
r ) ha deฺ
Sizing DB Smart Flash Cache 16-30
m ฺa Gui
ฺ co ent
Specifying DB Smart Flash Cache for a Table 16-31
n
Statistic Preferences: Overview 16-32
@ ao Stud
i l le this
Using New Statistic Preferences Features 16-33
z
c e loฺ use
Setting Global Preferences with Enterprise Manager 16-34
a r to
Partitioned Tables and Incremental Statistics: Overview 16-35
m e
i l l e ( icens
Hash-Based Sampling for Column Statistics 16-37

e oZ l
Multicolumn Statistics: Overview 16-39
l
Marc Expression Statistics: Overview 16-41
Deferred Statistics Publishing: Overview 16-42
Deferred Statistics Publishing: Example 16-44
Quiz 16-45
Locking Enhancements 16-46
Identify Foreground and Background Process Events 16-47
Summary 16-48
Practice 16: Overview 16-49

17 Application Performance Enhancements


Objectives 17-2
Online Redefinition Enhancements 17-3
Fine-Grained Dependency Management 17-4
Minimizing Dependent Recompilations 17-5
More Precise Dependency Metadata 17-6
Managing Dependencies 17-7

xv
Usage Guidelines to Reduce Invalidation 17-9
Invisible Index: Overview 17-10
Invisible Indexes: Examples 17-11
Adaptive Cursor Sharing: Overview 17-12
Adaptive Cursor Sharing: Architecture 17-13
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Adaptive Cursor Sharing Views 17-15


Interacting with Adaptive Cursor Sharing 17-16
SQL Query Result Cache: Overview 17-17
Setting Up SQL Query Result Cache 17-18
Managing the SQL Query Result Cache 17-19
Using the RESULT_CACHE Hint 17-20
In-Line View: Example 17-21 ble
Using Table Annotation to Control Result Caching 17-22 fe r a
Using the DBMS_RESULT_CACHE Package 17-23 ans
n - t r
Viewing SQL Result Cache Dictionary Information 17-24
SQL Query Result Cache: Considerations 17-25 a no
h a s ฺ
Quiz 17-27
OCI Client Query Cache 17-28 ฺ a r) uide
Using Client-Side Query Cache 17-29 ฺ c om ent G
PL/SQL Function Cache 17-30 a on tud
l l e@ is S
i
ฺz se th
Using PL/SQL Function Cache 17-31
l o
rce to u
PL/SQL Function Cache: Considerations 17-32
a
PL/SQL and Java Native Compilation Enhancements 17-33
(m ense
l e
Setting Up and Testing PL/SQL Native Compilation 17-34
i l
oZ lic
Recompiling the Entire Database for PL/SQL Native Compilation
l 17-35
e
Marc Summary 17-37
Practice 17: Overview 17-38

18 Backup and Recovery Enhancements


Objectives 18-2
Using New SET NEWNAME Clauses 18-3
Substitution Variables for SET NEWNAME 18-4
Using SET NEWNAME FOR DATABASE 18-5
Using SET NEWNAME FOR TABLESPACE 18-6
Performance Enhancements 18-7
Improved Block Corruption Detection 18-8
Using New Settings for Binary Compression 18-9
Using New Compression Algorithm Settings 18-10
Optimized Backups 18-11

xvi
Parallel Backup and Restore for Very Large Files 18-13
Using RMAN Multisection Backups 18-14
Quiz 18-15
Duplicating a Database 18-16
Performing Active Database Duplication 18-17
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

The RMAN DUPLICATE Command 18-18


Creating a Standby Database with the DUPLICATE Command 18-19
Enhancements to Database Duplication 18-20
Targetless DUPLICATE 18-21
Using Targetless DUPLICATE 18-22
Using New DUPLICATE Command Options 18-23
DUPLICATE … [SKIP] TABLESPACE Enhancements 18-24 ble
fe r a
Using RMAN to Create Archival Backups 18-25
ans
Managing Archival Database Backups 18-26
n - t r
o
an
Creating Archival Backups 18-27
Easier Recovery from Loss of Server Parameter File 18-28s
ha deฺ
TSPITR Enhancements and Modifications 18-29 r )
ฺa Gui
m
Identifying Relationships that Span Recovery Set Boundaries 18-30
co ent
n ฺ
Using Image Copies for Faster TSPITR Performance 18-31
Quiz 18-32 @ ao Stud
z i
Managing Recovery Catalogs 18-33l le this
c e loฺ use
The IMPORT CATALOG Command 18-35
a r to
m e
Creating and Using Virtual Private Catalogs 18-37
i l l e ( icens
Using RMAN Virtual Private Catalogs 18-38
e loZ
Quiz 18-40
l
Marc Summary 18-41
Practice 18: Overview Using RMAN Enhancements 18-42

19 Flashback Technology, LogMiner, and Data Pump Enhancements


Objectives 19-2
Flashback Data Archive: Overview 19-3
Flashback Data Archive: Architecture 19-5
Preparing Your Database 19-6
Flashback Data Archive: Workflow 19-10
Using Flashback Data Archive 19-11
Configuring a Default Flashback Data Archive 19-12
Filling the Flashback Data Archive Space 19-13
Maintaining Flashback Data Archives 19-14
Flashback Data Archive: Examples 19-15
Flashback Data Archive: DDL Restrictions 19-16

xvii
Flashback Data Archive: Supporting Transparent Schema Evolution 19-17
Flashback Data Archive: Supporting Full Schema Evolution 19-18
Viewing Flashback Data Archives 19-19
Guidelines and Usage Tips 19-20
Quiz 19-21
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Flashback Transaction Backout 19-22


Prerequisites 19-23
Flashing Back a Transaction 19-24
Using the Flashback Transaction Wizard 19-25
Using the DBMS_FLASHBACK.TRANSACTION_BACKOUT Procedure 19-26
Viewing a Dependency Report 19-27
Viewing Flashback Transaction Metadata 19-28 ble
Quiz 19-29 fe r a
Flashback Database Enhancements 19-30 ans
n - t r
Using LogMiner 19-31 o
Review: Data Pump Export and Import 19-32
s an
Migration with Data Pump Legacy Mode 19-33
r ) ha deฺ
Data Pump Legacy Mode 19-34 m ฺa Gui
Managing File Locations 19-36 n ฺ co ent
Quiz 19-37
@ ao Stud
Summary 19-38
z i l le this
c e loฺ use
Practice 19: Overview Using Flashback Technology 19-39
a r to
m e
i l l
20 Data Recovery e ( Advisor
c e ns
o Z 20-2li
Objectives
l
rceRepairing Data Failures 20-3
Ma Data Recovery Advisor 20-4
Assessing Data Failures 20-7
Data Failures 20-8
Data Failure: Examples 20-9
Data Recovery Advisor RMAN Command-Line Interface 20-10
Listing Data Failures 20-11
Advising on Repair 20-13
Executing Repairs 20-14
Classifying (and Closing) Failures 20-15
Quiz 20-16
Data Recovery Advisor Views 20-17
Best Practice: Proactive Checks 20-18
Setting Parameters to Detect Corruption 20-19
Summary 20-21
Practice 20: Overview Repairing Failures 20-22

xviii
Appendix A: Practices and Solutions

Appendix B: Scheduler Enhancements


Objectives B-2
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Lightweight Jobs B-3


Choosing the Right Job B-4
Scheduler Email Notification: Overview B-5
Using Scheduler Email Notification B-6
Setting the email_server Attribute B-7
Setting the email_sender Attribute B-8
Using ADD_JOB_EMAIL_NOTIFICATION B-9 ble
Using REMOVE_JOB_EMAIL_NOTIFICATION B-11 fe r a
ans
Email Notification: New Dictionary Views B-12
n - t r
Scheduler File Watcher: Overview B-13
a no
Creating a File Watcher and an Event-Based Job B-14
h a s ฺ
Step 1: Creating a Scheduler Credential Object B-15
ฺ a r) uide
Step 2: Creating a File Watcher B-16
ฺ c om ent G
on tud
Using DBMS_SCHEDULER.CREATE_FILE_WATCHER B-17
a
l l e@ is S
Step 3: Creating a Scheduler Program Object B-18
i
ฺz se th
Using the SCHEDULER_FILEWATCHER_RESULT Object Type B-20
l o
a rce to u
Using the SCHEDULER_FILEWATCHER_REQUEST Object Type B-21

l e n se Job that References the File Watcher B-22


(man eEvent-Based
Step 4: Creating
Z l
Step 5: iEnabling ithe
l c Objects B-23
l o
Enabling File Arrival Events from Remote Systems B-24
rce
Ma Using DBMS_SCHEDULER.DROP_FILE_WATCHER B-25
File Watcher: Changes to Existing DBMS_SCHEDULER Procedures B-26
File Watcher: Changes to Existing Attributes B-27
File Watcher: New Dictionary Views B-28
File Watcher: New Columns in Existing Views B-29
Scheduler Remote Database Jobs: Overview B-30
Using CREATE_DATABASE_DESTINATION B-31
Using DROP_DATABASE_DESTINATION B-32
Creating Remote Database Jobs: Configuration B-33
Setting Up the Database for Remote Jobs B-34
Creating Remote Database Jobs B-35
Scheduler Multiple Destination Jobs: Overview B-36
Scheduler Multiple Destination Jobs: Terminology B-37
Scheduler Multiple Destination Job States B-38
Creating Multiple Destination Jobs B-39

xix
Using Destination Groups for Multiple Destination Jobs B-40
Using CREATE_GROUP B-41
Using ADD_GROUP_MEMBER B-42
Using DROP_GROUP B-43
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Using REMOVE_GROUP_MEMBER B-44


Modifications to Existing DBMS_SCHEDULER Procedures B-45
Multiple Destination Jobs: New Dictionary Views B-46
Multiple Destination Jobs: New Columns in Existing Dictionary Views B-47
Summary B-48

Appendix C: Oracle Secure Backup Cloud Module


Objectives C-2 ble
fe r a
Oracle Database Backup in the Cloud C-3 s
Introducing Oracle Secure Backup Cloud Module C-4
- t r an
Advantages of Backing Up to the Cloud C-5 o n
What Is Amazon Simple Storage Service (S3)? C-6 s an
r
Installing the Oracle Secure Backup Cloud Module C-7) ha deฺ
Summary C-8 m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
e loZ l
Marc

xx
Appendix A
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Practices and Solutions

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc
Table of Contents
Practices for Lesson 1 ......................................................................................................... 4
Practice 1-1: Installing Oracle Grid Infrastructure for a Stand-Alone Server ............... 5
Practice 1-2: Configuring ASM Cluster File System ................................................... 11
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Practices for Lesson 2 ....................................................................................................... 16


Practice 2-1: Installing Oracle Database 11g Software ................................................ 17
Practice 2-2: Creating a New Database ........................................................................ 19
Practice 2-3: Using ASM Cluster File System Snapshots ............................................ 21
Practice 2-4: Using Online Patching ............................................................................. 26
Practices for Lesson 3 ....................................................................................................... 37
Practice 3-1: Using Oracle Restart to Manage Components ........................................ 38
Practices for Lesson 4 ....................................................................................................... 44 e
Practice 4-1: Using ASM Fast Mirror Resync .............................................................. 45 r a bl
fe
Practices for Lesson 5 ....................................................................................................... 51
s
Practice 5-1: Using Table Compression ....................................................................... 52
- t r an
n
Practices for Lesson 6 ....................................................................................................... 58
o
an
Practice 6-1: Using Reference Partitioning................................................................... 59
s
r ) ha deฺ
Practice 6-2: Using Interval Partitioning ...................................................................... 77
ฺa Gui
Practice 6-3: Using Extended Composite Partitioning ................................................. 88
m
n ฺ co ent
Practice 6-4: Using Virtual Column–Based Partitioning .............................................. 93
Practice 6-5: Using SQL Access Advisor for Partitioning Advice ............................. 105
ao Stud
Practices for Lesson 7 ..................................................................................................... 109
@
i l le this
Practice 7-1: Using SecureFiles .................................................................................. 110
z
c e loฺ use
Practices for Lesson 8 ..................................................................................................... 133
a r to
Practice 8-1: Using Password Security Features ........................................................ 134
m e
i l l e ( icens
Practice 8-2: Using an Encrypted Tablespace ............................................................ 143

el oZ l
Practices for Lesson 9 ..................................................................................................... 150
Practice 9-1: Using SQL Performance Analyzer ........................................................ 151
MarcPractices for Lesson 10 ................................................................................................... 176
Practice 10-1: Using SQL Plan Management ............................................................. 177
Practices for Lesson 11 ................................................................................................... 215
Practice 11-1: Using Database Replay........................................................................ 216
Practice 11-2: Using Database Replay - Nonsynchronized Mode .............................. 226
Practices for Lesson 12 ................................................................................................... 231
Practice 12-1: Using Automatic SQL Tuning............................................................. 232
Practices for Lesson 13 ................................................................................................... 244
Practice 13-1: Creating Baselines ............................................................................... 245
Practice 13-2: Controlling AutoTask Jobs .................................................................. 248
Practice 13-3: Calibrating I/O Resources ................................................................... 250
Practices for Lesson 14 ................................................................................................... 251
Practice 14-1: Using Support Workbench to Analyze Corruption ............................. 252
Practice 14-2: Using SQL Repair Advisor.................................................................. 264
Practices for Lesson 15 ................................................................................................... 278
Practice 15-1: Using Enterprise Manager to Monitor SQL Commands ..................... 279
Practices for Lesson 16 ................................................................................................... 283

Oracle Database 11g: New Features for Administrators A - 2


Practice 16-1: Using Automatic Memory Management ............................................. 284
Practice 16-2: Using Deferred Optimizer Statistics .................................................... 297
Practices for Lesson 17 ................................................................................................... 317
Practice 17-1: Using Result Cache ............................................................................. 318
Practices for Lesson 18 ................................................................................................... 336
Practice 18-1: Duplicating an Active Database .......................................................... 337
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Practice 18-2: Managing Catalogs .............................................................................. 343


Practices for Lesson 19 ................................................................................................... 353
Practice 19-1: Using Flashback Data Archive ............................................................ 354
Practice 19-2: Performing Flashback Transaction Blackout ...................................... 373
Practices for Lesson 20 ................................................................................................... 383
Practice 20-1: Repairing a Database by Using Enterprise Manager ........................... 384
Practice 20-2: Repairing Block Corruption by Using Enterprise Manager ................ 394
Practice 20-3: Repairing a Database by Using RMAN .............................................. 398
ble
fe r a
an s
n - t r
o
an
Note: In all the practices for this course, simple and easy to remember passwords are
s
r ) ha deฺ
used in order not to distract from the purpose of the exercise. In real development and

Database Security Guide. m ฺa Gui


production environments, use strong passwords following the guidelines in Oracle

n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 3


Practices for Lesson 1

In the practices for this lesson, you install the Oracle Grid Infrastructure for a stand-alone
server and configure the ASM cluster file system.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
an s
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 4


Practice 1-1: Installing Oracle Grid Infrastructure for a
Stand-Alone Server
In this practice, you create ASM disks that you use to install and configure Oracle Grid
Infrastructure on your machine.
1) Connected as the root user, in a terminal window, configure the oracleasm
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

component so that it is owned by oracle and group dba. In addition, make sure
that the oracleasm component starts on boot.
# lsmod | grep oracleasm
# oracleasm configure -i
Configuring the Oracle ASM library driver.

This will configure the on-boot properties of the Oracle ASM


library ble
driver. The following questions will determine whether the
fe r a
driver is
an s
loaded on boot and what permissions it will have. The current
n - t r
values
will be shown in brackets ('[]'). Hitting <ENTER> without a no
typing an h a s ฺ
answer will keep that current value. Ctrl-C will abort. ฺ a r) uide
Default user to own the driver ฺ c om ent[]:
interface
G
Default group to own the driver a on interface
t u d []:oracle dba
Start Oracle ASM library e@ s
l onthboot S
i (y/n) [y]: y[n]: y
driver on boot (y/n)
z i l
Scan for Oracle ASM
Writing Oracle c e loฺ library
ASM
disks
u se driver configuration: done
# a r to
m e
2) Make i l l e ( thaticyour
sure e nsoracleasm configuration is taken into account by starting this
l o Z
component.
l
rc e
Ma # oracleasm exit
# oracleasm init
Creating /dev/oracleasm mount point: /dev/oracleasm
Loading module "oracleasm": oracleasm
Mounting ASMlib driver filesystem: /dev/oracleasm
# oracleasm status
Checking if ASM is loaded: yes
Checking if /dev/oracleasm is mounted: yes
# lsmod | grep oracleasm
oracleasm 46356 1
#
3) Use oracleasm to create your ASM disks. You have 13 block devices that you can use
on your machine: /dev/xvdb, /dev/xvdc, …, /dev/xvdn. Name each
ASM disk as follows: ASMDISK01, ASMDISK02, …, ASMDISK13.
# oracleasm createdisk ASMDISK01 /dev/xvdb
Writing disk header: done
Instantiating disk: done

Oracle Database 11g: New Features for Administrators A - 5


Practice 1-1: Installing Oracle Grid Infrastructure for a
Stand-Alone Server (continued)
# oracleasm createdisk ASMDISK02 /dev/xvdc
Writing disk header: done
Instantiating disk: done
# oracleasm createdisk ASMDISK03 /dev/xvdd
Writing disk header: done
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Instantiating disk: done


# oracleasm createdisk ASMDISK04 /dev/xvde
Writing disk header: done
Instantiating disk: done
# oracleasm createdisk ASMDISK05 /dev/xvdf
Writing disk header: done
Instantiating disk: done
# oracleasm createdisk ASMDISK06 /dev/xvdg
Writing disk header: done
ble
Instantiating disk: done
fe r a
# oracleasm createdisk ASMDISK07 /dev/xvdh
ans
Writing disk header: done
n - t r
Instantiating disk: done o
# oracleasm createdisk ASMDISK08 /dev/xvdi
s an
Writing disk header: done
r ) ha deฺ
Instantiating disk: done
# oracleasm createdisk ASMDISK09 m ฺa Gui
/dev/xvdj
Writing disk header: done n ฺ co ent
Instantiating disk: done
@ ao Stud
z i l le this /dev/xvdk
# oracleasm createdisk ASMDISK10

e loฺ use
Writing disk header: done
Instantiating disk: done
c
a r to
# oracleasm createdisk ASMDISK11 /dev/xvdl
( m s e
ille licen
Writing disk header: done

l o Z
Instantiating disk: done
# oracleasm createdisk ASMDISK12
e /dev/xvdm

Marc Writing disk header: done


Instantiating disk: done
# oracleasm createdisk ASMDISK13 /dev/xvdn
Writing disk header: done
Instantiating disk: done
#

4) Make sure that you now have 13 ASM disks by using the listdisks command.
# oracleasm scandisks
Reloading disk partitions: done
Cleaning any stale ASM disks...
Scanning system for ASM disks...
# oracleasm listdisks
ASMDISK01
ASMDISK02
ASMDISK03
ASMDISK04
ASMDISK05
ASMDISK06

Oracle Database 11g: New Features for Administrators A - 6


Practice 1-1: Installing Oracle Grid Infrastructure for a
Stand-Alone Server (continued)
ASMDISK07
ASMDISK08
ASMDISK09
ASMDISK10
ASMDISK11
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ASMDISK12
ASMDISK13
#

5) As user oracle, in a graphical terminal session, install Oracle Grid Infrastructure on


your machine in the /u01/app/oracle/product/11.2.0/grid directory.
Make sure that you use the first four ASM disks (ASMDISK01, …, ASMDISK04)
you previously created to create the normal redundancy disk group DATA.
ble
a) Set up your environment variables to point to the
fe r a
/u01/app/oracle/product/11.2.0/grid Oracle home for your grid
ans
infrastructure installation. n - t r
$ . oraenv a no
ORACLE_SID = [db10g] ? +ASM h a s ฺ
ORACLE_HOME = [/home/oracle] ?
ฺ a r) uide
/u01/app/oracle/product/11.2.0/grid
$ echo $ORACLE_BASE ฺ c om ent G
/u01/app/oracle a on tud
$
l l e@ is S
i
ฺz sInstallerth from the Oracle Grid Infrastructure
b) Execute the Oraclel oUniversal e
rcedirectory.
software staging
a t o u
$ cd l e (m ense
i l /stage/11*/g*
lic
el o$ Z./runInstaller
arc
Starting Oracle Universal Installer...
M Checking Temp space: must be greater than 80 MB. Actual 9119
MB Passed
Checking swap space: must be greater than 150 MB. Actual
4000 MB Passed
Checking monitor: must be configured to display at least 256
colors. Actual 16777216 Passed
Preparing to launch Oracle Universal Installer from
/tmp/OraInstall2009-09-28_10-00-29AM. Please wait ...
c) On the Select Installation Option page, select “Install and Configure Grid
Infrastructure for a Standalone Server.” Click Next.
d) On the Select Product Languages page, select all languages by clicking the double
arrow button. Then click Next.

Oracle Database 11g: New Features for Administrators A - 7


Practice 1-1: Installing Oracle Grid Infrastructure for a
Stand-Alone Server (continued)
e) On the Create ASM DiskGroup page, enter DATA in the Disk Group Name, select
Normal for the Redundancy field, and select the following Candidate Disks:
ORCL:ASMDISK01, ORCL:ASMDISK02, ORCL:ASMDISK03,
ORCL:ASMDISK04. Then click Next.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

f) On the Specify ASM Password page, select “Use same passwords for these
accounts,” and then enter oracle_4U in both the Specify Password and
Confirm Password fields. Click Next.
g) On the Privileged Operating System Groups page, select dba for each group.
Click Next.
h) When the warning window appears, click Yes to continue.
i) On the Installation Location page, make sure that Oracle Base is set to ble
/u01/app/oracle, and Software Location is set to fe r a
/u01/app/oracle/product/11.2.0/grid. Then click Next. ans
n - t r
no
j) The Perform Prerequisite Checks page appears. Wait until the checks complete.
a
k) On the Summary page, click Finish.
h a s ฺ
l) The Setup page appears. ฺ a r) uide

m) Wait until you are asked to execute anscript. com ent G
n) When the Execute Configuration @
o
aScripts S tud appears, connected as root
window
from a terminal window,z i l e tthe
lexecute h isneeded script:
c e loฺ use
# /u01/app/oracle/product/11.2.0/grid/root.sh
a r 11g troot.sh
o
Running m
( Oracle
n s e script...
l e
ilfollowingi ce environment variables are set as:
Z
The l
rc elo ORACLE_OWNER= oracle
Ma ORACLE_HOME= /u01/app/oracle/product/11.2.0/grid

Enter the full pathname of the local bin directory:


[/usr/local/bin]:
Copying dbhome to /usr/local/bin ...
Copying oraenv to /usr/local/bin ...
Copying coraenv to /usr/local/bin ...

Entries will be added to the /etc/oratab file as needed by


Database Configuration Assistant when a database is created
Finished running generic part of root.sh script.
Now product-specific root actions will be performed.
2009-09-28 10:19:44: Checking for super user privileges
2009-09-28 10:19:44: User has super user privileges
2009-09-28 10:19:44: Parsing the host name
Using configuration parameter file:
/u01/app/oracle/product/11.2.0/grid/crs/install/crsconfig_para
ms
Creating trace directory

Oracle Database 11g: New Features for Administrators A - 8


Practice 1-1: Installing Oracle Grid Infrastructure for a
Stand-Alone Server (continued)
LOCAL ADD MODE
Creating OCR keys for user 'oracle', privgrp 'oinstall'..
Operation successful.
CRS-4664: Node edrsr22p1 successfully pinned.
ohasd is starting
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Adding daemon to inittab


CRS-4123: Oracle High Availability Services has been started.
ohasd is starting
Successfully configured Oracle Grid Infrastructure for a
Standalone Server
Updating inventory properties for clusterware
Starting Oracle Universal Installer…
Checking swap space: must be greater than 500 MB. Actual 4000
MB Passed
ble
The inventory pointer is located at /etc/OraInst.loc
fe r a
The inventory is located at /u01/app/oracle/oraInventory
ans
‘UpdateNodeList’ was successful.
n - t r
#
a no
o) Return to the Execute Configuration Scripts window and
h a sclick OK.

r ) i d e
ฺa Gu
p) Wait until all configuration assistants are executed.
m
q) On the Finish page, click Close. ฺ c o e n t
n
6) Use ASMCA to create the FRA @ external S tudusing the next four ASM disks
ao diskgroup
(ASMDISK05, …, ASMDISK08).z i l le this
e l oฺ use
a) In a graphical
a c
r terminaltowindow, connected as user oracle, make sure that your
l e m
environment se are correctly set, and invoke ASMCA.
( evariables
n
$Z
l
.i oraenvlic
l o
e ORACLE_SID = [+ASM] ? +ASM
rc
Ma The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid is
/u01/app/oracle
$ asmca

b) On the Disk Groups tab page, click Create.


c) On the Create Disk Group page, enter FRA in the Disk Group Name field. Select
External (None) for the disk group Redundancy. Select the following ASM disks:
ORCL:ASMDISK05, ORCL:ASMDISK06, ORCL:ASMDISK07, and
ORCL:ASMDISK08.
d) Click Show Advanced Options and make sure that both the ASM and Database
Compatibility fields are set to 11.2.0.0.0. Then click OK.
e) The DiskGroup: Creation windows appear. After the disk group is created, click
OK on the DiskGroup: Creation window.

Oracle Database 11g: New Features for Administrators A - 9


Practice 1-1: Installing Oracle Grid Infrastructure for a
Stand-Alone Server (continued)
f) On the Disk Group tabbed page, make sure that you can see the FRA disk group
mounted. Click Exit.
g) In the ASM Configuration Assistant window, click Yes.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 10


Practice 1-2: Configuring ASM Cluster File System
In this practice, you configure the ACFS drivers to load automatically on boot. Then you
create a new ASM disk group that you will use later to store your Oracle Database
binaries in an ASM Cluster File System.
1) Connected as the root user from a terminal session, determine the list of ASM
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

drivers that are currently loaded on your system.


# lsmod | grep oracle
oracleacfs 787460 0
oracleadvm 177792 0
oracleoks 226656 2 oracleacfs,oracleadvm
oracleasm 46356 1
#
2) Reboot your system. ble
fe r a
# reboot
ans
n - t r
Broadcast message from root (pts/2) (Mon Sep 28 12:21:04
2009): a no
h a s ฺ
The system is going down for reboot NOW! ฺ a r) uide
#
ฺ c om ent G
3) After reboot, reconnect to your system a oasnthe root
tud user and determine again the list
of ASM drivers that are currently @
le loaded. S
isWhat are your conclusions?
z i l t h
loofฺ the uACFS
a) It is clear that none
c e se drivers are loaded anymore.
a r oracle to
# lsmod m | grep e
i l l
oracleasm e ( icens 46356 1
#Z l
elo
rc 4) Manually restart the ACFS drivers.
Ma
# /u01/app/oracle/product/11.2.0/grid/bin/acfsload start -s
# lsmod | grep oracle
oracleacfs 787460 0
oracleadvm 177792 0
oracleoks 226656 2 oracleacfs,oracleadvm
oracleasm 46356 1
#
5) How would you make sure that those drivers are automatically loaded on boot?
a) Create a script in the /etc/init.d directory to start ACFS drivers. The script
should contain the following commands:
#!/bin/sh
# chkconfig: 2345 30 21
# description: Load Oracle ACFS drivers at system boot

Oracle Database 11g: New Features for Administrators A - 11


Practice 1-2: Configuring ASM Cluster File System (continued)
/u01/app/oracle/product/11.2.0/grid/bin/acfsload start
-s
# vi /etc/init.d/acfsload
Insert the commands as shown above into your file.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

This is what your file should look like:

# cat /etc/init.d/acfsload
#!/bin/sh

# chkconfig: 2345 30 21
# description: Load Oracle ACFS drivers at system boot
/u01/app/oracle/product/11.2.0/grid/bin/acfsload start -s

# ble
fe r a
b) Add the script as a service using the chkconfig command. ans
n - t r
# chmod u+x /etc/init.d/acfsload
# chkconfig --add acfsload a no
# chkconfig --list acfsload
h a s ฺ
acfsload 0:off 1:off 2:on
ฺ a r)3:on uide4:on 5:on
6:off
# ฺ c om ent G
6) Validate your solution and make@ aothatn allSACFS
sure tud drivers are loaded on boot.
# reboot z i l le this
c e loฺ use
a r
Broadcast message to root (pts/2) (Mon Sep 28 12:55:25
from
2009): ( m e
i l l e icens
l o Z l
The system is going down for reboot NOW!
rc e # login as: root
Ma root@...'s password:
Last login: Mon Sep 28 12:20:58 2009 from …
# lsmod | grep oracle
oracleacfs 787460 0
oracleadvm 177792 0
oracleoks 226656 2 oracleacfs,oracleadvm
oracleasm 46356 1
#
7) Use ASMCA to create the ACFS disk group with the following characteristics: Use
external redundancy, use ASMDISK09 to ASMDISK11. Also, make sure that this
disk group can host an ASM volume and an Oracle Database home.
a) Make sure that you wait until your ASM instance is automatically started by the
system following your previous reboot.
# ps -ef | grep lgwr
oracle 5799 1 0 19:08 ? 00:00:00 asm_lgwr_+ASM
root 5839 5600 0 19:12 pts/2 00:00:00 grep lgwr
#

Oracle Database 11g: New Features for Administrators A - 12


Practice 1-2: Configuring ASM Cluster File System (continued)
b) In a graphical terminal window, connected as the oracle user, set up your
environment variables to point to your ASM instance, and execute the asmca
command.
$ . oraenv
ORACLE_SID = [db10g] ? +ASM
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

$ asmca

c) On the Disk Groups page, click Create.


d) On the Create Disk Group page, enter ACFS in the Disk Group name field. Select
External (None) for the Redundancy. Then select the following ASM disks:
ORCL:ASMDISK09, ORCL:ASMDISK10, and ORCL:ASMDISK11. Click
Show Advanced Options, and make sure that all the three Diskgroup e
Compatibility attributes are set to 11.2.0.0.0. Click OK. r a bl
e) It takes a while to create the disk group.
fens
t r a
- Click
f) After the disk group is created, the Diskgroup: Creation window appears. o n
OK.
s an
g) On the Disk Group tabbed page, you should now r )
see
a ACFS
hyour e ฺ disk group
mounted. ฺa Gu i d
o m nt hosted by your ACFS disk
8) After you create the ACFS disk group,ocreate n ฺc a filedsystem
e
group. After it is created, make sure@ athat theSfiletusystem is mounted on
/u01/app/oracle/acfsmounts.z i l l e t h is
e
a) Right-click thecACFSloฺ DiskuGroup se Name.
a r t o
m
b) In the (menu that s e
i l l e icenappears, select Create ACFS for Database Home.
oc)ZThe Createl ACFS Hosted Database Home window appears. Leave all the defaults:
l
e acfs_db1, 6, oracle, oinstall, and enter
rc
Ma /u01/app/oracle/acfsmounts/acfs_db1 in the Database Home
Mountpoint field. Click OK.
d) The new ASM volume and file system are automatically created.
e) Once done, the Database Home: Run ACFS script window appears.
f) As user root, open a terminal window and execute the
/u01/app/oracle/cfgtoollogs/asmca/scripts/acfs_script.
sh script.
# /u01/app/oracle/cfgtoollogs/asmca/scripts/acfs_script.sh
#
g) Then click Close in the Database Home: Run ACFS script window.
h) On the Disk Groups tabbed page, notice that the ACFS disk group is almost full
now.
i) Click the Volumes tab to see the ASM volume that was automatically created.

Oracle Database 11g: New Features for Administrators A - 13


Practice 1-2: Configuring ASM Cluster File System (continued)
j) Click the ASM Cluster File Systems tab to see the file system that was
automatically created.
k) Click Exit to exit from ASMCA.
l) On ASM Configuration Assistant that appears, click Yes.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

9) Using a terminal session, connected as the root user, explore your new file system.
# ls -l /u01/app/oracle
total 36
drwxr-x--- 3 oracle oinstall 4096 Sep 28 13:06 acfsmounts
drwxr-x--- 4 oracle oinstall 4096 Sep 28 10:21 admin
drwxr-xr-x 4 oracle oinstall 4096 Sep 28 10:21 cfgtoollogs
drwxr-xr-x 2 oracle oinstall 4096 Sep 28 10:22 checkpoints
drwxrwxr-x 4 oracle oinstall 4096 Sep 28 10:21 diag
drwxr-x--- 3 oracle oinstall 4096 May 8 18:01 ble
flash_recovery_area fe r a
drwxr-x--- 3 oracle oinstall 4096 May 8 18:00 oradata
ans
drwxrwx--- 7 oracle oinstall 4096 Sep 28 10:20 oraInventory
n - t r
o
drwxrwx--- 4 oracle oinstall 4096 Sep 28 10:12 product
# ls -l /u01/app/oracle/acfsmounts s an
total 4
r ) ha deฺ
ฺa Gui
drwxrwxr-x 4 oracle oinstall 4096 Sep 28 13:08 acfs_db1
m
# ls -la /u01/app/oracle/acfsmounts/*
total 76 n ฺ co ent
ao Stud
drwxrwxr-x 4 oracle oinstall 4096 Sep 28 13:08 .
@
l le this
drwxr-x--- 3 oracle oinstall 4096 Sep 28 13:06 ..
z i
drwxr-xr-x 5 root
drwx------ 2 root c e loฺ use
root
root
4096 Sep 28 13:08 .ACFS
65536 Sep 28 13:08 lost+found
a r to
[root@edrsr22p1 ~]#
m e
i l l e ( icens
# ls -l /dev/asm

el oZ
total 0 l
brwxrwx--- 1 root dba 252, 246273 Sep 28 13:06 acfs_db1-481
Marc # mount
/dev/sda5 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda2 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw,size=1152M)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
oracleasmfs on /dev/oracleasm type oracleasmfs (rw)
/dev/sda1 on /mnt/cdrive type vfat (rw)
/dev/asm/acfs_db1-481 on /u01/app/oracle/acfsmounts/acfs_db1
type acfs (rw)
# acfsutil info fs
/u01/app/oracle/acfsmounts/acfs_db1
ACFS Version: 11.2.0.1.0.0
flags: MountPoint,Available
mount time: Mon Sep 28 13:08:48 2009
volumes: 1

Oracle Database 11g: New Features for Administrators A - 14


Practice 1-2: Configuring ASM Cluster File System (continued)
total size: 6442450944
total free: 6391668736
primary volume: /dev/asm/acfs_db1-481
label:
flags: Primary,Available,ADVM
on-disk version: 39.0
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

allocation unit: 4096


major, minor: 252, 246273
size: 6442450944
free: 6391668736
ADVM diskgroup ACFS
ADVM resize increment: 268435456
ADVM redundancy: unprotected
ADVM stripe columns: 4
ADVM stripe width: 131072
ble
number of snapshots: 0
fe r a
snapshot space usage: 0
ans
#
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 15


Practices for Lesson 2

In the practices for this lesson, you install the Oracle Database 11g software and create a
database. You use ASM cluster file system snapshots. Finally, you use online patching to
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

patch your database.

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 16


Practice 2-1: Installing Oracle Database 11g Software
In this practice, you install the Oracle Database software in the ASM Cluster File System
mounted on /u01/app/oracle/acfsmounts/acfs_db1.
1) From a graphical terminal session, make sure that you set up your environment
variables to point to your ASFC mount point for your ORACLE_HOME, and ensure
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

that your ORACLE_BASE is set to /u01/app/oracle.


$ . oraenv
ORACLE_SID = [+ASM] ? orcl
ORACLE_HOME = [/home/oracle] ?
/u01/app/oracle/acfsmounts/acfs_db1
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle
ble
$
fe r a
2) Change your current directory to the staged software, and invoke the Oracle an s
n - t r
Universal Installer.
a no
$ cd /stage/11*/d*
$ ./runInstaller h a s ฺ
Starting Oracle Universal Installer... ฺ a r) uide
ฺ c om ent G
Checking Temp space: must beogreater
a n udthan 80 MB. Actual 6589
MB Passed @ S t
Checking swap space:ilmust
z e s
l bethgreater
i than 150 MB. Actual
ฺ e
3868 MB
r
Checking monitor: c elo must
Passed
o
s configured to display at least 256
ube
a t
colors.(m Actuale 16777216 Passed
e n s
Z ill
Preparing
l
toelaunch Oracle Universal Installer from
i c
/tmp/OraInstall2009-05-25_02
l o
e Please wait …
rc
Ma 3) On the Configure Security Updates page, make sure that nothing is selected and click
Next.
4) In the Email Address Not Specified window alert, click Yes.
5) On the Installation Option page, select Install Database Software Only, and click
Next.
6) On the Grid Options page, select Single Instance Database Installation option, and
click Next.
7) On the Product Languages page, select all languages using the double arrow button.
Then click Next.
8) On the Database Edition page, select the Enterprise Edition option, and click Next.
9) On the Installation Location page, make sure that Oracle Base field is set to
/u01/app/oracle, and Software Location is set to
/u01/app/oracle/acfsmounts/acfs_db1. Then click Next.

Oracle Database 11g: New Features for Administrators A - 17


Practice 2-1: Installing Oracle Database 11g Software
(continued)
10) If a warning window appears stating that the Oracle Home selected is not empty,
click Yes.
11) On the Operating System Groups page, make sure that dba and dba are selected for
OSDBA and OSOPER, respectively. Then click Next.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

12) After the prerequisite checks complete, the Summary page appears. Click Finish.
13) The installation process starts.
14) Wait until you are asked to run a script as the root user.
15) When you are asked to execute the
/u01/app/oracle/acfsmounts/acfs_db1/root.sh script, open a
terminal window as the root user and execute the script: e
r a bl
$ su -
sfe
Password:
# /u01/app/oracle/acfsmounts/acfs_db1/root.sh - t r an
Running Oracle 11g root.sh script... no n
s a
The following environment variables are set h aas: eฺ
ORACLE_OWNER= oracle ฺ a r) uid
ฺ c om ent G
ORACLE_HOME= /u01/app/oracle/acfsmounts/acfs_db1

Enter the full pathname ofathe local


on tudbin directory:
[/usr/local/bin]: l l e@ is S
z i
ฺalready th in /usr/local/bin. Overwrite
The file "dbhome" l o eexists
it? (y/n)
a r ce to us
[n]:
l e
The lfile
(m"oraenv"
e n se already exists in /usr/local/bin. Overwrite
l Zi (y/n) lic
oit?
e [n]:
Marc The file "coraenv" already exists in /usr/local/bin.
Overwrite it? (y/n)
[n]:

Entries will be added to the /etc/oratab file as needed by


Database Configuration Assistant when a database is created
Finished running generic part of root.sh script.
Now product-specific root actions will be performed.
Finished product-specific root actions.
#
16) After it is complete, go back to your OUI window and click OK on the Execute
Configuration Scripts page.
17) On the Finish page, click Close.

Oracle Database 11g: New Features for Administrators A - 18


Practice 2-2: Creating a New Database
In this practice, you create a new database in ASM disk groups.
1) Use DBCA to create a new database.
a) Connected as the oracle user in a graphical terminal session, make sure that
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

your environment is correctly set for Oracle Database 11g.


$ . oraenv
ORACLE_SID = [orcl] ? orcl
ORACLE_HOME = [/home/oracle] ?
/u01/app/oracle/acfsmounts/acfs_db1
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle
$ ble
fe r a
b) Execute the dbca command from that same terminal window:
ans
$ dbca n - t r
a no
c) On the Welcome page, click Next. s ฺ
h a
d) On the Operations page, select Create a Database
ฺ a u de
) click iNext.
rand
e) On the Database Templates page, selectcthe
ฺ om General
n t G or Transaction
Purpose
Processing template and click Next.
a on tude
l e
f) On the Database Identification@page,ienter
s S orcl (do not use a domain) in the
i l h
tclick Next.
e l oฺz field
Global Database Name s e
and
u page, confirm the following selections and click
a rc Options
g) On the Management t o
Next:
l e (m ense
l
Z•i Configure
lic Enterprise Manager
e l o
rc
Ma • Configure Database Control for local management
h) On the Database Credentials page, select “Use the Same Administrative Password
for All Accounts,” enter oracle_4U in both the Password and the Confirm
Password fields and click Next.
i) On the Database File Locations page, select Automatic Storage Management
(ASM) from the Storage Type drop down list, and make sure Use Oracle-
Managed Files is selected.
j) On the same page, click the Browse button next to the Database Area field.
k) On the Select Disk Group page, select DATA and click OK.
l) Click Next.
m) On the ASM Credentials page, enter oracle_4U for the ASMSNMP user
password. Then click OK.
n) On the Recovery Configuration page, select Specify Flash Recovery Area.
o) Click Browse, next to the Flash Recovery Area field.

Oracle Database 11g: New Features for Administrators A - 19


Practice 2-2: Creating a New Database (continued)
p) On the Select Disk Group page, select FRA and click OK.
q) Click Next.
r) On the Database Content page, select Sample Schemas and click Next.
s) On the Initialization Parameters: Memory page, select Custom, and set SGA Size
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

to 404 M Bytes and PGA Size to 150 M Bytes. Then click the Character Sets
tab.
t) On the Character Sets page, select Use Unicode (AL32UTF8). Click Next.
u) On the Database Storage page, click Next.
v) On the Creation Options page, select Create Database and click Finish.
w) On the Confirmation page, click OK.
ble
x) Wait until the database is created.
fe r a
an
y) After the DBCA finishes, note the following information for future reference: s
- t r
Location of installation log files, global database name, system identifier (SID),
n
o
s an
server parameter file name and location, Enterprise Manager Database Control
URL. Note that Enterprise Manager Database Control is SSL-enabled by default.
) ha deฺ
In the Database Configuration Assistant dialog box, click Exit.
r
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 20


Practice 2-3: Using ASM Cluster File System Snapshots
In this practice, you use ACFS Snapshots to recover files from your file system.
1) In a terminal window, identify the directory structure of your
/u01/app/oracle/acfsmounts/acfs_db1 file system. What can you see?
(Note: Do not exit from your terminal window after completing step 1. You will use
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

it again in step 3.)


a) You should see a directory called .ACFS that contains ACFS snapshots.
$ cd /u01/app/oracle/acfsmounts/acfs_db1
$
$ ls -la
total 520
drwxrwxr-x 76 oracle oinstall 8192 Sep 28 14:37 .
drwxr-x--- 3 oracle oinstall 4096 Sep 28 13:06 .. ble
drwxr-xr-x 5 root root 4096 Sep 28 13:08 .ACFS fe r a
drwxr-xr-x 8 oracle oinstall 8192 Sep 28 13:51 apex ans
drwxr-xr-x 8 oracle oinstall 4096 Sep 28 13:48 - t
assistants
n r
drwxr-xr-x 2 oracle oinstall 20480 Sep 28
a no
14:34 bin
...
h a s ฺ
drwxr-xr-x 2 oracle oinstall 4096 Sep 28 13:49 utl
drwxr-xr-x 3 oracle oinstall 4096 Sep 28 ฺ a u idewwg
r) 13:48
drwxr-xr-x 7 oracle oinstall 4096 Sep 28
ฺ c om ent G13:49 xdk
$
a on tud
$ ls -la .ACFS l l e@ is S
i
ฺz se th
total 32 l o
e oroot u
drwxr-xr-x r5croot 4096 Sep 28 13:08 .
a t
drwxrwxr-x
l e
drwx------
se oinstall
(m 76e2 noracle
root root
8192 Sep 28 14:37 ..
4096 Sep 28 13:08 .fileid
Z i l
drwx------ l i c6 root root 4096 Sep 28 13:08 repl
rc elodrwxr-xr-x 2 root root 4096 Sep 28 13:08 snaps
Ma $
$ ls -la .ACFS/snaps
total 8
drwxr-xr-x 2 root root 4096 Sep 28 13:08 .
drwxr-xr-x 5 root root 4096 Sep 28 13:08 ..
$
2) Create a new snapshot of your ASM Cluster File System using Enterprise Manager
Database Control.
a) Invoke Enterprise Manager Database Control by entering the following URL in
your browser: https://<hostname>:5500/em. Connect as the SYS user with a
password of oracle_4U. Select SYSDBA from the Connect As menu. (In an
Oracle University classroom, you may receive an alert message regarding the
security certificate. If you do, click OK to close the Alert window. Click the “Or
you can add an exception link.” Click Add Exception. Click Get Certificate. Click
Confirm Security Exception. Continue to log in to Enterprise Manager as
described previously.)

Oracle Database 11g: New Features for Administrators A - 21


Practice 2-3: Using ASM Cluster File System Snapshots
(continued)
b) On the database Home page, click the +ASM link in the General section.
c) On the Automatic Storage Management: +ASM page, click the ASM Cluster File
System tab.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

d) On the Automatic Storage Management Login page, enter the SYS user
credentials (sys/oracle_4U), choose the SYSASM role from the drop down
box, select “Save as Preferred Credential,” and click Login.
e) On the Automatic Storage Management: +ASM page, ASM Cluster File System
tab, select the file system /u01/app/oracle/acfsmounts/acfs_db1
mount point, and then click Create Snapshot.
f) On the Create Snapshot on ASM Cluster File System:
/u01/app/oracle/acfsmounts/acfs_db1 page, enter snapshot_1 as the Snapshot ble
Name. fe r a
an s
t
g) Click Show Command, to view the acfsutil command to create this snapshot.
n - r
The command should be: /sbin/acfsutil snap create
a no
"snapshot_1" /u01/app/oracle/acfsmounts/acfs_db1 s ฺ
h a
h) On the Show Command page, click Return.
ฺ a r) uide
i) Back to the Create Snapshot on ASM Cluster ฺ c omFileenSystem:
tG
/u01/app/oracle/acfsmounts/acfs_db1
a onpage,tuclick
d OK.
j) On the ASM Cluster File @
e tHost
lSystem S
isCredentials page, enter oracle/oracle
z i l h
c e loฺ select
as your host credentials,
u s e“Save as Preferred Credential,” and click
Continue. r to
m a e
k) Back
i l l e to( theicAutomatic
e ns Storage Management: +ASM page, you should get a
l o ZConfirmation l status stating the snapshot "snapshot_1" has been created
rc e successfully.
Ma l) On the ASM Cluster File System tab, you should see that the number of snapshots
for your file system is now 1.
3) In your terminal window (still at the
/u01/app/oracle/acfsmounts/acfs_db1 directory), verify that the
snapshot was created.
a) Although you can see all files in your snapshot, its creation was very quick!
$ ls -la .ACFS/snaps
total 24
drwxr-xr-x 3 root root 4096 Sep 29 11:24 .
drwxr-xr-x 5 root root 4096 Sep 28 13:08 ..
drwxrwxr-x 76 oracle oinstall 8192 Sep 29 11:24 snapshot_1
$
$ ls -la .ACFS/snaps/*
total 456
drwxrwxr-x 76 oracle oinstall 8192 Sep 29 11:24 .
drwxr-xr-x 3 root root 4096 Sep 29 11:24 ..

Oracle Database 11g: New Features for Administrators A - 22


Practice 2-3: Using ASM Cluster File System Snapshots
(continued)
drwxr-xr-x 5 root root 4096 Sep 28 13:08 .ACFS
drwxr-xr-x 8 oracle oinstall 8192 Sep 28 13:51 apex
drwxr-xr-x 8 oracle oinstall 4096 Sep 28 13:48 assistants
drwxr-xr-x 2 oracle oinstall 20480 Sep 28 14:34 bin
...
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

drwxr-xr-x 2 oracle oinstall 4096 Sep 28 13:49 utl


drwxr-xr-x 3 oracle oinstall 4096 Sep 28 13:48 wwg
drwxr-xr-x 7 oracle oinstall 4096 Sep 28 13:49 xdk
$
4) Using Enterprise Manager Database Control, verify that your snapshot was created
and that it contains the necessary files.
a) Back to the ASM Cluster File System tab page, click 1 in the Snapshots column e
for your file system.
r a bl
s fe
b) On the ASM Cluster File System: /u01/app/oracle/acfsmounts/acfs_db1 page,
- t r
Snapshots tab, click the snapshot_1 link in the Name column of the Snapshots
an
table. no n
a
s and
c) If required, enter oracle/oracle for your Host Credentials
) h a e ฺ click Continue.
You can select “Save as Preferred Credential.”ฺa r uid
d) This brings you the Search and List: Directory
m
co page n G
tfrom where you can search
n ฺ e
for files in your snapshots.
@ ao Stud
5) From a terminal window, remove
z i l le thetdemo
h is directory from your Oracle Database
Home. This is doneetolo ฺ
simulate e error.
ashuman
r c to u
$ rm -r m a e
/u01/app/oracle/acfsmounts/acfs_db1/demo
$ ls le ( e ns
Z
apexi l c
li emcli md precomp
e l oassistants EMStagePatches_orcl mesg racg
rc
Ma bin
ccr
has
hs
mgw
network
rdbms
relnotes
cdata ide nls root.sh
cfgtoollogs install oc4j scheduler
clone install.platform odbc slax
config instantclient olap sqldeveloper
crs inventory ons sqlj
csmig j2ee OPatch sqlplus
css javavm opmn srvm
ctx jdbc oracore sysman
cv jdev oraInst.loc timingframework
dbs jdk ord ucp
dc_ocm jlib oui uix
deinstall ldap owb utl
diagnostics lib owm wwg
dv log perl xdk
edrsr lost+found plsql
$

Oracle Database 11g: New Features for Administrators A - 23


Practice 2-3: Using ASM Cluster File System Snapshots
(continued)
6) Using Enterprise Manager Database Control, make sure that you can recover that lost
directory.
a) Back to the Search and List: Directory page, click the demo link in the Search
table.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

b) You can see that it contains the schema directory.


c) Click the Close button.
7) Restore the demo directory using operating system commands.
$ cp -r
/u01/app/oracle/acfsmounts/acfs_db1/.ACFS/snaps/snapshot_1/dem
o /u01/app/oracle/acfsmounts/acfs_db1
$ ble
$ ls -ls /u01/app/oracle/acfsmounts/acfs_db1 fe r a
total 496 ans
16 drwxr-xr-x 8 oracle oinstall 8192 Sep 28 13:51 apex n - t r
o
s
52 drwxr-xr-x 2 oracle oinstall 20480 Sep 28 14:34 bin an
4 drwxr-xr-x 8 oracle oinstall 4096 Sep 28 13:48 assistants

r ) ha deฺ
4 drwxr-xr-x 7 oracle oinstall 4096 Sep 28 13:52 ccr
ฺa Gui
4 drwxr-xr-x 3 oracle oinstall 4096 Sep 28 13:53 cdata
m
n ฺ co ent
4 drwxr-xr-x 4 oracle oinstall 4096 Sep 28 14:09
cfgtoollogs
ao Stud
4 drwxr-xr-x 4 oracle oinstall 4096 Sep 28 13:50 clone
@
i l le this
4 drwxr-xr-x 2 oracle oinstall 4096 Sep 28 13:53 config
z
c e loฺ use
4 drwxr-xr-x 6 oracle oinstall 4096 Sep 28 13:48 crs
a r
4 drwxr-xr-x 3 oracle oinstall 4096 Sep 28 13:48 csmig
to
m e
4 drwxr-xr-x 6 oracle oinstall 4096 Sep 28 13:53 css
l e ( icens
4 drwxr-xr-x 10 oracle oinstall 4096 Sep 28 13:54 ctx
i l
el oZ l
4 drwxr-xr-x 6 oracle oinstall 4096 Sep 28 13:48 cv

arc
4 drwxr-xr-x 4 oracle oinstall 4096 Sep 28 14:34 dbs
M 4 drwxr-xr-x 2 oracle oinstall 4096 Sep 28 13:51 dc_ocm
4 drwxr-xr-x 4 oracle oinstall 4096 Sep 28 13:56 deinstall
4 drwxr-xr-x 3 oracle oinstall 4096 Sep 29 11:41 demo
4 drwxr-xr-x 3 oracle oinstall 4096 Sep 28 13:48
diagnostics

4 drwxr-xr-x 2 oracle oinstall 4096 Sep 28 13:49 utl
4 drwxr-xr-x 3 oracle oinstall 4096 Sep 28 13:48 wwg
4 drwxr-xr-x 7 oracle oinstall 4096 Sep 28 13:49 xdk
$

8) As the root user, using a terminal window, retrieve the information data about your
ASM Cluster File System.
# acfsutil info fs /u01/app/oracle/acfsmounts/acfs_db1
/u01/app/oracle/acfsmounts/acfs_db1
ACFS Version: 11.2.0.1.0.0
flags: MountPoint,Available
mount time: Mon Sep 28 13:08:48 2009

Oracle Database 11g: New Features for Administrators A - 24


Practice 2-3: Using ASM Cluster File System Snapshots
(continued)
volumes: 1
total size: 6442450944
total free: 1360973824
primary volume: /dev/asm/acfs_db1-481
label:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

flags: Primary,Available,ADVM
on-disk version: 39.0
allocation unit: 4096
major, minor: 252, 246273
size: 6442450944
free: 1360973824
ADVM diskgroup ACFS
ADVM resize increment: 268435456
ADVM redundancy: unprotected
ble
ADVM stripe columns: 4
fe r a
ADVM stripe width: 131072
an s
number of snapshots: 1
n - t r
snapshot space usage: 23502848
You have new mail in /var/spool/mail/root a no
# h a s ฺ
a r) ACFS e
idsnapshot.
9) Using Enterprise Manager Database Control, deleteฺ your u
ฺ c om ent G
page, Snapshots tab. a on /u01/app/oracle/acfsmounts/acfs_db1
a) Return to the ASM Cluster File System:
tud
@ S
b) On the Snapshots tabฺz illeselecttsnapshot_1
page, h is and click Delete.
e l o use
rc page,
c) On the Confirmation
a to expand the Show Command link. The command
m e
should( be: /sbin/acfsutil
i l l e icens snap delete "snapshot_1"
/u01/app/oracle/acfsmounts/acfs_db1
l o Z l
rc e d) On the Confirmation page, click Yes.
Ma e) Enter the host credentials of oracle/oracle and select “Save as Preferred
Credential.” Click Continue.
f) Back to the ASM Cluster File System: /u01/app/oracle/acfsmounts/acfs_db1
Snapshots tab page, you should get a Confirmation message stating that the
selected snapshots have been deleted successfully.

Oracle Database 11g: New Features for Administrators A - 25


Practice 2-4: Using Online Patching
In this practice, you apply an online patch to your live running database instance without
shutting it down first.
1) From a terminal window, connected as the oracle user, execute the
OP_setup.sh script. This script generates a bug in the Oracle Database software.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle
$ cd /home/oracle/solutions/OP
$ ./OP_setup.sh
Oracle Enterprise Manager 11g Database Control Release
ble
11.2.0.1.0
fe r a
Copyright (c) 1996, 2009 Oracle Corporation. All rights
ans
reserved.
https://ed.us.oracle.com:5500/em/console/aboutApplication n - t r
o
an
Stopping Oracle Enterprise Manager 11g Database Control ...
s
... Stopped.
r ) ha deฺ
SQL*Plus: Release 11.2.0.1.0 Production on Tue Sep 29
13:08:29 2009 m ฺa Gui
n ฺ co ent
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
@ ao Stud
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production z i l le this
c e loฺ use
With the Partitioning, Automatic Storage Management, OLAP,
r to
Data Mining and Real Application Testing options
a
m e
i l e ( icens
SQL> SQL> Database closed.
l
Database dismounted.
el oZ l
ORACLE instance shut down.

Marc SQL> SQL> Disconnected from Oracle Database 11g Enterprise


Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
chmod 755 /u01/app/oracle/acfsmounts/acfs_db1/bin
- Linking Oracle
rm -f /u01/app/oracle/acfsmounts/acfs_db1/rdbms/lib/oracle
gcc -o /u01/app/oracle/acfsmounts/acfs_db1/rdbms/lib/oracle -
m32 -L/u01/app/oracle/acfsmounts/acfs_db1/rdbms/lib/ -
L/u01/app/oracle/acfsmounts/acfs_db1/lib/ -
L/u01/app/oracle/acfsmounts/acfs_db1/lib/stubs/ -
L/u01/app/oracle/acfsmounts/acfs_db1/lib/ -lirc -lipgo -
Wl,-E /u01/app/oracle/acfsmounts/acfs_db1/rdbms/lib/opimai.o
/u01/app/oracle/acfsmounts/acfs_db1/rdbms/lib/ssoraed.o
/u01/app/oracle/acfsmounts/acfs_db1/rdbms/lib/ttcsoi.o -Wl,--
whole-archive -lperfsrv11 -Wl,--no-whole-archive
/u01/app/oracle/acfsmounts/acfs_db1/lib/nautab.o
/u01/app/oracle/acfsmounts/acfs_db1/lib/naeet.o
/u01/app/oracle/acfsmounts/acfs_db1/lib/naect.o
/u01/app/oracle/acfsmounts/acfs_db1/lib/naedhs.o

Oracle Database 11g: New Features for Administrators A - 26


Practice 2-4: Using Online Patching (continued)
/u01/app/oracle/acfsmounts/acfs_db1/rdbms/lib/config.o -
lserver11 -lodm11 -lcell11 -lnnet11 -lskgxp11 -lsnls11 -lnls11
-lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lxml11 -
lcore11 -lunls11 -lsnls11 -lnls11 -lcore11 -lnls11 -lclient11
-lvsn11 -lcommon11 -lgeneric11 -lknlopt `if /usr/bin/ar tv
/u01/app/oracle/acfsmounts/acfs_db1/rdbms/lib/libknlopt.a |
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

grep xsyeolap.o > /dev/null 2>&1 ; then echo "-loraolap11" ;


fi` -lslax11 -lpls11 -lrt -lplp11 -lserver11 -lclient11 -
lvsn11 -lcommon11 -lgeneric11 `if [ -f
/u01/app/oracle/acfsmounts/acfs_db1/lib/libavserver11.a ] ;
then echo "-lavserver11" ; else echo "-lavstub11"; fi` `if [ -
f /u01/app/oracle/acfsmounts/acfs_db1/lib/libavclient11.a ] ;
then echo "-lavclient11" ; fi` -lknlopt -lslax11 -lpls11 -lrt
-lplp11 -ljavavm11 -lserver11 -lwwg `cat
/u01/app/oracle/acfsmounts/acfs_db1/lib/ldflags` -lncrypt11 e
-lnsgr11 -lnzjs11 -ln11 -lnl11 -lnro11 `cat
r a bl
/u01/app/oracle/acfsmounts/acfs_db1/lib/ldflags` -lncrypt11 s fe
-lnsgr11 -lnzjs11 -ln11 -lnl11 -lnnz11 -lzt11 -lmm -lsnls11 -
- t r an
lnls11 -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -
o n
s an
lxml11 -lcore11 -lunls11 -lsnls11 -lnls11 -lcore11 -lnls11 -
lztkg11 `cat /u01/app/oracle/acfsmounts/acfs_db1/lib/ldflags`
) ha deฺ
-lncrypt11 -lnsgr11 -lnzjs11 -ln11 -lnl11 -lnro11 `cat
r
m ฺa Gui
/u01/app/oracle/acfsmounts/acfs_db1/lib/ldflags` -lncrypt11

n ฺ co ent
-lnsgr11 -lnzjs11 -ln11 -lnl11 -lnnz11 -lzt11 -lsnls11 -

@ ao Stud
lnls11 -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -
lxml11 -lcore11 -lunls11 -lsnls11 -lnls11 -lcore11 -lnls11 `if
/usr/bin/ar tv z i l le this
c e loฺ use
/u01/app/oracle/acfsmounts/acfs_db1/rdbms/lib/libknlopt.a |
r to
grep "kxmnsd.o" > /dev/null 2>&1 ; then echo " " ; else echo
a
m e
e ( icens
"-lordsdo11"; fi` -
l l
L/u01/app/oracle/acfsmounts/acfs_db1/ctx/lib/ -lctxc11 -lctx11
i
el oZ l
-lzx11 -lgx11 -lctx11 -lzx11 -lgx11 -lordimt11 -lclsra11 -

Marc ldbcfg11 -lhasgen11 -lskgxn2 -lnnz11 -lzt11 -lxml11 -locr11 -


locrb11 -locrutl11 -lhasgen11 -lskgxn2 -lnnz11 -lzt11 -lxml11
-lasmclnt11 -lcommon11 -lcell11 -lskgxp11 -lgeneric11 -
lcommon11 -lgeneric11 -loraz -llzopro -lorabz2 -lsnls11 -
lnls11 -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -
lxml11 -lcore11 -lunls11 -lsnls11 -lnls11 -lcore11 -lnls11 -
lsnls11 -lunls11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11
-lcore11 -lsnls11 -lnls11 -lxml11 -lcore11 -lunls11 -lsnls11 -
lnls11 -lcore11 -lnls11 -lasmclnt11 -laio `cat
/u01/app/oracle/acfsmounts/acfs_db1/lib/sysliblist` -Wl,-
rpath,/u01/app/oracle/acfsmounts/acfs_db1/lib -lm `cat
/u01/app/oracle/acfsmounts/acfs_db1/lib/sysliblist` -ldl -lm
-L/u01/app/oracle/acfsmounts/acfs_db1/lib
test ! -f /u01/app/oracle/acfsmounts/acfs_db1/bin/oracle ||\
mv -f
/u01/app/oracle/acfsmounts/acfs_db1/bin/oracle
/u01/app/oracle/acfsmounts/acfs_db1/bin/oracleO
mv /u01/app/oracle/acfsmounts/acfs_db1/rdbms/lib/oracle
/u01/app/oracle/acfsmounts/acfs_db1/bin/oracle
chmod 6751 /u01/app/oracle/acfsmounts/acfs_db1/bin/oracle

Oracle Database 11g: New Features for Administrators A - 27


Practice 2-4: Using Online Patching (continued)

SQL*Plus: Release 11.2.0.1.0 Production on Tue Sep 29 13:09:30


2009
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> SQL> ORACLE instance started.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Total System Global Area 422670336 bytes


Fixed Size 1336960 bytes
Variable Size 180357504 bytes
Database Buffers 234881024 bytes
Redo Buffers 6094848 bytes
Database mounted.
Database opened.
SQL> SQL> Disconnected from Oracle Database 11g Enterprise
Edition Release 11.2.0.1.0 - Production
ble
With the Partitioning, Automatic Storage Management, OLAP,
fe r a
Data Mining and Real Application Testing options
ans
$
n - t r
no
2) Invoke SQL*Plus and connect as the SYS user. Execute the following command:
a
select * from mysql_is_great;
h a s ฺ
What do you observe?
ฺ a r) uide
ฺ c om eintroduced
a) You get an ORA-600 error. The bug specifically
n t G for the purpose of
n SQL*Plus.
this practice caused this error. Exitofrom
@ a S tud
$ sqlplus / as sysdballe is
z i t h
SQL*Plus: Release c e loฺ11.2.0.1.0
u se Production on Tue Sep 29 13:14:27
2009 a r to
m
( (c)en1982, e
s 2009, Oracle. All rights reserved.
Copyright
i l l e c
l o Z
Connected lito:
rc e Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Ma Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> select * from mysql_is_great;
select * from mysql_is_great
*
ERROR at line 1:
ORA-00600: internal error code, arguments: [HAH!], [ORACLE],
[IS], [BETTER!], [], [], [], [], [], [], [], []

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining
and Real Application Testing options
$

Oracle Database 11g: New Features for Administrators A - 28


Practice 2-4: Using Online Patching (continued)
3) Unzip 5943776.zip in your $HOME/solutions/OP. This is the patch you
need to apply to fix the bug.
$ rm -r 5943776
$ unzip 5943776.zip
Archive: 5943776.zip
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

creating: 5943776/
creating: 5943776/files/
creating: 5943776/files/hpatch/
inflating: 5943776/files/hpatch/bug5943776.pch
creating: 5943776/etc/
creating: 5943776/etc/config/
inflating: 5943776/etc/config/inventory.xml
inflating: 5943776/etc/config/actions.xml
creating: 5943776/etc/xml/ e
inflating: 5943776/etc/xml/GenericActions.xml
r a bl
inflating: 5943776/etc/xml/ShiphomeDirectoryStructure.xml
s fe
extracting: 5943776/README.txt
- t r an
$
n on
a
4) Verify that the provided patch is an online patch, and apply itswhile your database is
running. It should only take a few seconds to install. Note:
r ) haBe sure
d e ฺ use a `, not a
to
straight quote! ฺa Gu i
c o m n t
$ cd /home/oracle/solutions/OP/5943776 n ฺ d e
$ $ORACLE_HOME/OPatch/opatch
@ aoquery S tu-is_online_patch `pwd`
Invoking OPatch 11.1.0.6.6
z ill e t hi s

lo Installer e
Oracle Interim
r c ePatch
t o us version 11.1.0.6.6
( a
Copyright (c) 2009,
m nse : Oracle Corporation. All rights reserved.
Oracle e Home /u01/app/oracle/acfsmounts/acfs_db1
Z ill Inventory
Central l i ce : /u01/app/oracle/oraInventory
lo from
rce OPatch : /etc/oraInst.loc
Ma version
OUI version
: 11.1.0.6.6
: 11.2.0.1.0
OUI location : /u01/app/oracle/acfsmounts/acfs_db1/oui
Log file location :
/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/opatch2
009-09-29_13-18-23PM.log

Patch history file:


/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/opatch_
history.txt
--------------------------------------------------------------
Patch is an online patch: true
OPatch succeeded.

$ $ORACLE_HOME/OPatch/opatch lsinventory
Invoking OPatch 11.1.0.6.6

Oracle Interim Patch Installer version 11.1.0.6.6


Copyright (c) 2009, Oracle Corporation. All rights reserved.

Oracle Database 11g: New Features for Administrators A - 29


Practice 2-4: Using Online Patching (continued)

Oracle Home : /u01/app/oracle/acfsmounts/acfs_db1


Central Inventory : /u01/app/oracle/oraInventory
from : /etc/oraInst.loc
OPatch version : 11.1.0.6.6
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

OUI version : 11.2.0.1.0


OUI location : /u01/app/oracle/acfsmounts/acfs_db1/oui
Log file location :
/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/opatch2
009-09-29_13-19-27PM. log

Patch history file:


/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/opatch_
history.txt
ble
fe r a
Lsinventory Output file location :
ans
/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/lsinv/l
sinventory2009-09-29_13-19-27PM.txt n - t r
a no
a s ฺ
--------------------------------------------------------------
h
Installed Top-level Products (1):
ฺ a r) uide
Oracle Database 11g ฺ c om ent G 11.2.0.1.0
There are 1 products installed o n in d
this Oracle Home.
There are no Interim patches @ a installed
S tu in this Oracle Home.
ill e t hi s
--------------------------------------------------------------
z
ฺ e
r c elo o us
OPatch succeeded.
m a e t
( s
Z ille licen
$ $ORACLE_HOME/OPatch/opatch apply
el o/home/oracle/solutions/OP/5943776 -connectString orcl:::
Marc Invoking OPatch 11.1.0.6.6

Oracle Interim Patch Installer version 11.1.0.6.6


Copyright (c) 2009, Oracle Corporation. All rights reserved.
Oracle Home : /u01/app/oracle/acfsmounts/acfs_db1
Central Inventory : /u01/app/oracle/oraInventory
from : /etc/oraInst.loc
OPatch version : 11.1.0.6.6
OUI version : 11.2.0.1.0
OUI location : /u01/app/oracle/acfsmounts/acfs_db1/oui
Log file location :
/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/opatch2
009-07-07_16-07-24PM.log

Patch history file:


/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/opatch_
history.txt

ApplySession applying interim patch '5555555' to OH


'/u01/app/oracle/acfsmounts/acfs_db1'

Oracle Database 11g: New Features for Administrators A - 30


Practice 2-4: Using Online Patching (continued)

Running prerequisite checks...

OPatch detected non-cluster Oracle Home from the inventory and


will patch the local system only.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Backing up files and inventory (not for auto-rollback) for the


Oracle Home
Backing up files affected by the patch '5555555' for restore.
This might take a while...
Backing up files affected by the patch '5555555' for rollback.
This might take a while...

Patching component oracle.rdbms, 11.2.0.1.0...


The patch will be installed on active database instances.
ble
Running mkpatch on 'bug5943776.pch' to make it compatible with
fe r a
the Oracle binary...
t r a ns
Installing and enabling the online patch 'bug5943776.pch', o n - on
database 'orcl'. a n
a s
h to dinventory

ApplySession adding interim patch '5555555' r ) i e
m ฺa Gu
Verifying the update... ฺ c o e n t
n
Inventory check OK: Patch a
Home inventory with proper @
IDo5555555
S
meta-data.
tudis registered in Oracle
Files check OK: Files z i l lefrom tPatch
h is ID 5555555 are present in
Oracle Home. elo
ฺ se
r c to u
m a e
i l l e ( icens
OPatch succeeded.

l o Z l
$ $ORACLE_HOME/OPatch/opatch lsinventory
rc e Invoking OPatch 11.1.0.6.6
Ma
Oracle Interim Patch Installer version 11.1.0.6.6
Copyright (c) 2009, Oracle Corporation. All rights reserved.

Oracle Home : /u01/app/oracle/acfsmounts/acfs_db1


Central Inventory : /u01/app/oracle/oraInventory
from : /etc/oraInst.loc
OPatch version : 11.1.0.6.6
OUI version : 11.2.0.1.0
OUI location : /u01/app/oracle/acfsmounts/acfs_db1/oui
Log file location :
/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/opatch2
009-09-29_13-27-06PM.log

Patch history file:


/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/opatch_
history.txt

Oracle Database 11g: New Features for Administrators A - 31


Practice 2-4: Using Online Patching (continued)
Lsinventory Output file location :
/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/lsinv/l
sinventory2009-09-29_13-27-06PM.txt
--------------------------------------------------------------
Installed Top-level Products (1):
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Oracle Database 11g 11.2.0.1.0


There are 1 products installed in this Oracle Home.
Interim patches (1) :

Patch (online) 5555555: applied on Tue Jul 07 16:07:31


GMT+07:00 2009
Unique Patch ID: 1
Created on 6 Jul 2009, 16:53:30 hrs PST8PDT
Bugs fixed:
ble
5943776
fe r a
--------------------------------------------------------------
ans
OPatch succeeded. n - t r
$ a no
h a s ฺ
5) Invoke SQL*Plus and connect as the SYS user. Execute r) uide command
the following
again: ฺ a
select * from mysql_is_great; ฺ c om ent G
What do you observe? a on tud
a) This time you receivezthe i l is S
e@ thORA-00942
lstandard error. Exit from SQL*Plus.

lo us e
$ sqlplus / as
r c esysdba
m a e to
SQL*Plus:
l e ( Release
e ns 11.2.0.1.0 Production on Tue Sep 29 13:30:59
Z
2009i l li c
l o
rce Copyright (c) 1982, 2009, Oracle. All rights reserved.
Ma Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> select * from mysql_is_great;


select * from mysql_is_great
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$

Oracle Database 11g: New Features for Administrators A - 32


Practice 2-4: Using Online Patching (continued)
6) While your database instance is still running, roll back your patch. What do you
observe?
a) The patch is removed very quickly.
$ $ORACLE_HOME/OPatch/opatch rollback -id 5555555 -
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

connectString orcl:::
Invoking OPatch 11.1.0.6.6

Oracle Interim Patch Installer version 11.1.0.6.6


Copyright (c) 2009, Oracle Corporation. All rights reserved.
Oracle Home : /u01/app/oracle/acfsmounts/acfs_db1
Central Inventory : /u01/app/oracle/oraInventory
from : /etc/oraInst.loc
OPatch version : 11.1.0.6.6
OUI version : 11.2.0.1.0
ble
OUI location : /u01/app/oracle/acfsmounts/acfs_db1/oui
fe r a
Log file location :
an s
/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/opatch2
n - t r
009-09-29_13-31-53PM.log
a no
Patch history file: h a s ฺ
ฺ a r) uide
/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/opatch_
history.txt
ฺ c om ent G
a n udpatch '5555555' from OH
ointerim
RollbackSession rolling back
@ S t
z ill e
'/u01/app/oracle/acfsmounts/acfs_db1'
t hi s
ฺ e
Running prerequisite
r c elo ochecks...
us
a e t
OPatch
l e (m ensnon-cluster
detected Oracle Home from the inventory and
i l li c
el oZ
will patch the local system only.

Marc Backing up files affected by the patch '5555555' for restore.


This might take a while...

Patching component oracle.rdbms, 11.2.0.1.0...


The patch will be removed from active database instances.
Disabling and removing online patch 'bug5943776.pch', on
database 'orcl'

RollbackSession removing interim patch '5555555' from


inventory

OPatch succeeded.

$ $ORACLE_HOME/OPatch/opatch lsinventory
Invoking OPatch 11.1.0.6.6

Oracle Interim Patch Installer version 11.1.0.6.6


Copyright (c) 2009, Oracle Corporation. All rights reserved.

Oracle Database 11g: New Features for Administrators A - 33


Practice 2-4: Using Online Patching (continued)

Oracle Home : /u01/app/oracle/acfsmounts/acfs_db1


Central Inventory : /u01/app/oracle/oraInventory
from : /etc/oraInst.loc
OPatch version : 11.1.0.6.6
OUI version : 11.2.0.1.0
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

OUI location : /u01/app/oracle/acfsmounts/acfs_db1/oui


Log file location :
/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/opatch2
009-09-29_13-33-15PM.log

Patch history file:


/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/opatch_
history.txt
ble
Lsinventory Output file location :
fe r a
/u01/app/oracle/acfsmounts/acfs_db1/cfgtoollogs/opatch/lsinv/l
ans
sinventory2009-09-29_13-33-15PM.txt
-------------------------------------------------------------- n - t r
Installed Top-level Products (1): a no
h a s ฺ
Oracle Database 11g
There are 1 products installed in this ฺ a )
rOracle u de11.2.0.1.0
iHome.
There are no Interim patches installed ฺ c om ein n G Oracle Home.
t this
on tud
--------------------------------------------------------------
a
OPatch succeeded. zill
e@ this S
$
c e loฺ use
a r to as the SYS user. Execute the following command:
7) Invoke SQL*Plusm and e
connect
select
i l l e (* from
c e nsmysql_is_great;
l o Z li
What do you observe?
rce
Ma a) You should get an internal error again. Exit from SQL*Plus.
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sep 29 13:34:51


2009
Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> select * from mysql_is_great;


select * from mysql_is_great
*
ERROR at line 1:

Oracle Database 11g: New Features for Administrators A - 34


Practice 2-4: Using Online Patching (continued)
ORA-00600: internal error code, arguments: [HAH!], [ORACLE],
[IS], [BETTER!], [], [], [], [], [], [], [], []

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

With the Partitioning, Automatic Storage Management, OLAP,


Data Mining and Real Application Testing options
$

8) From a terminal window connected as the oracle user, execute the


OP_cleanup.sh script to restore your environment.
$ cd /home/oracle/solutions/OP
$ ./OP_cleanup.sh
ble
SQL*Plus: Release 11.2.0.1.0 Production on Tue Sep 29 13:37:28 fe r a
2009 n s
Copyright (c) 1982, 2009, Oracle. All rights reserved. n - tra
Connected to:
a no
Oracle Database 11g Enterprise Edition Release
Production h a s 11.2.0.1.0

-

With the Partitioning, Automatic Storage ฺ a u ide OLAP,


r) Management,
Data Mining and Real Applicationco m ntoptions
Testing G

on tude
SQL> SQL> Database closed. a
@ is S
Database dismounted.ille
ORACLE instance lshut o ฺz down.
e th
ce to ufroms Oracle Database 11g Enterprise
r
SQL> SQL> Disconnected
a
Edition(m
n s e
Release 11.2.0.1.0 - Production
e
Withll the Partitioning,
i Mining i ceand Real Application
Automatic Storage Management, OLAP,
l o Z
Data l Testing options
e chmod 755 /u01/app/oracle/acfsmounts/acfs_db1/bin
Marc
- Linking Oracle
rm -f /u01/app/oracle/acfsmounts/acfs_db1/rdbms/lib/oracle
gcc -o /u01/app/oracle/acfsmounts/acfs_db1/rdbms/lib/oracle -
m32 -L/u01/app/oracle/acfsmounts/acfs_db1/rdbms/lib/ -
L/u01/app/oracle/acfsmounts/acfs_db1/lib/ -

/u01/app/oracle/acfsmounts/acfs_db1/bin/oracle
/u01/app/oracle/acfsmounts/acfs_db1/bin/oracleO
mv /u01/app/oracle/acfsmounts/acfs_db1/rdbms/lib/oracle
/u01/app/oracle/acfsmounts/acfs_db1/bin/oracle
chmod 6751 /u01/app/oracle/acfsmounts/acfs_db1/bin/oracle

SQL*Plus: Release 11.2.0.1.0 Production on Tue Sep 29 13:38:22


2009
Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to an idle instance.

Oracle Database 11g: New Features for Administrators A - 35


Practice 2-4: Using Online Patching (continued)
SQL> SQL> ORACLE instance started.

Total System Global Area 422670336 bytes


Fixed Size 1337116 bytes
Variable Size 167774436 bytes
Database Buffers 247463936 bytes
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Redo Buffers 6094848 bytes


Database mounted.
Database opened.
SQL> SQL> select * from mysql_is_great
*
ERROR at line 1:
ORA-00942: table or view does not exist

ble
SQL> SQL> Disconnected from Oracle Database 11g Enterprise
fe r a
Edition Release 11.2.0.1.0 - Production
an s
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options n - t r
$ a no
h a s ฺ
9) In a terminal window connected as the oracle user,rrestart
Database Control using the following command: ฺ a u ide Manager
) Enterprise
emctl start dbconsole ฺ c om ent G
$ emctl start dbconsole a on tud
l e S
@11g isDatabase
Oracle Enterprise Manager
ฺ z i l t h Control Release
11.2.0.1.0
elo o2009 e
us Oracle Corporation. All rights
Copyright (c)
a r c1996,
t
reserved.
l e (m ense
https://ed.us.oracle.com:5500/em/console/aboutApplication
Zi l
Starting lic Enterprise Manager 11g Database Control
Oracle
l o
e ......................... started.
rc
Ma --------------------------------------------------------------
Logs are generated in directory
/u01/app/oracle/acfsmounts/acfs_db1/edrsr40p1.us.oracle.com_or
cl/sysman/log
$

Oracle Database 11g: New Features for Administrators A - 36


Practices for Lesson 3

In this practice, you use Oracle Restart to manage components.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 37


Practice 3-1: Using Oracle Restart to Manage Components
In this practice, you manipulate Oracle Restart to manage your database component for
automatic restart.
1) Use Enterprise Manager to determine if your orcl database instance is currently
managed by Oracle Restart.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

a) Go to the Home page by clicking the Database tab.


b) On the Home page, look at the High Availability section and see that Oracle
Restart is Enabled for your database instance.
2) To determine the effect of Oracle Restart, kill the LGWR process of your orcl
database instance. What do you observe?
a) Set your environment variables for your orcl database instance. After you kill e
the LGWR process, the instance is shut down. After a little while, the instance is r a bl
automatically restarted by Oracle Restart. s fe
- t r an
$ . oraenv
o n
ORACLE_SID = [orcl] ? orcl
$ srvctl config database -d orcl s an
Database unique name: orcl r ) ha deฺ
Database name: orcl
m ฺa Gui
n ฺ co ent
Oracle home: /u01/app/oracle/acfsmounts/acfs_db1
Oracle user: oracle
Spfile: +DATA/orcl/spfileorcl.ora@ ao Stud
Domain: z i l le this
Start options: open
c e loฺ use
r
Stop options: immediate
a to
m e
i l e ( icens
Database role: PRIMARY
l
Management policy: automatic
el oZ l
Disk Groups: DATA,FRA

Marc Services:
$
$ ps -ef | grep ora_lgwr_orcl
oracle 8502 1 0 Sep29 ? 00:00:03 ora_lgwr_orcl
oracle 10115 5384 0 07:01 pts/2 00:00:00 grep ora_lgwr_orcl
$ kill -9 8502
$ ps -ef | grep ora_lgwr_orcl
oracle 10277 5384 0 07:03 pts/2 00:00:00 grep ora_lgwr_orcl
$ ps -ef | grep ora_lgwr_orcl
oracle 10336 1 0 07:03 ? 00:00:00 ora_lgwr_orcl
oracle 10519 5384 0 07:04 pts/2 00:00:00 grep ora_lgwr_orcl
$

3) Remove your orcl database instance from the Oracle Restart configuration.
$ srvctl remove database -d orcl
PRKO-3141 : Database orcl could not be removed because it was
running
$ srvctl stop database -d orcl
$ srvctl remove database -d orcl

Oracle Database 11g: New Features for Administrators A - 38


Practice 3-1: Using Oracle Restart to Manage Components
(continued)
Remove the database orcl? (y/[n]) y
$ srvctl remove database -d orcl
PRCD-1120 : The resource for database orcl could not be found.
PRCR-1001 : Resource ora.orcl.db does not exist
$
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

4) Restart your orcl database instance.


$ srvctl start database -d orcl
PRCD-1120 : The resource for database orcl could not be found.
PRCR-1001 : Resource ora.orcl.db does not exist
$
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 30 07:14:20 ble


2009 fe r a
Copyright (c) 1982, 2009, Oracle. All rights reserved. an s
n - t r
Connected to an idle instance.
a no
h a s ฺ
SQL> startup
ORACLE instance started. ฺ a r) uide
ฺ c om ent G
Total System Global Area 422670336
a n ubytes
o1336960 d
Fixed Size @ S t bytes
Variable Size
z i l le 222300544
t h is bytes
Database Buffersloฺ s e192937984 bytes
Redo Buffersr c e u 6094848 bytes
Database m a
mounted. e to
i l l
Database e ( opened.
c e ns
l o Z exit li
SQL>
rc e Disconnected from Oracle Database 11g Enterprise Edition
Ma Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$

5) Kill again the LGWR process of your orcl database instance. What do you observe?
a) The database instance is shut down, but is no longer automatically restarted.
$ ps -ef | grep ora_lgwr_orcl
oracle 11500 1 0 07:14 ? 00:00:00 ora_lgwr_orcl
oracle 11794 5384 0 07:17 pts/2 00:00:00 grep ora_lgwr_orcl
$ kill -9 11500
$
$ ps -ef | grep ora_lgwr_orcl
oracle 11841 5384 0 07:18 pts/2 00:00:00 grep ora_lgwr_orcl
$

6) Restart your orcl database instance.

Oracle Database 11g: New Features for Administrators A - 39


Practice 3-1: Using Oracle Restart to Manage Components
(continued)
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 30 07:19:51


2009
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 422670336 bytes


Fixed Size 1336960 bytes
Variable Size 222300544 bytes
ble
Database Buffers 192937984 bytes
fe r a
Redo Buffers 6094848 bytes
ans
Database mounted.
n - t r
Database opened.
SQL> exit a no
Disconnected from Oracle Database 11g Enterprise Edition h a s ฺ
Release 11.2.0.1.0 - Production
ฺ a r) uide

Data Mining and Real Application Testing options c om ent G
With the Partitioning, Automatic Storage Management, OLAP,

$ a on tud
l l e@ is S
7) Using Enterprise Manager, ฺ i
z your
add h database instance back into the Oracle
torcl
l o e
s observe?
a rce What
Restart configuration.
t o
douyou
a) Connect
l e (mto your
e n se Console as the SYS user and go to the Home page.
Database
i l
b)ZRefresh c of times until you no longer see the database being offline. You
alicouple
l o
e can also try to stop and then restart the Database Console to make sure it gets the
rc
Ma latest status. Use the following commands from a terminal window:
$ emctl stop dbconsole
Oracle Enterprise Manager 11g Database Control Release
11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation. All rights
reserved.
https://...:5500/em/console/aboutApplication
Stopping Oracle Enterprise Manager 11g Database Control ...
... Stopped.
$ emctl start dbconsole
Oracle Enterprise Manager 11g Database Control Release
11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation. All rights
reserved.
https://...:5500/em/console/aboutApplication
Starting Oracle Enterprise Manager 11g Database Control
....... started.
--------------------------------------------------------------

Oracle Database 11g: New Features for Administrators A - 40


Practice 3-1: Using Oracle Restart to Manage Components
(continued)
Logs are generated in directory
/u01/app/oracle/acfsmounts/acfs_db1/…_orcl/sysman/log
$
c) Go to the High Availability section on the Database Home page and click the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Disabled link next to the Oracle Restart field. (Note: If Oracle Restart is not
disabled on your Enterprise Manager page and you have no link to click, you may
need to execute the SRVCTL command in step f manually and proceed to step i.)
d) On the Specify Host Credentials page, enter oracle in both the username and
password fields and select “Save as Preferred Credential.”
e) Click Login.
f) On the Confirmation: Register Database page, you can see the command used to ble
register orcl with Oracle Restart: fe r a
srvctl add database -d orcl -o ans
/u01/app/oracle/acfsmounts/acfs_db1 n - t r
g) Click Continue. a no
h a s ฺ
h) Once back to your database Home page, you should
a r now e Oracle Restart is
) seeidthat
enabled for your orcl database instance. m ฺ u
ฺ c o ent G
i) However, only the database resource
a obynisusing
addedd
t u back to the Oracle Restart
configuration. You can verify
l l e @ is S
this SRVCTL:
$ srvctl config database i
ฺz se-dthorcl
Database unique l o
e name: uorcl
a
Database name: e
r c t o
Oracle l e (m e/u01/app/oracle/acfsmounts/acfs_db1
home: ns
i l
Z user:
Oracle c
li oracle
e l oSpfile:
rc
Ma Domain:
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: automatic
Disk Groups:
Services:

8) Add your orcl database instance and its dependencies back to the Oracle Restart
configuration.
$ srvctl status database -d orcl
Database is not running.

$ srvctl start database -d orcl


$ srvctl status database -d orcl
Database is running.
$
$ srvctl config database -d orcl
Database unique name: orcl

Oracle Database 11g: New Features for Administrators A - 41


Practice 3-1: Using Oracle Restart to Manage Components
(continued)
Database name:
Oracle home: /u01/app/oracle/acfsmounts/acfs_db1
Oracle user: oracle
Spfile:
Domain:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Start options: open


Stop options: immediate
Database role: PRIMARY
Management policy: automatic
Disk Groups:
Services:
$
$ srvctl modify database -d orcl -n orcl -p
+DATA/orcl/spfileorcl.ora -a DATA,FRA
ble
$ srvctl config database -d orcl
fe r a
Database unique name: orcl
ans
Database name: orcl
n - t r
Oracle home: /u01/app/oracle/acfsmounts/acfs_db1
Oracle user: oracle a no
Spfile: +DATA/orcl/spfileorcl.ora h a s ฺ
Domain:
ฺ a r) uide
Start options: open
Stop options: immediate ฺ c om ent G
Database role: PRIMARY a on tud
Management policy: automatic
l l e@ is S
Disk Groups: DATA,FRA i
ฺz se th
l o
Services:
$ a rce to u
l e (m ense
9) Make l
Zi again lictheRestart
sure Oracle is functioning properly with your orcl database instance.
e l oOnce kill LGWR process and verify that it is automatically restarted.
rc
Ma $ ps -ef | grep
oracle 4848
lgwr
1 0 Sep28 ? 00:00:00 asm_lgwr_+ASM
oracle 12033 1 0 07:20 ? 00:00:00 ora_lgwr_orcl
oracle 13712 5384 0 07:31 pts/2 00:00:00 grep lgwr
$ kill -9 12033
$ ps -ef | grep lgwr
oracle 4848 1 0 Sep28 ? 00:00:00 asm_lgwr_+ASM
oracle 13844 5384 0 07:33 pts/2 00:00:00 grep lgwr
$ ps -ef | grep lgwr
oracle 4848 1 0 Sep28 ? 00:00:00 asm_lgwr_+ASM
oracle 13905 1 0 07:33 ? 00:00:00 ora_lgwr_orcl
oracle 14036 5384 0 07:34 pts/2 00:00:00 grep lgwr
$

10) Disable Oracle Restart on your orcl database instance.


$ srvctl disable database -d orcl
$ srvctl status database -d orcl -f
Database is disabled

Oracle Database 11g: New Features for Administrators A - 42


Practice 3-1: Using Oracle Restart to Manage Components
(continued)
Database is running.
$

11) Verify that Oracle Restart is no longer automatically restarting your orcl database
instance. Again kill your LGWR process and then verify that the instance is not
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

restarting automatically.
$ ps -ef | grep lgwr
oracle 4848 1 0 Sep28 ? 00:00:00 asm_lgwr_+ASM
oracle 13905 1 0 07:33 ? 00:00:00 ora_lgwr_orcl
oracle 14273 5384 0 07:36 pts/2 00:00:00 grep lgwr
$ kill -9 13905
$ ps -ef | grep lgwr
oracle 4848 1 0 Sep28 ? 00:00:00 asm_lgwr_+ASM
ble
oracle 14414 5384 0 07:38 pts/2 00:00:00 grep lgwr
fe r a
$ ps -ef | grep lgwr s
oracle 4848 1 0 Sep28 ? 00:00:00 asm_lgwr_+ASM
- t r an
oracle 14414 5384 0 07:38 pts/2 n
00:00:00 grep lgwr
no
$ ps -ef | grep lgwr a
oracle 4848 1 0 Sep28 ? 00:00:00
h a s asm_lgwr_+ASM
ฺ lgwr
oracle 14414 5384 0 07:38 pts/2 )
00:00:00
r i d e
grep
$ m ฺa Gu
ฺ o t
cdatabaseeinstance.
n
n
ao Stud
12) Enable Oracle Restart again on your orcl
$ srvctl enable database l @
le -d is -f
orcl
z i t h
$ srvctl status database
e oฺ use
lrunning. -d orcl
Database is not
$ srvctl statusa c
r databaseto -d orcl -f
m e
Database
i l l e ( isicerunning.
ns
$Z l
e l o
rc
Ma

Oracle Database 11g: New Features for Administrators A - 43


Practices for Lesson 4

This practice includes using ASM fast mirror resync.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 44


Practice 4-1: Using ASM Fast Mirror Resync
In this practice, you compare the time it takes to add an offlined disk (a disk that has been
taken offline) following a nondata issue (a failure not related to data on the disk). You
compare the same operation once without using ASM Fast Mirror Resync, and once
while using ASM Fast Mirror Resync.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

1) Determine the compatibility values for your existing ASM disk groups. What do you
observe?
a) Both the ASM and Database compatibility attributes are set to their defaults.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle ble
$ sqlplus / as sysdba fe r a
t r a ns
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 30
o n -07:59:27
2009
s an
Copyright (c) 1982, 2009, Oracle. All rights
r ) ha reserved.
d e ฺ
Connected to: ฺa Gu i
Oracle Database 11g Enterprise Edition
c o m t
Release
n 11.2.0.1.0 -
Production n ฺ e
With the Partitioning, Automatic
@ tud Management, OLAP,
ao SStorage
le this Testing options
Data Mining and RealilApplication
z
SQL> col name c e loฺ a10
u se
a r format
to format a20
SQL> colm e
compatibility
( ens
SQL>lle
col database_compatibility format a25
Z i
SQL> l
selecti cname,compatibility,database_compatibility from
l o
e v$asm_diskgroup;
rc
Ma NAME COMPATIBILITY DATABASE_COMPATIBILITY
---------- -------------------- -------------------------
DATA 11.2.0.0.0 10.1.0.0.0
FRA 11.2.0.0.0 11.2.0.0.0
ACFS 11.2.0.0.0 11.2.0.0.0

2) Using Enterprise Manager Database Control, navigate to the DATA disk group page
and make sure that you see the same compatibility values for the DATA disk group as
the ones you saw previously.
a) Connect to Enterprise Manager Database Control as the SYS user.
b) On the Home page, click the +ASM link next to the ASM field in the General
section of the page.
c) On the ASM home page, click the Disk Groups tab.

Oracle Database 11g: New Features for Administrators A - 45


Practice 4-1: Using ASM Fast Mirror Resync (continued)
d) If the Automatic Storage Management Login page appears, enter sys in the
Username field, oracle_4U in the Password field, and select SYSASM in the
Connect As field. Select the “Save as Preferred Credentials” check box. And then
click Login.
e) On the Disk Groups page, click the DATA link in the table.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

f) You should see that Database compatibility is set to 10.1.0.0.0 and ASM
compatibility is set to 11.2.0.0.0. Also note that the Disk Repair Time attribute is
set to 3.6 hours.
3) Using Enterprise Manager Database Control, change the Database compatibility
attribute of the DATA disk group. Set it to 11.2.0.0.0.
a) On the Disk Group: DATA General subpage, click Edit in the Advanced
Attributes section.
bl e
b) On the “Edit Advanced Attributes for Disk Group: DATA” page, enter 11.2.0.0.0 fe r a
n s
n - traOK.
in the Database Compatibility and in the ASM Compatibility fields. Click

a no
4) Use SQL*Plus to verify that the previous update was done correctly. Exit from
SQL*Plus. s ฺ
h a
SQL> select name,compatibility,database_compatibility
ฺ a r) uide from
v$asm_diskgroup;
ฺ c om ent G
NAME COMPATIBILITY ao
n DATABASE_COMPATIBILITY
ud
@ S t
---------- --------------------
z i l le this -------------------------
DATA
FRA e l oฺ use
11.2.0.0.0
11.2.0.0.0
11.2.0.0.0
11.2.0.0.0
ACFS a rc
11.2.0.0.0t o 11.2.0.0.0
( m s e
SQL>
Z illeexit licen
loDisconnected from Oracle Database 11g Enterprise Edition
rce Release 11.2.0.1.0 - Production
Ma With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$

5) Execute the asm_setup.sh script (located in your


/home/oracle/solutions/ASM directory) to set up the environment for this
practice. The script creates a new tablespace called TBSJFV in the DATA disk group
using a 50 MB file. It then creates a new table called SYSTEM.JFV residing in this
new tablespace. The script then inserts some rows in the newly created table.
$ cd /home/oracle/solutions/ASM
$ ./asm_setup.sh

SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 30 08:23:01


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Oracle Database 11g: New Features for Administrators A - 46


Practice 4-1: Using ASM Fast Mirror Resync (continued)

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> SQL> SQL> SQL>


Tablespace created.

SQL> SQL> drop table jfv purge


*
ERROR at line 1:
ORA-00942: table or view does not exist
ble
fe r a
SQL> SQL>
ans
Table created.
n - t r
SQL> SQL> a no
1 row created.
h a s ฺ
SQL> SQL> ฺ a r) uide
Commit complete. ฺ c om ent G
a on tud
SQL> SQL> 2 3
l 4@ 5
e i s S6 7
i l h
oฺz use t
PL/SQL procedure successfully completed.
e l
rc
SQL> SQL> Disconnected
a to from-Oracle Database 11g Enterprise
Edition(m e
Releases11.2.0.1.0 Production
With
Z l i c en
illethe Partitioning, Automatic Storage Management, OLAP,
e l oData Mining and Real Application Testing options
rc $
Ma 6) Take the second disk that is part of that DATA disk group offline, making sure that the
Disk Repair Time attribute is set to 0:
a) Back to the Disk Group: DATA General page, select the second disk
(ASMDISK02) and click Offline.
b) On the Confirmation page, change the Disk Repair Time from its default (3.6
hours) to 0 and click Show SQL. The command should be: ALTER DISKGROUP
DATA OFFLINE DISK ASMDISK02 DROP AFTER 0 h
c) Then click Return.
d) Back at the Confirmation page, click Yes.
7) What do you observe?
a) Back at the Disk Group: DATA General page, you can see that ASM is putting
the ASMDISK02 offline. This operation takes a while to complete due to the
rebalance operation that is performed. Refresh your browser page until you no
longer see the ASM disk ASMDISK02.

Oracle Database 11g: New Features for Administrators A - 47


Practice 4-1: Using ASM Fast Mirror Resync (continued)
b) Back at the Disk Group: DATA General page, you should now see that the
remaining three disks are all approximately 53% full. This forced the lost
mirrored extents to be rebalanced across surviving disks.
8) Modify some rows in the SYSTEM.JFV table (delete 499 rows). Are you still able to
update the table?
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

a) You can still modify the JFV table:


$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle
[oracle@edrsr40p1-orcl ASM]$ sqlplus system
bl e
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 30 11:33:03 ra
2009 n s fe
n - tra
Copyright (c) 1982, 2009, Oracle. All rights reserved.
a no
Enter password: h a s ฺ
ฺ a r) uide
Connected to:
Oracle Database 11g Enterprise ฺ c om eRelease
Edition n t G 11.2.0.1.0 -
Production a on tud
With the Partitioning,
l l e@ is SStorage Management, OLAP,
Automatic
Data Mining and Real i th Testing options
ฺz Application
l o e
us rownum<500;
ce towhere
SQL> deletearfrom jfv
l e (m ense
499 l
Zi rows deleted.
lic
e l o
rc SQL> commit;
Ma
Commit complete.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$
9) Add the dropped ASM disk back to DATA disk group:
a) Back at the Disk Group: DATA General page, click Add.
b) On the Add Disks page, select All Disks from the Select Member Disks drop-
down list.
c) From the Member Disks table, select ORCL:ASMDISK02 and click Show SQL.
The command should be: ALTER DISKGROUP DATA ADD DISK
'ORCL:ASMDISK02' SIZE 2304 M

Oracle Database 11g: New Features for Administrators A - 48


Practice 4-1: Using ASM Fast Mirror Resync (continued)
d) Click Return.
e) On the Add Disks page, click OK.
f) Back to the Add Disks page, you receive an error stating “Failed to commit:
ORA-15032: not all alterations performed ORA-15033: disk
'ORCL:ASMDISK02' belongs to diskgroup "DATA".” This is because
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ASMDISK02 is still considered part of the DATA disk group and ASM does not
want to override it by default.
g) Now, make sure that ORCL:ASMDISK02 is selected as well as the corresponding
Force Reuse check box.
h) Click Show SQL. The command should be: ALTER DISKGROUP DATA ADD
DISK 'ORCL:ASMDISK02' SIZE 2304 M FORCE
i) Click Return. ble
fe r a
j) Back on the Add Disks page, click OK.
ans
t r
Note: If you receive an internal server error, refresh your browser or click the
n -
back button, and continue with step 10.
a no
10) What do you observe?
h a s ฺ
a) Back to the Disk Group: DATA page, refresh itฺa r) times
many
e the rebalance
iduntil
u
operation is finished.
ฺ c om ent G
b) You should see at the end of thea on toperation
rebalance ud that each ASM disk is now
40% full. @
le this S
z i l
11) Take the second diske oฺ is part
lthat u sofeDATA disk group offline, making sure that the
Disk Repair Time
a c
r attributetois set to its default value. And then modify the
SYSTEM.JFV m
( table n e (delete another batch of 499 rows). What are your
sagain
l l e e
l o Zi
observations?lic
rce a) Back to the Disk Group: DATA General page, select the second disk
Ma (ASMDISK02) and click Offline.
b) On the Confirmation page, leave the default value of 3.6 Hours in the Disk Repair
Time field, and click Yes.
c) Back at the Disk Group: DATA General page, you can see that ASMDISK02
keeps the same size as before the Offline operation. Even if you refresh your
browser page, no rebalance is taking place. You can check this by simply looking
at the Pending Operations field in the General section of the page. Its value should
stay at 0.
d) You can still modify the SYSTEM.JFV table:
$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle
[oracle@edrsr40p1-orcl ASM]$ sqlplus system

Oracle Database 11g: New Features for Administrators A - 49


Practice 4-1: Using ASM Fast Mirror Resync (continued)
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 30 11:44:02
2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Enter password: *********


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> delete from system.jfv where rownum<500;


ble
499 rows deleted.
fe r a
an s
SQL> commit;
n - t r
Commit complete. a no
h a s ฺ
SQL> exit
Disconnected from Oracle Database 11g ฺ a r) uideEdition
Enterprise
Release 11.2.0.1.0 - Productionฺco
m nt G
With the Partitioning, Automatic a t u de Management, OLAP,
on Storage
Data Mining and Real Application
l l e@ is STesting options
$ i
ฺz se th
l o
12) Now how wouldryou
a ce add ttheo u disk back into DATA disk group?
offline
a) You l e (m
do n
not need
e stoewipe off the dropped disk or force it to be re-created.
i l licDisk Group: DATA General page, select the offline disk
l ob)ZBack at the
rce (ASMDISK02) and click Online.
Ma c) On the confirmation page, click Yes.
d) Back at the Disk Group: DATA General page, you should see that the disk is back
to its level (around 39% full), without the need of any rebalance operation. You
might be able to see it SYNCING (pass your mouse over the corresponding red
cross). The disk is added back almost immediately. Refresh your browser window
to see the changes in Mode.

Oracle Database 11g: New Features for Administrators A - 50


Practices for Lesson 5

In the practice for this lesson, you use table compression.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 51


Practice 5-1: Using Table Compression
The cost of disk systems can be a very large portion of building and maintaining large
data warehouses. Oracle Database 11g helps to reduce this cost by compressing the data
and it does so without the typical trade-offs of space savings versus access time to data
for normal query operations. The overhead incurred by compression is generally related
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

to the initial compression of the data and operations that modify or change the data
(DML).
1) Change to the /home/oracle/solutions/TC directory. Invoke SQL*Plus and
log in as the SYS user. Execute the setup.sql script.
$ cd /home/oracle/solutions/TC

$ sqlplus / as sysdba
bl e
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 30 11:59:26era
2009
a n sf
n - tr
Copyright (c) 1982, 2009, Oracle. All rights reserved. o
s an
Connected to:
r ) ha deฺ
Oracle Database 11g Enterprise Edition
Production m ฺa Release
G ui 11.2.0.1.0 -
With the Partitioning, Automatic n ฺ coStorage
e n tManagement, OLAP,
Data Mining and Real Application
@ tud options
ao STesting
z i l le this
SQL> @setup
Connected. c e loฺ use
SQL> alter a r
user sh o
tidentified by sh account unlock
2 le
m
( unlimited
quota n s e on users;
Z il l i ce
rc eloUser altered.
Ma SQL> grant create tablespace to sh;

Grant succeeded.

SQL> grant drop tablespace to sh;

Grant succeeded.

SQL>
2) You can compare the storage requirements between a compressed table and an
uncompressed table. You first create two copies of the SALES table, the first being
compressed and the second being uncompressed. In your SQL*Plus session, execute
the create_sales_tbls.sql script.
SQL> @create_sales_tbls
SQL> set echo on
SQL> set pagesize 2000

Oracle Database 11g: New Features for Administrators A - 52


Practice 5-1: Using Table Compression (continued)
SQL> set long 10000
SQL> set linesize 200
SQL> REM
SQL> REM
SQL> connect sh/sh
Connected.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> drop table sales_nocompress purge


2 /
drop table sales_nocompress purge
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> drop table sales_compress purge


2 /
ble
drop table sales_compress purge
fe r a
*
ans
ERROR at line 1:
ORA-00942: table or view does not exist n - t r
a no
SQL> set echo on
h a s ฺ
SQL> set timing on
SQL> create table sales_nocompress mฺa
r) uide
2 as select * from sales ฺ c o ent G
3 / a on tud
l l e@ is S
Table created. i
ฺz se th
l o
rce to u
Elapsed: 00:00:16.09
a
SQL>
l e (m ense
SQL>l
Z2i create lictable sales_compress compress for all operations
e l o as select * from sales where 1=0
rc 3 /
Ma
Table created.

Elapsed: 00:00:00.14
SQL>
SQL> select count(*)
2 from sales_compress
3 /

COUNT(*)
----------
0

Elapsed: 00:00:00.00
SQL>
SQL> @oltp_insert
SQL> set timing on
SQL> declare
2

Oracle Database 11g: New Features for Administrators A - 53


Practice 5-1: Using Table Compression (continued)
3 commit_after integer := 0 ;
4 loop_variable integer ;
5
6 cursor c_sales is
7 select prod_id
8 , cust_id
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

9 , time_id
10 , channel_id
11 , promo_id
12 , quantity_sold
13 , amount_sold
14 from sales ;
15
16 begin
17
ble
18 for r_sales in c_sales
fe r a
19 loop
ans
20
21 if commit_after = 0 n - t r
o
22 then
s an
23
24 loop_variable := 0 ; r ) ha deฺ
25 m ฺa Gui
26 co ent
commit_after := round(dbms_random.value(1,1)) ;
n ฺ
27
28 end if ; @ ao Stud
29 z i l le this
30 loฺ use
insert into sales_compress
c e
31 r to
(prod_id, cust_id, time_id, channel_id, promo_id,
a
m e
i
32 l e ( icens
quantity_sold, amount_sold)
l values
el oZ33
l
( r_sales.prod_id

Marc 34
35
, r_sales.cust_id
, r_sales.time_id
36 , r_sales.channel_id
37 , r_sales.promo_id
38 , r_sales.quantity_sold
39 , r_sales.amount_sold
40 ) ;
41
42 if loop_variable = commit_after
43 then
44 commit ;
45 commit_after := 0 ;
46 end if ;
47
48 loop_variable := loop_variable + 1 ;
49
50 end loop ;
51
52 end ;
53 /

Oracle Database 11g: New Features for Administrators A - 54


Practice 5-1: Using Table Compression (continued)

PL/SQL procedure successfully completed.

Elapsed: 00:03:38.49
SQL> set timing off
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> set timing off


SQL> select count(*) from sales_compress
2 /

COUNT(*)
----------
918843

SQL> select count(*) from sales_nocompress


ble
2 /
fe r a
an s
COUNT(*)
---------- n - t r
918843 a no
h a s ฺ
SQL>
ฺ a r) uide
3) Now you can compare the storage requirements
ฺ c ombetween
e n t Gtwo tables you just
the
n the
created. From your SQL*Plus session,oexecute
a u dexamine_storage.sql
script: @ is S t
i l l e
SQL> @examine_storage l o ฺz se th
SQL> set echo r e ou
coff
SQL> m a e t
SQL>
(
leselect e n s
segment_name, sum(bytes)/1024/1024 mb
Z2
i l from l i c
dba_segments
rc elo 3 where owner = user
Ma 4
5
and segment_name in ('SALES_COMPRESS','SALES_NOCOMPRESS')
group by segment_name
6 order by segment_name
7 /

SEGMENT_NAME MB
-------------------------------------- ----------
SALES_COMPRESS 15
SALES_NOCOMPRESS 36

2 rows selected.

SQL>
SQL> select table_name,compression,compress_for from
user_tables where table_name like '%COMPRESS%';

TABLE_NAME COMPRESS COMPRESS_FOR


------------------------------ -------- ------------------
SALES_NOCOMPRESS DISABLED

Oracle Database 11g: New Features for Administrators A - 55


Practice 5-1: Using Table Compression (continued)
SALES_COMPRESS ENABLED OLTP

2 rows selected.

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

4) Even though you would expect modifying a compressed table’s data to be


significantly slower than the same modification on an uncompressed table, there is a
minimal difference. From your SQL*Plus session, execute the dml_perf.sql
script.
SQL> @dml_perf
SQL> set echo off
Connected.
SQL> set timing on e
SQL> delete from sales_nocompress
r a bl
2 /
s fe
- t r an
918843 rows deleted.
o n
Elapsed: 00:01:18.07 s an
SQL>
r ) ha deฺ
SQL> commit;
m ฺa Gui
n ฺ co ent
Commit complete.
@ ao Stud
Elapsed: 00:00:04.72ille t h is
SQL>
z
loฺ use
c e
SQL> delete rfrom sales_compress
2 / (m
a e to
i l l e icens
l o Z rows
918843 l deleted.
rc e
Ma Elapsed: 00:01:12.94
SQL>
SQL> commit;

Commit complete.

Elapsed: 00:00:00.10
SQL>
SQL> set timing off
SQL> select count(*) from sales_nocompress
2 /

COUNT(*)
----------
0

1 row selected.

SQL> select count(*) from sales_compress

Oracle Database 11g: New Features for Administrators A - 56


Practice 5-1: Using Table Compression (continued)
2 /

COUNT(*)
----------
0
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

1 row selected.

SQL>

1 row selected.

SQL>

5) To clean up your environment, execute the cleanup.sql script: e


SQL> @cleanup r a bl
s fe
SQL> connect sh/sh
Connected. - t r an
SQL> drop table sales_nocompress purge on
2 / s an
r ) ha deฺ
Table dropped.
m ฺa Gui
SQL> drop table sales_compress n ฺ co ent
purge
2 /
@ ao Stud
z i l le this
Table dropped. oฺ
c e l u se
SQL> drop a r q_sales
table to purge;
drop le
m
( q_sales
table
e
ns purge
Z i l c
li *e
e l oERROR at line 1:
rc
Ma ORA-00942: table or view does not exist

SQL> drop table q_sales2 purge;


drop table q_sales2 purge
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$

Oracle Database 11g: New Features for Administrators A - 57


Practices for Lesson 6

In the practices for this lesson you use new partitioning schemes. You also use SQL
Access Advisor for partitioning advice.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
an s
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 58


Practice 6-1: Using Reference Partitioning
Reference partitioning enables tables with a parent/child relationship to be logically
equipartitioned by inheriting the partition key from the parent table without duplicating
the key columns. In this practice, you will create a range-partitioned table called ORDERS,
then create a table called ORDER_ITEMS, reference partitioned on a foreign key contained
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

in the ORDERS table.


1) Open a terminal window as the oracle user, change to the
$HOME/solutions/part directory, and start a SQL*Plus session connected as
the SYS user. From your SQL*Plus session, execute the setup.sql script.
$ $ . oraenv
ORACLE_SID = [db10g] ? orcl
$
$ cd /home/oracle/solutions/part ble
$ sqlplus / as sysdba fe r a
t r a ns
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 30
o n -12:15:02
2009
s an
Copyright (c) 1982, 2009, Oracle. All rights
r ) ha reserved.
d e ฺ
ฺa Gu i
Connected to:
c o m n t
Oracle Database 11g Enterprise o n ฺEdition d eRelease 11.2.0.1.0 -
Production a t u
@ is SStorage Management, OLAP,
With the Partitioning,i l l eAutomatic
th Testing options
o ฺz Application
Data Mining and lReal e
a r ce to us
l e (m ense
SQL> @setup
l
Zi alterlicuser sh identified by sh account unlock;
SQL>
e l o
rc
Ma User altered.

SQL> grant create tablespace to sh;

Grant succeeded.

SQL> grant drop tablespace to sh;

Grant succeeded.

SQL> alter user hr identified by hr account unlock;

User altered.

SQL> alter user oe identified by oe account unlock;

User altered.

SQL> grant select on oe.orders to sh;

Oracle Database 11g: New Features for Administrators A - 59


Practice 6-1: Using Reference Partitioning (continued)

Grant succeeded.

SQL> grant select on oe.order_items to sh;

Grant succeeded.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> grant select on hr.employees to sh;

Grant succeeded.
SQL>

2) Still in your SQL*Plus session, connect as the SH user. Execute the


create_orders.sql script to create the range-partitioned ORDERS table.
SQL> connect sh/sh ble
Connected. fe r a
SQL> @create_orders ans
SQL> n - t r
o
SQL> set pagesize 2000
SQL> set long 10000 s an
SQL> set linesize 200
r ) ha deฺ
SQL> set feedback on
m ฺa Gui
SQL> column partition_name format a25
SQL> column high_value format a85 n ฺ co ent
SQL>
@ ao Stud
SQL> -- cleanup
z i l le this
SQL>
c e loฺ use
SQL> drop table order_items
a r to
2 / m e
l e ( icens
drop table order_items
i l
el oZ *l
ERROR at line 1:
Marc ORA-00942: table or view does not exist

SQL>
SQL> drop table orders
2 /
drop table orders
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL>
SQL>
SQL> -- create initial tablespaces
SQL>
SQL> drop tablespace x;
drop tablespace x
*
ERROR at line 1:
ORA-00959: tablespace 'X' does not exist

Oracle Database 11g: New Features for Administrators A - 60


Practice 6-1: Using Reference Partitioning (continued)

SQL> create tablespace x datafile '/tmp/x.f' size 10m reuse;

Tablespace created.

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> drop tablespace y;


drop tablespace y
*
ERROR at line 1:
ORA-00959: tablespace 'Y' does not exist

SQL> create tablespace y datafile '/tmp/y.f' size 10m reuse;

Tablespace created.
ble
fe r a
SQL>
ans
SQL> -- create a range-partitioned table orders
SQL> n - t r
o
SQL>
s an
SQL> create table orders
2 ( order_id number(12) not null r ) ha deฺ
3 , order_date date not null m ฺa Gui
4 , order_mode varchar2(8)
n ฺ co ent
5 , order_status varchar2(1)
6 ) @ ao Stud
i l le this
7 partition by range (order_date)
z
c e loฺ use
8 ( partition p_before_jan_2006 values less than
r to
(to_date('01-JAN-2006','dd-MON-yyyy'))
a
m e
i l e ( icens
9 , partition p_2006_jan values less than (to_date('01-FEB-
l
2006','dd-MON-yyyy'))
el oZ l
10 , partition p_2006_feb values less than (to_date('01-MAR-

Marc 2006','dd-MON-yyyy'))
11 , partition p_2006_mar values less than (to_date('01-APR-
2006','dd-MON-yyyy'))
12 , partition p_2006_apr values less than (to_date('01-MAY-
2006','dd-MON-yyyy'))
13 , partition p_2006_may values less than (to_date('01-JUN-
2006','dd-MON-yyyy'))
14 , partition p_2006_jun values less than (to_date('01-JUL-
2006','dd-MON-yyyy'))
15 , partition p_2006_jul values less than (to_date('01-AUG-
2006','dd-MON-yyyy'))
16 , partition p_2006_aug values less than (to_date('01-SEP-
2006','dd-MON-yyyy'))
17 , partition p_2006_sep values less than (to_date('01-OCT-
2006','dd-MON-yyyy'))
18 , partition p_2006_oct values less than (to_date('01-NOV-
2006','dd-MON-yyyy'))
19 , partition p_2006_nov values less than (to_date('01-DEC-
2006','dd-MON-yyyy'))

Oracle Database 11g: New Features for Administrators A - 61


Practice 6-1: Using Reference Partitioning (continued)
20 , partition p_2006_dec values less than (to_date('01-JAN-
2007','dd-MON-yyyy'))
21 ) parallel
22 /
Table created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> alter table orders add constraint orders_pk
2 primary key (order_id)
3 /

Table altered.

SQL>
3) Execute the create_order_items.sql script to create a reference-partitioned ble
ORDER_ITEMS table. fe r a
ans
SQL>
n - t r
SQL> @create_order_items o
SQL> REM
s an
SQL> REM REF Partitioning
r ) ha deฺ
SQL> REM 3.Create a REF partitioned table that depends on the
m ฺa Gui
first created one (e.g. Lineitems, pk-fk order_id)
SQL>
n ฺ co ent
SQL> set echo on
SQL> @ ao Stud
SQL> set pagesize 2000 z i l le this
SQL> set long 10000
c e loฺ use
a r
SQL> set linesize 200 to
m e
i l e ( icens
SQL> set feedback on
l
SQL> column partition_name format a25
el oZ l
SQL> column high_value format a85

Marc SQL>
SQL>
SQL> -- Create a table order_items with a reference to the
orders table partition scheme
SQL>
SQL>
SQL> Rem see ORA-14652 for restrictions around REF
Partitionining FKs
SQL>
SQL> create table order_items
2 ( order_id number(12) not null
3 , product_id number not null
4 , quantity number not null
5 , sales_amount number not null
6 , constraint order_items_orders_fk foreign key (order_id)
references orders(order_id)
7 )
8 partition by reference (order_items_orders_fk)
9 parallel
10 /

Oracle Database 11g: New Features for Administrators A - 62


Practice 6-1: Using Reference Partitioning (continued)
Table created.

SQL>

4) Execute the query_dict_1.sql script to view information about the reference-


partitioned ORDER_ITEMS table.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> @query_dict_1
SQL> REM
SQL> REM REF Partitioning
SQL> REM 4.show the partition setup for the REF partitioned
table in the dictionary
SQL> REM
SQL>
SQL> set echo on
ble
SQL>
fe r a
SQL> set pagesize 2000
ans
SQL> set long 10000
n - t r
SQL> set linesize 200 o
SQL> set feedback on
s an
SQL> column partition_name format a25
SQL> column high_value format a85 r ) ha deฺ
SQL> set echo on m ฺa Gui
SQL>
n ฺ co ent
SQL>
@ ao Stud
SQL> -- show how the partitions were created
SQL> z i l le this
SQL>
c e loฺ use
a r to
SQL> select table_name, partitioning_type,
m e
i l e ( icens
ref_ptn_constraint_name
l
2 from user_part_tables
el oZ l
3 where table_name in ('ORDERS','ORDER_ITEMS');

Marc TABLE_NAME PARTITION REF_PTN_CONSTRAINT_NAME


---------------------------- --------- -----------------------
ORDERS RANGE
ORDER_ITEMS REFERENCE ORDER_ITEMS_ORDERS_FK

2 rows selected.

SQL>
SQL> select table_name, partition_name, high_value
2 from user_tab_partitions
3 where table_name in ('ORDERS','ORDER_ITEMS')
4 order by partition_position, table_name;

TABLE_NAME PARTITION_NAME
HIGH_VALUE
------------------------------ ------------------------- -----
--------------------------------------------------------------
------------------

Oracle Database 11g: New Features for Administrators A - 63


Practice 6-1: Using Reference Partitioning (continued)
ORDERS P_BEFORE_JAN_2006
TO_DATE(' 2006-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_BEFORE_JAN_2006
ORDERS P_2006_JAN
TO_DATE(' 2006-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_JAN
ORDERS P_2006_FEB
TO_DATE(' 2006-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_FEB
ORDERS P_2006_MAR
TO_DATE(' 2006-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ble
ORDER_ITEMS P_2006_MAR
fe r a
ORDERS P_2006_APR
ans
TO_DATE(' 2006-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN') n - t r
o
ORDER_ITEMS P_2006_APR
s an
ORDERS P_2006_MAY
r ) ha deฺ
TO_DATE(' 2006-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN') m ฺa Gui
ORDER_ITEMS P_2006_MAY
n ฺ co ent
ORDERS ao Stud
P_2006_JUN
@
TO_DATE(' 2006-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')z i l le this
ORDER_ITEMS
c e loฺ use P_2006_JUN
ORDERS a r to P_2006_JUL
m e
i l e ( icens
TO_DATE(' 2006-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
l
'NLS_CALENDAR=GREGORIAN')
el oZ
ORDER_ITEMS
l P_2006_JUL

Marc ORDERS P_2006_AUG


TO_DATE(' 2006-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_AUG
ORDERS P_2006_SEP
TO_DATE(' 2006-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_SEP
ORDERS P_2006_OCT
TO_DATE(' 2006-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_OCT
ORDERS P_2006_NOV
TO_DATE(' 2006-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_NOV
ORDERS P_2006_DEC
TO_DATE(' 2007-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_DEC

Oracle Database 11g: New Features for Administrators A - 64


Practice 6-1: Using Reference Partitioning (continued)

26 rows selected.

SQL>
SQL> select up.table_name, up.partitioning_type, uc.table_name
ref_table
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

2 from user_part_tables up,


3 (select r.table_name, r.constraint_name from
user_constraints uc, user_constraints r
4 where uc.constraint_name=r.constraint_name and
uc.owner=r.owner) uc
5 where up.ref_ptn_constraint_name = uc.constraint_name(+)
6 and up.table_name in ('ORDERS','ORDER_ITEMS');

TABLE_NAME PARTITION REF_TABLE


ble
------------------------------ --------- ---------------------
fe r a
ORDERS RANGE
an s
ORDER_ITEMS REFERENCE ORDER_ITEMS
n - t r
2 rows selected. a no
h a s ฺ
SQL>
ฺ a r) uide
5) Execute the insert_orders.sql script ฺto
c m datantintoGthe ORDERS and
oinsert
ORDER_ITEMS tables. a on tude
SQL> @insert_orders ille
@ is S
SQL> REM l o ฺz se th
SQL> REM REFrc e ou
Partitioning
SQL> REMm a
5.inserte datat into orders. Show data placement in an
( s
Z
SQL> l i cen
illeREM partition
explicit

rc eloSQL>
Ma SQL> set echo on
SQL>
SQL> set pagesize 2000
SQL> set long 10000
SQL> set linesize 200
SQL> set feedback on
SQL> column partition_name format a25
SQL> column high_value format a85
SQL>
SQL> -- insert some data into the orders and order_items
tables
SQL>
SQL>
SQL> insert into orders values (1, to_date('23-OCT-2006','dd-
MON-yyyy'), 'manual', 'U') ;
1 row created.

SQL> insert into orders values (2, to_date('24-OCT-2006','dd-


MON-yyyy'), 'auto', 'I') ;

Oracle Database 11g: New Features for Administrators A - 65


Practice 6-1: Using Reference Partitioning (continued)

1 row created.

SQL> insert into orders values (3, to_date('25-OCT-2006','dd-


MON-yyyy'), 'manual', 'P') ;
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

1 row created.

SQL> insert into orders values (4, to_date('26-OCT-2006','dd-


MON-yyyy'), 'manual', 'U') ;

1 row created.

SQL> insert into orders values (5, to_date('26-NOV-2006','dd-


MON-yyyy'), 'manual', 'U') ;
ble
fe r a
1 row created.
t r a ns
SQL> insert into order_items values (1, 12, 40, 12000) o n -;
s an
1 row created.
r ) ha deฺ
SQL> insert into order_items valuesm(1, ฺa 2, G1,ui2000) ;
n ฺ co ent
1 row created.
@ ao Stud
z i
SQL> insert into order_items l le thvalues
is (1, 8, 20, 8400) ;
l o ฺ s e
1 row created.
a rce to u
l e (m ense
SQL>l
Zi insert licinto order_items values (2, 1, 4, 900) ;
e l o
rc 1 row created.
Ma
SQL> insert into order_items values (2, 87, 4, 6200) ;

1 row created.

SQL> insert into order_items values (2, 2, 4, 3400) ;

1 row created.

SQL> insert into order_items values (2, 6, 2, 70) ;

1 row created.

SQL> insert into order_items values (3, 1, 90, 1200) ;

1 row created.

SQL> insert into order_items values (4, 90, 10, 9000) ;

Oracle Database 11g: New Features for Administrators A - 66


Practice 6-1: Using Reference Partitioning (continued)
1 row created.

SQL> insert into order_items values (4, 74, 12, 8000) ;

1 row created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> insert into order_items values (4, 21, 1, 900) ;

1 row created.

SQL> insert into order_items values (4, 90, 4, 39000) ;

1 row created.

SQL> insert into order_items values (4, 32, 6, 700) ;


ble
fe r a
1 row created.
ans
SQL> insert into order_items values (4, 45, 2, 80) o ;n - t r
a n
1 row created. a s
h deฺ
r )
SQL> insert into order_items valuesm(4, ฺa 72,G6,ui 72000) ;
n ฺ co ent
1 row created.
@ ao Stud
z i
SQL> insert into order_items l le thvalues
is (5, 1, 40, 42000) ;
l o ฺ s e
1 row created.
a rce to u
l e (m ense
SQL>l
Zi insert licinto order_items values (5, 2, 40, 800) ;
e l o
rc 1 row created.
Ma
SQL> insert into order_items values (5, 52, 80, 100) ;

1 row created.

SQL> insert into order_items values (5, 90, 4, 1200) ;

1 row created.

SQL> commit
2 /

Commit complete.
SQL>

6) Execute the show_data_placement.sql script to observe how the data is


collocated in the partitions.
SQL> @show_data_placement

Oracle Database 11g: New Features for Administrators A - 67


Practice 6-1: Using Reference Partitioning (continued)
SQL> REM
SQL> REM REF Partitioning
SQL> REM 5.insert data into orders. Show data placement in an
explicit partition
SQL> REM
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> set echo on


SQL>
SQL> set pagesize 2000
SQL> set long 10000
SQL> set linesize 200
SQL> set feedback on
SQL> column partition_name format a25
SQL> column high_value format a85
SQL> set echo on
ble
SQL>
fe r a
SQL> set feedback on
ans
SQL>
SQL> -- see how the data was co-located in the same partitions n - t r
o
SQL>
s an
SQL> alter session set nls_date_format='dd-mon-yyyy' ;
r ) ha deฺ
Session altered. m ฺa Gui
n ฺ co ent
SQL>
SQL> select order_id, order_date @ ao Stud
2 from orders partition z i l le t(p_2006_oct)
h is
3 /
c e loฺ use
a r to
m e
i l l e ( ic-----------
ORDER_ID
---------- e ns
ORDER_DATE

l o Z l
1 23-oct-2006
rc e 2 24-oct-2006
Ma 3 25-oct-2006
4 26-oct-2006

4 rows selected.

SQL>
SQL>
SQL> select oi.order_id, o.order_date, sum(oi.sales_amount)
sum_sales
2 from orders o
3 , order_items partition (p_2006_oct) oi
4 where o.order_id = oi.order_id
5 group by oi.order_id, o.order_date
6 order by oi.order_id
7 /

ORDER_ID ORDER_DATE SUM_SALES


---------- ----------- ----------
1 23-oct-2006 22400

Oracle Database 11g: New Features for Administrators A - 68


Practice 6-1: Using Reference Partitioning (continued)
2 24-oct-2006 10570
3 25-oct-2006 1200
4 26-oct-2006 129680

4 rows selected.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL>
SQL> select order_id, order_date
2 from orders partition (p_2006_nov)
3 /

ORDER_ID ORDER_DATE
---------- -----------
5 26-nov-2006
ble
fe r a
1 row selected.
ans
SQL> n - t r
o
SQL>
s an
sum_sales r ) ha deฺ
SQL> select oi.order_id, o.order_date, sum(oi.sales_amount)

2 from orders o m ฺa Gui


3 , order_items partition (p_2006_nov) oi
n ฺ co ent
4 where o.order_id = oi.order_id
@ ao Stud
5 group by oi.order_id, o.order_date
6 order by oi.order_id z i l le this
7 /
c e loฺ use
a r to SUM_SALES
m e
i l e ( ic-----------
ORDER_ID
l
---------- e ns
ORDER_DATE
----------
l o Z l
5 26-nov-2006 44100
rc e
Ma 1 row selected.

SQL>

7) Execute the drop_partition.sql script to drop the p_before_jan_2006


partition from the ORDERS table.
SQL> @drop_partition
SQL> REM
SQL> REM REF Partitioning
SQL> REM 6.insert data into the REF partitioned table and show
that co-location of the dependent data is taken place
SQL> REM
SQL>
SQL> set echo on
SQL>
SQL> set pagesize 2000
SQL> set long 10000
SQL> set linesize 200

Oracle Database 11g: New Features for Administrators A - 69


Practice 6-1: Using Reference Partitioning (continued)
SQL> set feedback on
SQL> column partition_name format a25
SQL> column high_value format a85
SQL> set feedback on
SQL>
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> -- show the manageability aspects of inheriting the


partitioning scheme (drop a partition for the ORDERS table)
SQL>
SQL> set echo on
SQL> alter table orders drop partition p_before_jan_2006
update global indexes
2 /

Table altered.
ble
fe r a
SQL>
t r a ns
8) Execute the query_dict_2.sql script to view information about the n
o -
tables.
SQL> @query_dict_2 s an
SQL> REM
r ) ha deฺ
SQL> REM REF Partitioning
SQL> REM 6.insert data into the REF m ฺa Gui table and show
partitioned
that co-location of the dependent n ฺ co dataenist taken place
SQL> REM
@ ao Stud
SQL>
z i l le this
SQL> set echo on oฺ
SQL> c e l u se
SQL> setm a r
pagesize to
2000
SQL> le ( longen10000
set s e
i
SQL>
l li c
Z set linesize 200
e l oSQL> set feedback on
rc
Ma SQL>
SQL>
column partition_name format a25
column high_value format a85
SQL> set feedback on
SQL>
SQL>
SQL> -- again, show the partitions
SQL>
SQL> set echo on
SQL> select table_name, partition_name, high_value
2 from user_tab_partitions
3 where table_name in ('ORDERS','ORDER_ITEMS')
4 order by partition_position, table_name
5 /

TABLE_NAME PARTITION_NAME
HIGH_VALUE
------------------------------ ------------------------- -----
--------------------------------------------------------------
------------------

Oracle Database 11g: New Features for Administrators A - 70


Practice 6-1: Using Reference Partitioning (continued)
ORDERS P_2006_JAN
TO_DATE(' 2006-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_JAN
ORDERS P_2006_FEB
TO_DATE(' 2006-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_FEB
ORDERS P_2006_MAR
TO_DATE(' 2006-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_MAR
ORDERS P_2006_APR
TO_DATE(' 2006-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ble
ORDER_ITEMS P_2006_APR
fe r a
ORDERS P_2006_MAY
ans
TO_DATE(' 2006-06-01 00:00:00', 'SYYYY-MM-DD
'NLS_CALENDAR=GREGORIAN')
HH24:MI:SS',
n - t r
ORDER_ITEMS P_2006_MAY a no
ORDERS P_2006_JUN
h a s ฺ
TO_DATE(' 2006-07-01 00:00:00', 'SYYYY-MM-DD
'NLS_CALENDAR=GREGORIAN') ฺ a ide
r) uHH24:MI:SS',
ORDER_ITEMS c
P_2006_JUN
ฺ om ent G
ORDERS on tud
P_2006_JUL
a
l l e@ is S
TO_DATE(' 2006-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
i h
oฺz use t
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS e l P_2006_JUL
ORDERS a rc to P_2006_AUG
m
( ens e
TO_DATE(' 2006-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
i l l e
l ORDER_ITEMS
lic
'NLS_CALENDAR=GREGORIAN')
oZ P_2006_AUG
e
Marc ORDERS P_2006_SEP
TO_DATE(' 2006-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_SEP
ORDERS P_2006_OCT
TO_DATE(' 2006-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_OCT
ORDERS P_2006_NOV
TO_DATE(' 2006-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_NOV
ORDERS P_2006_DEC
TO_DATE(' 2007-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_DEC

24 rows selected.

SQL>

Oracle Database 11g: New Features for Administrators A - 71


Practice 6-1: Using Reference Partitioning (continued)
9) Execute the add_partition.sql script to add p2007_01/02 partitions.
SQL> @add_partition
SQL> REM
SQL> REM REF Partitioning
SQL> REM 6.insert data into the REF partitioned table and show
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

that co-location of the dependent data is taken place


SQL> REM
SQL>
SQL> set echo on
SQL>
SQL> set pagesize 2000
SQL> set long 10000
SQL> set linesize 200
SQL> set feedback on
SQL> column partition_name format a25 ble
SQL> column high_value format a85 fe r a
SQL> set echo on an s
SQL> set feedback on n - t r
SQL>
a no
h a s ฺ
SQL> -- manageability aspects and flexibility to combine PMOPs
but still have the flexibility to place various partitions
SQL> ฺ a r) uide
SQL> alter table orders
ฺ c om ent G
2007','dd-mon-yyyy')) a on tud
2 add partition p2007_01 values less than (to_date('01-feb-

3 tablespace x; l l e@ is S
i
ฺz se th
l o
Table altered.
a rce to u
SQL> l e (m ense
SQL>
l
Zi -- show lic co-location of partitions for parent and child
l o
e SQL>
rc
Ma SQL> select table_name, partition_name, tablespace_name,
high_value
2 from user_tab_partitions where table_name in
('ORDERS','ORDER_ITEMS')
3 order by partition_position, table_name;

TABLE_NAME PARTITION_NAME
TABLESPACE_NAME HIGH_VALUE
------------------------------ ------------------------- -----
------------------------- ------------------------------------
-------------------------------------------------
ORDERS P_2006_JAN USERS
TO_DATE(' 2006-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_JAN USERS
ORDERS P_2006_FEB USERS
TO_DATE(' 2006-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_FEB USERS

Oracle Database 11g: New Features for Administrators A - 72


Practice 6-1: Using Reference Partitioning (continued)
ORDERS P_2006_MAR USERS
TO_DATE(' 2006-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_MAR USERS
ORDERS P_2006_APR USERS
TO_DATE(' 2006-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_APR USERS
ORDERS P_2006_MAY USERS
TO_DATE(' 2006-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_MAY USERS
ORDERS P_2006_JUN USERS
TO_DATE(' 2006-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ble
ORDER_ITEMS P_2006_JUN USERS
fe r a
ORDERS P_2006_JUL s
USERS
an
TO_DATE(' 2006-08-01 00:00:00', 'SYYYY-MM-DD
'NLS_CALENDAR=GREGORIAN')
HH24:MI:SS',
n - t r
ORDER_ITEMS P_2006_JUL a no USERS
ORDERS P_2006_AUG
h a s ฺ USERS
TO_DATE(' 2006-09-01 00:00:00', 'SYYYY-MM-DD
'NLS_CALENDAR=GREGORIAN') ฺ a ide
r) uHH24:MI:SS',
ORDER_ITEMS P_2006_AUG
ฺ c om ent G USERS
ORDERS o n
P_2006_SEP
a Stu d USERS

l @
TO_DATE(' 2006-10-01 00:00:00', 'SYYYY-MM-DD
le this HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')z i
ORDER_ITEMS
c e loฺ use P_2006_SEP USERS
ORDERS a r t o P_2006_OCT USERS
m e
i l l e ( icens
TO_DATE(' 2006-11-01 00:00:00', 'SYYYY-MM-DD
'NLS_CALENDAR=GREGORIAN')
HH24:MI:SS',

el oZ
ORDER_ITEMS
l P_2006_OCT USERS

Marc ORDERS P_2006_NOV


TO_DATE(' 2006-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
USERS

'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_NOV USERS
ORDERS P_2006_DEC USERS
TO_DATE(' 2007-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_DEC USERS
ORDERS P2007_01 X
TO_DATE(' 2007-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P2007_01 X

26 rows selected.

SQL>
SQL> -- second PMOP
SQL>
SQL> alter table orders

Oracle Database 11g: New Features for Administrators A - 73


Practice 6-1: Using Reference Partitioning (continued)
2 add partition p2007_02 values less than (to_date('01-mar-
2007','dd-mon-yyyy'))
3 tablespace x
4 dependent tables ( order_items (partition foo tablespace
y));
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Table altered.

SQL>
SQL> select table_name, partition_name, tablespace_name,
high_value
2 from user_tab_partitions
3 where table_name in ('ORDERS','ORDER_ITEMS') order by
partition_position, table_name;
ble
TABLE_NAME PARTITION_NAME
fe r a
TABLESPACE_NAME HIGH_VALUE
ans
------------------------------ ------------------------- -----
n
------------------------- ------------------------------------ - t r
o
-------------------------------------------------
s an
ORDERS P_2006_JAN
r ) ha deฺ
TO_DATE(' 2006-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
USERS

'NLS_CALENDAR=GREGORIAN') m ฺa Gui
ORDER_ITEMS P_2006_JAN
n ฺ co ent USERS
ORDERS
@ ao Stud
P_2006_FEB
TO_DATE(' 2006-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
USERS

'NLS_CALENDAR=GREGORIAN')z i l le this
ORDER_ITEMS
c e loฺ use P_2006_FEB USERS
ORDERS a r to P_2006_MAR USERS
m e
i l e ( icens
TO_DATE(' 2006-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
l
'NLS_CALENDAR=GREGORIAN')
el oZ
ORDER_ITEMS
l P_2006_MAR USERS

Marc ORDERS P_2006_APR


TO_DATE(' 2006-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
USERS

'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_APR USERS
ORDERS P_2006_MAY USERS
TO_DATE(' 2006-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_MAY USERS
ORDERS P_2006_JUN USERS
TO_DATE(' 2006-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_JUN USERS
ORDERS P_2006_JUL USERS
TO_DATE(' 2006-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_JUL USERS
ORDERS P_2006_AUG USERS
TO_DATE(' 2006-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_AUG USERS

Oracle Database 11g: New Features for Administrators A - 74


Practice 6-1: Using Reference Partitioning (continued)
ORDERS P_2006_SEP USERS
TO_DATE(' 2006-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_SEP USERS
ORDERS P_2006_OCT USERS
TO_DATE(' 2006-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_OCT USERS
ORDERS P_2006_NOV USERS
TO_DATE(' 2006-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ORDER_ITEMS P_2006_NOV USERS
ORDERS P_2006_DEC USERS
TO_DATE(' 2007-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN')
ble
ORDER_ITEMS P_2006_DEC USERS
fe r a
ORDERS P2007_01 X
ans
TO_DATE(' 2007-02-01 00:00:00', 'SYYYY-MM-DD
'NLS_CALENDAR=GREGORIAN')
HH24:MI:SS',
n - t r
ORDER_ITEMS P2007_01 a no X
ORDERS P2007_02
h a s ฺ X
TO_DATE(' 2007-03-01 00:00:00', 'SYYYY-MM-DD
'NLS_CALENDAR=GREGORIAN') ฺ a ide
r) uHH24:MI:SS',
ORDER_ITEMS FOO ฺ c om ent G Y
o n
a Stu d
28 rows selected.
l l e@ is
z i t h
SQL>
c e loฺ use
a r to script to drop the partitions and tablespaces created in
10) Execute the mcleanup_1.sqle
l l e ( Exit
this ipractice. c e ns SQL*Plus.
from
l o Z li
rce SQL> @cleanup_1
Ma SQL>
SQL>
REM
REM REF Partitioning
SQL> REM
SQL>
SQL> set echo on
SQL>
SQL> set pagesize 2000
SQL> set long 10000
SQL> set linesize 200
SQL> set feedback on
SQL> column partition_name format a25
SQL> column high_value format a85
SQL> set echo on
SQL> set feedback on
SQL>
SQL> -- cleanup
SQL>
SQL> alter table orders drop partition p2007_01;

Oracle Database 11g: New Features for Administrators A - 75


Practice 6-1: Using Reference Partitioning (continued)
Table altered.

SQL> alter table orders drop partition p2007_02;

Table altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> drop tablespace x;

Tablespace dropped.

SQL> drop tablespace y;

Tablespace dropped.
ble
SQL>
fe r a
SQL> exit s
Disconnected from Oracle Database 11g Enterprise Edition
- t r an
Release 11.2.0.1.0 - Production o n
an
With the Partitioning, Automatic Storage Management, OLAP,
s
Data Mining and Real Application Testing options
$ r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 76


Practice 6-2: Using Interval Partitioning
Interval partitioning fully automates the creation of range partitions. Managing the
creation of new partitions can be a cumbersome and highly repetitive task. This is
especially true for predictable additions of partitions covering small ranges, such as
adding new daily partitions. Interval partitioning automates this operation by creating
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

partitions on demand. It is assumed that your current directory is


/home/oracle/solutions/part.
1) Execute the create_newsales.sql script to create the NEWSALES interval-
partitioned table.
$ . oraenv
ORACLE_SID = [db10g] ? orcl
$ cd /home/oracle/solutions/part
$ ble
$ sqlplus sh/sh
fe r a
ans
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 30 12:33:12
n - t r
2009
a no
Copyright (c) 1982, 2009, Oracle. All rights h a s reserved.

r ) i d e
m ฺa Gu
ฺ c o e n t
Connected to: n
Oracle Database 11g Enterprise
@ ao Edition
S tud Release 11.2.0.1.0 -
Production
z i l leAutomatic
t h is Storage Management, OLAP,
Data Mining and e oฺ Application
With the Partitioning,
lReal u se Testing options
a r c t o
SQL> le (m ense
@create_newsales
Zi
SQL>
l lic
l o
e SQL> set pagesize 2000
rc
Ma SQL>
SQL>
set long 10000
set linesize 200
SQL> set feedback on
SQL> column partition_name format a25
SQL> column high_value format a85
SQL>
SQL> REM
SQL> REM Interval Partitioning
SQL> REM 1.Introduce the concept of Interval Partitioning
SQL> REM 2.Create an interval partitioned table
SQL> REM
SQL>
SQL> -- cleanup
SQL> set echo on
SQL>
SQL> drop table historical_newsales
2 /
drop table historical_newsales
*

Oracle Database 11g: New Features for Administrators A - 77


Practice 6-2: Using Interval Partitioning (continued)
ERROR at line 1:
ORA-00942: table or view does not exist

SQL>
SQL> drop table newsales
2 /
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

drop table newsales


*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL>
SQL> -- create interval partitioned table
SQL>
SQL> create table newsales
ble
2 ( prod_id number(6) not null
fe r a
3 , cust_id number not null
ans
4
5
, time_id date not null
, channel_id char(1) not null n - t r
o
6 , promo_id number(6) not null
s an
7
8
, quantity_sold number(3) not null
, amount_sold number(10,2) not null r ) ha deฺ
9 ) m ฺa Gui
10 partition by range (time_id)
n ฺ co ent
11
12 @ ao Stud
interval (numtodsinterval(1,'DAY'))
( partition p_before_1_jan_2005 values
13 i l le this
less than (to_date('01-01-2005','dd-mm-yyyy')))
z
14 /
c e loฺ use
a r to
m e
i l l e ( icens
Table created.

l Z
oSQL> l
e
Marc SQL>

2) Execute the query_dict_3.sql script to query the USER_TAB_PARTITIONS


dictionary view for information about the NEWSALES table.
SQL>
SQL> @query_dict_3
SQL> set echo on
SQL> set pagesize 2000
SQL> set long 10000
SQL> set linesize 200
SQL> set feedback on
SQL> column partition_name format a25
SQL> column high_value format a85
SQL> REM
SQL> REM Interval Partitioning
SQL> REM 3.Show the segment allocation of it
SQL> REM
SQL> set echo on

Oracle Database 11g: New Features for Administrators A - 78


Practice 6-2: Using Interval Partitioning (continued)
SQL> -- show partitions and partition boundaries for the
interval partitioned table
SQL> select partition_name, high_value
2 from user_tab_partitions
3 where table_name = 'NEWSALES'
4 order by partition_position
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

5 /

PARTITION_NAME HIGH_VALUE
------------------------- ------------------------------------
-------------------------------------------------
P_BEFORE_1_JAN_2005 TO_DATE(' 2005-01-01 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')

1 row selected.
ble
fe r a
SQL>
t r a ns
3) Execute the insert_newsales.sql script to insert new data into the n
o -
NEWSALES
table that forces the creation of a new partition (segment).
s an
SQL>
r ) ha deฺ
SQL> @insert_newsales
m ฺa Gui
SQL> set echo on
SQL> set pagesize 2000 n ฺ co ent
SQL> set long 10000
@ ao Stud
SQL> set linesize 200
z i l le this
ฺon
elo o use format a25
SQL> set feedback
c
SQL> column rpartition_name
a high_valuet format a85
SQL> column
( m s e
SQL>lle
Z
SQL>
i REM l i cen Partitioning
REM Interval
rc eloSQL> REM 4.Insert new data that forces the creation of a new
Ma partition (segment)
SQL> set pagesize 2000
SQL> set long 10000
SQL> set linesize 200
SQL> set feedback on
SQL> column partition_name format a25
SQL> column high_value format a85
SQL> -- insert some data after January 1 2005
SQL>
SQL> insert into newsales values (11160,17450,to_date('01-jan-
2005','dd-mon-yyyy'),'I',9999,19,798) ;

1 row created.

SQL> insert into newsales values (1340,33710,to_date('02-jan-


2005','dd-mon-yyyy'),'S',9999,16,1264) ;

1 row created.

Oracle Database 11g: New Features for Administrators A - 79


Practice 6-2: Using Interval Partitioning (continued)
SQL> insert into newsales values (25270,65880,to_date('05-jan-
2005','dd-mon-yyyy'),'I',9999,5,210) ;

1 row created.

SQL> insert into newsales values (1615,73480,to_date('05-jan-


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

2005','dd-mon-yyyy'),'I',9999,8,96) ;

1 row created.

SQL> insert into newsales values (1900,84910,to_date('06-jan-


2005','dd-mon-yyyy'),'I',9999,42,378) ;

1 row created.
ble
SQL> insert into newsales values (8085,37900,to_date('09-jan-
fe r a
2005','dd-mon-yyyy'),'S',9999,1,68) ;
ans
1 row created. n - t r
a no
a s ฺ
SQL> insert into newsales values (755,26590,to_date('09-jan-
h
2005','dd-mon-yyyy'),'I',9999,11,132) ;r)
ฺ a u ide
1 row created. ฺ c om ent G
a on tud
SQL> insert into newsales
l e@values
i s S(10,68060,to_date('09-jan-
i l
ฺz se t h
2005','dd-mon-yyyy'),'P',9999,28,4900) ;
l o
1 row created.
a rce to u
l e (m ense
SQL>l
Zi insert licinto newsales values (13425,109310,to_date('10-
el ojan-2005','dd-mon-yyyy'),'I',9999,1,68) ;

Marc 1 row created.

SQL> insert into newsales values (1955,65190,to_date('10-jan-


2005','dd-mon-yyyy'),'S',9999,28,1512) ;

1 row created.

SQL>
SQL> set feedback on
SQL>
SQL> commit
2 /

Commit complete.

SQL>

4) Execute the query_dict_4.sql script to see information about the new partition.

Oracle Database 11g: New Features for Administrators A - 80


Practice 6-2: Using Interval Partitioning (continued)
SQL>
SQL> @query_dict_4
SQL> set echo on
SQL> set pagesize 2000
SQL> set long 10000
SQL> set linesize 200
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> set feedback on


SQL> column partition_name format a25
SQL> column high_value format a85
SQL> REM
SQL> REM Interval Partitioning
SQL> REM 5.Show the segment allocation again-you will see a
new segment
SQL> REM
SQL> set echo on
ble
SQL> -- see how new partitions were created
fe r a
SQL>
ans
SQL> select partition_name, high_value
2 from user_tab_partitions n - t r
3 where table_name = 'NEWSALES' a no
4 order by partition_position
h a s ฺ
5 /
ฺ a r) uide
PARTITION_NAME HIGH_VALUE
ฺ c om ent G
------------------------- a on tud
------------------------------------
e@TO_DATE(' S
-------------------------------------------------
s
P_BEFORE_1_JAN_2005zill t h i 2005-01-01 00:00:00',
l o ฺ
'SYYYY-MM-DD HH24:MI:SS', s e'NLS_CALENDAR=GREGORIAN')
SYS_P21 a rce to u TO_DATE(' 2005-01-02 00:00:00',
l e n se
(m eHH24:MI:SS',
'SYYYY-MM-DD 'NLS_CALENDAR=GREGORIAN')
Zi l
SYS_P22
lic TO_DATE(' 2005-01-03 00:00:00',
e l o'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
rc SYS_P23 TO_DATE(' 2005-01-06 00:00:00',
Ma 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
SYS_P24 TO_DATE(' 2005-01-07 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
SYS_P25 TO_DATE(' 2005-01-10 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
SYS_P26 TO_DATE(' 2005-01-11 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')

7 rows selected.

SQL>

5) Execute the merge_partition.sql script to merge two partitions.


SQL>
SQL> @merge_partition
SQL> set echo on
SQL> set pagesize 2000
SQL> set long 10000

Oracle Database 11g: New Features for Administrators A - 81


Practice 6-2: Using Interval Partitioning (continued)
SQL> set linesize 200
SQL> set feedback on
SQL> column partition_name format a25
SQL> column high_value format a85
SQL> REM
SQL> REM Interval Partitioning
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> REM 6.Do a partition maintenance operation on older


Partitions (e.g. MERGE). This will demonstrate the fact that
an interval partitioned table can have manually managed older
rnage partition components
SQL> REM
SQL> -- merge 2 partitions: traditional functionality of
course works
SQL> set echo on
SQL> alter table newsales
ble
2 merge partitions for(to_date('01-JAN-2005','dd-MON-
fe r a
yyyy'))
an s
3 , for(to_date('02-JAN-2005','dd-MON-yyyy'))
4 into partition p_before_3_jan_2005 n - t r
5 / a no
h a s ฺ
Table altered.
ฺ a r) uide
SQL> ฺ c om ent G
a onto view d
tuinformation
6) Execute the query_dict_5.sql
l e@script
i s S about the merged
partitions. l
ฺzi se th
l o
SQL>
a r ce to u
SQL> @query_dict_5
SQL>lle
(m enonse
set echo
l o Zi set pagesize
SQL> lic 2000
rc e SQL> set long 10000
Ma SQL> set linesize 200
SQL> set feedback on
SQL> column partition_name format a25
SQL> column high_value format a85
SQL> REM
SQL> REM Interval Partitioning
SQL> REM 7.take a standard range partitioned table and extend
it to an interval partitioned table. This demonstrates the
migration path to this new functionality.
SQL> REM
SQL> set echo on
SQL> -- show the list of partitions again
SQL> select partition_name, high_value
2 from user_tab_partitions
3 where table_name = 'NEWSALES'
4 order by partition_position
5 /

PARTITION_NAME HIGH_VALUE

Oracle Database 11g: New Features for Administrators A - 82


Practice 6-2: Using Interval Partitioning (continued)
------------------------- ------------------------------------
-------------------------------------------------
P_BEFORE_1_JAN_2005 TO_DATE(' 2005-01-01 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
P_BEFORE_3_JAN_2005 TO_DATE(' 2005-01-03 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SYS_P23 TO_DATE(' 2005-01-06 00:00:00',


'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
SYS_P24 TO_DATE(' 2005-01-07 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
SYS_P25 TO_DATE(' 2005-01-10 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
SYS_P26 TO_DATE(' 2005-01-11 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
ble
6 rows selected.
fe r a
an s
SQL>
n - t r
o
table. s an
7) Execute the create_hist_newsales.sql script to create a range-partitioned

r ) ha deฺ
SQL>
m ฺa Gui
SQL> @create_hist_newsales
SQL> set echo on n ฺ co ent
SQL> set pagesize 2000
@ ao Stud
SQL> set long 10000 ille is
z t h
SQL> set linesize
c
SQL> set feedbacke loฺ200
on u se
a rpartition_name
to
SQL> column
SQL>lle
m
( high_value
column e n s e format a25
format a85
l o Zi REM lic
SQL>
rc e SQL> REM Interval Partitioning
Ma SQL> REM 7.take a standard range partitioned table and extend
it to an interval partitioned table. This demonstrates the
migration path to this new functionality.
SQL> REM
SQL> set echo on
SQL> -- create a range partitioned table, that will be
migrated to interval partitioning
SQL> create table historical_newsales
2 ( prod_id number(6) not null
3 , cust_id number not null
4 , time_id date not null
5 , channel_id char(1) not null
6 , promo_id number(6) not null
7 , quantity_sold number(3) not null
8 , amount_sold number(10,2) not null
9 )
10 partition by range (time_id)
11 (partition p_previous_century values
12 less than (to_date('01-JAN-2000','dd-MON-yyyy'))

Oracle Database 11g: New Features for Administrators A - 83


Practice 6-2: Using Interval Partitioning (continued)
13 , partition p_2000 values less than (to_date('01-JAN-
2001','dd-MON-yyyy'))
14 , partition p_2001 values less than (to_date('01-JAN-
2002','dd-MON-yyyy'))
15 , partition p_2002 values less than (to_date('01-JAN-
2003','dd-MON-yyyy'))
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

16 , partition p_2003 values less than (to_date('01-JAN-


2004','dd-MON-yyyy'))
17 , partition p_2004 values less than (to_date('01-JAN-
2005','dd-MON-yyyy'))
18 , partition p_2005 values less than (to_date('01-JAN-
2006','dd-MON-yyyy'))
19 )
20 /
ble
Table created.
fe r a
ans
SQL>
n - t r
o
partitions. s an
8) Execute the query_dict_6.sql script to view information about the range

r ) ha deฺ
SQL>
m ฺa Gui
SQL> @query_dict_6
SQL> set echo on n ฺ co ent
SQL> set pagesize 2000
@ ao Stud
SQL> set long 10000 ille is
z t h
SQL> set linesize
c
SQL> set feedbacke loฺ200
on u se
a rpartition_name
to
SQL> column
SQL>lle
m
( high_value
column e n s e format a25
format a85
l o Zi REM lic
SQL>
rc e SQL> REM Interval Partitioning
Ma SQL> REM 7.take a standard range partitioned table and extend
it to an interval partitioned table. This demonstrates the
migration path to this new functionality.
SQL> REM
SQL> set echo on
SQL> -- show the list of partitions
SQL> select partition_name, high_value
2 from user_tab_partitions
3 where table_name = 'HISTORICAL_NEWSALES'
4 order by partition_position
5 /

PARTITION_NAME HIGH_VALUE
------------------------- ------------------------------------
-------------------------------------------------
P_PREVIOUS_CENTURY TO_DATE(' 2000-01-01 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
P_2000 TO_DATE(' 2001-01-01 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')

Oracle Database 11g: New Features for Administrators A - 84


Practice 6-2: Using Interval Partitioning (continued)
P_2001 TO_DATE(' 2002-01-01 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
P_2002 TO_DATE(' 2003-01-01 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
P_2003 TO_DATE(' 2004-01-01 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

P_2004 TO_DATE(' 2005-01-01 00:00:00',


'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
P_2005 TO_DATE(' 2006-01-01 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')

7 rows selected.

SQL>

9) Execute the insert_histnewsales_row_1.sql script to insert a row into the ble


fe r a
HISTORICAL_NEWSALES table. The insert fails because the partitioned table is not
s
currently an interval-partitioned table.
- t r an
o n
SQL>
SQL> @insert_histnewsales_row_1 s an
SQL> set echo on
r ) ha deฺ
SQL> set pagesize 2000
m ฺa Gui
SQL> set long 10000
n ฺ co ent
SQL> set linesize 200
SQL> set feedback on @ ao Stud
i l le this
SQL> column partition_name format a25
z
c e loฺ use
SQL> column high_value format a85
a r
SQL> REM Interval Partitioning
to
m e
SQL> REM 7.take a standard range partitioned table and extend
l l e ( icens
it to an interval partitioned table. This demonstrates the
i
el oZ l
migration path to this new functionality.

arc
SQL> REM
M SQL> set echo on
SQL> -- try to insert a new row in 2006 (THIS WILL FAIL)
SQL> insert into historical_newsales
2 values (11160,17450,to_date('02-jan-2006','dd-mon-
yyyy'),'I',9999,19,798)
3 /
insert into historical_newsales
*
ERROR at line 1:
ORA-14400: inserted partition key does not map to any
partition

SQL>

10) Execute the alter_hist_newsales.sql script to change the partitioned table to


an interval-partitioned table.
SQL>

Oracle Database 11g: New Features for Administrators A - 85


Practice 6-2: Using Interval Partitioning (continued)
SQL> @alter_hist_newsales
SQL> set echo on
SQL> set pagesize 2000
SQL> set long 10000
SQL> set linesize 200
SQL> set feedback on
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> column partition_name format a25


SQL> column high_value format a85
SQL> REM
SQL> REM 7.take a standard range partitioned table and extend
it to an interval partitioned table. This demonstrates the
migration path to this new functionality.
SQL> REM
SQL> set echo on
SQL> -- change the partitioned table to become interval
ble
partitioned
fe r a
SQL> alter table historical_newsales
ans
2 set interval (NUMTOYMINTERVAL(1, 'YEAR'))
3 / n - t r
a no
Table altered.
h a s ฺ
SQL> ฺ a r) uide
ฺ c om ent G
the table again. a on tud script to try to insert a row into
11) Execute the insert_histnewsales_row_2.sql

l l e@ is S
i
ฺz se th
SQL> @insert_histnewsales_row_2
SQL> set echo on l o
a
SQL> set pagesizerce 2000 t o u
SQL> set
l e se
(mlongen10000
SQL> l
Zi set linesize
lic 200
l oSQL> set feedback on
rce SQL> column partition_name format a25
Ma SQL> column high_value format a85
SQL> REM
SQL> REM Interval Partitioning
SQL> REM
SQL> set echo on
SQL> -- try to insert a new row in 2006 again (NOW IT WILL
SUCCEED)
SQL> insert into historical_newsales
2 values (11160,17450,to_date('02-jan-2006','dd-mon-
yyyy'),'I',9999,19,798)
3 /

1 row created.
SQL>
SQL> commit
2 /
Commit complete.

Oracle Database 11g: New Features for Administrators A - 86


Practice 6-2: Using Interval Partitioning (continued)
12) Execute the query_dict_7.sql script to view information about the partitions.
Exit from SQL*Plus.
SQL> @query_dict_7
SQL> set echo on
SQL> set pagesize 2000
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> set long 10000


SQL> set linesize 200
SQL> set feedback on
SQL> column partition_name format a25
SQL> column high_value format a85
SQL> REM
SQL> REM Interval Partitioning
SQL> REM
SQL> set echo on
SQL> -- show the list of partitions again ble
SQL> select partition_name, high_value fe r a
2 from user_tab_partitions ans
3 where table_name = 'HISTORICAL_NEWSALES' n - t r
4 order by partition_position
a no
5 /
h a s ฺ
PARTITION_NAME HIGH_VALUE ฺa
r) uide
ฺ c om ent G
------------------------- ------------------------------------
on tu2000-01-01
d
-------------------------------------------------
a
P_PREVIOUS_CENTURY
l e@ TO_DATE('
i s S 00:00:00',
'SYYYY-MM-DD HH24:MI:SS',l
ฺzi seTO_DATE('
th
'NLS_CALENDAR=GREGORIAN')
P_2000
e l o u 2001-01-01 00:00:00',
a c
'SYYYY-MM-DDr HH24:MI:SS',
to 'NLS_CALENDAR=GREGORIAN')
P_2001 (m
n s e TO_DATE(' 2002-01-01 00:00:00',
l l e
'SYYYY-MM-DD eHH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
l o Zi
P_2002 lic TO_DATE(' 2003-01-01 00:00:00',
rc e 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
Ma P_2003
'SYYYY-MM-DD
TO_DATE(' 2004-01-01 00:00:00',
HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
P_2004 TO_DATE(' 2005-01-01 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
P_2005 TO_DATE(' 2006-01-01 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
SYS_P27 TO_DATE(' 2007-01-01 00:00:00',
'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')

8 rows selected.

SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$

Oracle Database 11g: New Features for Administrators A - 87


Practice 6-3: Using Extended Composite Partitioning
Composite range-range partitioning enables logical range partitioning along two
dimensions; for example, partition by ORDER_DATE and range subpartition by
SHIPPING_DATE. Composite range-range partitioning provides an additional modeling
strategy to map a business need to the partitioning of an object.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

In this example, the service-level agreement with the customer states that an order will be
delivered in the calendar month after the order was placed. The following types of orders
are identified:
EARLY: Orders that are delivered before the middle of the next month after the order
was placed. These orders likely exceed customers’ expectations.
AGREED: Orders that are delivered in the calendar month after the order was placed (but
not early orders).
LATE: Orders that were only delivered starting the second calendar month after the order e
was placed.
r a bl
It is assumed that your current directory is /home/oracle/solutions/part. s fe
r an
Perform the following steps to create a range-range composite partitioned table to satisfy
- t
the business needs:
no n
1) Connect as the SH user and execute the create_shipments.sql
a
s ฺscript to create
h a
r) utable
the SHIPMENTS table as a range-range composite partitioned
ฺ a ideby ORDER_DATE
and SHIPDATE.
ฺ c om ent G
$ . oraenv
a on tud
ORACLE_SID = [db10g] ? orcl
l l e@ is S
i
ฺz se th
$ cd /home/oracle/solutions/part
$ l o
$ sqlplus sh/sh
a rce to u
SQL*Plus:
l e (mRelease
e n se 11.2.0.1.0 Production on Wed Sep 30 12:56:55
Zi
2009 l lic
l o
rce Copyright (c) 1982, 2009, Oracle. All rights reserved.
Ma Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL>
SQL> @create_shipments
SQL> set echo on
SQL> set pagesize 2000
SQL> set long 10000
SQL> set linesize 200
SQL> set feedback on
SQL> column partition_name format a25
SQL> column high_value format a85
SQL> REM New extended composite partitions
SQL> REM 1.Recap the concept of composite partitioned tables
SQL> REM 2.Introduce the new extension based on business cases
(e.g. RANGE-RANGE on oder_date/ship_date

Oracle Database 11g: New Features for Administrators A - 88


Practice 6-3: Using Extended Composite Partitioning (continued)
SQL> REM 3.Demonstrate the data placement for a business
scenario
SQL> REM
SQL> REM EXTENDED COMPOSITE PARTITIONING
SQL> REM
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> drop table shipments


2 /
drop table shipments
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL>
SQL> set echo on
ble
SQL>
fe r a
SQL> -- create table shipments, composite partition by
ans
order_date, shipdate
SQL> n - t r
o
SQL> create table shipments
s an
2 ( order_id number not null
3 , order_date date not null r ) ha deฺ
4 , ship_date date not null m ฺa Gui
5 , customer_id number not null
n ฺ co ent
6 , sales_amount number not null
7 ) @ ao Stud
i l le this
8 partition by range (order_date)
z
c e loฺ use
9 subpartition by range (ship_date)
r to
10 ( partition p_2006_jul values
a
m e
11
i
12 l l e ( icens
less than (to_date('01-AUG-2006','dd-MON-yyyy'))
( subpartition p_2006_jul_early values
el oZ13
l
less than (to_date('15-AUG-2006','dd-MON-yyyy'))

Marc 14
15
, subpartition p_2006_jul_agreed values
less than (to_date('01-SEP-2006','dd-MON-yyyy'))
16 , subpartition p_2006_jul_late values less than
(maxvalue)
17 )
18 , partition p_2006_aug values
19 less than (to_date('01-SEP-2006','dd-MON-yyyy'))
20 ( subpartition p_2006_aug_early values
21 less than (to_date('15-SEP-2006','dd-MON-yyyy'))
22 , subpartition p_2006_aug_agreed values
23 less than (to_date('01-OCT-2006','dd-MON-yyyy'))
24 , subpartition p_2006_aug_late values less than
(maxvalue)
25 )
26 , partition p_2006_sep values
27 less than (to_date('01-OCT-2006','dd-MON-yyyy'))
28 ( subpartition p_2006_sep_early values
29 less than (to_date('15-OCT-2006','dd-MON-yyyy'))
30 , subpartition p_2006_sep_agreed values
31 less than (to_date('01-NOV-2006','dd-MON-yyyy'))

Oracle Database 11g: New Features for Administrators A - 89


Practice 6-3: Using Extended Composite Partitioning (continued)
32 , subpartition p_2006_sep_late values less than
(maxvalue)
33 )
34 , partition p_2006_oct values
35 less than (to_date('01-NOV-2006','dd-MON-yyyy'))
36 ( subpartition p_2006_oct_early values
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

37 less than (to_date('15-NOV-2006','dd-MON-yyyy'))


38 , subpartition p_2006_oct_agreed values
39 less than (to_date('01-DEC-2006','dd-MON-yyyy'))
40 , subpartition p_2006_oct_late values less than
(maxvalue)
41 )
42 , partition p_2006_nov values
43 less than (to_date('01-DEC-2006','dd-MON-yyyy'))
44 ( subpartition p_2006_nov_early values
ble
45 less than (to_date('15-DEC-2006','dd-MON-yyyy'))
fe r a
46 , subpartition p_2006_nov_agreed values
ans
47
48
less than (to_date('01-JAN-2007','dd-MON-yyyy'))
, subpartition p_2006_nov_late values less than n - t r
o
(maxvalue)
s an
49 )
50 , partition p_2006_dec values r ) ha deฺ
51 ฺa Gui
less than (to_date('01-JAN-2007','dd-MON-yyyy'))
m
52 co ent
( subpartition p_2006_dec_early values
n ฺ
53
54 @ ao Stud
less than (to_date('15-JAN-2007','dd-MON-yyyy'))
, subpartition p_2006_dec_agreed values
55 i l le this
less than (to_date('01-FEB-2007','dd-MON-yyyy'))
z
56 loฺ use
, subpartition p_2006_dec_late values less than
c e
(maxvalue) a r to
m e
57
i l
58 ) l
)
e ( icens
el oZ59 /
l
Marc Table created.

SQL>

2) Use the insert_shipments.sql script to insert rows into the SHIPMENTS table.
SQL>
SQL> @insert_shipments
SQL> set echo on
SQL> set pagesize 2000
SQL> set long 10000
SQL> set linesize 200
SQL> set feedback on
SQL> column partition_name format a25
SQL> column high_value format a85
SQL>
SQL> REM New extended composite partitions
SQL> REM 1.Recap the concept of composite partitioned tables

Oracle Database 11g: New Features for Administrators A - 90


Practice 6-3: Using Extended Composite Partitioning (continued)
SQL> REM 2.Introduce the new extension based on business cases
(e.g. RANGE-RANGE on oder_date/ship_date
SQL> REM 3.Demonstrate the data placement for a business
scenario
SQL> REM
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> REM
SQL> REM EXTENDED COMPOSITE PARTITIONING
SQL> REM
SQL>
SQL> set echo on
SQL> -- insert some data into the shipments table
SQL>
SQL> insert into shipments select o.order_id
2 , to_date('12-oct-2006','dd-mon-yyyy')
ble
3 , to_date('12-oct-2006','dd-mon-yyyy') + trunc(70 *
fe r a
abs(dbms_random.value)) -- generate some early, agreed, late
ans
orders
4 , nvl(o.sales_rep_id,trunc(105 * dbms_random.value)) n - t r
o
5 , sum(oi.unit_price * oi.quantity)
s an
6 from oe.orders o
7 , oe.order_items oi r ) ha deฺ
8 where o.order_id = oi.order_id m ฺa Gui
9 group by o.order_id
n ฺ co ent
10 , o.sales_rep_id
11 / @ ao Stud
z i l le this
105 rows created.
c e loฺ use
a r to
SQL> m
( ens e
i l l ecommit
l o Z2 / lic
SQL>

rc e
Ma Commit complete.

SQL>

3) Execute the count_shipments.sql script to view how data was distributed in the
SHIPMENTS table. Note: Your results may vary because of the random generation of
values during the INSERT statement in the previous step.
SQL> @count_shipments
SQL> set echo on
SQL> set pagesize 2000
SQL> set long 10000
SQL> set linesize 200
SQL> set feedback on
SQL> column partition_name format a25
SQL> column high_value format a85
SQL>
SQL> REM New extended composite partitions
SQL> REM 1.Recap the concept of composite partitioned tables

Oracle Database 11g: New Features for Administrators A - 91


Practice 6-3: Using Extended Composite Partitioning (continued)
SQL> REM 2.Introduce the new extension based on business cases
(e.g. RANGE-RANGE on oder_date/ship_date
SQL> REM 3.Demonstrate the data placement for a business
scenario
SQL> REM
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> REM
SQL> REM EXTENDED COMPOSITE PARTITIONING
SQL> REM
SQL> set echo on
SQL>
SQL> -- show how data was distributed for this business case
SQL>
SQL>
SQL> select count(1) from shipments subpartition
ble
(P_2006_OCT_EARLY) ;
fe r a
ans
COUNT(1)
---------- n - t r
o
42
s an
1 row selected. r ) ha deฺ
m ฺa Gui
SQL> select count(1) from shipments
n ฺ co subpartition
e n t
(P_2006_OCT_AGREED) ;
@ ao Stud
COUNT(1) z i l le this
----------
c e loฺ use
30 ar to
m
( ens e
i l l eselected.
l o
1 row
Z lic
rc e SQL> select count(1) from shipments subpartition
Ma (P_2006_OCT_LATE) ;

COUNT(1)
----------
33

1 row selected.

SQL>
SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$

Oracle Database 11g: New Features for Administrators A - 92


Practice 6-4: Using Virtual Column–Based Partitioning
It is assumed that your current directory is /home/oracle/solutions/part.

You can use virtual column partitioning to partition key columns defined on virtual
columns of a table. Virtual columns are defined by evaluating an expression. Virtual
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

columns can be defined at table creation or during modification time. Frequently,


business requirements to logically partition objects do not match existing columns in a
one-to-one manner. Oracle partitioning has been enhanced to allow a partitioning strategy
being defined on virtual columns, thus enabling a more comprehensive match of the
business requirements.

In this example, employees’ categories are:

Poor: Total salary (salary + commission) is less than 1000 ble


Not doing too bad: Salary is between 1000 and 3000 fe r a
On target: Salary of 3000 ans
n - t r
Filthy rich: Salary > 3000
a no
a s theฺfollowing steps:
To understand the use of virtual column-based partitioning, perform
h
1) Execute the create_employees.sql script to ฺ a
create u ide table with a
r)the EMPLOYEES
virtual column. ฺ c om ent G
$ . oraenv a on tud
ORACLE_SID = [db10g]il? l e@
orcl his
S
e l oฺz use t
$ cd /home/oracle/solutions/part
$
a rc to
$ sqlplus m sh/sh e
l
SQL*Plus:
i l e ( iRelease
c e ns 11.2.0.1.0 Production on Wed Sep 30 13:03:10
l o Z
2009 l
rce
Ma Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL>
SQL> @create_employees
SQL> set echo on
SQL> set pagesize 2000
SQL> set long 10000
SQL> set linesize 200
SQL> set feedback on
SQL> column partition_name format a25
SQL> column high_value format a85
SQL>
SQL> REM
SQL> REM Virtual column-based partitioning

Oracle Database 11g: New Features for Administrators A - 93


Practice 6-4: Using Virtual Column–Based Partitioning
(continued)
SQL> REM 1.Introduce the concept of a virtual column (e.g.
Extract the month out of a date)
SQL> REM 2.Create a simple virtual column and select from it
(you can also highlight that you can collect stats on such a
column)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> REM 3.Create a virtual column-based partitioned table


(for demonstration purposes this can be something goofy like
adding two column values or so)
SQL> REM 4.insert some data and show the data placement based
on the virtual column definitions
SQL> REM
SQL>
SQL> set echo on
SQL> drop table employees
ble
2 /
fe r a
drop table employees
ans
*
n - t r
ERROR at line 1: o
ORA-00942: table or view does not exist
s an
r ) ha deฺ
SQL>
SQL> drop table product_returns m ฺa Gui
2 / n ฺ co ent
drop table product_returnsao
@ S t ud
*
ERROR at line 1: ฺzi
lle this
ORA-00942: table
c e loor view
u sedoes not exist
a r to
SQL> e ( m ns e
i l l
Z -- create
SQL> c e
li a table with a virtual column
e l oSQL>
rc
Ma
SQL>
SQL>
SQL> create table employees
2 ( employee_id number(6) not null
3 , first_name varchar2(20)
4 , last_name varchar2(25)
5 , email varchar2(25)
6 , phone_number varchar2(20)
7 , hiredate date
8 , job_id varchar2(10)
9 , salary number(8,2)
10 , commission_pct number(2,2)
11 , manager_id number(6)
12 , department_id number(4)
13 , well_off as (case sign(1000 - (salary +
nvl(commission_pct,0)))
14 when 1 then 'poor'
15 else case sign(3000 - (salary +
nvl(commission_pct,0)))

Oracle Database 11g: New Features for Administrators A - 94


Practice 6-4: Using Virtual Column–Based Partitioning
(continued)
16 when 1 then 'not doing too bad'
17 when 0 then 'on target'
18 else 'filthy rich'
19 end
20 end
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

21 ) virtual
22 )
23 /

Table created.

SQL>

2) Execute the insert_employees.sql script to INSERT rows into the EMPLOYEES


ble
table.
fe r a
SQL> @insert_employees ans
SQL> set echo on n - t r
o
SQL> set pagesize 2000
SQL> set long 10000 s an
SQL> set linesize 200 r ) ha deฺ
SQL> set feedback on
m ฺa Gui
SQL> column partition_name format a25
n ฺ co ent
SQL> column high_value format a85
SQL> @ ao Stud
SQL> z i l le this
SQL> REM
c e loฺ use
r to
SQL> REM Virtual column-based partitioning
a
m e
e ( icens
SQL> REM 1.Introduce the concept of a virtual column (e.g.
i l l
Extract the month out of a date)
el oZ l
SQL> REM 2.Create a simple virtual column and select from it

Marc (you can also highlight that you can collect stats on such a
column)
SQL> REM 3.Create a virtual column-based partitioned table
(for demonstration purposes this can be something goofy like
adding two column values or so)
SQL> REM 4.insert some data and show the data placement based
on the virtual column definitions
SQL> REM
SQL>
SQL> set echo on
SQL> -- insert data into the table
SQL>
SQL>
SQL> insert into employees
2 (employee_id, first_name, last_name, email, phone_number,
hiredate, job_id, salary, commission_pct, manager_id,
department_id)
3 select employee_id, first_name, last_name, email,
phone_number, hire_date, job_id, salary, commission_pct,
manager_id, department_id from hr.employees

Oracle Database 11g: New Features for Administrators A - 95


Practice 6-4: Using Virtual Column–Based Partitioning
(continued)
4 /

107 rows created.

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> commit
2 /

Commit complete.

SQL>

3) Execute the select_employees.sql script to query the EMPLOYEES table.


SQL> @select_employees ble
SQL> set echo on fe r a
SQL> set pagesize 2000 ans
SQL> set long 10000 n - t r
o
SQL> set linesize 200
SQL> set feedback on s an
SQL> column partition_name format a25
r ) ha deฺ
SQL> column high_value format a85
m ฺa Gui
SQL> column name format a45
n ฺ co ent
SQL>
SQL> REM @ ao Stud
i l le this
SQL> REM Virtual column-based partitioning
z
c e loฺ use
SQL> REM 1.Introduce the concept of a virtual column (e.g.
a r
Extract the month out of a date)
to
m e
SQL> REM 2.Create a simple virtual column and select from it
l l e ( icens
(you can also highlight that you can collect stats on such a
i
el oZ
column) l
arc
SQL> REM 3.Create a virtual column-based partitioned table
M (for demonstration purposes this can be something goofy like
adding two column values or so)
SQL> REM 4.insert some data and show the data placement based
on the virtual column definitions
SQL> REM
SQL> set echo on
SQL> -- select from the virtual column
SQL>
SQL>
SQL> select first_name ||' '|| last_name name, well_off,
salary + nvl(commission_pct,0) total_salary
2 from employees
3 /

NAME WELL_OFF TOTAL_SALARY


------------------------------- ----------------- ------------
Donald OConnell not doing too bad 2600
Douglas Grant not doing too bad 2600
Jennifer Whalen filthy rich 4400

Oracle Database 11g: New Features for Administrators A - 96


Practice 6-4: Using Virtual Column–Based Partitioning
(continued)
Michael Hartstein filthy rich 13000

Vance Jones not doing too bad 2800
Alana Walsh filthy rich 3100
Kevin Feeney on target 3000
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

107 rows selected.

SQL>

4) Execute the create_prod_ret.sql script to create the PRODUCT_RETURNS table


with a virtual column, which is used to partition the table.
SQL> e
SQL> @create_prod_ret
r a bl
SQL> set echo on s fe
SQL> set pagesize 2000
- t r an
SQL> set long 10000
o n
SQL> set linesize 200
SQL> set feedback on s an
SQL> column partition_name format a25 r ) ha deฺ
SQL> column high_value format a85
m ฺa Gui
SQL>
n ฺ co ent
SQL>
SQL> @ ao Stud
SQL> REM z i l le this
c e loฺ use
SQL> REM Virtual column-based partitioning
r to
SQL> REM 1.Introduce the concept of a virtual column (e.g.
a
m e
e ( icens
Extract the month out of a date)
i l l
SQL> REM 2.Create a simple virtual column and select from it
el oZ l
(you can also highlight that you can collect stats on such a

Marc column)
SQL> REM 3.Create a virtual column-based partitioned table
(for demonstration purposes this can be something goofy like
adding two column values or so)
SQL> REM 4.insert some data and show the data placement based
on the virtual column definitions
SQL> REM
SQL> set echo on
SQL> -- now, create a table product returns with a virtual
column, and partition by this column
SQL>
SQL>
SQL> create table product_returns
2 ( order_id number not null
3 , product_id number not null
4 , customer_id number not null
5 , quantity number not null
6 , unit_price number not null
7 , total_value as (quantity * unit_price) virtual
8 )

Oracle Database 11g: New Features for Administrators A - 97


Practice 6-4: Using Virtual Column–Based Partitioning
(continued)
9 partition by range(total_value)
10 ( partition dont_even_bother values less than (100)
11 , partition perhaps_the_accountant_cares values less than
(1000)
12 , partition now_it_becomes_worrying values less than
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

(10000)
13 , partition oops_somebody_be_fired values less than
(100000)
14 , partition this_means_bankruptcy values less than
(maxvalue)
15 )
16 /

Table created.
ble
fe r a
SQL>
ans
n - t r
5) Execute the insert_prod_ret.sql script to insert rows into the o
PRODUCT_RETURNS table.
s an
SQL> @insert_prod_ret r ) ha deฺ
SQL> set echo on
m ฺa Gui
SQL> set pagesize 2000
n ฺ co ent
SQL> set long 10000
SQL> set linesize 200 @
ao Stud
SQL> set feedback on z i l le this
c e loฺ use format a25
SQL> column partition_name
SQL> columnarhigh_value
to format a85
m e
SQL>
i
SQL> l l e ( icens
l o Z
SQL> l
rc e SQL> REM
Ma SQL> REM Virtual column-based partitioning
SQL> REM 1.Introduce the concept of a virtual column (e.g.
Extract the month out of a date)
SQL> REM 2.Create a simple virtual column and select from it
(you can also highlight that you can collect stats on such a
column)
SQL> REM 3.Create a virtual column-based partitioned table
(for demonstration purposes this can be something goofy like
adding two column values or so)
SQL> REM 4.insert some data and show the data placement based
on the virtual column definitions
SQL> REM
SQL>
SQL> set echo on
SQL> -- insert some data into the table
SQL>
SQL>
SQL> set feedback off
SQL>

Oracle Database 11g: New Features for Administrators A - 98


Practice 6-4: Using Virtual Column–Based Partitioning
(continued)
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (1, 36, 109, 10,
120) ;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (2, 46, 129, 20, 10)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (3, 73, 159, 15, 1)
;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (4,136,1109, 16, 2)
;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (5, 27, 309, 20,
ble
420) ;
fe r a
SQL> insert into product_returns (order_id, product_id,
ans
customer_id, quantity, unit_price) values (6, 96, 129, 10,
n - t r
1020) ; o
SQL> insert into product_returns (order_id, product_id,
s an
r ) ha deฺ
customer_id, quantity, unit_price) values (7, 39, 104, 1,
12000) ;
m ฺa Gui
SQL> insert into product_returns (order_id, product_id,
ฺ co ent
customer_id, quantity, unit_price) values (8,436,6109, 8, 200)
n
;
@ ao Stud
z i l le this
SQL> insert into product_returns (order_id, product_id,

2400) ; c e loฺ use


customer_id, quantity, unit_price) values (9,789, 709, 2,

a r to
SQL> insert into product_returns (order_id, product_id,
m e
i l l e ( icens
customer_id, quantity, unit_price) values (11,276, 809,9,

el oZ
10000) ; l
SQL> insert into product_returns (order_id, product_id,

Marc customer_id, quantity, unit_price) values (12, 34, 199, 10,


20000) ;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (15, 24, 100,5, 10)
;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (17, 76,1109, 1, 20)
;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (19, 55, 209, 1,
300000) ;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (21, 76, 139, 1, 10)
;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (31, 90, 104, 2,
4020) ;

Oracle Database 11g: New Features for Administrators A - 99


Practice 6-4: Using Virtual Column–Based Partitioning
(continued)
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (51,284,5109, 9, 60)
;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (1,912, 169, 1,
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

10980) ;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (31,536, 179, 2, 60)
;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (13,752, 108, 1,
400) ;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (12,986,1109, 3,
ble
700) ;
fe r a
SQL> insert into product_returns (order_id, product_id,
ans
customer_id, quantity, unit_price) values (1, 39, 129, 4, 6) ;
n - t r
SQL> insert into product_returns (order_id, product_id, o
an
customer_id, quantity, unit_price) values (1, 32, 103, 1, 30)
s
;
r ) ha deฺ
m ฺa Gui
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (12, 34, 104, 1,
98710) ; n ฺ co ent
ao Stud
SQL> insert into product_returns (order_id, product_id,
@
z i l le this
customer_id, quantity, unit_price) values (1,173,6109, 1,
9650) ;
e loฺ use
SQL> insert into product_returns (order_id, product_id,
c
a r to
customer_id, quantity, unit_price) values (17,853,7109, 1, 60)
m e
;
i l l e ( icens
el oZ l
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (19,981, 809, 5, 80)

Marc ;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (1, 84, 103, 16,
1000) ;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (1, 21,2109, 1000,
90) ;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (13,782,2359, 102,
1850) ;
SQL> insert into product_returns (order_id, product_id,
customer_id, quantity, unit_price) values (1,941,5309, 10, 40)
;
SQL> commit ;
SQL>

6) Execute the select_prod_return.sql script to query the PRODUCT_RETURNS


table.
SQL> @select_prod_return

Oracle Database 11g: New Features for Administrators A - 100


Practice 6-4: Using Virtual Column–Based Partitioning
(continued)
SQL> set echo on
SQL> set pagesize 2000
SQL> set long 10000
SQL> set linesize 200
SQL> set feedback on
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> column partition_name format a25


SQL> column high_value format a85
SQL>
SQL>
SQL>
SQL> REM
SQL> REM Virtual column-based partitioning
SQL> REM 1.Introduce the concept of a virtual column (e.g.
Extract the month out of a date)
ble
SQL> REM 2.Create a simple virtual column and select from it
fe r a
(you can also highlight that you can collect stats on such a
ans
column)
n - t r
SQL> REM 3.Create a virtual column-based partitioned table o
an
(for demonstration purposes this can be something goofy like
s
adding two column values or so)
r ) ha deฺ
on the virtual column definitions m ฺa Gui
SQL> REM 4.insert some data and show the data placement based

SQL> REM n ฺ co ent


SQL> set feedback on
@ ao Stud
SQL> set echo on
z i l le this
SQL> c e loฺ use
SQL> -- select from the different partitions

a r to
SQL> select order_id, quantity, unit_price, total_value
m e
i l l e ( icens
2 from product_returns partition (dont_even_bother)

el oZ 4 /
l
3 order by total_value

Marc ORDER_ID QUANTITY UNIT_PRICE TOTAL_VALUE


---------- ---------- ---------- -----------
21 1 10 10
3 15 1 15
17 1 20 20
1 4 6 24
1 1 30 30
4 16 2 32
15 5 10 50
17 1 60 60

8 rows selected.

SQL>
SQL> select order_id, quantity, unit_price, total_value
2 from product_returns partition
(perhaps_the_accountant_cares)
3 order by total_value

Oracle Database 11g: New Features for Administrators A - 101


Practice 6-4: Using Virtual Column–Based Partitioning
(continued)
4 /

ORDER_ID QUANTITY UNIT_PRICE TOTAL_VALUE


---------- ---------- ---------- -----------
31 2 60 120
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

2 20 10 200
1 10 40 400
13 1 400 400
19 5 80 400
51 9 60 540

6 rows selected.

SQL>
ble
SQL> select order_id, quantity, unit_price, total_value
fe r a
2 from product_returns partition (now_it_becomes_worrying)
ans
3 order by total_value
n - t r
4 / o
s an
ORDER_ID QUANTITY UNIT_PRICE TOTAL_VALUE
r ) ha deฺ
---------- ---------- ---------- -----------
1 10 120 m
ฺa 1200 G ui
8 8 200
n ฺ co en1600t
12 3
@ ao700Stud 2100
9 2 le is
2400 4800
z i l t h
31
5 e l oฺ 20 use 420
2 4020 8040
8400
1 ar
c t o
1 9650 9650
( m s e
7Zrows l cen
ille selected.
i
rc elo
Ma
SQL>
SQL> select order_id, quantity, unit_price, total_value
2 from product_returns partition (oops_somebody_be_fired)
3 order by total_value
4 /

ORDER_ID QUANTITY UNIT_PRICE TOTAL_VALUE


---------- ---------- ---------- -----------
6 10 1020 10200
1 1 10980 10980
7 1 12000 12000
1 16 1000 16000
11 9 10000 90000
1 1000 90 90000
12 1 98710 98710

7 rows selected.

SQL>

Oracle Database 11g: New Features for Administrators A - 102


Practice 6-4: Using Virtual Column–Based Partitioning
(continued)
SQL> select order_id, quantity, unit_price, total_value
2 from product_returns partition (this_means_bankruptcy)
3 order by total_value
4 /
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ORDER_ID QUANTITY UNIT_PRICE TOTAL_VALUE


---------- ---------- ---------- -----------
13 102 1850 188700
12 10 20000 200000
19 1 300000 300000

3 rows selected.

SQL> ble
fe r a
s
7) Execute the xplan_prod_ret.sql script to show partition pruning for queries that
an
use the expression that defines the virtual column. Exit from SQL*Plus.
n - t r
o
SQL> @xplan_prod_ret
SQL> set echo on s an
SQL> set pagesize 2000 r ) ha deฺ
SQL> set long 10000
m ฺa Gui
SQL> set linesize 200
n ฺ co ent
SQL> set feedback on
@ ao Stud
SQL> column partition_name format a25
i l le this
SQL> column high_value format a85
z
SQL>
c e loฺ use
SQL>
a r to
m e
e ( icens
SQL>
i l l
SQL> REM
el oZ l
SQL> REM Virtual column-based partitioning

Marc SQL> REM 1.Introduce the concept of a virtual column (e.g.


Extract the month out of a date)
SQL> REM 2.Create a simple virtual column and select from it
(you can also highlight that you can collect stats on such a
column)
SQL> REM 3.Create a virtual column-based partitioned table
(for demonstration purposes this can be something goofy like
adding two column values or so)
SQL> REM 4.insert some data and show the data placement based
on the virtual column definitions
SQL> REM
SQL>
SQL>
SQL> -- show partition pruning for queries that use the
expression that defines the virtual column (remember you can
also gather statistics on the virtual column)
SQL>
SQL> set echo on
SQL> explain plan for select * from product_returns where
quantity * unit_price = 60000

Oracle Database 11g: New Features for Administrators A - 103


Practice 6-4: Using Virtual Column–Based Partitioning
(continued)
2 /

Explained.

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> select * from table(dbms_xplan.display) ;

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
--------------
Plan hash value: 2847847071
ble
fe r a
--------------------------------------------------------------
ans
--------------------------------------------
n - t r
| Id | Operation | Name | Rows | o
Bytes | Cost (%CPU)| Time | Pstart| Pstop |
s an
r ) ha deฺ
--------------------------------------------------------------
--------------------------------------------
| 0 | SELECT STATEMENT | m ฺa Gui
| 1 |
78 | 3 (0)| 00:00:01 | | n ฺ co ent
|
| 1 | PARTITION RANGE SINGLE|
@ ao Stud | 1 |
78 | 3 (0)| 00:00:01 |
z i l le this
4 | 4 |
|* 2 |
78 | 3 e loฺ use
TABLE ACCESS FULL
(0)| 00:00:01 |
c
| PRODUCT_RETURNS |
4 | 4 |
1 |

a r to
--------------------------------------------------------------
m e
i l l e ( icens
--------------------------------------------

el oZ l
Predicate Information (identified by operation id):

Marc ---------------------------------------------------

2 - filter("PRODUCT_RETURNS"."TOTAL_VALUE"=60000)

Note
-----
- dynamic sampling used for this statement

18 rows selected.

SQL>
SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining
and Real Application Testing options
$

Oracle Database 11g: New Features for Administrators A - 104


Practice 6-5: Using SQL Access Advisor for Partitioning Advice
In this practice, you use the SQL Access Advisor to get partitioning recommendations.
1) In a terminal session connected as the oracle user, change to the
/home/oracle/solutions/partadv directory and execute the
partadv_setup.sh script. This script builds an STS named SQLSET_TEST_500
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

owned by the SH user and makes a template that instructs the advisor to partition very
small tables such as those in the SH schema.
$ cd /home/oracle/solutions/partadv
$ ./partadv_setup.sh

SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 30 13:34:05


2009
ble
Copyright (c) 1982, 2009, Oracle. All rights reserved.
fe r a
an s
Connected to:
n - t r
Production a no
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -

h a s ฺ
With the Partitioning, Automatic Storage Management, OLAP,
a r) uide
Data Mining and Real Application Testing options


SQL> SQL> SQL> SQL> SQL> SQL>nSQL>comSQL>enSQL>
t G SQL> SQL> SQL>
SQL> Connected.
@ ao Stud
3 lle
SQL> SQL>
12 13 14
2
i 4 17t5his186 197 208 219 2210
15oฺz 16
11
23 24
25 26
l 29use30 31 32 33 34 35
27 ce28 36 37
38 a
39 m40
r 41 to42 43 44 45 46 47 48 49 50
51 le 52( 53 ns54
e 55 56 57 58 59 60 61 62 63
l
64Zi 65 li66
e
c 67 68 69 70 71 72 73 74 75 76
l o
e 77 78 79 80
rc
Ma Function created.

SQL> SQL> No errors.


SQL> SQL>
Synonym created.

SQL> SQL>
Grant succeeded.

SQL> SQL>
Grant succeeded.

SQL> SQL> Connected.


SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> 2 3
4 5 6 7 8 9 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24
PL/SQL procedure successfully completed.

SQL> SQL> SQL> SQL> SQL> SQL> SQL> DROP TABLE temp_table purge

Oracle Database 11g: New Features for Administrators A - 105


Practice 6-5: Using SQL Access Advisor for Partitioning Advice
(continued)
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Table created.

SQL> SQL> SQL> SQL> SQL> SQL> SQL>


System altered.

SQL> BEGIN dbms_sqltune.drop_sqlset('SQLSET_TEST_500'); END;

*
ERROR at line 1:
ble
ORA-13754: "SQL Tuning Set" "SQLSET_TEST_500" does not exist
fe r a
for user "SH".
an s
ORA-06512: at "SYS.DBMS_SQLTUNE_INTERNAL", line 11567
n - t r
ORA-06512: at "SYS.DBMS_SQLTUNE", line 3118
ORA-06512: at line 1 a no
h a s ฺ
SQL> SQL> 2 3 4 5 6
ฺ7ar) 8
u i d9e 10 11
12 13 14 15 16 17 18 m 20 G 21
25 26 27 28 29 30 n31ฺ co 1932 en33
t 34 22 35
23
36
24
37
PL/SQL procedure successfully a o completed.
t u d
l l e @ is S
SQL> SQL> SQL> i
ฺz se th
l o
COUNT(*)
---------- ar
ce to u
l e (m ense
499
Z i l l ic
l o
e 1 row selected.
rc
Ma SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL>
PL/SQL procedure successfully completed.

SQL>
PL/SQL procedure successfully completed.

SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> 2 3 4


PL/SQL procedure successfully completed.

SQL> SQL> 2 3 4 5 begin


*
ERROR at line 1:
ORA-13605: The specified task or object
SQLACCESS_PARTITION_SMALL does not exist for the current user.
ORA-06512: at "SYS.PRVT_ADVISOR", line 4635
ORA-06512: at "SYS.DBMS_ADVISOR", line 848
ORA-06512: at line 2

Oracle Database 11g: New Features for Administrators A - 106


Practice 6-5: Using SQL Access Advisor for Partitioning Advice
(continued)

SQL> SQL> 2 3 4 5 6 7 8 9 10
PL/SQL procedure successfully completed.

SQL> SQL> SQL> Connected.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> SQL>
Synonym dropped.

SQL>
Function dropped.

SQL> SQL>
Revoke succeeded.
ble
SQL> SQL>
fe r a
Grant succeeded.
ans
n - t r
SQL>
Grant succeeded. a no
h a s ฺ
SQL>
ฺ a r) uide
Grant succeeded.
ฺ c om ent G
a n uDatabase
oOracle d
SQL> SQL> Disconnected from
@ S t 11g Enterprise
Edition Release 11.2.0.1.0
z e -
t s
Production
ill Automatic
hi Storage Management, OLAP,
With the Partitioning, ฺ e
o Application
Data Mining and
r c elReal o us Testing options
$ a t
l e (m ense
2) Use l
ZiEnterpriselicManagerusing
Database Control to generate recommendations for
e l oSQLSET_TEST_500 SQLACCESS_PARTITION_SMALL template.
rc
Ma a) Log in to Enterprise Manager as the SH user with a password of SH. Connect as
Normal. If you were already logged in when executing step 1, log out and log in
again as Enterprise Manager caches the user’s privileges.
b) Click the Advisor Central link at the bottom of the page.
c) On the Advisor Central page, click the SQL Advisors link.
d) On the SQL Advisors page, click SQL Access Advisor.
e) On the SQL Access Advisor: Initial Options page, select “Inherit Options from a
previously saved Task or Template.” Wait for the page to refresh. In the Tasks
and Templates table, make sure that Templates Only is selected from the View
drop-down list. Select the SQLACCESS_PARTITION_SMALL template and
click Continue.
f) On the SQL Access Advisor: Workload Source page, select “Use an existing SQL
Tuning Set” and enter SH.SQLSET_TEST_500 in the SQL Tuning Set field.
Click Next.

Oracle Database 11g: New Features for Administrators A - 107


Practice 6-5: Using SQL Access Advisor for Partitioning Advice
(continued)
g) On the SQL Access Advisor: Recommendation Options page, make sure that the
following settings are chosen: Indexes, Materialized Views, and Partitioning;
and the Advisor should be in Comprehensive mode. Click Next.
h) On the SQL Access Advisor: Schedule page make sure that your schedule is set to
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Immediately and click Next.


i) On the Review page, click Submit.
j) Back to the Advisor Central page, wait for your task to complete.
k) After your task is completed, select the task name for the SQL Access Advisor in
the Results section of the Advisor Central page and click the View Result button.
l) When on the corresponding task page, click the Recommendations tab. Click
Recommendation Details to see partitioning recommendations. ble
fe r a
m) Click OK to return to the task results page.
ans
n) Click Database to return to the Database Home page. n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 108


Practices for Lesson 7

In this practice, you compare BasicFiles with SecureFiles.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 109


Practice 7-1: Using SecureFiles
In this practice, you explore the advantages of using SecureFiles for compression, data
encryption, and performance.

1) To set up your database and environment for SecureFiles, perform the following
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

steps:
a) Create a directory to store the Transparent Data Encryption (TDE) wallet. This is
required for the SecureFiles LOB encryption.
$ mkdir /u01/app/oracle/admin/orcl/wallet
$
b) Edit the
/u01/app/oracle/product/11.2.0/grid/network/admin/sqln ble
et.ora file to indicate the location of the TDE wallet by specifying the fe r a
ans
directory you created in the previous step. Add the following parameter to the
file: ENCRYPTION_WALLET_LOCATION= n - t r
(SOURCE=(METHOD=FILE)(METHOD_DATA= a no
(DIRECTORY=/u01/app/oracle/admin/orcl/wallet)))
h a s ฺ
ฺ a r) uide
$ cd /u01/app/oracle/product/11.2.0/grid/network/admin
$ vi sqlnet.ora
ฺ c om ent G
$ cat sqlnet.ora
a on tuFile:
d
# sqlnet.ora Network Configuration
@
le this S
i l
/u01/app/oracle/product/11.2.0/grid/network/admin/sqlnet.ora
z
c e loฺ uconfiguration
# Generated by Oracle se tools.
a r o
t (TNSNAMES, EZCONNECT)
m
NAMES.DIRECTORY_PATH=
( s e
Z i lle licen
el oADR_BASE = /u01/app/oracle
Marc ENCRYPTION_WALLET_LOCATION= (SOURCE=(METHOD=FILE)(METHOD_DATA=
(DIRECTORY=/u01/app/oracle/admin/orcl/wallet)))

2) Change to the /home/oracle/solutions/SecF directory. Using SQL*Plus,


connect to the database as SYS.
$ cd /home/oracle/solutions/SecF
$
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 1 07:32:51


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:

Oracle Database 11g: New Features for Administrators A - 110


Practice 7-1: Using SecureFiles (continued)
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

3) In your SQL*Plus session, execute the secf_setup.sql script. The first step is to
create an encryption key and store it in the TDE wallet. You will use this encryption
key later to encrypt the SecureFiles.
SQL> @secf_setup
Connected.
SQL> set serveroutput on
SQL> -- set verify on;
SQL> set term on; ble
SQL> set lines 200 fe r a
SQL> set pause on ans
SQL> n - t r
SQL> /*== Store the encryption key in the TDE wallet ==*/
a no
SQL> s ฺ
h a
SQL> alter system set wallet open identified by "welcome1";
ฺ a r) uide
alter system set wallet open identified by "welcome1"
*
ฺ c om ent G
ERROR at line 1:
ORA-28367: wallet does not exist a on tud
l l e @ is S
i
ฺz se th
SQL> l o
a r ce SET
SQL> ALTER SYSTEM
t o uENCRYPTION KEY AUTHENTICATED BY
2 lle
/
(m ense
"welcome1"

l o Zi lic
rc e System altered.
Ma SQL>
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
4) Press [Enter] to continue to the next step in the script. The next step in the script is to
create a database schema for this practice. The schema is called SF_DEMO. It is
granted the CONNECT and RESOURCE roles. It also requires the EXECUTE ANY
PROCEDURE and CREATE ANY DIRECTORY system privileges.
SQL>
SQL>
SQL> /*== Create a database account for this OBE ==*/
SQL>
SQL> DROP USER sf_demo CASCADE
2 /
DROP USER sf_demo CASCADE
*
ERROR at line 1:

Oracle Database 11g: New Features for Administrators A - 111


Practice 7-1: Using SecureFiles (continued)
ORA-01918: user 'SF_DEMO' does not exist

SQL>
SQL> CREATE USER sf_demo IDENTIFIED BY oracle_4U
2 DEFAULT TABLESPACE users
3 TEMPORARY TABLESPACE temp
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

4 QUOTA UNLIMITED ON users


5 /

User created.

SQL>
SQL> GRANT connect, resource TO sf_demo
2 /
ble
Grant succeeded.
fe r a
ans
SQL>
SQL> GRANT EXECUTE ANY PROCEDURE, CREATE ANY DIRECTORY TO n - t r
sf_demo a no
2 /
h a s ฺ
Grant succeeded. ฺ a r) uide
ฺ c om ent G
SQL> a on tud
SQL> pause Press [Enter]@
l e i s S
to continue...
i l h
oฺz use t
Press [Enter] to continue...
e l
c totothe next step in the script. Next, the script creates two 150
5) Press [Enter] to rcontinue
a
(m eThe
MB tablespaces. e tablespace will be used to store the LOB in
l e n sSECF_TBS1
l
ZiSecureFiles
BasicFiles lic format.
format, and the SECF_TBS2 tablespace will be used to store the LOB in the
e l onew Automatic Segment Space Management (ASSM) needs to be
rc enabled for the tablespace to support SecureFiles.
Ma
SQL>
SQL> /*== Create tablespaces to store the LOB tables ==*/
SQL> /*== ==*/
SQL> /*== Note that SecureFile LOB storage requires ASSM.==*/
SQL> /*== The segment allocation unit is 64MB. ==*/
SQL>
SQL> DROP TABLESPACE secf_tbs1 INCLUDING CONTENTS
2 /
DROP TABLESPACE secf_tbs1 INCLUDING CONTENTS
*
ERROR at line 1:
ORA-00959: tablespace 'SECF_TBS1' does not exist

SQL>
SQL> CREATE TABLESPACE secf_tbs1
2 DATAFILE '+DATA' SIZE 150M REUSE
3 EXTENT MANAGEMENT LOCAL
4 UNIFORM SIZE 64M

Oracle Database 11g: New Features for Administrators A - 112


Practice 7-1: Using SecureFiles (continued)
5 SEGMENT SPACE MANAGEMENT AUTO
6 /

Tablespace created.

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> DROP TABLESPACE secf_tbs2 INCLUDING CONTENTS


2 /
DROP TABLESPACE secf_tbs2 INCLUDING CONTENTS
*
ERROR at line 1:
ORA-00959: tablespace 'SECF_TBS2' does not exist

SQL>
SQL> CREATE TABLESPACE secf_tbs2
ble
2 DATAFILE '+DATA' SIZE 150M REUSE
fe r a
3 EXTENT MANAGEMENT LOCAL
ans
4
5
UNIFORM SIZE 64M
SEGMENT SPACE MANAGEMENT AUTO n - t r
6 / a no
h a s ฺ
Tablespace created.
ฺ a r) uide
SQL> ฺ c om ent G
SQL> pause Press [Enter] to a n ud
ocontinue...
Press [Enter] to continue... @ S t
z ill e t s
hi in the script. The rest of the script is to

lo us
6) Press [Enter] to continue to the e
next step
create objects a ceSF_DEMO
inrthe to schema. First a table called RESUMES is created. This
m e
table has a( BLOB column
i l l e icens (RESUME) that is stored in the BasicFiles format.
l o Z /*== lAs SF_DEMO, create a table with a LOB that uses
SQL>
rc e BasicFile LOB storage ==*/
Ma SQL>
SQL> connect sf_demo/oracle_4US
Connected.
SQL>
SQL> CREATE TABLE resumes
2 (id NUMBER, first_name VARCHAR2(15),
3 last_name VARCHAR2(40), resume BLOB)
4 LOB(resume) STORE AS BASICFILE
5 (TABLESPACE secf_tbs1)
6 /

Table created.

SQL>
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...

Oracle Database 11g: New Features for Administrators A - 113


Practice 7-1: Using SecureFiles (continued)
7) Press [Enter] to continue to the next step in the script. A DIRECTORY object is
required to store the path name of the MS Word files that will be retrieved and stored
in the LOB column. When prompted for the directory name, enter the full path
where you have the SQL scripts for this practice. For example, the path name may
be /home/oracle/solutions/SecF.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> /*== Create a DIRECTORY object. It is required for
accessing the MS Word files ==*/
SQL> /*== to be loaded into the LOB column. Enter the full
path to the files, omit ==*/
SQL> /*== the final "/" at the end.
==*/
SQL>
SQL> CREATE OR REPLACE DIRECTORY cwd AS '&directory_name';
ble
Enter value for directory_name: /home/oracle/solutions/SecF
fe r a
old 1: CREATE OR REPLACE DIRECTORY cwd AS '&directory_name'
an s
new 1: CREATE OR REPLACE DIRECTORY cwd AS
n - t r
'/home/oracle/solutions/SecF'
a no
Directory created.
h a s ฺ
ฺ a r) uide
SQL>
SQL> pause Press [Enter] to continue... ฺ c om ent G
Press [Enter] to continue... a on tud
S
@ stepisin the
lenext
8) Press [Enter] to continue z l
toithe h
t column, script. To read the MS Word files on
the file system and e l oฺthemuinsthe
store e LOB a procedure called
a r
LOADLOBFROMBFILE_PROC
c o
t is created. This procedure calls the DBMS_LOB package.
Note that ( m
this same n s e
procedure will be used for both BasicFiles as well as SecureFiles
i l l e i c e
l o Z storagelformats.
LOB
rc e SQL>
Ma SQL> /*== Create the procedure to read the MS Word files and
load them into the LOB column ==*/
SQL>
SQL> CREATE OR REPLACE PROCEDURE loadLOBFromBFILE_proc
(dest_loc IN OUT BLOB, file_name IN VARCHAR2)
2 IS
3 src_loc BFILE := BFILENAME('CWD', file_name);
4 amount INTEGER := 4000;
5 BEGIN
6
7 DBMS_LOB.OPEN(src_loc, DBMS_LOB.LOB_READONLY);
8 amount := DBMS_LOB.GETLENGTH(src_loc);
9 DBMS_LOB.LOADFROMFILE(dest_loc, src_loc, amount);
10 DBMS_LOB.CLOSE(src_loc);
11
12 END;
13 /

Procedure created.

Oracle Database 11g: New Features for Administrators A - 114


Practice 7-1: Using SecureFiles (continued)

SQL>
SQL> show errors
No errors.
SQL>
SQL> pause Press [Enter] to continue...
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Press [Enter] to continue...


9) Press [Enter] to continue to the next step in the script. To insert records into the
RESUMES table, including the LOB values, a procedure called WRITE_LOB is created.
This procedure calls the LOADLOBFROMBFILE_PROC procedure created in the
previous step.
SQL>
SQL> /*== Create the procedure to insert LOBs into the table e
==*/
r a bl
SQL> s fe
SQL> CREATE OR REPLACE PROCEDURE write_lob (p_file IN
- t r an
VARCHAR2)
o n
2 IS
3 i NUMBER; s an
4 fn VARCHAR2(15); r ) ha deฺ
5 ln VARCHAR2(40);
m ฺa Gui
6 b BLOB;
n ฺ co ent
7
8 BEGIN @ ao Stud
9 DBMS_OUTPUT.ENABLE; z i l le this
c e loฺ use
10 DBMS_OUTPUT.PUT_LINE('Begin inserting rows...');
11 r to
FOR i IN 1 .. 30 LOOP
a
12 m e
fn:=SUBSTR(p_file,1,INSTR(p_file,'.')-1);
13
i l l e ( icens
ln:=SUBSTR(p_file,INSTR(p_file,'.')+1,LENGTH(p_file)-

el oZ l
INSTR(p_file,'.')-4);

Marc 14
15
INSERT INTO resumes VALUES (i, fn, ln, EMPTY_BLOB())
RETURNING resume INTO b;
16 loadLOBFromBFILE_proc(b,p_file);
17 DBMS_OUTPUT.PUT_LINE('Row '|| i ||' inserted.');
18 END LOOP;
19 COMMIT;
20 END;
21 /

Procedure created.

SQL>
SQL> show errors
No errors.
SQL>
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
10) Press [Enter] to continue to the next step in the script. To retrieve records from the
RESUMES table, including the LOB values, a procedure called READ_LOB is created.

Oracle Database 11g: New Features for Administrators A - 115


Practice 7-1: Using SecureFiles (continued)
SQL>
SQL> /*== Create the procedure to read LOBs from the table
==*/
SQL>
SQL> CREATE OR REPLACE PROCEDURE read_lob
2 IS
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

3 lob_loc BLOB;
4 CURSOR resumes_cur IS
5 SELECT id, first_name, last_name, resume
6 FROM resumes;
7 resumes_rec resumes%ROWTYPE;
8 BEGIN
9 OPEN resumes_cur;
10 LOOP
11 FETCH resumes_cur INTO resumes_rec;
ble
12 lob_loc := resumes_rec.resume;
fe r a
13 DBMS_OUTPUT.PUT_LINE('The length is: '||
ans
DBMS_LOB.GETLENGTH(lob_loc));
14 DBMS_OUTPUT.PUT_LINE('The ID is: '|| n - t r
o
resumes_rec.id);
s an
15
16 r ) ha deฺ
-- just print out the first 200 bytes of the LOB
-- because DBMS_OUTPUT.PUT_LINE cannot display more
than 255 bytes m ฺa Gui
17 co ent
DBMS_OUTPUT.PUT_LINE('The blob is read: '||
n ฺ
18
@ ao Stud
UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(lob_loc,200,1)));
19 i l le this
EXIT WHEN resumes_cur%NOTFOUND;
z
20 END LOOP;
c e loฺ use
21 r
CLOSE resumes_cur;
a to
m e
22 END;
i l
23 / l e ( icens
el oZ l
Marc Procedure created.

SQL> show errors


No errors.
SQL>
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
11) Press [Enter] to continue to the next step in the script. A procedure called
CHECK_SPACE_BF is created to display the space usage in the disk blocks allocated
to the BasicFiles LOB segment in the RESUMES table. This procedure calls the
DBMS_SPACE package. Note: The DBMS_SPACE.SPACE_USAGE procedure has been
overloaded in Oracle Database 11g. There are now two DBMS_SPACE.SPACE_USAGE
procedures. The two cannot be used interchangeably. The invocation of the
DBMS_SPACE.SPACE_USAGE procedure in CHECK_SPACE_BF is only valid for use
against BasicFiles.
SQL>

Oracle Database 11g: New Features for Administrators A - 116


Practice 7-1: Using SecureFiles (continued)
SQL> /*== Create a procedure for checking BasicFile LOB space
usage. ==*/
SQL> /*==
==*/
SQL> /*== Note that the DBMS_SPACE.SPACE_USAGE procedure has
been ==*/
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> /*== overloaded. There are 2 DBMS_SPACE.SPACE_USAGE


procedures. ==*/
SQL> /*== The two cannot be used interchangeably. The
invocation of ==*/
SQL> /*== the DBMS_SPACE.SPACE_USAGE procedure here is ONLY
valid ==*/
SQL> /*== for use against BasicFile LOBs.
==*/
SQL>
ble
SQL> CREATE OR REPLACE PROCEDURE check_space_bf
fe r a
2 IS
ans
3
4 l_fs1_bytes NUMBER; n - t r
o
5 l_fs2_bytes NUMBER;
s an
6
7
l_fs3_bytes NUMBER;
l_fs4_bytes NUMBER; r ) ha deฺ
8 l_fs1_blocks NUMBER; m ฺa Gui
9 l_fs2_blocks NUMBER;
n ฺ co ent
10
11
l_fs3_blocks NUMBER;
l_fs4_blocks NUMBER; @ ao Stud
12 i
l_full_bytes NUMBER;
z l le this
13 loฺ use
l_full_blocks NUMBER;
c e
14 r to
l_unformatted_bytes NUMBER;
a
m e
15
i
16 l l e ( icens
l_unformatted_blocks NUMBER;
v_segname VARCHAR2(500);
el oZ17 BEGIN
l
Marc 18
19
SELECT segment_name
INTO v_segname
20 FROM user_lobs
21 WHERE table_name = 'RESUMES'
22 AND column_name = 'RESUME';
23
24 DBMS_SPACE.SPACE_USAGE(
25 segment_owner => 'SF_DEMO',
26 segment_name => v_segname,
27 segment_type => 'LOB',
28 fs1_bytes => l_fs1_bytes,
29 fs1_blocks => l_fs1_blocks,
30 fs2_bytes => l_fs2_bytes,
31 fs2_blocks => l_fs2_blocks,
32 fs3_bytes => l_fs3_bytes,
33 fs3_blocks => l_fs3_blocks,
34 fs4_bytes => l_fs4_bytes,
35 fs4_blocks => l_fs4_blocks,
36 full_bytes => l_full_bytes,
37 full_blocks => l_full_blocks,

Oracle Database 11g: New Features for Administrators A - 117


Practice 7-1: Using SecureFiles (continued)
38 unformatted_blocks => l_unformatted_blocks,
39 unformatted_bytes => l_unformatted_bytes
40 );
41 DBMS_OUTPUT.ENABLE;
42 DBMS_OUTPUT.PUT_LINE(' FS1 Blocks = '||l_fs1_blocks||'
Bytes = '||l_fs1_bytes);
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

43 DBMS_OUTPUT.PUT_LINE(' FS2 Blocks = '||l_fs2_blocks||'


Bytes = '||l_fs2_bytes);
44 DBMS_OUTPUT.PUT_LINE(' FS3 Blocks = '||l_fs3_blocks||'
Bytes = '||l_fs3_bytes);
45 DBMS_OUTPUT.PUT_LINE(' FS4 Blocks = '||l_fs4_blocks||'
Bytes = '||l_fs4_bytes);
46 DBMS_OUTPUT.PUT_LINE('Full Blocks =
'||l_full_blocks||' Bytes = '||l_full_bytes);
47 DBMS_OUTPUT.PUT_LINE('Unformatted Blocks =
ble
'||l_unformatted_blocks||' Bytes = '||l_unformatted_bytes);
fe r a
48
ans
DBMS_OUTPUT.PUT_LINE('========================================
====='); n - t r
o
49 DBMS_OUTPUT.PUT_LINE('Total Blocks =
s an
'||to_char(l_fs1_blocks + l_fs2_blocks +
50 r ) ha deฺ
l_fs3_blocks + l_fs4_blocks
+ l_full_blocks)|| ' || Total Bytes = '|| m ฺa Gui
51 co ent
to_char(l_fs1_bytes +
n ฺ
l_fs2_bytes +
52 @ ao Stud
l_fs3_bytes + l_fs4_bytes +
l_full_bytes)); z i l le this
53 END;
c e loฺ use
54 / a r to
m e
i l l
Proceduree ( icreated.
c e ns
l o Z l
rc e SQL>
Ma SQL> show errors
No errors.
SQL>
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
12) Press [Enter] to continue to the next step in the script. A procedure called
CHECK_SPACE_SF is created to display the space usage in the disk blocks allocated
to the SecureFiles LOB segment in the RESUMES table. This procedure calls the
DBMS_SPACE package. The invocation of the DBMS_SPACE.SPACE_USAGE
procedure in CHECK_SPACE_SF is only valid for use against SecureFiles LOBs.
SQL>
SQL> /*== Create a procedure for checking SecureFiles LOB
space usage. ==*/
SQL> /*==
==*/
SQL> /*== Note that the DBMS_SPACE.SPACE_USAGE procedure has
been ==*/

Oracle Database 11g: New Features for Administrators A - 118


Practice 7-1: Using SecureFiles (continued)
SQL> /*== overloaded. There are 2 DBMS_SPACE.SPACE_USAGE
procedures. ==*/
SQL> /*== The two cannot be used interchangeably. The
invocation of ==*/
SQL> /*== the DBMS_SPACE.SPACE_USAGE procedure here is ONLY
valid ==*/
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> /*== for use against SecureFiles LOBs.


==*/
SQL>
SQL> CREATE OR REPLACE PROCEDURE check_space_sf
2 IS
3 l_segment_size_blocks NUMBER;
4 l_segment_size_bytes NUMBER;
5 l_used_blocks NUMBER;
6 l_used_bytes NUMBER;
ble
7 l_expired_blocks NUMBER;
fe r a
8 l_expired_bytes NUMBER;
ans
9
10
l_unexpired_blocks NUMBER;
l_unexpired_bytes NUMBER; n - t r
o
11 v_segname varchar2(30);
s an
12 BEGIN
13 SELECT segment_name r ) ha deฺ
14 INTO v_segname m ฺa Gui
15 FROM user_lobs
n ฺ co ent
16
17 @
AND column_name = 'RESUME';
ao Stud
WHERE table_name = 'RESUMES'

18 i l
DBMS_SPACE.SPACE_USAGE(
z le this
19
c e loฺ use
segment_owner => 'SF_DEMO',
20 r
segment_name
a to => v_segname,
m e
21
i
22 l l e ( icens
segment_type => 'LOB',
segment_size_blocks => l_segment_size_blocks,
el oZ23
l
segment_size_bytes => l_segment_size_bytes,

Marc 24
25
used_blocks
used_bytes
=> l_used_blocks,
=> l_used_bytes,
26 expired_blocks => l_expired_blocks,
27 expired_bytes => l_expired_bytes,
28 unexpired_blocks => l_unexpired_blocks,
29 unexpired_bytes => l_unexpired_bytes
30 );
31 DBMS_OUTPUT.ENABLE;
32 DBMS_OUTPUT.PUT_LINE(' Segment Blocks =
'||l_segment_size_blocks||' Bytes = '||l_segment_size_bytes);
33 DBMS_OUTPUT.PUT_LINE(' Used Blocks =
'||l_used_blocks||' Bytes = '||l_used_bytes);
34 DBMS_OUTPUT.PUT_LINE(' Expired Blocks =
'||l_expired_blocks||' Bytes = '||l_expired_bytes);
35 DBMS_OUTPUT.PUT_LINE(' Unexpired Blocks =
'||l_unexpired_blocks||' Bytes = '||l_unexpired_bytes);
36
DBMS_OUTPUT.PUT_LINE('========================================
=====');
37 END;

Oracle Database 11g: New Features for Administrators A - 119


Practice 7-1: Using SecureFiles (continued)
38 /

Procedure created.

SQL> show errors


No errors.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
13) Sampling the performance of BasicFiles LOB storage. To capture write and read
performance statistics for BasicFiles LOB storage, perform the following steps:
a) Using your SQL*Plus session, execute the write_data.sql script. This script
inserts 90 records into the RESUMES table. Each record includes a LOB between
35 KB to 65 KB in size. A SQL*Plus timer is started to capture the total elapsed
time for the insert. e
b) When the script completes, write down the elapsed time for loading LOBs in r a bl
s fe
- t
CPU speed or amount of memory), the elapsed time you observe may differ.
an
BasicFiles format. Note: Depending on your hardware configuration (for example,
r
o n
SQL>
s an
SQL> @write_data
r ) ha deฺ
SQL> connect sf_demo/oracle_4U
Connected. m ฺa Gui
SQL> n ฺ co ent
SQL> set serveroutput on
@ ao Stud
SQL> set verify on
z i l le this
SQL> set term on
SQL> set lines 200c e loฺ use
SQL> a r to
m e
i l l e ( icens
SQL> timing start load_data

el oZ l
SQL> exec write_lob('karl.brimmer.doc');
Begin inserting rows...

Marc Row 1 inserted.


Row 2 inserted.
Row 3 inserted.

Row 30 inserted.

PL/SQL procedure successfully completed.

SQL> exec write_lob('monica.petera.doc');


Begin inserting rows...
Row 1 inserted.
Row 2 inserted.
Row 3 inserted.

Row 30 inserted.

PL/SQL procedure successfully completed.

SQL> exec write_lob('david.sloan.doc');

Oracle Database 11g: New Features for Administrators A - 120


Practice 7-1: Using SecureFiles (continued)
Begin inserting rows...
Row 1 inserted.
Row 2 inserted.
Row 3 inserted.

Row 30 inserted.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

PL/SQL procedure successfully completed.

SQL> timing stop


timing for: load_data
Elapsed: 00:00:00.94
SQL>
14) Now retrieve the records that were inserted in the previous step. e
a) Execute the read_data.sql script. This script reads back the 90 records from era
bl
the RESUMES table. For each record, the size of the LOB value plus the first a n sf
200
characters of the LOB are displayed on the screen. A SQL*Plus timer
o n -istrstarted to
capture the total elapsed time for the retrieval.
s an
b) When the script completes, write down the elapsed time
r ) hafor dreading
e ฺ LOBs in
ฺa Gu
BasicFiles format. Note: Depending on your hardware i
configuration (for
example, CPU speed or amount of memory), m
co theeelapsed
n t time you observe may
n ฺ
differ.
@ ao Stud
SQL>
SQL> @read_data oฺz
ille this
SQL> connect c e l u se
sf_demo/oracle_4US
Connected. a r to
SQL> le (
m ns e
i l li c e
Z set serveroutput
el oSQL>
SQL> set verify on
on

Marc SQL> set term on


SQL> set lines 200
SQL>
SQL> timing start read_data
SQL> exec read_lob;
The length is: 64000
The ID is: 1
The blob is read: ??? > ?? x
z ???? w
??????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????
The length is: 64000
The ID is: 2
The blob is read: ??? > ?? x
z ???? w
??????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????
The length is: 64000
The ID is: 3

Oracle Database 11g: New Features for Administrators A - 121


Practice 7-1: Using SecureFiles (continued)
The blob is read: ??? > ?? x
z ???? w
??????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????
The length is: 64000
The ID is: 4
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

The blob is read: ??? > ?? x


z ???? w
??????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????
The length is: 64000
The ID is: 5
The blob is read: ??? > ?? x
z ???? w
??????????????????????????????????????????????????????????????
ble
????????????????????????????????????????????????????????
fe r a
The length is: 64000
ans
The ID is: 6
The blob is read: ??? > ?? x n - t r
o
z ???? w
s an
r ) ha deฺ
??????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????
The length is: 64000 m ฺa Gui
The ID is: 7
n ฺ co ent
The blob is read: ???
z ???? w
> ??
@ ao Stud x

i l le this
??????????????????????????????????????????????????????????????
z
c e loฺ use
????????????????????????????????????????????????????????
r
The length is: 64000
a to
m e
i l l e ( icens
The ID is: 8
The blob is read: ??? > ?? x
el oZ
z ????
l w

Marc …
The length is: 37376
The ID is: 30
The blob is read: ??? > ?? D
F ???? C
??????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????
The length is: 37376
The ID is: 30
The blob is read: ??? > ?? D
F ???? C
??????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????

PL/SQL procedure successfully completed.

SQL> timing stop


timing for: read_data
Elapsed: 00:00:00.56
SQL>

Oracle Database 11g: New Features for Administrators A - 122


Practice 7-1: Using SecureFiles (continued)
15) Verify the space usage of BasicFiles LOBs by performing the following steps:
a) Using SQL*Plus, execute the space_usage.sql script.
b) When prompted for the LOB type, enter BF. When the script completes, write
down the number of Full Blocks and the Full Blocks Bytes.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> @space_usage
SQL> connect sf_demo/oracle_4US
Connected.
SQL>
SQL> set serveroutput on
SQL> set pause off
SQL> set echo on
SQL>
ble
SQL> exec check_space_&Enter_BF_or_SF_for_LOB_type
fe r a
Enter value for enter_bf_or_sf_for_lob_type: BF
ans
FS1 Blocks = 0 Bytes = 0
n - t r
FS2 Blocks = 0 Bytes = 0
FS3 Blocks = 0 Bytes = 0 a no
FS4 Blocks = 0 Bytes = 0
h a s ฺ
Full Blocks = 540 Bytes = 4423680
Unformatted Blocks = 7618 Bytes = 62406656 ฺ a r) uide
ฺ c
=============================================om ent G
on tud
Total Blocks = 540 || Total Bytes = 4423680
a
l l e@ is S
i
ฺz se th completed.
PL/SQL procedure successfully
l o
SQL> a rce to u
l e (m e n sestorage to SecureFiles storage, perform the following steps:
Zi l
16) To migrate BasicFiles
lic
l o
rce a) From your SQL*Plus session, execute the mig_bf_to_sf.sql script. The
Ma script first queries the DBA_SEGMENTS view to see the LOB segment subtype
name for BasicFiles LOB storage.
b) Notice that it says “ASSM.”
SQL> @mig_bf_to_sf
SQL> -- run this script as SYS
SQL> connect / as sysdba
Connected.
SQL>
SQL> set echo on;
SQL> set serveroutput on
SQL> set term on;
SQL> set lines 200
SQL>
SQL> set pause off
SQL>
SQL> /*== Check the current segment type of the LOB ==*/
SQL> /*== ==*/
SQL> /*== Note that the segment subtype for ==*/

Oracle Database 11g: New Features for Administrators A - 123


Practice 7-1: Using SecureFiles (continued)
SQL> /*== BasicFile LOB storage is ASSM ==*/
SQL>
SQL> SELECT segment_name, segment_type, segment_subtype
2 FROM dba_segments
3 WHERE tablespace_name = 'SECF_TBS1'
4 AND segment_type = 'LOBSEGMENT'
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

5 /

SEGMENT_NAME
SEGMENT_TYPE SEGMENT_SU
--------------------------------------------------------------
------------------- ------------------ ----------
SYS_LOB0000074197C00004$$
LOBSEGMENT ASSM
ble
SQL>
fe r a
SQL> pause Press [Enter] to continue...
ans
Press [Enter] to continue...
n - t r
o
s an
17) Press [Enter] to continue to the next step in the script. The migration from BasicFiles
to SecureFiles LOB storage format is done online. This means that the RESUMES table
) ha deฺ
continues to be accessible during the migration. This type of operation is called
r
ฺa Gui
“online redefinition.” Online redefinition requires an interim table for data storage. In
m
ฺ co ent
this step of the script, the interim table is defined with the SecureFiles LOB storage
n
ao Stud
format, and the LOB is stored in the SECF_TBS2 tablespace. After the migration
@
z i l le this
completes, the RESUME LOB is stored in the SECF_TBS2 tablespace.

c e loฺ use
Note: It is a recommended practice that you enable compression and deduplication at
r to
table creation time. Also, the ALTER TABLE SHRINK operation is not yet supported
a
m e
i l l e ( icens
for SecureFiles in this release of Oracle Database.

l Z
oSQL> l
e SQL> set pause on
Marc SQL>
SQL> /*== Create the interim table for online redefinition
==*/
SQL> /*==
SQL> /*== Note that the recommended practice is to enable
==*/
SQL> /*== COMPRESSION and DEDUPLICATION at table creation ==*/
SQL> /*== time. Also, the ALTER TABLE SHRINK operation is
==*/
SQL> /*== not yet supported for SecureFiles LOBs in
==*/
SQL> /*== release 1 of Oracle Database 11g.
==*/
SQL>
SQL> CREATE TABLE sf_demo.resumes_interim
2 (id NUMBER, first_name VARCHAR2(15),
3 last_name VARCHAR2 (40), resume BLOB)
4 LOB (resume) STORE AS SECUREFILE
5 (TABLESPACE secf_tbs2

Oracle Database 11g: New Features for Administrators A - 124


Practice 7-1: Using SecureFiles (continued)
6 COMPRESS HIGH
7 DEDUPLICATE)
8 /

Table created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
18) Press [Enter] to continue to the next step in the script. The next step in the script calls
the DBMS_REDEFINITION package to perform the online redefinition operation.
SQL>
SQL> /*== Perform the online redefinition ==*/
SQL> ble
SQL> DECLARE fe r a
2 error_count PLS_INTEGER := 0;
ans
3 BEGIN
n - t r
o
4
5 DBMS_REDEFINITION.START_REDEF_TABLE s an
6 ('sf_demo', 'resumes', 'resumes_interim',
r ) ha deฺ
7 ฺa Gui
'id id, first_name first_name, last_name last_name,
m
resume resume',
8 n ฺ co ent
OPTIONS_FLAG => DBMS_REDEFINITION.CONS_USE_ROWID);
9
@ ao Stud
l le this
10 DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS
z i
c e loฺ use
11 ('sf_demo', 'resumes', 'resumes_interim',
12 1, true,true,true,false, error_count);
a r to
13 m e
l e ( icens
14 DBMS_OUTPUT.PUT_LINE('Errors := ' ||
i l
el oZ15
l
TO_CHAR(error_count));

Marc 16 DBMS_REDEFINITION.FINISH_REDEF_TABLE
17 ('sf_demo', 'resumes', 'resumes_interim');
18
19 END;
20 /
Errors := 0

PL/SQL procedure successfully completed.

SQL>
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
19) Press [Enter] to continue to the next step in the script. After the online redefinition
operation completes, the interim table can be dropped.
SQL>
SQL> /*== Drop the interim table ==*/
SQL>
SQL> DROP TABLE sf_demo.resumes_interim

Oracle Database 11g: New Features for Administrators A - 125


Practice 7-1: Using SecureFiles (continued)
2 /

Table dropped.

SQL>
SQL> pause Press [Enter] to continue...
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Press [Enter] to continue...

20) Press [Enter] to continue to the next step in the script. The migrated LOB data now
resides in the SECF_TBS2 tablespace. This step in the script queries the
DBA_SEGMENTS view to see the LOB segment subtype name for SecureFiles storage.
Note that it says “SECUREFILE.”
SQL>
SQL> set pause off
ble
SQL>
fe r a
SQL> /*== Check the segment type of the migrated LOB ==*/ s
SQL> /*== ==*/
- t r an
SQL> /*== Note that the segment subtype for ==*/
no n
SQL> /*== SecureFiles LOB storage is SECUREFILE ==*/
a
SQL>
SQL> has deฺ
SELECT segment_name, segment_type,r)segment_subtype
2 FROM dba_segments m ฺa Gui
3 co ent
WHERE tablespace_name = 'SECF_TBS2'
n ฺ
4
5 / @ ao Stud
AND segment_type = 'LOBSEGMENT'

z i l le this
SEGMENT_NAME elo
ฺ se
SEGMENT_TYPE r c o u
tSEGMENT_SU
m a e
i l e ( icens ------------------ ----------
--------------------------------------------------------------
l
-------------------
l Z l
oSYS_LOB0000074206C00004$$
e
Marc LOBSEGMENT SECUREFILE

SQL> pause Press [Enter] to continue...


Press [Enter] to continue...

21) The final step in the script queries the DBA_LOBS view to see the compression and
deduplication settings for the SecureFiles segment.
SQL>
SQL> set pause off
SQL>
SQL> /*== Check the DBA_LOBS data dictionary view for ==*/
SQL> /*== information on the SecureFiles COMPRESSION ==*/
SQL> /*== and DEDUPLICATION settings ==*/
SQL>
SQL> SELECT column_name, segment_name,
2 compression, deduplication, securefile
3 FROM dba_lobs
4 WHERE owner = 'SF_DEMO' and table_name = 'RESUMES'
5 /

Oracle Database 11g: New Features for Administrators A - 126


Practice 7-1: Using SecureFiles (continued)

COLUMN_NAME
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
--------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SEGMENT_NAME COMPRE DEDUPLICATION SEC


------------------------------ ------ --------------- ---
RESUME
SYS_LOB0000074206C00004$$ HIGH LOB YES

SQL>
22) Verify the space usage of SecureFiles. e
To verify the space usage of SecureFiles, perform the following steps: r a bl
s fe
a) Using SQL*Plus, execute the space_usage.sql script.
- t r an
no n
b) When prompted for the LOB type, enter SF. When the script completes, write
down the number of Used Blocks, and the Used Blocks Bytes.s ฺ a
h a e 15b with the
c) Contrast the BasicFiles Full Blocks number and
ฺ a r) from
Bytes
u idstep
SecureFiles Used Blocks number and Bytes.
ฺ c omNoteenthet G
dramatic decrease in space
on tuandd deduplication enabled.
usage for the SecureFiles with compression
a
SQL>
l l e@ is S
SQL> @space_usage ฺz i th
l o e
ce to us
SQL> connect sf_demo/oracle_4U
Connected. ar
SQL>
l e (m ense
SQL>l
Zi set lic off on
serveroutput
e l oSQL> set pause
rc SQL> set echo on
Ma SQL>
SQL> exec check_space_&Enter_BF_or_SF_for_LOB_type
Enter value for enter_bf_or_sf_for_lob_type: SF
Segment Blocks = 8192 Bytes = 67108864
Used Blocks = 6 Bytes = 49152
Expired Blocks = 8162 Bytes = 66863104
Unexpired Blocks = 0 Bytes = 0
=============================================

PL/SQL procedure successfully completed.

SQL>

Oracle Database 11g: New Features for Administrators A - 127


Practice 7-1: Using SecureFiles (continued)
23) Sample the performance of SecureFiles storage.
To capture read and write performance statistics for SecureFiles LOB storage,
perform the steps below. Unlike the previous section on sampling performance of
BasicFiles storage, you start with a read performance test first for SecureFiles storage.
This is to ensure a valid read performance comparison between BasicFiles and
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SecureFiles—you need to perform the read test on the same set of records, right after
they have been migrated from BasicFiles to SecureFiles.
a) Execute the read_data.sql script. Note: Depending on your hardware
configuration (for example, CPU speed or amount of memory), the elapsed time
you observe may differ.
SQL> @read_data
SQL> connect sf_demo/oracle_4U
Connected.
ble
SQL>
fe r a
SQL> set serveroutput on
ans
SQL> set verify on
n - t r
SQL> set term on o
SQL> set lines 200
s an
SQL>
SQL> timing start read_data r ) ha deฺ
SQL> exec read_lob; m ฺa Gui
The length is: 64000
n ฺ co ent
The ID is: 1
The blob is read: ??? > ??@ ao Stud x
z ???? w z i l le this
c e loฺ use
??????????????????????????????????????????????????????????????
a r to
????????????????????????????????????????????????????????
m e
i l e ( icens
The length is: 64000
l
The ID is: 2
el oZ l
The blob is read: ??? > ?? x

Marc z ???? w
??????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????
The length is: 64000
The ID is: 3
The blob is read: ??? > ?? x
z ???? w
??????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????
The length is: 64000
The ID is: 4
The blob is read: ??? > ?? x
z ???? w
??????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????
The length is: 64000
The ID is: 5
The blob is read: ??? > ?? x
z ???? w

Oracle Database 11g: New Features for Administrators A - 128


Practice 7-1: Using SecureFiles (continued)
??????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????
The length is: 64000
The ID is: 6
The blob is read: ??? > ?? x
z ???? w
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ


The length is: 37376
The ID is: 29
The blob is read: ??? > ?? D
F ???? C
??????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????
The length is: 37376
The ID is: 30
ble
The blob is read: ??? > ?? D
fe r a
F ???? C
ans
??????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????? n - t r
o
The length is: 37376
s an
The ID is: 30
The blob is read: ??? > ?? r ) ha deฺ
D
F ???? C m ฺa Gui
n ฺ co ent
??????????????????????????????????????????????????????????????
ao Stud
????????????????????????????????????????????????????????
@
i
PL/SQL procedure successfully
z l le thiscompleted.
c e loฺ use
SQL> timingarstop to
m e
i l
Elapsed: e ( 00:00:00.61
timing for:
l c e ns
read_data

l o Z
SQL>
li
e
rc 24) Now insert additional records.
Ma
a) Execute the write_data.sql script. This script inserts 90 records into the
RESUMES table. Each record includes a LOB between 35 KB to 65 KB in size. A
SQL*Plus timer is started to capture the total elapsed time for the insert.
b) When the script completes, write down the elapsed time for writing LOBs in
SecureFiles format. Note: Depending on your hardware configuration (for
example, CPU speed or amount of memory), the elapsed time you observe may
differ.
SQL>
SQL> @write_data
SQL> connect sf_demo/oracle_4U
Connected.
SQL>
SQL> set serveroutput on
SQL> set verify on
SQL> set term on
SQL> set lines 200

Oracle Database 11g: New Features for Administrators A - 129


Practice 7-1: Using SecureFiles (continued)
SQL>
SQL> timing start load_data
SQL> exec write_lob('karl.brimmer.doc');
Begin inserting rows...
Row 1 inserted.
Row 2 inserted.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Row 3 inserted.

Row 30 inserted.

PL/SQL procedure successfully completed.

SQL> exec write_lob('monica.petera.doc');


Begin inserting rows...
Row 1 inserted.
ble
Row 2 inserted.
fe r a
Row 3 inserted.
an s

Row 30 inserted. n - t r
o
s an
PL/SQL procedure successfully completed.
r ) ha deฺ
SQL> exec write_lob('david.sloan.doc'); m ฺa Gui
Begin inserting rows...
n ฺ co ent
Row 1 inserted.
Row 2 inserted. @ ao Stud
Row 3 inserted. z i l le this

c e loฺ use
Row 30 inserted.
a r to
m
( ens e
i l l e procedure
l
PL/SQL
oZ lic successfully completed.
e
Marc SQL> timing stop
timing for: load_data
Elapsed: 00:00:00.45
SQL>
SQL>
SQL>
25) Enable encryption.
To encrypt the LOB stored in SecureFiles format, perform the following steps:
a) Using SQL*Plus, connect to the database as sf_demo/oracle_4U. Execute the
encrypt_lob.sql script.
SQL>
SQL> @encrypt_lob
SQL> set serveroutput on
SQL> set verify on
SQL> set term on
SQL> set lines 200
SQL> set pause off

Oracle Database 11g: New Features for Administrators A - 130


Practice 7-1: Using SecureFiles (continued)
SQL> set echo on
SQL>
SQL> connect / as sysdba
Connected.
SQL>
SQL> ALTER TABLE sf_demo.resumes
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

2 MODIFY (resume ENCRYPT USING 'AES192')


3 /

Table altered.

SQL>

26) Verify that the LOB is now encrypted. Execute the check_encrypt.sql script.
Note: The column encryption operation essentially updates all existing LOB values. e
However, if free space is available in the data block, the original unencrypted form of r a bl
s fe
the LOB value may still exist. To ensure that no unencrypted values are on disk, it is
t r
best to enable encryption at table creation time (that is, before any values are
- an
inserted). o n
SQL> @check_encrypt s an
SQL> connect sf_demo/oracle_4U r ) ha deฺ
Connected. m ฺa Gui
SQL> set pause off
n ฺ co ent
SQL> set echo on
SQL> @ ao Stud
SQL> col TABLE_NAMEziformat l le ta18;
h is
SQL> col COLUMN_NAME
c e loฺ format
u se a19;
r
SQL> col ENCRYPTION_ALG
a to format a17;
SQL> m
( ens e
i
SQL> l l eSELECTc*
l o Z2 FROM liUSER_ENCRYPTED_COLUMNS
rc e 3 /
Ma TABLE_NAME COLUMN_NAME ENCRYPTION_ALG SAL
INTEGRITY_AL
------------------ ------------------- ----------------- --- -
-----------
RESUMES RESUME AES 192 bits key YES
SHA-1

SQL>
27) To clean up the database accounts and objects created for this practice, connect as the
SYSDBA user and execute the cleanup.sql script. Exit from SQL*Plus.
SQL>
SQL> connect / as sysdba
Connected.
SQL> @cleanup
SQL> drop user sf_demo cascade
2 /

Oracle Database 11g: New Features for Administrators A - 131


Practice 7-1: Using SecureFiles (continued)
User dropped.

SQL> drop tablespace secf_tbs1 including contents and


datafiles
2 /
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Tablespace dropped.

SQL> drop tablespace secf_tbs2 including contents and


datafiles
2 /

Tablespace dropped.
SQL>
SQL> exit
ble
Disconnected from Oracle Database 11g Enterprise Edition
fe r a
Release 11.2.0.1.0 - Production
ans
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 132


Practices for Lesson 8

In this practice you will apply the several security features.


Assumptions: Listener has been started, instance name is orcl, the SYS password is
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

oracle_4U, and the database instance is started.

ble
fe r a
an s
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 133


Practice 8-1: Using Password Security Features
You have installed the Oracle 11g database in a mixed environment of 10.2 and 11.1
databases. Use the Evaluation Results: Secure Configuration for Oracle databases page in
Enterprise Manager to check your compliance. Based on the compliance score, you
decide to increase the security of your passwords by enforcing case sensitivity for the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

passwords for privileged users. Password complexity is not being checked, so you
implement the verify_function_11g password complexity check. Before you start
this practice, connected as user SYS in a SQL*Plus session, execute the following script
located in your /home/oracle/solutions/SEC directory: setup_sec.sql.
$ cd /home/oracle/solutions/SEC
$
$ . oraenv
ORACLE_SID = [db10g] ? orcl
$ ble
$ sqlplus / as sysdba fe r a
t r a ns
SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 1 11:30:37
o n -
2009
s an
Copyright (c) 1982, 2009, Oracle. All rights
r ) ha reserved.
d e ฺ
ฺa Gu i
Connected to:
c o m n t
Oracle Database 11g Enterprise
o n ฺEdition d eRelease 11.2.0.1.0 -
Production a t u
@ is SStorage Management, OLAP,
With the Partitioning, i l l eAutomatic
th Testing options
Data Mining and Real
l o ฺz Application
e
r c e o us
a
SQL> @setup_sec
m e t
( s
SQL> le
Z il connect
SQL> l i ce/nas sysdba
rc eloConnected.
Ma SQL>
SQL> ALTER USER HR identified by hr account unlock;

User altered.

SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$
1) Start Enterprise Manager Database Control if it is not already started, using the
emctl start dbconsole command. Hint: Check the status of the processes
with emctl status dbconsole.
$ emctl status dbconsole

Oracle Database 11g: New Features for Administrators A - 134


Practice 8-1: Using Password Security Features (continued)
Oracle Enterprise Manager 11g Database Control Release
11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation. All rights
reserved.
https://...:5500/em/console/aboutApplication
Oracle Enterprise Manager 11g is running.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

--------------------------------------------------------------
Logs are generated in directory
/u01/app/oracle/acfsmounts/acfs_db1/ed.us.oracle.com_orcl/sysm
an/log
$

2) Launch Enterprise Manager Database Control and log in as the SYS user. View the
Security Violations and Policy Trend Overview and note the configuration score.
a) On the Database Home page in the Policy Violations section, the policy score ble
shows: fe r a
ans
Policy Violations
n - t r
All 7 Critical Rules Violated 7 Critical Security Patches 0 a no
Compliance Score (%) 95 h a s ฺ
r) directs e
idyou
b) Click the number for the Compliance Scorem ฺaThis
(%). u to the Policy
G representation
Trend Overview Page where you can see ฺ c o
an n
overall
e t
visual of policy
compliance. o n
a Stu d
l e @ is
l being violated:
i
3) Find the distinct rules thatzare t h
e loฺ row,usclick
a) In the CriticalcSeverity
e the number in the Distinct Rules Violated
column.ma
r to
( ens e
illeshould
b)ZYou l icsee several violations about PUBLIC having EXECUTE privilege on
l o
e PL/SQL packages, and one about profiles with excessive allowed failed login
rc
Ma attempts.
4) Find the rule to determine the value of failed login attempts that are considered
excessive.
a) Click “Profiles With Excessive Allowed Failed Login Attempts” in the Policy
Rule column.
b) On the View Policy Rule Settings page for this rule, you see that the default
setting for this rule is 10.
5) You determine that per your site policy, five failed login attempts should result in an
account lock for five minutes. Check the Password Profile Settings and change the
settings of the DEFAULT profile to match the site policy.
a) Return to the Database Home page. On the Database Home page, click the Server
tab and then Profiles in the Security section.
b) On the Profiles page, select the DEFAULT profile and click Edit.
c) On the Edit Profile page, click the Password tab.

Oracle Database 11g: New Features for Administrators A - 135


Practice 8-1: Using Password Security Features (continued)
d) In the Failed Login section, change “Number of failed login attempts to lock
after” to 5, and the “Number of days to lock for” to 0.0035. This value represents
5 minutes in days (5/1440).
e) Click Apply. You receive an update message.
6) Confirm the Password Case Sensitivity settings for the instance for database users.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

View the SEC_CASE_SENSITIVE_LOGIN parameter value. Connect to the orcl


instance as HR with HR as the password. Attempt to connect with the
username/passwords combinations: HR/hr, hr/hr, and hr/HR.
a) Connect to SQL*Plus as sysdba and check the SEC_CASE_SENSITIVE_LOGON
parameter:
$ sqlplus / as sysdba
bl e
SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 1 11:43:56 ra
2009 n s fe
n - tra
Copyright (c) 1982, 2009, Oracle. All rights reserved.
a no
Connected to: h a s ฺ
Oracle Database 11g Enterprise EditionarRelease ) e
id11.2.0.1.0 -
Production ฺ
m nt G u
With the Partitioning, Automatic ฺ c oStorage
e Management, OLAP,
o n d
Data Mining and Real Application
@ a STesting tu options

z ll e t hi s
isec_case_sensitive_logon
SQL> show parameter ฺ e
r c elo o us
NAME
m a e t TYPE VALUE
( s
------------------------------------ ----------- -------------
Z ille licen
sec_case_sensitive_logon boolean TRUE
e l oSQL> exit
rc Disconnected from Oracle Database 11g Enterprise Edition
Ma Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$

b) Start SQL*Plus with the /nolog option. Attempt to connect with the various
combinations of username and password. Observe which combinations allow a
connection.
Note: Be sure to use a valid connect string before you make five failed attempts,
or the account will be locked for five minutes.
$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 1 11:45:46


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

SQL> connect HR/HR

Oracle Database 11g: New Features for Administrators A - 136


Practice 8-1: Using Password Security Features (continued)
ERROR:
ORA-01017: invalid username/password; logon denied

SQL> connect HR/hr


Connected.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> connect hr/hr


Connected.
SQL> connect hr/HR
ERROR:
ORA-01017: invalid username/password; logon denied

Warning: You are no longer connected to ORACLE.


SQL> exit
ble
$
fe r a
ans
n - t r
o
7) Make the password file non-case-sensitive because it would be in an upgraded
database. Use the command: s an
orapwd file=$ORACLE_HOME/dbs/orapworcl entries=5
r ) ha deฺ
password=oracle_4U ignorecase=Y force=Y
m ฺa Gui
$ . oraenv n ฺ co ent
ORACLE_SID = [orcl] ? orclao
@ S t ud
The Oracle base for le is
z i l t h
/u01/app/oracle e l oฺ use
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is

a rc to
$ orapwd file=$ORACLE_HOME/dbs/orapworcl entries=5
( m s e
$ Zil
le licen
password=oracle_4U ignorecase=Y force=Y

elo
rc 8) Confirm the Password Case Sensitivity settings for the instance for privileged users.
Ma Attempt to connect to the orcl instance as the SYSDBA user using a net service name
and:
• A lowercase password
• An uppercase password
• A mixed-case password
The net service name forces the use of the password file. Which connections
succeed?
Start SQL*Plus and attempt to connect using the various password combinations.
$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 1 11:48:25


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.


SQL> connect sys/oracle_4U@orcl AS SYSDBA

Oracle Database 11g: New Features for Administrators A - 137


Practice 8-1: Using Password Security Features (continued)
Connected.
SQL> connect sys/ORACLE_4U@orcl AS SYSDBA
Connected.
SQL> connect sys/OraCle_4u@orcl AS SYSDBA
Connected.
SQL> exit
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Disconnected from Oracle Database 11g Enterprise Edition


Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$
9) Make the password file case-sensitive to match the database password usage. Use the
command:
orapwd file=$ORACLE_HOME/dbs/orapworcl entries=5 e
password=oracle_4U ignorecase=N force=Y r a bl
s fe
$ orapwd file=$ORACLE_HOME/dbs/orapworcl entries=5
- t r an
password=oracle_4U ignorecase=N force=Y
$ no n
s a
h
10) Attempt to connect to the orcl instance as the SYSDBA user ausing aฺnet service name
and: ฺ a r) uide
• A lowercase password ฺ c om ent G
• An uppercase password @a
on tud
l e i s S
i l h
e l oฺz use t
• A mixed-case password
rc forces
The net serviceaname tothe use of the password file. Which connections succeed?
m e
i l l e ( icand
Start SQL*Plus
e s to connect using the various password combinations.
nattempt
o$Z sqlplus l /nolog
e l
rc
Ma SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 1 11:51:01
2009
Copyright (c) 1982, 2009, Oracle. All rights reserved.

SQL> connect sys/oracle_4U@orcl AS SYSDBA


Connected.
SQL> connect sys/ORACLE_4U@orcl AS SYSDBA
ERROR:
ORA-01017: invalid username/password; logon denied

Warning: You are no longer connected to ORACLE.


SQL> connect sys/OraCle_4u@orcl AS SYSDBA
ERROR:
ORA-01017: invalid username/password; logon denied

SQL> exit
$

Oracle Database 11g: New Features for Administrators A - 138


Practice 8-1: Using Password Security Features (continued)
11) Install the password complexity checking functions supplied with the Oracle 11g
Database software. Do not change the DEFAULT profile. The utlpwdmg.sql script
installs the password complexity check functions and changes the DEFAULT profile.
Use the cr_verification_funct.sql script. This script has the changes to the
DEFAULT profile commented out. This script creates both verify_function and
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

verify_function_11g.
Execute cr_verification_funct.sql from the $HOME/solutions/SEC
directory.
$ pwd
/home/oracle/solutions/SEC
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 1 11:53:59


2009 ble
fe r a
Copyright (c) 1982, 2009, Oracle. All rights reserved. ans
n - t r
Connected to:
a no
h a s ฺ
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
ฺ a r) uide
With the Partitioning, Automatic Storage Management, OLAP,
ฺ c om ent G
Data Mining and Real Application Testing options

SQL> @cr_verification_funct a on tud


l l e@ is S
i
ฺz se th
Function created. l o
a r ce to u
Function
l e ( mcreated.
e n se
l
Zi exit lic
SQL>
l o
e Disconnected from Oracle Database 11g Enterprise Edition
rc
Ma Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$

12) Create the DBUSER profile. Set everything the same as the DEFAULT profile except
password complexity checking. In the DBUSER profile, use the supplied verification
function named VERIFY_FUNCTION_11G. View the password limits set in the
DBUSER profile. Reminder: When you create a new profile, any values that are not
explicitly set inherit the DEFAULT profile values. Use the
cr_dbuser_profile.sql script in the $HOME/solutions/SEC directory.
$ pwd
/home/oracle/solutions/SEC
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 1 11:56:27


2009
Copyright (c) 1982, 2009, Oracle. All rights reserved.

Oracle Database 11g: New Features for Administrators A - 139


Practice 8-1: Using Password Security Features (continued)

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> @cr_dbuser_profile
SQL>
SQL> connect / as sysdba
Connected.
SQL>
SQL> -- create a DBUSER profile
SQL> CREATE PROFILE DBUSER
2 LIMIT
ble
3 PASSWORD_VERIFY_FUNCTION verify_function_11g;
fe r a
ans
Profile created.
n - t r
SQL> a no
SQL> -- View the settings of the DBUSER profile
h a s ฺ
SQL>
SQL> SELECT RESOURCE_NAME, LIMIT ฺ a r) uide
2 FROM DBA_PROFILES ฺ c om ent G
3 on tud
WHERE PROFILE = 'DBUSER'
a
4
l l e@ is S
AND RESOURCE_TYPE = 'PASSWORD';
i
ฺz se th LIMIT
RESOURCE_NAME elo
rc t o u
-------------------------------- -----------------------------
m a
( ens e
FAILED_LOGIN_ATTEMPTS DEFAULT
l l e
l o Zi lic
PASSWORD_LIFE_TIME
PASSWORD_REUSE_TIME
DEFAULT
DEFAULT
rc e PASSWORD_REUSE_MAX DEFAULT
Ma PASSWORD_VERIFY_FUNCTION VERIFY_FUNCTION_11G
PASSWORD_LOCK_TIME DEFAULT
PASSWORD_GRACE_TIME DEFAULT

7 rows selected.

SQL>

13) Create a user named FRED with a simple password oracle. Grant the CREATE
SESSION privilege to FRED. As the SYS user, connect and create the FRED user with
the password oracle.
SQL>
SQL> CREATE USER fred IDENTIFIED BY oracle;

User created.

SQL> GRANT CREATE SESSION TO FRED IDENTIFIED BY oracle;

Oracle Database 11g: New Features for Administrators A - 140


Practice 8-1: Using Password Security Features (continued)
Grant succeeded.

SQL>

14) Is the password case-sensitive? Test by connecting as the FRED user.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> connect fred/ORACLE


ERROR:
ORA-01017: invalid username/password; logon denied

Warning: You are no longer connected to ORACLE.


SQL> connect FRED/ORACLE
ERROR:
ORA-01017: invalid username/password; logon denied
ble
fe r a
SQL> connect fred/oracle
ans
Connected.
n - t r
SQL>
a no
15) Set the profile for the FRED user to DBUSER. h a s ฺ
r) user.uide
As the SYS user, assign the DBUSER profile to the ฺFRED
a
SQL> CONNECT / as sysdba ฺ c om ent G
Connected. a on tud
SQL> ALTER USER fred PROFILE
l e@ dbuser;
i s S
i l
ฺz se t h
User altered. elo u
a rc t o
SQL>
l e (m ense
l
Zi as thelicFRED user and attempt to change the password to welcome4 and
16)
l oConnect
rce then to welcome1. What happens?
Ma Connect as the FRED user. Use the ALTER USER command to change the password.
SQL> connect fred/oracle
Connected.
SQL> ALTER USER fred IDENTIFIED BY welcome4 REPLACE oracle;

User altered.

SQL> ALTER USER fred IDENTIFIED BY welcome1 REPLACE welcome4;


ALTER USER fred IDENTIFIED BY welcome1 REPLACE welcome4
*
ERROR at line 1:
ORA-28003: password verification for the specified password
failed
ORA-20006: Password too simple

SQL>

Oracle Database 11g: New Features for Administrators A - 141


Practice 8-1: Using Password Security Features (continued)
17) Pick a password that has at least four characters, one must be a letter, and one a
number. As the FRED user, change the password to the value you picked. What
happens?
Use the ALTER USER command again to change the password to a more complex
value. Suggested password is Ft54red#.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> ALTER USER fred IDENTIFIED BY Ft54red# REPLACE welcome4;

User altered.

SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
ble
Data Mining and Real Application Testing options
fe r a
$
t r a ns
18) Alter the Security Profile Rules to reduce the number of critical violations. o n - The
network-related PL/SQL packages require an ACL in order to access
s a n any network
machine. Because these ACLs, when they do exist, specify hausers andฺ machines that
may be accessed, there is no security violation allowing
ฺ a r ) these
u ide to execute
packages
privilege by PUBLIC.
ฺ c om ent G
n Metrics
a) In Enterprise Manager, navigatea
clicking the link in the Related @
toothe
Links S tuofdand
section the
Policy Settings page by
Database Home page.
i l l e h i s
tclick the Polices tab, and then find the policies
b) On the Metrics and l ฺz spage,
oPolicies e
e
rc“Restricted
that start with o uPrivilege to Execute.” These are in the 76–100 range of
a t
rows. (m
l e e n se
l
i “Restricted
c)ZSelect lic Privilege to Execute UTL_HTTP,” and click the Edit icon at
l o
rce the right.
Ma d) On the “Edit Policy Rule Settings: Restricted Privilege to Execute UTL_HTTP”
page, change Policy Evaluation to Disabled. Then click Continue.
e) Repeat for UTL_SMTP and UTL_TCP. On the Metrics and Policies page, click
OK.
f) On the Confirmation page, click OK.
19) Click Database to return to the Database Home page.

Oracle Database 11g: New Features for Administrators A - 142


Practice 8-2: Using an Encrypted Tablespace
If you have not completed Practice 7-1, make sure that you execute the following setup
steps before doing this practice. Edit the sqlnet.ora file to add the
ENCRYPTION_WALLET_LOCATION entry:
$ mkdir /u01/app/oracle/admin/orcl/wallet
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

$ cd /u01/app/oracle/product/11.2.0/grid/network/admin
$ vi sqlnet.ora
$ cat
/u01/app/oracle/product/11.2.0/grid/network/admin/sqlnet.ora
# sqlnet.ora Network Configuration File:
/u01/app/oracle/product/11.2.0/grid/network/admin/sqlnet.ora
# Generated by Oracle configuration tools.

NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT) e


r a bl
ADR_BASE = /u01/app/oracle
ns fe
- t r a
ENCRYPTION_WALLET_LOCATION= (SOURCE=(METHOD=FILE)(METHOD_DATA=
o n
(DIRECTORY=/u01/app/oracle/admin/orcl/wallet)))a n
h a s ฺ
$
$ sqlplus / as sysdba ฺ a r) uide
ฺ c om ent G
n ud on Thu Oct 1 12:09:47
SQL*Plus: Release 11.2.0.1.0oProduction
a
2009 @ S t
Copyright (c) 1982,zi2009,
e
ll Oracle.
t hi s All rights reserved.
l o ฺ s e
Connected to:a rce to u
(m ens11g
Oracle Database e Enterprise Edition Release 11.2.0.1.0 -
l l e
l Zi the Partitioning,
Production
oWith lic Automatic Storage Management, OLAP,
e
Marc Data Mining and Real Application Testing options

SQL>
SQL> alter system set wallet open identified by "welcome1";
alter system set wallet open identified by "welcome1"
*
ERROR at line 1:
ORA-28367: wallet does not exist

SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$

The CUSTOMER_ID column of the ORDERS and CUSTOMERS tables contains sensitive
data. For the application to work properly, the column must be indexed and column_id

Oracle Database 11g: New Features for Administrators A - 143


Practice 8-2: Using an Encrypted Tablespace (continued)
must be a foreign key column. Perform a test, checking for a changed access path.
Implement tablespace encryption by placing the two tables and the index in the
CUSTOMER_ID column in the encrypted tablespace.
1) Create a database master encryption key. Use the command
ALTER SYSTEM SET ENCRYPTION KEY IDENTIFIED BY "welcome1";
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Connect to the orcl database as SYSDBA and issue the SET ENCRYPTION KEY
command:
$ cd /home/oracle/solutions/SEC
$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle e
$ sqlplus / as sysdba
r a bl
s fe
SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 1 12:15:39
- t r an
2009
no n
Copyright (c) 1982, 2009, Oracle. All rights
a
s reserved.
) h a e ฺ
r
ฺa Gu i d
Connected to:
c o m n t
Oracle Database 11g Enterprise
o n ฺEdition
d eRelease 11.2.0.1.0 -
Production a t u
@ is SStorage Management, OLAP,
With the Partitioning,
i l l e Automatic
th Testing options
Data Mining and Real
l o ฺz Application
s e
rce SET
SQL> ALTER aSYSTEM t o uENCRYPTION KEY IDENTIFIED BY "welcome1";
( m s e
Z
System l cen
ille altered.
i
rc elo SQL>
Ma
2) Create an encrypted tablespace named ENCTS that uses the default encryption
algorithm with a size of 10 MB. Use the following command:
CREATE TABLESPACE encts
DATAFILE '+DATA' SIZE 10M
ENCRYPTION
DEFAULT STORAGE (ENCRYPT);
SQL> CREATE TABLESPACE encts
2 DATAFILE '+DATA' SIZE 10M
3 ENCRYPTION
4 DEFAULT STORAGE (ENCRYPT);
Tablespace created.

SQL>

Oracle Database 11g: New Features for Administrators A - 144


Practice 8-2: Using an Encrypted Tablespace (continued)
3) Does indexing work in the encrypted tablespace? Test as the OE user. The query in
the query_orders_index.sql file uses a foreign key index named
ORD_CUSTOMER_IX. Check the query in an unencrypted tablespace to verify that the
foreign key index is being used. Move the accessed objects to the encrypted
tablespace. Verify that the execution plan did not change.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

a) Connect to SQL*Plus as the SYSDBA user. Create the PLUSTRACE role by


executing the plustrce.sql script in the
$ORACLE_HOME/sqlplus/admin directory. Grant the PLUSTRACE role to
the OE user. Unlock the OE account and change the password to oe.
SQL> connect / as sysdba
Connected.
SQL> @?/sqlplus/admin/plustrce
SQL> ble
SQL> drop role plustrace;
fe r a
drop role plustrace
ans
*
n - t r
ERROR at line 1: o
ORA-01919: role 'PLUSTRACE' does not exist s an
r ) ha deฺ
SQL> create role plustrace;
m ฺa Gui
Role created. n ฺ co ent
@ ao Stud
z i le this to plustrace;
SQL> grant select on lv_$sesstat

Grant succeeded. c e loฺ use


a r to
SQL> le
m
( select
grant
e
ns on v_$statname to plustrace;
Z i l li c e
e l oGrant succeeded.
rc
Ma SQL> grant select on v_$mystat to plustrace;

Grant succeeded.

SQL> grant plustrace to dba with admin option;

Grant succeeded.

SQL> set echo off


SQL> GRANT PLUSTRACE to OE;

Grant succeeded.

SQL> ALTER USER oe IDENTIFIED BY oe ACCOUNT UNLOCK;

User altered.

SQL>

Oracle Database 11g: New Features for Administrators A - 145


Practice 8-2: Using an Encrypted Tablespace (continued)
b) As the OE user with autotrace enabled, execute the query
query_orders_index.sql script found in
/home/oracle/solutions/SEC and examine the execution plan. Notice
that the ORD_CUSTOMER_IX index is being accessed. The password for the OE
user is oe.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> connect oe/oe
Connected.
SQL> set autotrace traceonly explain
SQL> set echo on
SQL> @query_orders_index
SQL> select cust_last_name, order_id, order_total
2 from customers, orders
3 where customers.customer_id = orders.customer_id ble
4 and account_mgr_id = 145;
fe r a
ans
Execution Plan
n - t r
----------------------------------------------------------
Plan hash value: 3558567882 a no
h a s ฺ
ฺ a r) uide
--------------------------------------------------------------
------------------
---------------- ฺ c om ent G
a on tud
| Id | Operation l l e@ is S | Name | Rows
| Bytes | Cost (% ฺz i t h
CPU)| Time e|l
o use
a r c to
m
( ens e
--------------------------------------------------------------
i l l e
l Z lic
o------------------
e ----------------

Marc | 0 | SELECT STATEMENT | | 105


| 3150 | 8
(13)| 00:00:01 |

|* 1 | HASH JOIN | | 105


| 3150 | 8
(13)| 00:00:01 |

| 2 | TABLE ACCESS BY INDEX ROWID| ORDERS | 105


| 1470 | 2
(0)| 00:00:01 |

|* 3 | INDEX RANGE SCAN | ORD_CUSTOMER_IX | 105


| | 1
(0)| 00:00:01 |

|* 4 | TABLE ACCESS FULL | CUSTOMERS | 111


| 1776 | 5

Oracle Database 11g: New Features for Administrators A - 146


Practice 8-2: Using an Encrypted Tablespace (continued)
(0)| 00:00:01 |

--------------------------------------------------------------
------------------
----------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Predicate Information (identified by operation id):


---------------------------------------------------

1 -
access("CUSTOMERS"."CUSTOMER_ID"="ORDERS"."CUSTOMER_ID")
3 - access("ORDERS"."CUSTOMER_ID">0)
4 - filter("ACCOUNT_MGR_ID"=145)
ble
SQL>
fe r a
SQL>
t r a ns
c) Move the accessed objects, the ORDERS table, the CUSTOMERS table,nand
o - the
ORD_CUSTOMER_IX index, to the encrypted tablespace.
s an
Use the ALTER TABLE … MOVE TABLESPACE ENCTS
r ) hacommand
e ฺ to move the
ORDERS and CUSTOMERS tables into the encrypted
m a Guid
ฺwith tablespace.
The ORD_CUSTOMER_IX index can be moved o enthe t ALTER INDEX …
ฺ c
REBUILD TABLESPACE ENCTS command.
a on tud
SQL>
l l e@ is S
SQL> connect oe/oeฺz i th
l o e
us MOVE TABLESPACE ENCTS;
Connected.
rce CUSTOMERS
SQL> ALTER aTABLE t o
l e (m ense
l
Zi altered.
Table lic
e l o
rc SQL> ALTER TABLE ORDERS MOVE TABLESPACE ENCTS;
Ma
Table altered.

SQL> ALTER INDEX ORD_CUSTOMER_IX REBUILD TABLESPACE ENCTS;

Index altered.

SQL>

d) With autotrace enabled, execute the query and examine the execution plan.
Verify that the ORD_CUSTOMER_IX index is being used. Connect as OE with the
password oe, set autotrace on, and run the query_orders_index.sql script.
Examine the execution plan. Notice that the ORD_CUSTOMER_IX index is being
accessed.
SQL> connect oe/oe
Connected.
SQL> set autotrace traceonly explain

Oracle Database 11g: New Features for Administrators A - 147


Practice 8-2: Using an Encrypted Tablespace (continued)
SQL> set echo on
SQL> @query_orders_index
SQL> select cust_last_name, order_id, order_total
2 from customers, orders
3 where customers.customer_id = orders.customer_id
4 and account_mgr_id = 145;
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Execution Plan
----------------------------------------------------------
Plan hash value: 3558567882

--------------------------------------------------------------
------------------
----------------
ble
| Id | Operation | Name | Rows
fe r a
| Bytes | Cost (%
ans
CPU)| Time |
n - t r
o
an
--------------------------------------------------------------
s
------------------
---------------- r ) ha deฺ
m ฺa Gui
| 0 | SELECT STATEMENT
n ฺ co |ent | 105
| 3150 |
(13)| 00:00:01 |
8
@ ao Stud
z i l le this
|* 1 | HASH JOIN
c e loฺ use | | 105
| 3150 | ar 8 t o
( m
(13)| 00:00:01 |e
s
Z ille licen
elo| 2 | TABLE ACCESS BY INDEX ROWID| ORDERS | 105

Marc | 1470 | 2
(0)| 00:00:01 |

|* 3 | INDEX RANGE SCAN | ORD_CUSTOMER_IX | 105


| | 1
(0)| 00:00:01 |

|* 4 | TABLE ACCESS FULL | CUSTOMERS | 111


| 1776 | 5
(0)| 00:00:01 |

--------------------------------------------------------------
------------------
----------------

Predicate Information (identified by operation id):


---------------------------------------------------

Oracle Database 11g: New Features for Administrators A - 148


Practice 8-2: Using an Encrypted Tablespace (continued)
1 -
access("CUSTOMERS"."CUSTOMER_ID"="ORDERS"."CUSTOMER_ID")
3 - access("ORDERS"."CUSTOMER_ID">0)
4 - filter("ACCOUNT_MGR_ID"=145)

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

e) Connect as the OE user with the oe password. Move the objects back to the
EXAMPLE tablespace, from the ENCTS tablespace, by executing the
cleanup.sql script.
SQL> connect oe/oe
Connected.
SQL> @cleanup
Connected. e
SQL>
r a bl
SQL> -- Move the OE.ORDERS table to EXAMPLE tablespace s fe
SQL> ALTER TABLE orders MOVE TABLESPACE EXAMPLE;
- t r an
Table altered. no n
a
s ฺ
SQL> ) h a e
SQL> -- Move the OE.CUSTOMERS table to ฺ a rEXAMPLE
u idtablespace
SQL> ALTER TABLE customers MOVE cTABLESPACE
ฺ om ent GEXAMPLE;
a on tud
Table altered.
l l e@ is S
i
ฺz se th
SQL> l
e ouo
SQL> -- Moverc the OE.ORD_CUSTOMER_IX
t index to the EXAMPLE
tablespace m a
( INDEX e
SQL>
i l l eALTER c e ns ORD_CUSTOMER_IX REBUILD TABLESPACE EXAMPLE;
l o Z li
rc e Index altered.
Ma Connected.

SQL> DROP TABLESPACE encts including contents and datafiles;

Tablespace dropped.

SQL>
SQL>
SQL> EXIT
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.0.2 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$

Oracle Database 11g: New Features for Administrators A - 149


Practices for Lesson 9

In this practice, you will manipulate SQL Performance Analyzer in an upgrade scenario
where you want to test some SQL statements before upgrading your 10g database.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 150


Practice 9-1: Using SQL Performance Analyzer
In this practice, you will export a SQL Tuning Set (STS) from your 10g database and
import it back into your 11g test environment. There you will access the performance of
the SQL statements that you imported before upgrading your 10g database.
1) From a terminal window, referred to as “first session,” execute the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

setup_SPAbig10g.sh script to set up your 10g environment.


$ cd /home/oracle/solutions/SPAbig
$ ./setup_SPAbig10g.sh
rm: cannot remove
`/u01/app/oracle/product/10.2.0/dbhome_1/rdbms/log/apps.dmp':
No such file or directory
rm: cannot remove
`/u01/app/oracle/product/10.2.0/dbhome_1/rdbms/log/appsandstag
ble
e.dmp': No such file or directory
fe r a
ans
SQL*Plus: Release 10.2.0.3.0 - Production on Fri Oct 2
08:53:20 2009 n - t r
a no
Copyright (c) 1982, 2006, Oracle. All Rights
h a s Reserved.

r ) i d e
Connected to an idle instance. m ฺa Gu
ฺ c o e n t
SQL> SQL> SQL> SQL> ORACLEainstance o n d
@ S tustarted.
Total System GlobalziArea l le 314572800
t h is bytes
l o ฺ e
Fixed Size
r c e o us 117440540 bytes
1261540
Variable Size
m a e t bytes
Database
l e ( ens
Buffers 192937984 bytes
Redol
Zi Buffers lic 2932736 bytes
e l oDatabase mounted.
rc Database opened.
Ma SQL> SQL> BEGIN dbms_sqltune.drop_sqlset('STS_JFV','SYSTEM');
END;

*
ERROR at line 1:
ORA-13754: "SQL Tuning Set" "STS_JFV" does not exist for user
"SYSTEM".
ORA-06512: at "SYS.DBMS_SQLTUNE_INTERNAL", line 4672
ORA-06512: at "SYS.DBMS_SQLTUNE", line 2795
ORA-06512: at line 1

SQL> SQL> drop user apps cascade


*
ERROR at line 1:
ORA-01918: user 'APPS' does not exist

SQL> SQL>
Import: Release 10.2.0.3.0 - Production on Friday, 02 October,
2009 8:53:44

Oracle Database 11g: New Features for Administrators A - 151


Practice 9-1: Using SQL Performance Analyzer (continued)

Copyright (c) 2003, 2005, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release


10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully


loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/********
directory=DATA_PUMP_DIR dumpfile=apps.dmp
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
ble
Processing object type SCHEMA_EXPORT/TABLE/TABLE
fe r a
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
ans
. . imported "APPS"."FACT_PD_OUT_ITM_293"
MB 1501663 rows
175.0
n - t r
o
. . imported "APPS"."ADM_PG_FEATUREVALUE"
s an14.26
MB 172392 rows
. . imported "APPS"."LU_ELEMENTGROUP_REL" r ) ha deฺ3.477
MB 84468 rows m ฺa Gui
. . imported "APPS"."LU_OUTLET_293"
n ฺ co ent 3.398
MB 22289 rows
. . imported "APPS"."LU_ITEM_293"@ ao Stud 1.274
MB 5355 rows z i l le this
c e loฺ use
. . imported "APPS"."LU_ELEMENTRANGE_REL" 779.3
KB 8155 rows
a r to
m e
KBi l l e ( icens
. . imported "APPS"."LU_ELEMENTRANGE_REL_Q2"
8155 rows
779.3

el oZ l
. . imported "APPS"."ADM_CC_FEATUREVALUE" 248.5

Marc KB 3047 rows


. . imported "APPS"."LU_PG_FEATUREVALUE_15_Q2" 122.8
KB 2505 rows
. . imported "APPS"."LU_PERIOD_293" 8.031
KB 31 rows
. . imported "APPS"."PLAN_TABLE" 0
KB 0 rows
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type
SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type
SCHEMA_EXPORT/TABLE/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
Processing object type
SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/IND
EX_STATISTICS
Processing object type
SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at
17:22:24

Oracle Database 11g: New Features for Administrators A - 152


Practice 9-1: Using SQL Performance Analyzer (continued)

SQL> SQL>
LAST_ANAL
---------
04-JUL-07
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

04-JUL-07
04-JUL-07
04-JUL-07
04-JUL-07
04-JUL-07
04-JUL-07

8 rows selected.
ble
SQL> SQL>
fe r a
PL/SQL procedure successfully completed.
t r a ns
SQL> SQL> Disconnected from Oracle Database 10g Enterprise o n -
Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Miningaoptions s an
$ r ) h deฺ
m ฺa Gui
2) Before you can use the SQL Performance Analyzer
n ฺ co This t upgrade scenario, you
innthis
e
must patch your 10g database with patch
a o 6903335.
t u d patch is currently staged in
your /stage directory and isecalled
l i s S
@ p6903335_10203_GENERIC.zip. Apply
i l h
t continuing this practice.
that patch to your db10g
e l oฺzdatabase
u s ebefore
rc o
$ cd /home/oracle/solutions/SPAbig
a t
$ ls /stage
l e (m e n se
Z l
i -r 6903335
10.2.0 10.2.0.3_patchset
l i c 11.2.0 p6903335_10203_GENERIC.zip
lo$ rm
rce $ unzip /stage/p6903335_10203_GENERIC.zip
Ma Archive: /stage/p6903335_10203_GENERIC.zip
creating: 6903335/
creating: 6903335/files/
creating: 6903335/files/rdbms/
creating: 6903335/files/rdbms/admin/
inflating: 6903335/files/rdbms/admin/prvtspao.plb
creating: 6903335/etc/
creating: 6903335/etc/config/
inflating: 6903335/etc/config/inventory
inflating: 6903335/etc/config/actions
creating: 6903335/etc/xml/
inflating: 6903335/etc/xml/GenericActions.xml
inflating: 6903335/etc/xml/ShiphomeDirectoryStructure.xml
inflating: 6903335/README.txt
$ ls
6903335 bench80.sh exportapps.sh movedmp.sh
setup_SPAbig10g.sh stop_orcl.sh wrkl10g_jfv.sh
apps.dmp capsts10g.sh importapps.sh new_wrkl10g_jfv.sh
stage_sts.sh unpack_sts.sh

Oracle Database 11g: New Features for Administrators A - 153


Practice 9-1: Using SQL Performance Analyzer (continued)
$ cd 6903335
$ . oraenv
ORACLE_SID = [orcl] ? db10g
The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/10.2.0/dbhome_1 is
/u01/app/oracle
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

$ export PATH=$PATH:$ORACLE_HOME/OPatch
$ echo $PATH
/u01/app/oracle/product/10.2.0/dbhome_1/bin:/usr/java/jdk1.5.0
_11/bin:/bin:/home/oracle/bin:/usr/bin:/usr/local/bin:/usr/X11
R6/bin:/u01/app/oracle/product/10.2.0/dbhome_1/OPatch:/u01/app
/oracle/product/10.2.0/dbhome_1/OPatch
$ opatch lsinventory
Invoking OPatch 10.2.0.3.0
ble
Oracle interim Patch Installer version 10.2.0.3.0
fe r a
Copyright (c) 2005, Oracle Corporation. All rights reserved..
ans
n - t r
Oracle Home no
: /u01/app/oracle/product/10.2.0/dbhome_1
a
Central Inventory : /u01/app/oraInventory
h a s ฺ
from
OPatch version
: /etc/oraInst.loc
: 10.2.0.3.0 ฺ a r) uide
OUI version : 10.2.0.3.0 ฺ c om ent G
OUI location : a on tud
l l e@ is S
/u01/app/oracle/product/10.2.0/dbhome_1/oui
Log file location : i
ฺz se th
l o
/u01/app/oracle/product/10.2.0/dbhome_1/cfgtoollogs/opatch/
rce to u
opatch2009-10-02_08-59-45AM.log
a
l e (m ense
Zi l
Lsinventory
licOutput file location :
e l o/u01/app/oracle/product/10.2.0/dbhome_1/cfgtoollogs/opatch/
rc lsinventory2009-10-02_08-59-45AM.txt
Ma --------------------------------------------------------------
------------------
Installed Top-level Products (2):

Oracle Database 10g


10.2.0.1.0
Oracle Database 10g Release 2 Patch Set 2
10.2.0.3.0
There are 2 products installed in this Oracle Home.

Interim patches (2) :

Patch 5556081 : applied on Fri May 08 17:54:39 UTC 2009


Created on 9 Nov 2006, 22:20:50 hrs PST8PDT
Bugs fixed:
5556081

Patch 5557962 : applied on Fri May 08 17:54:31 UTC 2009


Created on 9 Nov 2006, 23:23:06 hrs PST8PDT

Oracle Database 11g: New Features for Administrators A - 154


Practice 9-1: Using SQL Performance Analyzer (continued)
Bugs fixed:
4269423, 5557962, 5528974

--------------------------------------------------------------
------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

OPatch succeeded.
$ opatch apply
Invoking OPatch 10.2.0.3.0

Oracle interim Patch Installer version 10.2.0.3.0


Copyright (c) 2005, Oracle Corporation. All rights reserved..

Oracle Home : /u01/app/oracle/product/10.2.0/dbhome_1


ble
Central Inventory : /u01/app/oraInventory
fe r a
from : /etc/oraInst.loc
ans
OPatch version
OUI version
: 10.2.0.3.0
: 10.2.0.3.0 n - t r
OUI location : a no
/u01/app/oracle/product/10.2.0/dbhome_1/oui
h a s ฺ
Log file location :
ฺ a r) uide
/u01/app/oracle/product/10.2.0/dbhome_1/cfgtoollogs/opatch/
opatch2009-10-02_09-01-54AM.log ฺ c om ent G
a on tud
ApplySession applying interim
l e S '6903335' to OH
@ ispatch
i l h
oฺz use t
'/u01/app/oracle/product/10.2.0/dbhome_1'
e l
OPatch detecteda rc non-cluster
tosystem Oracle Home from the inventory and
m e
i l l e ( icens
will patch the local only.

l o Z l
rc e Please shutdown Oracle instances running out of this
Ma ORACLE_HOME on the local system.
(Oracle Home = '/u01/app/oracle/product/10.2.0/dbhome_1')

Is the local system ready for patching?

Do you want to proceed? [y|n]


n
User Responded with: N
ApplySession exits on request
ApplySession system modification phase did not start: Oracle
Home is not modified. ApplySession exits on request
System intact, OPatch will not attempt to restore the system

OPatch stopped on request.


$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.3.0 - Production on Fri Oct 2


09:03:47 2009

Oracle Database 11g: New Features for Administrators A - 155


Practice 9-1: Using SQL Performance Analyzer (continued)
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 -
Production
With the Partitioning, OLAP and Data Mining options
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> shutdown immediate;


Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition
Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
ble
$
fe r a
$ opatch apply s
Invoking OPatch 10.2.0.3.0
- t r an
no n
Oracle interim Patch Installer version 10.2.0.3.0 a
a s ฺ
Copyright (c) 2005, Oracle Corporation. All rights reserved..
h
Oracle Home ฺ a r) uide
: /u01/app/oracle/product/10.2.0/dbhome_1
c
Central Inventory : /u01/app/oraInventory
ฺ om ent G
from on tud
: /etc/oraInst.loc
a
OPatch version
OUI version l le@ this S
: 10.2.0.3.0
:zi10.2.0.3.0
OUI location elo :
ฺ se
r c to u
/u01/app/oracle/product/10.2.0/dbhome_1/oui
m a e
Log file
i l l e ( icens
location :
/u01/app/oracle/product/10.2.0/dbhome_1/cfgtoollogs/opatch/
l Z l
oopatch2009-10-02_09-04-59AM.log
e
Marc ApplySession applying interim patch '6903335' to OH
'/u01/app/oracle/product/10.2.0/dbhome_1'

OPatch detected non-cluster Oracle Home from the inventory and


will patch the local system only.

Please shutdown Oracle instances running out of this


ORACLE_HOME on the local system.
(Oracle Home = '/u01/app/oracle/product/10.2.0/dbhome_1')

Is the local system ready for patching?

Do you want to proceed? [y|n]


y
User Responded with: Y
Backing up files and inventory (not for auto-rollback) for the
Oracle Home
Backing up files affected by the patch '6903335' for restore.
This might take a while...

Oracle Database 11g: New Features for Administrators A - 156


Practice 9-1: Using SQL Performance Analyzer (continued)
Backing up files affected by the patch '6903335' for rollback.
This might take a while...

Patching component oracle.rdbms, 10.2.0.3.0...


Copying file to
"/u01/app/oracle/product/10.2.0/dbhome_1/rdbms/admin/prvtspao.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

plb"
ApplySession adding interim patch '6903335' to inventory

Verifying the update...


Inventory check OK: Patch ID 6903335 is registered in Oracle
Home inventory with proper meta-data.
Files check OK: Files from Patch ID 6903335 are present in
Oracle Home.
ble
The local system has been patched and can be restarted.
fe r a
ans
OPatch succeeded.
$ n - t r
$ opatch lsinventory a no
Invoking OPatch 10.2.0.3.0
h a s ฺ
Oracle interim Patch Installer version ฺ a )
u ide
r10.2.0.3.0
Copyright (c) 2005, Oracle Corporation.
ฺ c om entAll G rights reserved..
a on tud
Oracle Home
le@ this S
: /u01/app/oracle/product/10.2.0/dbhome_1
l
Central Inventory :zi/u01/app/oraInventory
from
c e loฺ: /etc/oraInst.loc
u se
OPatch version
a r :to
10.2.0.3.0
m e
( ens 10.2.0.3.0
OUI version :
l l e
OUIi location
l o Z lic :
/u01/app/oracle/product/10.2.0/dbhome_1/oui
rc e Log file location :
Ma /u01/app/oracle/product/10.2.0/dbhome_1/cfgtoollogs/opatch/
opatch2009-10-02_09-06-47AM.log

Lsinventory Output file location :


/u01/app/oracle/product/10.2.0/dbhome_1/cfgtoollogs/opatch/
lsinventory2009-10-02_09-06-47AM.txt

--------------------------------------------------------------
------------------
Installed Top-level Products (2):

Oracle Database 10g


10.2.0.1.0
Oracle Database 10g Release 2 Patch Set 2
10.2.0.3.0
There are 2 products installed in this Oracle Home.

Interim patches (3) :

Oracle Database 11g: New Features for Administrators A - 157


Practice 9-1: Using SQL Performance Analyzer (continued)
Patch 6903335 : applied on Fri Oct 02 09:05:29 UTC 2009
Created on 12 May 2008, 08:56:41 hrs US/Pacific
Bugs fixed:
6903335

Patch 5556081 : applied on Fri May 08 17:54:39 UTC 2009


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Created on 9 Nov 2006, 22:20:50 hrs PST8PDT


Bugs fixed:
5556081

Patch 5557962 : applied on Fri May 08 17:54:31 UTC 2009


Created on 9 Nov 2006, 23:23:06 hrs PST8PDT
Bugs fixed:
4269423, 5557962, 5528974
ble
--------------------------------------------------------------
fe r a
------------------
ans
OPatch succeeded. n - t r
$ a no
$ sqlplus / as sysdba
h a s ฺ
SQL*Plus: Release 10.2.0.3.0 - Production ฺ a ideOct 2
r) on uFri
09:11:38 2009 ฺ c om ent G
a on tud
Copyright (c) 1982, 2006,
l e@Oracle. i s S All Rights Reserved.
i l t h
Connected to an e l oฺz instance.
idle
u s e
a rc t o
l e (m ense
SQL> startup
l
Zi instance
ORACLE
lic started.
e l o
rc Total System Global Area 314572800 bytes
Ma Fixed Size 1261540 bytes
Variable Size 138412060 bytes
Database Buffers 171966464 bytes
Redo Buffers 2932736 bytes
Database mounted.
Database opened.
SQL> drop table plan_table$;

Table dropped.

SQL> @?/rdbms/admin/catplan.sql
create type dbms_xplan_type
*
ERROR at line 1:
ORA-00955: name is already used by an existing object

create type dbms_xplan_type_table


*
ERROR at line 1:

Oracle Database 11g: New Features for Administrators A - 158


Practice 9-1: Using SQL Performance Analyzer (continued)
ORA-00955: name is already used by an existing object

Grant succeeded.

Grant succeeded.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

create type sql_plan_row_type


*
ERROR at line 1:
ORA-00955: name is already used by an existing object

Synonym created.

Grant succeeded.
ble
create type sql_plan_table_type
fe r a
*
ans
ERROR at line 1:
ORA-00955: name is already used by an existing object n - t r
a no
Synonym created.
h a s ฺ
Grant succeeded. ฺ a r) uide
ฺ c om ent G
create sequence ora_plan_id_seq$ a on tud
ERROR at line 1: zill
*
e@ this S
ORA-00955: name e oฺ already
lis u se used by an existing object
a r c to
m e
i l l e ( icens
Table created.

l o Z l
Grant succeeded.
rc e
Ma Synonym created.

create type sql_plan_stat_row_type


*
ERROR at line 1:
ORA-00955: name is already used by an existing object

Synonym created.

Grant succeeded.

Library created.

No errors.

Library created.

Package created.

Oracle Database 11g: New Features for Administrators A - 159


Practice 9-1: Using SQL Performance Analyzer (continued)

Synonym created.

Grant succeeded.

Package body created.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

No errors.
SQL>
SQL> @?/rdbms/admin/dbmsxpln.sql

Library created.

No errors.
ble
Library created.
fe r a
ans
Package created.
n - t r
o
Synonym created.
s an
Grant succeeded. r ) ha deฺ
m ฺa Gui
SQL>
n ฺ co ent
SQL> @?/rdbms/admin/prvtxpln.plb
@ ao Stud
Package body created. z i l le this
c e loฺ use
No errors. ar to
SQL> m
( ens e
i l l e@?/rdbms/admin/prvtspao.plb
l o
SQL>
Z lic
rc e PL/SQL procedure successfully completed.
Ma
Package created.

No errors.

Synonym created.

No errors.

Package body created.

No errors.
SQL>
SQL> grant all on dbms_sqlpa to system;

Grant succeeded.

SQL>
SQL> exit

Oracle Database 11g: New Features for Administrators A - 160


Practice 9-1: Using SQL Performance Analyzer (continued)
Disconnected from Oracle Database 10g Enterprise Edition
Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
$
3) Before creating an STS from within your 10g environment, stop Enterprise Manager
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Database Control and shut down your 11g database instance orcl. This is done to
save resources on your system. Use the stop_orcl.sh script to execute this step.
Note that this script is also cleaning up possible previous executions of this practice
on your orcl database.
$ cd /home/oracle/solutions/SPAbig
$ ./stop_orcl.sh
rm: cannot remove
`/u01/app/oracle/admin/orcl/dpdump/appsandstage.dmp': No such
ble
file or directory
fe r a
Oracle Enterprise Manager 11g Database Control Release
ans
11.2.0.1.0
n - t r
Copyright (c) 1996, 2009 Oracle Corporation. All rights
reserved. a no
https://ed.us.oracle.com:5500/em/console/aboutApplication
h a s ฺ
... Stopped. ฺ a r) uide
Stopping Oracle Enterprise Manager 11g Database Control ...

ฺ c om ent G
SQL*Plus: Release 11.2.0.1.0 a n ud on Fri Oct 2 10:59:06
oProduction
2009 @ S t
Copyright (c) 1982, z e
ll Oracle.
i2009, t hi s All rights reserved.
l o ฺ s e
Connected to:a rce to u
(m ens11g
Oracle Database e Enterprise Edition Release 11.2.0.1.0 -
l l e
l o Zi
Production
lic
With the Partitioning, Automatic Storage Management, OLAP,
rc e Data Mining and Real Application Testing options
Ma
SQL> SQL> SQL> SQL> BEGIN
dbms_sqlpa.drop_analysis_task('SPA_JFV1'); END;

*
ERROR at line 1:
ORA-13605: The specified task or object SPA_JFV1 does not
exist for the current
user.
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "SYS.PRVT_ADVISOR", line 5827
ORA-06512: at "SYS.DBMS_SQLPA", line 400
ORA-06512: at line 1

SQL> SQL> BEGIN dbms_sqlpa.drop_analysis_task('SPA_JFV2');


END;

*
ERROR at line 1:

Oracle Database 11g: New Features for Administrators A - 161


Practice 9-1: Using SQL Performance Analyzer (continued)
ORA-13605: The specified task or object SPA_JFV2 does not
exist for the current
user.
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "SYS.PRVT_ADVISOR", line 5827
ORA-06512: at "SYS.DBMS_SQLPA", line 400
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ORA-06512: at line 1

SQL> SQL> BEGIN dbms_sqltune.drop_sqlset('STS_JFV','SYSTEM');


END;

*
ERROR at line 1:
ORA-13754: "SQL Tuning Set" "STS_JFV" does not exist for user
"SYSTEM".
ble
ORA-06512: at "SYS.DBMS_SQLTUNE_INTERNAL", line 11567
fe r a
ORA-06512: at "SYS.DBMS_SQLTUNE", line 3118
ans
ORA-06512: at line 1
n - t r
SQL> SQL> drop user apps cascade a no
*
h a s ฺ
ERROR at line 1:
ORA-01918: user 'APPS' does not exist ฺ a r) uide
ฺ c om ent G
SQL> SQL> Database closed.aon
Database dismounted. @ S tud
ORACLE instance shut z i l le this
down.
loฺ ufrom
SQL> SQL> Disconnected
c e se Oracle Database 11g Enterprise
Edition Release
a r 11.2.0.1.0
to Automatic
- Production
With the m
( ens e
Partitioning, Storage Management, OLAP,
l l e
l o$
Zi Mining
Data
licand Real Application Testing options
e
rc 4)
Ma (Do steps 4 and 5 at the same time.) Generate a SQL Tuning Set (STS) called
STS_JFV that captures SQL statements from the cursor cache for approximately
twelve minutes every five seconds. Make sure that you try to capture only statements
that come out of the SQL_JFV module in the APPS schema. Also this STS should
belong to SYSTEM user. Use the capsts10g.sh script to perform that step.
$ cd /home/oracle/solutions/SPAbig
$ ./capsts10g.sh

SQL*Plus: Release 10.2.0.3.0 - Production on Fri Oct 2


12:13:57 2009

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 -
Production
With the Partitioning, OLAP and Data Mining options

Oracle Database 11g: New Features for Administrators A - 162


Practice 9-1: Using SQL Performance Analyzer (continued)
SQL> SQL> SQL> SQL> SQL> 2 3 4 5 6 7 8
9 10 11
PL/SQL procedure successfully completed.

Elapsed: 00:09:04.90
SQL> No errors.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> SQL> Disconnected from Oracle Database 10g Enterprise


Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
$
5) (Do steps 4 and 5 at the same time.) From a second terminal window, connected as
the oracle user, execute your workload using the wrkl10g_jfv.sh script. This
script runs a workload of 45 statements that are going to be captured in STS_JFV
automatically.
ble
$ cd /home/oracle/solutions/SPAbig fe r a
$ an s
$ ./wrkl10g_jfv.sh n - t r
a no
SQL*Plus: Release 10.2.0.3.0 - Production on
h a sFri Oct
ฺ 2
12:14:27 2009
ฺ a r) uide
Copyright (c) 1982, 2006, Oracle. ฺ c omAlleRights
n t G Reserved.
a on tud
Connected to: S
le@ thisEdition
ฺ l
Oracle Database 10gziEnterprise Release 10.2.0.3.0 -
Production l o s e
rce to uOLAP and Data Mining options
With the Partitioning,
a
l e (mSQL> e n se
SQL>l
Zi altered.
SQL>
lic
e l oSystem
rc
Ma SQL>
System altered.

SQL> SQL> SQL> SQL> Connected.


SQL> SQL> SQL> SQL>
Session altered.

SQL> SQL> SQL> SQL> SQL> SQL> @Start 2009:OCT-02:12:15:26

SQL> SQL> SQL> SQL> SQL> SQL> SQL>


System altered.

SQL> SQL> SQL> @Statement 1


SQL>
PL/SQL procedure successfully completed.

SQL> SQL> SQL> 2 3 4 5 6 7 8 9 10


11 12 13 14
Elapsed: 00:00:00.39

Oracle Database 11g: New Features for Administrators A - 163


Practice 9-1: Using SQL Performance Analyzer (continued)

Statistics
----------------------------------------------------------
957 recursive calls
0 db block gets
292 consistent gets
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

146 physical reads


188 redo size
427 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
18 sorts (memory)
0 sorts (disk)
1 rows processed
ble
SQL> @1 Results in 15 Ticks
fe r a
SQL> SQL> SQL> SQL> @Statement 2
10n
a s
SQL> SQL> SQL>
11 12 13 14
2 3 4 5 6 7 8 9
n- t r
Elapsed: 00:00:00.01 a no
h a s ฺ
Statistics
ฺ a r) uide
----------------------------------------------------------
8 recursive calls ฺ c om ent G
0 db block getsaon
120 consistent @ gets S tud
9 physicalz i l lereadsthis
0 redo
c e loฺsizeuse
428ar bytes tsent
o via SQL*Net to client
m
( ens
400 bytese received via SQL*Net from client
i l l e
l oZ li20c SQL*Net roundtrips to/from client
sorts (memory)
e
Marc 0
1
sorts (disk)
rows processed

SQL> @1 Results in 0 Ticks


SQL> SQL> SQL> SQL> @Statement 3
SQL> SQL> SQL> 2 3 4 5 6 7 8 9 10
11 12 13 14
Elapsed: 00:00:00.03

Statistics
----------------------------------------------------------
8 recursive calls
0 db block gets
120 consistent gets
16 physical reads
0 redo size
428 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)

Oracle Database 11g: New Features for Administrators A - 164


Practice 9-1: Using SQL Performance Analyzer (continued)
0 sorts (disk)
1 rows processed

SQL> @1 Results in 16 Ticks


SQL> SQL> SQL> SQL> @Statement 4
SQL> SQL> SQL> 2 3 4 5 6 7 8 9 10
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

11 12 13 14
Elapsed: 00:00:00.30

Statistics
----------------------------------------------------------
470 recursive calls
0 db block gets
598 consistent gets
528 physical reads
ble
72 redo size
fe r a
427 bytes sent via SQL*Net to client
an s
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client n - t r
14 sorts (memory) a no
0 sorts (disk)
h a s ฺ
1 rows processed
ฺ a r) uide
SQL> @1 Results in 0 Ticks ฺ c om ent G
SQL> SQL> SQL> SQL> @Statement a on 5 tud
SQL> SQL> SQL>
11 12 13
2
14 zill
e3 @ t4his S 5 6 7 8 9 10

Elapsed: 00:00:00.02
c e loฺ use
a r to
m e
i l e ( icens
Statistics
l
----------------------------------------------------------
l o Z l8 recursive calls
rc e 0 db block gets
Ma 525 consistent gets
9 physical reads
0 redo size
428 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed

SQL> @10 Results in 1188 Ticks


SQL> SQL> SQL> SQL>
PL/SQL procedure successfully completed.

SQL> SQL> we are done


SQL> SQL> SQL> SQL> @End 2009:OCT-02:12:18:16

Oracle Database 11g: New Features for Administrators A - 165


Practice 9-1: Using SQL Performance Analyzer (continued)
SQL> SQL> SQL> Disconnected from Oracle Database 10g
Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
$
6) After approximately five minutes, both sessions should be finished. Check the content
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

of STS_JFV, and stage it in a table called APPS.STS_JFV_TAB. Use the


stage_sts.sh script to perform this step.
$ cd /home/oracle/solutions/SPAbig
$ ./stage_sts.sh

SQL*Plus: Release 10.2.0.3.0 - Production on Fri Oct 2


12:25:05 2009

Copyright (c) 1982, 2006, Oracle. All Rights Reserved. ble


fe r a
Connected to: ans
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - n - t r
o
Production
With the Partitioning, OLAP and Data Mining options s an
r ) ha deฺ
SQL> SQL> SQL> SQL>
m ฺa Gui
NAME
n ฺ co ent
STATEMENT_COUNT
------------------------------
STS_JFV @ ao Stud ---------------
33
l l e i s
SQL> SQL> drop tablel o ฺzi apps.sts_jfv_tab
s e th purge
c e
r * to u
a
ERROR at
l e m
line
( table
e
1:
n seor view does not exist
Zi l
ORA-00942:
lic
l o
e SQL> SQL>
rc
Ma PL/SQL procedure successfully completed.

SQL> SQL>
PL/SQL procedure successfully completed.

SQL> SQL> Disconnected from Oracle Database 10g Enterprise


Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
$

7) Using Data Pump export, export the APPS schema to the default Data Pump 10g
directory. Use the exportapps.sh script to perform this step.
$ cd /home/oracle/solutions/SPAbig
$ ./exportapps.sh

SQL*Plus: Release 10.2.0.3.0 - Production on Fri Oct 2


12:26:40 2009

Oracle Database 11g: New Features for Administrators A - 166


Practice 9-1: Using SQL Performance Analyzer (continued)
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 -
Production
With the Partitioning, OLAP and Data Mining options
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> SQL>
Table dropped.

SQL> SQL> Disconnected from Oracle Database 10g Enterprise


Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
rm: cannot remove
`/u01/app/oracle/product/10.2.0/dbhome_1/rdbms/log/appsandstag
ble
e.dmp': No such file or directory
fe r a
ans
Export: Release 10.2.0.3.0 - Production on Friday, 02 October,
2009 12:26:41 n - t r
a no
Copyright (c) 2003, 2005, Oracle. All rights
h a s reserved.

r ) i d e
Connected to: Oracle Database 10g Enterprise m ฺa GuEdition Release
10.2.0.3.0 - Production ฺ c o e n t
n
With the Partitioning, OLAP
@ aoand S
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01":
tudMiningsystem/********
Data options

directory=DATA_PUMP_DIR z i l le dumpfile=appsandstage
t h is schemas=apps
Estimate in progressl o ฺ using s e BLOCKS method...
rce type
Processing aobject t o uSCHEMA_EXPORT/TABLE/TABLE_DATA
l e (m enseusing BLOCKS method: 240.5 MB
Total estimation
Zi l
Processing
licobject type SCHEMA_EXPORT/USER
el oProcessing object type SCHEMA_EXPORT/SYSTEM_GRANT

Marc Processing object type SCHEMA_EXPORT/ROLE_GRANT


Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type
SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type
SCHEMA_EXPORT/TABLE/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
Processing object type
SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/IND
EX_STATISTICS
Processing object type
SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "APPS"."FACT_PD_OUT_ITM_293" 175.0
MB 1501663 rows
. . exported "APPS"."ADM_PG_FEATUREVALUE" 14.26
MB 172392 rows

Oracle Database 11g: New Features for Administrators A - 167


Practice 9-1: Using SQL Performance Analyzer (continued)
. . exported "APPS"."LU_ELEMENTGROUP_REL" 3.477
MB 84468 rows
. . exported "APPS"."LU_OUTLET_293" 3.398
MB 22289 rows
. . exported "APPS"."LU_ITEM_293" 1.274
MB 5355 rows
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

. . exported "APPS"."LU_ELEMENTRANGE_REL" 779.3


KB 8155 rows
. . exported "APPS"."LU_ELEMENTRANGE_REL_Q2" 779.3
KB 8155 rows
. . exported "APPS"."STS_JFV_TAB_CPLANS" 254.8
KB 570 rows
. . exported "APPS"."STS_JFV_TAB" 80.05
KB 33 rows
. . exported "APPS"."ADM_CC_FEATUREVALUE" 248.5
ble
KB 3047 rows
fe r a
. . exported "APPS"."LU_PG_FEATUREVALUE_15_Q2" 122.8
an s
KB 2505 rows
. . exported "APPS"."STS_JFV_TAB_CBINDS" 9.484 n - t r
KB 0 rows a no
. . exported "APPS"."LU_PERIOD_293"
h a s ฺ 8.031
KB 31 rows
ฺ a r) uide
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully
loaded/unloaded ฺ c om ent G
on tud
**************************************************************
a
****************
l l e@ is S
i
ฺz se th
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
l o
rce to u
/u01/app/oracle/product/10.2.0/dbhome_1/rdbms/log/appsandstage
a
.dmp
l e (m ense
Z l
Jobi "SYSTEM"."SYS_EXPORT_SCHEMA_01"
lic successfully completed at
e l o12:27:24
rc
Ma $
8) Make sure that you copy the generated dump file from the default Data Pump 10g
directory to the default Data Pump 11g directory. Use the movedmp.sh script to
perform this step.
$ cd /home/oracle/solutions/SPAbig
$ ./movedmp.sh

9) Start your 11g environment including your database instance and Enterprise Manager
Database Control.
$ . oraenv
ORACLE_SID = [db10g] ? orcl
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 2 12:30:37


2009

Oracle Database 11g: New Features for Administrators A - 168


Practice 9-1: Using SQL Performance Analyzer (continued)
Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Total System Global Area 422670336 bytes


Fixed Size 1336960 bytes
Variable Size 293603712 bytes
Database Buffers 121634816 bytes
Redo Buffers 6094848 bytes
Database mounted.
Database opened.
SQL> exit
ble
Disconnected from Oracle Database 11g Enterprise Edition
fe r a
Release 11.2.0.1.0 - Production
ans
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options n - t r
o
$ emctl start dbconsole
s an
11.2.0.1.0 r ) ha deฺ
Oracle Enterprise Manager 11g Database Control Release

ฺa Gui
Copyright (c) 1996, 2009 Oracle Corporation. All rights
m
reserved.
n ฺ co ent
@ ao Stud
https://...:5500/em/console/aboutApplication
Starting Oracle Enterprise Manager 11g Database Control
................ started.z i l le this
c e loฺ use
--------------------------------------------------------------
r to
Logs are generated in directory
a
m e
i l
an/log e ( icens
/u01/app/oracle/acfsmounts/acfs_db1/ed.us.oracle.com_orcl/sysm
l
eloZ
$
l
r c
a 10) By using Data Pump import, import the APPS schema into your 11g system. Use
M
importapps.sh script to perform that step. You can safely ignore the following
errors. They are due to some conversion errors.
$ cd /home/oracle/solutions/SPAbig
$ ./importapps.sh

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 2 12:39:21


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining
and Real Application Testing options

Oracle Database 11g: New Features for Administrators A - 169


Practice 9-1: Using SQL Performance Analyzer (continued)
SQL> SQL> drop user apps cascade
*
ERROR at line 1:
ORA-01918: user 'APPS' does not exist

SQL> SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Import: Release 11.2.0.1.0 - Production on Friday, 02 October,


2009 12:40:30

Copyright (c) 2003, 2007, Oracle. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release


11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
ble
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully
fe r a
loaded/unloaded
ans
Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/********
directory=DATA_PUMP_DIR dumpfile=appsandstage n - t r
o
Processing object type SCHEMA_EXPORT/USER
s an
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANTr ) ha deฺ
ฺa Gui
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
m
n ฺ co ent
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA

@ ao Stud
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
i l le this
. . imported "APPS"."FACT_PD_OUT_ITM_293"
z 175.0
MB 1501663 rows
c e loฺ use
r to
. . imported "APPS"."ADM_PG_FEATUREVALUE"
a 14.26
m e
i l e ( icens
MB 172392 rows
l
. . imported "APPS"."LU_ELEMENTGROUP_REL" 3.477
el oZ
MB
l
84468 rows

Marc . . imported "APPS"."LU_OUTLET_293"


MB 22289 rows
3.398

. . imported "APPS"."LU_ITEM_293" 1.274


MB 5355 rows
ORA-02374: conversion error loading table
"APPS"."LU_ELEMENTRANGE_REL"
ORA-12899: value too large for column ELEMENTRANGE_SDESC
(actual: 16, maximum: 15)

ORA-02372: data for row: ELEMENTRANGE_SDESC :


0X'32302C3031202D2033302C303020BF'

ORA-02374: conversion error loading table


"APPS"."LU_ELEMENTRANGE_REL"
ORA-12899: value too large for column ELEMENTRANGE_SDESC
(actual: 16, maximum: 15)

ORA-02372: data for row: ELEMENTRANGE_SDESC :


0X'33302C3031202D2034302C303020BF'

Oracle Database 11g: New Features for Administrators A - 170


Practice 9-1: Using SQL Performance Analyzer (continued)

. . imported "APPS"."LU_ELEMENTRANGE_REL_Q2" 779.3


KB 7957 out of 8155 rows
. . imported "APPS"."STS_JFV_TAB_CPLANS" 254.8
KB 570 rows
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

. . imported "APPS"."STS_JFV_TAB" 80.05


KB 33 rows
. . imported "APPS"."ADM_CC_FEATUREVALUE" 248.5
KB 3047 rows
. . imported "APPS"."LU_PG_FEATUREVALUE_15_Q2" 122.8
KB 2505 rows
. . imported "APPS"."STS_JFV_TAB_CBINDS" 9.484
KB 0 rows
. . imported "APPS"."LU_PERIOD_293" 8.031
ble
KB 31 rows
fe r a
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
ans
Processing object type
SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS n - t r
Processing object type SCHEMA_EXPORT/VIEW/VIEW a no
Processing object type
h a s ฺ
Processing object type ฺ a r) uide
SCHEMA_EXPORT/TABLE/INDEX/FUNCTIONAL_AND_BITMAP/INDEX

c om ent G
SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/IND

EX_STATISTICS a on tud
Processing object type
l l e@ is S
i
ฺz se th
SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
l o
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at
12:42:30 a rce to u
l e (m ense
SQL>l
Zi SQL> liDisconnected
c from Oracle Database 11g Enterprise
e l oEdition Release 11.2.0.1.0 - Production
rc With the Partitioning, Automatic Storage Management, OLAP,
Ma Data Mining and Real Application Testing options
$

11) Unpack the previously imported staging table in the SYSTEM schema. Use the
unpack_sts.sh script to perform that step.
$ cd /home/oracle/solutions/SPAbig
$ ./unpack_sts.sh

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 2 12:46:29


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production

Oracle Database 11g: New Features for Administrators A - 171


Practice 9-1: Using SQL Performance Analyzer (continued)
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> SQL> SQL> SQL>


PL/SQL procedure successfully completed.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> SQL>
System altered.

SQL>
System altered.

SQL> SQL> Disconnected from Oracle Database 11g Enterprise


Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
ble
Data Mining and Real Application Testing options
fe r a
$
t r a ns
12) Use NETCA to create a TNS entry for your db10g database instances.n
o - must
You
perform that from the 11g database home.
s an
a) From a graphical terminal session, set your environment
r ) havariables
d e ฺ to point to your
ฺa Gu
11g installation. Then execute the netca command: i
c o m n t
$ . oraenv n ฺ e
ORACLE_SID = [db10g] ? orcl
@ ao Stud
$ netca
z i l le this
c e loฺ use
a
b) On the Welcome r page,toselect the Local Net Service Name configuration, and
click
l e ( ense
m
Next.
i l licService Name Configuration page, select Add, and click Next.
l oc)ZOn the Net
rce
Ma d) On the Service name configuration page, enter db10g in the Service name field.
Then click Next.
e) On the Select Protocol page, select TCP, and click Next.
f) On the TCP/IP Protocol page, enter your host name in the Host name field. Use
the hostname command from a terminal window to get the exact name.
Make sure that the port number used is 1521.
Then click Next.
g) On the Test page, select Yes, and click Next.
h) On the Connecting page, click Change Login.
i) On the Change Login window, enter system/oracle as your credentials to use
for the test. Click OK.
j) Back to the Connecting page, the test should now be successful. Click Next.
k) On the Net Service Name page, enter db10g in the Net Service name field. Click
Next.

Oracle Database 11g: New Features for Administrators A - 172


Practice 9-1: Using SQL Performance Analyzer (continued)
l) On the Another Net Service name page, select No, and click Next.
m) On the Done page, click Next.
n) Click Finish on the Welcome page.
13) Use Enterprise Manager Database Control, as the SYSTEM user, to test the behavior
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

of STS_JFV in your 11g environment and compare it to its execution in your 10g
environment. What are your conclusions?
a) On the Home page, click the Software and Support tab.
b) On the “Software and Support” subpage, click SQL Performance Analyzer in the
Real Application Testing section.
c) On the SQL Performance Analyzer page, click the “Upgrade from 10.2 or 11g”
link.
ble
d) On the “Upgrade from 10.2 or 11g” page, enter: fe r a
SPA_JFV1 in the Task Name field, and ans
SYSTEM.STS_JFV in the SQL Tuning Set field. n - t r
Select Execute SQLs from the Creation Method drop-down list. a no
Select Unlimited from the Per-SQL Time limit. h a s ฺ
ฺ a
e) Click the Create Database Link button in the Pre-upgrade idesection.
r) uTrial
c m nt G
odb10g.us.oracle.com
f) On the Create Database Link page, enter
o ฺ
n ude in the
Name field. a S
@ nameisfield. t
Enter db10g in the Net i l l e
Service t h
l
Make sure that Public
e oฺzis selected.
u s e
Select Fixed
a c in the
rUser t o Connect As section, and use system for Username, and
oracle (mfor eboth
n e
spasswords.
l l e
i clicklicOK.
l o ZThen
rc e g) Back to the Upgrade from 10.2 or 11g page, enter DB10G.US.ORACLE.COM in
Ma the Database Link field in the Pre-upgrade Trial section.
h) In the Post-upgrade Trial section, deselect “Use the same system as in the pre-
upgrade trial.” Then click the Create Database Link button in that same section.
i) On the Create Database Link page, enter orcl.us.oracle.com@loopback
in the Name field.
Enter orcl in the Net Service name field.
Make sure that Public is selected.
Select Fixed User in the Connect As section, and use system for Username, and
oracle_4U for both passwords.
Then click OK.
j) Back to the Upgrade from 10.2 or 11g page, enter
ORCL.US.ORACLE.COM@LOOPBACK in the Database Link field in the Post-
upgrade Trial section.

Oracle Database 11g: New Features for Administrators A - 173


Practice 9-1: Using SQL Performance Analyzer (continued)
k) Make sure that the Comparison Metric field is set to Elapsed Time, and that
Schedule is set to Immediately.
When done, click Submit.
l) Back at the SQL Performance Analyzer page, wait until you see the Status set to
Completed for your submitted task (SPA_JFV1). It might take around 10 minutes
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

to execute.
m) Click the SPA_JFV1 link.
n) This brings you to the SQL Performance Analyzer Task: SYS.SPA_JFV1 page.
Click the Eyeglass icon in the SQL Trial Comparisons table, Comparison Report
column. There should be only one entry in this table.
o) From the SQL Performance Analyzer Task Report: SYSTEM.SPA_JFV1 page,
you can tell that the second trial was faster than the first one. The second trial
ble
corresponds to the run that used the Oracle Database 11g. The benefit depends on
fe r a
the statements that were captured and reexecuted. You should also see that the
ans
majority of the statements were using a new plan with 11g optimization.
n - t r
a no
p) From the “Top 10 SQL Statements Based on Impact on Workload” table, click
one of the SQL ID links. h a s ฺ
a r) uidwheree
q) This takes you to the corresponding SQL Details
m ฺ page from
G you can see the
o
ฺc execution
text of your statement as well as the different
e t
n plans that were used
during both trials. o
a Stun d
r) You could invoke the SQL l e@ is to tune this statement by clicking the
l TuningthAdvisor
z i
ฺ to the
STS_JFV link right
e lonext u s eSQL Tuning Set Name field. However, you will
c
not do thatainr this practice.
to
m
( ewindow,
14) Fromllaeterminal
e
ns make sure that you shut down your db10g database
Z i
instance. li c
e l o
rc $ . oraenv
Ma ORACLE_SID = [orcl] ? db10g
The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/10.2.0/dbhome_1 is
/u01/app/oracle
$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.3.0 - Production on Fri Oct 2


13:26:23 2009

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 -
Production
With the Partitioning, OLAP and Data Mining options

SQL> shutdown immediate


Database closed.

Oracle Database 11g: New Features for Administrators A - 174


Practice 9-1: Using SQL Performance Analyzer (continued)
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition
Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 175


Practices for Lesson 10

SQL Plan Management (SPM) is a new Oracle Database 11g feature that provides
controlled execution plan evolution.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

With SPM the optimizer automatically manages execution plans and ensures that only
known or verified plans are used.

When a new plan is found for a SQL statement it will not be used until it has been
verified to have comparable or better performance than the current plan.

SPM has three main components: ble


1. Plan Capture
fe r a
2. Plan Selection
ans
3. Plan Verification n - t r
o
In this practice, you will see each of these components covered.as
an
r ) h deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
l o Z l
rce
Ma

Oracle Database 11g: New Features for Administrators A - 176


Practice 10-1: Using SQL Plan Management
In this practice, you will see all phases of using SQL Plan Management.
1) Before we can start this practice, you need to set up a new user. Execute the
spm_setup.sh script to set up the environment for this practice. This script creates
the SPM user that you use throughout the practice.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

$ cd /home/oracle/solutions/SPM
$ ./spm_setup.sh

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 2 14:20:15


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.


ble
Connected to:
fe r a
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - s
Production
- t r an
With the Partitioning, Automatic Storage Management, OLAP, o n
Data Mining and Real Application Testing options
s an
SQL> SQL> SQL> SQL> drop user spm cascade r ) ha deฺ
* m ฺa Gui
ERROR at line 1:
n ฺ co ent
ORA-01918: user 'SPM' doesanot
@
o exist
S tud
SQL> SQL> z i l le this
User created. elo
ฺ se
r c to u
SQL> SQL> m a
( ens e
i l l esucceeded.
l o
Grant
Z lic
rc e SQL> SQL>
Ma System altered.

SQL> SQL> Disconnected from Oracle Database 11g Enterprise


Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$
2) The first component of SPM is Plan Capture. There are two main ways to capture
plans: automatically (on the fly), or bulk load. Let’s look at the automatic capture
first. In this practice, you turn on automatic plan capture so that the SPM repository is
automatically populated for any repeatable SQL statement. Turn on automatic plan
capture by setting the OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES
initialization parameter to TRUE in your SQL*Plus session connected as the SPM
user. After connected to your session, do not disconnect.
$ . oraenv
ORACLE_SID = [orcl] ? orcl

Oracle Database 11g: New Features for Administrators A - 177


Practice 10-1: Using SQL Plan Management (continued)
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle
$ sqlplus spm/spm

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 2 14:22:34


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

2009
Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
ble
SQL> show parameter baseline
fe r a
ans
NAME TYPE VALUE
n - t r
------------------------------------ ----------- -------------
optimizer_capture_sql_plan_baselines boolean FALSE a no
optimizer_use_sql_plan_baselines boolean TRUE h a s ฺ
a r) uide
SQL> alter session set optimizer_capture_sql_plan_baselines =

TRUE;
ฺ c om ent G
Session altered. a on tud
l l e@ is S
SQL>
i
ฺz se th
l o
a rce query
3) Execute the following t o u
in your SQL*Plus session (no space in /*LOAD…):
select e m nse
(/*LOAD_AUTO*/ * from sh.sales where quantity_sold
i l l
> Z40 order c e
li by prod_id; Use query1.sql script to execute the query.
e l o
rc SQL> @query1
Ma SQL>
SQL> select /*LOAD_AUTO*/ * from sh.sales where quantity_sold
> 40 order by prod_id;
no rows selected
SQL>
4) As this is the first time we have seen this SQL statement, it is not yet repeatable, so
there is no plan baseline for it. To confirm this, you can check that the plan baseline
was not loaded. Check whether there are any plan baselines that exist for your
statement (use the check_baselines.sql script).
SQL>
SQL> @check_baselines
SQL> set echo on
SQL>
SQL> select signature, sql_handle, sql_text, plan_name,
origin, enabled, accepted, fixed, autopurge from

Oracle Database 11g: New Features for Administrators A - 178


Practice 10-1: Using SQL Plan Management (continued)
dba_sql_plan_baselines where sql_text like 'select
/*LOAD_AUTO*/%';

no rows selected

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

5) Reexecute the query you ran in step 3:


SQL>
SQL> @query1
SQL> set echo on
SQL>
SQL> select /*LOAD_AUTO*/ * from sh.sales where quantity_sold
> 40 order by prod_id;
ble
no rows selected
fe r a
ans
SQL>
n - t r
6) The SQL statement is now known to be repeatable and a plan baseline is a no
a s ฺ
automatically captured. Check that the plan baseline was loaded for the previous
h
statement. What do you observe?
ฺ a r) uide
a) You can see from the output that a baseline
ฺ c om has been
n t G and enabled for this
created
e captured automatically by
SQL statement. You can also tell that
a onthis plan
t u dwas
checking the values of thee
l @ column
origin
i s S(use the check_baselines.sql
i l h
script):
e l oฺz use t
SQL>
a rc to
m
SQL> @check_baselines e
SQL>i l l eset( echo
c e nons
l o Z
SQL> li
rc e SQL> select signature, sql_handle, sql_text, plan_name,
Ma origin, enabled, accepted, fixed, autopurge from
dba_sql_plan_baselines where sql_text like 'select
/*LOAD_AUTO*/%';

SIGNATURE SQL_HANDLE
---------- ------------------------------
SQL_TEXT
--------------------------------------------------------------
------------------
PLAN_NAME ORIGIN ENA ACC FIX AUT
------------------------------ -------------- --- --- --- ---
8.0622E+18 SYS_SQL_6fe28d438dfc352f
select /*LOAD_AUTO*/ * from sh.sales where quantity_sold > 40
order by prod_id
SQL_PLAN_6zsnd8f6zsd9g54bc8843 AUTO-CAPTURE YES YES NO YES

SQL>

Oracle Database 11g: New Features for Administrators A - 179


Practice 10-1: Using SQL Plan Management (continued)
7) Now, change or alter the optimizer mode to use FIRST_ROWS optimization, and re-
execute your statement. Describe what happened:
a) This triggers the SQL statement to execute with a different plan:
SQL>
SQL> alter session set optimizer_mode = first_rows;
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Session altered.

SQL> @query1
SQL> set echo on
SQL>
SQL> select /*LOAD_AUTO*/ * from sh.sales where quantity_sold
> 40 order by prod_id;
ble
no rows selected
fe r a
ans
SQL>
n - t r
no
b) Because the SQL statement will have a new plan, another plan baseline is
a
a s ฺ
automatically captured. You can confirm this by checking the plan baseline again:
h
SQL> @check_baselines ฺ a r) uide
SQL> set echo on ฺ c om ent G
SQL>
a on tud
l e@ fixed,
SQL> select signature, sql_handle,
i s S sql_text, plan_name,
origin, enabled, accepted,i l
ฺz where h
t sql_text autopurge from
l o
e o us
dba_sql_plan_baselines e like 'select
r
/*LOAD_AUTO*/%';
a c t
( m s e
i
SIGNATURE
Z en
lle licSQL_HANDLE
rc elo----------
SQL_TEXT
------------------------------

Ma --------------------------------------------------------------
PLAN_NAME ORIGIN ENA ACC FIX AUT
------------------------------ -------------- --- --- --- ---
8.0622E+18 SYS_SQL_6fe28d438dfc352f
select /*LOAD_AUTO*/ * from sh.sales where quantity_sold > 40
order by prod_id
SQL_PLAN_6zsnd8f6zsd9g11df68d0 AUTO-CAPTURE YES NO NO YES

8.0622E+18 SYS_SQL_6fe28d438dfc352f
select /*LOAD_AUTO*/ * from sh.sales where quantity_sold > 40
order by prod_id
SQL_PLAN_6zsnd8f6zsd9g54bc8843 AUTO-CAPTURE YES YES NO YES

SIGNATURE SQL_HANDLE
---------- ------------------------------
SQL_TEXT
--------------------------------------------------------------
PLAN_NAME ORIGIN ENA ACC FIX AUT
------------------------------ -------------- --- --- --- ---

Oracle Database 11g: New Features for Administrators A - 180


Practice 10-1: Using SQL Plan Management (continued)

SQL>
c) Now you see two plan baselines for your query, but notice that the second plan
has not been accepted. This new plan will have to be validated before it is
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

acceptable as a good plan to use.


8) Now reset the optimizer mode to the default values and disable auto capture of plan
baselines.
SQL> alter session set optimizer_mode = all_rows;

Session altered.

SQL> alter session set optimizer_capture_sql_plan_baselines =


ble
FALSE;
fe r a
ans
Session altered.
n - t r
SQL> a no
h a s ฺ
ฺ a u ideis empty. Use
r) baseline
9) Now purge plan baselines and confirm that the SQL plan
purge_auto_baseline.sql for that:
ฺ c om ent G
SQL> @purge_auto_baseline on
SQL> set echo on @ a Stud
SQL> z i l le this
SQL> variable cnt
c e loฺnumber;u s e
SQL> a r to
m e
SQL> exec
i l l e ( icens
:cnt :=
dbms_spm.drop_sql_plan_baseline('SYS_SQL_6fe28d438dfc352f');
l o Z l
rc e PL/SQL procedure successfully completed.
Ma SQL> exec :cnt :=
dbms_spm.drop_sql_plan_baseline('SYS_SQL_396e2e2b6cb3e334');
BEGIN :cnt :=
dbms_spm.drop_sql_plan_baseline('SYS_SQL_396e2e2b6cb3e334');
END;

*
ERROR at line 1:
ORA-38131: specified SQL handle SYS_SQL_396e2e2b6cb3e334 does
not exist
ORA-06512: at "SYS.DBMS_SPM", line 2524
ORA-06512: at line 1

SQL>
SQL> select signature, sql_handle, sql_text, plan_name,
origin, enabled, accepted, fixed, autopurge
2 from dba_sql_plan_baselines
3 where sql_text like 'select /*LOAD_AUTO*/%';

Oracle Database 11g: New Features for Administrators A - 181


Practice 10-1: Using SQL Plan Management (continued)

no rows selected

SQL>
10) Next look at how to load plans from SQL tuning sets. Still connected to your
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL*Plus session, check the execution plan for the following SQL statement and
then execute it (use explain_query2.sql and query2.sql):
select /*LOAD_STS*/ * from sh.sales where quantity_sold >
40 order by prod_id;
SQL>
SQL> @explain_query2
SQL> set echo on
SQL> e
SQL> explain plan for
r a bl
2 select /*LOAD_STS*/ * from sh.sales where quantity_sold > s fe
40 order by prod_id;
- t r an
no n
Explained.
a
s ฺ
h a
SQL>
SQL> select * from ฺ a r) uide
c om ent G
table(dbms_xplan.display(null,null,'basic'));

a on tud
PLAN_TABLE_OUTPUT
l l e@ is S
i
ฺz se th
--------------------------------------------------------------
------------------ l o
Plan hash value:
a rce 3803407550
t o u
l e (m ense
i l
--------------------------------------
lic
l o|ZId | Operation | Name |
rc e --------------------------------------
Ma |
|
0 | SELECT STATEMENT
1 | SORT ORDER BY
|
|
|
|
| 2 | PARTITION RANGE ALL| |
| 3 | TABLE ACCESS FULL | SALES |
--------------------------------------

10 rows selected.

SQL>
SQL> @query2
SQL> set echo on
SQL>
SQL> select /*LOAD_STS*/ * from sh.sales where quantity_sold >
40 order by prod_id;

no rows selected

SQL>

Oracle Database 11g: New Features for Administrators A - 182


Practice 10-1: Using SQL Plan Management (continued)
11) Alter the optimizer mode to use FIRST_ROWS optimization, check the execution
plan, and reexecute the query:
SQL>
SQL> alter session set optimizer_mode = first_rows;
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Session altered.

SQL> @explain_query2
SQL> set echo on
SQL>
SQL> explain plan for
2 select /*LOAD_STS*/ * from sh.sales where quantity_sold >
40 order by prod_id;

Explained. ble
fe r a
SQL> ans
SQL> select * from n - t r
table(dbms_xplan.display(null,null,'basic'));
a no
h a s ฺ
PLAN_TABLE_OUTPUT
ฺ a r) uide
--------------------------------------------------------------
Plan hash value: 899219946
ฺ c om ent G
a on tud
l l e@ is S
--------------------------------------------------------------
| Id | Operation
ฺ z i t h | Name
|
elo o us e
r c
--------------------------------------------------------------
a STATEMENT t
| 0 |(mSELECT s
n e | |
l
| il1 e| SORT
i c e ORDER BY | |
l o| Z 2 | l PARTITION RANGE ALL | |
e
Marc |
|
3 |
4 |
TABLE ACCESS BY LOCAL INDEX ROWID|SALES
BITMAP CONVERSION TO ROWIDS |
|
|
| 5 | BITMAP INDEX FULL SCAN |SALES_PROMO_BIX |

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
--------------------------------------------------------------

12 rows selected.

SQL>
SQL> @query2
SQL> set echo on
SQL>
SQL> select /*LOAD_STS*/ * from sh.sales where quantity_sold >
40 order by prod_id;

no rows selected

SQL>

Oracle Database 11g: New Features for Administrators A - 183


Practice 10-1: Using SQL Plan Management (continued)
12) Reset the optimizer mode to ALL_ROWS optimization:
SQL>
SQL> alter session set optimizer_mode = all_rows;

Session altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
13) Check that there is currently no baseline plan for your statement (use the
check_baselines2.sql script):
SQL> @check_baselines2
SQL> set echo on
SQL>
SQL> select signature, sql_handle, sql_text, plan_name,
ble
origin, enabled, accepted, fixed, autopurge from
fe r a
dba_sql_plan_baselines where sql_text like 'select
ans
/*LOAD_STS*/%';
n - t r
no rows selected a no
h a s ฺ
SQL>
ฺ a r) uide
14) Create a SQL tuning set that captures SELECT ฺ c om n t
statements
Gthat contain the
LOAD_STS hint. These statements are a oinnthe cursor
t u decache. The STS should be called
SPM_STS and owned by thellSPM e@user. Use
i s Sthe catchup_sts.sql script to
i h
capture those statements.
e l oฺz use t
SQL> a rc to
m e
i l eset( echo
SQL> @catchup_sts
l c e nons
l o
SQL>
Z
SQL>
li
rc e SQL> exec sys.dbms_sqltune.create_sqlset(sqlset_name =>
Ma 'SPM_STS', sqlset_owner => 'SPM');

PL/SQL procedure successfully completed.

SQL>
SQL> DECLARE
2 stscur dbms_sqltune.sqlset_cursor;
3 BEGIN
4 OPEN stscur FOR
5 SELECT VALUE(P)
6 FROM TABLE(dbms_sqltune.select_cursor_cache(
7 'sql_text like ''select /*LOAD_STS*/%''',
8 null, null, null, null, null, null, 'ALL'))
P;
9
10 -- populate the sqlset
11 dbms_sqltune.load_sqlset(sqlset_name =>
'SPM_STS',
12 populate_cursor => stscur,

Oracle Database 11g: New Features for Administrators A - 184


Practice 10-1: Using SQL Plan Management (continued)
13 sqlset_owner => 'SPM');
14 END;
15 /

PL/SQL procedure successfully completed.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>

15) Verify which SQL statements are in SPM_STS (use the check_sts.sql script):
a) So SPM_STS has your SQL statement with two different plans.
SQL>
SQL> @check_sts
SQL> set echo on
SQL>
ble
SQL> select sql_text from dba_sqlset_statements where
fe r a
sqlset_name='SPM_STS';
ans
n - t r
SQL_TEXT
-------------------------------------------------------------- a no
------------------
h a s ฺ
ฺ a r) uide
select /*LOAD_STS*/ * from sh.sales where quantity_sold > 40
order by prod_id
ฺ c om ent G
select /*LOAD_STS*/ * from sh.sales where quantity_sold > 40
order by prod_id a on tud
l l e@ is S
SQL> i
ฺz se th
l o
e orepository u with the plans found in SPM_STS. Use the
16) Populate the plan
a rcbaselinet
l e (m ense
populate_baseline.sql script for that:
Z i l li c
l oSQL>
rc e SQL> @populate_baseline
Ma SQL> set echo on
SQL>
SQL> variable cnt number;
SQL>
SQL> execute :cnt := dbms_spm.load_plans_from_sqlset( -
> sqlset_name => 'SPM_STS', -
> basic_filter => 'sql_text like ''select
/*LOAD_STS*/%''');

PL/SQL procedure successfully completed.

SQL>
17) Confirm that the plan baselines are loaded and note the value in the origin column.
What do you observe? (Use check_baselines2.sql.)
a) You should see MANUAL-LOAD because you manually loaded these plans. Also
note that this time both plans are accepted.
SQL>

Oracle Database 11g: New Features for Administrators A - 185


Practice 10-1: Using SQL Plan Management (continued)
SQL> @check_baselines2
SQL> set echo on
SQL>
SQL> select signature, sql_handle, sql_text, plan_name,
origin, enabled, accepted, fixed, autopurge from
dba_sql_plan_baselines where sql_text like 'select
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

/*LOAD_STS*/%';

SIGNATURE SQL_HANDLE
---------- ------------------------------
SQL_TEXT
--------------------------------------------------------------
------------------
PLAN_NAME ORIGIN ENA ACC FIX AUT
------------------------------ -------------- --- --- --- ---
ble
1.2134E+19 SYS_SQL_a8632bd857a4a25e
fe r a
select /*LOAD_STS*/ * from sh.sales where quantity_sold > 40
ans
order by prod_id
SQL_PLAN_ahstbv1bu98ky11df68d0 MANUAL-LOAD YES YES NO YES n - t r
a no
1.2134E+19 SYS_SQL_a8632bd857a4a25e
h a s ฺ
select /*LOAD_STS*/ * from sh.sales where
order by prod_id ฺ a u ide
r) quantity_sold > 40

SQL_PLAN_ahstbv1bu98ky54bc8843 ฺMANUAL-LOADc om ent G YES YES NO YES


a on tud
SIGNATURE SQL_HANDLE @
l e i s S
i l h
oฺz use t
---------- ------------------------------
SQL_TEXT e l
rc to
--------------------------------------------------------------
a
m e
i l l
PLAN_NAMEe ( icens
------------------
ORIGIN ENA ACC FIX AUT
l Z l
o------------------------------ -------------- --- --- --- ---
e
Marc
SQL>

18) Purge the plan baselines and drop SPM_STS. Use the purge_sts_baseline.sql
script for that:
SQL>
SQL> @purge_sts_baseline
SQL> set echo on
SQL>
SQL> variable cnt number;
SQL>
SQL> exec :cnt :=
dbms_spm.drop_sql_plan_baseline('SYS_SQL_a8632bd857a4a25e');

PL/SQL procedure successfully completed.

SQL>
SQL> print cnt;

Oracle Database 11g: New Features for Administrators A - 186


Practice 10-1: Using SQL Plan Management (continued)

CNT
----------
2

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> select signature, sql_handle, sql_text, plan_name,


origin, enabled, accepted, fixed, autopurge
2 from dba_sql_plan_baselines
3 where sql_text like 'select /*LOAD_STS*/%';

no rows selected

SQL>
SQL> exec sys.dbms_sqltune.drop_sqlset(sqlset_name =>
ble
'SPM_STS', -
fe r a
> sqlset_owner => 'SPM');
ans
PL/SQL procedure successfully completed. n - t r
a no
SQL>
h a s ฺ

19) Now, you will see how to directly load plan baselines a u de cache. Before
) the icursor
rfrom
you begin, you need some SQL Statements. ฺ c omconnected
Still n t Gto your SQL*Plus
e statement, and then execute
onfollowing
session, check the execution plan forathe
t u dSQL
it (use the explain_query3.sql
l e S
@ andisquery3.sql scripts):
i l h
t sh.sales where quantity_sold >
select /*LOAD_CC*/
40 order by c e loฺz *ufrom
prod_id; se
a r to
SQL> m
( ens e
SQL> i l l e@explain_query3
l o Z
SQL> set echo lic on
rce SQL>
Ma SQL> explain plan for
2 select /*LOAD_CC*/ * from sh.sales where quantity_sold >
40 order by prod_id;

Explained.

SQL>
SQL> select * from
table(dbms_xplan.display(null,null,'basic'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
------------------
Plan hash value: 3803407550

--------------------------------------
| Id | Operation | Name |
--------------------------------------
| 0 | SELECT STATEMENT | |

Oracle Database 11g: New Features for Administrators A - 187


Practice 10-1: Using SQL Plan Management (continued)
| 1 | SORT ORDER BY | |
| 2 | PARTITION RANGE ALL| |
| 3 | TABLE ACCESS FULL | SALES |
--------------------------------------

10 rows selected.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> @query3
SQL> set echo on
SQL>
SQL> select /*LOAD_CC*/ * from sh.sales where quantity_sold >
40 order by prod_id;

no rows selected
ble
fe r a
SQL>
t r a ns
-
20) Now change the optimizer mode to use FIRST_ROWS optimization andnre-execute
o
the previous step. What do you observe?
s an
a) You should see a different execution plan:
r ) ha deฺ
SQL> m ฺa Gui
SQL> alter session set optimizer_mode
n ฺ co e=nfirst_rows;
t
@ a o
S t ud
Session altered.
z i l le this
SQL> @explain_query3
c e loฺ use
SQL> set echo a r on to
SQL>
l e ( ense
m
SQL> l
Z2i explainlic plan for
l o select /*LOAD_CC*/ * from sh.sales where quantity_sold >
rce 40 order by prod_id;
Ma
Explained.

SQL>
SQL> select * from
table(dbms_xplan.display(null,null,'basic'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
------------------
Plan hash value: 899219946

--------------------------------------------------------------
-
| Id | Operation | Name
|
--------------------------------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT ORDER BY | |

Oracle Database 11g: New Features for Administrators A - 188


Practice 10-1: Using SQL Plan Management (continued)
| 2 | PARTITION RANGE ALL | |
| 3 | TABLE ACCESS BY LOCAL INDEX ROWID|SALES |
| 4 | BITMAP CONVERSION TO ROWIDS | |
| 5 | BITMAP INDEX FULL SCAN |SALES_PROMO_BIX |

PLAN_TABLE_OUTPUT
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

--------------------------------------------------------------
--------------------------------------------------------------

12 rows selected.

SQL>
SQL> @query3
SQL> set echo on
SQL>
ble
SQL> select /*LOAD_CC*/ * from sh.sales where quantity_sold >
fe r a
40 order by prod_id;
ans
no rows selected n - t r
a no
SQL>
h a s ฺ
21) Reset optimizer mode to ALL_ROWS: ฺ a r) uide
ฺ c om ent G
SQL>
SQL> alter session set optimizer_mode a on tud = all_rows;
l l e@ is S
Session altered. oฺz
i th
l
e o us e
SQL> a r c t
( m s e
22) Now
Z i cencache is populated, you need to get the SQL ID for your SQL
le thelcursor
ilthat
lostatement. Use the SQL ID to filter the content of the cursor cache and load the
rce
Ma baselines with these two plans. Use the load_cc_baseline.sql script for that:
SQL> @load_cc_baseline
SQL> set echo on
SQL>
SQL> variable cnt number;
SQL>
SQL> variable sqlid varchar2(20);
SQL>
SQL> begin
2 select distinct sql_id into :sqlid from v$sql where
sql_text like 'select /*LOAD_CC*/%';
3 end;
4 /

PL/SQL procedure successfully completed.

SQL>
SQL> print sqlid;

Oracle Database 11g: New Features for Administrators A - 189


Practice 10-1: Using SQL Plan Management (continued)
SQLID
--------------------------------------------------------------
9qx77nb12bh6z

SQL>
SQL> execute :cnt :=
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

dbms_spm.load_plans_from_cursor_cache(sql_id => :sqlid);

PL/SQL procedure successfully completed.

SQL>

23) Confirm that the baselines were loaded (use check_baselines3.sql):


SQL>
SQL> @check_baselines3 ble
SQL> set echo on fe r a
SQL>
ans
SQL> select signature, sql_handle, sql_text, plan_name,
n - t r
origin, enabled, accepted, fixed, autopurge from
dba_sql_plan_baselines where sql_text like 'select a no
/*LOAD_CC*/%'; h a s ฺ
ฺ a r) uide
SIGNATURE SQL_HANDLE
ฺ c om ent G
SQL_TEXT a on tud
---------- ------------------------------

l e@ is S
--------------------------------------------------------------
l
------------------
i
ฺz se th
l o
e ou
PLAN_NAME
a r c t
------------------------------
ORIGIN
--------------
ENA ACC FIX AUT
--- --- --- ---
( n s e
m SYS_SQL_f6cb7f742ef93547
e
1.7783E+19
ill /*LOAD_CC*/
i ce
l o Z
select l * from sh.sales where quantity_sold > 40
rc e order by prod_id
Ma SQL_PLAN_gdkvzfhrgkda711df68d0 MANUAL-LOAD YES YES NO YES

1.7783E+19 SYS_SQL_f6cb7f742ef93547
select /*LOAD_CC*/ * from sh.sales where quantity_sold > 40
order by prod_id
SQL_PLAN_gdkvzfhrgkda754bc8843 MANUAL-LOAD YES YES NO YES

SIGNATURE SQL_HANDLE
---------- ------------------------------
SQL_TEXT
--------------------------------------------------------------
------------------
PLAN_NAME ORIGIN ENA ACC FIX AUT
------------------------------ -------------- --- --- --- ---

SQL>
24) Purge plan baselines:

Oracle Database 11g: New Features for Administrators A - 190


Practice 10-1: Using SQL Plan Management (continued)
SQL>
SQL> @purge_cc_baseline
SQL> set echo on
SQL>
SQL> variable cnt number;
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> exec :cnt :=


dbms_spm.drop_sql_plan_baseline('SYS_SQL_f6cb7f742ef93547');

PL/SQL procedure successfully completed.

SQL>
SQL> print cnt;

CNT
ble
----------
fe r a
2
ans
SQL> n - t r
SQL> REM Check that plan baselines were purged: a no
SQL>
h a s ฺ
SQL> select signature, sql_handle, sql_text, plan_name,
origin, enabled, accepted, fixed, autopurge ฺ a r) uide
2 from dba_sql_plan_baselines ฺ c om ent G
on tud
3 where sql_text like 'select /*LOAD_CC*/%';
a
no rows selected zill
e@ this S
c e loฺ use
SQL> a r to
m e
l e (youiknow
25) Nowilthat c e s to capture plans, look at how the optimizer selects which
nhow
l o Z baselinesl to use. First you create two baselines for a statement and show them
plan
rce being used. Then you disable one of the baselines and see the second baseline being
Ma used. Finally, you disable both baselines and show now the optimizer falls back to the
default behavior of a cost-based plan. You can start by executing the same query
twice, with different plans. Determine the execution of the following statement and
then execute it (use the explain_query4.sql and query4.sql scripts):
select /*SPM_USE*/ * from sh.sales where quantity_sold >
40 order by prod_id
SQL>
SQL> @explain_query4
SQL> set echo on
SQL>
SQL> explain plan for
2 select /*SPM_USE*/ * from sh.sales where quantity_sold >
40 order by prod_id;

Explained.

SQL>

Oracle Database 11g: New Features for Administrators A - 191


Practice 10-1: Using SQL Plan Management (continued)
SQL> select * from
table(dbms_xplan.display(null,null,'basic'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
Plan hash value: 3803407550
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

--------------------------------------
| Id | Operation | Name |
--------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT ORDER BY | |
| 2 | PARTITION RANGE ALL| |
| 3 | TABLE ACCESS FULL | SALES |
--------------------------------------
ble
fe r a
10 rows selected.
ans
SQL> n - t r
SQL> @query4 a no
SQL> set echo on
h a s ฺ
SQL>
ฺ a r) uide
SQL> select /*SPM_USE*/ * from sh.sales where quantity_sold >
40 order by prod_id; ฺ c om ent G
a on tud
no rows selected
l l e@ is S
i
ฺz se th
SQL> l o
a rce to u
26) Now change
l e n se mode to use FIRST_ROWS optimization and re-execute
(mthe eoptimizer
Z i l
the previous step.
l i c What do you observe?
lo
rce a) You should see a different execution plan:
Ma SQL>
SQL> alter session set optimizer_mode = first_rows;

Session altered.

SQL> @explain_query4
SQL> set echo on
SQL>
SQL> explain plan for
2 select /*SPM_USE*/ * from sh.sales where quantity_sold >
40 order by prod_id;

Explained.

SQL>
SQL> select * from
table(dbms_xplan.display(null,null,'basic'));

PLAN_TABLE_OUTPUT

Oracle Database 11g: New Features for Administrators A - 192


Practice 10-1: Using SQL Plan Management (continued)
--------------------------------------------------------------
------------------
Plan hash value: 899219946

--------------------------------------------------------------
| Id | Operation | Name
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

|
--------------------------------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT ORDER BY | |
| 2 | PARTITION RANGE ALL | |
| 3 | TABLE ACCESS BY LOCAL INDEX ROWID|SALES |
| 4 | BITMAP CONVERSION TO ROWIDS | |
| 5 | BITMAP INDEX FULL SCAN |SALES_PROMO_BIX |
ble
PLAN_TABLE_OUTPUT
fe r a
--------------------------------------------------------------
ans
--------------------------------------------------------------
n - t r
12 rows selected. a no
h a s ฺ
SQL>
SQL> @query4 ฺ a r) uide
SQL> set echo on ฺ c om ent G
SQL> a on tud
SQL> select /*SPM_USE*/ @
l e i s S
* from sh.sales where quantity_sold >
i l h
oฺz use t
40 order by prod_id;
e l
no rows selected
a rc to
m e
i
SQL> l l e ( icens
l o Z l
rc e27) Reset the optimizer mode to ALL_ROWS:
Ma SQL>
SQL> alter session set optimizer_mode = all_rows;

Session altered.

SQL>
28) Populate the baseline with the two plans for your statement directly from the cursor
cache. Use the load_use_baseline.sql script for that. When done, verify that
baselines were loaded. What do you observe?
a) You should see both plan baselines loaded. Note that both plans have been
marked acceptable. This is because both plans were present in the cursor cache at
the time of the load, and because these plans have been manually loaded, it is
assumed that both plans have acceptable performance.
SQL> @load_use_baseline
SQL> set echo on
SQL>

Oracle Database 11g: New Features for Administrators A - 193


Practice 10-1: Using SQL Plan Management (continued)
SQL> variable cnt number;
SQL>
SQL> variable sqlid varchar2(20);
SQL>
SQL> begin
2 select distinct sql_id into :sqlid from v$sql where
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

sql_text like 'select /*SPM_USE*/%';


3 end;
4 /

PL/SQL procedure successfully completed.

SQL>
SQL> print sqlid;
ble
SQLID
fe r a
--------------------------------------------------------------
ans
gudfs2kqb90sz
n - t r
o
SQL>
s an
SQL> execute :cnt :=
r ) ha deฺ
dbms_spm.load_plans_from_cursor_cache(sql_id => :sqlid);
m ฺa Gui
PL/SQL procedure successfully completed.
n ฺ co ent
SQL> @ ao Stud
SQL> print cnt; z i l le this
c e loฺ use
CNT ar to
m e
i l l e ( 2icens
----------

l o Z l
rc e SQL>
Ma SQL> select signature, sql_handle, sql_text, plan_name,
origin, enabled, accepted, fixed, autopurge
2 from dba_sql_plan_baselines
3 where sql_text like 'select /*SPM_USE*/%';

SIGNATURE SQL_HANDLE
---------- ------------------------------
SQL_TEXT
--------------------------------------------------------------
------------------
PLAN_NAME ORIGIN ENA ACC FIX AUT
------------------------------ -------------- --- --- --- ---
7.6492E+17 SYS_SQL_0a9d872600ece455
select /*SPM_USE*/ * from sh.sales where quantity_sold > 40
order by prod_id
SQL_PLAN_0p7c74s0ftt2p11df68d0 MANUAL-LOAD YES YES NO YES

7.6492E+17 SYS_SQL_0a9d872600ece455

Oracle Database 11g: New Features for Administrators A - 194


Practice 10-1: Using SQL Plan Management (continued)
select /*SPM_USE*/ * from sh.sales where quantity_sold > 40
order by prod_id
SQL_PLAN_0p7c74s0ftt2p54bc8843 MANUAL-LOAD YES YES NO YES

SIGNATURE SQL_HANDLE
---------- ------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL_TEXT
--------------------------------------------------------------
------------------
PLAN_NAME ORIGIN ENA ACC FIX AUT
------------------------------ -------------- --- --- --- ---

SQL>
29) Determine the baseline and the execution plan used to execute the following query: ble
select /*SPM_USE*/ * from sh.sales where quantity_sold > fe r a
40 order by prod_id. ans
n - t r
What do you observe?
a no
h a s is using
a) The note at the end of the explain output tells you the system

a baseline.
a )
From the execution plan, you can see that the firstrbaseline is
i d e
being used, a full
table scan. Use the explain_query4_note.sql ฺ
m nt G u
script.
c o
SQL>
a o nฺ ude
SQL> @explain_query4_note
@ S t
SQL> set echo on
z ill e t hi s
ฺ e
SQL>
SQL> explainrc elo for
plan o us
2 select m a e t
/*SPM_USE*/ * from sh.sales where quantity_sold >
e ( n s
Z ill by
40 order
l i ceprod_id;
el oExplained.
Marc
SQL>
SQL> select * from table(dbms_xplan.display(null,null,'basic
+note'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
Plan hash value: 3803407550

--------------------------------------
| Id | Operation | Name |
--------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT ORDER BY | |
| 2 | PARTITION RANGE ALL| |
| 3 | TABLE ACCESS FULL | SALES |
--------------------------------------

Oracle Database 11g: New Features for Administrators A - 195


Practice 10-1: Using SQL Plan Management (continued)
PLAN_TABLE_OUTPUT
--------------------------------------------------------------
------------------
Note
-----
- SQL plan baseline "SQL_PLAN_0p7c74s0ftt2p54bc8843" used
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

for this statement

14 rows selected.

SQL>
30) Disable that plan baseline, and check that the system uses the other plan baseline
when reexecuting the statement. Use the check_baseline_used.sql script for
that. What do you observe?
ble
fe
a) Now from the execution plan you can see that you are using an index scan instead r a
of a full table scan, so this is the second baseline. n s
n - tra
SQL> n o
SQL> a
s ฺ
SQL> @check_baseline_used h a
SQL> set echo on ฺ a r) uide
SQL>
SQL> variable cnt number; ฺ c om ent G
SQL> a on tud
SQL> select sql_handle,plan_name
l l e@ is S
i
ฺz se th
2 from dba_sql_plan_baselines
l o
3 where sql_text
a rce tolike u 'select /*SPM_USE*/%';
SQL_HANDLE
l e (m ense PLAN_NAME
Z i l l i c
------------------------------ ------------------------------

rc eloSYS_SQL_0a9d872600ece455 SQL_PLAN_0p7c74s0ftt2p11df68d0
Ma SYS_SQL_0a9d872600ece455 SQL_PLAN_0p7c74s0ftt2p54bc8843

SQL>
SQL>
SQL> exec :cnt := dbms_spm.alter_sql_plan_baseline( -
> sql_handle =>
'SYS_SQL_0a9d872600ece455', -
> plan_name =>
'SQL_PLAN_0p7c74s0ftt2p54bc8843', -
> attribute_name => 'ENABLED', -
> attribute_value => 'NO');

PL/SQL procedure successfully completed.

SQL>
SQL> select signature, sql_handle, sql_text, plan_name,
origin, enabled, accepted, fixed, autopurge
2 from dba_sql_plan_baselines
3 where sql_text like 'select /*SPM_USE*/%';

Oracle Database 11g: New Features for Administrators A - 196


Practice 10-1: Using SQL Plan Management (continued)

SIGNATURE SQL_HANDLE
---------- ------------------------------
SQL_TEXT
--------------------------------------------------------------
------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

PLAN_NAME ORIGIN ENA ACC FIX AUT


------------------------------ -------------- --- --- --- ---
7.6492E+17 SYS_SQL_0a9d872600ece455
select /*SPM_USE*/ * from sh.sales where quantity_sold > 40
order by prod_id
SQL_PLAN_0p7c74s0ftt2p11df68d0 MANUAL-LOAD YES YES NO YES

7.6492E+17 SYS_SQL_0a9d872600ece455
select /*SPM_USE*/ * from sh.sales where quantity_sold > 40
ble
order by prod_id
fe r a
SQL_PLAN_0p7c74s0ftt2p54bc8843 MANUAL-LOAD NO YES NO YES
ans
SIGNATURE SQL_HANDLE n - t r
---------- ------------------------------ a no
SQL_TEXT
h a s ฺ
------------------ ฺ a r) uide
--------------------------------------------------------------

PLAN_NAME ORIGIN ฺ c om ent G


ENA ACC FIX AUT
on tud
------------------------------ -------------- --- --- --- ---
a
l l e@ is S
i
ฺz se th
SQL> l o
SQL> a rce to u
l e (m eplan
SQL> explain
n se for select /*SPM_USE*/ * from sh.sales where
Zi l lic > 40 order by prod_id;
quantity_sold
e l o
rc Explained.
Ma
SQL>
SQL> select * from table(dbms_xplan.display(null, null, 'basic
+note'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
Plan hash value: 899219946

--------------------------------------------------------------
| Id | Operation | Name |
--------------------------------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT ORDER BY | |
| 2 | PARTITION RANGE ALL | |
| 3 | TABLE ACCESS BY LOCAL INDEX ROWID|SALES |
| 4 | BITMAP CONVERSION TO ROWIDS | |
| 5 | BITMAP INDEX FULL SCAN |SALES_PROMO_BIX |

Oracle Database 11g: New Features for Administrators A - 197


Practice 10-1: Using SQL Plan Management (continued)
PLAN_TABLE_OUTPUT
--------------------------------------------------------------
------------------
--------------------------------------------------------------
-
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Note
-----
- SQL plan baseline "SQL_PLAN_0p7c74s0ftt2p11df68d0" used
for this statement

16 rows selected.

SQL>
31) Disable this other plan baseline and check that the system falls back to the cost-based ble
approach when reexecuting the explain plan for the statement. Use the fe r a
check_baseline_used2.sql script for that: ans
n - t r
no
a) You know that the optimizer has gone back to the default cost-based approach
a
h a s ฺ
because there is no note at the end of the plan stating that a baseline was used.
SQL> ฺ a r) uide
SQL> @check_baseline_used2
SQL> set echo on ฺ c om ent G
SQL> a on tud
SQL> variable cnt number; l l e@ is S
SQL>
i
ฺz se th
SQL> exec :cnt l o
e:= dbms_spm.alter_sql_plan_baseline(
u -
> a r c t o
( m nsesql_handle -
'SYS_SQL_0a9d872600ece455',
e
=>

> Zil
l l i ce plan_name =>
e l o'SQL_PLAN_0p7c74s0ftt2p11df68d0', -
rc
Ma >
>
attribute_name
attribute_value
=> 'ENABLED', -
=> 'NO');

PL/SQL procedure successfully completed.


SQL>
SQL> select signature, sql_handle, sql_text, plan_name,
origin, enabled, accepted, fixed, autopurge
2 from dba_sql_plan_baselines
3 where sql_text like 'select /*SPM_USE*/%';

SIGNATURE SQL_HANDLE
---------- ------------------------------
SQL_TEXT
--------------------------------------------------------------
------------------
PLAN_NAME ORIGIN ENA ACC FIX AUT
------------------------------ -------------- --- --- --- ---
7.6492E+17 SYS_SQL_0a9d872600ece455

Oracle Database 11g: New Features for Administrators A - 198


Practice 10-1: Using SQL Plan Management (continued)
select /*SPM_USE*/ * from sh.sales where quantity_sold > 40
order by prod_id
SQL_PLAN_0p7c74s0ftt2p11df68d0 MANUAL-LOAD NO YES NO YES

7.6492E+17 SYS_SQL_0a9d872600ece455
select /*SPM_USE*/ * from sh.sales where quantity_sold > 40
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

order by prod_id
SQL_PLAN_0p7c74s0ftt2p54bc8843 MANUAL-LOAD NO YES NO YES

SIGNATURE SQL_HANDLE
---------- ------------------------------
SQL_TEXT
--------------------------------------------------------------
------------------
PLAN_NAME ORIGIN ENA ACC FIX AUT
ble
------------------------------ -------------- --- --- --- ---
fe r a
SQL> ans
SQL> n - t r
no
SQL> explain plan for select /*SPM_USE*/ * from sh.sales where
a
quantity_sold > 40 order by prod_id;
h a s ฺ
Explained. ฺ a r) uide
ฺ c om ent G
SQL>
a on tud
l l e@ is S
SQL> select * from table(dbms_xplan.display(null, null, 'basic
+note'));
l o ฺzi se th
rce to u
PLAN_TABLE_OUTPUT
a
l e (m ense
--------------------------------------------------------------

Plan
l
------------------
Zi hash livalue:
c 3803407550
e l o
rc
Ma --------------------------------------
| Id | Operation | Name |
--------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT ORDER BY | |
| 2 | PARTITION RANGE ALL| |
| 3 | TABLE ACCESS FULL | SALES |
--------------------------------------
10 rows selected.

SQL>
32) Drop plan baselines and check that they are purged. Use the
purge_use_baseline.sql script for that.
SQL>
SQL> @purge_use_baseline
SQL> set echo on
SQL>

Oracle Database 11g: New Features for Administrators A - 199


Practice 10-1: Using SQL Plan Management (continued)
SQL> variable cnt number;
SQL>
SQL> exec :cnt :=
dbms_spm.drop_sql_plan_baseline('SYS_SQL_0a9d872600ece455');

PL/SQL procedure successfully completed.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> print cnt;

CNT
----------
2

SQL>
ble
SQL> select signature, sql_handle, sql_text, plan_name,
fe r a
origin, enabled, accepted, fixed, autopurge
an s
2 from dba_sql_plan_baselines
3 where sql_text like 'select /*SPM_USE*/%'; n - t r
a no
no rows selected
h a s ฺ
SQL> ฺ a r) uide
ฺ c om ent G
33) One of the methods used to enable plan
a onevolution
t u d(or plan verification) is Automatic
SQL Tuning that is run as an automated
SQL Tuning targets onlyฺz the
e@ thSQL
illhigh-load s Sstatements;
itask in a maintenance window. Automatic
for them, it automatically
implements actionse l o as making
such u s e a successfully verified plan an accepted plan.
r c
a trigger
Here, you manually o
t SQL tuning to find a better plan for a given SQL
statement. ( m
First, s e
determine
n the execution plan of the following statement:
i l l e c e
l o Z
select li USE_NL(s c) FULL(s) FULL(c) */ c.cust_id,
/*+
rce sum(s.quantity_sold)
Ma from sh.sales s, sh.customers c
where s.cust_id = c.cust_id and c.cust_id < 2
group by c.cust_id
Some optimizer hints are added to the statements to ensure that you get a nonoptimal
plan at first. Use the check_evolve_plan.sql script for that. What do you
observe?
a) As you can see, the execution plan is being forced by the hints to be two full table
scans, followed by a nest loop join.
SQL>
SQL> @check_evolve_plan
SQL> set echo on
SQL>
SQL> explain plan for
2 select /*+ USE_NL(s c) FULL(s) FULL(c) */ c.cust_id,
sum(s.quantity_sold)
3 from sh.sales s, sh.customers c
4 where s.cust_id = c.cust_id and c.cust_id < 2

Oracle Database 11g: New Features for Administrators A - 200


Practice 10-1: Using SQL Plan Management (continued)
5 group by c.cust_id;

Explained.

SQL>
SQL> select * from table(dbms_xplan.display(null, null));
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
------------------
Plan hash value: 4005616876

--------------------------------------------------------------
------------------
-------------------
ble
fe r a
| Id | Operation | Name | Rows | Bytes |
an s
Cost (%CPU)| Time
| Pstart| Pstop | n - t r
a no
a s ฺ
--------------------------------------------------------------
h
------------------
------------------- ฺ a r) uide
ฺ c om ent G
a on tud
PLAN_TABLE_OUTPUT
l l e@ is S
i
ฺz se th
--------------------------------------------------------------
------------------l o
| rceSTATEMENT
0 | SELECT
a t o u | | 1 | 13 |
898 m
( ens
(2)| 00:00:1e
1 |ille
l oZ li|c |
e
Marc |
898
1 | HASH GROUP BY
(2)| 00:00:1
| | 1 | 13 |

1 | | |

| 2 | NESTED LOOPS | | 1 | 13 |
897 (2)| 00:00:1
1 | | |

|* 3 | TABLE ACCESS FULL | CUSTOMERS | 1 | 5 |


405 (1)| 00:00:0
5 | | |

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
------------------

| 4 | PARTITION RANGE ALL| | 1 | 8 |


492 (3)| 00:00:0
6 | 1 | 28 |

Oracle Database 11g: New Features for Administrators A - 201


Practice 10-1: Using SQL Plan Management (continued)
|* 5 | TABLE ACCESS FULL | SALES | 1 | 8 |
492 (3)| 00:00:0
6 | 1 | 28 |

--------------------------------------------------------------
------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

-------------------

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
------------------
Predicate Information (identified by operation id):
---------------------------------------------------
ble
fe r a
3 - filter("C"."CUST_ID"<2)
an s
5 - filter("S"."CUST_ID"<2 AND "S"."CUST_ID"="C"."CUST_ID")
n - t r
18 rows selected. a no
h a s ฺ
SQL>
SQL> ฺ a r) uide
ฺ c om ent G
34) Now execute the statement so that youocan
a n get the u dplan in the cursor cache and load
the corresponding plan baseline.@ S t
Use the load_evolve_baseline.sql script
i l l e h i s
e l oฺz use t
for that. What do you observe?

a c the current
a) You can see rthat
t o plan is both enabled and accepted, but not fixed.
SQL> e (m
l e n se
SQL>
Z l
i @load_evolve_baseline
l ic
l oSQL> set echo on
rce SQL>
Ma SQL> variable cnt number;
SQL>
SQL> variable sqlid varchar2(20);
SQL>
SQL> select /*+ USE_NL(s c) FULL(s) FULL(c) */ c.cust_id,
sum(s.quantity_sold)
2 from sh.sales s, sh.customers c
3 where s.cust_id = c.cust_id and c.cust_id < 2
4 group by c.cust_id;

no rows selected

SQL>
SQL> begin
2 select sql_id into :sqlid from v$sql where sql_text like
'select /*+ USE_NL(s c) FULL(s) FULL(c) */%';
3 end;
4 /

Oracle Database 11g: New Features for Administrators A - 202


Practice 10-1: Using SQL Plan Management (continued)

PL/SQL procedure successfully completed.

SQL>
SQL> execute :cnt :=
dbms_spm.load_plans_from_cursor_cache(sql_id => :sqlid);
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

PL/SQL procedure successfully completed.

SQL>
SQL> select signature, sql_handle, sql_text, plan_name,
origin, enabled, accepted, fixed, autopurge
2 from dba_sql_plan_baselines
3 where sql_text like 'select /*+ USE_NL(s c) FULL(s)
FULL(c) */%';
ble
fe r a
SIGNATURE SQL_HANDLE
an s
---------- ------------------------------
SQL_TEXT n - t r
-------------------------------------------------------------- a no
------------------
h a s ฺ
PLAN_NAME ORIGIN r) uide
ENA ACC FIX AUT
ฺ a
------------------------------ -------------- --- --- --- ---
1.7750E+18 SYS_SQL_18a1ef14c17f5b75 ฺ c om ent G
on tud
select /*+ USE_NL(s c) FULL(s) FULL(c) */ c.cust_id,
a
sum(s.quantity_sold)
l l e@ is S
from s i
ฺz se th
l o
SQL_PLAN_1j8gg2m0ryqvpdc5f94e5 MANUAL-LOAD YES YES NO YES
a rce to u
l e (m ense
Zi
SQL>l lic
l o
e35) Manually create and execute a SQL Tuning task to tune your statement. Use the
rc
Ma tune_evolve_sql.sql script for that.
SQL>
SQL> @tune_evolve_sql
SQL> set echo on
SQL>
SQL> variable sqltext varchar2(4000);
SQL>
SQL> BEGIN
2 :sqltext := q'# select /*+ USE_NL(s c) FULL(s) FULL(c)
*/ c.cust_id, sum(s.quantity_sold)
3 from sh.sales s, sh.customers c
4 where s.cust_id = c.cust_id
5 and c.cust_id < 2
6 group by c.cust_id
7 #';
8 END;
9 /

Oracle Database 11g: New Features for Administrators A - 203


Practice 10-1: Using SQL Plan Management (continued)
PL/SQL procedure successfully completed.

SQL>
SQL> variable spmtune varchar2(30);
SQL>
SQL> exec :spmtune := dbms_sqltune.create_tuning_task(sql_text
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

=> :sqltext);

PL/SQL procedure successfully completed.

SQL>
SQL> exec dbms_sqltune.execute_tuning_task(:spmtune);

PL/SQL procedure successfully completed.


ble
SQL>
fe r a
SQL>
t r a ns
36) Now that the tuning task has been completed, run the report and see what
o n -
recommendations have been made for your statement. What do you
s a nobserve?
a) There are two recommendations: a SQL profile or a new
r ) haindex d ฺ
ecreation. Use the
report_evolve_tuning.sql script. ฺa u i
o m t G
SQL>
o n ฺc den
SQL> @report_evolve_tuninga
@ S tu
SQL> set echo on
z ill e t hi s
SQL> ฺ e
SQL> set longc10000
r elo o us
SQL>
e t
ma dbms_sqltune.report_tuning_task(:spmtune,'TEXT')
( s
ill dual;licen
SQL> e select

lo Z
from

rce DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
Ma --------------------------------------------------------------
------------------
GENERAL INFORMATION SECTION
--------------------------------------------------------------
-----------------
Tuning Task Name : TASK_163
Tuning Task Owner : SPM
Workload Type : Single SQL Statement
Scope : COMPREHENSIVE
Time Limit(seconds): 1800
Completion Status : COMPLETED
Started at : 06/19/2009 14:54:47
Completed at : 06/19/2009 14:54:53

DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
--------------------------------------------------------------

Oracle Database 11g: New Features for Administrators A - 204


Practice 10-1: Using SQL Plan Management (continued)
--------------------------------------------------------------
-----------------
Schema Name: SPM
SQL ID : dgs41cdr4t7q2
SQL Text : select /*+ USE_NL(s c) FULL(s) FULL(c) */
c.cust_id,
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

sum(s.quantity_sold)
from sh.sales s, sh.customers c
where s.cust_id = c.cust_id
and c.cust_id < 2
group by c.cust_id

DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
ble
--------------------------------------------------------------
fe r a
--------------------------------------------------------------
ans
FINDINGS SECTION (2 findings)
--------------------------------------------------------------n - t r
----------------- a no
h a s ฺ
1- SQL Profile Finding (see explain plans
ฺ a u
--------------------------------------------------------
ide below)
r) section
A potentially better execution c m was
oplan n t G
found for this
statement.

on tude
a
@ is S
i l l e
l o ฺz se thbenefit: 98.47%)
Recommendation (estimated
------------------------------------------
e o uthe recommended SQL profile. A SQL
rcaccepting
- Consider
m a e t plan
(
baseline s
Z ille licen
el oDBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
Marc --------------------------------------------------------------
------------------
corresponding to the plan with the SQL profile will also
be created.
execute dbms_sqltune.accept_sql_profile(task_name =>
'TASK_163',
task_owner => 'SPM', replace => TRUE);

Validation results
------------------
The SQL profile was tested by executing both its plan and
the original plan
and measuring their respective execution statistics. A plan
may have been
only partially executed if the other could be run to
completion in less time.

Original Plan With SQL Profile %


Improved

Oracle Database 11g: New Features for Administrators A - 205


Practice 10-1: Using SQL Plan Management (continued)
DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
--------------------------------------------------------------
------------- ---------------- -
Completion Status: COMPLETE COMPLETE
Elapsed Time(us): 158435 217
99.86 %
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

CPU Time(us): 157576 100


99.93 %
User I/O Time(us): 0 0
Buffer Gets: 2541 39
98.46 %
Physical Read Requests: 0 0
Physical Write Requests: 0 0
Physical Read Bytes: 0 0
Physical Write Bytes: 0 0
ble
Rows Processed: 0 0
fe r a
ans
DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
-------------------------------------------------------------- n - t r
------------------ a no
Fetches: 0
h0a s ฺ
Executions: 1
ฺ a r) uide
1

Notes ฺ c om ent G
----- a on tud
1. The original plan was
l e@ first i s Sexecuted to warm the buffer
cache. i l t h
2. Statistics e l oฺz original
for
u s e plan were averaged over next 4
executions.arc o
t plan was first executed to warm the
3. The( m s
SQL profile e
ille cache.
buffer
Z l i c en
rc elo 4. Statistics for the SQL profile plan were averaged over
next 9 executions.
Ma
2- Index Finding (see explain plans section below)

DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
--------------------------------------------------------------
--------------------------------------------------
The execution plan of this statement can be improved by
creating one or more
indices.

Recommendation (estimated benefit: 90.98%)


------------------------------------------
- Consider running the Access Advisor to improve the
physical schema design
or creating the recommended index.
create index SH.IDX$$_00A30001 on SH.SALES("CUST_ID");

Rationale

Oracle Database 11g: New Features for Administrators A - 206


Practice 10-1: Using SQL Plan Management (continued)
DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
--------------------------------------------------------------
------------------
Creating the recommended indices significantly improves
the execution plan
of this statement. However, it might be preferable to run
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

"Access Advisor"
using a representative SQL workload as opposed to a single
statement. This
will allow to get comprehensive index recommendations
which takes into
account index maintenance overhead and additional space
consumption.

--------------------------------------------------------------
ble
-----------------
fe r a
EXPLAIN PLANS SECTION
ans
--------------------------------------------------------------
----------------- n - t r
a no
h a s ฺ
DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
ฺ a r) uide
--------------------------------------------------------------
------------------ ฺ c om ent G
1- Original With Adjusted a on tud
Cost
------------------------------
l l e@ is S
i
ฺz se th
Plan hash value: 4005616876
l o
rce to u
--------------------------------------------------------------
a
l e (m ense
-------------------
| Idl
Zi (%CPU)| lic Time
| Operation | Name | Rows | Bytes |
el oCost
Marc | Pstart| Pstop |
--------------------------------------------------------------
-------------------
| 0 | SELECT STATEMENT | | 1 | 13 |
898 (2)| 00:00:1

DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
--------------------------------------------------------------
------------------
1 | | |
| 1 | HASH GROUP BY | | 1 | 13 |
898 (2)| 00:00:1
1 | | |
| 2 | NESTED LOOPS | | 1 | 13 |
897 (2)| 00:00:1
1 | | |
|* 3 | TABLE ACCESS FULL | CUSTOMERS | 1 | 5 |
405 (1)| 00:00:0
5 | | |

Oracle Database 11g: New Features for Administrators A - 207


Practice 10-1: Using SQL Plan Management (continued)
| 4 | PARTITION RANGE ALL| | 1 | 8 |
492 (3)| 00:00:0
6 | 1 | 28 |
|* 5 | TABLE ACCESS FULL | SALES | 1 | 8 |
492 (3)| 00:00:0
6 | 1 | 28 |
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
--------------------------------------------------------------
--------------------------------------------------------------
-------------------

Predicate Information (identified by operation id):


---------------------------------------------------
ble
3 - filter("C"."CUST_ID"<2)
fe r a
5 - filter("S"."CUST_ID"<2 AND "S"."CUST_ID"="C"."CUST_ID")
an s
2- Using SQL Profile n - t r
-------------------- a no
h a s ฺ
DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
ฺ a r) uide
--------------------------------------------------------------
------------------ ฺ c om ent G
Plan hash value: 3070788227 a on tud
l l e@ is S
i
ฺz se th
--------------------------------------------------------------
l o
---------------------------------------
| Id | Operation
a rce to u | Name
| Rows (m | Bytess|e
ille(%CPU)|
Cost c n
eTime | Pstart| Pstop |
Z l i
o--------------------------------------------------------------
el
Marc ---------------------------------------
| 0 | SELECT STATEMENT |
| 1 | 13 |
55 (2)| 00:00:01 | | |
| 1 | HASH GROUP BY |
| 1 | 13 |

DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
--------------------------------------------------------------
------------------
55 (2)| 00:00:01 | | |
| 2 | NESTED LOOPS |
| 1 | 13 |
54 (0)| 00:00:01 | | |
| 3 | PARTITION RANGE ALL |
| 1 | 8 |
54 (0)| 00:00:01 | 1 | 28 |
| 4 | TABLE ACCESS BY LOCAL INDEX ROWID| SALES
| 1 | 8 |
54 (0)| 00:00:01 | 1 | 28 |

Oracle Database 11g: New Features for Administrators A - 208


Practice 10-1: Using SQL Plan Management (continued)
| 5 | BITMAP CONVERSION TO ROWIDS |
| | |
| | | |
|* 6 | BITMAP INDEX RANGE SCAN | SALES_CUST_BIX
| | |
| | 1 | 28 |
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
--------------------------------------------------------------
------------------
|* 7 | INDEX UNIQUE SCAN | CUSTOMERS_PK
| 1 | 5 |
0 (0)| 00:00:01 | | |
--------------------------------------------------------------
---------------------------------------
ble
fe r a
Predicate Information (identified by operation id):
ans
---------------------------------------------------
n - t r
6 - access("S"."CUST_ID"<2) a no
filter("S"."CUST_ID"<2)
h a s ฺ
7 - access("S"."CUST_ID"="C"."CUST_ID")
ฺ a r) uide
c om ent G
DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')

on tud
--------------------------------------------------------------
a
------------------
l l e@ is S
i
ฺz se th
filter("C"."CUST_ID"<2)
l
e ouo
3- Using New a rcIndices t
( m
--------------------s e
Plan
Z cen 1501631325
illehash livalue:
rc elo --------------------------------------------------------------
Ma ---------------------------------------
| Id | Operation | Name
| Rows | Bytes |
Cost (%CPU)| Time | Pstart| Pstop |
--------------------------------------------------------------
------------------

DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
--------------------------------------------------------------
------------------
---------------------------------------
| 0 | SELECT STATEMENT |
| 1 | 13 |
5 (0)| 00:00:01 | | |
| 1 | SORT GROUP BY NOSORT |
| 1 | 13 |
5 (0)| 00:00:01 | | |
| 2 | NESTED LOOPS |
| | |

Oracle Database 11g: New Features for Administrators A - 209


Practice 10-1: Using SQL Plan Management (continued)
| | | |
| 3 | NESTED LOOPS |
| 1 | 13 |
5 (0)| 00:00:01 | | |
|* 4 | INDEX RANGE SCAN | CUSTOMERS_PK
| 1 | 5 |
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

2 (0)| 00:00:01 | | |

DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
--------------------------------------------------------------
------------------
|* 5 | INDEX RANGE SCAN | IDX$$_00A30001
| 1 | |
2 (0)| 00:00:01 | | |
| 6 | TABLE ACCESS BY GLOBAL INDEX ROWID| SALES
ble
| 1 | 8 |
fe r a
3 (0)| 00:00:01 | ROWID | ROWID |
ans
--------------------------------------------------------------
------------------ n - t r
--------------------------------------- a no
h a s ฺ
Predicate Information (identified by operation
a e
r) uidid):

---------------------------------------------------
ฺ c om ent G
4 - access("C"."CUST_ID"<2) a on tud
l l e@ is S
i
ฺz se th
DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
l o
--------------------------------------------------------------
rce to u
5 - access("S"."CUST_ID"="C"."CUST_ID")
a
l e (m ense
filter("S"."CUST_ID"<2)
Zi l lic
el o--------------------------------------------------------------
Marc SQL>
SQL>
37) Accept the SQL profile proposed by the SQL Tuning Advisor. Use the
accept_evolve_baseline.sql script for that. What happens?
a) Accepting the profile causes a new SQL profile and plan baseline to be created for
your statement. Now you see two baselines for your statement. Both of them are
enabled and accepted.
Note: One is MANUAL-LOAD and the other is MANUAL-SQLTUNE.
SQL>
SQL> @accept_evolve_baseline
SQL> set echo on
SQL>
SQL> select signature, sql_handle, sql_text, plan_name,
origin, enabled, accepted, fixed, autopurge
2 from dba_sql_plan_baselines
3 where sql_text like 'select /*+ USE_NL(s c) FULL(s)
FULL(c) */%';

Oracle Database 11g: New Features for Administrators A - 210


Practice 10-1: Using SQL Plan Management (continued)

SIGNATURE SQL_HANDLE
---------- ------------------------------
SQL_TEXT
--------------------------------------------------------------
PLAN_NAME ORIGIN ENA ACC FIX AUT
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

------------------------------ -------------- --- --- --- ---


1.7750E+18 SYS_SQL_18a1ef14c17f5b75
select /*+ USE_NL(s c) FULL(s) FULL(c) */ c.cust_id,
sum(s.quantity_sold)
from sh.sales s, sh.customers c
where s.cust_id = c.cust_id and c.cust_id < 2
group by c.cust_id
SQL_PLAN_1j8gg2m0ryqvpdc5f94e5 MANUAL-LOAD YES YES NO YES
ble
SQL>
fe r a
SQL> exec dbms_sqltune.accept_sql_profile(task_name =>
ans
:spmtune, name => 'SPM_SQL_PROF');
n - t r
PL/SQL procedure successfully completed. a no
h a s ฺ
SQL>
SQL> select signature, category, name, ฺ a )
rsql_text
u idefrom
dba_sql_profiles where name like c m nt G
o'SPM%';

on tude
SIGNATURE CATEGORY
a
@ is S NAME
i l l e h
oฺz use t
---------- ------------------------------ --------------------
SQL_TEXT e l
rc to
--------------------------------------------------------------
a
1.7750E+18 m
( ens
DEFAULT e SPM_SQL_PROF
l l e
l o Zi /*+licUSE_NL(s c) FULL(s) FULL(c) */ c.cust_id,
select
sum(s.quantity_sold)
rc e from sh.sales s, sh.customers c
Ma where s.cust_id = c.cust_id and c.cust_id < 2
group by c.cust_id

SQL>
SQL> select signature, sql_handle, sql_text, plan_name,
origin, enabled, accepted, fixed, autopurge
2 from dba_sql_plan_baselines
3 where sql_text like 'select /*+ USE_NL(s c) FULL(s)
FULL(c) */%';

SIGNATURE SQL_HANDLE
---------- ------------------------------
SQL_TEXT
--------------------------------------------------------------
PLAN_NAME ORIGIN ENA ACC FIX AUT
------------------------------ -------------- --- --- --- ---
1.7750E+18 SYS_SQL_18a1ef14c17f5b75
select /*+ USE_NL(s c) FULL(s) FULL(c) */ c.cust_id,
sum(s.quantity_sold)

Oracle Database 11g: New Features for Administrators A - 211


Practice 10-1: Using SQL Plan Management (continued)
from sh.sales s, sh.customers c
where s.cust_id = c.cust_id and c.cust_id < 2
group by c.cust_id
SQL_PLAN_1j8gg2m0ryqvpa10c1dcf MANUAL-SQLTUNE YES YES NO YES

SIGNATURE SQL_HANDLE
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

---------- ------------------------------
SQL_TEXT
--------------------------------------------------------------
PLAN_NAME ORIGIN ENA ACC FIX AUT
------------------------------ -------------- --- --- --- ---
1.7750E+18 SYS_SQL_18a1ef14c17f5b75
select /*+ USE_NL(s c) FULL(s) FULL(c) */ c.cust_id,
sum(s.quantity_sold)
from sh.sales s, sh.customers c ble
where s.cust_id = c.cust_id and c.cust_id < 2
fe r a
group by c.cust_id
ans
SQL_PLAN_1j8gg2m0ryqvpdc5f94e5 MANUAL-LOAD YES YES NO YES
n - t r
a no
SQL>
h a s ฺ
a
38) Determine the plan used for your statement when executing
ฺ de do you observe?
r) it.uiWhat
a) Next time you execute the query, it uses ฺ c omplanebaseline
the n t G and the SQL profile.
Use the explain_query5.sql a n ud
oscript.
@ S t
SQL> z ill e t hi s
ฺ e
SQL> @explain_query5
SQL> set echo r c elo o us
on
m a e t
SQL> ( s
n for
SQL>
Z i lleexplain
l i c eplan
e l o 2 select /*+ USE_NL(s c) FULL(s) FULL(c) */ c.cust_id,
rc sum(s.quantity_sold)
Ma 3
4
from sh.sales s, sh.customers c
where s.cust_id = c.cust_id and c.cust_id < 2
5 group by c.cust_id;

Explained.

SQL>
SQL> select * from table(dbms_xplan.display(null, null, 'basic
+note'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
------------------
Plan hash value: 3070788227

--------------------------------------------------------------
| Id | Operation | Name |
--------------------------------------------------------------
| 0 | SELECT STATEMENT | |

Oracle Database 11g: New Features for Administrators A - 212


Practice 10-1: Using SQL Plan Management (continued)
| 1 | HASH GROUP BY | |
| 2 | NESTED LOOPS | |
| 3 | PARTITION RANGE ALL | |
| 4 | TABLE ACCESS BY LOCAL INDEX ROWID|SALES |
| 5 | BITMAP CONVERSION TO ROWIDS | |
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
------------------
| 6 | BITMAP INDEX RANGE SCAN |SALES_CUST_BIX |
| 7 | INDEX UNIQUE SCAN |CUSTOMERS_PK |
--------------------------------------------------------------

Note
-----
ble
- SQL profile "SPM_SQL_PROF" used for this statement
fe r a
- SQL plan baseline "SQL_PLAN_1j8gg2m0ryqvpa10c1dcf" used
ans
for this statement
n - t r
19 rows selected. a no
h a s ฺ
SQL>
SQL> ฺ a r) uide
ฺ c om ent G
39) Execute the cleanup_spm.sql script
a oton purgetuyour
d environment for this practice.
SQL> l l e@ is S
SQL> @cleanup_spmoฺz
i th
SQL> set echocon
l
e o us e
SQL> a r t
( m s e
SQL> le
Z cen
il exec lidbms_sqltune.drop_sql_profile(name
'SPM_SQL_PROF');
=>

lo
rce
Ma PL/SQL procedure successfully completed.

SQL>
SQL> exec :cnt :=
dbms_spm.drop_sql_plan_baseline('SYS_SQL_18a1ef14c17f5b75');

PL/SQL procedure successfully completed.

SQL>
SQL> select signature, sql_handle, sql_text, plan_name,
origin, enabled, accepted, fixed, autopurge
2 from dba_sql_plan_baselines
3 where sql_text like 'select /*+ USE_NL(s c) FULL(s)
FULL(c) */%';

no rows selected

SQL>

Oracle Database 11g: New Features for Administrators A - 213


Practice 10-1: Using SQL Plan Management (continued)
SQL> select signature, category, name, sql_text from
dba_sql_profiles where name like 'SPM%';

no rows selected

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining
and Real Application Testing options
$
ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 214


Practices for Lesson 11

In this practice, you use a small application that updates a table as the basis for your
Database Replay sessions. This is to minimize the amount of resources needed to run the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

practice.

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 215


Practice 11-1: Using Database Replay
In this practice, you capture the workload for a small application using Database Replay.
You then replay this workload automatically to make sure that you get the same result as
during the original execution. Then you replay your workload, but this time in
nonsynchronized mode.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

1) Before you start this practice, you need to set up its environment. Execute the
wcr_init_grid.sh script. This script invokes a SQL script called
wcr_demo_init_grid.sql that creates a new user called JFV and a table called
wcr_grid, which represents a 10x10 grid where each cell is a color. Initially, the
script initializes the grid with all cells set to black.
$ cd /home/oracle/solutions/DBReplay
$ ./wcr_init_grid.sh
ble
SQL*Plus: Release 11.2.0.1.0 Production on Mon Oct 5 11:24:50 fe r a
2009 n s
n - tra
Copyright (c) 1982, 2009, Oracle. All rights reserved.
a no
Connected to: h a s ฺ
a )
rRelease e
id11.2.0.1.0
Oracle Database 11g Enterprise Edition
m ฺ G u -
Production
With the Partitioning, Automatic n ฺ coStorage
e n tManagement, OLAP,
Data Mining and Real Application
@ tud options
ao STesting
z i l le this
SQL> SQL> SQL> SQL>
jfv cascade rce
loฺ SQL> u seSQL> SQL> SQL> SQL> SQL> drop user
m *a e to
ERROR
i l l eat( line
c e n1:s
l Z
oORA-01918: li user 'JFV' does not exist
e
Marc SQL> SQL> 2 3
User created.

SQL> SQL>
Grant succeeded.

SQL> SQL> Connected.


SQL> SQL> drop table wcr_grid purge
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> SQL> 2 3 4 5 6 7
Table created.

SQL> SQL> 2 3 4 5 6 7 8 9 10 11
12 13 14 15 16 17 18 19 20 21 22 23 24
25 26 27
PL/SQL procedure successfully completed.

Oracle Database 11g: New Features for Administrators A - 216


Practice 11-1: Using Database Replay (continued)

SQL> SQL>
Commit complete.

SQL> SQL> SQL> Disconnected from Oracle Database 11g


Enterprise Edition Release 11.2.0.1.0 - Production
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

With the Partitioning, Automatic Storage Management, OLAP,


Data Mining and Real Application Testing options
$

2) To make sure that the practice is set up correctly, use the wcr_printgrid.sh script
to print the current content of the grid. What do you observe?
a) You should see a 10x10 grid full of bs.
$ ./wcr_printgrid.sh
ble
fe r a
SQL*Plus: Release 11.2.0.1.0 Production on Mon Oct 5 11:26:35
ans
2009
n - t r
Copyright (c) 1982, 2009, Oracle. a
All rights reserved.
no
h a s ฺ
Connected to:
ฺ a r) uide
Oracle Database 11g Enterprise Edition
c o m Release
n t G 11.2.0.1.0 -
onฺ Storage
Production
With the Partitioning, Automatic a t u de Management, OLAP,
Data Mining and Real Application
l l e@ is STesting options
ฺ z i th
l o s e
SQL> a rce to uON
SQL> SET SERVEROUTPUT

SQL> e
l (m ense
declare
l
Z23i begin c
col livarchar2(10);
e l o
rc 4 for i in 0..9 loop
Ma 5 for j in 0..9 loop
6 select substr(color,1,1) into col from wcr_grid where
xcoor=i and ycoor=j;
7 dbms_output.put(col||' ');
8 end loop;
9 dbms_output.put_line('');
10 end loop;
11 end;
12 /
b b b b b b b b b b
b b b b b b b b b b
b b b b b b b b b b
b b b b b b b b b b
b b b b b b b b b b
b b b b b b b b b b
b b b b b b b b b b
b b b b b b b b b b
b b b b b b b b b b
b b b b b b b b b b

Oracle Database 11g: New Features for Administrators A - 217


Practice 11-1: Using Database Replay (continued)

PL/SQL procedure successfully completed.

SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

With the Partitioning, Automatic Storage Management, OLAP,


Data Mining and Real Application Testing options
$
3) To use Database Replay, you need to create an operating system directory that holds
all files generated by the replay session. Create the
/home/oracle/solutions/dbreplay directory on your system (not
DBReplay!).
$ rm -rf /home/oracle/solutions/dbreplay ble
$ mkdir -p /home/oracle/solutions/dbreplay fe r a
$ ans
n - t r
no
4) You also need to create an Oracle directory object pointing to the previously created
a
operating system directory. s ฺ
h a
$ . oraenv
ฺ a r) uide
ORACLE_SID = [db10g] ? orcl
$ sqlplus system ฺ c om ent G
a on tud
SQL*Plus: Release 11.2.0.1.0 l e i s S
@ Production on Mon Oct 5 11:29:04
z i l t h
2009
c e loฺ use
Copyright (c)a r 1982,to2009, Oracle. All rights reserved.
l e ( ense
m
l
Zi password:
Enter lic **********
e l o
rc Connected to:
Ma Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> drop directory dbreplay;


drop directory dbreplay
*
ERROR at line 1:
ORA-04043: object DBREPLAY does not exist

SQL> create or replace directory dbreplay as


'/home/oracle/solutions/dbreplay';

Directory created.

SQL> exit

Oracle Database 11g: New Features for Administrators A - 218


Practice 11-1: Using Database Replay (continued)
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

5) The following is the step-by-step process of using Database Replay:


a) Log in to Enterprise Manager as the SYS user. Click the Software and Support
tab.
b) On the Software and Support subpage, click the Database Replay link in the Real
Application Testing section.
c) On the Database Replay page, click the Capture Workload icon in the “Go to
Task” column for the Capture Workload line. e
d) On the Capture Workload: Plan environment page, acknowledge both r a bl
prerequisites, and click Next.
fe
ns
t r a
-restart the
e) On the Capture Workload: Options page, make sure to select “Doo n
not
database prior to capture” in the Database Restart Options section,
s a n and make sure
that Filter Mode is set to Exclusion and that the Excluded
r ) ha deฺSessions
table contains both Oracle Management Service
m G uiManagement Agent.
ฺaand Oracle
Click Next.
n ฺ co ent
f) On the Capture Workload: Parameters ao page, d a Capture Name (for
tuspecify
example, use capturegrid1) @
le and S
isselect the Capture Directory that you
ฺ z i l t h
previously createdlo
c e (DBREPLAY).
u se Click Next.
a
g) On the Capture r Workload:
to Schedule page, specify a Job Name (for example, use
m e
i l l e ( icens
capturegrid1_job) and select Immediately from the Job Schedule section.
l Z l
oh) In the Job Credentials section, enter oracle/oracle for the Host Credentials and
e
Marc select “Save as Preferred Credentials.” Click Next. On the Capture Workload:
Review page, click Submit.
i) Wait on the Processing: Workload Capture page.
j) This takes you to the View Workload Capture page on which you should see the
In Progress status for your capture session.
k) Back at your terminal session, execute the wcr_demo_workload.sh script. This
script generates database sessions that randomly update the grid table with
different colors (red, green, blue, black, yellow, orange, and salmon). The script
should run for no more than two minutes.
[oracle@edrsr40p1-orcl DBReplay]$ ./wcr_demo_workload.sh
Mon Oct 5 11:38:48 UTC 2009
Connecting to the database...Connecting...
Connecting to the database...Connecting...
Connecting to the database...Connecting...
Connecting to the database...Connecting...
Connecting to the database...Connecting...
Connecting to the database...Connecting...

Oracle Database 11g: New Features for Administrators A - 219


Practice 11-1: Using Database Replay (continued)
Connecting to the database...Connecting...
connected.
connected.
connected.
connected.
connected.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

connected.
connected.
Done.
Done.
Done.
Done.
Done.
Done.
Done.
ble
Mon Oct 5 11:39:56 UTC 2009
fe r a
$
t r a ns
l) While the script executes, look at the /home/oracle/solutions/dbreplay
o n -
directory from a second terminal window. You should see the n
agenerated files.
$ ls -l /home/oracle/solutions/dbreplay ha
s ฺ
r ) i d e
total 8
drwxr----- 2 oracle dba 4096 Oct o5m11:36t cap
ฺa Gu
drwxr----- 3 oracle dba 4096 Oct
o n ฺc 5 11:36
d e n capfiles
-rw-r----- 1 oracle dba
@ a0 OctSt5u11:36 wcr_cap_00001.start
$
z i l l e t h is
total 4 c e loฺ use
$ ls -l /home/oracle/solutions/dbreplay/capfiles

a r todba 4096 Oct 5 11:36 inst1


drwxr----- m 12 oraclee
$
i l l e ( icens
el o$ Zls -l /home/oracle/solutions/dbreplay/capfiles/inst1
total 44
l
Marc drwxr-xr-x 2 oracle dba 4096 Oct 5 11:41 aa
drwxr-xr-x 2 oracle dba 4096 Oct 5 11:36 ab
drwxr-xr-x 2 oracle dba 4096 Oct 5 11:36 ac
drwxr-xr-x 2 oracle dba 4096 Oct 5 11:36 ad
drwxr-xr-x 2 oracle dba 4096 Oct 5 11:36 ae
drwxr-xr-x 2 oracle dba 4096 Oct 5 11:36 af
drwxr-xr-x 2 oracle dba 4096 Oct 5 11:36 ag
drwxr-xr-x 2 oracle dba 4096 Oct 5 11:36 ah
drwxr-xr-x 2 oracle dba 4096 Oct 5 11:36 ai
drwxr-xr-x 2 oracle dba 4096 Oct 5 11:36 aj
-rw-r--r-- 1 oracle dba 1198 Oct 5 11:36
wcr_cmqkrh0000000.rec
$
$ ls -l /home/oracle/solutions/dbreplay/capfiles/inst1/aa
total 980
-rw-r--r-- 1 oracle dba 982 Oct 5 11:36
wcr_cmqkth0000002.rec
-rw-r----- 1 oracle dba 1302 Oct 5 11:36
wcr_cmqkth0000003.rec

Oracle Database 11g: New Features for Administrators A - 220


Practice 11-1: Using Database Replay (continued)
-rw-r--r-- 1 oracle dba 1200 Oct 5 11:36
wcr_cmqkth0000004.rec
-rw-r--r-- 1 oracle dba 1198 Oct 5 11:36
wcr_cmqkth0000005.rec
-rw-r--r-- 1 oracle dba 1198 Oct 5 11:36
wcr_cmqkuh0000006.rec
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

-rw-r--r-- 1 oracle dba 1199 Oct 5 11:36


wcr_cmqkvh0000007.rec
-rw-r--r-- 1 oracle dba 1198 Oct 5 11:37
wcr_cmqkzh0000008.rec
-rw-r--r-- 1 oracle dba 988 Oct 5 11:37
wcr_cmqkzh0000009.rec
-rw-r--r-- 1 oracle dba 1210 Oct 5 11:37
wcr_cmqm5h000000c.rec
-rw-r--r-- 1 oracle dba 982 Oct 5 11:37
ble
wcr_cmqm9h000000d.rec
fe r a
-rw-r--r-- 1 oracle dba 1774 Oct 5 11:38
ans
wcr_cmqpjh000000h.rec
-rw-r--r-- 1 oracle dba 1293 Oct 5 11:38 n - t r
o
wcr_cmqpph000000j.rec
s an
-rw-r--r-- 1 oracle dba 130023 Oct 5 11:39
wcr_cmqqah000000n.rec r ) ha deฺ
-rw-r--r-- 1 oracle dba 129680 Oct 5 11:39 m ฺa Gui
wcr_cmqqah000000p.rec
n ฺ co ent
wcr_cmqqbh000000q.rec @ ao Stud
-rw-r--r-- 1 oracle dba 130284 Oct 5 11:39

i l le this
-rw-r--r-- 1 oracle dba 130319 Oct 5 11:39
z
wcr_cmqqch000000r.rec
c e loฺ use
r to
-rw-r--r-- 1 oracle dba 130612 Oct 5 11:39
a
m e
i l e ( icens
wcr_cmqqfh000000s.rec
l
-rw-r--r-- 1 oracle dba 130616 Oct 5 11:39
el oZ l
wcr_cmqqfh000000t.rec

Marc -rw-r--r-- 1 oracle dba 130619 Oct 5 11:39


wcr_cmqqfh000000u.rec
-rw-r--r-- 1 oracle dba 2973 Oct 5 11:41
wcr_cmqubh000000x.rec
-rw-r--r-- 1 oracle dba 2790 Oct 5 11:41
wcr_cmquch000000y.rec
$
$ ls -l /home/oracle/solutions/dbreplay/cap
total 4
-rw-r----- 1 oracle dba 206 Oct 5 11:36 wcr_scapture.wmd
$

m) Wait until the workload from step k is executed entirely.


n) Return to the Enterprise Manager View Workload Capture page and click Stop
Capture.
o) On the Confirmation page, click Yes.
p) Wait on the Processing: Stop Capture page.

Oracle Database 11g: New Features for Administrators A - 221


Practice 11-1: Using Database Replay (continued)
q) When you are at the Export AWR Data page, click No.
r) Back at the View Workload Capture page, you should see the refreshed Statistics
with Database Time, Average Active Sessions, User Calls, Transactions, Session
Logins, Application Errors. Make a note of these statistics (or click View
Workload Capture Report. Firefox prevents pop-ups, so click Preferences and
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

allow pop-ups, and then click Save to File to generate an HTML report), and click
OK. This takes you back to the Database Replay page.
s) From your terminal session, look at the workload results by executing the
wcr_printgrid.sh script. Make a note of the resulting colors in the grid. This
will be used later to confirm that the replay session went well. Make sure that you
keep your session output, or execute a CREATE TABLE modified_grid AS
SELECT * FROM jfv.wcr_grid;
t) Back at the Database Replay page, click the Preprocess Workload icon in the “Go ble
fe r a
to Task” column for the Process Workload task.
t r a ns
u) On the Preprocess Captured Workload page, select the capture Directory
o n -
(DBREPLAY). You should now see the Capture Summary section
with a Completed status. Click Preprocess Workload. as
a n on the page
r ) h deฺ
v) On the Preprocess Captured Workload: Database ฺa Gupage,
Version i click Next.
w) On the Preprocess Captured Workload:ฺc
m
o epage,
Schedule n t enter a job name (for
n
example, process_capturegrid1),
@ ao Smake tudsure that Immediately is selected,
z i l le th(oracle/oracle),
and specify your Host Credentials is if necessary. When done,
click Next.
c e loฺ use
a r Captured
x) On the Preprocess to Workload: Review page, click Submit.
m
( youenback e
s to the Database Replay page where you can see some
y) This
i l l e takes c
l o ZConfirmationli information.
rc e
Ma z) Wait for one or two minutes, and then click View Job in the Confirmation section.
aa) This takes you to the corresponding Execution page where you should see that the
job has succeeded. Click the Back arrow on your browser to return to the
Database Replay page.
bb) Back at your second terminal session; look at the generated files in the
/home/oracle/solutions/dbreplay/pp11.2.0.1.0 directory. You
should see additional files that correspond to the process phase you just did
(additional .wmd, .extb, and .pp files).
cc) Before you can replay the previously captured workload, you need to restore the
environment as it was just before you started the capture. Here, it is just a matter
of initializing the grid table again with black colors. So, back at your first terminal
session, execute the wcr_init_grid_table.sh script.
dd) When done, make sure that the grid table is correctly initialized with black colors
using the wcr_printgrid.sh script.

Oracle Database 11g: New Features for Administrators A - 222


Practice 11-1: Using Database Replay (continued)
ee) Back at the Enterprise Manager Database Replay page, select the Replay
Workload icon from the “Go to Task” column for the Replay Workload task.
ff) On the Replay Workload page, select your replay directory (DBREPLAY). The
Capture Summary section should appear on the page with the Completed status.
Note that the Replay History table should be empty at this point. Click Set Up
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Replay.
gg) On the Replay Workload: Prerequisites page, you can safely click Continue, as
you are already done with this part.
hh) On the Replay Workload: References to External Systems page, you can safely
click Continue as you are already done with this part.
ii) On the Replay Workload: Choose Initialize Options page, enter a replay name
(for example, replay_capturegrid1), and then make sure that “Use the
ble
default replay options” is selected. Click Next.
fe r a
jj) On the Replay Workload: Customize Options page, click the Replay Parameters ans
n - t r
tab.
a no
kk) On the Replay Parameters subpage, make sure that the synchronization
s ฺ value is
set to SCN. Click Next. h a
ฺ a r) uide
ll) On the Replay Workload: Prepare ReplayoClients
c m npage, t Gclick Next.
mm) On the Replay Workload: Wait for
ฺ de page. The system is now
n Connections
oClient
waiting for you to start replay
a
@clients.is S t u
i l l e thenter the following command at the OS
nn) From your secondlo ฺz session,
terminal s e
prompt:
a rce to u
e
$ . oraenv
l (m ense
Zi l
ORACLE_SID lic= [db10g] ? orcl
l o
e $ wrc REPLAYDIR=/home/oracle/solutions/dbreplay USERID=system
rc
Ma PASSWORD=oracle_4U

Workload Replay Client: Release 11.2.0.1.0 - Production on Mon


Oct 5 12:07:09 2009

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All


rights reserved.

Wait for the replay to start (12:07:09)


oo) From a third terminal session, enter the following command at the OS prompt:
$ . oraenv
ORACLE_SID = [db10g] ? orcl
$ wrc REPLAYDIR=/home/oracle/solutions/dbreplay USERID=system
PASSWORD=oracle_4U

Workload Replay Client: Release 11.2.0.1.0 - Production on Mon


Oct 5 12:08:24 2009

Oracle Database 11g: New Features for Administrators A - 223


Practice 11-1: Using Database Replay (continued)
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All
rights reserved.

Wait for the replay to start (12:08:24)


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

pp) The wrc executables are now waiting for you to start the replay operation from the
database.
qq) Back at the “Replay Workload: Wait for Client Connections” page, you should
see two rows in the Client Connections table on the page. These lines correspond
to the client session you have just started. Click Next.
rr) On the Replay Workload: Review page, click Submit to start the replay session
for capturegrid1. This takes you to the View Workload Replay page.
ble
ss) Back at your second and third terminal sessions, you should see that the replay
fe r a
clients started the replay.
t r a ns
tt) Back at the Enterprise Manager View Workload Replay page, wait until
o n - the
replay is completed.
s an
uu) When done, you can look at the generated Statistics on
r ) hathe View
d etheฺWorkload
Replay page. Look at the Detailed Comparisonฺa i
section. (Click
u “+” icon if you
want to view that information.) Click OK m
coto returnn G
tot the Database Replay page.
n ฺ e
vv) In your second and third terminal
@
o
awindows,
S tuthedclient sessions should also be
finished.
z i l le this
ww) From your first e
c loฺ session,
terminal
u se execute the wcr_printgrid.sh script to
look at thea r table after
grid to the replay is finished. You should see exactly the same
values m
(as youesaw e
nsright after you applied the workload for the first time. This is
i l l e c
l o Zbecause the li replay session was done using the synchronized mode.
rc e $ ./wcr_printgrid.sh
Ma
SQL*Plus: Release 11.2.0.1.0 Production on Mon Oct 5 12:23:26
2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> SET SERVEROUTPUT ON


SQL>
SQL> declare
2 col varchar2(10);
3 begin
4 for i in 0..9 loop
5 for j in 0..9 loop

Oracle Database 11g: New Features for Administrators A - 224


Practice 11-1: Using Database Replay (continued)
6 select substr(color,1,1) into col from wcr_grid where
xcoor=i and ycoor=j;
7 dbms_output.put(col||' ');
8 end loop;
9 dbms_output.put_line('');
10 end loop;
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

11 end;
12 /
y r g r s B B r b g
o B b s r g B g s B
b o y B g g y b o g
o y y s o r g y r o
b r g r g g s o s o
s s o r B y y s o r
o o B g g s g y b b
ble
B y y g b B B B B y
fe r a
s o r r B s B s B o
ans
y y r g g s g o r r
n - t r
PL/SQL procedure successfully completed. a no
h a s ฺ
SQL> exit;
Disconnected from Oracle Database 11g ฺ a r) uideEdition
Enterprise
Release 11.2.0.1.0 - Productionฺco
m nt G
With the Partitioning, Automatic a t u de Management, OLAP,
on Storage
Data Mining and Real Application
l l e@ is STesting options
$ i
ฺz se th
l o
a rce to u
l e (m ense
Zi l lic
e l o
rc
Ma

Oracle Database 11g: New Features for Administrators A - 225


Practice 11-2: Using Database Replay - Nonsynchronized Mode
In this practice, you replay your workload in nonsynchronized mode. You should observe
that the resulting grid is set up with different colors.

1) Before you can replay the previously captured workload, you need to restore the
environment as it was just before you started the capture. Here, it is just a matter of
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

initializing the grid table again with black colors. In your first terminal session,
execute the wcr_init_grid_table.sh script.
$ ./wcr_init_grid_table.sh
SQL*Plus: Release 11.2.0.1.0 Production on Mon Oct 5 15:41:08
2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to: ble


Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - fe r a
Production an s
With the Partitioning, Automatic Storage Management, OLAP, n - t r
Data Mining
a no
and Real Application Testing options
h a s ฺ
SQL> Connected. ฺ a r) uide
SQL> SQL>
ฺ c om ent G
100 rows deleted.
a on tud
l l e@ is S
SQL> SQL>
z i th
Commit complete.loฺ s e
a rce to u
SQL> SQL>
12 ille
13
(m14e2 ns15e3 164 175 186 197 208 219 2210 11
23 24
25Z 26 li27
c
l o
e PL/SQL procedure successfully completed.
rc
Ma SQL> SQL>
Commit complete.

SQL> SQL> Disconnected from Oracle Database 11g Enterprise


Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$
2) When done, make sure that the grid table is correctly initialized with black colors by
using the wcr_printgrid.sh script.
$ ./wcr_printgrid.sh
SQL*Plus: Release 11.2.0.1.0 Production on Mon Oct 5 15:42:35
2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Oracle Database 11g: New Features for Administrators A - 226


Practice 11-2: Using Database Replay - Nonsynchronized Mode
(continued)

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Data Mining
and Real Application Testing options

SQL> SET SERVEROUTPUT ON


SQL>
SQL> declare
2 col varchar2(10);
3 begin
4 for i in 0..9 loop
ble
5 for j in 0..9 loop
fe r a
6 select substr(color,1,1) into col from wcr_grid where
ans
xcoor=i and ycoor=j;
n - t r
7 dbms_output.put(col||' '); o
8 end loop;
s an
9 dbms_output.put_line('');
r ) ha deฺ
10 end loop;
11 end; m ฺa Gui
12 / n ฺ co ent
b b b b b b b b b b
@ ao Stud
b b b b b b b b b b
z i l le this
b b b b b b b b b b
b b b b b b b b b b
c e loฺ use
a r
b b b b b b b b b b to
m e
i l l e ( icens
b b b b b b b b b b

el oZ l
b b b b b b b b b b
b b b b b b b b b b

Marc b b b b b b b b b b
b b b b b b b b b b

PL/SQL procedure successfully completed.

SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$
3) On the Enterprise Manager Database Replay page, click the Replay Workload icon in
the “Go to Task” column for the Replay Workload line.
4) On the Replay Workload page, select your replay directory (DBREPLAY). The
Capture Summary section should appear on the page with the Completed Status. Note
that the Replay History table should contain two entries.
5) Click Set Up Replay.

Oracle Database 11g: New Features for Administrators A - 227


Practice 11-2: Using Database Replay - Nonsynchronized Mode
(continued)
6) On the Replay Workload: Prerequisites page, you can safely click Continue, as you
are already done with this part.
7) On the Replay Workload: References to External Systems page, you can safely click
Continue, as you are already done with this part, too.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

8) On the Replay Workload: Choose Initialize Options page, enter a replay name (for
example, replay_capturegrid3), and then make sure that “Use the default
replay options” is selected. Click Next.
9) On the Replay Workload: Customize Options page, click the Replay Parameters tab.
10) On the Replay Parameters subpage, make sure that the synchronization value is set to
OFF. Click Next.
11) On the Replay Workload: Prepare Replay Clients page, click Next. ble
fe r a
12) The system is now waiting for you to start replay clients.
t r a ns
13) From your second terminal session, enter the following command at the
o n - prompt.
OS
n
aUSERID=system
$ wrc REPLAYDIR=/home/oracle/solutions/dbreplay s
PASSWORD=oracle_4U
r ) ha deฺ
Workload Replay Client: Release 11.2.0.1.0 i
ฺa G- uProduction on Mon
Oct 5 15:47:33 2009 m
co ent
n ฺ
Copyright (c) 1982, 2009, a
@
o tud its affiliates. All
OracleSand/or
rights reserved.
z i l le this
ฺ se (15:47:33)
Wait for therc elo otoustart
replay
m a e t
(
14) From lyour s
n session, enter the following command at the OS prompt:
Z il e third
l i c eterminal
lo$ wrc REPLAYDIR=/home/oracle/solutions/dbreplay USERID=system
rce PASSWORD=oracle_4U
Ma Workload Replay Client: Release 11.2.0.1.0 - Production on Mon
Oct 5 15:48:20 2009

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All


rights reserved.

Wait for the replay to start (15:48:20)


15) The command is now waiting for you to start the replay operation from the database.
16) Back at the “Replay Workload: Wait for Client Connections” page, you should see
two rows in the Client Connections table. These lines correspond to the client
sessions you that have just started. Click Next.
17) On the Replay Workload: Review page, click Submit to start the replay session for
capturegrid1.
18) This takes you to the View Workload Replay page.

Oracle Database 11g: New Features for Administrators A - 228


Practice 11-2: Using Database Replay - Nonsynchronized Mode
(continued)
19) Back at your second and third terminal sessions, you should see that the replay clients
started the replay.
20) Back at the View Workload Replay page, wait until the replay is completed.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

21) In your second and third terminal windows, the client sessions should also be
finished.
22) From your first terminal session, execute the wcr_printgrid.sh script to look at
the grid table after replay is finished. You should see some differences with the
original workload result. This is because the replay session was done using
unsynchronized mode.
$ ./wcr_printgrid.sh
SQL*Plus: Release 11.2.0.1.0 Production on Mon Oct 5 15:59:28
ble
2009
fe r a
ans
Copyright (c) 1982, 2009, Oracle. All rights reserved.
n - t r
o
Connected to:
s an
r ) ha deฺ
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
m ฺa Gui
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining n ฺ co ent
and Real Application Testing options
@ ao Stud
z i l leON this
SQL> SET SERVEROUTPUT
SQL> c e loฺ use
SQL> declare a r to
2 ecol m e
( varchar2(10);
ns
3i l l begin c e
Z4 for ili in 0..9 loop
e l o
rc 5 for j in 0..9 loop
Ma 6 select substr(color,1,1) into col from wcr_grid where
xcoor=i and ycoor=j;
7 dbms_output.put(col||' ');
8 end loop;
9 dbms_output.put_line('');
10 end loop;
11 end;
12 /
r g g y B o b y o o
b o o o s y g B y s
g s r b o y r s r o
o y o s s s r y y y
s B y o s s y o r o
s o o y b o y s g y
o o b b y s y g r r
s o o s r o y s g B
g y y b s b y y g o
r b y g g s o B r s

Oracle Database 11g: New Features for Administrators A - 229


Practice 11-2: Using Database Replay - Nonsynchronized Mode
(continued)

PL/SQL procedure successfully completed.

SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Release 11.2.0.1.0 - Production


With the Partitioning, Automatic Storage Management, OLAP,
Data Mining
and Real Application Testing options
$

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 230


Practices for Lesson 12

By default, Automatic SQL Tuning executes automatically during each nightly


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

maintenance window. For this practice, you simulate the execution of Automatic SQL
Tuning, and explore its results

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 231


Practice 12-1: Using Automatic SQL Tuning
In this practice, you manually launch Automatic SQL Tuning to automatically tune a
small application workload. You then investigate the outcomes and configuration
possibilities.
1) Navigate to the Enterprise Manager Server page. Click Automated Maintenance
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Tasks in the Oracle Scheduler section. Verify that Status is set to Enabled. Click
Configure. Click the Configure button next to Automatic SQL Tuning. Select Yes for
“Automatic Implementation of SQL Profiles.” Then click Apply.
2) Execute the ast_setup.sh script from a terminal window connected as the oracle
user. This script creates the AST user used throughout this practice, turns off
automatic maintenance tasks, and drops any existing profiles on queries executed by
the AST user.
ble
$ cd /home/oracle/solutions/AST
fe r a
$ . oraenv
an s
ORACLE_SID = [db10g] ? orcl
n - t r
$
$ ./ast_setup.sh a no
h a s ฺ
SQL*Plus: Release 11.2.0.1.0 Production a r)on Tue e 6 07:16:32
idOct
ฺ u
2009
ฺ c om ent G
Copyright (c) 1982, 2009, a on tuAll
Oracle. d rights reserved.
@
le this S
z i l
Connected to:
Oracle Database e oฺ Enterprise
l11g u se Edition Release 11.2.0.1.0 -
Production ar
c t o
With e
l the
e n se
(mPartitioning, Automatic Storage Management, OLAP,
Z i
Data l li
Mining c and Real Application Testing options
e l o
rc SQL> SQL> SQL> SQL> drop user ast cascade
Ma *
ERROR at line 1:
ORA-01918: user 'AST' does not exist

SQL> SQL>
User created.

SQL> SQL>
Grant succeeded.

SQL> SQL>
System altered.

SQL> SQL> SQL> SQL> SQL> SQL>


System altered.

SQL> SQL> SQL> SQL> SQL> SQL>


PL/SQL procedure successfully completed.

Oracle Database 11g: New Features for Administrators A - 232


Practice 12-1: Using Automatic SQL Tuning (continued)

SQL> SQL> SQL> SQL> SQL> SQL> 2 3 4 5 6 7


8 9
PL/SQL procedure successfully completed.

SQL> SQL> Disconnected from Oracle Database 11g Enterprise


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Edition Release 11.2.0.1.0 - Production


With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$
3) In preparation for the practice, you should execute a workload. Execute the
run_workload_stream.sh script. This script executes, multiple times, a query that
is not correctly optimized. The query in question uses hints that force the optimizer to
pick a suboptimal execution plan. The script executes for approximately 30 to 60
ble
seconds.
fe r a
$ ./run_workload_stream.sh an s
Tue Oct 6 07:18:33 UTC 2009 n - t r
a no
SQL*Plus: Release 11.2.0.1.0 Production on a
h s Octฺ 6 07:18:33
Tue
2009
ฺ a r) uide
Copyright (c) 1982, 2009, Oracle. ฺ c omAllerights
n t G reserved.
a on tud
Connected to: S
le@ thisEdition
ฺ l
Oracle Database 11gziEnterprise Release 11.2.0.1.0 -
Production l o s e
rce to uAutomatic Storage Management, OLAP,
With the Partitioning,
a
(m eand
Data Mining
n e Application Testing options
sReal
l l e
l o Zi SQL> liSQL>
SQL>
c SQL>
rc e no rows selected
Ma SQL>
no rows selected

SQL>
no rows selected

SQL>
no rows selected

SQL> SQL> Disconnected from Oracle Database 11g Enterprise


Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Tue Oct 6 07:19:01 UTC 2009
$

Oracle Database 11g: New Features for Administrators A - 233


Practice 12-1: Using Automatic SQL Tuning (continued)
4) Automatic SQL Tuning is implemented using an automated task that runs during
maintenance windows. However, you are not going to wait for the next maintenance
window to open. This might take too long. Instead, you will force the opening of your
next maintenance window now. This will automatically trigger the Automatic SQL
Tuning task. Execute the run_ast.sh script to do that. The script’s execution takes
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

a couple of minutes.
$ ./run_ast.sh
Tue Oct 6 07:21:08 UTC 2009

SQL*Plus: Release 11.2.0.1.0 Production on Tue Oct 6 07:21:08


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.


ble
Connected to:
fe r a
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
an s
Production
n - t r
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options a no
h a s ฺ
SQL> SQL> SQL> SQL>
ฺ a r) uide
PL/SQL procedure successfully completed.
ฺ c om ent G
SQL> SQL> SQL> SQL> 2 a3o
n 4 ud
PL/SQL procedure successfully @ S t
completed.
z ill e t hi s
ฺ e
SQL> SQL>
r c elo o us
WINDOW
m a e t
( s
--------------------------------------------------------------
ille licen
TUESDAY_WINDOW
Z
rc elo SQL> SQL> SQL> SQL> SQL> SQL> 2
Ma System altered.

SQL> SQL> >


PL/SQL procedure successfully completed.

SQL> SQL> >


PL/SQL procedure successfully completed.

SQL> SQL>
PL/SQL procedure successfully completed.

SQL> SQL> SQL> SQL> SQL> SQL>


PL/SQL procedure successfully completed.

SQL> SQL> 2 3 4 5 6 7 8 9 10 11
12 13 14 15 16 17 18 19 20 21 22
PL/SQL procedure successfully completed.

SQL> SQL> 2

Oracle Database 11g: New Features for Administrators A - 234


Practice 12-1: Using Automatic SQL Tuning (continued)
System altered.

SQL> SQL> SQL> SQL> SQL> SQL> SQL> >


PL/SQL procedure successfully completed.

SQL> SQL> >


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

PL/SQL procedure successfully completed.

SQL> SQL> SQL> Disconnected from Oracle Database 11g


Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Tue Oct 6 07:32:16 UTC 2009
$

5) Execute the run_workload_stream.sh script again. What do you observe? ble


fe r a
a) You should see that the execution time for run_workload_stream.sh is much
ans
- t r
faster than the original execution. This is probably due to the fact that Automatic
n
no
SQL Tuning implemented a profile for your statement automatically.
a
$ ./run_workload_stream.sh h a s ฺ
Tue Oct 6 07:35:15 UTC 2009
ฺ a r) uide
SQL*Plus: Release 11.2.0.1.0 Production ฺ c om enont GTue Oct 6 07:35:15
2009 a on tud
l l e@ is S
Copyright (c) 1982, i
ฺz 2009, th
Oracle. All rights reserved.
e l o u s e
Connected to: a rc t o
Oracle (m ens11g
Database
e Enterprise Edition Release 11.2.0.1.0 -
i l l e ic
l o Z
Production l
rc e With the Partitioning, Automatic Storage Management, OLAP,
Ma
Data Mining and Real Application Testing options

SQL> SQL> SQL> SQL>


no rows selected

SQL>
no rows selected

SQL>
no rows selected

SQL> SQL> Disconnected from Oracle Database 11g Enterprise


Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Tue Oct 6 07:35:15 UTC 2009
$
6) Force the creation of an AWR snapshot.

Oracle Database 11g: New Features for Administrators A - 235


Practice 12-1: Using Automatic SQL Tuning (continued)
$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle
$
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

$ sqlplus ast/ast

SQL*Plus: Release 11.2.0.1.0 Production on Tue Oct 6 07:37:45


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
ble
Production
fe r a
With the Partitioning, Automatic Storage Management, OLAP,
ans
Data Mining and Real Application Testing options
n - t r
SQL> set echo on a no
h a s ฺ
SQL>

SQL> exec dbms_workload_repository.create_snapshot; a r) uide
ฺ c om ent G
PL/SQL procedure successfully a oncompleted.
tud
@
le this S
SQL> exit z i l
Disconnected from
c e loฺOracle u seDatabase 11g Enterprise Edition
r
Release 11.2.0.1.0
a t-oProduction
With the m
( ens e
Partitioning, Automatic Storage Management, OLAP,
l l e
i Mining
Data
o$ Z licand Real Application Testing options
r c el
Ma 7) How would you confirm that a SQL Profile was automatically implemented?
a) In Oracle Enterprise Manager, locate the Automatic SQL Tuning summary page
under Server > Automated Maintenance Tasks > Automatic SQL Tuning. The
task has already run in one maintenance window and has results ready to be
viewed.
b) View the tuning results.
c) Look at the graphs on the Automatic SQL Tuning Result Summary page.
d) Focus on understanding the pie chart and the bar graph next to it. You should be
able to get a feeling for the general findings breakdown, as well as the number of
SQL profiles implemented by the task.
e) Click View Report to see a detailed SQL-level report. Find and select the SQL
that ran in the AST schema. Note the green check mark meaning that the profile
was implemented.
f) Click the View Recommendations button.

Oracle Database 11g: New Features for Administrators A - 236


Practice 12-1: Using Automatic SQL Tuning (continued)
g) Click the Compare Explain Plans eyeglass icon for the SQL Profile entry.
h) Look at the old and new explain plans for the query.
i) Then click the “Recommendations for SQL ID” locator link to return to the
previous page.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

j) Investigate a SQL profile. While still on the “Recommendations for SQL_ID”


page, click the SQL text to go to the SQL Details page for this SQL.
k) The Tuning History tabbed page appears. Note the
SYS_AUTO_SQL_TUNING_TASK link that shows that the SQL statement was
tuned by this tuning task.
l) Look at the Plan Control subpage and note that a profile was created
automatically for this SQL. The type of AUTO means it was automatically created.
ble
m) Click the Statistics tab to take a look at the execution history for this SQL.
fe r a
n) Depending on the speed of your machine, you may not see two hash values. If an s
n - t
that is the case, ignore this step and the following one. Select Real Time: Manual
r
no
Refresh from the View Data and then each of possible two Plan Hash Values from
a
a s ฺ
the corresponding drop-down list. Choose one after the other and wait for the
h
page to refresh each time.
ฺ a r) uide
o) Depending on the speed of your environment,
ฺ c omyou n t G see one statement with
should
on tuand
a relatively high elapsed time per execution,
a deone with very low elapsed time
per execution. This showse
l @improved
the
i s Splan. If you select All from the Plan Hash
Values drop-down list, ฺ z i l
you might t h
not be able to see the execution corresponding
to the statement l o
eafter tuning e
uson the Summary graph. This might be because the
workload wasa rctoo shortt oto execute.
( m s e
Z ille a text
8) Generate
l i en for more in-depth information. From the command line,
creport
rc eloexecute the get_task_report.sh script. What do you observe?
Ma a) Note the first queries that fetch execution name and object number from the
advisor schema, followed by the final query that gets the text report. In the text
report, look for the section about the SQL profile finding and peruse the
Validation Results section. This shows you the execution statistics observed
during test-execute and allows you to get more of a feeling about the profile’s
quality. You can also use the report_auto_tuning_task API to get reports
that span multiple executions of the task.
$ ./get_task_report.sh

SQL*Plus: Release 11.2.0.1.0 Production on Tue Oct 6 07:50:20


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production

Oracle Database 11g: New Features for Administrators A - 237


Practice 12-1: Using Automatic SQL Tuning (continued)
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL>


Session altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> SQL> 2 3 4
EXECUTION_NAME STATUS EXECUTION_START
------------------------------ ----------- -------------------
EXEC_298 COMPLETED 10/06/2009 07:21:18

SQL> SQL> SQL> SQL> 2 3 4 5 6 7


PL/SQL procedure successfully completed.

SQL> SQL>
ble
LAST_EXEC
fe r a
--------------------------------------------------------------
ans
EXEC_298
n - t r
SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> 2
o
3 n 4 5
s a
6 7 8 9 10
PL/SQL procedure successfully completed. r ) ha deฺ
m ฺa Gui
SQL> SQL>
n ฺ co ent
OBJ_ID
---------- @ ao Stud
11 z i l le this
c e loฺ use
ar SQL>
SQL> SQL> SQL>
SECTION(m e toSQL> SQL> 2 3 GENERAL INFORMATION
i l l e icens
--------------------------------------------------------------
l o Z l
Tuning Task Name :
rc e SYS_AUTO_SQL_TUNING_TASK
Ma Tuning Task Owner : SYS
Workload Type : Automatic High-Load
SQL Workload
Scope : COMPREHENSIVE
Global Time Limit(seconds) : 3600
Per-SQL Time Limit(seconds) : 1200
Completion Status : COMPLETED
Started at : 10/06/2009 07:21:18
Completed at : 10/06/2009 07:31:36
Number of Candidate SQLs : 42
Cumulative Elapsed Time of SQL (s) : 369

--------------------------------------------------------------
Object ID : 11
Schema Name: AST
SQL ID : by9m5m597zh19
SQL Text : select /*+ USE_NL(s c) FULL(s) FULL(c) AST */
c.cust_id,sum(s.quantity_sold) from sh.sales s, sh.customers c

Oracle Database 11g: New Features for Administrators A - 238


Practice 12-1: Using Automatic SQL Tuning (continued)
where s.cust_id = c.cust_id and c.cust_id < 2 group by
c.cust_id

--------------------------------------------------------------
FINDINGS SECTION (2 findings)
--------------------------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

1- SQL Profile Finding (see explain plans section below)


--------------------------------------------------------
A potentially better execution plan was found for this
statement.
SQL profile "SYS_SQLPROF_ 012428bb9c6e0000" was created
automatically for this statement.

Recommendation (estimated benefit: 98.47%) e


------------------------------------------
r a bl
- An automatically-created SQL profile is present on the s fe
system.
- t r an
Name: SYS_SQLPROF_ 012428bb9c6e0000 nno
Status: ENABLED
a
s ฺ
h a
Validation results
------------------ ฺ a r) uide
The SQL profile was tested by executing ฺ c om enboth t G its plan and the
original plan and measuring o
a n respective
their
u d execution
statistics. A plan may have @ been S t
only partially executed if
l l e i s
the other could be zrun
l o ฺ i to e th
completion in less time.

rce tOriginal
o us Plan With SQL Profile % Improved
a
l e (m Status:
e n se ------------- ---------------- ----------
Z l
Completion
i Time(us):
l i c COMPLETE COMPLETE

rc eloCPU Time(us):
Elapsed 184526
183172
194
200
99.89 %
99.89 %
Ma User I/O Time(us):
Buffer Gets:
0
2541
0
39 98.46 %
Physical Read Requests: 0 0
Physical Write Requests: 0 0
Physical Read Bytes: 0 0
Physical Write Bytes: 0 0
Rows Processed: 0 0
Fetches: 0 0
Executions: 1 1

Notes
-----
1. The original plan was first executed to warm the buffer
cache.
2. Statistics for original plan were averaged over next 4
executions.
3. The SQL profile plan was first executed to warm the
buffer cache.

Oracle Database 11g: New Features for Administrators A - 239


Practice 12-1: Using Automatic SQL Tuning (continued)
4. Statistics for the SQL profile plan were averaged over
next 9 executions.

2- Index Finding (see explain plans section below)


--------------------------------------------------
The execution plan of this statement can be improved by
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

creating one or more indices.

Recommendation (estimated benefit: 90.98%)


------------------------------------------
- Consider running the Access Advisor to improve the
physical schema design or creating the recommended index.
create index SH. IDX$$_00010003 on SH.SALES("CUST_ID");

Rationale
ble
---------
fe r a
Creating the recommended indices significantly improves the
ans
execution plan of this statement. However, it might be
preferable to run "Access Advisor" using a representative SQLn - t r
workload as opposed to a single statement. This will allow to a no
get comprehensive index recommendations which takes into
h a s ฺ
account index maintenance overhead and additional space
consumption. ฺ a r) uide
ฺ c om ent G
on tud
--------------------------------------------------------------
a
EXPLAIN PLANS SECTION @
l e i s S
i l h
oฺz use t
--------------------------------------------------------------
e l
c Adjusted
1- OriginalarWith to Cost
m
( ens e
------------------------------
i
Plan l l ehash c
l o Z livalue: 4005616876

rc e --------------------------------------------------------------
Ma -------------------
| Id | Operation | Name | Rows | Bytes |
Cost (%CPU)| Time
| Pstart| Pstop |
--------------------------------------------------------------
-------------------
| 0 | SELECT STATEMENT | | 1 | 13 |
898 (2)| 00:00:1
1 | | |
| 1 | HASH GROUP BY | | 1 | 13 |
898 (2)| 00:00:1
1 | | |
| 2 | NESTED LOOPS | | 1 | 13 |
897 (2)| 00:00:1
1 | | |
|* 3 | TABLE ACCESS FULL | CUSTOMERS | 1 | 5 |
405 (1)| 00:00:0
5 | | |

Oracle Database 11g: New Features for Administrators A - 240


Practice 12-1: Using Automatic SQL Tuning (continued)
| 4 | PARTITION RANGE ALL| | 1 | 8 |
492 (3)| 00:00:0
6 | 1 | 28 |
|* 5 | TABLE ACCESS FULL | SALES | 1 | 8 |
492 (3)| 00:00:0
6 | 1 | 28 |
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

--------------------------------------------------------------
-------------------

Predicate Information (identified by operation id):


---------------------------------------------------

3 - filter("C"."CUST_ID"<2)
5 - filter("S"."CUST_ID"<2 AND "S"."CUST_ID"="C"."CUST_ID")
ble
2- Using SQL Profile
fe r a
--------------------
ans
Plan hash value: 3070788227
n - t r
o
an
--------------------------------------------------------------
s
---------------------------------------
| Id | Operation r )
| Nameha deฺ
| Rows | Bytes | m ฺa Gui
Cost (%CPU)| Time | Pstart| Pstop |
n ฺ co ent
@ ao Stud
--------------------------------------------------------------
---------------------------------------
| 0 | SELECT STATEMENT z i l le this |
| 1 | 13 |
c e loฺ use
55 r
(2)| 00:00:01 |
a to | |
m e
|
| i l e ( icens
1 | HASH GROUP BY
l
1 | 13 |
|

el oZ 55
l
(2)| 00:00:01 | | |

Marc |
|
2 |
1 |
NESTED LOOPS
13 |
|

54 (0)| 00:00:01 | | |
| 3 | PARTITION RANGE ALL |
| 1 | 8 |
54 (0)| 00:00:01 | 1 | 28 |
| 4 | TABLE ACCESS BY LOCAL INDEX ROWID| SALES
| 1 | 8 |
54 (0)| 00:00:01 | 1 | 28 |
| 5 | BITMAP CONVERSION TO ROWIDS |
| | |
| | | |
|* 6 | BITMAP INDEX RANGE SCAN | SALES_CUST_BIX
| | |
| | 1 | 28 |
|* 7 | INDEX UNIQUE SCAN | CUSTOMERS_PK
| 1 | 5 |
0 (0)| 00:00:01 | | |
--------------------------------------------------------------
---------------------------------------

Oracle Database 11g: New Features for Administrators A - 241


Practice 12-1: Using Automatic SQL Tuning (continued)

Predicate Information (identified by operation id):


---------------------------------------------------

6 - access("S"."CUST_ID"<2)
filter("S"."CUST_ID"<2)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

7 - access("S"."CUST_ID"="C"."CUST_ID")
filter("C"."CUST_ID"<2)

3- Using New Indices


--------------------
Plan hash value: 2481939942

--------------------------------------------------------------
---------------------------------------
ble
| Id | Operation | Name
fe r a
| Rows | Bytes |
ans
Cost (%CPU)| Time | Pstart| Pstop |
n
-------------------------------------------------------------- - t r
o
---------------------------------------
s an
|
|
0 | SELECT STATEMENT
1 | 13 |
|
r ) ha deฺ
5 (0)| 00:00:01 | | | m ฺa Gui
| 1 | SORT GROUP BY NOSORT
n ฺ co ent
|
|
5
1 | 13 |
(0)| 00:00:01 | | @ ao Stud
|
| 2 | NESTED LOOPS z i l le this |
| | |
c e loฺ use
| a r | to | |
m e
|
| i
3 |
l l e ( icens
1 |
NESTED LOOPS
13 |
|

el oZ 5
l
(0)| 00:00:01 | | |

Marc |* 4 |
| 1 |
INDEX RANGE SCAN
5 |
| CUSTOMERS_PK

2 (0)| 00:00:01 | | |
|* 5 | INDEX RANGE SCAN | IDX$$_00010001
| 1 | |
2 (0)| 00:00:01 | | |
| 6 | TABLE ACCESS BY GLOBAL INDEX ROWID| SALES
| 1 | 8 |
3 (0)| 00:00:01 | ROWID | ROWID |
--------------------------------------------------------------
---------------------------------------

Predicate Information (identified by operation id):


---------------------------------------------------

4 - access("C"."CUST_ID"<2)
5 - access("S"."CUST_ID"="C"."CUST_ID")
filter("S"."CUST_ID"<2)

--------------------------------------------------------------

Oracle Database 11g: New Features for Administrators A - 242


Practice 12-1: Using Automatic SQL Tuning (continued)

SQL> SQL> Disconnected from Oracle Database 11g Enterprise


Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

9) Investigate how to configure Automatic SQL Tuning using Enterprise Manager.


a) Return to Enterprise Manager and go to the Automated Maintenance Tasks page.
b) The chart here shows times in the past when each client was executed, and times
in the future when they are scheduled to run again.
c) Modify the graph’s begin and end points with the arrows below the chart.
d) Click the Configure button.
ble
e) The Automated Maintenance Tasks Configuration page appears. fe r a
an s
f) From this page, you can disable individual clients and change which windows
n - t r
they run in.
a no
g) Disable the Automatic SQL Tuning client by selecting Disabled.
h a s ฺClick Apply and
then click the locator link to return to the Automated
ฺ a u ide Tasks page.
r) Maintenance
h) Notice the forbidden sign (red circle with c m next
oslash) n t toGthe task name.

on tudpage. e
i) Click Configure to return to the a configuration Click Enabled for the
Automatic SQL Tuningitask l e@and i
click s S
Apply. Click the locator link to return to
z l t h
loฺ usTasks
the Automated Maintenance
c e e page.
a r
j) Click the Automatic to Tuning link on the Automated Maintenance Tasks
SQL
m e
i l l e ( icepage.
Configuration ns
l ok)ZThis takesl you to the page where you can configure the task itself.
rc e
Ma l) From the Automatic SQL Tuning Result Summary page, click the Configure
button right next to the “Automatic Implementation of SQL Profiles is currently
Enabled” field.
m) On the Automatic SQL Tuning Settings page, select No in front of the “Automatic
Implementation of SQL Profiles” field and click Apply. Click the Database
Instance link to return to the Server page.
10) OPTIONAL: You can investigate how to configure Automatic SQL Tuning using
PL/SQL by looking at the manual_config.sh script.
Note: In your case, the task executes quickly because the workload to take into
account is really small. However, you could use the interrupt_task.sh script
from another session to stop the task, should it last too long.

Oracle Database 11g: New Features for Administrators A - 243


Practices for Lesson 13

In the practices for this lesson, you create AWR baselines. You monitor the performance
of AUTOTASK jobs and adjust the resources and windows for AUTOTASK jobs.
Finally, you calibrate I/O resources.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 244


Practice 13-1: Creating Baselines
Using the orcl database, create baselines. (This exercise requires that the default
snapshot collection has been running since the database was started.)
1) Create a baseline over past snapshots, and compute statistics over the static baseline.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

a) As the SYS user, click the Server tab on the Home page of Database Control. On
the Server page, click the AWR Baselines link in the Statistics Management
section.
b) On the AWR Baselines page, click the Create button.
c) On the Create Baseline: Baseline Interval Type page, select Single and click
Continue.
d) On the Create Baseline: Single Baseline page, set the Baseline Name to Monday. e
Expand the Change Chart Time Period section. Choose Sunday's date for the r a bl
Chart Start Date and Tuesday's date for the Chart End Date, and click Go. Then s fe
t r an
click the first snapshot icon below the chart that represents the earliest time on
-
n
no
Monday. (A drop down box may appear for Period Start Time. If so, choose the
a
earliest time.) Click the radio button for Period End Time and click on the
s ฺ
h a
snapshot icon below the chart closest to midnight on Tuesday. Click Finish.
ฺ a r) uide
e) On the AWR Baselines page, select the Monday m nt G and then select
baseline,
c o
Schedule Statistics Computation from
a onฺthe Actions
t u de drop-down list. Click Go.
f) On the Compute Threshold Statistics:
l e @ isMonday S page, confirm that Immediately is
selected, and click Submit i l
ฺz se t to start h
the computation job.
l o
a r ce page
g) The AWR Baselines
t o uwill be displayed. Wait for a while and refresh the
e m nse
page. (The Statistics Computed column displays Yes when the job is completed.
Z ill maylhave
You
i ce to refresh the page several times.
rc e2)loCustomize the Performance page.
Ma a) On the AWR Baselines page select Customize Performance Page from the
Actions drop-down list, and click Go.
b) Accept the default settings. Click OK.
c) Navigate to the Performance Page and observe the differences.
3) Create a repeating baseline in the future.
a) Navigate to the AWR Baseline page, and then click Create.
b) Choose Repeating for the baseline Interval type, and click Continue.

Oracle Database 11g: New Features for Administrators A - 245


Practice 13-1: Creating Baselines (continued)
c) On the Create Baseline: Repeating Baseline Template, set the following:
Baseline Name: afterwork
Start Time: 6:00 PM
Duration: 12 hours
Frequency: Daily
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Start Time: Set it to the Sunday preceding the class.


End Time: Set it to the Saturday following the class.
Retention Time 28 days.
d) Click Finish.
e) On the AWR Baselines page, click AWR Baseline Templates in the Related Links
section.
f) On the AWR Baseline Templates page, notice that a template has been created for
the future baselines that will be created. ble
fe r a
4) View the Data Dictionary views.
ans
a) Connect to the orcl database instance as the SYS user. n - t r
n o
b) Select the BASELINE_NAME and BASELINE_TYPE columns a
s from
DBA_HIST_BASELINE. ) h a e ฺ
r
ฺa Gu i d
$ . oraenv o m t
ORACLE_SID = [db10g] ? orcl nฺc e n
$ sqlplus / as sysdba
@ ao Stud
z ille thProduction
SQL*Plus: Releaseoฺ11.2.0.1.0
is on Tue Oct 6 11:24:33
2009 e l u s e
a rc t o
Copyright
l e se 2009, Oracle. All rights reserved.
(m(c)en1982,
Zi l lic
l o
e Connected to:
rc
Ma Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> select baseline_name, baseline_type from


dba_hist_baseline;

BASELINE_NAME BASELINE_TYPE
------------------------------------------------ -------------
Monday STATIC
SYSTEM_MOVING_WINDOW MOVING_WINDOW

SQL>

c) Describe DBA_HIST_BASELINE_DETAILS.
SQL> desc dba_hist_baseline_details
Name Null? Type
--------------------------------- -------- ----------

Oracle Database 11g: New Features for Administrators A - 246


Practice 13-1: Creating Baselines (continued)
DBID NUMBER
INSTANCE_NUMBER NUMBER
BASELINE_ID NUMBER
BASELINE_NAME VARCHAR2(64)
BASELINE_TYPE VARCHAR2(13)
START_SNAP_ID NUMBER
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

START_SNAP_TIME TIMESTAMP(3)
END_SNAP_ID NUMBER
END_SNAP_TIME TIMESTAMP(3)
SHUTDOWN VARCHAR2(3)
ERROR_COUNT NUMBER
PCT_TOTAL_TIME NUMBER
LAST_TIME_COMPUTED DATE
MOVING_WINDOW_SIZE NUMBER
CREATION_TIME DATE
ble
EXPIRATION NUMBER
fe r a
TEMPLATE_NAME VARCHAR2(64)
ans
SQL> exit n - t r
o
an
Disconnected from Oracle Database 11g Enterprise Edition
s
Release 11.2.0.1.0 - Production
r ) ha deฺ
With the Partitioning, Automatic Storage Management, OLAP,
ฺa Gui
Data Mining and Real Application Testing options
m
$
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 247


Practice 13-2: Controlling AutoTask Jobs
Automatic maintenance tasks are designed to run in the maintenance windows. The tasks
are assigned to consumer groups based on job class. The jobs and windows are designed
to complete in the allotted time, without using excessive resources.
1) Review the window settings for the automatic maintenance tasks. When does the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Tuesday window open and for how long is it open?


a) Navigate to the Server page and click Window Groups in the Oracle Scheduler
section.
b) On the Scheduler Window Groups page, click MAINTENACE_WINDOW_GROUP.
c) On the View Window Group: MAINTENANCE_WINDOW_GROUP page, Click
TUESDAY_WINDOW.
ble
d) The Tuesday window opens every Tuesday at 10:00 PM for four hours.
fe r a
e) Click the Database link to return to the Database Home page. an s
n - t r
a no
2) How long do the automatic maintenance tasks take to complete? How much resource
is allocated to these jobs? Statistical information about the automatic maintenance
tasks is kept in the DBA_AUTOTASK_CLIENT view. h a s ฺ
ฺ a r) uide
a) In a terminal window, invoke SQL*Plus and
c o m nt asGthe SYS user.
connect
DESCRIBE the DBA_AUTOTASK_CLIENT
a onฺ tudview.
e
$ cd /home/oracle/solutions/INFRA
l l e@ is S
$ . oraenv i
ฺz ? orcl th
ORACLE_SID = [orcl] l o s e
The Oracle abase rce forto u
l e (m ense
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
i l
/u01/app/oracle
Z li c
e l o$
rc $ sqlplus / as sysdba
Ma
SQL*Plus: Release 11.2.0.1.0 Production on Tue Oct 6 11:33:43
2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> desc dba_autotask_client


Name Null? Type
----------------------- -------- ---------------------------
CLIENT_NAME VARCHAR2(64)
STATUS VARCHAR2(8)
CONSUMER_GROUP VARCHAR2(30)
CLIENT_TAG VARCHAR2(2)

Oracle Database 11g: New Features for Administrators A - 248


Practice 13-2: Controlling AutoTask Jobs (continued)
PRIORITY_OVERRIDE VARCHAR2(7)
ATTRIBUTES VARCHAR2(4000)
WINDOW_GROUP VARCHAR2(64)
SERVICE_NAME VARCHAR2(64)
RESOURCE_PERCENTAGE NUMBER
USE_RESOURCE_ESTIMATES VARCHAR2(5)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

MEAN_JOB_DURATION INTERVAL DAY(9) TO SECOND(9)


MEAN_JOB_CPU INTERVAL DAY(9) TO SECOND(9)
MEAN_JOB_ATTEMPTS NUMBER
MEAN_INCOMING_TASKS_7_DAYS NUMBER
MEAN_INCOMING_TASKS_30_DAYS NUMBER
TOTAL_CPU_LAST_7_DAYS INTERVAL DAY(9) TO SECOND(9)
TOTAL_CPU_LAST_30_DAYS INTERVAL DAY(9) TO SECOND(9)
MAX_DURATION_LAST_7_DAYS INTERVAL DAY(3) TO SECOND(0)
MAX_DURATION_LAST_30_DAYS INTERVAL DAY(3) TO SECOND(0)
ble
WINDOW_DURATION_LAST_7_DAYS INTERVAL DAY(9) TO SECOND(9)
fe r a
WINDOW_DURATION_LAST_30_DAYS INTERVAL DAY(9) TO SECOND(9)
an s
SQL> n - t r
a no
b) Select the CLIENT_NAME, MEAN_JOB_DURATION, and a
h s ฺ
RESOURCE_PERCENTAGE
columns. The job with longest mean job duration is
a r) uidTuning
the SQL e Advisor in
the example. If the MEAN_JOB_DURATION m ฺ
for the job Gincreases to near the
duration of the window, the windown ฺ c o
duration n
should
e t be increased or the
RESOURCE_PERCENTAGE increased o
a to allow d
tuthe autotask job the resources
needed to complete in the l e @
allocated i s
time.
S This query is available as a script in the
z i l t h
solutions/INFRA
c e loฺdirectory.
u seUse the get_autotask_time.sql script.
a r
SQL> @get_autotask_time to
SQL> e ( m ns e
i l l li c e
oZ
SQL> SELECT client_name,
el 2 mean_job_duration,

Marc 3
4
resource_percentage
FROM DBA_AUTOTASK_CLIENT
5 /

CLIENT_NAME MEAN_JOB_DURATION
------------------------------- ------------------------------
RESOURCE_PERCENTAGE
-------------------
auto optimizer stats collection +000000000 00:02:51.285714286
25
auto space advisor +000000000 00:00:40.142857143
25
sql tuning advisor +000000000 00:02:55.857142857
25

SQL> exit

Oracle Database 11g: New Features for Administrators A - 249


Practice 13-3: Calibrating I/O Resources
It is important to know the capabilities of the I/O subsystem on your server. The I/O
calibration facility allows you to monitor the I/O load compared to the I/O capacities.
1) Review the current I/O configuration. Navigate to the I/O Calibration Page.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

a) Click the Performance tab on the Database Control home page.


b) Click the I/O tab near the center of the Performance Page.
c) Select I/O Type for the I/O chart settings.
2) Use Enterprise Manager to calibrate the I/O resource metrics. Enter the inputs for a
new calibration.
a) On the Performance page, click the I/O Calibration button.
b) On the I/O Calibration page, scroll to the “Inputs for a New Calibration” section. ble
For the Approximate Number of Physical Disks in the Database’s Storage System fe r a
field, enter 1. an s
n - t r
For the Maximum Tolerable Latency in Milliseconds for Single-Block I/O
Requests, enter 50. a no
h a s ฺ
ฺ a r) uide
c) Click Submit. This operation may take up to 15 minutes.
d) You can view the submitted job information
ฺ c omon ethenScheduler
t G Central page. Click
the database instance link to returnotonthe Performance tab. Click the Server tab.
d Scheduler
On the Server page, click the@ Jobs tuOracle
a link inSthe section.
l l e
i you tshouldi s
h see the IOCalibration link. You should
e) On the Scheduler Jobs
l o ฺzpage, e
see it running.ce
r t o us
a
(mviewethe e activity on the Performance page. Click the Database tab.
f) You can
l e n sI/O
l
i clicklicthe Performance tab.
ZThen
l o
e g) When the calibration is finished, review the Calibration page by clicking the I/O
rc
Ma Calibration button.
h) On the I/O Calibration page, look at the Existing Calibration Results section.
Your results will vary depending on your machine.
i) After viewing the results, click the Database link to return to the Database Home
page.

Oracle Database 11g: New Features for Administrators A - 250


Practices for Lesson 14

In this practice, you will use various new diagnostic capabilities.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 251


Practice 14-1: Using Support Workbench to Analyze Corruption
In this practice, you corrupt a data dictionary table. Then you analyze the corruption
using Support Workbench and ADRCI.
1) Execute the hm_setup.sh script found in the /home/oracle/solutions/HM
directory. This script corrupts the data dictionary.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

$ cd /home/oracle/solutions/HM
$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle
$
$ ./hm_setup.sh e
r a bl
SQL*Plus: Release 11.2.0.1.0 Production on Tue Oct 6 12:06:49
n s fe
2009
n - tra
Copyright (c) 1982, 2009, Oracle. All rights reserved. a no
h a s ฺ
Connected to:
a )
rRelease e
id11.2.0.1.0
Oracle Database 11g Enterprise Edition
m ฺ G u -
Production o
ฺc Storage
e t
n Management, OLAP,
With the Partitioning, Automatic o n d
Data Mining and Real Application @ a STesting tu options
i l l e h i s
SQL> SQL> SQL> SQL>
e l oฺz use t
Table created. a rc to
m
( ens e
i
SQL> l l eSQL> SQL>
i c SQL> 2 3 4
Z l
rc eloPL/SQL procedure successfully completed.

Ma SQL> SQL>
OBJ
----------
76538

SQL> SQL> Database closed.


Database dismounted.
ORACLE instance shut down.
SQL> SQL> ORACLE instance started.

Total System Global Area 422670336 bytes


Fixed Size 1336960 bytes
Variable Size 310380928 bytes
Database Buffers 104857600 bytes
Redo Buffers 6094848 bytes
Database mounted.
Database opened.
SQL> SQL>
1 row updated.

Oracle Database 11g: New Features for Administrators A - 252


Practice 14-1: Using Support Workbench to Analyze Corruption
(continued)

SQL> SQL>
Commit complete.

SQL> SQL> Database closed.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Database dismounted.
ORACLE instance shut down.
SQL> SQL> ORACLE instance started.

Total System Global Area 422670336 bytes


Fixed Size 1336960 bytes
Variable Size 310380928 bytes
Database Buffers 104857600 bytes
Redo Buffers 6094848 bytes
ble
Database mounted.
fe r a
Database opened.
ans
SQL> SQL> Disconnected from Oracle Database 11g Enterprise
n - t r
Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP, a no
Data Mining and Real Application Testing options h a s ฺ
$
ฺ a r) uide
2) Use Enterprise Manager to trigger a healthฺc omonethe
check n G dictionary.
tdata
a) Log in to Enterprise Manager asathe
onSYS user.
tudClick the Advisor Central link at
@ S
le in thethRelated
is Links section.
the bottom of the home
z i l
page
b) On the Advisor
c e loฺ page,
Central u e the Checkers tab.
sclick
c) On the(m
ar e to click Dictionary Integrity Check.
i l l e icens
Checker subpage,
d)ZOn the Run
l Dictionary Integrity Check page, specify a Run Name of
l o
e DicoCheck.
rc
Ma e) Click OK.
f) On the Advisor Central Checkers page, you should see a Confirmation message
indicating that your check ran successfully.
g) In the Results table, select your DicoCheck run and click Details.
This takes you to the Run Details Findings subpage where you can see some data
corruption. In particular, you should see the following finding: “SQL dictionary
health check: invalid column number 8 on object TAB$ failed.” This should
correspond to a row in TAB$ that references SCOTT.TABJFV.
3) How would you get a report about the previous finding using SQL*Plus?
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Tue Oct 6 12:18:04


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Oracle Database 11g: New Features for Administrators A - 253


Practice 14-1: Using Support Workbench to Analyze Corruption
(continued)

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Data Mining and Real Application Testing options

SQL> set long 100000


SQL> select dbms_hm.get_run_report('DicoCheck') from dual;

DBMS_HM.GET_RUN_REPORT('DICOCHECK')
--------------------------------------------------------------
Basic Run Information
Run Name : DicoCheck
ble
Run Id : 41
fe r a
Check Name : Dictionary Integrity Check
ans
Mode : MANUAL
n - t r
Status
Start Time
: COMPLETED
a no
: 2009-10-06 12:11:34.153957 +00:00
End Time a s ฺ
: 2009-10-06 12:11:38.938352 +00:00
h
Error Encountered : 0
ฺ a r) uide
Source Incident Id : 0
Number of Incidents Created: 0 ฺ c om ent G
a on tud
e@ is S
DBMS_HM.GET_RUN_REPORT('DICOCHECK')
l l
i
ฺz se th
--------------------------------------------------------------
l o
a
Input Paramtersrce fortotheu Run
l e (m ense
TABLE_NAME=ALL_CORE_TABLES
Zi l lic
CHECK_MASK=ALL
e l o
rc
Ma
Run Findings And Recommendations
Finding
Finding Name : Dictionary Inconsistency
Finding ID : 42
Type : FAILURE
Status : OPEN

DBMS_HM.GET_RUN_REPORT('DICOCHECK')
--------------------------------------------------------------
Priority : CRITICAL
Message : SQL dictionary health check: invalid column
number 8 on object TAB$ failed
Message : Damaged rowid is AAAAACAABAAAWFaAAB -
description: Object SCOTT.TABJFV is referenced
Finding
Finding Name : Dictionary Inconsistency
Finding ID : 45
Type : FAILURE
Status : OPEN

Oracle Database 11g: New Features for Administrators A - 254


Practice 14-1: Using Support Workbench to Analyze Corruption
(continued)
Priority : CRITICAL

DBMS_HM.GET_RUN_REPORT('DICOCHECK')
--------------------------------------------------------------
Message : SQL dictionary health check: file$ pk 42 on
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

object FILE$ failed


Message : Damaged rowid is AAAAARAABAAAADpAAG -
description: No further damage description
available
Finding
Finding Name : Dictionary Inconsistency
Finding ID : 48
Type : FAILURE
Status : OPEN
ble
Priority : CRITICAL
fe r a
Message : SQL dictionary health check: file$ pk 42 on
an s
object FILE$
n - t r
DBMS_HM.GET_RUN_REPORT('DICOCHECK') a no
a s ฺ
--------------------------------------------------------------
h
failed
ฺ a r) uide
Message
ฺ c om ent G
: Damaged rowid is AAAAARAABAAAADpAAH –
description: No further damage description
available a on tud
l l e@ is S
SQL> i
ฺz se th
l o
SQL>
a rce to u
4) Go back to
l e (m e n se Manager Home page. What do you observe?
your Enterprise
i l ic
a)ZClick thelDatabase tab to return to the Database Home page.
e l o
rc b) You should see a new critical alert (Data Failure) for the previously detected
Ma corruption in the Alerts section of the Home page.
5) Return to your terminal session. Flush your shared pool and buffer cache and then
exit and reconnect as the SYS user. Then execute the following statement: select
* from scott.tabjfv;
What do you observe?
SQL> alter system flush shared_pool;

System altered.

SQL> alter system flush buffer_cache;

System altered.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production

Oracle Database 11g: New Features for Administrators A - 255


Practice 14-1: Using Support Workbench to Analyze Corruption
(continued)
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Tue Oct 6 12:39:27


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
ble
fe r a
SQL> select * from scott.tabjfv;
an s
n - t r
select * from scott.tabjfv
* a no
ERROR at line 1: h a s ฺ
ORA-03113: end-of-file on communication channel
ฺ a r) uide
Process ID: 6404
Session ID: 37 Serial number: 778 ฺ c om ent G
a on tud
SQL>
l l e@ is S
SQL> exit ฺ z i th
l o e
us Database 11g Enterprise Edition
rce t-oProduction
Disconnected from Oracle
a
Release 11.2.0.1.0
With the
l e e n se
(mPartitioning, Automatic Storage Management, OLAP,
Data
Z i l Mining
li c and Real Application Testing options
e l o$
rc 6)
Ma Use Enterprise Manager to investigate the previous problem.
a) On the Database Home page, you should see one active incident in the Diagnostic
Summary region. Click the Active Incident link (Access Violation). If you do not
see the incident, click Software and Support. On the Software and Support
subpage, click Support Workbench in the Support section.
b) On the Support Workbench Problems subpage, you should see a new active
incident with a description similar to ORA 7445 [qcstda()+720].
c) Expand the Show link in the Details column.
d) Click the incident link.
e) This takes you to the corresponding Incident Details page. Make a note of the
incident number: _____________________
f) In the Application Information section of that page, you can clearly see what
caused the incident. It was due to “select * from scott.tabjfv.”

Oracle Database 11g: New Features for Administrators A - 256


Practice 14-1: Using Support Workbench to Analyze Corruption
(continued)
g) On the Dump Files subpage, you can also see two dump files. The first one
corresponds to the incident dump file and is located in the ADR directory. (As an
example:
/u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_18273)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

The second one is the classic corresponding trace file located in


/u01/app/oracle/diag/rdbms/orcl/orcl/trace.
h) Click the Eyeglass icon in the View Contents column for the incident trace (first
row).
i) If you did not save your Host credentials previously, the Host Credentials page is
displayed. Enter oracle/oracle and click Continue.
j) This brings you to the Contents page, where you see the structured trace
ble
information.
fe r a
an s
k) For example, click Expand All link, then click the “current sql statement” link just
n - t
below the “incident dump” link in the custom_assert_dump section. This prints
r
the culprit SQL statement in the window below the Trace Map. a no
l) Click OK to return to the Incident Details page. h a s ฺ
ฺ a r) uide
m) On the Incident Details page, click the Problem m nt Glocator link at the top.
Details
c o
ฺ next dtoethe SR field.
n) On the Problems Details page, click
a onEdit tu
o) Enter 1234 in the SR Number l e@ pop-up
i s S
window that appears and click OK. It is
z i l t h
c e loฺ opened
assumed that you already
u se an SR (1234) with My Oracle Support.
p) You should a r see the
now toSR number on the Problem Details page.
m e
q) Click
i l l e (the Activity
c e nsLog tab.
l or)
ZThis takesliyou to the Activity Log subpage on which you now see your last action
rc e on the problem. You could enter a comment here.
Ma
7) Return to your terminal window. Locate your incident and your health check report in
ADR.
$ cd $ORACLE_BASE/diag/rdbms/orcl/orcl
$ ls
alert cdump hm incident incpkg ir lck metadata stage
sweep trace
$ cd incident
$ ls
incdir_18273
$ cd incdir_18273
$ ls
orcl_ora_12211_i18273.trc orcl_ora_12211_i18273.trm
$ cd ../..
$ cd hm
$ ls
HMREPORT_DicoCheck.hm
$ cd ..

Oracle Database 11g: New Features for Administrators A - 257


Practice 14-1: Using Support Workbench to Analyze Corruption
(continued)
8) Use ADRCI to locate your incident and problem information.
$ adrci

ADRCI: Release 11.2.0.1.0 - Production on Tue Oct 6 12:58:51


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

2009

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All


rights reserved.

ADR base = "/u01/app/oracle"


adrci> set homepath diag/rdbms/orcl/orcl
adrci> show homes
ADR Homes: e
diag/rdbms/orcl/orcl
r a bl
adrci> show incidents s fe
- t r an
ADR Home = /u01/app/oracle/diag/rdbms/orcl/orcl:
o n
INCIDENT_ID PROBLEM_KEY s an
**************************************************************

CREATE_TIME r ) ha deฺ
ฺa Gui
------------- ------------------------------------------------
m
---------------------------------
n ฺ co ent
6233 ORA 600 [HAH!]
2009-09-29 13:15:37.877000 +00:00@ ao Stud
6193 i
ORA 600 [HAH!]
z l le this
c e loฺ use
2009-09-29 13:35:00.123000 +00:00
18235 r to
ORA 7445 [qcstda()+720]
a
m e
i l e ( icens
2009-10-06 12:40:19.014000 +00:00
l
3 rows fetched
el oZ l
Marc adrci> show problem

ADR Home = /u01/app/oracle/diag/rdbms/orcl/orcl:


**************************************************************
***********
PROBLEM_ID PROBLEM_KEY
LAST_INCIDENT LASTINC_TIME
-------------------- -----------------------------------------
------------------ -------------------- ----------------------
2 ORA 7445 [qcstda()+720]
18235 2009-10-06 12:40:19.014000 +00:00
1 ORA 600 [HAH!]
6193 2009-09-29 13:35:00.123000 +00:00
2 rows fetched
adrci> exit
$
9) Use Enterprise Manager to quickly package your problem.

Oracle Database 11g: New Features for Administrators A - 258


Practice 14-1: Using Support Workbench to Analyze Corruption
(continued)
a) On the Problems Details page, click the Quick Package button in the Investigate
and Resolve section.
b) On the Quick Packaging: Create New Package page, accept the default package
name (something similar to ORA7445qc_2009 1006132246) and select No next
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

to the “Send to Oracle Support” entry.


c) When the page is refreshed, click Next.
d) On the Quick Packaging: View Contents page, you see the list of incidents that
are part of this package. There should be only one incident in your case. Click
Next.
e) On the Quick Packaging: View Manifest page, look at the name of the manifest.
Click Next. ble
f) On the Quick Packaging: Schedule page, make sure that Immediately is selected fe r a
n s
and click Submit.
n - tra
g) The Processing: Generating Upload File for Package page appears.
a noWait until it is
finished.
h a s ฺ
h) On the Confirmation page, you should see something
ฺ a u idto:e “Generating an
r) similar
upload file for package: ORA7445qc_2009
c o m
1006132246
n t G has been successfully
generated. The upload file is located ฺ
onat tude
a
/u01/app/oracle/product/11.1.0/db_1/edrsr14p1.us.oracle.com_orcl/sysman/emd/st
@ _COM_1.zip.S
z i
ate/ ORA7445qc_20090622162930l l e t h i s Please send it manually to

lo receive
Oracle.” Note: Ifeyou e
remaining a steps o usanYou
rc of thetpractice.
error regarding the file creation, proceed with the
will see that the package has been created.
m e
i) Click
i l l e (OK.icens
el oj) ZOn the Problem
l Details Activity Log subpage, you should now see two new

Marc entries in the log reporting about the package creation for this problem.
k) In the Summary section, click the Yes link in the Packaged field.
l) This takes you to the Packages page.
m) Select your package, and click View.
This takes you to the Package Details page from where you can see the package
details.
n) Click the Files tab.
o) On the Files subpage, you can now see the Full Package Content view.
10) Return to your terminal session and use ADRCI to determine the list of existing
packages. Exit from ADRCI.
$ adrci

ADRCI: Release 11.2.0.1.0 - Production on Tue Oct 6 13:32:35


2009

Oracle Database 11g: New Features for Administrators A - 259


Practice 14-1: Using Support Workbench to Analyze Corruption
(continued)
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All
rights reserved.

ADR base = "/u01/app/oracle"


adrci> set homepath diag/rdbms/orcl/orcl
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

adrci> query ips_package

ADR Home = /u01/app/oracle/diag/rdbms/orcl/orcl:


**************************************************************
***********
PACKAGE_ID FLAGS STATUS
CREATION_TIME LAST_SEQUENCE
LAST_COMPLETE_SEQUEN PROBLEM_ID NAME
DESCRIPTION
ble
CORRELATION_LEVEL DRIVING_INCIDENT BEGIN_TIME
fe r a
END_TIME UPDATE_TIME
ans
LAST_BASE_SEQUENCE
n - t r
-------------------- -------------------- -------------------- o
an
---------------------------------------- --------------------
s
r ) ha deฺ
-------------------- -------------------- --------------------

m ฺa Gui
--------------------------------------------------------------
------------------- ------------------------------------------
ฺ co ent
--------------------------------------------------------------
n
ao Stud
--------------------------------------------------------------
@
z i l le this
--------------------------------------------------------------

1 c 0loฺ use
--------------------------------------------------------------
e 4
a r to
2009-10-06 13:23:38.219283 +00:00 1
m e
1
i l l e ( icens 1

el oZ
2
l
ORA7445qc_20091006132246
18235

Marc 2009-10-06 13:23:38.455133 +00:00


1 rows fetched
0

adrci> exit
$

11) After analyzing the problem, you know that the number of columns for TABJFV is
wrong in TAB$. Fix the issue by updating TAB$ and close your problem. You can
execute hm_fix.sh for that purpose.
$ cd /home/oracle/solutions/HM
$ ./hm_fix.sh

SQL*Plus: Release 11.2.0.1.0 Production on Tue Oct 6 13:36:13


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:

Oracle Database 11g: New Features for Administrators A - 260


Practice 14-1: Using Support Workbench to Analyze Corruption
(continued)
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> SQL> SQL> SQL> SQL> SQL> 2 3 4


PL/SQL procedure successfully completed.

SQL> SQL>
OBJ
----------
76538

SQL> SQL> Database closed.


ble
Database dismounted.
fe r a
ORACLE instance shut down.
ans
SQL> SQL> ORACLE instance started.
n - t r
o
Total System Global Area 422670336 bytes
s an
Fixed Size 1336960 bytes
r ) ha deฺ
Variable Size
Database Buffers
310380928
104857600
bytes
m
bytes
ฺa Gui
Redo Buffers 6094848n ฺ co ent
bytes
Database mounted.
@ ao Stud
Database opened.
z i l le this
SQL> SQL>
1 row updated. c e loฺ use
a r to
SQL> e m
( ens
SQL>
e
Z i l
Commit
l lic
complete.
e l o
rc
Ma
SQL> SQL> Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> SQL> ORACLE instance started.

Total System Global Area 422670336 bytes


Fixed Size 1336960 bytes
Variable Size 310380928 bytes
Database Buffers 104857600 bytes
Redo Buffers 6094848 bytes
Database mounted.
Database opened.
SQL> SQL>
PL/SQL procedure successfully completed.

SQL> SQL> SQL> SQL>


DBMS_HM.GET_RUN_REPORT('DICOCHECKJFV')
--------------------------------------------------------------
Basic Run Information

Oracle Database 11g: New Features for Administrators A - 261


Practice 14-1: Using Support Workbench to Analyze Corruption
(continued)
Run Name : DicoCheckjfv
Run Id : 61
Check Name : Dictionary Integrity Check
Mode : MANUAL
Status : COMPLETED
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Start Time : 2009-10-06 13:36:57.581510 +00:00


End Time : 2009-10-06 13:36:58.798228 +00:00
Error Encountered : 0
Source Incident Id : 0
Number of Incidents Created: 0

DBMS_HM.GET_RUN_REPORT('DICOCHECKJFV')
--------------------------------------------------------------
ble
Input Paramters for the Run
fe r a
TABLE_NAME=tab$
ans
CHECK_MASK=ALL
n - t r
Run Findings And Recommendations a no
h a s ฺ
SQL> SQL> Disconnected from Oracle Database
ฺ a r) 11g
u i deEnterprise
Edition Release 11.2.0.1.0 - Production
c m nt G
oStorage
With the Partitioning, Automatic ฺ
on Testing de Management, OLAP,
Data Mining and Real Application a
@ is S t u options

z i l l e th
Recovery Manager: ฺRelease 11.2.0.1.0 - Production on Tue Oct 6
13:37:04 2009ce l o u s e
a r t o
Copyright
l e se 2009, Oracle and/or its affiliates. All
(m(c)en1982,
l
Zi reserved.
rights lic
e l o
rc
Ma
connected to target database: ORCL (DBID=1226549444)
using target database control file instead of recovery catalog

RMAN>
RMAN>
List of Database Failures
=========================

Failure ID Priority Status Time Detected Summary


---------- -------- --------- ------------- -------
48 CRITICAL OPEN 06-OCT-09 SQL dictionary
health check: file$ pk 42 on object FILE$ failed
45 CRITICAL OPEN 06-OCT-09 SQL dictionary
health check: file$ pk 42 on object FILE$ failed

RMAN>

Recovery Manager complete.


$

Oracle Database 11g: New Features for Administrators A - 262


Practice 14-1: Using Support Workbench to Analyze Corruption
(continued)
12) Use Enterprise Manager to close your incident.
a) On the Package Details page, click the problem link next to the Problems in
Package field in the Summary section.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

b) On the Problem Details Incidents subpage, select your incident and click Close.
c) On the Confirmation page, click Yes.
d) Click Database to return to the Database Home page.

ble
fe r a
an s
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 263


Practice 14-2: Using SQL Repair Advisor
In this practice, you simulate an SQL crash and analyze it with the SQL Repair Advisor.
1) In a terminal session, change to the /home/oracle/solutions/SQL_Repair
directory. Connected as SYS from a SQL*plus session, execute the
sql_repair1.sql script.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

$ . oraenv
ORACLE_SID = [db10g] ? orcl
$
$ cd /home/oracle/solutions/SQL_Repair
$
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Mon Jun 29 00:33:12


ble
2009
fe r a
ans
Copyright (c) 1982, 2009, Oracle. All rights reserved.
n - t r
a no
Connected to:
h a s ฺ
Oracle Database 11g Enterprise Edition rRelease
a ) e
id11.2.0.1.0 -
Production ฺ u
m ntManagement,
G
With the Partitioning, Automatic ฺ c oStorage
e OLAP,
Data Mining o n d
and Real Application Testing @ a optionsS tu
z ill e t hi s
ฺ e
SQL> @sql_repair1
r c elo o us
SQL>
SQL> --(m
a e t generates a workaround for a crash. This
le already en s
This example
bugilhas i c
Z l
rc eloSQL> -- been fixed but we toggle the bug fix using an
underscore parameter
Ma SQL> -- which uses the (internal) feature called bug fix
control.
SQL> -- This script will pause periodically to allow you to
read the comments
SQL> -- and see the output of the previous command on the
screen. Just press
SQL> -- return to make the demo resume.
SQL>
SQL> pause

2) Press [Enter] to continue. The script now grants privileges to user SCOTT, which is
used for the demo.
SQL>
SQL> -- To begin the demo we will create the user scott and
grant
SQL> -- advisor privileges to him.
SQL>
SQL> pause

Oracle Database 11g: New Features for Administrators A - 264


Practice 14-2: Using SQL Repair Advisor (continued)

SQL>
SQL> grant connect, resource, dba, query rewrite, unlimited
tablespace to scott identified by tiger;

Grant succeeded.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> alter user scott account unlock;

User altered.

SQL>
SQL> -- Next we need to create and populate the table used by
the demo.
ble
SQL> -- We will also create an index on the table;
fe r a
SQL>
an s
SQL> pause
n - t r
no
3) When you press [Enter], a table is created and populated.
a
SQL> connect scott/tiger; h a s ฺ
Connected. ฺ a r) uide
SQL>
SQL> drop table simple_table;nฺc
om ent G
drop table simple_table
@ ao Stud
*
ERROR at line 1: oฺz
ille this
ORA-00942: table c e l or view
u sedoes not exist
a r to
m
( ens e
i l l e
l o Z
SQL> lic
e SQL> create table simple_table(a varchar(40), b number, c
Marc varchar(240), d varchar(240));

Table created.

SQL>
SQL> create index tc on simple_table(b, d, a);

Index created.

SQL>
SQL> insert into simple_table values('a', 1, 'b', 'c');

1 row created.

SQL> insert into simple_table values('a', 1, 'x', 'c');

1 row created.

SQL> insert into simple_table values('e', 2, 'f', 'g');

Oracle Database 11g: New Features for Administrators A - 265


Practice 14-2: Using SQL Repair Advisor (continued)

1 row created.

SQL>
SQL> -- In order to crash the system we need to switch off the
code line that
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> -- normal protects against this type of crash. We can


switch off the code
SQL> -- using the (internal) feature called bug fix control.
SQL>
SQL> pause
4) Press [Enter] to continue. You need to switch off some code in the system to
intentionally cause a crash when executing a particular SQL statement.
SQL> ble
SQL> -- switch the code fe r a
SQL> alter system set "_fix_control"="5868490:OFF";
ans
n - t r
System altered.
a no
SQL> -- alter session set optimizer_dynamic_sampling h a s ฺ = 0;
SQL> ฺ a r) uide
SQL> -- Now that the code line has
ฺ c ombeenenswitched
tG off lets get
the execution
SQL> -- plan for a simple a
on tud
delete statement.
SQL> l l e@ is S
SQL> pause
i
ฺz se th
l o
a
5) Press [Enter] to
ce tThe
rcontinue. o u
DELETE statement used in this practice is explained.
( m s e
SQL>
Z ille licen
rc eloSQL> --- explain the plan
SQL> explain plan for delete
Ma 2 /*+
3 USE_HASH_AGGREGATION(@"SEL$80F8B8C6")
4 USE_HASH(@"SEL$80F8B8C6" "T1"@"DEL$1")
5 LEADING(@"SEL$80F8B8C6" "T2"@"SEL$1" "T1"@"DEL$1")
6 FULL(@"SEL$80F8B8C6" "T1"@"DEL$1")
7 FULL(@"SEL$80F8B8C6" "T2"@"SEL$1")
8 OUTLINE(@"DEL$1")
9 OUTLINE(@"SEL$1")
10 OUTLINE(@"SEL$AD0B6B07")
11 OUTLINE(@"SEL$7D4DB4AA")
12 UNNEST(@"SEL$1")
13 OUTLINE(@"SEL$75B5BFA2")
14 MERGE(@"SEL$7D4DB4AA")
15 OUTLINE_LEAF(@"SEL$80F8B8C6")
16 ALL_ROWS
17 OPT_PARAM('_optimizer_cost_model' 'fixed')
18 DB_VERSION('11.1.0.7')
19 OPTIMIZER_FEATURES_ENABLE('11.1.0.7')
20 NO_INDEX(@"SEL$1" "T2"@"SEL$1")

Oracle Database 11g: New Features for Administrators A - 266


Practice 14-2: Using SQL Repair Advisor (continued)
21 */
22 from simple_table t1 where t1.a = 'a' and rowid <>
(select max(rowid) from simple_table t2 where t1.a= t2.a and
t1.b = t2.b and t1.d=t2.d);

Explained.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> --- display the plan
SQL> select plan_table_output from
table(dbms_xplan.display('plan_table',null));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
------------------
ble
Plan hash value: 1481897562
fe r a
ans
--------------------------------------------------------------
------ n - t r
a no
| Id | Operation | Name
h a s| Rows
ฺ | Bytes |
Cost (%CPU)| Time
| ฺ a r) uide
ฺ c om ent G
on tud
--------------------------------------------------------------
a
------
l l e@ is S
i
ฺz se th
l o
rce to u
PLAN_TABLE_OUTPUT
a
l e (m ense
--------------------------------------------------------------
l
Zi 0 | DELETE
lic STATEMENT
------------------
e l o| | | 1 | 338 |
rc 6 (34)| 00:0
Ma 0:01 |

| 1 | DELETE | SIMPLE_TABLE | | |
|
|

|* 2 | FILTER | | | |
|
|

| 3 | HASH GROUP BY | | 1 | 338 |


6 (34)| 00:0
0:01 |

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
------------------

Oracle Database 11g: New Features for Administrators A - 267


Practice 14-2: Using SQL Repair Advisor (continued)
|* 4 | HASH JOIN | | 1 | 338 |
5 (20)| 00:0
0:01 |

|* 5 | TABLE ACCESS FULL| SIMPLE_TABLE | 1 | 169 |


2 (0)| 00:0
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

0:01 |

|* 6 | TABLE ACCESS FULL| SIMPLE_TABLE | 1 | 169 |


2 (0)| 00:0
0:01 |

--------------------------------------------------------------
------------------
ble
PLAN_TABLE_OUTPUT
fe r a
--------------------------------------------------------------
ans
------
n - t r
a no
Predicate Information (identified by operation
h a s id): ฺ
r )
---------------------------------------------------
i d e
m ฺa Gu
2 - filter(ROWID<>MAX(ROWID)) ฺ c o e n t
n
4 - access("T1"."A"="T2"."A"
"T1"."D"="T2"."D") @ ao S t d
ANDu"T1"."B"="T2"."B" AND

i l
5 - filter("T2"."A"='a')
z le this
c e loฺ use
6 - filter("T1"."A"='a')

21 rows(m
ar e to
i l l e icens
selected.

l Z
oSQL> l
e
Marc SQL> -- The plan shows that we we will do a full table scan
oun r.
SQL> -- If we execut this simple system it will crash the
system.
SQL>
SQL> Pause
6) Press [Enter] to continue. Now, execute the statement and you see that it crashed.
SQL> --- This statement caused the system to crash.
SQL> delete
2 /*+
3 USE_HASH_AGGREGATION(@"SEL$80F8B8C6")
4 USE_HASH(@"SEL$80F8B8C6" "T1"@"DEL$1")
5 LEADING(@"SEL$80F8B8C6" "T2"@"SEL$1" "T1"@"DEL$1")
6 FULL(@"SEL$80F8B8C6" "T1"@"DEL$1")
7 FULL(@"SEL$80F8B8C6" "T2"@"SEL$1")
8 OUTLINE(@"DEL$1")
9 OUTLINE(@"SEL$1")
10 OUTLINE(@"SEL$AD0B6B07")

Oracle Database 11g: New Features for Administrators A - 268


Practice 14-2: Using SQL Repair Advisor (continued)
11 OUTLINE(@"SEL$7D4DB4AA")
12 UNNEST(@"SEL$1")
13 OUTLINE(@"SEL$75B5BFA2")
14 MERGE(@"SEL$7D4DB4AA")
15 OUTLINE_LEAF(@"SEL$80F8B8C6")
16 ALL_ROWS
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

17 OPT_PARAM('_optimizer_cost_model' 'fixed')
18 DB_VERSION('11.1.0.7')
19 OPTIMIZER_FEATURES_ENABLE('11.1.0.7')
20 NO_INDEX(@"SEL$1" "T2"@"SEL$1")
21 */
22 from simple_table t1 where t1.a = 'a' and rowid <>
(select max(rowid) from simple_table t2 where t1.a= t2.a and
t1.b = t2.b and t1.d=t2.d);
from simple_table t1 where t1.a = 'a' and rowid <> (select
ble
max(rowid) from simple_table t2 where t1.a= t2.a and t1.b =
fe r a
t2.b and t1.d=t2.d)
an s
*
ERROR at line 22: n - t r
ORA-00600: internal error code, arguments: [13011], [74582], a no
[16777740], [0],
h a s ฺ
[16777740], [17], [], [], [], [], [], []
SQL> ฺ a r) uide
ฺ c om ent G
7) You have to use the SQL Repair@ aonto Sanalyze
Advisor tud the situation and find a better
alternative. Still connected z inlle
i h is session, execute the
your SQL*Plus
t
sql_repair2.sql

loscript. se
r c e u
m
SQL> @sql_repair2a e to
SQL> i l l e ( icens
l o Z
SQL> l
rc e SQL> connect scott/tiger
Ma Connected.
SQL> set lines 10000;
SQL> set pages 10000;
SQL> set long 20000;
SQL> set serveroutput on;
SQL> SET TRIMSPOOL ON;
SQL> SET TAB OFF;
SQL> SET FEEDBACK 1;
SQL>
SQL> alter system flush shared_pool;

System altered.

SQL>
SQL> set echo on;
SQL>
SQL> -- At this point your previous session has crashed due to
a problem

Oracle Database 11g: New Features for Administrators A - 269


Practice 14-2: Using SQL Repair Advisor (continued)
SQL> -- with our delete statement. We now want to use the SQL
Repair Advisor
SQL> -- to fit that problem. Before we begin to fix this
problem lets ensure
SQL> -- that the actual code that prevents this issue in real
life is switched off.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> pause
8) Press [Enter] to continue. Make sure that the code for the previous issue is still
disabled.
SQL>
SQL> alter system set "_fix_control"="5868490:OFF";

System altered. ble


fe r a
SQL>
an s
SQL> -- Before we can run the SQL Repair Advisor we need to
n - t r
create a o
an
SQL> -- diagnosis task using dbms_sqldiag. We need to specify
s
the SQL text
r ) ha deฺ
ฺa Gui
SQL> -- for the statement that causes the crash and a task
m
name. We also need
n ฺ co ent
SQL> -- to specify the problem type. There are three possible
problem types
@ ao Stud
SQL>
z i l le this
c e loฺ use
SQL> -- PROBLEM_TYPE_COMPILATION_ERROR
SQL> -- PROBLEM_TYPE_EXECUTION_ERROR
a r
SQL> -- WRONG_RESULTS to
m e
SQL>
i l l e ( icens
el oZ l
SQL> -- In this cause since the statement failed during
execution we will use
Marc SQL> -- PROBLEM_TYPE_EXECUTION_ERROR. When the SQL Repair
Advisor completes we will run
SQL> -- dbms_sqldiag.report_diagnosis_task to output the
results report to the screen.
SQL>
SQL> pause
9) Press [Enter] to continue. You have to analyze the situation using the SQL Repair
Advisor. You can see that a SQL Patch was found during the analysis.
SQL>
SQL> exec
dbms_sqldiag.drop_diagnosis_task('sqldiag_bug_5869490');
BEGIN dbms_sqldiag.drop_diagnosis_task('sqldiag_bug_5869490');
END;

*
ERROR at line 1:
ORA-13605: The specified task or object sqldiag_bug_5869490
does not exist for the current user.

Oracle Database 11g: New Features for Administrators A - 270


Practice 14-2: Using SQL Repair Advisor (continued)
ORA-06512: at "SYS.PRVT_ADVISOR", line 2323
ORA-06512: at "SYS.DBMS_ADVISOR", line 172
ORA-06512: at "SYS.DBMS_SQLTUNE", line 812
ORA-06512: at "SYS.DBMS_SQLDIAG", line 977
ORA-06512: at line 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> declare
2 rep_out clob;
3 t_id varchar2(50);
4 begin
5 t_id := dbms_sqldiag.create_diagnosis_task(
6 sql_text => 'delete /*+
7 USE_HASH_AGGREGATION(@"SEL$80F8B8C6")
8 USE_HASH(@"SEL$80F8B8C6" "T1"@"DEL$1")
ble
9 LEADING(@"SEL$80F8B8C6" "T2"@"SEL$1" "T1"@"DEL$1")
fe r a
10 FULL(@"SEL$80F8B8C6" "T1"@"DEL$1")
ans
11
12
FULL(@"SEL$80F8B8C6" "T2"@"SEL$1")
OUTLINE(@"DEL$1") n - t r
o
13 OUTLINE(@"SEL$1")
s an
14
15
OUTLINE(@"SEL$AD0B6B07")
OUTLINE(@"SEL$7D4DB4AA") r ) ha deฺ
16 UNNEST(@"SEL$1") m ฺa Gui
17 OUTLINE(@"SEL$75B5BFA2")
n ฺ co ent
18
19
MERGE(@"SEL$7D4DB4AA")
@ ao Stud
OUTLINE_LEAF(@"SEL$80F8B8C6")
20 ALL_ROWS z i l le this
21 loฺ use
OPT_PARAM(''_optimizer_cost_model'' ''fixed'')
c e
22 r to
DB_VERSION(''11.1.0.7'')
a
m e
23
i
24 l l e ( icens
OPTIMIZER_FEATURES_ENABLE(''11.1.0.7'')
NO_INDEX(@"SEL$1" "T2"@"SEL$1")
el oZ25 */
l
Marc 26 from simple_table t1 where t1.a = ''a'' and rowid <>
(select max(rowid) from simple_table t2 where t1.a= t2.a and
t1.b = t2.b and t1.d=t2.d)',
27 task_name => 'sqldiag_bug_5869490',
28 problem_type
=>DBMS_SQLDIAG.PROBLEM_TYPE_COMPILATION_ERROR);
29
30 dbms_sqltune.set_tuning_task_parameter(
31 t_id,
32 '_SQLDIAG_FINDING_MODE',
33 dbms_sqldiag.SQLDIAG_FINDINGS_FILTER_PLANS);
34
35 dbms_output.put_line ('t_id = ' || t_id);
36
37 dbms_sqldiag.execute_diagnosis_task (t_id);
38
39 dbms_output.put_line ('executed t_id = ' || t_id);
40
41 rep_out := dbms_sqldiag.report_diagnosis_task (t_id,
DBMS_SQLDIAG.TYPE_TEXT);

Oracle Database 11g: New Features for Administrators A - 271


Practice 14-2: Using SQL Repair Advisor (continued)
42
43 dbms_output.put_line ('Report : ' || rep_out);
44
45 end;
46 /
t_id = sqldiag_bug_5869490
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

executed t_id = sqldiag_bug_5869490


Report : GENERAL INFORMATION SECTION
--------------------------------------------------------------
Tuning Task Name : sqldiag_bug_5869490
Tuning Task Owner : SCOTT
Workload Type : Single SQL Statement
Scope : COMPREHENSIVE
Time Limit(seconds): 1800
Completion Status : COMPLETED
ble
Started at : 06/29/2009 00:37:08
fe r a
Completed at : 06/29/2009 00:37:17
t r a ns
-------------------------------------------------------------
o n -
Schema Name: SCOTT
s an
SQL ID
SQL Text
: apnt3dq2mq1ds
: delete /*+ r ) ha deฺ
ฺa Gui
USE_HASH_AGGREGATION(@"SEL$80F8B8C6")
m
n ฺ co ent "T1"@"DEL$1")
USE_HASH(@"SEL$80F8B8C6"

"T1"@"DEL$1") @ ao Stud
LEADING(@"SEL$80F8B8C6" "T2"@"SEL$1"

z i l le this
FULL(@"SEL$80F8B8C6" "T1"@"DEL$1")
l o ฺ FULL(@"SEL$80F8B8C6"
s e "T2"@"SEL$1")
r c e OUTLINE(@"DEL$1")
o u
m a e tOUTLINE(@"SEL$1")
( s
Z ille licen OUTLINE(@"SEL$AD0B6B07")
el o OUTLINE(@"SEL$7D4DB4AA")

Marc UNNEST(@"SEL$1")
OUTLINE(@"SEL$75B5BFA2")
MERGE(@"SEL$7D4DB4AA")
OUTLINE_LEAF(@"SEL$80F8B8C6")
ALL_ROWS
OPT_PARAM('_optimizer_cost_model' 'fixed')
DB_VERSION('11.1.0.7')
OPTIMIZER_FEATURES_ENABLE('11.1.0.7')
NO_INDEX(@"SEL$1" "T2"@"SEL$1")
*/
from simple_table t1 where t1.a = 'a' and rowid
<> (select
max(rowid) from simple_table t2 where t1.a= t2.a
and t1.b = t2.b
and t1.d=t2.d)

--------------------------------------------------------------
FINDINGS SECTION (1 finding)
--------------------------------------------------------------
-----------------

Oracle Database 11g: New Features for Administrators A - 272


Practice 14-2: Using SQL Repair Advisor (continued)

1- SQL Patch Finding (see explain plans section below)


------------------------------------------------------
A potentially better execution plan was found for this
statement.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Recommendation
--------------
- Consider accepting the recommended SQL patch.
execute dbms_sqldiag.accept_sql_patch(task_name =>
'sqldiag_bug_5869490',task_owner => 'SCOTT', replace => TRUE);

Rationale
---------
Recommended plan with hash value 3259336479 has number of
ble
rows 0, check sum 0, execution time 0 and 12 buffer gets
fe r a
ans
--------------------------------------------------------------
n - t r
PL/SQL procedure successfully completed. a no
h a s ฺ
SQL>
SQL> -- The above report tells us that ฺ a )
rthe u ide fails
statement
during execute ฺ c om ent G
SQL> -- and it has found aaSQL on patch tudfor this statement that
will prevent @
le inththe S
is future. However, unning the
SQL> -- it from crashing
ฺ z i l
repair advisor elo
c u se
SQL> -- wont a r fix thetoproblem automatically. If we run our
problematic
l e m
( eSQL n se
SQL>l
Zi -- statement
lic now the session will crash.
e l oSQL>
rc SQL> pause
Ma 10) Press [Enter] twice to continue. If you execute the statement again, you will get the
same error. This is because you have not yet accepted the proposed SQL Patch.
SQL> connect scott/tiger
Connected.
SQL>
SQL> -- We need to accept the SQL Patch that the SQL Repair
Advisor recommended before
SQL> -- our SQL statement will be able to run without
crashing. To accept the SQL Patch
SQL> -- we must execute dbms_sqldiag.accept_sql_patch and pass
it task name
SQL>
SQL> pause

SQL> execute dbms_sqldiag.accept_sql_patch(task_name =>


'sqldiag_bug_5869490', name => 'delete_patch', task_owner =>
'SCOTT', replace => TRUE);

Oracle Database 11g: New Features for Administrators A - 273


Practice 14-2: Using SQL Repair Advisor (continued)

PL/SQL procedure successfully completed.

SQL>
SQL> -- Now that we have successfully accepted the SQL patch
we should be able to
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> -- run our statement without it crashing. Lets first look


at the execution
SQL> -- plan to see if it has changed.
SQL>
SQL> pause
11) Press [Enter] to continue. Look at the alternative execution plan for the culprit SQL
statement.
SQL> ble
SQL> explain plan for fe r a
2 delete
ans
3 /*+
n - t r
4 USE_HASH_AGGREGATION(@"SEL$80F8B8C6") o
5 USE_HASH(@"SEL$80F8B8C6" "T1"@"DEL$1") s an
6 ha deฺ
LEADING(@"SEL$80F8B8C6" "T2"@"SEL$1" "T1"@"DEL$1")
r )
7 FULL(@"SEL$80F8B8C6" "T1"@"DEL$1")
m ฺa Gui
8
9 OUTLINE(@"DEL$1") n ฺ co ent
FULL(@"SEL$80F8B8C6" "T2"@"SEL$1")

10 OUTLINE(@"SEL$1")
@ ao Stud
11
z i l le this
OUTLINE(@"SEL$AD0B6B07")
12
13 c e loฺ use
OUTLINE(@"SEL$7D4DB4AA")
UNNEST(@"SEL$1")
14 a r to
OUTLINE(@"SEL$75B5BFA2")
m e
15
i l l e ( icens
MERGE(@"SEL$7D4DB4AA")

el oZ16
17
l
OUTLINE_LEAF(@"SEL$80F8B8C6")
ALL_ROWS
Marc 18 OPT_PARAM('_optimizer_cost_model' 'fixed')
19 DB_VERSION('11.1.0.7')
20 OPTIMIZER_FEATURES_ENABLE('11.1.0.7')
21 NO_INDEX(@"SEL$1" "T2"@"SEL$1")
22 */
23 from simple_table t1 where t1.a = 'a' and rowid <>
(select max(rowid) from simple_table t2 where t1.a= t2.a and
t1.b = t2.b and t1.d=t2.d);

Explained.

SQL>
SQL> -- display the plan
SQL> select plan_table_output from
table(dbms_xplan.display('plan_table',null,'advanced'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------

Oracle Database 11g: New Features for Administrators A - 274


Practice 14-2: Using SQL Repair Advisor (continued)
Plan hash value: 3259336479

--------------------------------------------------------------
-----------------------
| Id | Operation | Name | Rows | Bytes |
Cost (%CPU)| Time |
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

--------------------------------------------------------------
-----------------------
| 0 | DELETE STATEMENT | | 1 | 169 |
6 (0)| 00:00:01 |
| 1 | DELETE | SIMPLE_TABLE | | |
| |
|* 2 | FILTER | | | |
| |
|* 3 | INDEX FULL SCAN | TC | 4 | 676 |
ble
0 (0)| 00:00:01 |
fe r a
| 4 | SORT AGGREGATE | | 1 | 169 |
ans
|
|* 5 |
|
TABLE ACCESS FULL| SIMPLE_TABLE | 1 | 169 |n - t r
3 (0)| 00:00:01 | a no
a s ฺ
--------------------------------------------------------------
h
-----------------------
ฺ a r) uide
om ent Gby operation id):
Query Block Name / Object Aliasฺc(identified
on tud
-------------------------------------------------------------
a
l l e@ is S
i h
oฺz use t
1 - DEL$1
l
3 - DEL$1 / eT1@DEL$1
4 - SEL$1 a rc to
m e
i l l e ( icens
5 - SEL$1 / T2@SEL$1

l o Z
Outline Data
l
rc e -------------
Ma
/*+
BEGIN_OUTLINE_DATA
FULL(@"SEL$1" "T2"@"SEL$1")
INDEX(@"DEL$1" "T1"@"DEL$1" ("SIMPLE_TABLE"."B"
"SIMPLE_TABLE"."D"
"SIMPLE_TABLE"."A"))
OUTLINE_LEAF(@"DEL$1")
OUTLINE_LEAF(@"SEL$1")
ALL_ROWS
OPT_PARAM('_fix_control' '5868490:0')
OPT_PARAM('_optimizer_cost_model' 'fixed')
DB_VERSION('11.2.0.1')
OPTIMIZER_FEATURES_ENABLE('11.1.0.7')
IGNORE_OPTIM_EMBEDDED_HINTS
END_OUTLINE_DATA
*/

Predicate Information (identified by operation id):

Oracle Database 11g: New Features for Administrators A - 275


Practice 14-2: Using SQL Repair Advisor (continued)
---------------------------------------------------

2 - filter(ROWID<> (SELECT /*+ UNNEST UNNEST NO_INDEX


("T2") NO_INDEX
("T2") */ MAX(ROWID) FROM "SIMPLE_TABLE" "T2"
WHERE "T2"."A"=:B1 AND
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

"T2"."B"=:B2 AND "T2"."D"=:B3))


3 - access("T1"."A"='a')
filter("T1"."A"='a')
5 - filter("T2"."A"=:B1 AND "T2"."B"=:B2 AND "T2"."D"=:B3)

Column Projection Information (identified by operation id):


-----------------------------------------------------------

2 - (cmp=2,3,4) ROWID[ROWID,10], "T1"."A"[VARCHAR2,40],


ble
"T1"."B"[NUMBER,22], "T1"."D"[VARCHAR2,240]
fe r a
3 - ROWID[ROWID,10], "T1"."A"[VARCHAR2,40],
ans
"T1"."B"[NUMBER,22],
"T1"."D"[VARCHAR2,240] n - t r
4 - (#keys=0) MAX(ROWID)[10] a no
5 - ROWID[ROWID,10], "T2"."A"[VARCHAR2,40],
h a s ฺ
"T2"."B"[NUMBER,22],
"T2"."D"[VARCHAR2,240] ฺ a r) uide
ฺ c om ent G
Note a on tud
-----
l l e@ is S
i
ฺz se th used for this statement
- SQL patch "delete_patch"
l o
rce to u
64 rows selected.
a
l e (m ense
Zi
SQL>l lic
e l oSQL> -- Now lets execute it.
rc SQL>
Ma SQL> pause
12) Press [Enter] to continue. Try to execute the statement again. You should see that it
no longer generates the error. The end of the script reestablishes the original code
path. You can exit from your SQL*Plus session.
SQL>
SQL> delete
2 /*+
3 USE_HASH_AGGREGATION(@"SEL$80F8B8C6")
4 USE_HASH(@"SEL$80F8B8C6" "T1"@"DEL$1")
5 LEADING(@"SEL$80F8B8C6" "T2"@"SEL$1" "T1"@"DEL$1")
6 FULL(@"SEL$80F8B8C6" "T1"@"DEL$1")
7 FULL(@"SEL$80F8B8C6" "T2"@"SEL$1")
8 OUTLINE(@"DEL$1")
9 OUTLINE(@"SEL$1")
10 OUTLINE(@"SEL$AD0B6B07")
11 OUTLINE(@"SEL$7D4DB4AA")
12 UNNEST(@"SEL$1")

Oracle Database 11g: New Features for Administrators A - 276


Practice 14-2: Using SQL Repair Advisor (continued)
13 OUTLINE(@"SEL$75B5BFA2")
14 MERGE(@"SEL$7D4DB4AA")
15 OUTLINE_LEAF(@"SEL$80F8B8C6")
16 ALL_ROWS
17 OPT_PARAM('_optimizer_cost_model' 'fixed')
18 DB_VERSION('11.1.0.7')
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

19 OPTIMIZER_FEATURES_ENABLE('11.1.0.7')
20 NO_INDEX(@"SEL$1" "T2"@"SEL$1")
21 */
22 from simple_table t1 where t1.a = 'a' and rowid <>
(select max(rowid) from simple_table t2 where t1.a= t2.a and
t1.b = t2.b and t1.d=t2.d);

1 row deleted.
ble
SQL>
fe r a
SQL> -- Finally we need to restore the system back the way we
ans
found it.
SQL> -- We must drop the SQL Patch we have accepted and turn n - t r
o
back on the
s an
first place. r ) ha deฺ
SQL> -- original code path that prevented this problem in the

SQL> m ฺa Gui
n ฺ co ent
SQL> execute dbms_sqldiag.drop_sql_patch('delete_patch');

PL/SQL procedure successfully @ S tud


ao completed.
z i l le this
SQL>
c e loฺ use
r
SQL> alter asystem to "_fix_control"="5868490:ON";
set
m
( ens e
i l l e altered.
l o
System
Z lic
rc e SQL>
Ma SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining
and Real Application Testing options
$

Oracle Database 11g: New Features for Administrators A - 277


Practices for Lesson 15

In the practice for this lesson, you use Enterprise Manager to monitor SQL Commands.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 278


Practice 15-1: Using Enterprise Manager to Monitor SQL
Commands
In this practice, you use Enterprise Manager to monitor SQL Commands.
1) Navigate to the /home/oracle/solutions/SQLMONITOR directory. Log in to
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL*Plus as the SYS user and execute the moni_setup.sql script. Continue with
the next step of this practice while the last SELECT statement is running.
$ cd /home/oracle/solutions/SQLMONITOR
$ . oraenv
ORACLE_SID = [db10g] ? orcl
$
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Wed Oct 7 06:59:34 ble


2009
fe r a
ans
Copyright (c) 1982, 2009, Oracle. All rights reserved.
n - t r
o
Connected to:
s an
r ) ha deฺ
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
m ฺa Gui
With the Partitioning, Automatic Storage Management, OLAP,
ฺ co ent
Data Mining and Real Application Testing options
n
@ ao Stud
SQL> @moni_setup
z i l le this
e loฺ u10000000
SQL> set long 10000000
SQL> set longchunksize
c se
a r
SQL> set linesize to
200
SQL> leset
m
( pagesize e
ns 1000
Z i l li c e
el oSQL>
SQL>
Marc SQL> /*== Drop and create a test tablespace and user ==*/
SQL>
SQL>
SQL> DROP USER moni CASCADE;
DROP USER moni CASCADE
*
ERROR at line 1:
ORA-01918: user 'MONI' does not exist

SQL>
SQL> DROP TABLESPACE moni_tbs INCLUDING CONTENTS;
DROP TABLESPACE moni_tbs INCLUDING CONTENTS
*
ERROR at line 1:
ORA-00959: tablespace 'MONI_TBS' does not exist

SQL>
SQL> CREATE SMALLFILE TABLESPACE MONI_TBS
2 DATAFILE '+DATA'

Oracle Database 11g: New Features for Administrators A - 279


Practice 15-1: Using Enterprise Manager to Monitor SQL
Commands (continued)
3 SIZE 100M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE 32767M
NOLOGGING
4 EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;

Tablespace created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> CREATE USER moni IDENTIFIED BY moni
2 DEFAULT TABLESPACE moni_tbs TEMPORARY TABLESPACE temp;

User created.

SQL>
SQL> GRANT connect, resource, dba to moni;
ble
fe r a
Grant succeeded.
ans
n - t r
SQL>
a no
SQL> /*== Drop and create a MONI_TEST table as MONI user ==*/
SQL> h a s ฺ
SQL> CONNECT moni/moni
ฺ a r) uide
Connected.
SQL> ฺ c om ent G
SQL> DROP TABLE moni_test purge; a on tud
DROP TABLE moni_test purge
l l e@ is S
* i
ฺz se th
l o
ERROR at line 1:
a rce to u
ORA-00942: table or view does not exist
l e (m ense
Z i
SQL> l l ic
l o
e SQL> CREATE TABLE moni_test(c number, d varchar2(500));
rc
Ma Table created.

SQL>
SQL> begin
2 for i in 1..200000 loop
3 insert into moni_test
values(1,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
4 end loop;
5 commit;
6 end;
7 /

PL/SQL procedure successfully completed.

SQL>
SQL> CREATE INDEX moni_test_c_indx on moni_test(c);

Oracle Database 11g: New Features for Administrators A - 280


Practice 15-1: Using Enterprise Manager to Monitor SQL
Commands (continued)

Index created.

SQL>
SQL> /*== Start long running query ==*/
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> SELECT count(*) FROM moni_test t1, moni_test t2
2 WHERE t1.c=t2.c AND t1.c=1;

2) To view and monitor a long-running SQL statement with the Enterprise Manager
Database Control interface, perform the following:
a) In a browser window, open Enterprise Manager Database Control. e
b) On the Database Login page, enter SYS as User Name and oracle_4U as r a bl
s fe
Password. Select SYSDBA from the Connect As drop-down list, and then click
Login. - t r an
no n
a
c) Click the Performance tab. You should see system activity on the Performance
s ฺ
page. h a e
d) Scroll to the bottom of the page and click SQL ฺ a r) uiindthe
Monitoring Additional
c o m nt G
Monitoring Links section.
a o nฺ ude
e) The Monitored SQL Executions @ page is S t
displayed.
z ll e
iExecution
t s
i click the SQL ID link.
hpage,
f) On the Monitored SQL ฺ
lo us e
r c eSQL
g) The Monitored
m a e to
Execution Details page is displayed.

i l e (top ipart
h) Inlthe
c e nsthe page, you see Overview information. In the top right view,
of
l o Zyou see Time
l and Wait Statistics and I/O Statistics.
rc e i) The Details section has a minimum of two tabbed pages: Plan Statistics and
Ma Activity. If you have Parallel execution of queries, there is also a Parallel tabbed
page.
j) To the right you see more details of the Plan Statistics page.
k) Click the Activity tab.
l) You see on this graph that your SELECT statement is using all CPU resources.
m) On your Monitored SQL Execution Details page, click View Report at the top
right.
n) The SQL Monitoring Report is displayed with the same information that you saw
earlier on the graphic pages. If required, scroll down.
o) At the bottom you see the SQL Plan Monitoring Details. Click OK.
p) On the Monitored SQL Execution Details page, click the User MONI link to
display session information for that user.
q) Review the session information on the Session Details page.

Oracle Database 11g: New Features for Administrators A - 281


Practice 15-1: Using Enterprise Manager to Monitor SQL
Commands (continued)
r) On that page, there are several tabbed pages. After you review the session
information, click the SQL Monitoring tab on the right.
s) Click the SQL ID to return to the Monitored SQL Execution Details page.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

t) To view SQL details, click the SQL ID on the Monitored SQL Execution Details
page.
u) Review the SQL details.
v) Then click Logout in the top-right part of the page.
3) To clean up your environment, perform the following:
a) When you have finished monitoring your query, return to your SQL*Plus session
and enter Ctrl + C to stop the execution. Connect as SYSDBA, and then execute
ble
the moni_cleanup.sql script.
fe r a
ans
SELECT count(*) FROM moni_test t1, moni_test t2
* n - t r
o
ERROR at line 1:
s an
SQL> connect / as sysdba r ) ha deฺ
ORA-01013: user requested cancel of current operation

Connected. m ฺa Gui
SQL> @moni_cleanup
n ฺ co ent
SQL>
@ ao Stud
SQL> /*== Drop test tablespace and user ==*/
SQL> z i l le this
c e loฺ use
SQL> DROP USER moni CASCADE;
a r to
m e
i l l e ( icens
User dropped.

l Z
oSQL> l
e
Marc SQL> DROP TABLESPACE moni_tbs INCLUDING CONTENTS AND
DATAFILES;

Tablespace dropped.

SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$

Oracle Database 11g: New Features for Administrators A - 282


Practices for Lesson 16

The practices for this lesson include using Automatic Memory Management and using
deferred optimizer statistics.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 283


Practice 16-1: Using Automatic Memory Management
In this practice, you use Automatic Memory Management to show that you no longer
need to manually modify SGA_TARGET and PGA_AGGREGATE_TARGET. You will
observe the memory distribution when you run an expensive parallel query that consumes
a lot of SGA memory, as well as when you run an expensive PL/SQL block that
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

consumes a lot of PGA memory.


1) Before you start this practice, stop Enterprise Manager Database Control for your
orcl database.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle e
$
r a bl
$ emctl stop dbconsole s fe
Oracle Enterprise Manager 11g Database Control Release
- t r an
11.2.0.1.0
no n
Copyright (c) 1996, 2009 Oracle Corporation. All rights
reserved.
a
s ฺ
h a
ฺ a r) uide
https://ed.us.oracle.com:5500/em/console/aboutApplication
Stopping Oracle Enterprise Manager 11g Database Control ...
... Stopped.
ฺ c om ent G
$
a on tud
2) Make a copy of your spfile.lle@ i s S
i h
l oฺz use t
$ cd /home/oracle/solutions/AMM
e
$
a r c to
$ sqlplus m e
e ( icens
/ as sysdba

Z i l l lRelease 11.2.0.1.0 Production on Wed Oct 7


oSQL*Plus: 07:42:19
l
e 2009
rc
Ma Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> CREATE
PFILE='/u01/app/oracle/acfsmounts/acfs_db1/dbs/initorcl.ora.ba
k' FROM SPFILE;

File created.

SQL>

Oracle Database 11g: New Features for Administrators A - 284


Practice 16-1: Using Automatic Memory Management
(continued)
3) Still connected as SYS in SQL*Plus, set the following parameters to the given value
in your SPFILE only. Use the change_parameters.sql file located in your
/home/oracle/solutions/AMM directory.
_PX_use_large_pool = TRUE
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

_memory_broker_stat_interval = 5
_memory_management_tracing = 31
parallel_execution_message_size = 36864
parallel_max_servers = 200
parallel_adaptive_multi_user = FALSE
processes = 200
sga_target = 0
pga_aggregate_target = 0
memory_target = 280M ble
fe r a
SQL> @change_parameters
ans
SQL>
n - t r
SQL> alter system set "_PX_use_large_pool" = TRUE
SCOPE=SPFILE; a no
h a s ฺ
System altered.
ฺ a r) uide
SQL> ฺ c om ent G
a on tud
SQL> alter system set "_memory_broker_stat_interval" = 5
SCOPE=SPFILE;
l l e@ is S
ฺ z i th
l o s e
rce to u
System altered.
a
SQL>
l e (m ense
SQL>l
Zi alterlicsystem set "_memory_management_tracing" = 31
e l oSCOPE=SPFILE;
rc
Ma System altered.

SQL>
SQL> alter system set "parallel_execution_message_size" =
36864 SCOPE=SPFILE;

System altered.

SQL>
SQL> alter system set "parallel_max_servers" = 200
SCOPE=SPFILE;

System altered.

SQL>
SQL> alter system set "parallel_adaptive_multi_user" = FALSE
SCOPE=SPFILE;

System altered.

Oracle Database 11g: New Features for Administrators A - 285


Practice 16-1: Using Automatic Memory Management
(continued)

SQL>
SQL> alter system set "processes" = 200 SCOPE=SPFILE;

System altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> alter system set "pga_aggregate_target" = 0 SCOPE=SPFILE;

System altered.

SQL>
SQL> alter system set "sga_target" = 0 SCOPE=SPFILE;
ble
System altered.
fe r a
ans
SQL>
n - t r
SQL> alter system set "memory_target" = 280M SCOPE=SPFILE;
a no
System altered. h a s ฺ
ฺ a r) uide
SQL>
ฺ c om ent G
4) Still connected in your SQL*Plus session a onas thetuSYS
d user, execute the
amm_setup.sql script. @
le this S
z i l
SQL>
c e loฺ use
SQL> @amm_setup a r to
m e
SQL>
i
SQL> l l eset( echo
c e nons
l o Z
SQL> li
rc e SQL> drop tablespace tbssga including contents and datafiles;
Ma drop tablespace tbssga including contents and datafiles
*
ERROR at line 1:
ORA-00959: tablespace 'TBSSGA' does not exist

SQL>
SQL> create tablespace tbssga datafile '+DATA' size 20m;

Tablespace created.

SQL>
SQL> drop tablespace mytemp including contents and datafiles;
drop tablespace mytemp including contents and datafiles
*
ERROR at line 1:
ORA-00959: tablespace 'MYTEMP' does not exist

SQL>

Oracle Database 11g: New Features for Administrators A - 286


Practice 16-1: Using Automatic Memory Management
(continued)
SQL> create temporary tablespace mytemp tempfile '+DATA' size
40m reuse;

Tablespace created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> drop user amm cascade;
drop user amm cascade
*
ERROR at line 1:
ORA-01918: user 'AMM' does not exist

SQL>
SQL> create user amm identified by amm default tablespace
ble
tbssga temporary tablespace mytemp;
fe r a
ans
User created.
n - t r
SQL> a no
SQL> grant connect,resource,dba to amm; h a s ฺ
ฺ a r) uide
Grant succeeded.
ฺ c om ent G
SQL> a on tud
SQL> select substr(COMPONENT,
l l e@ is0,S10) COMP, CURRENT_SIZE CS,
USER_SPECIFIED_SIZE i
ฺz US from thv$memory_dynamic_components where
l o s e
rce to u
CURRENT_SIZE!=0;
a
COMP e (m
l e n se CS US
i l
Z pooli c
---------------------------------------- ---------- ----------
e l oshared 260046848 0
rc
Ma
large pool 4194304 0
java pool 4194304 0
streams po 8388608 0
SGA Target 423624704 423624704
DEFAULT bu 104857600 0
Shared IO 33554432 33554432
PGA Target 159383552 159383552

8 rows selected.

SQL>
SQL> connect amm/amm
Connected.
SQL>
SQL> drop table tabsga purge;
drop table tabsga purge
*
ERROR at line 1:
ORA-00942: table or view does not exist

Oracle Database 11g: New Features for Administrators A - 287


Practice 16-1: Using Automatic Memory Management
(continued)

SQL>
SQL> create table tabsga(a number, b number) tablespace
tbssga;
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Table created.

SQL>
SQL> begin
2 for i in 1..100000 loop
3 insert into tabsga values (i, i);
4 end loop;
5 end;
6 /
ble
fe r a
PL/SQL procedure successfully completed.
an s
n - t r
SQL>
SQL> commit; a no
h a s ฺ
Commit complete.
ฺ a r) uide
SQL> ฺ c om ent G
SQL> alter table tabsga parallel a on 64; tud
@
le this S
z i l
Table altered.
c e loฺ use
SQL> a r to
SQL> e m
create
e
( eornsreplace procedure testpga( psize number ) as
i l l
Z3 declare
2 lic
begin
e l o
rc
Ma
4 TYPE nAllotment_tabtyp IS TABLE OF char(2048) INDEX
BY BINARY_INTEGER;
5 myarray nAllotment_tabtyp;
6 begin
7 for i in 1..psize loop
8 myarray(i) := to_char(i);
9 end loop;
10 end;
11 end;
12 /

Procedure created.

SQL>
SQL> show errors
No errors.
SQL>

Oracle Database 11g: New Features for Administrators A - 288


Practice 16-1: Using Automatic Memory Management
(continued)
SQL> select substr(COMPONENT, 0, 10) COMP, CURRENT_SIZE CS,
USER_SPECIFIED_SIZE US from v$memory_dynamic_components where
CURRENT_SIZE!=0;

COMP CS US
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

---------------------------------------- ---------- ----------


shared poo 260046848 0
large pool 4194304 0
java pool 4194304 0
streams po 8388608 0
SGA Target 423624704 423624704
DEFAULT bu 104857600 0
Shared IO 33554432 33554432
PGA Target 159383552 159383552
ble
fe r a
8 rows selected.
ans
n - t r
SQL>
SQL> connect / as sysdba a no
Connected. h a s ฺ
SQL>
ฺ a r) uide
5) Still connected in your SQL*Plus session ฺasctheomSYSeuser,
n tG shut down and start up
your database instance: o n
a Stu d
l l e@ is
SQL> shutdown immediate;
z i t h
Database closed.loฺ s e
r c e u
Database dismounted.
m a e todown.
l ( ens
ORACLE instance
estartup;
shut
SQL>
i l
Z instance lic started.
e l oORACLE
rc
Ma Total System Global Area
Fixed Size
292933632
1336092
bytes
bytes
Variable Size 201329892 bytes
Database Buffers 83886080 bytes
Redo Buffers 6381568 bytes
Database mounted.
Database opened.
SQL>

6) Connect as the AMM user in your SQL*Plus session and determine the current settings
for the various memory buffers as well as list of resized operations that were done
since you started your instance. Use the components.sql script for that purpose.
SQL> connect amm/amm
Connected.
SQL> @components
SQL> set echo on
SQL>

Oracle Database 11g: New Features for Administrators A - 289


Practice 16-1: Using Automatic Memory Management
(continued)
SQL> select substr(COMPONENT, 0, 10) COMP, CURRENT_SIZE CS,
USER_SPECIFIED_SIZE US from v$memory_dynamic_components where
CURRENT_SIZE!=0;

COMP CS US
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

---------------------------------------- ---------- ----------


shared poo 83886080 0
large pool 4194304 0
java pool 4194304 0
SGA Target 176160768 0
DEFAULT bu 75497472 0
PGA Target 117440512 0
6 rows selected.
ble
SQL>
fe r a
SQL> select substr(COMPONENT, 0, 10), FINAL_SIZE, OPER_TYPE,
ans
OPER_MODE, status from v$memory_resize_ops order by
n - t r
START_TIME;
a no
SUBSTR(COMPONENT,0, FINAL_SIZE OPER_TYPE haOPER_MODE s ฺ STATUS
------------------- ---------- ------------
ฺ a u i de
r) --------- --------
DEFAULT 8K
DEFAULT bu 92274688 ฺ om ent G
0 STATIC
c
STATIC
COMPLETE
COMPLETE
DEFAULT 2K a o0n STATICt ud COMPLETE
DEFAULT bu @
le92274688 S
isSTATIC IMMEDIATE COMPLETE
z i l t h
shared poo
large pool c e loฺ u4194304
67108864
se
STATIC
STATIC
COMPLETE
COMPLETE
large pool ar t o 4194304 GROW IMMEDIATE COMPLETE
java e (
poolm nse 4194304 STATIC COMPLETE
Z ill police
streams 0 STATIC COMPLETE
el oSGA Target 176160768 STATIC COMPLETE

Marc DEFAULT 32
DEFAULT 16
0
0
STATIC
STATIC
COMPLETE
COMPLETE
PGA Target 117440512 STATIC COMPLETE
RECYCLE bu 0 STATIC COMPLETE
KEEP buffe 0 STATIC COMPLETE
ASM Buffer 0 STATIC COMPLETE
DEFAULT 4K 0 STATIC COMPLETE
DEFAULT bu 88080384 STATIC IMMEDIATE COMPLETE
DEFAULT bu 88080384 INITIALIZING IMMEDIATE COMPLETE
shared poo 71303168 GROW IMMEDIATE COMPLETE
shared poo 75497472 GROW IMMEDIATE COMPLETE
DEFAULT bu 83886080 SHRINK IMMEDIATE COMPLETE
shared poo 79691776 GROW IMMEDIATE COMPLETE
DEFAULT bu 79691776 SHRINK IMMEDIATE COMPLETE
DEFAULT bu 75497472 SHRINK IMMEDIATE COMPLETE
shared poo 83886080 GROW IMMEDIATE COMPLETE

26 rows selected.
SQL>

Oracle Database 11g: New Features for Administrators A - 290


Practice 16-1: Using Automatic Memory Management
(continued)
7) Still connected as the AMM user under your SQL*Plus session, execute the following
query and immediately afterwards determine again both component sizes and resized
operations. Use query1.sql script for that purpose. What do you observe?
select /*+ PARALLEL(s 24) */ count(*) from (select /*+
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

parallel(s 24) */ * from tabsga s group by a);


a) You can see that the large pool has a much bigger size while the buffer cache is
smaller. This memory transfer was automatically done by the system.
SQL> @query1
SQL> set echo on
SQL>
SQL> select /*+ PARALLEL(s 24) */ count(*) from (select /*+
parallel(s 24) */ * from tabsga s group by a); e
r a bl
COUNT(*) s fe
----------
- t r an
100000
no n
SQL>
a
s ฺ
h a
SQL> select substr(COMPONENT, 0, 10) COMP,
ฺ a r) uide
CURRENT_SIZE
USER_SPECIFIED_SIZE US from v$memory_dynamic_components
CS,
where
o m t G
CURRENT_SIZE!=0;
o n ฺc den
COMP @ a Stu CS US
i l l e h i s
---------------------------------------- ---------- ----------
shared poo
e l oฺz use t 83886080 0
large pool arc t o 83886080 0
m e
l e ( icens
java pool
SGAilTarget
4194304
184549376
0
0
l o Z
DEFAULT l
bu 4194304 0
e
Marc PGA Target 109051904 0

6 rows selected.

SQL>
SQL> select substr(COMPONENT, 0, 10), FINAL_SIZE, OPER_TYPE,
OPER_MODE, status from v$memory_resize_ops order by
START_TIME;

SUBSTR(COMPONENT,0,10)FINAL_SIZE OPER_TYPE OPER_MODE STATUS


--------------------- ---------- --------- --------- ---------
shared poo 67108864 STATIC COMPLETE
large pool 4194304 GROW IMMEDIATE COMPLETE
large pool 4194304 STATIC COMPLETE
java pool 4194304 STATIC COMPLETE
streams po 0 STATIC COMPLETE
SGA Target 176160768 STATIC COMPLETE
ASM Buffer 0 STATIC COMPLETE

large pool 41943040 GROW IMMEDIATE COMPLETE

Oracle Database 11g: New Features for Administrators A - 291


Practice 16-1: Using Automatic Memory Management
(continued)
large pool 37748736 GROW IMMEDIATE COMPLETE
large pool 33554432 GROW IMMEDIATE COMPLETE
large pool 29360128 GROW IMMEDIATE COMPLETE
SGA Target 184549376 GROW IMMEDIATE COMPLETE
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

68 rows selected.

SQL>

8) Redo the same thing as in the previous step but this time use query2.sql script for
that purpose. What do you observe?
a) The same trend continues.
SQL> @query2 ble
SQL> set echo on
fe r a
SQL>
ans
SQL> select /*+ PARALLEL(s 25) */ count(*) from (select /*+
n - t r
parallel(s 25) */ * from tabsga s group by a);
a no
COUNT(*) h a s ฺ
---------- ฺ a r) uide
100000
ฺ c om ent G
SQL> a on tud
SQL> select substr(COMPONENT,
l l e@ is0,S10) COMP, CURRENT_SIZE CS,
USER_SPECIFIED_SIZE
i
ฺz US from thv$memory_dynamic_components where
l o s e
CURRENT_SIZE!=0;
a rce to u
COMP le (
m nse CS US
Z i l l i ce
---------------------------------------- ---------- ----------
rc eloshared poo 83886080 0
Ma large pool
java pool
83886080
4194304
0
0
SGA Target 188743680 0
DEFAULT bu 8388608 0
PGA Target 104857600 0

6 rows selected.

SQL>
SQL> select substr(COMPONENT, 0, 10), FINAL_SIZE, OPER_TYPE,
OPER_MODE, status from v$memory_resize_ops order by
START_TIME;

SUBSTR(COMPONENT,0,10) FINAL_SIZE OPER_TYPE OPER_MODE STATUS


---------------------- ---------- --------- --------- --------
RECYCLE bu 0 STATIC COMPLETE
PGA Target 117440512 STATIC COMPLETE
shared poo 67108864 STATIC COMPLETE
large pool 4194304 STATIC COMPLETE

Oracle Database 11g: New Features for Administrators A - 292


Practice 16-1: Using Automatic Memory Management
(continued)
large pool 4194304 GROW IMMEDIATE COMPLETE
java pool 4194304 STATIC COMPLETE

DEFAULT bu 12582912 GROW DEFERRED ERROR
DEFAULT bu 8388608 SHRINK IMMEDIATE COMPLETE
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

shared poo 83886080 GROW IMMEDIATE COMPLETE


shared poo 79691776 SHRINK DEFERRED ERROR
DEFAULT bu 12582912 GROW DEFERRED ERROR
DEFAULT bu 8388608 SHRINK IMMEDIATE COMPLETE
shared poo 83886080 GROW IMMEDIATE COMPLETE

91 rows selected.

SQL> ble
fe r a
9) Still connected as the AMM user in your SQL*Plus session, execute the query3.sql
ans
t r
script, and immediately after, determine the memory component sizes and the list of
n -
break. What do you observe? a no
resize operations. This script executes for around 10 to 15 minutes so you can take a

h a s ฺ
a) You can now see that SGA is automatically shrunk
a r)whileuPGA eis automatically
iduntunable
raised. This is because the query number three ฺneeds
m nt G a lot of PGA
c o
memory. Exit from SQL*Plus.
a onฺ tude
SQL> @query3
SQL> set echo on zille
@ is S
l o ฺ e th
SQL> s
rce to u
SQL> exec testpga(800000);
a
l e (m ense
Z i
PL/SQLl procedure
l i c successfully completed.

rc eloSQL>
Ma SQL> select substr(COMPONENT, 0, 10) COMP, CURRENT_SIZE CS,
USER_SPECIFIED_SIZE US from v$memory_dynamic_components where
CURRENT_SIZE!=0;

COMP CS US
---------------------------------------- ---------- ----------
shared poo 88080384 0
large pool 4194304 0
java pool 4194304 0
SGA Target 184549376 0
DEFAULT bu 79691776 0
PGA Target 109051904 0

6 rows selected.

SQL>
SQL> select substr(COMPONENT, 0, 10), FINAL_SIZE, OPER_TYPE,
OPER_MODE, status from v$memory_resize_ops order by
START_TIME;

Oracle Database 11g: New Features for Administrators A - 293


Practice 16-1: Using Automatic Memory Management
(continued)

SUBSTR(COMPONENT,0,10)FINAL_SIZE OPER_TYPE OPER_MODE STATUS


--------------------- ---------- ---------- --------- --------
RECYCLE bu 0 STATIC COMPLETE
PGA Target 117440512 STATIC COMPLETE
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

shared poo 67108864 STATIC COMPLETE



shared poo 83886080 GROW IMMEDIATE COMPLETE
DEFAULT bu 88080384 SHRINK IMMEDIATE COMPLETE
SGA Target 184549376 SHRINK DEFERRED COMPLETE
DEFAULT bu 79691776 SHRINK DEFERRED COMPLETE
PGA Target 109051904 GROW MANUAL COMPLETE

128 rows selected.


ble
fe r a
SQL>
ans
SQL>
n - t r
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition a no
Release 11.2.0.1.0 - Production h a s ฺ
ฺ a r) uide
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$ ฺ c om ent G
a on tud
10) From a terminal window, restart
l e@Enterprise
i s S
Manager Database Control and look at the
i l h
t this practice. What do you observe?
e l oฺz useduring
memory variations that happened
$ emctl start
a rcdbconsole
to
m
Oracle Enterprise
( ens e Manager 11g Database Control Release
l l e
11.2.0.1.0
l o Zi
Copyright
c 1996, 2009 Oracle Corporation. All rights
li(c)
rc e reserved.
Ma https://ed.us.oracle.com:5500/em/console/aboutApplication
Starting Oracle Enterprise Manager 11g Database Control
.................... started.
-------------------------------------------------------------
Logs are generated in directory
/u01/app/oracle/acfsmounts/acfs_db1/ed.us.oracle.com_orcl/sysm
an/log
$
a) Go to the Enterprise Manager Home page.
b) Click the Server tab.
c) On the Server subpage, click Memory Advisors in the Database Configuration
section.
d) On the Memory Advisors page, look at the first two graphics.
e) You should see that large pool was raised, then total SGA was raised too, and
then SGA was shrunk to the benefit of the PGA.

Oracle Database 11g: New Features for Administrators A - 294


Practice 16-1: Using Automatic Memory Management
(continued)
f) Log out from Enterprise Manager Database Console.
11) To clean up your environment, shut down your database instance, restore the original
SPFILE, and restart your database instance. To do all that, execute the
amm_cleanup.sh script to undo your changes.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

$ cd /home/oracle/solutions/AMM
$ ./amm_cleanup.sh
Oracle Enterprise Manager 11g Database Control Release
11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation. All rights
reserved.
https://ed.us.oracle.com:5500/em/console/aboutApplication
Stopping Oracle Enterprise Manager 11g Database Control ...
... Stopped. ble
fe r a
SQL*Plus: Release 11.2.0.1.0 Production on Wed Oct 7 08:54:59 ans
2009 n - t r
a no
Copyright (c) 1982, 2009, Oracle. All rightss reserved.
r ) ha deฺ
Connected to:
m ฺa Gui
n ฺ co eRelease
Oracle Database 11g Enterprise Edition
n t 11.2.0.1.0 -
Production
tud Management, OLAP,
ao SStorage
With the Partitioning, Automatic
@
le this Testing options
Data Mining and RealilApplication
z
e l oฺ use
SQL> SQL> SQL>
a c
r SQL>to
( ense
m
User dropped.
l e
l
Zi SQL> lic
SQL>
l o
e Tablespace dropped.
rc
Ma SQL> SQL>
Tablespace dropped.

SQL> SQL> Database closed.


Database dismounted.
ORACLE instance shut down.
SQL> SQL>
File created.

SQL> SQL> ORACLE instance started.

Total System Global Area 422670336 bytes


Fixed Size 1337116 bytes
Variable Size 310380772 bytes
Database Buffers 104857600 bytes
Redo Buffers 6094848 bytes
Database mounted.
Database opened.

Oracle Database 11g: New Features for Administrators A - 295


Practice 16-1: Using Automatic Memory Management
(continued)
SQL> SQL> Disconnected from Oracle Database 11g Enterprise
Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Oracle Enterprise Manager 11g Database Control Release
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation. All rights
reserved.
https://ed.us.oracle.com:5500/em/console/aboutApplication
Starting Oracle Enterprise Manager 11g Database Control
................. started.
--------------------------------------------------------------
Logs are generated in directory
/u01/app/oracle/acfsmounts/acfs_db1/ed.us.oracle.com_orcl/sysm
ble
an/log
fe r a
$
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 296


Practice 16-2: Using Deferred Optimizer Statistics
In this practice, you manipulate both deferred statistics publishing and statistic
extensions. The basic idea of this practice is to test various statistic gatherings on a
particular table before publishing the best ones in your production environment.
1) Execute the stats_setup.sh script. This script creates a new user called STATS
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

and creates and populates a new table called STATS.TABJFV


$ cd /home/oracle/solutions/stats
$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle
$ ./stats_setup.sh
ble
fe r a
SQL*Plus: Release 11.2.0.1.0 Production on Wed Oct 7 10:24:58
an s
2009
n - t r
Copyright (c) 1982, 2009, Oracle. no
All rights reserved.
a
h a s ฺ
Connected to:
a )
rRelease e
id11.2.0.1.0
Oracle Database 11g Enterprise Edition ฺ
m nt G u -
c o
onฺ Storage
Production
With the Partitioning, Automatic a t u de Management, OLAP,
l l e@ is STesting options
Data Mining and Real Application
i th
l oฺz drop
SQL> SQL> SQL> eSQL> u s e
user stats cascade
*a r c t o
(
ERROR at m
line 1: s e
ORA-01918:
Z en 'STATS' does not exist
ille licuser
rc elo SQL> SQL>
Ma User created.

SQL> SQL>
Grant succeeded.

SQL> SQL> Connected.


SQL> SQL> drop table tabjfv purge
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> SQL> SQL> 2


Table created.

SQL> SQL> SQL> SQL> 2 3 4 5 6 7 8


PL/SQL procedure successfully completed.

SQL>
Commit complete.

Oracle Database 11g: New Features for Administrators A - 297


Practice 16-2: Using Deferred Optimizer Statistics (continued)

SQL> SQL> Disconnected from Oracle Database 11g Enterprise


Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

2) Start a SQL*Plus session connected as user STATS, and do not disconnect from that
session. Make sure that you delete all existing statistics on STATS.TABJFV, and
verify that none exist either as public statistics or as pending statistics. Use the
delete_stats.sql script for that.
$ sqlplus stats/stats

SQL*Plus: Release 11.2.0.1.0 Production on Wed Oct 7 10:26:44 e


2009
r a bl
s fe
Copyright (c) 1982, 2009, Oracle. All rights reserved.
- t r an
o n
Connected to:
s an
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production r ) ha deฺ
ฺa Gui
With the Partitioning, Automatic Storage Management, OLAP,
m
n ฺ co ent
Data Mining and Real Application Testing options

SQL> @delete_stats @ ao Stud


z i l le this
Session altered.loฺ se
r c e u
m a e to
l ( ens successfully completed.
e procedure
i l
PL/SQL
Z lic
l o
e old 3: where table_name = '&1'
rc
Ma new 3: where table_name = 'TABJFV'

TABLE_NAME ANALYZE_TIME NUM_ROWS BLOCKS AVG_ROW_LEN


------------- -------------- ---------- ---------- -----------
TABJFV

old 4: where table_name = '&1'


new 4: where table_name = 'TABJFV'

no rows selected

old 4: where table_name = '&1'


new 4: where table_name = 'TABJFV'

COLUMN_NAME ANALYZE_TIME NUM_DISTINCT NUM_NULLS DENSITY


------------ -------------- ------------ ---------- ----------
C1
C2
C3

Oracle Database 11g: New Features for Administrators A - 298


Practice 16-2: Using Deferred Optimizer Statistics (continued)
C4
C5
C6
C7
C8
C9
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

9 rows selected.

SQL>
SQL>
SQL> -- private statistics: none
SQL> @ show_pending_stats TABJFV
SQL>
SQL> set echo off
ble
old 3: where table_name = '&1' and partition_name is null
fe r a
new 3: where table_name = 'TABJFV' and partition_name is
ans
null
n - t r
no rows selected a no
h a s ฺ
old
new
4: where table_name = '&1' and partition_name
4: where table_name = 'TABJFV' ฺ a
and u ide is null
r) partition_name is
null c o m nt G
a onฺ tude
no rows selected
l l e@ is S
i h
old l oฺz use=t '&1' and partition_name is null
4: where etable_name
new rc table_name
4: where
a to = 'TABJFV' and partition_name is
m e
null
i l l e ( icens
l o Z l
no rows selected
rc e
Ma SQL>
SQL>

3) Determine the publishing mode for STATS.TABJFV statistics, and set it to PENDING
mode. Use the pending_mode.sql script for that.
SQL>
SQL> @pending_mode
SQL> -- table publish mode should be TRUE, for now
SQL> select dbms_stats.get_prefs('PUBLISH', 'stats', 'tabjfv')
publish from dual;

PUBLISH
--------------------------------------------------------------
TRUE

SQL>
SQL> -- set table value to false, i.e, do not publish
statistics

Oracle Database 11g: New Features for Administrators A - 299


Practice 16-2: Using Deferred Optimizer Statistics (continued)
SQL> exec dbms_stats.set_table_prefs('stats', 'tabjfv',
'PUBLISH', 'FALSE');

PL/SQL procedure successfully completed.

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> -- table publish mode should be FALSE now


SQL> select dbms_stats.get_prefs('PUBLISH', 'stats', 'tabjfv')
publish from dual;

PUBLISH
--------------------------------------------------------------
FALSE

SQL>
ble
SQL>
fe r a
4) Collect statistics on STATS.TABJFV and investigate the result. What do you ans
observe? Use the collect_pending.sql script for that. n - t r
a no
a) Statistics are only visible from the pending area. Note alsosthat, by default, your
session only uses public statistics.
r ) ha deฺ
SQL> @collect_pending m ฺa Gui
SQL> -- Collect stats n ฺ co ent
SQL> begin
@ ao Stud
2 le'forthall
is columns size'tabjfv',
dbms_stats.gather_table_stats(null,
z i l
3
size 254 for c
method_opt
e loฺ c2ussize
columns
=> e 254'); 1 for columns c1

4 end; ar e to
5 e / (
m ns
Z i l l li c e
e l oPL/SQL procedure successfully completed.
rc
Ma SQL>
SQL> -- public statistics: still nothing
SQL> @ show_public_stats TABJFV
SQL>
SQL> set echo off
old 3: where table_name = '&1'
new 3: where table_name = 'TABJFV'

TABLE_NAME ANALYZE_TIME NUM_ROWS BLOCKS AVG_ROW_LEN


------------- -------------- ---------- ---------- -----------
TABJFV

old 4: where table_name = '&1'


new 4: where table_name = 'TABJFV'

no rows selected

old 4: where table_name = '&1'

Oracle Database 11g: New Features for Administrators A - 300


Practice 16-2: Using Deferred Optimizer Statistics (continued)
new 4: where table_name = 'TABJFV'

COLUMN_NAME ANALYZE_TIME NUM_DISTINCT NUM_NULLS DENSITY


------------ -------------- ------------ ---------- ----------
C1
C2
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

C3
C4
C5
C6
C7
C8
C9

9 rows selected.
ble
fe r a
SQL>
ans
SQL>
SQL> -- private statistics: should see values (0.001 for n - t r
density for both C1 and C2, 0.2 for others) a no
SQL> @ show_pending_stats TABJFV
h a s ฺ
SQL>
SQL> set echo off ฺ a r) uide
old c om ent G
3: where table_name = '&1' and partition_name is null

new on tud
3: where table_name = 'TABJFV' and partition_name is
a
null
l l e@ is S
i
ฺz time th
TABLE_NAME l o
analyze e
e o us ---------- NUM_ROWS BLOCKS AVG_ROW_LEN
-------------r c t 10:34:00
--------------
a 10/07 ---------- -----------
TABJFV (m
n s e 500 5 27
l l e e
l o Zi 4: where
old
lic table_name = '&1' and partition_name is null
rc e new 4: where table_name = 'TABJFV' and partition_name is
Ma null

no rows selected

old 4: where table_name = '&1' and partition_name is null


new 4: where table_name = 'TABJFV' and partition_name is
null

COLUMN_NAME analyze time NUM_DISTINCT NUM_NULLS DENSITY


------------ -------------- ------------ ---------- ----------
C1 10/07 10:33:59 5 0 .001
C2 10/07 10:33:59 5 0 .001
C3 10/07 10:33:59 5 0 .2
C4 10/07 10:33:59 5 0 .2
C5 10/07 10:33:59 5 0 .2
C6 10/07 10:33:59 5 0 .2
C7 10/07 10:33:59 5 0 .2
C8 10/07 10:33:59 5 0 .2
C9 10/07 10:33:59 5 0 .2

Oracle Database 11g: New Features for Administrators A - 301


Practice 16-2: Using Deferred Optimizer Statistics (continued)

9 rows selected.

SQL>
SQL>
SQL> -- Should be false: use public statistics
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> show parameter optimizer_use_pending_statistics

NAME TYPE VALUE


------------------------------------ ----------- -------------
optimizer_use_pending_statistics boolean FALSE
SQL>
SQL>

5) From a terminal window, connected as the STATS user in a SQL*Plus session (Do e
not exit from this session after this step!), disable dynamic sampling for your session r a bl
and determine the estimation for the number of rows that the optimizer can currently fe
ns
guess for the following query: - t r a
select count(*) from tabjfv where c1 = 1 and c2 = 1;
n o n
What is your conclusion? Use the determine1.sql script toa execute this step.
s
ha there ฺare currently no
)
a) Because you are not using dynamic sampling, andrbecause
i d e
public statistics for your table, the optimizerm ฺa a wrong
makes G u guess on the number
of rows that the query returns: It is using o
ฺc1 instead
e t
nof 100.
o n
a Stu d
SQL> @determine1 @
SQL> set echo on
z i l l e t h is
SQL>
c e loฺ use
SQL> alter session
a r o optimizer_dynamic_sampling = 0;
tset
m e
i l
Session l e (altered.
c e ns
l o Z li
rc e SQL>
Ma SQL> select count(*) from tabjfv where c1 = 1 and c2 = 1;

COUNT(*)
----------
100

SQL>
SQL> explain plan for select count(*) from tabjfv where c1 = 1
and c2 = 1;

Explained.

SQL>
SQL> select plan_table_output
2 from table(dbms_xplan.display('plan_table',null,'BASIC
ROWS'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------

Oracle Database 11g: New Features for Administrators A - 302


Practice 16-2: Using Deferred Optimizer Statistics (continued)
Plan hash value: 3122694931

---------------------------------------------
| Id | Operation | Name | Rows |
---------------------------------------------
| 0 | SELECT STATEMENT | | 1 |
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

| 1 | SORT AGGREGATE | | 1 |
| 2 | TABLE ACCESS FULL| TABJFV | 1 |
---------------------------------------------

9 rows selected.

SQL>
6) Now, switch your session to use pending statistics that were previously collected. e
SQL> alter session set optimizer_use_pending_statistics = r a bl
s fe
true;
- t r an
Session altered. no n
s ฺa
SQL> h a
ฺ a r) uide
7) Determine again the optimizer’s estimation of the number
m nt G of rows returned by your
c o
onฺ tude script to execute this step.
query. What do you observe? Use the determine2.sql
a
a) Again, the optimizer picks up S
@a wrongisestimation. This is due to the fact that the
ille that C1
optimizer is unable toฺzguess t h and C2 are highly correlated for value 1.
l o s e
SQL> @determine2
a rce to u
SQL> set
l e (mechoenonse
SQL>l
Zi explain
SQL> lic plan for select count(*) from tabjfv where c1 = 1
l o
e and c2 = 1;
rc
Ma Explained.

SQL>
SQL> select plan_table_output
2 from table(dbms_xplan.display('plan_table',null,'BASIC
ROWS'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
Plan hash value: 3122694931

---------------------------------------------
| Id | Operation | Name | Rows |
---------------------------------------------
| 0 | SELECT STATEMENT | | 1 |
| 1 | SORT AGGREGATE | | 1 |
| 2 | TABLE ACCESS FULL| TABJFV | 20 |
---------------------------------------------

Oracle Database 11g: New Features for Administrators A - 303


Practice 16-2: Using Deferred Optimizer Statistics (continued)

9 rows selected.

SQL>
8) Create a statistics extension to group C1 and C2 to indicate that both columns are
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

correlated in STATS.TABJFV. When done, gather statistics again on your table with
maximum precision for your extension. Use the
create_stats_extension.sql script for that.
SQL> @create_stats_extension
SQL> col table_name format a10
SQL> col extension format a12
SQL>
SQL> select * from user_stat_extensions; e
r a bl
no rows selected s fe
- t r an
SQL>
no n
SQL> -- Create extention on the 2 columns
SQL> select
a
s ฺ
h a
dual; ฺ a r) uide
dbms_stats.create_extended_stats(null,'tabjfv','(c1,c2)') from

ฺ c om ent G
on tud
DBMS_STATS.CREATE_EXTENDED_STATS(NULL,'TABJFV','(C1,C2)')
a
l l e@ is S
--------------------------------------------------------------
i
ฺz se th
SYS_STUF3GLKIOP5F4B0BTTCFTMX0W
l o
SQL> a rce to u
SQL> select
l e se user_stat_extensions;
(m e* nfrom
Zi l lic
l oTABLE_NA EXTENSION_NAME EXTENSION
e -------- ------------------------------ ----------- CREATO DRO
rc ------ ---
Ma TABJFV SYS_STUF3GLKIOP5F4B0BTTCFTMX0W ("C1","C2") USER YES

SQL>
SQL> -- Collect stats
SQL> begin
2 dbms_stats.gather_table_stats(null, 'tabjfv',
3 method_opt => 'for all columns size 1 for columns
(c1,c2) size 254');
4 end;
5 /

PL/SQL procedure successfully completed.

SQL>
SQL> -- public statistics: still nothing
SQL> @ show_public_stats TABJFV
SQL>
SQL> set echo off
old 3: where table_name = '&1'

Oracle Database 11g: New Features for Administrators A - 304


Practice 16-2: Using Deferred Optimizer Statistics (continued)
new 3: where table_name = 'TABJFV'

TABLE_NAME ANALYZE_TIME NUM_ROWS BLOCKS AVG_ROW_LEN


---------- -------------- ---------- ---------- -----------
TABJFV
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

old 4: where table_name = '&1'


new 4: where table_name = 'TABJFV'

no rows selected

old 4: where table_name = '&1'


new 4: where table_name = 'TABJFV'

COLUMN_NAME ANALYZE_TIME NUM_DISTINCT NUM_NULLS DENSITY


ble
------------ -------------- ------------ ---------- ----------
fe r a
C1
ans
C2
C3 n - t r
C4 a no
C5
h a s ฺ
C6
C7 ฺ a r) uide
C8 ฺ c om ent G
C9 a on tud
9 rows selected. zill
e@ this S
c e loฺ use
SQL> a r to
m e
SQL>
i
SQL> l l e--(private
c e nsstatistics: should see values and also the new
l o Z li
virtual column! Density=0.2 for all except virtual one: 0.001
rc e SQL> @ show_pending_stats TABJFV
Ma SQL>
SQL> set echo off
old 3: where table_name = '&1' and partition_name is null
new 3: where table_name = 'TABJFV' and partition_name is
null

TABLE_NAME analyze time NUM_ROWS BLOCKS AVG_ROW_LEN


---------- -------------- ---------- ---------- -----------
TABJFV 10/07 10:44:59 500 5 39

old 4: where table_name = '&1' and partition_name is null


new 4: where table_name = 'TABJFV' and partition_name is
null

no rows selected

old 4: where table_name = '&1' and partition_name is null


new 4: where table_name = 'TABJFV' and partition_name is
null

Oracle Database 11g: New Features for Administrators A - 305


Practice 16-2: Using Deferred Optimizer Statistics (continued)

COLUMN_NAME analyze time NUM_DISTINCT


NUM_NULLS DENSITY
------------------------------ -------------- ------------ ---
------- ----------
C1 10/07 10:44:59 5
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

0 .2
C2 10/07 10:44:59 5
0 .2
C3 10/07 10:44:59 5
0 .2
C4 10/07 10:44:59 5
0 .2
C5 10/07 10:44:59 5
0 .2
ble
C6 10/07 10:44:59 5
fe r a
0 .2
a5n
s
C7
0 .2
10/07 10:44:59
n- t r
C8 10/07 10:44:59 a no 5
0 .2 s
ha deฺ
C9
ฺ a r )
10/07 10:44:59
i 5
0 .2 u
SYS_STUF3GLKIOP5F4B0BTTCFTMX0W ฺ c om 10:44:59
10/07
e n t G 5
0 .001 o n
a Stu d
e @ is
10 rows selected. zill t h
c e loฺ use
SQL> a r to
m e
i l
9) Determinel e ( again
c e nsoptimizer’s estimation of the number of rows returned by your
the
l o Z What ldoi you observe? (Use the determine2.sql script.)
query.
rc e
Ma a) You should see the correct estimation this time.
SQL> @determine2
SQL> set echo on
SQL>
SQL> explain plan for select count(*) from tabjfv where c1 = 1
and c2 = 1;

Explained.

SQL>
SQL> select plan_table_output
2 from table(dbms_xplan.display('plan_table',null,'BASIC
ROWS'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
Plan hash value: 3122694931

---------------------------------------------

Oracle Database 11g: New Features for Administrators A - 306


Practice 16-2: Using Deferred Optimizer Statistics (continued)
| Id | Operation | Name | Rows |
---------------------------------------------
| 0 | SELECT STATEMENT | | 1 |
| 1 | SORT AGGREGATE | | 1 |
| 2 | TABLE ACCESS FULL| TABJFV | 100 |
---------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

9 rows selected.

SQL>

10) Execute the add_rows.sql script from your SQL*Plus session. When done, the
table contains five different values, each repeating 200 times (uniform). All columns
have same value. It also has 200 null rows.
SQL> @add_rows ble
SQL> -- Insert some more rows. Now the table has 5 values each fe r a
repeating 200 ans
SQL> -- times (uniform). All columns have same value. n - t r
o
SQL> begin
2 for i in 1..5 loop s an
3 for j in 1..100 loop
r ) ha deฺ
4 ฺa Gui
insert into tabjfv(c1,c2,c3,c4,c5,c6,c7,c8,c9)
m
values (i,i,i,i,i,i,i,i,i);
n ฺ co ent
5
6
end loop;
end loop; @ ao Stud
7 end;
z i l le this
8 /
c e loฺ use
a r successfully
to
( m
PL/SQL procedure
n s e completed.
e
ill commit;i ce
l o Z
SQL> l
e
Marc Commit complete.

SQL>
SQL>
SQL> -- Insert 200 null rows
SQL> begin
2 for j in 1..200 loop
3 insert into tabjfv(c1) values (null);
4 end loop;
5 end;
6 /

PL/SQL procedure successfully completed.

SQL> commit;

Commit complete.

SQL>

Oracle Database 11g: New Features for Administrators A - 307


Practice 16-2: Using Deferred Optimizer Statistics (continued)
11) Determine again the optimizer’s estimation of the number of rows returned by your
query for the following three cases: without dynamic sampling, with dynamic
sampling level 3, and with dynamic sampling level 4. What do you observe? Use the
show_dynamic_stats.sql script for that.
a) Without dynamic sampling, the estimation is now incorrect because statistics have
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

not been refreshed. Dynamic sampling level 3 is not enough to force a better
estimation. At dynamic sampling level 4, a better estimate is found.
SQL> @show_dynamic_stats
SQL> -- Try without dynamic sampling
SQL> --
SQL> explain plan for select * from tabjfv where c1 = 1 and c2
= 1;

Explained. ble
fe r a
SQL> ans
SQL> select plan_table_output from n - t r
table(dbms_xplan.display('plan_table',null,'BASIC ROWS'));
a no
h a s ฺ
PLAN_TABLE_OUTPUT
ฺ a r) uide
--------------------------------------------------------------
Plan hash value: 349803950
ฺ c om ent G
a on tud
--------------------------------------------
l e@| Namei s S
| Id | Operation
ฺ z i l t h | Rows |
lo us e
--------------------------------------------
eSTATEMENT
| r
0 | SELECTc
a ACCESS to FULL|| TABJFV || 100 |
| 1 |(mTABLE s e 100 |
ille licen
--------------------------------------------
Z
el o
Marc 8 rows selected.

SQL>
SQL>
SQL> -- Try the queries with dynamic sampling level 3. Dynamic
sampling will not
SQL> -- kick in. It will use multi column stats and produce
the same estimate
SQL> -- (100 rows) as before.
SQL> explain plan for select /*+ dynamic_sampling(3) */ * from
tabjfv where c1 = 1 and c2 = 1;

Explained.

SQL>
SQL> select plan_table_output from
table(dbms_xplan.display('plan_table',null,'BASIC ROWS'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------

Oracle Database 11g: New Features for Administrators A - 308


Practice 16-2: Using Deferred Optimizer Statistics (continued)
Plan hash value: 349803950

--------------------------------------------
| Id | Operation | Name | Rows |
--------------------------------------------
| 0 | SELECT STATEMENT | | 100 |
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

| 1 | TABLE ACCESS FULL| TABJFV | 100 |


--------------------------------------------

8 rows selected.

SQL>
SQL>
SQL> -- Try with level 4. Dynamic sampling kicks in. we should
see the improved
ble
SQL> -- estimate (200 rows)
fe r a
SQL> explain plan for select /*+ dynamic_sampling(4) */ * from
ans
tabjfv where c1 = 1 and c2 = 1;
n - t r
Explained. a no
h a s ฺ
SQL>
SQL> select plan_table_output from mฺa
r) uide
table(dbms_xplan.display('plan_table',null,'BASIC
ฺ c o ent G ROWS'));
o n
a Stu d
PLAN_TABLE_OUTPUT
l l e@ is
i t h
--------------------------------------------------------------
ฺ z
Plan hash value:
c e lo349803950 u se
a r to
m e
i
| Id l e|(Operation
c ns
--------------------------------------------
l e | Name | Rows |
l o Z li
--------------------------------------------
rc e | 0 | SELECT STATEMENT | | 200 |
Ma | 1 | TABLE ACCESS FULL| TABJFV | 200 |
--------------------------------------------

8 rows selected.

SQL>

12) Collect pending statistics for your table again. Use the collect_pending2.sql
script for that.
SQL> @collect_pending2
SQL> -- Collect stats
SQL> begin
2 dbms_stats.gather_table_stats(null, 'tabjfv',
3 method_opt => 'for all columns size 1 for columns
(c1,c2) size 254');
4 end;
5 /

Oracle Database 11g: New Features for Administrators A - 309


Practice 16-2: Using Deferred Optimizer Statistics (continued)
PL/SQL procedure successfully completed.

SQL>
SQL> -- public statistics: still nothing
SQL> @ show_public_stats TABJFV
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> set echo off


old 3: where table_name = '&1'
new 3: where table_name = 'TABJFV'

TABLE_NAME ANALYZE_TIME NUM_ROWS BLOCKS AVG_ROW_LEN


---------- -------------- ---------- ---------- -----------
TABJFV

old 4: where table_name = '&1'


ble
new 4: where table_name = 'TABJFV'
fe r a
ans
no rows selected
n - t r
old 4: where table_name = '&1' a no
new 4: where table_name = 'TABJFV'
h a s ฺ
COLUMN_NAME ANALYZE_TIME ฺ a
NUM_DISTINCT u ide
r) NUM_NULLS DENSITY
c
------------ -------------- ------------o m nt----------
G ----------
C1 a onฺ tude
C2
l l e@ is S
C3 i
ฺz se th
C4 l o
C5 a rce to u
C6
l e (m ense
C7 i
Z l lic
e l oC8
rc C9
Ma
9 rows selected.

SQL>
SQL>
SQL> -- private statistics: should see values (0.001 for
density for both C1 and C2, 0.2 for others)
SQL> @ show_pending_stats TABJFV
SQL>
SQL> set echo off
old 3: where table_name = '&1' and partition_name is null
new 3: where table_name = 'TABJFV' and partition_name is
null

TABLE_NAME analyze time NUM_ROWS BLOCKS AVG_ROW_LEN


---------- -------------- ---------- ---------- -----------
TABJFV 10/07 10:54:28 1200 5 37

old 4: where table_name = '&1' and partition_name is null

Oracle Database 11g: New Features for Administrators A - 310


Practice 16-2: Using Deferred Optimizer Statistics (continued)
new 4: where table_name = 'TABJFV' and partition_name is
null

no rows selected

old 4: where table_name = '&1' and partition_name is null


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

new 4: where table_name = 'TABJFV' and partition_name is


null

COLUMN_NAME analyze time NUM_DISTINCT


NUM_NULLS DENSITY
------------------------------ -------------- ------------ ---
------- ----------
C1 10/07 10:54:28 5
200 .2
ble
C2 10/07 10:54:28 5
fe r a
200 .2
a5n
s
C3
200 .2
10/07 10:54:28
n- t r
o
C4 10/07 10:54:28
s an 5
200
C5
.2
r ) ha deฺ
10/07 10:54:28 5
200 .2 m ฺa Gui
C6
n ฺ co 10:54:28
10/07
e n t 5
200
C7
.2
@ ao 10/07
S tud10:54:28 5
200 .2 z i l le this
C8
c e loฺ use 10/07 10:54:28 5
200 .2a r t o
C9 ( m n s e 10/07 10:54:28 5
i l l e e
l
200
oZ lic
.2
SYS_STUF3GLKIOP5F4B0BTTCFTMX0W 10/07 10:54:28 5
e
Marc 200 .0005

10 rows selected.

SQL>
SQL>
SQL> -- Should be false: use public statistics
SQL> show parameter optimizer_use_pending_statistics

NAME TYPE VALUE


------------------------------------ ----------- -------------
optimizer_use_pending_statistics boolean TRUE
SQL>
13) Determine again the optimizer’s estimation of the number of rows returned by your
query. What do you observe? (Use determine2.sql.)
a) This time the estimation is correct.
SQL> @determine2
SQL> set echo on

Oracle Database 11g: New Features for Administrators A - 311


Practice 16-2: Using Deferred Optimizer Statistics (continued)
SQL>
SQL> explain plan for select count(*) from tabjfv where c1 = 1
and c2 = 1;

Explained.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> select plan_table_output
2 from table(dbms_xplan.display('plan_table',null,'BASIC
ROWS'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
Plan hash value: 3122694931
ble
---------------------------------------------
fe r a
| Id | Operation | Name | Rows |
ans
---------------------------------------------
| 0 | SELECT STATEMENT | | 1 | n - t r
| 1 | SORT AGGREGATE | | 1 | a no
| 2 | TABLE ACCESS FULL| TABJFV | 200 |
h a s ฺ
---------------------------------------------
ฺ a r) uide
9 rows selected. ฺ c om ent G
a on tud
SQL>
l l e @ is S
SQL> i
ฺz se th
l o
a rceto public
14) Switch your session t o ustatistics mode.
SQL> le (m session
alter
e n se set optimizer_use_pending_statistics =
Zi l
false; lic
l o
rce Session altered.
Ma
SQL>
15) Determine again the optimizer’s estimation of the number of rows returned by your
query. What do you observe? (Use determine2.sql.)
a) Because there are no public statistics yet, and because dynamic sampling is not
turned on, the estimation is wrong.
SQL> @determine2
SQL> set echo on
SQL>
SQL> explain plan for select count(*) from tabjfv where c1 = 1
and c2 = 1;

Explained.

SQL>
SQL> select plan_table_output

Oracle Database 11g: New Features for Administrators A - 312


Practice 16-2: Using Deferred Optimizer Statistics (continued)
2 from table(dbms_xplan.display('plan_table',null,'BASIC
ROWS'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
Plan hash value: 3122694931
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

---------------------------------------------
| Id | Operation | Name | Rows |
---------------------------------------------
| 0 | SELECT STATEMENT | | 1 |
| 1 | SORT AGGREGATE | | 1 |
| 2 | TABLE ACCESS FULL| TABJFV | 1 |
---------------------------------------------
ble
9 rows selected.
fe r a
ans
SQL>
SQL> n - t r
a no
16) Now that you are satisfied with these statistics, publish them s to the public level. Use
the publish_stats.sql script to execute this step. ) h a e ฺ
r
ฺa Gu i d
SQL> @publish_stats
c o m n t
SQL> set echo on n ฺ e
SQL>
@ ao Stud
l le this
SQL> exec dbms_stats.publish_pending_stats('stats','tabjfv');
z i

losuccessfullyse completed.
PL/SQL procedure
r c e u
m a e to
SQL>lle
( ens
i lic
Z @ show_public_stats
SQL> TABJFV
l o
rce SQL>
Ma SQL> set echo off
old 3: where table_name = '&1'
new 3: where table_name = 'TABJFV'

TABLE_NAME ANALYZE_TIME NUM_ROWS BLOCKS AVG_ROW_LEN


---------- -------------- ---------- ---------- -----------
TABJFV 10/07 10:54:28 1200 5 37

old 4: where table_name = '&1'


new 4: where table_name = 'TABJFV'

no rows selected

old 4: where table_name = '&1'


new 4: where table_name = 'TABJFV'

COLUMN_NAME ANALYZE_TIME NUM_DISTINCT NUM_NULLS DENSITY


------------ -------------- ------------ ---------- ----------
C1 10/07 10:54:28 5 200 .2

Oracle Database 11g: New Features for Administrators A - 313


Practice 16-2: Using Deferred Optimizer Statistics (continued)
C2 10/07 10:54:28 5 200 .2
C3 10/07 10:54:28 5 200 .2
C4 10/07 10:54:28 5 200 .2
C5 10/07 10:54:28 5 200 .2
C6 10/07 10:54:28 5 200 .2
C7 10/07 10:54:28 5 200 .2
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

C8 10/07 10:54:28 5 200 .2


C9 10/07 10:54:28 5 200 .2

9 rows selected.

SQL>
SQL>
SQL> @ show_pending_stats TABJFV
SQL>
ble
SQL> set echo off
fe r a
old 3: where table_name = '&1' and partition_name is null
ans
new
null
3: where table_name = 'TABJFV' and partition_name is
n - t r
a no
no rows selected
h a s ฺ
old 4: where table_name = '&1' and ฺ a r) uide is null
partition_name
new c
4: where table_name = 'TABJFV'
ฺ om andn t G
partition_name is
null a on tude
no rows selected zill
e@ this S
c e loฺ use
old r table_name
4: where
a to = '&1' and partition_name is null
new 4:m
( ens
where e
table_name = 'TABJFV' and partition_name is
l l e
l o Zi
null
lic
rc e no rows selected
Ma
SQL>
SQL>
17) Determine again the optimizer’s estimation of the number of rows returned by your
query. What do you observe? (Use determine2.sql.)
a) This time the statistics estimation is correct!
SQL> @determine2
SQL> set echo on
SQL>
SQL> explain plan for select count(*) from tabjfv where c1 = 1
and c2 = 1;

Explained.

SQL>
SQL> select plan_table_output

Oracle Database 11g: New Features for Administrators A - 314


Practice 16-2: Using Deferred Optimizer Statistics (continued)
2 from table(dbms_xplan.display('plan_table',null,'BASIC
ROWS'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
Plan hash value: 3122694931
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

---------------------------------------------
| Id | Operation | Name | Rows |
---------------------------------------------
| 0 | SELECT STATEMENT | | 1 |
| 1 | SORT AGGREGATE | | 1 |
| 2 | TABLE ACCESS FULL| TABJFV | 200 |
---------------------------------------------
ble
9 rows selected.
fe r a
ans
SQL>
n - t r
no
18) Determine the publishing mode for STATS.TABJFV statistics, and set it back to
a
h a s ฺ
PUBLIC mode (use determine_publish.sql). Exit from SQL*Plus.
SQL> ฺ a r) uide
SQL> @determine_publish
ฺ c om ent G
publish a on tud
SQL> select dbms_stats.get_prefs('PUBLISH', 'stats', 'tabjfv')

2 from dual; l l e@ is S
i
ฺz se th
l o
PUBLISH
a r ce to u
FALSE l e (m ense
--------------------------------------------------------------

Zi l lic
e l oSQL>
rc SQL> exec
Ma dbms_stats.set_table_prefs('stats','tabjfv','PUBLISH','TRUE');

PL/SQL procedure successfully completed.

SQL>
SQL> select dbms_stats.get_prefs('PUBLISH', 'stats', 'tabjfv')
publish
2 from dual;

PUBLISH
--------------------------------------------------------------
TRUE
SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$

Oracle Database 11g: New Features for Administrators A - 315


Practice 16-2: Using Deferred Optimizer Statistics (continued)
19) Execute the stats_cleanup.sh script to clean up your environment.
$ ./stats_cleanup.sh

SQL*Plus: Release 11.2.0.1.0 Production on Wed Oct 7 11:07:20


2009
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> SQL> SQL> SQL> ble


User dropped. fe r a
t r a ns
SQL> SQL> Disconnected from Oracle Database 11g Enterprise
o n -
Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management,s a n OLAP,
Data Mining and Real Application Testing) options
r ha deฺ
$
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 316


Practices for Lesson 17

In the practice for this lesson, you use result cache.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 317


Practice 17-1: Using Result Cache
In this practice, you explore the various possibilities to cache query results in the SGA.
Perform the following steps to understand the use of Query Result Cache.
1) Change to the $HOME/solutions/qrc directory and execute the
result_cache_setup.sh script.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

$ cd /home/oracle/solutions/qrc
$
$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle
$ ./result_cache_setup.sh
ble
fe r a
SQL*Plus: Release 11.2.0.1.0 Production on Wed Oct 7 11:16:29
ans
2009
n - t r
Copyright (c) 1982, 2009, Oracle. no
All rights reserved.
a
h a s ฺ
Connected to:
a )
rRelease e
id11.2.0.1.0
Oracle Database 11g Enterprise Edition ฺ
m nt G u -
Production c o
With the Partitioning, Automatic
a onฺ Storage
t u de Management, OLAP,
le@user
Data Mining and Real Application
i s STesting options
ฺ l
SQL> SQL> SQL> SQL>zidrop t h qrc cascade
* l o
e o us e
ERROR at line
a rc1: t does not exist
( m
ORA-01918: e
users'QRC'
Z ille licen
rc eloSQL> SQL> 2 3
User created.
Ma
SQL> SQL>
Grant succeeded.

SQL> SQL> Connected.


SQL> SQL>
PL/SQL procedure successfully completed.

SQL> SQL> drop table cachejfv purge


*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> SQL>
Table created.

SQL> SQL>
1 row created.

Oracle Database 11g: New Features for Administrators A - 318


Practice 17-1: Using Result Cache (continued)
SQL>
1 row created.

SQL>
2 rows created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
4 rows created.

SQL>
524288 rows created.

SQL> SQL>
ble
1 row created.
fe r a
ans
SQL> SQL>
Commit complete. n - t r
a no
SQL> SQL>
h a s ฺ
System altered.
ฺ a r) uide
SQL> SQL> Disconnected from Oracle ฺ c omDatabase
n t G11g Enterprise
Edition Release 11.2.0.1.0a-oProduction n ude
With the Partitioning, Automatic @ S t
Storage Management, OLAP,
Data Mining and Real z l e
ilApplication
t s
hi Testing options
ฺ e
$
r c elo o us
m a window
2) In your terminal e t
log in to SQL*Plus as the QRC user. From now on, do not
( s
Z ille from
disconnect
l i cethisn session. Determine the current content of the query cache using
rc elothe following statement:
Ma select type,status,name,object_no,row_count,row_size_avg
from v$result_cache_objects order by 1;
You can use the check_result_cache.sql script. What do you observe? Right
now, the query cache should be empty.
$ sqlplus qrc/qrc

SQL*Plus: Release 11.2.0.1.0 Production on Wed Oct 7 11:21:43


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> @check_result_cache

Oracle Database 11g: New Features for Administrators A - 319


Practice 17-1: Using Result Cache (continued)
SQL>
SQL> select type,status,name,object_no,row_count,row_size_avg
from v$result_cache_objects order by 1;

no rows selected
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>

3) Set timing on and execute the following query. You can use the query1.sql script.
Note the time that it takes to execute.
select /*+ result_cache q_name(Q1) */ count(*)
from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv c4,
cachejfv c5
where c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and
c5.c='b'; ble
SQL> set timing on fe r a
SQL> @query1
ans
SQL> select /*+ result_cache q_name(Q1) */ count(*) n - t r
2 from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv
a no
c4,cachejfv c5 s ฺ
h a
3 where c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and
c5.c='b'; ฺ a r) uide
ฺ c om ent G
COUNT(*)
---------- a on tud
1 l l e@ is S
i
ฺz se th
l o
a r ce to u
Elapsed: 00:00:01.64
SQL>
l e (m ense
Zi l
4) Determine licexecution plan of the previous query by using the
the
l o
e explain_query1.sql script. What do you observe? Because of the
rc
Ma result_cache hint, the result of the query is computed using the result cache.
SQL> @explain_query1
SQL> set echo on
SQL>
SQL> explain plan for select /*+ result_cache q_name(Q1) */
count(*) from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv
c4,cachejfv c5 where c1.c='b' and c2.c='b' and c3.c='b' and
c4.c='b' and c5.c='b';

Explained.

Elapsed: 00:00:00.20
SQL>
SQL> set linesize 180
SQL>
SQL> @/u01/app/oracle/acfsmounts/acfs_db1/rdbms/admin/utlxpls
SQL> Rem
SQL> Rem $Header: utlxpls.sql 26-feb-2002.19:49:37 bdagevil

Oracle Database 11g: New Features for Administrators A - 320


Practice 17-1: Using Result Cache (continued)
..
SQL> Rem
SQL> select plan_table_output from
table(dbms_xplan.display('plan_table',null,'serial'));

PLAN_TABLE_OUTPUT
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

--------------------------------------------------------------
Plan hash value: 2522916280

--------------------------------------------------------------
| Id | Operation | Name
| Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------
------------------------------------------
| 0 | SELECT STATEMENT |
ble
| 1 | 1260 | 2295G (1)|999:59:59 |
fe r a
| 1 | RESULT CACHE | c334km80wg4dq0418y5p1frmnz
ans
|
| 2 |
| |
SORT AGGREGATE
|
|
|
n - t r
| 1 | 1260 | | | a no
| 3 | MERGE JOIN CARTESIAN |
h a s ฺ
|
|
92G|
4 |
105T| 2295G (1)|999:59:59 |
MERGE JOIN CARTESIAN | ฺ a r) uide
| 591M| 555G| 14G (1)|999:59:59 |
ฺ c om ent G
| 5 | MERGE JOIN CARTESIAN |
a on tud
| 3794K| 2735M|
l l e@ is S
94M (1)|314:36:35 |
i
ฺz se th
PLAN_TABLE_OUTPUT l o
rce to u
--------------------------------------------------------------
a
l e (m ense
--------------------------------------------------------
Z l
| i6 |
lic 11M|
MERGE JOIN CARTESIAN|
e l o| 24326 | 605K (1)| 02:01:03 |
rc |* 7 | TABLE ACCESS FULL | CACHEJFV
Ma | 156 | 39312 | 3856 (1)| 00:00:47 |
| 8 | BUFFER SORT |
| 156 | 39312 | 601K (1)| 02:00:17 |
|* 9 | TABLE ACCESS FULL | CACHEJFV
| 156 | 39312 | 3855 (1)| 00:00:47 |
| 10 | BUFFER SORT |
| 156 | 39312 | 94M (1)|314:35:49 |
|* 11 | TABLE ACCESS FULL | CACHEJFV
| 156 | 39312 | 3855 (1)| 00:00:47 |
| 12 | BUFFER SORT |
| 156 | 39312 | 14G (1)|999:59:59 |
|* 13 | TABLE ACCESS FULL | CACHEJFV
| 156 | 39312 | 3855 (1)| 00:00:47 |
| 14 | BUFFER SORT |
| 156 | 39312 | 2295G (1)|999:59:59 |
|* 15 | TABLE ACCESS FULL | CACHEJFV
| 156 | 39312 | 3855 (1)| 00:00:47 |
--------------------------------------------------------------

Oracle Database 11g: New Features for Administrators A - 321


Practice 17-1: Using Result Cache (continued)
PLAN_TABLE_OUTPUT
--------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------

7 - filter("C1"."C"='b')
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

9 - filter("C2"."C"='b')
11 - filter("C3"."C"='b')
13 - filter("C4"."C"='b')
15 - filter("C5"."C"='b')

Result Cache Information (identified by operation id):

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
ble
---------------------------------------------------------
fe r a
1 - column-count=1; dependencies=(QRC.CACHEJFV);
ans
attributes=(single-row); parameters=(nls); name="select /*+
n - t r
c2,cac a no
result_cache q_name(Q1) */ count(*) from cachejfv c1,cachejfv

hejfv c3,cachejfv c4,cachejfv c5 where c1.c='b' a" h a s ฺ


ฺ a r) uide
Note ฺ c om ent G
----- a on tud
- dynamic sampling le used S statement (level=2)
@ foristhis
i l h
40 rows selected. e l oฺz use t
a rc to
Elapsed:
m
( 00:00:00.63
ns e
i l l e c e
l o Z
SQL> li
e
rc 5) Determine the current content of the query cache by using the
Ma check_result_cache.sql script. What do you observe? You can now see the
result of your query cached.
SQL> @check_result_cache
SQL> set echo on
SQL>
SQL> select type,status,name,object_no,row_count,row_size_avg
from v$result_cache_objects order by 1;

TYPE STATUS NAME


OBJECT_NO ROW_COUNT
---------- --------- -----------------------------------------
--------------------------------------------------------------
------------------------- ---------- ----------
ROW_SIZE_AVG
------------
Dependency Published QRC.CACHEJFV
76960 0
0

Oracle Database 11g: New Features for Administrators A - 322


Practice 17-1: Using Result Cache (continued)

Result Published select /*+ result_cache q_name(Q1) */


count(*)
0 1
from cachejfv c1,cachejfv c2,cachejfv
c3,cachejfv c4,cachejfv c5
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

where c1.c='b' a
5

Elapsed: 00:00:00.00
SQL>
6) Flush the buffer cache of your instance and rerun the query executed at step 3. What
do you observe? The execution time for the query is now almost instantaneous. e
r a bl
SQL> alter system flush buffer_cache;
s fe
System altered. - t r an
n o n
Elapsed: 00:00:00.01 a
s ฺ
SQL> @query1 h a
SQL> select /*+ result_cache q_name(Q1) ฺ a u ide
r)*/ count(*)
2 from cachejfv c1,cachejfv c2,cachejfv
ฺ c om ent Gc3,cachejfv
c4,cachejfv c5
3 where c1.c='b' and c2.c='b' a on and tudc3.c='b' and c4.c='b' and
c5.c='b'; @
le this S
z i l
COUNT(*)
---------- rce
loฺ use
m1a e to
i l l e ( icens
l Z
oElapsed: l
00:00:00.00
e SQL>
Marc7) Insert a new row into the CACHEJFV table using the following statement: insert
into cachejfv values('c');. What do you observe? The corresponding
result cache entry is automatically invalidated.
SQL> insert into cachejfv values('c');

1 row created.

Elapsed: 00:00:00.00
SQL> commit;

Commit complete.

Elapsed: 00:00:00.01
SQL> @check_result_cache
SQL> set echo on
SQL>

Oracle Database 11g: New Features for Administrators A - 323


Practice 17-1: Using Result Cache (continued)
SQL> select type,status,name,object_no,row_count,row_size_avg
from v$result_cache_objects order by 1;

TYPE STATUS NAME


OBJECT_NO ROW_COUNT
---------- --------- -----------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

--------------------------------------------------------------
------------------------- ---------- ----------
ROW_SIZE_AVG
------------
Dependency Published QRC.CACHEJFV
76960 0
0

Result Invalid select /*+ result_cache q_name(Q1) */


ble
count(*)
fe r a
0 1
an s
from cachejfv c1,cachejfv c2,cachejfv
c3,cachejfv c4,cachejfv c5 n - t r
where c1.c='b' a a no
5
h a s ฺ
ฺ a r) uide
Elapsed: 00:00:00.00 ฺ c om ent G
SQL> a on tud
l l e @ istheSresult cache. What do you observe?
8) Execute your first query again i and check
ฺzto execute th query. Looking at the result cache shows that
l
Again, it takes some timeo s e the
a new entry hasa ce addedtoforuthe
rbeen new result.
( m
@query1ens
SQL>lle
e
i
Z select
SQL> lic/*+ result_cache q_name(Q1) */ count(*)
l o
e 2 from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv
rc
Ma c4,cachejfv c5
3 where c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and
c5.c='b';

COUNT(*)
----------
1

Elapsed: 00:00:01.36
SQL>
SQL> @check_result_cache
SQL> set echo on
SQL>
SQL> select type,status,name,object_no,row_count,row_size_avg
from v$result_cache_objects order by 1;

TYPE STATUS NAME


OBJECT_NO ROW_COUNT

Oracle Database 11g: New Features for Administrators A - 324


Practice 17-1: Using Result Cache (continued)
---------- --------- -----------------------------------------
--------------------------------------------------------------
------------------------- ---------- ----------
ROW_SIZE_AVG
------------
Dependency Published QRC.CACHEJFV
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

76960 0
0

Result Invalid select /*+ result_cache q_name(Q1) */


count(*)
0 1
from cachejfv c1,cachejfv c2,cachejfv
c3,cachejfv c4,cachejfv c5
where c1.c='b' a
ble
5
fe r a
ans
Result
count(*)
Published select /*+ result_cache q_name(Q1) */
n - t r
0 1 a no
h a s ฺ
TYPE STATUS
OBJECT_NO ROW_COUNT
NAME
ฺ a r) uide
c om ent G
---------- --------- -----------------------------------------

on tud
--------------------------------------------------------------
a
-------------------------
l e@----------
i s S ----------
ROW_SIZE_AVG i l
ฺz se t h
------------ elo
rc t o u
from cachejfv c1,cachejfv c2,cachejfv
a
l e n se
(m ec4,cachejfv
c3,cachejfv c5
Zi l lic5 where c1.c='b' a
e l o
rc
Ma
Elapsed: 00:00:00.01
SQL>
9) Generate a detailed result cache memory report.
SQL> set serveroutput on
SQL> EXEC DBMS_RESULT_CACHE.MEMORY_REPORT(detailed=>true);
R e s u l t C a c h e M e m o r y R e p o r t
[Parameters]
Block Size = 1K bytes
Maximum Cache Size = 2080K bytes (2080 blocks)
Maximum Result Size = 104K bytes (104 blocks)
[Memory]
Total Memory = 107836 bytes [0.041% of the Shared Pool]
... Fixed Memory = 9440 bytes [0.004% of the Shared Pool]
....... Memory Mgr = 124 bytes
....... Bloom Fltr = 2K bytes
....... Cache Mgr = 4416 bytes

Oracle Database 11g: New Features for Administrators A - 325


Practice 17-1: Using Result Cache (continued)
....... State Objs = 2852 bytes
... Dynamic Memory = 98396 bytes [0.038% of the Shared Pool]
....... Overhead = 65628 bytes
........... Hash Table = 32K bytes (4K buckets)
........... Chunk Ptrs = 12K bytes (3K slots)
........... Chunk Maps = 12K bytes
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

........... Miscellaneous = 8284 bytes


....... Cache Memory = 32K bytes (32 blocks)
........... Unused Memory = 29 blocks
........... Used Memory = 3 blocks
............... Dependencies = 1 blocks (1 count)
............... Results = 2 blocks
................... SQL = 1 blocks (1 count)
................... Invalid = 1 blocks (1 count)
ble
PL/SQL procedure successfully completed.
fe r a
ans
Elapsed: 00:00:00.33
SQL> n - t r
a no
h a s uses
10) Execute your query again. What do you observe? The query again

the result that
was previously cached.
ฺ a r) uide
SQL> @query1
ฺ c om en*/t Gcount(*)
2 from cachejfv c1,cachejfv a on c2,cachejfv
SQL> select /*+ result_cache q_name(Q1)
tud c3,cachejfv
e @ s S
c4,cachejfv c5
3 where c1.c='b' ฺ z ll c2.c='b'
iand t hi and c3.c='b' and c4.c='b' and
elo o us e
c5.c='b';
a r c t
( m s e
Z ille licen
COUNT(*)
----------
lo
rce 1
Ma Elapsed: 00:00:00.01
SQL>
11) Make sure that you bypass the result cache before executing the next step.
SQL> exec DBMS_RESULT_CACHE.BYPASS(bypass_mode=>true);

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL>
12) Execute your query again. What do you observe? The query is again taking longer to
execute because it no longer uses the result cache.
SQL> @query1
SQL> select /*+ result_cache q_name(Q1) */ count(*)
2 from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv
c4,cachejfv c5

Oracle Database 11g: New Features for Administrators A - 326


Practice 17-1: Using Result Cache (continued)
3 where c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and
c5.c='b';

COUNT(*)
----------
1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Elapsed: 00:00:01.36
SQL>
13) Make sure that you no longer bypass the result cache and verify that your query is
using it again.
SQL> exec DBMS_RESULT_CACHE.BYPASS(bypass_mode=>false);

PL/SQL procedure successfully completed. ble


fe r a
Elapsed: 00:00:00.00
ans
SQL> @query1
n - t r
SQL> select /*+ result_cache q_name(Q1) */ count(*) o
an
2 from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv
s
c4,cachejfv c5
r ) ha deฺ
ฺa Gui
3 where c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and
m
c5.c='b';
n ฺ co ent
COUNT(*)
@ ao Stud
----------
z i l le this
1
c e loฺ use
Elapsed:m a r
00:00:00.01 to
SQL> le ( ns e
i l li c e
l oZ
14) Execute the following query by using the query2.sql script:
e
Marc select count(*) from cachejfv c1,cachejfv c2,cachejfv
c3,cachejfv c4,cachejfv c5
where c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and
c5.c='b';
What do you observe? Although the query is the same as the one used in step 3, it is not
recognized as cached because it does not contain the hint. So, its execution time is long
again.
SQL> @query2
SQL> select count(*)
2 from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv
c4,cachejfv c5
3 where c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and
c5.c='b';

COUNT(*)
----------
1

Oracle Database 11g: New Features for Administrators A - 327


Practice 17-1: Using Result Cache (continued)

Elapsed: 00:00:01.38
SQL>
15) How would you force the previous query to use the cached result without using hints?
Do it by using the force_query2.sql script and then verify that you successfully
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

used the cached result. Finally, undo your change.


SQL> @force_query2
SQL> set echo on
SQL>
SQL> show parameter result_cache_mode

NAME TYPE VALUE


------------------------------------ ----------- ------------
result_cache_mode string MANUAL ble
SQL> fe r a
SQL> select type,status,name,object_no,row_count,row_size_avg ans
from v$result_cache_objects order by 1; n - t r
a no
TYPE STATUS NAME
h a s ฺ
OBJECT_NO ROW_COUNT
ฺ a r) uide
---------- --------- -----------------------------------------
ฺ c om ent G
--------------------------------------------------------------
------------------------- ----------
ROW_SIZE_AVG a on tud----------
l l e@ is S
------------ i th
ฺz QRC.CACHEJFV
Dependency Published l o e
76960 0
a r ce to us
e ( m 0 nse
Z ill
Result l i e
cInvalid select /*+ result_cache q_name(Q1) */
el ocount(*)
Marc 0 1
from cachejfv c1,cachejfv c2,cachejfv
c3,cachejfv c4,cachejfv c5
where c1.c='b' a
5

Result Published select /*+ result_cache q_name(Q1) */


count(*)
0 1

TYPE STATUS NAME


OBJECT_NO ROW_COUNT
---------- --------- -----------------------------------------
--------------------------------------------------------------
------------------------- ---------- ----------
ROW_SIZE_AVG
------------
from cachejfv c1,cachejfv c2,cachejfv
c3,cachejfv c4,cachejfv c5

Oracle Database 11g: New Features for Administrators A - 328


Practice 17-1: Using Result Cache (continued)
where c1.c='b' a
5

Elapsed: 00:00:00.00
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> alter session set result_cache_mode=force;

Session altered.

Elapsed: 00:00:00.01
SQL>
SQL> explain plan for select count(*) from cachejfv
c1,cachejfv c2,cachejfv c3,cachejfv c4,cachejfv c5 where
c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and c5.c='b';
ble
fe r a
Explained.
ans
Elapsed: 00:00:00.03 n - t r
SQL> a no
a s ฺ
SQL> @/u01/app/oracle/acfsmounts/acfs_db1/rdbms/admin/utlxpls
h
..
SQL> Rem ฺ a r) uide
SQL> select plan_table_output from ฺ c om ent G
on tud
table(dbms_xplan.display('plan_table',null,'serial'));
a
PLAN_TABLE_OUTPUT zill
e@ this S
c e loฺ use
--------------------------------------------------------------
Plan hash value:
a r 2522916280
to
m e
i l l e ( icens
--------------------------------------------------------------
l o Z l
| Id | Operation | Name
rc e | Rows | Bytes | Cost (%CPU)| Time |
Ma --------------------------------------------------------------
------------------------------------------
| 0 | SELECT STATEMENT |
| 1 | 1260 | 2295G (1)|999:59:59 |
| 1 | RESULT CACHE | c334km80wg4dq0418y5p1frmnz
| | | | |
| 2 | SORT AGGREGATE |
| 1 | 1260 | | |
| 3 | MERGE JOIN CARTESIAN |
| 92G| 105T| 2295G (1)|999:59:59 |
| 4 | MERGE JOIN CARTESIAN |
| 591M| 555G| 14G (1)|999:59:59 |
| 5 | MERGE JOIN CARTESIAN |
| 3794K| 2735M| 94M (1)|314:36:35 |

PLAN_TABLE_OUTPUT
--------------------------------------------------------------
| 6 | MERGE JOIN CARTESIAN|
| 24326 | 11M| 605K (1)| 02:01:03 |

Oracle Database 11g: New Features for Administrators A - 329


Practice 17-1: Using Result Cache (continued)
|* 7 | TABLE ACCESS FULL | CACHEJFV
| 156 | 39312 | 3856 (1)| 00:00:47 |
| 8 | BUFFER SORT |
| 156 | 39312 | 601K (1)| 02:00:17 |
|* 9 | TABLE ACCESS FULL | CACHEJFV
| 156 | 39312 | 3855 (1)| 00:00:47 |
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

| 10 | BUFFER SORT |
| 156 | 39312 | 94M (1)|314:35:49 |
|* 11 | TABLE ACCESS FULL | CACHEJFV
| 156 | 39312 | 3855 (1)| 00:00:47 |
| 12 | BUFFER SORT |
| 156 | 39312 | 14G (1)|999:59:59 |
|* 13 | TABLE ACCESS FULL | CACHEJFV
| 156 | 39312 | 3855 (1)| 00:00:47 |
| 14 | BUFFER SORT |
ble
| 156 | 39312 | 2295G (1)|999:59:59 |
fe r a
|* 15 | TABLE ACCESS FULL | CACHEJFV
ans
| 156 | 39312 | 3855 (1)| 00:00:47 |
n
--------------------------------------------------------------- t r
a no
PLAN_TABLE_OUTPUT
h a s ฺ
ฺ a r) uide
--------------------------------------------------------------

Predicate Information (identified c m operation


oby n t G id):

on tude
---------------------------------------------------
a
@ is S
i l l e
l o ฺz se th
7 - filter("C1"."C"='b')
9 - filter("C2"."C"='b')
rce to u
11 - filter("C3"."C"='b')
a
l e (m ense
13 - filter("C4"."C"='b')
15l
i - filter("C5"."C"='b')
lic
el oZ
Marc Result Cache Information (identified by operation id):

PLAN_TABLE_OUTPUT
--------------------------------------------------------------

1 - column-count=1; dependencies=(QRC.CACHEJFV);
attributes=(single-row); parameters=(nls); name="select /*+
result_cache q_name(Q1) */ count(*) from cachejfv c1,cachejfv
c2,cac
hejfv c3,cachejfv c4,cachejfv c5 where c1.c='b' a"

Note
-----
- dynamic sampling used for this statement (level=2)

40 rows selected.

Oracle Database 11g: New Features for Administrators A - 330


Practice 17-1: Using Result Cache (continued)
Elapsed: 00:00:00.48
SQL>
SQL> select count(*) from cachejfv c1,cachejfv c2,cachejfv
c3,cachejfv c4,cachejfv c5 where c1.c='b' and c2.c='b' and
c3.c='b' and c4.c='b' and c5.c='b';
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

COUNT(*)
----------
1

Elapsed: 00:00:00.02
SQL>
SQL> select type,status,name,object_no,row_count,row_size_avg
from v$result_cache_objects order by 1;
ble
TYPE STATUS NAME
fe r a
OBJECT_NO ROW_COUNT
ans
---------- --------- -----------------------------------------
n
-------------------------------------------------------------- - t r
------------------------- ---------- ---------- a no
ROW_SIZE_AVG
h a s ฺ
------------
Dependency Published QRC.CACHEJFV ฺ a r) uide
76960 0 ฺ c om ent G
0 a on tud
Result Invalid zilselect is S
le@ th/*+ result_cache q_name(Q1) */
count(*) l o ฺ s e
0 1 a rce to u
l e (m ense from cachejfv c1,cachejfv c2,cachejfv
Zi l
c3,cachejfv
licc4,cachejfv c5
e l o where c1.c='b' a
rc 5
Ma
Result Published select /*+ result_cache q_name(Q1) */
count(*)
0 1

TYPE STATUS NAME


OBJECT_NO ROW_COUNT
---------- --------- -----------------------------------------
--------------------------------------------------------------
------------------------- ---------- ----------
ROW_SIZE_AVG
------------
from cachejfv c1,cachejfv c2,cachejfv
c3,cachejfv c4,cachejfv c5
where c1.c='b' a
5

Elapsed: 00:00:00.01

Oracle Database 11g: New Features for Administrators A - 331


Practice 17-1: Using Result Cache (continued)
SQL>
SQL> alter session set result_cache_mode=manual;

Session altered.

Elapsed: 00:00:00.00
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>

16) Clear the result cache. Query V$RESULT_CACHE_OBJECTS to verify the clear
operation.
SQL> exec dbms_result_cache.flush;

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00 ble


SQL> select type,status,name,object_no,row_count,row_size_avg fe r a
from v$result_cache_objects order by 1;
an s
n - t r
no rows selected
a no
Elapsed: 00:00:00.00 h a s ฺ
SQL> ฺ a r) uide
c m nt G
ocache

n udeby running the cre_func.sql
17) Create a PL/SQL function that uses the result
o
script.
@ a S t
SQL> @cre_func z ill e t hi s
SQL> create or ereplace

lo ufunctions e CACHEJFV_COUNT(v varchar2)
r c
2 returna number to
l e (m ense relies_on (cachejfv)
3 result_cache
l
Z45i iscnt linumber;
c
l o
rce 6 begin
Ma 7 select count(*) into cnt
8 from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv
c4,cachejfv c5
9 where c1.c=v and c2.c=v and c3.c=v and c4.c=v and
c5.c=v;
10
11 return cnt;
12 end;
13 /

Function created.

Elapsed: 00:00:01.26
SQL>

18) Determine what is in the result cache by querying V$RESULT_CACHE_OBJECTS.


SQL> select type,status,name,object_no,row_count,row_size_avg
from v$result_cache_objects order by 1;

Oracle Database 11g: New Features for Administrators A - 332


Practice 17-1: Using Result Cache (continued)

no rows selected

Elapsed: 00:00:00.00
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

19) Call the new function with ‘b’ as its argument. What do you observe? It takes again
a long time to execute because the result is not cached yet. After executing the
function, the function’s result for argument ‘b’ is cached.
SQL> select cachejfv_count('b') from dual;

CACHEJFV_COUNT('B')
-------------------
1
ble
Elapsed: 00:00:02.84 fe r a
SQL> select type,status,name,object_no,row_count,row_size_avg ans
from v$result_cache_objects order by 1; n - t r
a no
TYPE STATUS NAME
h a s ฺ
OBJECT_NO ROW_COUNT
ฺ a r) uide
---------- --------- -----------------------------------------
ฺ c om ent G
--------------------------------------------------------------
------------------------- ----------
a on tud----------
ROW_SIZE_AVG
l l e@ is S
------------ i th
ฺz QRC.CACHEJFV
Dependency Published l o s e
76960 0
a rce to u
l e (m 0ense
Zi l licPublished QRC.CACHEJFV_COUNT
el oDependency
Marc 76961 0
0

Result Published
"QRC"."CACHEJFV_COUNT"::8."CACHEJFV_COUNT"#8440831613f0f5d3 #1
0 1
4

Elapsed: 00:00:00.00
SQL>

20) Call the new function with ‘b’ as its argument again. What do you observe? This
time the function executes almost instantaneously.
SQL> select cachejfv_count('b') from dual;

CACHEJFV_COUNT('B')
-------------------
1

Oracle Database 11g: New Features for Administrators A - 333


Practice 17-1: Using Result Cache (continued)

Elapsed: 00:00:00.00
SQL>

21) Call the new function with ‘c’ as its argument again. What do you observe? Again it
takes a long time to execute the function because of the new value for the argument.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

After execution, the second result is cached.


SQL> select cachejfv_count('c') from dual;

CACHEJFV_COUNT('C')
-------------------
1

Elapsed: 00:00:01.11
SQL> select type,status,name,object_no,row_count,row_size_avg ble
from v$result_cache_objects order by 1; fe r a
ans
TYPE STATUS NAME n - t r
o
OBJECT_NO ROW_COUNT
s an
---------- --------- -----------------------------------------
r ) ha deฺ
--------------------------------------------------------------
ฺa Gui
------------------------- ---------- ----------
m
ROW_SIZE_AVG
n ฺ co ent
------------
Dependency Published QRC.CACHEJFV@ ao Stud
76960 0
z i l le this
0
c e loฺ use
a r toQRC.CACHEJFV_COUNT
Dependency m e
Published
76961
i l l e (0 icens
l o Z l0
rc e
Ma Result Published
"QRC"."CACHEJFV_COUNT"::8."CACHEJFV_COUNT"#8440831613f0f5d3 #1
0 1
4

TYPE STATUS NAME


OBJECT_NO ROW_COUNT
---------- --------- -----------------------------------------
--------------------------------------------------------------
------------------------- ---------- ----------
ROW_SIZE_AVG
------------
Result Published
"QRC"."CACHEJFV_COUNT"::8."CACHEJFV_COUNT"#8440831613f0f5d3 #1
0 1
4

Elapsed: 00:00:00.01

Oracle Database 11g: New Features for Administrators A - 334


Practice 17-1: Using Result Cache (continued)
SQL> select cachejfv_count('c') from dual;

CACHEJFV_COUNT('C')
-------------------
1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Elapsed: 00:00:00.00
SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$
ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 335


Practices for Lesson 18

The practices for this lesson include duplicating an active database and merging recovery
catalogs.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 336


Practice 18-1: Duplicating an Active Database
You are responsible for an active database that cannot be shut down. It is running in
ARCHIVELOG mode. Now you are requested to duplicate this database, for testing
purposes, onto another directory.
To simulate this environment, assume that your active database is orcl (which is stored
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

in ASM).
1) Before you start cloning your database, add the last two ASM disks to the DATA disk
group.
a) From a graphical terminal window, connected as the oracle user, set up your
environment to use the +ASM instance, and invoke ASMCA.
$ . oraenv
ORACLE_SID = [orcl] ? +ASM
ble
The Oracle base for
fe r a
ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid is
an s
/u01/app/oracle
n - t r
$
$ asmca a no
h a s ฺ
r) uthe
b) On the Configure ASM: Disk Groups subpage, right-click
ฺ a ideDATA disk group.
om ent G
c) From the menu that appears, select Addcdisks.

a n ud
oORCl:ASMDISK12
d) On the Add Disks page, select both
@ S t and
ORCL:ASMDISK13. ill
z e t hi s
ฺ e
e) Click OK.
r c elo o us
f) On the(m a
information e t
window that appears, click OK.
s
en ASM: Disk Groups subpage, click Exit.
ille to the
g)ZBack l i cConfigure
rcelo h) On the ASM Configuration Assistant window, click Yes.
Ma 2) Wait until the rebalance operation is finished:
a) Log in to Enterprise Manager as the SYS user.
b) On the Home page, click the +ASM link in the General section.
c) On the ASM Home page, click the Disk Groups subtab.
d) You may have to log in to the ASM instance if not already done: On the
Automatic Storage Management Login page, enter SYS in the Username field,
oracle_4U in the Password field, and SYSASM in the Connect As field.
Select Save as Preferred Credential.
Click Login.
e) On the Disk Groups page, click the DATA link.
f) On the Disk Group: DATA page, look at the Pending Operations field in the
General section.
g) Refresh your browser page until there are no longer any pending operations.

Oracle Database 11g: New Features for Administrators A - 337


Practice 18-1: Duplicating an Active Database (continued)
3) To ensure that you are pointing to the orcl database and that this database is in
ARCHIVELOG mode with a 7 GB fast recovery area, execute the
rman_archivelog.sh script in the /home/oracle/solutions/RMAN
directory.
$ cd /home/oracle/solutions/RMAN
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

$ ./rman_archivelog.sh
*******************************************
For demo purposes ONLY:
* Enable ARCHIVELOG mode for database

The script may appear to hang at the SQL prompt


when the database is shutting down and being
opened. Wait a few minutes and it should progress.
*******************************************
ble
orcl
fe r a
ans
SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 8 09:27:02
n - t r
2009
a no
Copyright (c) 1982, 2009, Oracle. All rights
h a s reserved.

r ) i d e
Connected to: m ฺa Gu
Oracle Database 11g Enterprise ฺEdition c o e n t
Release 11.2.0.1.0 -
o n d
Production
@
With the Partitioning,eAutomatic
a SStorage tu Management, OLAP,
i l l t h i s
Data Mining and Real
e l oฺz Application
u s e Testing options

SQL> SQL> arc t o


l e (m ense
System altered.
Zi l lic
e l oSQL> SQL> Database closed.
rc Database dismounted.
Ma ORACLE instance shut down.
SQL> ORACLE instance started.

Total System Global Area 422670336 bytes


Fixed Size 1336960 bytes
Variable Size 314575232 bytes
Database Buffers 100663296 bytes
Redo Buffers 6094848 bytes
Database mounted.
SQL>
Database altered.

SQL>
Database altered.

SQL> Database log mode Archive Mode


Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 99

Oracle Database 11g: New Features for Administrators A - 338


Practice 18-1: Duplicating an Active Database (continued)
Next log sequence to archive 101
Current log sequence 101
SQL> Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

4) Set up dbtest as the net service name for your planned dbtest database.
a) In a graphical terminal window as the oracle user, set up your environment to
point to your orcl instance and invoke NETCA.
$ . oraenv
ORACLE_SID = [+ASM] ? orcl
The Oracle base for ble
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
fe r a
/u01/app/oracle
ans
$ netca
n - t r
no
b) The Oracle Net Configuration Assistant (NETCA) opens a window. On the
a
a s ฺ
Welcome page, select “Local Net Service Name configuration,” and click Next.
h
c) On the Net Service Name Configuration page, ฺselect a ideclick Next.
r) Adduand
c m nt G
oand
d) In the Service Name field, enter dbtest ฺ
on tudclick e Next.
e) On the Net Service Name e
a
@ is SSelect Protocols page, select TCP and
Configuration,
i l l
click Next.
l o ฺz se th
a rce Name
f) On the Net Service
t o uConfiguration, TCP/IP Protocol page, enter your host
l e mexample,
name,(for
e n seedt3r10p10.us.oracle.com, select “Use the standard
l
i number
Zport lic of 1521,” and then click Next.
l o
e g) On the Net Service Name Configuration, Test page, select “No, do not test”
rc
Ma (because your dbtest database does not yet exist) and click Next.
h) On the Net Service Name Configuration, Net Service Name page, enter dbtest
as Net Service Name, and then click Next.
i) Click No in the answer to the question “Would you like to configure another net
service name?” and then click Next.
j) When you see the completion message, click Next again.
k) Finally, click Finish.
5) Use Oracle Net Manager to configure the LISTENER with the dbtest and orcl
database services.
a) In a graphical terminal window as the oracle user, set up your environment to
point to your +ASM instance and invoke NETMGR.
$ . oraenv
ORACLE_SID = [orcl] ? +ASM

Oracle Database 11g: New Features for Administrators A - 339


Practice 18-1: Duplicating an Active Database (continued)
The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid is
/u01/app/oracle
$ netmgr

b) The Oracle Net Manager opens a window. Click the “+” icon, right before the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

word “Local.” Then click the “+” icon, right before the word “Listeners” to
expand the nodes in the navigation tree until you see the listener, called
“LISTENER.”
c) First select LISTENER in the left part of the window. Then select Database
Services from the drop-down list at the right of the window.
d) Click the Add Database button.
e) Enter the following values:
ble
Global Database Name: dbtest
fe r a
Oracle Home Directory: /u01/app/oracle/acfsmounts/acfs_db1/
an s
SID: dbtest n - t r
f) Click the Add Database button again. a no
h a s ฺ
g) Enter the following values: r) uide
Global Database Name: orcl ฺ a
ฺ c om ent G
Oracle Home Directory: /u01/app/oracle/acfsmounts/acfs_db1/
SID: orcl a on tud
l e@menuibar,
s S
i
h) From the Oracle Net Manager l
ฺz > Exit. t h select File > Save Network
l o e
a r ce to us
Configuration, then File
6) Clone a database
m bynsusing e RMAN. Start the duplication process in Enterprise
e (
Z ill
Manager.
l i ce
rc eloa) Log in to Enterprise Manager as the SYS user with the oracle_4U password
Ma and connect as SYSDBA.
b) First click the Data Movement tab, and then click Clone Database in the Move
Database Files section.
c) On the Clone Database: Source Type page, select “A running database” and “Use
Recovery Manager (RMAN) to copy database files,” and then click Continue.
d) On the Clone Database: Source Options page, enter oracle as the username and
password, click “Save as Preferred Credential,” and then click Next.
e) On the Clone Database: Select Destination page, enter dbtest both as Global
Database Name and as Instance Name, and select Automatic Storage
Management (ASM) from the Database Storage drop down list. Then click Next.
f) If the Clone Database: ASM Instance Login page appears, enter oracle_4U as
the SYS password, and click Login.
g) On the Clone Database: Destination Options page, enter FRA in the Flash
Recovery Area field. Then click Next.

Oracle Database 11g: New Features for Administrators A - 340


Practice 18-1: Duplicating an Active Database (continued)
h) On the Clone Database: Database Configuration page:
• Select “Configure Enterprise Manager Database Control for this database.”
• Make sure that
/u01/app/oracle/acfsmounts/acfs_db1/network/admin is
entered in the Configuration File Location field.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• Enter /u01/app/oracle/product/11.2.0/grid in the Listener


Oracle Home field.
• Enter oracle_4U six times in all password fields, and enter 5505 as HTTP
port.
• Click Next.
i) If you receive a warning that the sqlnet.ora file or the listener.ora file
ble
does not exist, accept the warning by clicking Yes.
fe r a
j) On the Clone Database: Schedule page, ensure that the job starts immediately. an s
n - t r
Click Next.
a no
k) On the Clone Database: Review page, review the Details,sincluding the Database
Storage and click Submit Job.
r ) ha deฺ
ฺa page i
ufor
c m
l) Wait on the “Clone Database job is beingosubmitted”
n t G a while.
m) The Clone Database: Confirmationopage

n should dedisplay a success message. Click
the View Status to transfereto@
a
the Job s
t u
S page.
Activity
z i l l h i
t Occasionally, click your browser’s reload
e oฺExecution
n) This takes you to lthe
u s e page.
a rc the job
button, to display
t o progress until you receive a success message. (The

l e (mtime
execution
e n seyour job depends on your hardware and available system
for
Zi l
resources.)
lic
l o
e7) Test the access to your cloned databases in SQL*Plus.
rc
Ma a) Connected as the oracle user in a graphical terminal session, ensure that you are
pointing to the orcl database.
$ . oraenv
ORACLE_SID = [db10g] ? orcl
$

b) Connect as the SYS user to your orcl database and execute the following query:
select dbid, name, created, open_mode
from v$database;
$ sqlplus sys/oracle_4U@orcl as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 8 10:49:40


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:

Oracle Database 11g: New Features for Administrators A - 341


Practice 18-1: Duplicating an Active Database (continued)
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> select dbid, name, created, open_mode from v$database;


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

DBID NAME CREATED OPEN_MODE


---------- --------- --------- --------------------
1226549444 ORCL 28-SEP-09 READ WRITE

SQL>

c) Now connect as the SYSTEM user with the oracle_4U password to your dbtest
database and execute the preceding query. Exit from SQL*Plus. e
r a bl
SQL> connect system/oracle_4U@dbtest
s fe
Connected.
SQL> select dbid, name, created, open_mode from v$database; - t r an
n o n
DBID NAME CREATED OPEN_MODE a
s ฺ
---------- --------- --------- --------------------h a
1092566820 DBTEST ฺ a
08-OCT-09 READ WRITE r) uide
ฺ c om ent G
SQL> exit
Disconnected from Oracle Databasea on t11g ud Enterprise Edition
@
le this
Release 11.2.0.1.0 -ilProduction
S
z
oฺ Application
With the Partitioning,
Data Mining rand c elReal u se
Automatic Storage Management, OLAP,
Testing options
a t o
$
l e (m ense
Zi l lic
e l o
rc
Ma

Oracle Database 11g: New Features for Administrators A - 342


Practice 18-2: Managing Catalogs
In this practice, you consolidate multiple RMAN catalogs in one database.
1) To prepare this scenario, create a catalog in the orcl instance and in the dbtest
instance by executing the setup_cat.sh script in your working directory
(/home/oracle/solutions/RMAN).
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

$ cd /home/oracle/solutions/RMAN
$
$ ./setup_cat.sh
*******************************************
For training purposes ONLY, not for production use
* Setup RMAN catalogs in ORCL and DBTEST instances
Execute as oracle OS user orcl
ble
SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 8 11:20:59
fe r a
2009
an s
- t r
Copyright (c) 1982, 2009, Oracle. All rights reserved.
n on
s a
Connected to:
Oracle Database 11g Enterprise Edition rRelease ) a
h d11.2.0.1.0
e ฺ -
Production ฺ a u i
With the Partitioning, Automatic c m ntManagement,
oStorage G OLAP,
Data Mining and Real Application o n ฺ d e
Testing options
@ a Stu
SQL> set serveroutput z i l e
l on this
SQL> set term on
c e loฺ use
SQL> set lines
a r 200 to
SQL>
l e ( ense
m
SQL>l
Zi /*== liConfirm
c database connection ==*/
e l oSQL> SELECT NAME FROM V$DATABASE;
rc
Ma NAME
---------
ORCL

SQL>
SQL> /*== Create RCAT tablespace of 10 MB ==*/
SQL> DROP TABLESPACE RCAT including contents and datafiles;
DROP TABLESPACE RCAT including contents and datafiles
*
ERROR at line 1:
ORA-00959: tablespace 'RCAT' does not exist

SQL>
SQL> CREATE TABLESPACE RCAT
2 DATAFILE '+DATA' SIZE 10M;

Tablespace created.

SQL>

Oracle Database 11g: New Features for Administrators A - 343


Practice 18-2: Managing Catalogs (continued)
SQL> /*== Create CATOWNER user with "oracle" password ==*/
SQL> DROP USER catowner CASCADE;
DROP USER catowner CASCADE
*
ERROR at line 1:
ORA-01918: user 'CATOWNER' does not exist
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> create user catowner identified by oracle_4U
2 default tablespace rcat
3 quota unlimited on rcat;

User created.

SQL>
ble
SQL> /*== Grant privileges to CATOWNER ==*/
fe r a
SQL> GRANT CREATE SESSION to catowner;
ans
Grant succeeded. n - t r
a no
SQL>
h a s ฺ
SQL> GRANT RECOVERY_CATALOG_OWNER to catowner;
ฺ a r) uide
Grant succeeded. ฺ c om ent G
a on tud
S with "oracle_4U" password
le@ thisuser
SQL> PROMPT "Setup of CATOWNER
l
and RCAT tablespacezicomplete."
"Setup of CATOWNER
c e loฺ useruswith
e "oracle_4U" password and RCAT
r
tablespace acomplete." to
m e
SQL> exit
i l l e ( icefrom
Disconnected
ns Oracle Database 11g Enterprise Edition
l o Z l
Release 11.2.0.1.0 - Production
rc e With the Partitioning, Automatic Storage Management, OLAP,
Ma Data Mining and Real Application Testing options

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Oct 8


11:21:14 2009

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All


rights reserved.

connected to target database: ORCL (DBID=1226549444)


connected to recovery catalog database

RMAN>
RMAN> CREATE CATALOG TABLESPACE RCAT;
2>
3> REGISTER DATABASE;
4>
5> exit;
recovery catalog created

Oracle Database 11g: New Features for Administrators A - 344


Practice 18-2: Managing Catalogs (continued)
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

Recovery Manager complete.


dbtest
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 8 11:22:28


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
ble
With the Partitioning, Automatic Storage Management, OLAP,
fe r a
Data Mining and Real Application Testing options
ans
SQL> set serveroutput on n - t r
SQL> set term on a no
SQL> set lines 200
h a s ฺ
SQL>
SQL> /*== Confirm database connection ฺ a r) uide
==*/
SQL> SELECT NAME FROM V$DATABASE; ฺ c om ent G
a on tud
NAME
l l e@ is S
--------- i
ฺz se th
DBTEST l o
a rce to u
SQL>
l e (m ense
SQL>l
Zi /*== liCreate
c RCAT tablespace of 10 MB ==*/
e l oSQL> DROP TABLESPACE RCAT including contents and datafiles;
rc DROP TABLESPACE RCAT including contents and datafiles
Ma *
ERROR at line 1:
ORA-00959: tablespace 'RCAT' does not exist

SQL>
SQL> CREATE TABLESPACE RCAT
2 DATAFILE '+DATA' SIZE 10M;

Tablespace created.

SQL>
SQL> /*== Create CATOWNER user with "oracle_4U" password ==*/
SQL> DROP USER catowner CASCADE;
DROP USER catowner CASCADE
*
ERROR at line 1:
ORA-01918: user 'CATOWNER' does not exist

SQL>

Oracle Database 11g: New Features for Administrators A - 345


Practice 18-2: Managing Catalogs (continued)
SQL> create user catowner identified by oracle_4U
2 default tablespace rcat
3 quota unlimited on rcat;

User created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> /*== Grant privileges to CATOWNER ==*/
SQL> GRANT CREATE SESSION to catowner;

Grant succeeded.

SQL>
SQL> GRANT RECOVERY_CATALOG_OWNER to catowner;
ble
Grant succeeded.
fe r a
ans
SQL> PROMPT "Setup for RMAN catalog in DBTEST complete."
"Setup for RMAN catalog in DBTEST complete." n - t r
SQL> exit a no
a s ฺ
Disconnected from Oracle Database 11g Enterprise Edition
h
Release 11.2.0.1.0 - Production
ฺ a r) uide
With the Partitioning, Automatic Storage Management, OLAP,
c om ent G
Data Mining and Real Application Testing options

a on tud
Recovery Manager: Release
l e i s S - Production on Thu
@11.2.0.1.0 Oct 8
i l h
oฺz use t
11:22:35 2009
e l
Copyright (c)a rc1982,to2009, Oracle and/or its affiliates. All

l e (m ense
rights reserved.
Zi l lic
e l oconnected to target database: DBTEST (DBID=1092566820)
rc connected to recovery catalog database
Ma
RMAN>
RMAN> CREATE CATALOG TABLESPACE RCAT;
2>
3> REGISTER DATABASE;
4>
5> exit;
recovery catalog created

database registered in recovery catalog


starting full resync of recovery catalog
full resync complete

Recovery Manager complete.


$

2) Back up the EXAMPLE tablespace from the orcl database and log it in the RMAN
catalog.

Oracle Database 11g: New Features for Administrators A - 346


Practice 18-2: Managing Catalogs (continued)
a) Ensure that you are pointing to the orcl database.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

/u01/app/oracle
$

b) Back up the EXAMPLE tablespace from the orcl database, using RMAN and the
RMAN catalog. Execute the following commands:
rman target sys/oracle_4U catalog catowner/oracle_4U
backup tablespace example;
exit
$ rman target sys/oracle_4U catalog catowner/oracle_4U
ble
fe r a
Recovery Manager: Release 11.2.0.1.0 - Production on Thu Oct 8
ans
11:34:05 2009
n - t r
Copyright (c) 1982, 2009, Oracle and/or its affiliates. a no All
rights reserved. h a s ฺ
connected to target database: ORCL m u ide
ฺar) 1226549444)
connected to recovery catalog database ฺ c o ent G
(DBID=

a on tud
RMAN> backup tablespace
l e@ example;
i s S
i l t h
Starting backup e l oฺz08-OCT-09
at u s e
a rc
allocated channel: t o
ORA_DISK_1
channel(m
l e e n se SID=53 device type=DISK
ORA_DISK_1:
l
Zi ORA_DISK_1:
channel lic starting full datafile backup set
e l ochannel ORA_DISK_1: specifying datafile(s) in backup set
rc input datafile file number=00005
Ma name=+DATA/orcl/datafile/example.265.698768805
channel ORA_DISK_1: starting piece 1 at 08-OCT-09
channel ORA_DISK_1: finished piece 1 at 08-OCT-09
piece
handle=+FRA/orcl/backupset/2009_10_08/nnndf0_tag20091008t11350
4_0.287.699708907 tag=TAG20091008T113504 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time:
00:00:16
Finished backup at 08-OCT-09

RMAN> exit

Recovery Manager complete.


$

3) Back up the EXAMPLE tablespace from the dbtest database.


a) Ensure that you are pointing to the dbtest database.

Oracle Database 11g: New Features for Administrators A - 347


Practice 18-2: Managing Catalogs (continued)
$ . oraenv
ORACLE_SID = [orcl] ? dbtest
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle
$
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

b) Back up the EXAMPLE tablespace from the dbtest database, using RMAN and
the RMAN catalog. Execute the following commands:
rman target sys/oracle_4U@dbtest catalog
catowner/oracle_4U@dbtest
backup tablespace example;
exit
$ rman target sys/oracle_4U@dbtest catalog e
catowner/oracle_4U@dbtest r a bl
s fe
Recovery Manager: Release 11.2.0.1.0 - Production on Thu Oct 8
- t r an
11:37:19 2009 nno
Copyright (c) 1982, 2009, Oracle and/or itsaaffiliates.
a
s ฺ All
rights reserved. h
r) uide
ฺ a
connected to target database: DBTEST ฺ c om (DBID=1092566820)
n t G
connected to recovery catalog
a ondatabase
t u de
l l e@ is S
RMAN> backup tablespace i
ฺz sexample;th
l o e
Starting backupa rce at t08-OCT-09
o u
allocated
l e (mchannel:
e n se ORA_DISK_1
Z i l
channel ORA_DISK_1:
l i c SID=54 device type=DISK

rc elochannel ORA_DISK_1: starting full datafile backup set


channel ORA_DISK_1: specifying datafile(s) in backup set
Ma input datafile file number=00005
name=+DATA/dbtest/datafile/example.274.699703705
channel ORA_DISK_1: starting piece 1 at 08-OCT-09
channel ORA_DISK_1: finished piece 1 at 08-OCT-09
piece
handle=+FRA/dbtest/backupset/2009_10_08/nnndf0_tag20091008t113
801_0.288.699709083 tag=TAG20091008T113801 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time:
00:00:15
Finished backup at 08-OCT-09

RMAN> exit

Recovery Manager complete.


$

4) Merge the dbtest catalog into the orcl database catalog.

Oracle Database 11g: New Features for Administrators A - 348


Practice 18-2: Managing Catalogs (continued)
a) Ensure that you are pointing to the orcl database.
$ . oraenv
ORACLE_SID = [dbtest] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

/u01/app/oracle
$
b) Execute the following commands:
rman catalog catowner/oracle_4U
IMPORT CATALOG catowner/oracle_4U@dbtest;
$ rman catalog catowner/oracle_4U

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Oct 8


ble
11:39:36 2009
fe r a
Copyright (c) 1982, 2009, Oracle and/or its affiliates. t r a ns
All
rights reserved.
no n-
a
s ฺ
connected to recovery catalog database h a
ฺ a r) uide
RMAN> IMPORT CATALOG catowner/oracle_4U@dbtest;
ฺ c om ent G
Starting import catalog ata08-OCT-09 on tud
connected to source recovery l e@ catalogi s S database
i l h
e
database unregisteredl o z ufrom
import validation ฺcomplete
s e tthe source recovery catalog
Finished importa rc catalog
to at 08-OCT-09
m e
i
RMAN>l l e ( icens
l o Z l
e
rc 5) Report on the dbtest backups from the orcl catalog. Determine which databases
Ma are registered in the orcl RMAN repository. List the backups that are recorded for
the dbtest database.
a) From the RMAN prompt, list the incarnations that are registered in the orcl
repository.
RMAN> LIST INCARNATION;

List of Database Incarnations


DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time
------ ------- ------- ----------- ------ --------- ----------
167 189 DBTEST 1092566820 PARENT 754488 28-SEP-09
167 169 DBTEST 1092566820 CURRENT 2678383 08-OCT-09
2 23 ORCL 1226549444 PARENT 1 13-AUG-09
2 4 ORCL 1226549444 CURRENT 754488 28-SEP-09
RMAN>

Oracle Database 11g: New Features for Administrators A - 349


Practice 18-2: Managing Catalogs (continued)
b) From the RMAN prompt, list the recorded backups of the dbtest database. Then
exit RMAN.
RMAN> connect target sys/oracle_4U@dbtest

connected to target database: DBTEST (DBID= 1092566820)


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

RMAN> list backup;

List of Backup Sets


===================

BS Key Type LV Size Device Type Elapsed Time Completion


Time ble
------- ---- -- ---------- ----------- ------------ ---------- fe r a
----- ans
234 Full 69.57M DISK 00:00:08 08-OCT-09 n - t r
o
BP Key: 236
TAG20091008T113801 an
Status: AVAILABLE Compressed: NO Tag:
s
Piece Name:
r ) ha deฺ
ฺa Gui
+FRA/dbtest/backupset/2009_10_08/nnndf0_tag20091008t113801_0.2
m
88.699709083
n ฺ co ent
ao Stud
List of Datafiles in backup set 234
File LV Type Ckp SCN Ckp Time Name
@
i l le this
---- -- ---- ------- --------- ----
z
5 loฺ use
Full 2834274 08-OCT-09
c e
a r
+DATA/dbtest/datafile/example.274.699703705
to
m
( ens e
RMAN>
i l l eexit
l o Z lic
rc e Recovery Manager complete.
Ma $

6) Execute the cleanup_rcat.sh script to shut down the dbtest instance, remove
OS files, and disable ARCHIVELOG mode for the orcl database.
$ ./cleanup_rcat.sh
For training purposes ONLY, not for production use
Shutdown DBTEST database and delete recovery files
Execute as oracle OS user
dbtest
Oracle Enterprise Manager 11g Database Control Release
11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation. All rights
reserved.
https://ed.us.oracle.com:5505/em/console/aboutApplication
Stopping Oracle Enterprise Manager 11g Database Control ...
... Stopped.

Oracle Database 11g: New Features for Administrators A - 350


Practice 18-2: Managing Catalogs (continued)
SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 8 11:48:21
2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -


Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining
and Real Application Testing options

SQL> Database closed.


Database dismounted.
ORACLE instance shut down.
ble
SQL> Disconnected from Oracle Database 11g Enterprise Edition
fe r a
Release 11.2.0.1.0 - Production
ans
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options n - t r
orcl a no
h a s ฺ
SQL*Plus: Release 11.2.0.1.0 Productionr)on Thu d
a e 8 11:48:40
i Oct
2009 ฺ u
ฺ c om ent G
Copyright (c) 1982, 2009, a on tuAll
Oracle. d rights reserved.
@
le this S
Connected to: z i l
Oracle Database e oฺ Enterprise
l11g u se Edition Release 11.2.0.1.0 -
Production ar c o
t Automatic Storage Management, OLAP,
With the ( m s
Partitioning,e
n Real Application Testing options
Z illeMining
Data
l i ceand
rc elo SQL> SQL>
Ma User dropped.

SQL>
Tablespace dropped.

SQL> SQL>
System altered.

SQL> SQL> Database closed.


Database dismounted.
ORACLE instance shut down.
SQL> ORACLE instance started.

Total System Global Area 422670336 bytes


Fixed Size 1336960 bytes
Variable Size 318769536 bytes
Database Buffers 96468992 bytes
Redo Buffers 6094848 bytes
Database mounted.

Oracle Database 11g: New Features for Administrators A - 351


Practice 18-2: Managing Catalogs (continued)
SQL>
Database altered.

SQL>
Database altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> Database log mode No Archive Mode


Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 102
Current log sequence 104
SQL> SQL> "Cleanup finished."
SQL> Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
ble
Data Mining and Real Application Testing options
fe r a
$
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 352


Practices for Lesson 19

In this practice, you will use Flashback Data Archive and Flashback Transaction
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

functionality. While working with flashback data archives, you will perform tasks in
three different roles:
• As the SYS user with SYSDBA privileges, you work with tablespaces, users,
privileges, and undo.
• As the ARCHIVE_ADMIN user, you create and maintain flashback data archives
(within given tablespaces) and grant the FLASHBACK ARCHIVE object privilege
to the HR user.
• As the HR user, you enable history tracking for the HR.EMPLOYEES table, create ble
transactions, and after the undo tablespace has been switched (to prove that youfe r a
ans
retrieve information from the flashback data archives, not from the undo), you
n - t r
execute a query into the past, and use a row from the flashback data archive to
o
update a current “erroneous” row.
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 353


Practice 19-1: Using Flashback Data Archive
In this practice, you use Flashback Data Archive.
1) Ensure that you are pointing to the orcl database. Using SQL*Plus, connect to the
database as the SYS user and execute the flada_setup.sql script from the
/home/oracle/solutions/FDA directory. The setup script creates a small
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

FLA_TBS1 tablespace, creates the ARCHIVE_ADMIN user with the ARCHIVE_ADMIN


password, and unlocks the HR user with the HR password. The password is case-
sensitive by default. The script also creates a table called HR.EMPLOYEES2 that is
used during this lab.
$ . oraenv
ORACLE_SID = [db10g] ? orcl
$ cd /home/oracle/solutions/FDA
$ sqlplus / as sysdba ble
fe r a
SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 9 07:21:07 ans
2009 n - t r
a no
Copyright (c) 1982, 2009, Oracle. All rightss reserved.
r ) ha deฺ
Connected to:
m ฺa Gui
Oracle Database 11g Enterprise Edition
n ฺ co eRelease
n t 11.2.0.1.0 -

tud Management, OLAP,


Production
With the Partitioning, Automatic @ ao SStorage
le this Testing options
Data Mining and RealilApplication
z
SQL> @flada_setup c e loฺ use
a r to
Connected. m e
SQL>
i l l eset( serveroutput
i c e ns on
Z
SQL> -- l
set verify on
rc eloSQL> set term on
Ma SQL> set lines 200
SQL> set pages 44
SQL> set pause on
SQL>
SQL> /*== Create a tablespace for your flashback data archive
==*/
SQL> DROP TABLESPACE fla_tbs1 INCLUDING CONTENTS
2 /
DROP TABLESPACE fla_tbs1 INCLUDING CONTENTS
*
ERROR at line 1:
ORA-00959: tablespace 'FLA_TBS1' does not exist

SQL> CREATE SMALLFILE TABLESPACE fla_tbs1


2 DATAFILE '+DATA'
3 SIZE 10M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE 32767M
4 NOLOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE
MANAGEMENT AUTO
5 /

Oracle Database 11g: New Features for Administrators A - 354


Practice 19-1: Using Flashback Data Archive (continued)

Tablespace created.

SQL> pause Press [Enter] to continue...


Press [Enter] to continue...
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>
SQL> /*== Set up the HR database account for this lesson ==*/
SQL> /*== Note: The HR user has the UNLIMITED TABLESPACE
system privilege. ==*/
SQL>
SQL> ALTER USER hr IDENTIFIED BY "HR" ACCOUNT UNLOCK
2 /

User altered.
ble
fe r a
SQL> /*== Create an ARCHIVE_ADMIN user like the HR user ==*/
ans
SQL> /*==
SQL>
with FLA_TBS1 default tablespace ==*/
n - t r
o
SQL> CREATE USER ARCHIVE_ADMIN PROFILE DEFAULT IDENTIFIED BY
s an
ARCHIVE_ADMIN
r )
2 DEFAULT TABLESPACE FLA_TBS1 TEMPORARY TABLESPACE TEMPha deฺ
3 ACCOUNT UNLOCK m ฺa Gui
4 /
n ฺ co ent
User created. @ ao Stud
z i l le this
SQL> pause Press

lo[Enter] seto continue...
c e
r to continue... u
Press [Enter]
m a e to
i
SQL> l l e ( icens
l o Z l
SQL> GRANT ALTER SESSION TO ARCHIVE_ADMIN;
rc e
Ma Grant succeeded.

SQL> GRANT CREATE DATABASE LINK TO ARCHIVE_ADMIN;

Grant succeeded.

SQL> GRANT CREATE SEQUENCE TO ARCHIVE_ADMIN;

Grant succeeded.

SQL> GRANT CREATE SESSION TO ARCHIVE_ADMIN;

Grant succeeded.

SQL> GRANT CREATE SYNONYM TO ARCHIVE_ADMIN;

Grant succeeded.

SQL> GRANT CREATE VIEW TO ARCHIVE_ADMIN;

Oracle Database 11g: New Features for Administrators A - 355


Practice 19-1: Using Flashback Data Archive (continued)

Grant succeeded.

SQL> GRANT UNLIMITED TABLESPACE TO ARCHIVE_ADMIN;

Grant succeeded.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> GRANT EXECUTE ON SYS.DBMS_STATS TO ARCHIVE_ADMIN;

Grant succeeded.

SQL> GRANT CONNECT, RESOURCE TO ARCHIVE_ADMIN;

Grant succeeded.
ble
SQL>
fe r a
SQL> /*== copy employees table for demo purposes ==*/
ans
SQL>
SQL> connect hr/HR n - t r
Connected. a no
SQL>
h a s ฺ
SQL> drop table employees2 purge;
drop table employees2 purge ฺ a r) uide
* ฺ c om ent G
ERROR at line 1: a on tud
l l e@ is S
ORA-00942: table or view does not exist
i
ฺz se th
SQL> l o
ce employees2
SQL> createartable t o u as select * from employees;
m
( ens e
i l l ecreated.
l o
Table
Z lic
rc e SQL>
Ma SQL> CONNECT / AS SYSDBA
Connected.
SQL>
SQL> /*== Setup for Flashback Data Archive completed ==*/
SQL> /*== The ARCHIVE_ADMIN user has the password:
ARCHIVE_ADMIN ==*/
SQL> /*== The HR user has the password: HR ==*/
SQL>
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...

SQL>
SQL> set pause off
SQL> set feedback on
SQL>

Oracle Database 11g: New Features for Administrators A - 356


Practice 19-1: Using Flashback Data Archive (continued)
2) To give the ARCHIVE_ADMIN user administrative privileges for creating, maintaining,
and dropping flashback data archives, execute the following command as the SYS
user:
GRANT FLASHBACK ARCHIVE ADMINISTER TO archive_admin;
SQL> GRANT FLASHBACK ARCHIVE ADMINISTER TO archive_admin;
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Grant succeeded.

SQL>

3) In SQL*Plus, connect as the ARCHIVE_ADMIN user with the ARCHIVE_ADMIN


password.
Note: The password has to be in uppercase; the username is not case-sensitive.
SQL> connect archive_admin/ARCHIVE_ADMIN ble
Connected. fe r a
SQL> ans
n - t r
o
4) To create a flashback data archive, execute the create_fla1.sql script or
execute the following command: s an
CREATE FLASHBACK ARCHIVE fla1
r ) ha deฺ
TABLESPACE fla_tbs1
m ฺa Gui
QUOTA 10M
RETENTION 1 YEAR; n ฺ co ent
@ ao Stud
SQL> @create_fla1
SQL> set echo on ฺzi
lle this
SQL> DROP FLASHBACKc e u se fla1
lo ARCHIVE
2 / a r to
DROP e
m e
( ensARCHIVE fla1
FLASHBACK
*Z i l l l ic
l o
e ERROR at line 1:
rc
Ma ORA-55605: Incorrect Flashback Archive is specified

SQL> CREATE FLASHBACK ARCHIVE fla1


2 TABLESPACE fla_tbs1
3 QUOTA 10M
4 RETENTION 1 YEAR
5
SQL> /

Flashback archive created.

SQL>

5) Give the privilege to use the FLA1 archive to the HR user, by executing the following
command:
GRANT FLASHBACK ARCHIVE on FLA1 to HR;
SQL> GRANT FLASHBACK ARCHIVE on FLA1 to HR;

Oracle Database 11g: New Features for Administrators A - 357


Practice 19-1: Using Flashback Data Archive (continued)
Grant succeeded.

SQL>

6) Now, you switch to the role of a flashback archive user. Connect as the HR user with
the HR password. To enable this flashback data archive for the EMPLOYEES table,
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

execute the following command:


ALTER TABLE hr.employees FLASHBACK ARCHIVE fla1;
SQL> connect HR/HR
Connected.
SQL> ALTER TABLE hr.employees2 FLASHBACK ARCHIVE fla1;

Table altered.

SQL> ble
fe r a
7) To view and increase the salary of Mr. Fox three times by 1000, execute the
ans
-
flada_dml.sql script. This produces activity in the flashback data archive.
n t r
o
SQL> @flada_dml
s an
r ) ha deฺ
SQL> REM "********************************************** "

SQL> m ฺa Gui
SQL> REM "For demo purposes ONLY: Flashback Data Archive "

SQL> connect hr/HR n ฺ co ent


Connected.
@ ao Stud
SQL>
z i l le this
SQL> set echo on
e loฺ use
SQL> set serveroutput on
c
a r
SQL> -- set verify on to
m e
i l l e ( icens
SQL> set term on

oZ l
SQL> set lines 200
el SQL> set pages 44

Marc SQL> set pause on pause "Press [Enter] to continue..."


SQL>
SQL> /*== Query the current salary for Mr. Fox ==*/
SQL>
SQL> SELECT employee_id, last_name, salary
2 FROM hr.employees2
3 WHERE last_name = 'Fox'
4 /
Press [Enter] to continue...

EMPLOYEE_ID LAST_NAME SALARY


----------- ------------------------- ----------
170 Fox 9600

1 row selected.

SQL>
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...

Oracle Database 11g: New Features for Administrators A - 358


Practice 19-1: Using Flashback Data Archive (continued)
SQL>
SQL> /*== Increase the salary three times by 1000 ==*/
SQL>
SQL> UPDATE hr.employees2
2 SET salary = salary + 1000
3 WHERE last_name = 'Fox'
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

4 /

1 row updated.

SQL> COMMIT
2 /

Commit complete.
ble
SQL> UPDATE hr.employees2
fe r a
2 SET salary = salary + 1000
ans
3
4
WHERE last_name = 'Fox'
/ n - t r
o
s an
1 row updated.
r ) ha deฺ
SQL> COMMIT m ฺa Gui
2 /
n ฺ co ent
Commit complete. @ ao Stud
z i l le this
c e loฺ use
SQL> UPDATE hr.employees2
2 SET arsalary t=o salary + 1000
3 WHERE
l e n se = 'Fox'
(m elast_name
l
Z4i / lic
e l o
rc 1 row updated.
Ma
SQL> COMMIT
2 /

Commit complete.

SQL> pause Press [Enter] to continue...


Press [Enter] to continue...

SQL>
SQL> /*== Query the up-to-date value for Mr. Fox ==*/
SQL>
SQL> SELECT employee_id, last_name, salary
2 FROM hr.employees2
3 WHERE last_name = 'Fox'
4 /
Press [Enter] to continue...

EMPLOYEE_ID LAST_NAME SALARY

Oracle Database 11g: New Features for Administrators A - 359


Practice 19-1: Using Flashback Data Archive (continued)
----------- ------------------------- ----------
170 Fox 12600

1 row selected.

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> pause Press [Enter] to continue...


Press [Enter] to continue...

SQL>
SQL> set pause off
SQL> set feedback on
SQL>
8) To query the internal name of the archive table, execute the following command: e
SELECT * FROM USER_FLASHBACK_ARCHIVE_TABLES; r a bl
s fe
SQL> SELECT * FROM USER_FLASHBACK_ARCHIVE_TABLES;
- t r an
no n
TABLE_NAME OWNER_NAME FLASHBACK_ARCHIVE_NAME
---------- ---------- ----------------------
a
s ฺ
h a
ARCHIVE_TABLE_NAME
ฺ a r) uide
STATUS
----------------------------------------------------- --------
EMPLOYEES2 HR FLA1 ฺ c om ent G
SYS_FBA_HIST_75036
a on tud ENABLED

l l e@ is S
1 row selected. i
ฺz se th
l o
SQL> a rce to u
e m nse
(user,
9) As the
Z l l HR
i you executed
l i cchoose
e a time after the creation of the flashback data archive and
l obefore the erroneous DML. To view Mr. Fox's employee record as of
e
rc that time, execute the following query (replace '10' MINUTE with your chosen
Ma historic date, format examples: ‘50’ SECOND, ‘10’ DAY, ‘5’ MONTH):
Note: You receive an ORA-1466 error, if you specify a time before the flashback
data archive was started. Reduce the time to a smaller interval and try again. If you
still see the salary of 12600, increase your time interval.
SELECT employee_id, last_name, salary
FROM hr.employees2 AS OF TIMESTAMP
(SYSTIMESTAMP - INTERVAL '10' MINUTE)
WHERE last_name = 'Fox';
SQL> connect hr/HR
Connected.
SQL> SELECT employee_id, last_name, salary
FROM hr.employees2 AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL
'10' MINUTE)
WHERE last_name = 'Fox'; 2 3

EMPLOYEE_ID LAST_NAME SALARY


----------- ------------------------- ----------

Oracle Database 11g: New Features for Administrators A - 360


Practice 19-1: Using Flashback Data Archive (continued)
170 Fox 9600

1 row selected.

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

10) As the HR user, you realize that the recent updates were mistakes. To revert to the
original values for your chosen historic date (for example, ten minutes ago), execute
the following command (replace '10' MINUTE with your chosen historic date):
UPDATE hr.employees2
SET salary = (SELECT salary FROM hr.employees2
AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '10' MINUTE)
WHERE last_name = 'Fox')
WHERE last_name = 'Fox';
ble
SQL> UPDATE hr.employees2
fe r a
SET salary = (SELECT salary FROM hr.employees
ans
AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '10' MINUTE)
n - t r
WHERE last_name = 'Fox')
WHERE last_name = 'Fox'; a no
2 3 4 5 h a s ฺ
1 row updated.
ฺ a r) uide
SQL> commit; ฺ c om ent G
a on tud
Commit complete.
l l e@ is S
ฺ z i th
l o s e
SQL>
a rce to u
11) Continuing
l e (m e n se execute the following query. You will notice that the email
in SQL*Plus,
l
Zi areliacconcatenation of the first initial and last name for each person.
addresses
l oSELECT email, last_name, salary
rce FROM hr.employees2
Ma WHERE email LIKE 'T%';
SQL> SELECT email, last_name, salary
FROM hr.employees2
WHERE email LIKE 'T%'; 2 3

EMAIL LAST_NAME SALARY


------------------------- ------------------------- ----------
TJOLSON Olson 2100
TRAJS Rajs 3500
TFOX Fox 9600
TGATES Gates 2900

4 rows selected.

SQL>

Oracle Database 11g: New Features for Administrators A - 361


Practice 19-1: Using Flashback Data Archive (continued)
12) Execute the following UPDATE and COMMIT commands to append
@mycompany.com to all of the email addresses:
UPDATE hr.employees2 SET email = email||'@mycompany.com';
SQL> UPDATE hr.employees2 SET email = email||'@mycompany.com';
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

107 rows updated.

SQL> COMMIT;

Commit complete.

SQL>
13) Re-query the table to confirm the changes.
ble
SQL> SELECT email, last_name, salary
fe r a
FROM hr.employees2
ans
WHERE email LIKE 'T%'; 2 3
n - t r
EMAIL LAST_NAME a no SALARY
------------------------- a s ฺ
------------------------- ----------
h
TJOLSON@mycompany.com Olson
ฺ a r) uide 2100
TRAJS@mycompany.com
TFOX@mycompany.com
Rajs
Fox ฺ c om ent G 3500
9600
TGATES@mycompany.com a on tud
Gates 2900
l l e@ is S
4 rows selected. ฺz i th
l o s e
SQL> a rce to u
l e (m ense
l
i that laicnew email address standard is being implemented. For a while the
14) Imagine
Z
l o
e current email addresses will be stored in the OLD_EMAIL column while the original
rc
Ma email column will be updated to contain the new addresses. Add the required column
using the following statement:
ALTER TABLE hr.employees2 ADD (old_email varchar2(30));
SQL> ALTER TABLE hr.employees2 ADD (old_email varchar2(30));

Table altered.

SQL>
15) Populate the newly added column with the current email addresses:
SQL> UPDATE hr.employees2 SET old_email = email;

107 rows updated.

SQL> COMMIT;

Commit complete.

Oracle Database 11g: New Features for Administrators A - 362


Practice 19-1: Using Flashback Data Archive (continued)
SQL>
16) In addition, another new column needs to be implemented to store a computed value
for the employee's total compensation. Add the new column using the following
statement:
ALTER TABLE hr.employees2 ADD (total_comp number(8,2));
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> ALTER TABLE hr.employees2 ADD (total_comp number(8,2));

Table altered.

SQL>

17) Populate the new column with the computed value for TOTAL_COMP:
SQL> UPDATE hr.employees2 SET total_comp =
ble
(1+NVL(commission_pct,0))*salary;
fe r a
an s
107 rows updated.
n - t r
SQL> COMMIT; a no
h a s ฺ
Commit complete.
ฺ a r) uide
SQL> ฺ c om ent G
a on tud
18) Execute the following query to see
l l e@all ofistheSversions of Mr Fox's record since the
beginning of this practice. i
ฺz stheeuse
Note thof the VERSIONS_ENDTIME and
VERSIONS_ENDSCN l o
e pseudocolumns
u in the query. VERSIONS_ENDTIME shows
the time at m a r c t
which that versiono of the record expired. You can see that
( n s eis NULL
i ll e
VERSIONS_ENDTIME
i c e in the last record as that is the current view.
l Z l
oVERSIONS_ENDSCN provides the correct order of transactions even if the time
e
rc cannot be differentiated. You can use the query_fox_versions.sql script.
Ma SELECT last_name, email, old_email, salary, total_comp,
versions_endtime
FROM hr.employees2
VERSIONS BETWEEN TIMESTAMP (SYSTIMESTAMP - INTERVAL '60'
MINUTE) AND SYSTIMESTAMP
WHERE last_name = 'Fox'
ORDER BY versions_endscn;
SQL> @query_fox_versions
SQL> SELECT last_name, email, old_email, salary, total_comp,
versions_endtime
2 FROM hr.employees2
3 VERSIONS BETWEEN TIMESTAMP (SYSTIMESTAMP - INTERVAL '60'
MINUTE) AND SYSTIMESTAMP
4 WHERE last_name = 'Fox'
5 ORDER BY versions_endscn
6
SQL> /

Oracle Database 11g: New Features for Administrators A - 363


Practice 19-1: Using Flashback Data Archive (continued)
LAST_NAME EMAIL OLD_EMAIL
SALARY TOTAL_COMP VERSIONS_ENDTIME
------------------------- ------------------------- ----------
-------------------- ---------- ---------- -------------------
--------------------------------------------------------
Fox TFOX
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

9600 09-OCT-09 08.10.40.000000000 AM


Fox TFOX
10600 09-OCT-09 08.10.43.000000000 AM
Fox TFOX
11600 09-OCT-09 08.10.43.000000000 AM
Fox TFOX
12600 09-OCT-09 08.18.08.000000000 AM
Fox TFOX@mycompany.com
9600 09-OCT-09 08.19.34.000000000 AM
ble
Fox TFOX@mycompany.com
fe r a
TFOX@mycompany.com 9600
ans
6 rows selected. n - t r
SQL> a no
as ฺ the
19) The OLD_EMAIL column is no longer required. It canr)behremovedeusing
following statement: m ฺa Guid
SQL> ALTER TABLE hr.employees2 n ฺ co ent old_email;
ao Stud
DROP COLUMN

Table altered. l @
le this
z i
SQL> c e loฺ use
a r to
20) Whilele m e
the(results ofnthe
s previous query show how Mr Fox's record changed over time,
it Z i l
may be useful c e
li to also know how the EMPLOYEES2 table changed as well. Execute
l o
rce the following statements to gather this information. Note the name of the
Ma SYS_FBA_DDL_COLMAP_nnnnn table (the numeric identifiers in your table names
may differ).
SQL> SELECT * FROM tab;

TNAME TABTYPE CLUSTERID


------------------------------ ------- ----------
COUNTRIES TABLE
DEPARTMENTS TABLE
EMPLOYEES TABLE
EMPLOYEES2 TABLE
EMP_DETAILS_VIEW VIEW
JOBS TABLE
JOB_HISTORY TABLE
LOCATIONS TABLE
REGIONS TABLE
SYS_FBA_DDL_COLMAP_77042 TABLE
SYS_FBA_HIST_77042 TABLE
SYS_FBA_TCRV_77042 TABLE

Oracle Database 11g: New Features for Administrators A - 364


Practice 19-1: Using Flashback Data Archive (continued)

12 rows selected.

SQL>
21) Query the table you identified in the previous step to determine the System Change
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Number (SCN) ranges that define the existence of each column in the table:
SQL> SELECT column_name, startscn, endscn
FROM SYS_FBA_DDL_COLMAP_77042; 2

COLUMN_NAME STARTSCN ENDSCN


------------------- -------- -------
EMPLOYEE_ID 2931863

FIRST_NAME 2931863 ble


fe r a
LAST_NAME 2931863
ans
n - t r
EMAIL 2931863 o
s an
PHONE_NUMBER 2931863
r ) ha deฺ
m ฺa Gui
HIRE_DATE 2931863
n ฺ co ent
JOB_ID ao Stud
2931863
@
z i l le this
SALARY
c e loฺ u2931863
se
COMMISSION_PCT a r to 2931863
m e
i l l e ( icens
l o Z
MANAGER_ID l 2931863
rc e
Ma DEPARTMENT_ID 2931863

D_2937150_OLD_EMAIL 2936436 2937150

TOTAL_COMP 2936564

13 rows selected.
SQL>

22) From your previous result, the NULL values for ENDSCN indicate that the column still
exists in the table. You can convert the SCNs into timestamps using the
SCN_TO_TIMESTAMP function.
Note: You now have all the information you require to reconstruct a complete history
of the data.
SQL> SELECT SCN_TO_TIMESTAMP(2931863) FROM DUAL;

SCN_TO_TIMESTAMP(2931863)

Oracle Database 11g: New Features for Administrators A - 365


Practice 19-1: Using Flashback Data Archive (continued)
--------------------------------------------------------------
09-OCT-09 07.22.08.000000000 AM
1 row selected.

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

23) From your SQL*Plus session, connect to the database as the SYS user and list the data
dictionary views available to you by executing the flada_list1.sql file:
SQL> connect / as sysdba
Connected.
SQL> @flada_list1
SQL> REM "******************************************* "
SQL> REM "For demo purposes ONLY:"
SQL>
SQL> connect / as sysdba ble
Connected. fe r a
SQL> ans
SQL> set echo on n - t r
o
SQL> set serveroutput on
SQL> -- set verify on s an
SQL> set term on
r ) ha deฺ
SQL> set lines 200
m ฺa Gui
SQL> set pages 44
n ฺ co ent
SQL> set pause on pause "Press [Enter] to continue ..."
SQL>
@ ao Stud
l le this
SQL> /*== To list the available data dictioary views ==*/
z i
SQL>
c e
SQL> SELECT table_name
loฺ use
a r to
2 FROM mdict e
l e ( icens
3 WHERE table_name LIKE '%FLASHBACK_ARCHIVE%'
i l
el oZ 4 / l
arc
Press [Enter] to continue ...
M TABLE_NAME
------------------------------
DBA_FLASHBACK_ARCHIVE
DBA_FLASHBACK_ARCHIVE_TABLES
DBA_FLASHBACK_ARCHIVE_TS
USER_FLASHBACK_ARCHIVE
USER_FLASHBACK_ARCHIVE_TABLES

5 rows selected.

SQL> pause Press [Enter] to continue ...


Press [Enter] to continue ...

SQL>
SQL> col FLASHBACK_ARCHIVE_NAME format A25
SQL> col ARCHIVE_TABLE_NAME format A20
SQL> col TABLE_NAME format A12
SQL> col OWNER_NAME format A10

Oracle Database 11g: New Features for Administrators A - 366


Practice 19-1: Using Flashback Data Archive (continued)
SQL>
SQL> DESC dba_flashback_archive
Name Null? Type
----------------------------- -------- ---------------
OWNER_NAME VARCHAR2(30)
FLASHBACK_ARCHIVE_NAME NOT NULL VARCHAR2(255)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

FLASHBACK_ARCHIVE# NOT NULL NUMBER


RETENTION_IN_DAYS NOT NULL NUMBER
CREATE_TIME TIMESTAMP(9)
LAST_PURGE_TIME TIMESTAMP(9)
STATUS VARCHAR2(7)

SQL> pause Press [Enter] to continue ...


Press [Enter] to continue ...
ble
SQL>
fe r a
SQL> /*== To query the time when the flashback data archive(s)
ans
have been created ==*/
SQL> n - t r
SQL> SELECT flashback_archive_name, create_time, status a no
2 FROM dba_flashback_archive
h a s ฺ
3 /
Press [Enter] to continue ... ฺ a r) uide
ฺ c om ent G
FLASHBACK_ARCHIVE_NAME on tud
CREATE_TIME
a
STATUS
l l e@ is S
------------------------- i th
ฺz se------------------------------------
l o
--------------------------------------- -------
e o u 09-OCT-09 07.28.09.000000000
FLA1 a r c t AM
m
( ens e
i l l eselected.
l o
1 row
Z lic
rc e SQL> pause Press [Enter] to continue ...
Ma Press [Enter] to continue ...

SQL>
SQL> DESC dba_flashback_archive_ts
Name Null? Type
------------------------- -------- -------------
FLASHBACK_ARCHIVE_NAME NOT NULL VARCHAR2(255)
FLASHBACK_ARCHIVE# NOT NULL NUMBER
TABLESPACE_NAME NOT NULL VARCHAR2(30)
QUOTA_IN_MB VARCHAR2(40)

SQL> pause Press [Enter] to continue ...


Press [Enter] to continue ...

SQL>
SQL> /*== To list the tablespace(s), which are used for
flashback data archives ==*/
SQL>
SQL> SELECT *

Oracle Database 11g: New Features for Administrators A - 367


Practice 19-1: Using Flashback Data Archive (continued)
2 FROM dba_flashback_archive_ts
3 /
Press [Enter] to continue ...

FLASHBACK_ARCHIVE_NAME FLASHBACK_ARCHIVE# TABLESPACE_NAME


QUOTA_IN_MB
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

------------------------- ------------------ -----------------


------------- ----------------------------------------
FLA1 1 FLA_TBS1
10

1 row selected.

SQL> pause Press [Enter] to continue ...


Press [Enter] to continue ...
ble
fe r a
SQL>
ans
SQL> DESC dba_flashback_archive_tables
Name Null? Type n - t r
---------------------- -------- ------------- a no
TABLE_NAME NOT NULL VARCHAR2(30)
h a s ฺ
OWNER_NAME NOT NULL VARCHAR2(30)
FLASHBACK_ARCHIVE_NAME NOT NULL VARCHAR2(255) ฺ a r) uide
ARCHIVE_TABLE_NAME VARCHAR2(53) ฺ c om ent G
a on tud
SQL> pause Press [Enter]@
l e i s S ...
to continue
i l h
oฺz use t
Press [Enter] to continue ...
e l
SQL> a rc totable name(s), the owner name(s),
SQL> /*== m
( ensQuery e
the and ==*/
i
SQL> l l e/*== c internal "history" table name(s) of the
l o Z lithe
flashback data archive ==*/
rc e SQL>
Ma SQL> SELECT *
2 FROM dba_flashback_archive_tables
3 /
Press [Enter] to continue ...

TABLE_NAME OWNER_NAME FLASHBACK_ARCHIVE_NAME


ARCHIVE_TABLE_NAME STATUS
------------ ---------- ------------------------- ------------
-------- --------
EMPLOYEES2 HR FLA1
SYS_FBA_HIST_77042 ENABLED

1 row selected.

SQL>
SQL> pause Press [Enter] to continue ...
Press [Enter] to continue ...

SQL> clear columns

Oracle Database 11g: New Features for Administrators A - 368


Practice 19-1: Using Flashback Data Archive (continued)
SQL>
SQL> connect hr/HR
Connected.
SQL>
SQL> SELECT table_name
2 FROM dict
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

3 WHERE table_name LIKE '%FLASHBACK_ARCHIVE%'


4 /
Press [Enter] to continue ...

TABLE_NAME
------------------------------
USER_FLASHBACK_ARCHIVE
USER_FLASHBACK_ARCHIVE_TABLES
ble
2 rows selected.
fe r a
ans
SQL> pause Press [Enter] to continue ...
Press [Enter] to continue ... n - t r
a no
SQL> exit
h a s ฺ
Disconnected from Oracle Database 11g Enterprise
Release 11.2.0.1.0 - Production ฺ a r) uideEdition
With the Partitioning, Automatic c m ntManagement,
oStorage G OLAP,
Data Mining and Real Application o n ฺ d e
Testing options
$ @ a Stu
z i l l e t h is
24) To practice additionallo ฺ
flashback e archive maintenance tasks, connect by using
sdata
SQL*Plus to the c e u
rdatabasetaso the ARCHIVE_ADMIN user.
a
l
$ sqlpluse m
e se
( ARCHIVE_ADMIN/ARCHIVE_ADMIN
n
Zi l lic
l o
rce SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 9 08:53:09
Ma 2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL>
25) Data in the flashback data archive is automatically purged, when the retention time
has expired. However, you can also explicitly purge data. Use the following
command to purge data older than two minutes:
ALTER FLASHBACK ARCHIVE fla1 PURGE BEFORE TIMESTAMP (SYSTIMESTAMP -
INTERVAL '2' MINUTE);

Oracle Database 11g: New Features for Administrators A - 369


Practice 19-1: Using Flashback Data Archive (continued)
SQL> ALTER FLASHBACK ARCHIVE fla1 PURGE BEFORE
TIMESTAMP(SYSTIMESTAMP - INTERVAL '2' MINUTE);

Flashback archive altered.

SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

26) Execute the flada_tbs2.sql script to create an additional 10 MB tablespace as the


SYS user.
SQL> @flada_tbs2
Connected.
SQL> set serveroutput on
SQL> -- set verify on
SQL> set term on
SQL> set lines 200 ble
SQL> set pages 44 fe r a
SQL> set pause on ans
SQL> n - t r
SQL> /*== Create another tablespace ==*/
a no
SQL>
h a s ฺ
SQL> DROP TABLESPACE fla_tbs2 INCLUDING CONTENTS and DATAFILES
2 / ฺ a r) uide
ฺ c om ent G
DROP TABLESPACE fla_tbs2 INCLUDING CONTENTS and DATAFILES
*
ERROR at line 1: a on tud
l l e@ is S
ORA-00959: tablespace 'FLA_TBS2' does not exist
i
ฺz se th
l o
SQL>
a r ce to u
SQL> CREATE
2 lle (m eSMALLFILE
DATAFILE n se TABLESPACE fla_tbs2
'+DATA'
i c
el o Z3 SIZE li10M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE 32767M
4 NOLOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE
Marc MANAGEMENT AUTO
5 /

Tablespace created.

SQL> pause Press [Enter] to continue...


Press [Enter] to continue...

27) As the ARCHIVE_ADMIN user, add 5 MB of the FLA_TBS2 tablespace to the FLA1
flashback data archive.
SQL> connect ARCHIVE_ADMIN/ARCHIVE_ADMIN
Connected.
SQL> ALTER FLASHBACK ARCHIVE fla1 ADD TABLESPACE fla_tbs2
QUOTA 5M;
Flashback archive altered.

SQL>

Oracle Database 11g: New Features for Administrators A - 370


Practice 19-1: Using Flashback Data Archive (continued)
28) All tables in one specific flashback data archive have the same retention time. Change
the retention time of the FLA1 flashback data archive to two years.
SQL> ALTER FLASHBACK ARCHIVE fla1 MODIFY RETENTION 2 YEAR;

Flashback archive altered.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL>

29) As the ARCHIVE_ADMIN user, drop the FLA1 flashback data archive.
Note: Dropping a flashback data archive includes dropping the internal tamper-
proofed history table. You cannot drop this table directly due to auditing and security
requirements. Dropping a flashback data archive does not drop the tablespaces in
which they are stored, because the tablespaces might contain other data. e
r a bl
SQL> DROP FLASHBACK ARCHIVE fla1;
s fe
Flashback archive dropped. - t r an
no n
SQL> s ฺa
h a
30) Connected as the SYS user, clean up your environment
ฺ a u ide the
r)by executing
flada_cleanup.sql script.
ฺ c om ent G
SQL> @flada_cleanup a on tud
SQL> REM Execute this le @ script
script i s S for training purposes only
SQL> REM Undo Cleanup i l
ฺz for t h
Flashback Data Archive
SQL> REM Execute e l oscript u s e
as SYSDBA
SQL> a rc t o
SQL> e
l (mechoenonse
set
SQL>l
Zi set lic on
serveroutput on
l oSQL> set term
rce SQL> set lines 200
Ma SQL> set pause on
SQL>
SQL> connect / as sysdba
Connected.
SQL>
SQL> DROP TABLESPACE fla_tbs1 INCLUDING CONTENTS and DATAFILES
2 /

Tablespace dropped.

SQL> DROP TABLESPACE fla_tbs2 INCLUDING CONTENTS and DATAFILES


2 /

Tablespace dropped.

SQL> ALTER USER hr PASSWORD EXPIRE ACCOUNT LOCK


2 /

Oracle Database 11g: New Features for Administrators A - 371


Practice 19-1: Using Flashback Data Archive (continued)
User altered.

SQL> DROP USER archive_admin CASCADE


2 /

User dropped.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> drop table hr.employees2 purge;

Table dropped.

SQL>
SQL> prompt Flashback Data Archive cleanup complete.
Flashback Data Archive cleanup complete.
SQL> pause Press [Enter] to continue...
ble
Press [Enter] to continue...
fe r a
ans
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition n - t r
o
Release 11.2.0.1.0 - Production
s an
r
Data Mining and Real Application Testing options ) ha deฺ
With the Partitioning, Automatic Storage Management, OLAP,

$ m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 372


Practice 19-2: Performing Flashback Transaction Backout
Flashback Transaction Backout is a logical recovery option to roll back a specific
transaction and dependent transactions while the database remains online. A dependent
transaction is related by either a write-after-write (WAW) relationship, in which a
transaction modifies the same data that was changed by the target transaction, or a
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

primary key constraint relationship, in which a transaction reinserts the same primary key
value that was deleted by the target transaction. Flashback Transaction utilizes undo and
the redo generated for undo blocks, to create and execute a compensating transaction for
reverting the affected data back to its original state.
1) Flashback Transaction Backout requires that the database be in ARCHIVELOG mode.
In a terminal session, connected as the oracle user, change to the
/home/oracle/solutions/FTX directory. Ensure that you are pointing to the
orcl database. Execute the flatxn_archivelog.sh script. ble
fe r a
$ cd /home/oracle/solutions/FTX s
$ . oraenv
- t r an
ORACLE_SID = [orcl] ? orcl
o n
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is s an
/u01/app/oracle r ) ha deฺ
$ ./flatxn_archivelog.sh
m ฺa Gui
n ฺ co ent
*******************************************
For demo purposes ONLY:
* Unlock HR account @ ao Stud
i l le this
* Enable ARCHIVELOG mode for database
z
c e loฺ use
The script amay r appear toshutting
to hang at the SQL prompt
when the m
( ens
database e is down and being
i l
opened.l e Wait
i c a few minutes and it should progress.
Z l
rc elo*******************************************
Ma SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 9 09:10:34
2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> SQL>
User altered.

SQL>
System altered.

SQL> SQL> Database closed.


Database dismounted.

Oracle Database 11g: New Features for Administrators A - 373


Practice 19-2: Performing Flashback Transaction Backout
(continued)
ORACLE instance shut down.
SQL> ORACLE instance started.

Total System Global Area 422670336 bytes


Fixed Size 1336960 bytes
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Variable Size 318769536 bytes


Database Buffers 96468992 bytes
Redo Buffers 6094848 bytes
Database mounted.
SQL>
Database altered.

SQL>
Database altered.
ble
fe r a
SQL> Database log mode Archive Mode
ans
Automatic archival Enabled
n - t r
Archive destination
Oldest online log sequence
USE_DB_RECOVERY_FILE_DEST
108 a no
Next log sequence to archive 110 h a s ฺ
Current log sequence 110
ฺ a r) uide
Release 11.2.0.1.0 - Production ฺ c om ent G
SQL> Disconnected from Oracle Database 11g Enterprise Edition

a on tud
With the Partitioning, Automatic Storage Management, OLAP,
e@ is S
Data Mining and Real Application Testing options
l l
$ i
ฺz se th
l o
e too the u database as the SYS user and run the
2) Using SQL*Plus, a rcconnect t
l e (m ensescript. This setup script sets up the database and the HR user
flatxn_setup1.sql
i l
forZbacking lictransactions with flashback. Note the ALTER DATABASE and GRANT
out
l o
e commands.
rc
Ma $ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 9 09:12:54


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> @flatxn_setup1
SQL> set serveroutput on
SQL> set term on
SQL> set lines 200
SQL> set pause on
SQL>

Oracle Database 11g: New Features for Administrators A - 374


Practice 19-2: Performing Flashback Transaction Backout
(continued)
SQL> /*== Set up the HR database account for this lab ==*/
SQL>
SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;

Database altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY)


COLUMNS;

Database altered.

SQL> GRANT EXECUTE ON dbms_flashback TO hr;

Grant succeeded.
ble
fe r a
SQL> GRANT select any transaction TO hr;
ans
n - t r
Grant succeeded.
a no
SQL> pause Press [Enter] to continue... has ฺ
r ) i d e
Press [Enter] to continue...
m ฺa Gu
o
3) Press [Enter] to continue to the next step inฺcthe script.n
e Thet script connects to the
n
database as HR user and creates the first
@ tud which consists of inserting
ao test Stransaction,
five rows.
z i l le this
SQL>
c e loฺ use
SQL> /*== Createa r test to data for flashback transaction ==*/
m e
i l l
Connected.e ( icens
SQL> connect hr/hr

l o Z
SQL> l
rc e SQL> /*== Test transaction 1 ==*/
Ma SQL> INSERT INTO hr.regions VALUES (10,'Pole');

1 row created.

SQL> INSERT INTO hr.regions VALUES (20,'Moon');

1 row created.

SQL> INSERT INTO hr.regions VALUES (30,'Venus');

1 row created.

SQL> INSERT INTO hr.regions VALUES (40,'Mars');

1 row created.

SQL> INSERT INTO hr.regions VALUES (50,'Saturn');

1 row created.

Oracle Database 11g: New Features for Administrators A - 375


Practice 19-2: Performing Flashback Transaction Backout
(continued)

SQL> COMMIT;

Commit complete.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> pause Press [Enter] to continue...


Press [Enter] to continue...

4) Press [Enter] to continue to the next step in the script. The script continues to create
the second test transaction, which consists of updating two rows that you just
inserted. This creates a write-after-write (WAW) dependency. A WAW dependency
exists when a transaction updates or deletes a row that has been inserted or updated
by a dependent transaction.
ble
SQL>
fe r a
SQL> /*== Test transaction 2 ==*/
ans
SQL> /*== Region 10 and 20 has a WAW dependency on transaction
n - t r
1 ==*/
SQL> UPDATE hr.regions SET region_name='Two Poles' WHEREa no
region_id = 10;
h a s ฺ
ฺ a r) uide
1 row updated.
ฺ c om ent G
on tud
SQL> UPDATE hr.regions SETaregion_name='Many Moons' WHERE
region_id = 20; @
le this S
ฺ z i l
1 row updated. elo
c u se
a r to
m e
i l l e ( icens
SQL> COMMIT;

l o Z l
Commit complete.
rc e
Ma SQL> pause Press [Enter] to continue...
Press [Enter] to continue...

5) Press [Enter] to continue to the next step in the script. The script continues to create
the third transaction, which consists of updating three rows, one of which was also
updated in the previous transaction. This action creates another WAW dependency.
SQL>
SQL> /*== Test transaction 3 ==*/
SQL> /*== Region 10 has a WAW dependency on transaction 1 and
2 ==*/
SQL> /*== Region 40 and 50 has a WAW dependency on transaction
1 ==*/
SQL> UPDATE hr.regions SET region_name='No star' WHERE
region_id = 10;

1 row updated.

Oracle Database 11g: New Features for Administrators A - 376


Practice 19-2: Performing Flashback Transaction Backout
(continued)
SQL> UPDATE hr.regions SET region_name='Red star' WHERE
region_id = 40;

1 row updated.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> UPDATE hr.regions SET region_name='Big star' WHERE


region_id = 50;

1 row updated.

SQL> COMMIT;

Commit complete.
ble
SQL> pause Press [Enter] to continue...
fe r a
Press [Enter] to continue...
t r a ns
n - to create a
6) Press [Enter] to continue to the next step in the script. The script continues
o
a n in transaction 1.
fourth transaction, which consists of updating a row that was inserted
s
This action creates another WAW dependency.
r ) ha deฺ
SQL>
m ฺa Gui
SQL> /*== Test transaction 4 ==*/ ฺ c o ent
n
SQL> /*== Region 30 has a WAW
SQL> UPDATE hr.regions SET @ tud on transaction
o dependency
aregion_name='Still
S called Venus'
1 ==*/

WHERE region_id = 30; z i l le this


c e loฺ use
1 row updated. a r to
m
( ens e
SQL>i l l eCOMMIT;
l o Z lic
rce Commit complete.
Ma SQL>
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
7) Press [Enter] to continue to the next step in the script. Lastly, the script connects to
the database as the SYS user and switches archive logs. Flashback Transaction
requires at least one archived log to start analyzing redo.
SQL>
SQL> connect / as sysdba
Connected.
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;

System altered.

SQL>
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;

Oracle Database 11g: New Features for Administrators A - 377


Practice 19-2: Performing Flashback Transaction Backout
(continued)
System altered.

SQL>
SQL> prompt "Setup for Flashback Transaction completed"
"Setup for Flashback Transaction completed"
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> pause Press [Enter] to continue...


Press [Enter] to continue...

8) Press [Enter] to exit the script.


SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP, ble
Data Mining and Real Application Testing options fe r a
$ an s
n - t r
a no
9) A transaction can have a write-after-write (WAW) dependency, meaning that a
transaction updates or deletes row data that has been inserted or updated by a
h a s ฺ
previous transaction. In this section, you want to back out a bad transaction, in
ฺ a r) uide
addition to its WAW dependents, which also caused incorrect changes. Perform the
following steps: ฺ c om ent G
a
a) Log in to Enterprise Manager Database on Controltud as the SYS user.
@ S
z ille thtable
b) You suspect that the ฺHR.REGIONS
is contains changes from the bad
transaction, and e lo to view
want u e complete table data. Click the Schema tab, and
sthe
then click a
c
r located
Tables to under Database Objects.
m
( ens e
i
c) Tol l eview
l o Zand clickall ictables
lthe that belong to the HR schema user, enter HR in the Schema field
Go button.
rc e
Ma d) On the Tables page, select the REGIONS table, and then select View Data from the
Actions drop-down list. Click the Go button to view the data in the HR.REGIONS
table.
e) While viewing the content of the table, you realize that it should not contain the
following rows: “Many moons” and “Still called Venus.” Click OK.
f) Back to the list of tables, select the REGIONS table, and then select Flashback
Transaction from the Actions drop-down list and click the Go button.
g) Review the query conditions. Specify a time period in which you believe the
faulty changes were made. For this example, accept the default time period and
click Next.
h) On the Flashback Transaction: Select Transaction page, click the Transaction ID
link of the transaction that updated two regions.
i) On the Select Transaction: Show Details page, review the erroneous UPDATE
commands and click OK.

Oracle Database 11g: New Features for Administrators A - 378


Practice 19-2: Performing Flashback Transaction Backout
(continued)
j) Click Next to identify any dependent transactions and back out all needed
changes. The Processing: Flashback Transaction window appears. On the
Flashback Transaction: Show Dependencies page, click the first Transaction ID
link.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

k) On the Show Dependencies: Details page, review the compensating transactions.


Notice that one of the compensating transactions has been executed. It is marked
[exec=yes]. The other one is not executed; it is marked [exec=no]. Click OK.
l) On the Flashback Transaction: Show Dependencies page, click the Change
Recovery Option button.
m) On the Show Dependencies: Change Recovery Option page, select Cascade,
which will also back out the erroneous dependent transaction changes, and click e
OK. r a bl
n) On the Flashback Transaction: Show Dependencies page, click Next.
fe
ns
t r a
- Script
o) On the Flashback Transaction: Review page, click the Show UndooSQL n
button.
s an
)
p) On the Review: Show Undo SQL page, review allrcompensating ha deฺUPDATE
commands, then click OK. m ฺa Gui
q) Enter the following command in the n ฺ co SQL
Execute e n t and click the Execute
region,
SQL button, to preview the result @ S tud
o the compensating
athat undo statements produce:
l l e i s
SELECT * FROM HR.REGIONS;
l o ฺzi se th
r) Notice thatathe rc“eManytoMoons u ” row disappeared from the result list. Click OK.
(m n e
sTransaction:
s) On
i l l e
the e
Flashback
i c Review page, click Finish.
Z l
rc elot) The Flashback Transaction executed successfully. Click OK.
Ma u) Go back and view the content of the HR.REGIONS table. Return to the Tables
page. Specify HR as the Schema, click Go, select the REGIONS table, select View
Data from the Actions drop-down list, and click Go.
v) The content of the table is the same as displayed four steps above. Transactions 2
and 3 are backed out, but transaction 4 remains (the region name is set to “Still
called Venus”) because there is no WAW dependency between transaction 2
and 4.
w) Log out of Enterprise Manager.
10) Clean up your environment by performing the following steps. Ensure that you are
pointing to the orcl database. In a SQL*Plus session, connected as the SYS user,
execute the flatxn_cleanup1.sql script.
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 9 09:31:33


2009

Oracle Database 11g: New Features for Administrators A - 379


Practice 19-2: Performing Flashback Transaction Backout
(continued)
Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

With the Partitioning, Automatic Storage Management, OLAP,


Data Mining and Real Application Testing options

SQL> @flatxn_cleanup1
SQL> set serveroutput on
SQL> set term on
SQL> set lines 200
SQL> set pause on
SQL>
ble
SQL> connect / as sysdba
fe r a
Connected.
ans
SQL>
n - t r
SQL> DELETE FROM hr.regions WHERE region_id=10; o
s an
1 row deleted.
r ) ha deฺ
m ฺa Gui
SQL> DELETE FROM hr.regions WHERE region_id=20;
n ฺ co ent
1 row deleted.
@ ao Stud
z i l le thWHERE
is region_id=30;
c e loฺ use
SQL> DELETE FROM hr.regions

1 row deleted. a r to
m
( ens e
i l l eDELETE
l o Z
SQL> licFROM hr.regions WHERE region_id=40;
rc e
Ma
1 row deleted.

SQL> DELETE FROM hr.regions WHERE region_id=50;

1 row deleted.

SQL> COMMIT;

Commit complete.

SQL>
SQL> ALTER DATABASE DROP SUPPLEMENTAL LOG DATA (PRIMARY KEY)
COLUMNS;

Database altered.

SQL> ALTER DATABASE DROP SUPPLEMENTAL LOG DATA;

Database altered.

Oracle Database 11g: New Features for Administrators A - 380


Practice 19-2: Performing Flashback Transaction Backout
(continued)

SQL> REVOKE EXECUTE ON dbms_flashback FROM hr;

Revoke succeeded.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> REVOKE select any transaction FROM hr;

Revoke succeeded.

SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
ble
Data Mining and Real Application Testing options
fe r a
$
t r a ns
11) Now execute the flatxn_cleanup.sh script to disable ARCHIVELOGo n -mode.
$ ./flatxn_cleanup.sh s an
*******************************************
r ) ha deฺ
For cleanup of demo:
m ฺa Gui
* Change HR password back to HR
* Disable ARCHIVELOG mode on
ฺco dent
@ a Stu
i
SQL*Plus: Release 11.2.0.1.0
z l l e t h is
Production on Fri Oct 9 09:32:52
ฺ e
2009
r c elo o us
Copyright m a
(c) 1982, e t 2009, Oracle. All rights reserved.
( s
Z i lle licen
e l oConnected to:
rc Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Ma Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> SQL>
System altered.

SQL> SQL> Database closed.


Database dismounted.
ORACLE instance shut down.
SQL> ORACLE instance started.

Total System Global Area 422670336 bytes


Fixed Size 1336960 bytes
Variable Size 318769536 bytes
Database Buffers 96468992 bytes
Redo Buffers 6094848 bytes
Database mounted.
SQL>

Oracle Database 11g: New Features for Administrators A - 381


Practice 19-2: Performing Flashback Transaction Backout
(continued)
Database altered.

SQL>
Database altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

SQL> Database log mode No Archive Mode


Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 110
Current log sequence 112
SQL> SQL> "Cleanup finished."
SQL> Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
ble
Data Mining and Real Application Testing options
fe r a
$
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 382


Practices for Lesson 20

The Data Recovery Advisor is a tool that helps you to diagnose and repair data failures
and corruptions. The Data Recovery Advisor analyzes failures based on symptoms and
intelligently determines optimal repair strategies. The tool can also automatically repair
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

diagnosed failures.

In this practice, you use the Data Recovery Advisor in three different scenarios:
• Repairing a “down” database by using Enterprise Manager
• Repairing block corruption by using Enterprise Manager
• Repairing a “down” database by using RMAN commands

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 383


Practice 20-1: Repairing a Database by Using Enterprise
Manager
The first scenario assumes that your database is “down.” In a production environment,
this would be a highly critical situation, which you have to resolve as quickly as possible
to “save the business.” You attempt to reopen the database, but this fails. You then use
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

the Data Recovery Advisor from Enterprise Manager Database Control to diagnose the
failures. The diagnosis reveals the inaccessibility of two data files. For the first data file
issue, you use the manual repair option (rename a data file). This issue could have
resulted from a DBA executing the ALTER DATABASE ... RENAME FILE ...
command and the System Administrator neglecting to properly rename the data file in the
operating system.

After fixing the first data file issue by renaming the file, you again request repair advice e
from the Data Recovery Advisor. For the second data file issue, you use the automated r a bl
repair option to recover the lost data file. Finally, you verify that the database is up and
s fe
running again.
- t r an
no
1) In a terminal window, change to the /home/oracle/solutions/DRA directory
n
and execute the./dra_setup.sh command.
a
s ฺ
h a
$ . oraenv ฺ a r) uide
ORACLE_SID = [orcl] ? orcl
ฺ c om ent G
The Oracle base for
a on tud
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle l l e@ is S
o ฺzi se th
$ cd /home/oracle/solutions/DRA
l
rce to u
$ ./dra_setup.sh
a
l
Recoverye (mManager:
e n se Release 11.2.0.1.0 - Production on Fri Oct 9
Zi l
10:34:57 lic
2009
e l o
rc
Ma Copyright (c) 1982, 2009, Oracle and/or its affiliates.
rights reserved.
All

connected to target database: ORCL (DBID=1226549444)


using target database control file instead of recovery catalog

RMAN>
RMAN>
no failures found that match specification

RMAN>
no failures found that match specification

RMAN>
no failures found that match specification

RMAN>
Recovery Manager complete.
*******************************************

Oracle Database 11g: New Features for Administrators A - 384


Practice 20-1: Repairing a Database by Using Enterprise
Manager (continued)
For demo purposes ONLY
Run as the OS user who installed the Oracle software, e.g.
oracle

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 9 10:35:02


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
ble
fe r a
SQL> SQL> SQL> SQL> drop tablespace users2 including contents
an s
and datafiles
n - t r
*
ERROR at line 1: a no
ORA-00959: tablespace 'USERS2' does not exist h a s ฺ
ฺ a r) uide
SQL> SQL> drop tablespace example2 m G contents
datafiles ฺ c o including
n t and

* a on tude
ERROR at line 1:
l l e@ is S
ORA-00959: tablespace i
ฺz 'EXAMPLE2' th does not exist
l o s e
SQL> SQL> SQL> a rce to u
Tablespace
l e (m created.
e n se
Z i l l ic
l o
e SQL> SQL>
rc
Ma
Tablespace created.

SQL> SQL>
Table created.

SQL>
Table created.

SQL>
Table created.

SQL>
Table created.

SQL> SQL>
Table created.

SQL>
Table created.

Oracle Database 11g: New Features for Administrators A - 385


Practice 20-1: Repairing a Database by Using Enterprise
Manager (continued)

SQL>
Table created.

SQL> SQL> Disconnected from Oracle Database 11g Enterprise


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Edition Release 11.2.0.1.0 - Production


With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
*******************************************
For demo purposes ONLY:
* Unlock HR account with the HR password
* Enable ARCHIVELOG mode for database

The script may appear to hang at the SQL prompt


ble
when the database is shutting down and being
fe r a
opened. Wait a few minutes and it should progress.
ans
*******************************************
n - t r
a no
SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 9 10:35:05
2009 h a s ฺ
ฺ a r) uide
Copyright (c) 1982, 2009, Oracle. m
ฺ c n t G reserved.
o Allerights
Connected to: a on tud
e
Oracle Database 11g Enterprise
l S
@ isEdition Release 11.2.0.1.0 -
z i l t h
Production
c e loฺ uAutomatic
With the Partitioning, se Storage Management, OLAP,
Data Miningarand Realt o Application Testing options
l e (m ense
Z
SQL>l
i SQL> lic
l o
e User altered.
rc
Ma SQL>
System altered.

SQL> SQL> Database closed.


Database dismounted.
ORACLE instance shut down.
SQL> ORACLE instance started.

Total System Global Area 422670336 bytes


Fixed Size 1336960 bytes
Variable Size 318769536 bytes
Database Buffers 96468992 bytes
Redo Buffers 6094848 bytes
Database mounted.
SQL>
Database altered.

SQL>

Oracle Database 11g: New Features for Administrators A - 386


Practice 20-1: Repairing a Database by Using Enterprise
Manager (continued)
Database altered.

SQL> Database log mode Archive Mode


Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Oldest online log sequence 110


Next log sequence to archive 112
Current log sequence 112
SQL> Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

Recovery Manager: Release 11.2.0.1.0 - Production on Fri Oct 9


ble
10:35:28 2009
fe r a
Copyright (c) 1982, 2009, Oracle and/or its affiliates. t r a ns
All
rights reserved. n-
no
a
s ฺ
connected to target database: ORCL (DBID=1226549444) h a
ฺ a r) uide
RMAN> configure controlfile autobackup
2> ฺ c om eon; n tG
a n current';
olog ud
3> sql 'alter system archive
@ S t
4>
z i l le thlogis current';
5> sql 'alter system
e
6> sql 'altercsystemloฺ archive
archive
u se log current';
a r
7> backup database; to
8> sql m
( ensystems e
lle 'alter
9>Zisql l i
'alterc system
archive log current';
archive log current';
l o
e 10> sql 'alter system archive log current';
rc
Ma
11> backup archivelog all delete input;
12> sql 'alter system archive log current';
13> sql 'alter system archive log current';
14> sql 'alter system archive log current';
15> list backup summary;
16>
17>
using target database control file instead of recovery catalog
old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

sql statement: alter system archive log current

sql statement: alter system archive log current

sql statement: alter system archive log current

Oracle Database 11g: New Features for Administrators A - 387


Practice 20-1: Repairing a Database by Using Enterprise
Manager (continued)

Starting backup at 09-OCT-09


allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=51 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

channel ORA_DISK_1: specifying datafile(s) in backup set


input datafile file number=00002
name=+DATA/orcl/datafile/sysaux.257.698768527
channel ORA_DISK_1: starting piece 1 at 09-OCT-09
channel ORA_DISK_1: finished piece 1 at 09-OCT-09
piece
handle=+FRA/orcl/backupset/2009_10_09/nnndf0_tag20091009t10354
7_0.294.699791749 tag=TAG20091009T103547 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time:
ble
00:01:06
fe r a

ans
input datafile file number=00004
n - t r
name=+DATA/orcl/datafile/users.259.698768531
channel ORA_DISK_1: starting piece 1 at 09-OCT-09 a no
channel ORA_DISK_1: finished piece 1 at 09-OCT-09 h a s ฺ
piece
ฺ a r) uide
ฺ c om ent G
handle=+FRA/orcl/backupset/2009_10_09/nnndf0_tag20091009t10354
7_0.297.699791905 tag=TAG20091009T103547 comment=NONE
a on tud
channel ORA_DISK_1: backup set complete, elapsed time:
00:00:45
l l e@ is S
i
ฺz se th
Finished backup at 09-OCT-09
l o
a rce File
Starting Control t o u
and SPFILE Autobackup at 09-OCT-09
piecee (m s e
Z ill l i cen
handle=+FRA/orcl/autobackup/2009_10_09/s_699791951.298.6997919

rc elo55 comment=NONE
Ma
Finished Control File and SPFILE Autobackup at 09-OCT-09

sql statement: alter system archive log current

sql statement: alter system archive log current

sql statement: alter system archive log current

Starting backup at 09-OCT-09


current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=101 RECID=1
STAMP=699702518
input archived log thread=1 sequence=102 RECID=2
STAMP=699703795

Oracle Database 11g: New Features for Administrators A - 388


Practice 20-1: Repairing a Database by Using Enterprise
Manager (continued)
archived log file
name=+FRA/orcl/archivelog/2009_10_09/thread_1_seq_118.302.6997
91969 RECID=12 STAMP=699791969
Finished backup at 09-OCT-09
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Starting Control File and SPFILE Autobackup at 09-OCT-09


piece
handle=+FRA/orcl/autobackup/2009_10_09/s_699791997.302.6997919
99 comment=NONE
Finished Control File and SPFILE Autobackup at 09-OCT-09

sql statement: alter system archive log current

sql statement: alter system archive log current


ble
fe r a
sql statement: alter system archive log current
an s
n - t r
List of Backups a no
=============== h a s ฺ
Key TY LV S Device Type
ฺ u ide #Copies
) #Pieces
CompletionarTime
Compressed Tag
------- -- -- - ----------- ฺ c om ent G------- -------
--------------- --
-------- --- a on tud
1 B F A DISK l e@ 08-OCT-09
i s S 1 1 NO
z i l t h
TAG20091008T113504
2 B F A DISKc e loฺ use 09-OCT-09 1 1 NO
a r
TAG20091009T103547 t o
3
l e (m ense
B F A DISK 09-OCT-09 1 1 NO
i l li c
el oZ
TAG20091009T103547
4 B F A DISK 09-OCT-09 1 1 NO

Marc TAG20091009T103547
5 B F A DISK 09-OCT-09 1 1 NO
TAG20091009T103547
6 B F A DISK 09-OCT-09 1 1 NO
TAG20091009T103911
7 B A A DISK 09-OCT-09 1 1 NO
TAG20091009T103929
8 B F A DISK 09-OCT-09 1 1 NO
TAG20091009T103957

Recovery Manager complete.


Basic setup done.
Now, run one of the setup scripts for a specific scenario.
$

Oracle Database 11g: New Features for Administrators A - 389


Practice 20-1: Repairing a Database by Using Enterprise
Manager (continued)
2) Continue when you see the lines: “Basic setup done. Now, run one of the
setup scripts for a specific scenario.” To set up a data failure and shut
down the database, execute the following command in your terminal window:
./dra1_corruption.sh
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

The users2.dbf data file is deleted and the example2.dbf file renamed. You will
diagnose and repair these failures, by using both manual repair and automated repair
options.
$ ./dra1_corruption.sh
*******************************************
For demo purposes ONLY:
* Shutdown database

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 9 10:49:07 ble


2009 fe r a
t r a ns
Copyright (c) 1982, 2009, Oracle. All rights reserved.
o n -
Connected to: s an
Oracle Database 11g Enterprise Edition Release
r ) ha d11.2.0.1.0
e ฺ -
Production ฺ a u i
With the Partitioning, Automaticco m ntManagement,
Storage G OLAP,
n ฺ e
Data Mining and Real Application
@ ao StudTesting options

SQL> Database closed.


z i l le this
Database dismounted.
e oฺ use
lshut
ORACLE instance
a r c t o down.

e ( m nse
SQL> Disconnected from Oracle Database 11g Enterprise Edition

Z ill the11.2.0.1.0
Release
With l i ce
Partitioning,
- Production
Automatic Storage Management, OLAP,
rc eloData Mining and Real Application Testing options
Ma *******************************************
For demo purposes ONLY:
* Corrupt datafiles to produce failures
$
3) Use Enterprise Manager to repair the situation as quickly as possible.
a) Log in to Enterprise Manager as the SYS user with the oracle_4U password and
connect as SYSDBA.
b) If you cannot access Enterprise Manager Database Control, stop and start it using
the following commands:
$ emctl stop dbconsole
Oracle Enterprise Manager 11g Database Control Release
11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation. All rights
reserved.
https://ed.us.oracle.com:5500/em/console/aboutApplication
Stopping Oracle Enterprise Manager 11g Database Control ...

Oracle Database 11g: New Features for Administrators A - 390


Practice 20-1: Repairing a Database by Using Enterprise
Manager (continued)
all attemps to stop oc4j failed... now trying to kill 9
--- Failed to shutdown DBConsole Gracefully ---
... Stopped.
$ emctl start dbconsole
Oracle Enterprise Manager 11g Database Control Release
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation. All rights
reserved.
https://ed.us.oracle.com:5500/em/console/aboutApplication
Starting Oracle Enterprise Manager 11g Database Control
........... started.
--------------------------------------------------------------
Logs are generated in directory
/u01/app/oracle/acfsmounts/acfs_db1/ed.us.oracle.com_orcl/sysm
ble
an/log
fe r a
$
ans
c) You encounter a “down” database. Click Startup. n - t r
o
an
d) Specify all needed credentials on the Startup/Shutdown page. Use
s
r ) ha deฺ
oracle/oracle for your host and SYS/oracle_4U as SYSDBA for your
database. Click OK.
m ฺa Gui
n ฺ co ent
e) On the Select Startup Type page, make sure that Start database along with
ao Stud
dependent resources is selected (it should be the default), and click OK.
@
l le this
f) On the Startup/Shutdown: Confirmation page, click Yes.
z i
c e loฺ use
g) The Startup page appears for a while. Wait.
a r to
h) The Startup/Shutdown: Select Operation page appears with an error message
m e
i l l e ( icens
indicating that one file cannot be found.

el oZ l
i) Make sure orcl is selected and click Startup.

Marc j) On the Confirmation page, click the Advanced Options button.


k) On the Advanced Options page, select Mount the database, and click OK.
l) On the Confirmation page, click Yes.
m) Wait on the Startup page.
n) You then get a Startup Successful message on the Startup/Shutdown: Select
Operation page. Click Return.
o) After a while you are taken to the Database Instance page. On the Database
Instance page, click the Perform Recovery button to diagnose the failures and
perform a repair.
p) On the Perform Recovery: Credentials page enter oracle as username and
password, and then click Continue. (If you previously selected Save Credentials,
this page does not appear.)
q) On the Database Login page, enter SYS/oracle_4U as SYSDBA as credentials,
and then click Login.

Oracle Database 11g: New Features for Administrators A - 391


Practice 20-1: Repairing a Database by Using Enterprise
Manager (continued)
r) If the Perform Recovery: Credentials page appears, enter oracle/oracle as
your host credentials. Click Continue.
s) On the Perform Recovery page, click the Advise and Recover button in the Oracle
Advised Recovery section.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

t) This takes you to the View and Manage Failures page. When the opening of the
database failed, the Data Recovery Advisor automatically diagnosed the problem.
View the result of this diagnosis. Click the “+” icon under Failure Description to
view more details. You can see two missing files.
u) To view suggested repair strategies, leave all failures selected and click the
Advise button.
v) The Manual Actions page appears, in which the Data Recovery Advisor prompts
you to consider manual repairs. Do NOT click any buttons at this time. Perform ble
the next step. fe r a
an s
t
w) This practice assumes that the example01.dbf data file was renamed by error.
n - r
no
In a terminal window, enter the following commands to manually repair the
a
failure: s ฺ
h a
$
$ mv /u01/app/oracle/oradata/example2.dbf.old ฺ a r) uide
/u01/app/oracle/oradata/example2.dbf ฺ c om ent G
$ a on tud
S
le@pagethinisEnterprise
x) Return to the Manual z i l
Actions Manager. Because you
ฺ steps,seclick Re-assess Failures.
l
completed the previouso
a r ce to u
y) The Data mRecovery eAdvisor revalidates all failures and closes the ones that you
e ( n s
Z ll icon lunder
manually
i“+” repaired.
i On the View and Manage Failures page, if necessary, click the
ce Failure Description to expand the node and to see any other
el o
Marc outstanding failures.
z) Note that the failure, which you manually repaired, is closed, but there is still
another open failure. Leave it selected and click Advise.
aa) On the Manual Actions page, click “Continue with Advise” to initiate an
automated repair.
bb) On the Recovery Advise page, the Data Recovery Advisor generates and displays
an RMAN repair script. Click Continue.
cc) On the Review page, you can review the failure and the repair script that will
address this failure. Click Execute Recovery.
dd) Wait for the repair execution to complete. When the Data Recovery Advisor is
finished, it displays the Recovery Results page with a Recovery Succeeded
message at the top. Review all repair results. Scroll down the page using the
vertical scroll bar.
ee) Click Open Database.

Oracle Database 11g: New Features for Administrators A - 392


Practice 20-1: Repairing a Database by Using Enterprise
Manager (continued)
ff) After a successful repair, the database has been opened. On the Recovery Results
page, click OK.
gg) Enterprise Manager displays the Login page. Log in with the SYS/oracle_4U
as SYSDBA credentials.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

hh) On the Database Instance home page, confirm that the database instance is up and
running. This may take a couple of minutes (or seconds, depending on your
available system resources) and some refreshes before you can see it opened.

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 393


Practice 20-2: Repairing Block Corruption by Using Enterprise
Manager
To diagnose and repair block corruption, perform the following steps:
1) To set up block corruptions in your example01.dbf data file, use a terminal
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

window, navigate to the /home/oracle/solutions/DRA directory, and


execute the dra2_corruption.sh script.
Block corruption errors typically appear in this form to application users. DBAs can
see the same error on the Enterprise Manager Database Control home page. (See the
next step.) However, there is a slight delay due to internal processing between error
discovery and Enterprise Manager displaying the error.
$ cd /home/oracle/solutions/DRA
$ . oraenv
ORACLE_SID = [orcl] ? orcl ble
The Oracle base for fe r a
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is ans
/u01/app/oracle n - t r
$ ./dra2_corruption.sh
a no
*******************************************
h a s ฺ
For demo purposes ONLY:
Create block corruption for scenario 2 ฺ a r) uide
Please wait setup in process
ฺ c om ent G
a n ud
oProduction
SQL*Plus: Release 11.2.0.1.0 @ S t on Fri Oct 9 11:12:53
l l e i s
2009
l o ฺzi se th
Copyright (c) e o2009,
rc1982, u Oracle. All rights reserved.
a t
l e (m ense
SQL>
Zi l Connected.
lic
oSQL>
l
e dd of=/u01/app/oracle/oradata/example2.dbf bs=8192
rc
Ma conv=notrunc seek=131 << EOF
CORRUPT corrupt CORRUPT corrupt CORRUPT corrupt CORRUPT
corrupt CORRUPT corrupt
EOF

dd of=/u01/app/oracle/oradata/example2.dbf bs=8192
conv=notrunc seek=147 << EOF
CORRUPT corrupt CORRUPT corrupt CORRUPT corrupt CORRUPT
corrupt CORRUPT corrupt
EOF

dd of=/u01/app/oracle/oradata/example2.dbf bs=8192
conv=notrunc seek=139 << EOF
CORRUPT corrupt CORRUPT corrupt CORRUPT corrupt CORRUPT
corrupt CORRUPT corrupt
EOF

Disconnected from Oracle Database 11g Enterprise Edition


Release 11.2.0.1.0 - Production

Oracle Database 11g: New Features for Administrators A - 394


Practice 20-2: Repairing Block Corruption by Using Enterprise
Manager (continued)
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
0+1 records in
0+1 records out
246 bytes (246 B) copied, 0.0158417 seconds, 15.5 kB/s
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

0+1 records in
0+1 records out
246 bytes (246 B) copied, 0.0026572 seconds, 92.6 kB/s
0+1 records in
0+1 records out
246 bytes (246 B) copied, 0.0326892 seconds, 7.5 kB/s

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 9 11:12:54


2009
ble
fe r a
Copyright (c) 1982, 2009, Oracle. All rights reserved.
ans
n - t r
SQL> Connected.
SQL> a no
System altered. h a s ฺ
ฺ a r) uide
select * from hr.regions2
* ฺ c om ent G
ERROR at line 1: a on tud
ORA-01578: ORACLE data l e@ corrupted
block i s S (file # 8, block # 131)
z i l t h
ORA-01110: data file
c e loฺ use 8: '/u01/app/oracle/oradata/example2.dbf'

select * from a r hr.locations2


to
m e
i l l eat( line
c e n1:s *
l o Z
ERROR
ORA-01578:
li ORACLE data block corrupted (file # 8, block # 139)
rc e
Ma
ORA-01110: data file 8: '/u01/app/oracle/oradata/example2.dbf'

select * from hr.employees2


*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 8, block # 147)
ORA-01110: data file 8: '/u01/app/oracle/oradata/example2.dbf'

Disconnected from Oracle Database 11g Enterprise Edition


Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Setup 2 completed.
$
2) Use Enterprise Manager to quickly address these errors.
a) Log in to Enterprise Manager with the SYS/oracle_4U as SYSDBA credentials.
b) On the Database Instance home page, click Advisor Central.

Oracle Database 11g: New Features for Administrators A - 395


Practice 20-2: Repairing Block Corruption by Using Enterprise
Manager (continued)
c) Click Data Recovery Advisor.
d) Click the “+” icon under Failure Description to expand the node for more details.
e) On the View and Manage Failures page, view the details of the block corruptions.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Enter oracle as Host and Password credentials, if they are not previously saved.
Leave all failures selected and click Advise.
f) On the Recovery Advice page, view the repair script and click Continue.
g) On the Review page, you can review the failures and the suggested repairs. Click
Submit Recovery Job.
h) On the Job Activity page, you should receive a confirmation, that your job was
created successfully.
ble
i) On the Job Activity page, you may or may not see the job “running” status,
fe r a
depending on how quickly the job is completed. Periodically, click your
an s
browser’s Reload or Refresh button. The job is completed, when the job
n - t r
“running” status no longer appears. Click the job name link under the
a no
confirmation message.
h a s ฺ
j) On the Job Run page, confirm that your job executed
ฺ a u ide and click the
r) successfully,
Database tab on the top right part of the page.
ฺ c om ent G
n Database
k) View the block corruption alertsaon
monitor this page regularly, @so
othe
they would S tbeudableInstance
to see
home page. DBAs
the block corruption
i l l e h i s
e l o z auslight
alerts (which appear ฺwith
s e tdelay).
3) To confirm that rthe
a c blocktcorruption
o is repaired, execute the following commands in
m
a terminal(window: e
nsHR.REGIONS2;
i
SELECT l l e * FROM
c e
l o Z li
rc e $
Ma $ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 9 11:35:11


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> select * from hr.regions2;

REGION_ID REGION_NAME
---------- -------------------------
1 Europe
2 Americas

Oracle Database 11g: New Features for Administrators A - 396


Practice 20-2: Repairing Block Corruption by Using Enterprise
Manager (continued)
3 Asia
4 Middle East and Africa

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Release 11.2.0.1.0 - Production


With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
$

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
el oZ l
Marc

Oracle Database 11g: New Features for Administrators A - 397


Practice 20-3: Repairing a Database by Using RMAN
To diagnose and repair a down database, perform the following steps:
1) To set up a data failure and shut down the database, use a terminal window, navigate
to the /home/oracle/solutions/DRA directory, and execute the
dra1_corruption.sh script.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

The users01.dbf data file is deleted and the example01.dbf file renamed.
You will diagnose and repair these failures, by using both manual repair and
automated repair options.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/acfsmounts/acfs_db1 is
/u01/app/oracle ble
$ cd /home/oracle/solutions/DRA
fe r a
$
ans
$ ./dra1_corruption.sh
n - t r
*******************************************
For demo purposes ONLY: a no
* Shutdown database h a s ฺ
ฺ a r) uide
SQL*Plus: Release 11.2.0.1.0 Production
ฺ c om enont GFri Oct 9 11:39:01
2009
a on tud
Copyright (c) 1982, 2009, l e@Oracle.
i s S All rights reserved.
i l h
Connected to:cel
oฺz use t
a
Oracle Database
r 11gtoEnterprise Edition Release 11.2.0.1.0 -
e
Production
l ( ense
m
With
l
Zi the Partitioning,
lic Automatic Storage Management, OLAP,
e l oData Mining and Real Application Testing options
rc
Ma SQL> Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
*******************************************
For demo purposes ONLY:
* Corrupt datafiles to produce failures
$
2) Because you find your database in a down state, try to start it.
a) Note that the database is mounted and has a data file error.
$ sqlplus /nolog

Oracle Database 11g: New Features for Administrators A - 398


Practice 20-3: Repairing a Database by Using RMAN (continued)
SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 9 11:40:08
2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

SQL> connect / as sysdba


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Connected to an idle instance.


SQL> startup
ORACLE instance started.

Total System Global Area 422670336 bytes


Fixed Size 1336960 bytes
Variable Size 318769536 bytes
Database Buffers 96468992 bytes
Redo Buffers 6094848 bytes
ble
Database mounted.
fe r a
ORA-01157: cannot identify/lock data file 7 - see DBWR trace
ans
file
ORA-01110: data file 7: '/u01/app/oracle/oradata/users2.dbf' n - t r
a no
SQL>
h a s ฺ
3) Exit SQL*Plus and start RMAN. ฺ a r) uide
SQL> exit ฺ c om ent G
Disconnected from Oracle Databasea on t11g ud Enterprise Edition
@
leAutomatic
Release 11.2.0.1.0 - lProduction S
is Storage Management, OLAP,
z i t h
Data Mining and e oฺ Application
With the Partitioning,
lReal u se Testing options
$ rman targeta c
r / nocatalog
t o
l e (m ense
Zi l
Recovery lic
Manager: Release 11.2.0.1.0 - Production on Fri Oct 9
e l o11:42:14 2009
rc
Ma Copyright (c) 1982, 2009, Oracle and/or its affiliates. All
rights reserved.

connected to target database: ORCL (DBID=1226549444, not open)


using target database control file instead of recovery catalog

RMAN>
4) List failures and failure details.
RMAN> LIST FAILURE;

List of Database Failures


=========================

Failure ID Priority Status Time Detected Summary


---------- -------- --------- ------------- -------
422 HIGH OPEN 09-OCT-09 One or more non-
system datafiles are missing

Oracle Database 11g: New Features for Administrators A - 399


Practice 20-3: Repairing a Database by Using RMAN (continued)

RMAN> LIST FAILURE DETAIL;

List of Database Failures


=========================
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Failure ID Priority Status Time Detected Summary


---------- -------- --------- ------------- -------
422 HIGH OPEN 09-OCT-09 One or more non-
system datafiles are missing
Impact: See impact for individual child failures
List of child failures for parent failure ID 422
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
526 HIGH OPEN 09-OCT-09 Datafile 8:
ble
'/u01/app/oracle/oradata/example2.dbf' is missing
fe r a
Impact: Some objects in tablespace EXAMPLE2 might be
ans
unavailable
520 HIGH OPEN 09-OCT-09 Datafile 7: n - t r
'/u01/app/oracle/oradata/users2.dbf' is missing a no
Impact: Some objects in tablespace USERS2 might be
h a s ฺ
unavailable
RMAN> ฺ a r) uide
ฺ c om ent G
5) Diagnose the failures.
a on tud
a) You should see two failures.l e@You will
i s S to this window after the next step.
return
i l h
RMAN> ADVISE FAILURE;
e l oฺz use t
a rc to
List of(m e
i l l e icens
Database Failures
=========================
l o Z l
rc e Failure ID Priority Status Time Detected Summary
Ma ---------- -------- --------- ------------- -------
422 HIGH OPEN 09-OCT-09 One or more non-
system datafiles are missing
Impact: See impact for individual child failures
List of child failures for parent failure ID 422
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
526 HIGH OPEN 09-OCT-09 Datafile 8:
'/u01/app/oracle/oradata/example2.dbf' is missing
Impact: Some objects in tablespace EXAMPLE2 might be
unavailable
520 HIGH OPEN 09-OCT-09 Datafile 7:
'/u01/app/oracle/oradata/users2.dbf' is missing
Impact: Some objects in tablespace USERS2 might be
unavailable

analyzing automatic repair options; this may take some time


allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=24 device type=DISK

Oracle Database 11g: New Features for Administrators A - 400


Practice 20-3: Repairing a Database by Using RMAN (continued)
analyzing automatic repair options complete

Mandatory Manual Actions


========================
no manual actions available
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Optional Manual Actions


=======================
1. If file /u01/app/oracle/oradata/users2.dbf was
unintentionally renamed or moved, restore it
2. If file /u01/app/oracle/oradata/example2.dbf was
unintentionally renamed or moved, restore it

Automated Repair Options


========================
ble
Option Repair Description
fe r a
------ ------------------
an s
1 Restore and recover datafile 7; Restore and recover
datafile 8 n - t r
Strategy: The repair includes complete media recovery with a no
no data loss
h a s ฺ
Repair script:
ฺ a
/u01/app/oracle/diag/rdbms/orcl/orcl/hm/reco_4235069421.hm
r) uide
ฺ c om ent G
RMAN> a on tud
l @ is S data file was renamed by error. Open
leexample2.dbf
6) This practice assumes thatzthei
ฺ and rename h
tthat
l o
e o us
another terminal window e file correctly to manually repair a failure.
a r c t
$ mv /u01/app/oracle/oradata/example2.dbf.old
m e
( s
ille licen
/u01/app/oracle/oradata/example2.dbf
$Z
elo
rc 7) Return to your RMAN window and check the results of your manual repair.
Ma a) You should see one failure.
RMAN> ADVISE FAILURE;

List of Database Failures


=========================

Failure ID Priority Status Time Detected Summary


---------- -------- --------- ------------- -------
422 HIGH OPEN 09-OCT-09 One or more non-
system datafiles are missing
Impact: See impact for individual child failures
List of child failures for parent failure ID 422
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
520 HIGH OPEN 09-OCT-09 Datafile 7:
'/u01/app/oracle/oradata/users2.dbf' is missing

Oracle Database 11g: New Features for Administrators A - 401


Practice 20-3: Repairing a Database by Using RMAN (continued)
Impact: Some objects in tablespace USERS2 might be
unavailable

analyzing automatic repair options; this may take some time


using channel ORA_DISK_1
analyzing automatic repair options complete
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Mandatory Manual Actions


========================
no manual actions available

Optional Manual Actions


=======================
1. If file /u01/app/oracle/oradata/users2.dbf was
unintentionally renamed or moved, restore it
ble
fe r a
Automated Repair Options
ans
========================
Option Repair Description n - t r
------ ------------------ a no
1 Restore and recover datafile 7
h a s ฺ
no data loss ฺ a r) uide
Strategy: The repair includes complete media recovery with

Repair script: ฺ c om ent G


on tud
/u01/app/oracle/diag/rdbms/orcl/orcl/hm/reco_3823931837.hm
a
l l e@ is S
RMAN> i
ฺz se th
l
e ouo
8) Review the repair
a rcscript. t
( m s e
cen
RMAN>
Z illeREPAIR
l i
FAILURE PREVIEW;

lo
rce Strategy: The repair includes complete media recovery with no
Ma data loss
Repair script: Repair script:
/u01/app/oracle/diag/rdbms/orcl/orcl/hm/reco_3823931837.hm

contents of repair script:


# restore and recover datafile
restore datafile 7;
recover datafile 7;

RMAN>
9) Initiate an automated repair, then restart your database, and exit RMAN.
RMAN> REPAIR FAILURE;

Strategy: The repair includes complete media recovery with no


data loss
Repair script: Repair script:
/u01/app/oracle/diag/rdbms/orcl/orcl/hm/reco_3823931837.hm

Oracle Database 11g: New Features for Administrators A - 402


Practice 20-3: Repairing a Database by Using RMAN (continued)
contents of repair script:
# restore and recover datafile
restore datafile 7;
recover datafile 7;

Do you really want to execute the above repair (enter YES or


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

NO)? YES
executing repair script

Starting restore at 09-OCT-09


using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore


channel ORA_DISK_1: specifying datafile(s) to restore from
backup set
ble
channel ORA_DISK_1: restoring datafile 00007 to
fe r a
/u01/app/oracle/oradata/users2.dbf
ans
channel ORA_DISK_1: reading from backup piece
+FRA/orcl/backupset/2009_10_09/nnndf0_tag20091009t103547_0.296 n - t r
o
.699791891
s an
channel ORA_DISK_1: piece
r ) ha deฺ
handle=+FRA/orcl/backupset/2009_10_09/nnndf0_tag20091009t10354
7_0.296.699791891 tag=TAG20091009T103547 m ฺa Gui
channel ORA_DISK_1: restored backup piece 1
n ฺ co ent
Finished restore at 09-OCT-09 @ ao Stud
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

z i l le this
Starting recover
c e loatฺ 09-OCT-09
u se
using channel a r ORA_DISK_1
to
m e
i l l
starting e ( media
c e nsrecovery
l o Z li
rc e archived log for thread 1 with sequence 119 is already on disk
Ma as file
+FRA/orcl/archivelog/2009_10_09/thread_1_seq_119.301.699792001
archived log for thread 1 with sequence 120 is already on disk
as file
+FRA/orcl/archivelog/2009_10_09/thread_1_seq_120.300.699792003
archived log for thread 1 with sequence 121 is already on disk
as file
+FRA/orcl/archivelog/2009_10_09/thread_1_seq_121.299.699792005
channel ORA_DISK_1: starting archived log restore to default
destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=115
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=116
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=117
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=118

Oracle Database 11g: New Features for Administrators A - 403


Practice 20-3: Repairing a Database by Using RMAN (continued)
channel ORA_DISK_1: reading from backup piece
+FRA/orcl/backupset/2009_10_09/annnf0_tag20091009t103929_0.303
.699791971
channel ORA_DISK_1: piece
handle=+FRA/orcl/backupset/2009_10_09/annnf0_tag20091009t10392
9_0.303.699791971 tag=TAG20091009T103929
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

channel ORA_DISK_1: restored backup piece 1


channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
archived log file
name=+FRA/orcl/archivelog/2009_10_09/thread_1_seq_115.293.6997
96223 thread=1 sequence=115
channel default: deleting archived log(s)
archived log file
name=+FRA/orcl/archivelog/2009_10_09/thread_1_seq_115.293.6997
96223 RECID=24 STAMP=699796225
ble
archived log file
fe r a
name=+FRA/orcl/archivelog/2009_10_09/thread_1_seq_116.291.6997
ans
96225 thread=1 sequence=116
channel default: deleting archived log(s) n - t r
o
archived log file
s an
96225 RECID=26 STAMP=699796226 r ) ha deฺ
name=+FRA/orcl/archivelog/2009_10_09/thread_1_seq_116.291.6997

archived log file m ฺa Gui


n ฺ co ent
name=+FRA/orcl/archivelog/2009_10_09/thread_1_seq_117.292.6997
96225 thread=1 sequence=117
@ ao Stud
channel default: deleting archived log(s)
archived log file z i l le this
c e loฺ use
name=+FRA/orcl/archivelog/2009_10_09/thread_1_seq_117.292.6997
r to
96225 RECID=25 STAMP=699796225
a
m e
i l e ( icens
archived log file
l
name=+FRA/orcl/archivelog/2009_10_09/thread_1_seq_118.290.6997
el oZ l
96227 thread=1 sequence=118

Marc channel default: deleting archived log(s)


archived log file
name=+FRA/orcl/archivelog/2009_10_09/thread_1_seq_118.290.6997
96227 RECID=27 STAMP=699796227
archived log file
name=+FRA/orcl/archivelog/2009_10_09/thread_1_seq_119.301.6997
92001 thread=1 sequence=119
media recovery complete, elapsed time: 00:00:04
Finished recover at 09-OCT-09
repair failure complete

Do you want to open the database (enter YES or NO)? YES


database opened

RMAN> exit

Recovery Manager complete.


$
10) Using SQL*Plus, test that your database is up and running now.

Oracle Database 11g: New Features for Administrators A - 404


Practice 20-3: Repairing a Database by Using RMAN (continued)
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 9 11:56:06


2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> select open_mode from v$database;


ble
OPEN_MODE
fe r a
--------------------
ans
READ WRITE
n - t r
SQL> exit a no
Disconnected from Oracle Database 11g Enterprise Edition
h a s ฺ
Release 11.2.0.1.0 - Production
ฺ a r) uide
With the Partitioning, Automatic Storage Management, OLAP,
c
Data Mining and Real Application Testing options
ฺ om ent G
$ a on tud
l e@ the i s S
i
11) To clean up your environment,l
ฺz se t h
execute dra_cleanup.sh script.
l o
e ou
a c
$ ./dra_cleanup.sh
r t
*******************************************
( m s e
ofndemo:
Z lle liceaccount
For cleanup
*i Lock HR
rc elo * Disable ARCHIVELOG mode
Ma SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 9 11:57:14
2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
With the Partitioning, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> SQL>
Tablespace dropped.

SQL>
Tablespace dropped.

SQL> SQL>

Oracle Database 11g: New Features for Administrators A - 405


Practice 20-3: Repairing a Database by Using RMAN (continued)
User altered.

SQL>
System altered.

SQL> SQL> Database closed.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Database dismounted.
ORACLE instance shut down.
SQL> ORACLE instance started.

Total System Global Area 422670336 bytes


Fixed Size 1336960 bytes
Variable Size 318769536 bytes
Database Buffers 96468992 bytes
Redo Buffers 6094848 bytes
ble
Database mounted.
fe r a
SQL>
ans
Database altered.
n - t r
SQL> a no
Database altered.
h a s ฺ
SQL> Database log mode ฺ a
No Archive
r) Mode
u ide
Automatic archival ฺ c om ent G
Disabled
Archive destination a on USE_DB_RECOVERY_FILE_DEST
tud
Oldest online log sequence @
le this122 S
120
Current log sequence z i l
SQL> SQL> "Cleanup
c e loฺ finished."
u se
ar e from
SQL> Disconnected
Release(m
t-oProduction
Oracle Database 11g Enterprise Edition

i
With l l c ns
11.2.0.1.0
ethe Partitioning,
e Automatic Storage Management, OLAP,
l o Z li
Data Miningand Real Application Testing options
rc e $
Ma

Oracle Database 11g: New Features for Administrators A - 406


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Scheduler Enhancements

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
i l lic
el oZ
Marc
Objectives
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

After completing this lesson, you should be able to:


• Use lightweight jobs
• Use Scheduler email notification
• Create a file watcher
• Create remote database jobs
• Create multiple destination jobs ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
i l lic
el oZ
Marc

Oracle Database 11g: New Features for Administrators B - 2


Lightweight Jobs
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Persistent lightweight jobs:


• Created from a job template
• Recoverable
• JOB_STYLE => LIGHTWEIGHT

ble
fe r a
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Lightweight i l
ZJobs lic
l o
rcecustomers need to create hundreds of jobs each second. With regular jobs, each job
Some
a
M creates a database object describing the job, modifying several tables, and creating redo in the
process. In the Oracle Database 11g Scheduler, there is a persistent lightweight job. The goal
of a lightweight job is to reduce the overhead and the time required to start a job. A minimal
amount of metadata is created for the job. This reduces the time required and the redo created
when the job starts.
To achieve these goals, the lightweight job has a small footprint on disk for the job metadata
and for storing run-time data. The footprint on disk also makes recovery and load balancing
possible in RAC environments. The lightweight job is always created from a job template,
which can be a stored procedure or a program. The stored procedure holds all the information
needed for the job. A few job attributes may be set (such as job arguments).
Job templates are created by using the DBMS_SCHEDULER.CREATE_PROGRAM procedures.
Oracle Database 11g continues to support the database object–based jobs that have existed
since Oracle Scheduler was first introduced in Oracle 10g. Lightweight jobs are not intended
to replace these jobs because each job type has its own advantages and gives you the flexibility
to choose a job based on your needs.

Oracle Database 11g: New Features for Administrators B - 3


Choosing the Right Job
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• Regular job
– Highest overhead
– Best recovery
– Most flexible
• Persistent lightweight job
– Less overhead ble
– Some recovery fe r a
ans
– Limited change to attributes n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Choosing the
l
Zi RightliJobc
e l o
a rcadvantages
The and disadvantages of the types of jobs are as follows:
M • A regular job offers maximum flexibility but entails a significant overhead in create/drop
performance. A job can be created with a single command. Users have fine-grained
control of privileges on the job and can also use programs or stored procedures owned by
other users. A regular job requires the job database object to be created and dropped. This
action updates several tables and the associated redo. Users who are creating a relatively
small number of jobs that run relatively infrequently should choose regular jobs.
• A persistent lightweight job has a significant improvement in create/drop time because it
does not have the overhead of creating a database object. Every lightweight job is created
from a job template, which is stored as a program. Because persistent lightweight jobs
write state information to disk at run time, only a small improvement is expected in
execution. There are several limitations to persistent lightweight jobs:
- Users cannot set privileges on these jobs. Instead, they inherit their privileges from
the parent job template.
- The use of a template is mandatory. It is not possible to create a fully self-contained
persistent lightweight job.
- Only certain job attributes are available to be set, such as JOB_ARGUMENTS.
Lightweight jobs are most useful when the user needs to create a large number of jobs in a
very short time (from 10 to 100 jobs a second) and has a library of programs (job
templates) available for use.

Oracle Database 11g: New Features for Administrators B - 4


11.2

Scheduler Email Notification: Overview


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• Jobs can be configured so that email notifications are


sent when the job changes state.
• Email messages can be triggered by any event in a list
of specified job state events, such as when a job fails.
• More than one email notification can be configured for
a job. le
a b
• An email message can be sent to multiple recipients.sfer
tra n
o n -
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
Scheduler Z l
i Notification:
Email lic Overview
l o
e email notification feature enables you to add email notifications to existing jobs so
The
a rcjob
M that events of interest that happen to the job are emailed to specified email addresses. For each
job, you can add notifications for different events. You can send the email notification to more
than one recipient.

Oracle Database 11g: New Features for Administrators B - 5


11.2

Using Scheduler Email Notification


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• To use Scheduler email notification, perform the


following configuration steps on each database:
– Set the Scheduler email_server attribute to the
address of the SMTP server you will use to send email
message.
– Optionally, set the Scheduler email_sender attribute to
a default sender email address. bl e
fe r a
• For each job for which you want the system to send
t r a ns
email messages, perform the following: on- n
– Use the s a
) a
h deฺ
r
DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION
ฺa for uai specified job.
m
procedure to add email notifications
o t G
o n ฺc den
@ a Stu
z i l l e t h is

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
l
Zi Email
Using Scheduler lic Notification
l o
To
a ce the email notification feature, perform the following one-time configuration steps
renable
Mon each database:
• Set the email_server Scheduler attribute.
• Optionally, you can use the email_sender Scheduler attribute to specify a default
sender email address for the email notifications.
After creating a job, execute the DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION
procedure to add one or more notifications for the job.
Additional information is provided on the following pages.

Oracle Database 11g: New Features for Administrators B - 6


11.2

Setting the email_server Attribute


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Specify an SMTP server address that the Scheduler will


use to send email notifications for job state events:
DBMS_SCHEDULER.SET_SCHEDULER_ATTRIBUTE
('email_server','host[:port]');

ble
fe r a
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
i l
Setting theZemail_serverlic Attribute
e l o
The
a rcScheduler email_server attribute specifies an SMTP server address that the Scheduler
Muses to send email notifications for job state events. The format for the attribute is
host[:port] where host is the host name or IP address of the SMTP server, and port is
the TCP port on which the SMTP server listens. If port is not specified, a default port of 25
is used.
If you do not set the email_server attribute, set it to NULL, or set it to an invalid SMTP
server address, the Scheduler cannot send job state email notifications. SMTP servers that
require secure sockets layer (SSL) connections or require user authentication are not
supported.

Oracle Database 11g: New Features for Administrators B - 7


11.2

Setting the email_sender Attribute


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Specify a default email address of the sender for job state


email notifications:
DBMS_SCHEDULER.SET_SCHEDULER_ATTRIBUTE
('email_sender','valid email address');

ble
fe r a
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
i l
Setting theZemail_senderlic Attribute
l o
e use the email_sender attribute to specify a default email address of the sender for
You
a rccan
Mjob state email notifications. The email address specified must be valid. If you do not set this
attribute or set it to NULL, job state email notifications that do not specify a sender address
will not have a FROM address in the email header.

Oracle Database 11g: New Features for Administrators B - 8


11.2

Using ADD_JOB_EMAIL_NOTIFICATION

DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION (
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

job_name IN VARCHAR2,
recipients IN VARCHAR2,
sender IN VARCHAR2 DEFAULT NULL,
subject IN VARCHAR2
DEFAULT dbms_scheduler.default_notification_subject,
body IN VARCHAR2
DEFAULT dbms_scheduler.default_notification_body,
a b le
er
events IN VARCHAR2
n
DEFAULT 'JOB_FAILED,JOB_BROKEN,JOB_SCH_LIM_REACHED, s f
JOB_CHAIN_STALLED,JOB_OVER_MAX_DUR',-tra
filter_condition non
IN VARCHAR2 DEFAULT NULL);
a
a
h deฺs
r
ฺa Gui)
co entm
n ฺ
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
Zi l lic
Using ADD_JOB_EMAIL_NOTIFICATION
e l o
The
a rcDBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION procedure adds one or more
Mjob email notifications. Email messages will be sent to the specified recipient addresses
whenever any of the listed events are generated by the job. The job is automatically modified
to raise these events. If a filter condition is specified, only events that match the specification
in FILTER_CONDITION will generate an email message.
This procedure will fail if the EMAIL_SERVER scheduler attribute is not set or if the specified
job does not exist.
Note: The user calling this procedure must be the owner of the job, have the CREATE ANY
JOB system privilege, or have been granted the ALTER privilege for the job.
Procedure arguments are as follows:
• JOB_NAME: Name of the job for which email notifications will be sent. The value cannot
be NULL.
• RECIPIENTS: Comma-separated list of email addresses to send notifications to. Email
notifications will be sent to all specified email addresses. The value cannot be NULL.
• SENDER: Email address to use as the sender for email notifications. If NULL, the value
of the DEFAULT_EMAIL_SENDER scheduler attribute (if it is a valid email address) will
be used.

Oracle Database 11g: New Features for Administrators B - 9


Using ADD_JOB_EMAIL_NOTIFICATION (continued)
• SUBJECT: Subject of notification emails and can contain the following variables for
which values will be substituted: %job_owner%, %job_name%,
%event_type%, %event_timestamp%, %log_id%, %error_code%,
%error_message%, %run_count%, %failure_count%,
%retry_count%, %job_subname%, %job_class_name%
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• BODY: Used as the notification email message body; can contain any of the variables that
are valid in the SUBJECT
• EVENTS: Comma-separated list of events that email notifications will be sent for; cannot
be NULL. Refer to the list of events for the RAISE_EVENTS attribute of JOBS for valid
events.
• FILTER_CONDITION: Used to filter events for which email notifications are sent. If it
is NULL (the default), all occurrences of the specified events will be emailed to all
e
specified recipient addresses.
fer abl
a n s
n - tr
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this
c e loฺ use
a r to
m e
i l l e ( icens
e loZ l
M arc

Oracle Database 11g: New Features for Administrators B - 10


11.2

Using REMOVE_JOB_EMAIL_NOTIFICATION
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

DBMS_SCHEDULER.REMOVE_JOB_EMAIL_NOTIFICATION (
job_name IN VARCHAR2,
recipients IN VARCHAR2 DEFAULT NULL,
events IN VARCHAR2 DEFAULT NULL);
bl e
fe r a
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Zi l lic
Using REMOVE_JOB_EMAIL_NOTIFICATION
e l o
The
a rcDBMS_SCHEDULER.REMOVE_JOB_EMAIL_NOTIFICATION procedure is used to
Mremove one or more email notifications for the specified job.
Note: The user calling this procedure must be the owner of the job, have the CREATE ANY
JOB system privilege, or have been granted the ALTER privilege for the job.
Procedure arguments are as follows:
• JOB_NAME: Name of the job for which email notifications will be removed; cannot be
NULL
• RECIPIENTS: Comma-separated list of email addresses to remove notifications for. If
the value is NULL, all notifications for the given job and specified events will be
removed.
• EVENTS: Comma-separated list of events for which to remove email notifications. If the
value is NULL, all notifications for the given job and the specified email addresses will be
removed.

Oracle Database 11g: New Features for Administrators B - 11


11.2

Email Notification: New Dictionary Views


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Query the following views to determine what email


notifications have been set:
• DBA_SCHEDULER_NOTIFICATIONS
• ALL_SCHEDULER_FILE_NOTIFICATIONS
• USER_SCHEDULER_FILE_NOTIFICATIONS
ble
fe r a
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Zi l
Email Notification: lic Dictionary Views
New
l o
rceare three new views with email notification information:
There
a
MDBA_SCHEDULER_NOTIFICATIONS, ALL_SCHEDULER_NOTIFICATIONS, and
USER_SCHEDULER_NOTIFICATIONS.
The DBA_SCHEDULER_NOTIFICATIONS and ALL_SCHEDULER_NOTIFICATIONS
views have the following columns (the USER_ view does not have an OWNER column):
• OWNER: Owner of the job the notification is for
• JOB_NAME: Name of the job the notification is for
• JOB_SUBNAME: Subname of the job the notification is for
• RECIPIENT: Email address to send this email notification to
• SENDER: Email address to send this email notification from
• SUBJECT: Subject of the email notification
• BODY: Body of the email notification
• FILTER_CONDITION: Filter specifying which job events to send emails for
• EVENT: Job event to send emails for
• EVENT_FLAG: Event number of the job event to send emails for

Oracle Database 11g: New Features for Administrators B - 12


11.2

Scheduler File Watcher: Overview


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• Scheduler has a built-in functionality that enables it to


“watch” for files on the local system or on a remote
system.
• Scheduler raises an event that can be picked by event-
based jobs when it detects that the “watched” file has
arrived.
a b le
• The file watcher can be referenced by either event- fer
based jobs or schedules. t r a ns
o n -
n
• The file watching functionality on remoteamachines is
handled through the Scheduler agent. ha s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Scheduler Z l
i Watcher:
File lic Overview
l o
rcewatcher is a database object used to define the location, name, and other properties of a
Aafile
M file. When the file arrives on a system, the Scheduler starts a job. You create the file watcher
object by using the DBMS_SCHEDULER.CREATE_FILE_WATCHER procedure, and then
create any number of event-based jobs or event schedules that reference the file watcher.
When the file watcher detects the arrival of the specified file, it raises a file arrival event. The
job started by the file arrival event can retrieve the event message to obtain information about
the newly arrived file.
A file watcher can watch for a file on the local system (the server running Oracle Database) or
a remote system that is running the Scheduler agent.

Oracle Database 11g: New Features for Administrators B - 13


11.2

Creating a File Watcher and an Event-Based Job


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

To create a file watcher and create the event-based job


that starts when the designated file arrives, perform the
following tasks:
1. Create a Scheduler credential object (a credential) with
which to authenticate with the host operating system
for access to the file.
a b le
2. Create a file watcher.
s f er
3. Create a Scheduler program object with a metadata - t r an
argument that references the event message. n on
s a
4. Create an event-based job that references) a
h dethe ฺ file
r
ฺa Gu i
watcher. m
ฺ c o e n t
n
5. Enable the file watcher,athe
o program, and the job.
tud
@ is S
i l l e
l o ฺz se th
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Creatingoa Z
l
i Watcher
File lic and an Event-Based Job
l
e perform the tasks listed in the slide to create a file watcher and the event-based job
You
a rccan
M that starts when the specified file arrives. The steps are discussed in more detail on the
following pages.

Oracle Database 11g: New Features for Administrators B - 14


11.2

Step 1: Creating a Scheduler Credential Object


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• Create a credential for the operating system user that


requires access to the watched-for file:
BEGIN
DBMS_SCHEDULER.CREATE_CREDENTIAL('', '', '');
END;

• Grant EXECUTE on the credential to the schema that


a b le
owns the event-based job that the file watcher will nsfe
r
a
start: n-tr no
a
s ฺ
h a
GRANT EXECUTE ON credential_name to user_name;
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
l
Zi a Scheduler
Step 1: Creating lic Credential Object
l o
e watcher requires a Scheduler credential object (a credential) with which to
The
a rcfile
Mauthenticate with the host operating system for access to the file.
Note: EXECUTE on the credential does not need to be granted when the event-based job and
the credential reside in the same schema.

Oracle Database 11g: New Features for Administrators B - 15


11.2

Step 2: Creating a File Watcher


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• Create the file watcher:


BEGIN
DBMS_SCHEDULER.CREATE_FILE_WATCHER(
FILE_WATCHER_NAME => '',
DESTINATION =>,
DIRECTORY_PATH => '',
FILE_NAME => '',
ble
CREDENTIAL_NAME => '',
fe r a
ENABLED => );
ans
END;
n - t r
a no
• Grant EXECUTE on the file watcher tohany a s schema
ฺ that
r ) e
owns an event-based job that m ฺa Guidthe file
references
watcher: n ฺ co ent
GRANT EXECUTE ON file_watcher_name @ ao Stud to user_name;
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
l
Zi a File
Step 2: Creating lic Watcher
l o
rcethe file watcher by using the DBMS_SCHEDULER.CREATE_FILE_WATCHER
Create
a
Mprocedure. Additional information is provided on the next page.
Note: EXECUTE on the file watcher does not need to be granted when the event-based job and
the file watcher reside in the same schema.

Oracle Database 11g: New Features for Administrators B - 16


11.2

Using DBMS_SCHEDULER.CREATE_FILE_WATCHER

Argument Data type Default


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

FILE_WATCHER_NAME VARCHAR2 No default

DESTINATION VARCHAR2 NULL

DIRECTORY_PATH VARCHAR2 No default

FILE_NAME VARCHAR2 No default

VARCHAR2 No default ble


CREDENTIAL_NAME
fe r a
ans
MIN_FILE_SIZE PLS_INTEGER 0
n - t r
STEADY_STATE_DURATION INTERVAL DAY NULL a no
TO SECOND h a s ฺ
ฺ a r) uide
COMMENTS VARCHAR2
c o m nt GNULL

onBOOLEAN de
ENABLED
@ a S t u TRUE

z ill e t hi s
ฺ e
r c eloCopyright
o u©s2009, Oracle. All rights reserved.
a t
l e (m ense
Zi l lic
Using DBMS_SCHEDULER.CREATE_FILE_WATCHER
l o
e a database object called a file watcher by using the
rccreate
You
a
MDBMS_SCHEDULER.CREATE_FILE_WATCHER procedure. It has the following arguments:
• FILE_WATCHER_NAME: Name of the file watcher
• DESTINATION: Remote destination at which the file will arrive. If NULL, the
destination is the local machine.
• DIRECTORY_PATH: Directory in which file will be located. A single wildcard '?' is
permitted at the beginning of the path name and it will denote the value of
ORACLE_HOME. The value cannot be NULL.
• FILE_NAME: Name of the file that is being "watched." Two wildcards are permitted, '?'
(any single character) and '*' (any sequence of 0 or more characters). The value cannot be
NULL.
• CREDENTIAL_NAME: Name of a valid credential object. File watcher owner should have
execute privileges on this object if the create call is to succeed. The value cannot be
NULL.
• MIN_FILE_SIZE: Minimum size the file should be before the file watcher will report
that it is found; cannot be NULL.
• STEADY_STATE_DURATION: Minimum interval of time the file should stay unchanged
before the file watcher will report that it is found. If this is NULL, an internal default value
will be used.
• COMMENTS: Comments on this file watcher
• ENABLED: Whether this file watcher is enabled
Oracle Database 11g: New Features for Administrators B - 17
11.2

Step 3: Creating a Scheduler Program Object


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• Create the program:


BEGIN
DBMS_SCHEDULER.CREATE_PROGRAM(
PROGRAM_NAME => '',
PROGRAM_TYPE => 'STORED_PROCEDURE',
PROGRAM_ACTION => '',
NUMBER_OF_ARGUMENTS => 1,
ble
ENABLED => FALSE);
fe r a
END;
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
l
Zi a Scheduler
Step 3: Creating lic Program Object
l o
rcea Scheduler program object with a metadata argument that references the event
Create
a
Mmessage.

Oracle Database 11g: New Features for Administrators B - 18


11.2

Step 3: Creating a Scheduler Program Object


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• Define the metadata argument using the


EVENT_MESSAGE attribute:
BEGIN
DBMS_SCHEDULER.DEFINE_METADATA_ARGUMENT(
PROGRAM_NAME => '',
METADATA_ATTRIBUTE => 'event_message',
ARGUMENT_POSITION => 1);
bl e
END;
fe r a
t r a ns
• Create the stored procedure with an argument o n - type
of
n the
athat
SYS.SCHEDULER_FILEWATCHER_RESULT s
ha deฺ
program invokes. r
ฺa Gui)
co entm
n ฺ
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
l
Zi a Scheduler
Step 3: Creating lic Program Object (continued)
l o
rcecreate a stored procedure that the program invokes. The stored procedure must have an
Then
a
Margument of type SYS.SCHEDULER_FILEWATCHER_RESULT, which is the data type of
the event message. The position of that argument must match the position of the defined
metadata argument. The procedure can access attributes of this abstract data type to learn
about the arrived file. Additional information about
SYS.SCHEDULER_FILEWATCHER_RESULT is provided on the next page.

Oracle Database 11g: New Features for Administrators B - 19


11.2

Using the SCHEDULER_FILEWATCHER_RESULT


Object Type
Argument Data type Definition
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

DESTINATION VARCHAR2(4000) Destination at which the file


was found

DIRECTORY_PATH VARCHAR2(4000) Directory in which the file


was found

ACTUAL_FILE_NAME VARCHAR2(4000) Actual name of the file

ble
FILE_SIZE NUMBER Size of the file
fe r a
t r a ns
FILE_TIMESTAMP TIMESTAMP WITH TIME Timestamp of the file
o n -
ZONE
s an
TS_MS_FROM_EPOCH NUMBER
r ) ha deuseฺ only
For internal

m ฺ a Gui
MATCHING_REQUESTS SCHEDULER_FILEWAT
n ฺ co eDefined n t as a table of
CHER_REQ_LIST
@ ao Stud REQUEST SCHEDULER_FILEWATCHER_

z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
Zi l lic
Using the SCHEDULER_FILEWATCHER_RESULT Object Type
l o
a rce
SCHEDULER_FILEWATCHER_RESULT is the data type of a file arrival event message. You
Maccess the event message as a parameter of an event-based job (or a parameter of a program
referenced by an event-based job). The message contains information needed to locate and
process a file that arrived on a local or remote system.

Oracle Database 11g: New Features for Administrators B - 20


11.2

Using the SCHEDULER_FILEWATCHER_REQUEST


Object Type
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Argument Data type Definition

OWNER VARCHAR2(4000) File watcher owner

NAME VARCHAR2(4000) File watcher name

REQUESTED_PATH_NAME VARCHAR2(4000) Requested path name


ble
REQUESTED_FILE_NAME VARCHAR2(4000) Requested file name
fe r a
ans
CREDENTIAL_OWNER VARCHAR2(4000) - t r
Owner of used credential
n n o
CREDENTIAL_NAME VARCHAR2(4000) Credential a
s name
) h a e ฺ
MIN_FILE_SIZE NUMBER
r
ฺa Minimum i d
u file size
o m t G
NUMBER o n ฺc denSteady state duration
STEADY_STATE_DUR
@ a Stu
z i l l e t h is

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
Zi l lic
Using the SCHEDULER_FILEWATCHER_REQUEST Object Type
e l o
a rcSCHEDULER_FILEWATCH_REQUEST
The object is returned in the
MMATCHING_REQUESTS attribute of the SCHEDULER_FILEWATCHER_RESULT object
type.

Oracle Database 11g: New Features for Administrators B - 21


11.2

Step 4: Creating an Event-Based Job that


References the File Watcher
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• Create the job:


BEGIN
DBMS_SCHEDULER.CREATE_JOB(
JOB_NAME => '',
PROGRAM_NAME => '',
EVENT_CONDITION => NULL,
QUEUE_SPEC => '<name_of_file_watcher>',
ble
AUTO_DROP => FALSE,
fe r a
ENABLED => FALSE);
ans
END;
n - t r
a no
• Optionally, enable the job to run for each s instance of
h a ฺ
the file arrival event:
ฺ a r) uide
BEGIN
ฺ c om ent G
on tud
DBMS_SCHEDULER.SET_ATTRIBUTE('','PARALLEL_INSTANCES',
a
l e @ isTRUE); S END;
i l h
e l oฺz use t
a rc Copyright
t o © 2009, Oracle. All rights reserved.

l e (m ense
l
Zi anlEvent-Based
Step 4: Creating ic Job that References the File Watcher
l o
e use the DBMS_SCHEDULER.SET_ATTRIBUTE procedure to enable the job to run
You
a rccan
Mfor each instance of the file arrival event, even if the job is already processing a previous
event. Set the PARALLEL_INSTANCES attribute to TRUE. This enables the job to run as a
lightweight job so that multiple instances of the job can be started quickly.
If PARALLEL_INSTANCES is set to the default value of FALSE, file watcher events that
occur while the event-based job is already processing another will be discarded.

Oracle Database 11g: New Features for Administrators B - 22


11.2

Step 5: Enabling the Objects


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Enable the file watcher, the program, and the job:


BEGIN
DBMS_SCHEDULER.ENABLE('MY_FILE_WATCHER,
DSSUSER.MY_PROGRAM,
DSSUSER.MY_JOB');
END;
ble
fe r a
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
l
Zi thelicObjects
Step 5: Enabling
l o
e DBMS_SCHEDULER.ENABLE procedures to enable the file watcher, the program,
Use
a rcthe
Mand the job.

Oracle Database 11g: New Features for Administrators B - 23


11.2

Enabling File Arrival Events from Remote


Systems
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Perform the following tasks to enable the raising of file


arrival events at remote systems:
1. Set up the database to run remote external jobs.
2. Install, configure, register, and start the Scheduler
agent on the first remote system.
3. Repeat step 2 for each additional remote system. ble
fe r a
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
EnablingoFile
l
Zi ArrivallicEvents from Remote Systems
l
ce file arrival events from a remote system, you must install the Scheduler agent on
To
a rreceive
M that system, and you must register the agent with the database. The remote system does not
need an Oracle Database instance to generate file arrival events.
Refer to the Oracle Database Administrator's Guide 11g Release 2 for detailed information.

Oracle Database 11g: New Features for Administrators B - 24


11.2

Using DBMS_SCHEDULER.DROP_FILE_WATCHER
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Argument Data type Default

FILE_WATCHER_NAME VARCHAR2 No default

FORCE BOOLEAN FALSE

ble
fe r a
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Zi l lic
Using DBMS_SCHEDULER.DROP_FILE_WATCHER
l o
e drop the file watcher database object by using the
rccan
You
a
MDBMS_SCHEDULER.DROP_FILE_WATCHER procedure. It has the following arguments:
• FILE_WATCHER_NAME: Name of the file watcher
• FORCE: Force flag. When set to FALSE, the file watcher will not be dropped if there are
any jobs that depend on it. When set to TRUE, jobs that reference the dropped file watcher
are disabled.
If there are executing jobs referencing the file watcher when you drop the file watcher, they
are not affected by this procedure and continue to execute.

Oracle Database 11g: New Features for Administrators B - 25


11.2

File Watcher: Changes to Existing


DBMS_SCHEDULER Procedures
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• CREATE_JOB and CREATE_JOBS: QUEUE_SPEC


argument can be a file watcher name.
• CREATE_EVENT_SCHEDULE: QUEUE_SPEC argument can
be a file watcher name.
• SET_ATTRIBUTE and GET_ATTRIBUTE: These can be
used to set and get individual attributes of a file le
a b
watcher.
s f er
• ENABLE and DISABLE: These can accept a file watcher
- t r an
name as an argument. n on
a s ฺ
h a
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
File Watcher:
l
Zi Changes lic to Existing DBMS_SCHEDULER Procedures
l o
a rce
CREATE_JOB and CREATE_JOBS: The QUEUE_SPEC argument to these calls can be a file
Mwatcher name instead of a queue name. The job created will be an event-based job whose
source queue is the one in which the file watcher will enqueue its results. Do not specify an
agent name with the file watcher.
CREATE_EVENT_SCHEDULE: The QUEUE_SPEC argument to this call can be a file watcher
name instead of a queue name. The schedule created will be an event-based schedule whose
source queue is the one in which the file watcher will enqueue its results. Do not specify an
agent name with the file watcher.
SET_ATTRIBUTE and GET_ATTRIBUTE: These two calls can accept a file watcher name as
argument. For a file watcher, the following attributes are legal: DESTINATION,
DIRECTORY_PATH, FILE_NAME, CREDENTIAL_NAME, MIN_FILE_SIZE.
STEADY_STATE_DURATION and COMMENTS.
ENABLE and DISABLE: These two calls can accept a file watcher name as an argument. A
file watcher will not be enabled unless all of its attributes have been set to legal values and the
file watcher owner has execute privileges on the credential being used. If a file watcher is
disabled with the force flag set to FALSE, there should be no jobs that depend on it. If there
are, the call will fail.

Oracle Database 11g: New Features for Administrators B - 26


11.2

File Watcher: Changes to Existing Attributes


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

The EVENT_SPEC attribute for jobs and schedules can


accept a file watcher name.

ble
fe r a
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
File Watcher:
l
Zi Changeslic to Existing Attributes
e l o
The
a rcEVENT_SPEC attribute for jobs and schedules can accept a file watcher name instead of a
Mqueue name. The resulting job/schedule will be event-based with the file watcher queue as its
source queue.

Oracle Database 11g: New Features for Administrators B - 27


11.2

File Watcher: New Dictionary Views


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Query the following to view file watcher configuration


information:
• DBA_SCHEDULER_FILE_WATCHERS
• ALL_SCHEDULER_FILE_WATCHERS
• USER_SCHEDULER_FILE_WATCHERS
ble
fe r a
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
File Watcher:
l
Zi New Dictionary
lic Views
l o
rceare three new views with file watcher information:
There
a
MDBA_SCHEDULER_FILE_WATCHERS, ALL_SCHEDULER_FILE_WATCHERS, and
USER_SCHEDULER_FILE_WATCHERS.
The DBA_SCHEDULER_FILE_WATCHERS and ALL_SCHEDULER_FILE_WATCHERS
views have the following columns (the USER_ view does not have an OWNER column):
• OWNER: Name of file watcher owner
• FILE_WATCHER_NAME: Name of the file watcher
• ENABLED: Should be either TRUE or FALSE depending on whether or not the file
watcher is enabled
• DESTINATION: Remote destination where file will be located; set to NULL if the
destination is the local machine.
• DIRECTORY_PATH: Path name of the directory where the file is located
• FILE_NAME: Name of the file to be found
• CREDENTIAL_OWNER: Name of the credential owner
• CREDENTIAL_NAME: Name of the credential
• MIN_FILE_SIZE: Minimum size of the file before file watcher will report that it has
arrived
• STEADY_STATE_DURATION: Minimum amount of time the file has to stay unchanged
before file watcher reports that it has arrived
• LAST_MODIFIED_TIME: Last time this file watcher was modified
• COMMENTS: Comments

Oracle Database 11g: New Features for Administrators B - 28


11.2

File Watcher: New Columns in Existing Views


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

New columns in *_SCHEDULER_JOBS and the


*_SCHEDULER_SCHEDULES views:

Column Name Data type Description

FILE_WATCHER_OWNER VARCHAR2(30) Name of file watcher owner. If


not file watcher-based, this
column will be NULL. ble
fe r a
FILE_WATCHER_NAME VARCHAR2(30) Name of file watcher. If not
ans
file watcher-based, this
n - t r
column will be NULL.
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
File Watcher:
l
Zi New Columns
lic in Existing Views
e l o
New
a rccolumns have been added to the *_SCHEDULER_JOBS and
M*_SCHEDULER_SCHEDULES views to provide file watcher information:
• FILE_WATCHER_NAME: Name of the file watcher
• FORCE: Force flag. When set to FALSE, the file watcher will not be dropped if there are
any jobs that depend on it.

Oracle Database 11g: New Features for Administrators B - 29


11.2

Scheduler Remote Database Jobs: Overview

• Create a job that runs stored procedures and


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

anonymous PL/SQL blocks on another database


instance on the same host or on a remote host.
• The target database can be any release of Oracle
Database.
• DBMS_SCHEDULER.CREATE_DATABASE_DESTINATION
must be used to identify the remote database. a b le
• DBMS_SCHEDULER.CREATE_CREDENTIAL must beaused s f er
t r n
to identify the user. on -
a n
• Jobs with job types of PLSQL_BLOCK and a s
STORED_PROCEDURE can be the subject r ) h ofdeฺ
m ฺa Gui
SET_ATTRIBUTE calls for the
n ฺ coDESTINATION
e n t and
CREDENTIAL attributes.ao Stud
l l e@ is
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Scheduler Zi l
Remote lic
Database Jobs: Overview
l o
e now create a job that runs stored procedures and anonymous PL/SQL blocks on
You
a rccan
M another database instance on the same host or on a remote host. The target database can be any
release of Oracle Database.
There are no new procedures to support remote database jobs, rather there have been changes
to existing DBMS_SCHEDULER procedures to support this functionality.
DBMS_SCHEDULER.CREATE_DATABASE_DESTINATION must be used to identify the
remote databases on which you want to run the remote database jobs. You must first register
each remote database that you want to run a remote database job on by invoking
DBMS_SCHEDULER.CREATE_DB_DESTINATION.
DBMS_SCHEDULER.CREATE_CREDENTIAL must be used to identify the user that you
want to connect as in the remote database.
Additional information is provided on the following pages.

Oracle Database 11g: New Features for Administrators B - 30


11.2

Using CREATE_DATABASE_DESTINATION
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Argument Data type Default

DESTINATION_NAME VARCHAR2 No default

AGENT VARCHAR2 No default

TNS_NAME VARCHAR2 No default


ble
fe r a
COMMENTS VARCHAR2 Null
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Zi l lic
Using DBMS_SCHEDULER.CREATE_DATABASE_DESTINATION
l o
To
a ce a remote database job, you must first create a database destination that represents the
rcreate
Mremote database by using the DBMS_SCHEDULER.CREATE_DATABASE_DESTINATION
procedure. It has the following arguments:
• DESTINATION_NAME: Name of the destination representing the database that you want
to connect to
• AGENT: Name of the external destination that represents the agent that is used to connect
to the remote database
• TNS_NAME: Any valid Oracle Net connect identifier (net service name in the local
database tnsnames.ora file or an actual Oracle Net connect string). If this argument is
not specified, the scheduler agent must be configured such that it has a default database it
connects to.
• COMMENTS: Comments

Oracle Database 11g: New Features for Administrators B - 31


11.2

Using DROP_DATABASE_DESTINATION
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Argument Data type Default

DESTINATION_NAME VARCHAR2 No default

• All members of destination groups referring to this


a b le
destination will be dropped. er
n s f
• All the job instances that point to this destination- t r awill
be dropped. n on
s a
• Jobs running against this destination a
h will be
eฺ stopped.
ฺ a r) uid
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Zi l lic
Using DBMS_SCHEDULER.DROP_DATABASE_DESTINATION
l o
e DBMS_SCHEDULER.DROP_DATABASE_DESTINATION procedure to drop a
rcthe
Use
a
Mdestination. It has the following argument:
• DESTINATION_NAME: Name of the destination representing the database that you want
to connect to
When a database destination is dropped, all members of the destination groups referring to this
destination will also be dropped.
When a database destination is dropped, all the job instances that point to this destination will
be dropped. Jobs that are running against this destination will be stopped.

Oracle Database 11g: New Features for Administrators B - 32


11.2

Creating Remote Database Jobs: Configuration


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Perform the following configuration steps:


1. Set up the originating database for remote jobs.
2. Name each remote database that you want to run
remote database jobs on by using
DBMS_SCHEDULER.CREATE_DB_DESTINATION.
3. Create credentials for all users that will connect on the ble
remote databases by using f e ra
DBMS_SCHEDULER.CREATE_CREDENTIAL. t r a ns
- on
a n
a
h deฺs
r
ฺa Gui)
co entm
n ฺ
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
l
Zi Database
CreatingoRemote lic Jobs: Configuration
l
e perform the tasks listed in the slide to configure the environment for remote database
You
a rccan
M jobs.
Refer to Oracle Database Administrator's Guide 11g Release 2 for a detailed example.

Oracle Database 11g: New Features for Administrators B - 33


11.2

Setting Up the Database for Remote Jobs


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• Verify that XML DB is installed.


• Enable HTTP connections to the database.
BEGIN
DBMS_XDB.SETHTTPPORT(port);
END;

• Execute the prvtrsch.plb script. bl e


fe r a
s
ran
• Set a registration password for the Scheduler agents:
n -t
o
BEGIN
s an
DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('password');
) h a eฺ
END; r
ฺa Guid
co entm
n ฺ
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
Setting Up Zthel
i Database
lic for Remote Jobs
l o
rce the steps listed in the slide on the originating database.
Perform
a
M

Oracle Database 11g: New Features for Administrators B - 34


11.2

Creating Remote Database Jobs


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Create the job by using DBMS_SCHEDULER.CREATE_JOB.


• Set the default credential by using the
CREDENTIAL_NAME parameter.
• Set the destination by using the DESTINATION_NAME
parameter.
• Enable the job by setting the ENABLED parameter to b le
r a
TRUE. sfe n
n - tra
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
Creatingoa Z i l
Remote lic
Database Job
l
e DBMS_SCHEDULER.CREATE_JOB procedure to create each remote job. The
Use
a rcthe
M CREATE_JOB procedure includes the following parameters that are applicable for remote
database jobs:
• CREDENTIAL_NAME is used to specify the default credential to use with the job. The
credential must exist.
• DESTINATION_NAME is used to specify the database destination or external destination
for the job.

Oracle Database 11g: New Features for Administrators B - 35


11.2

Scheduler Multiple Destination Jobs: Overview


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• This feature enables you to specify several targets on


which your jobs should execute.
• It provides the ability to monitor and control the jobs
from the database on which they were created.
• While running, a multiple destination job is viewed as a
collection of jobs, which are near-identical copies of le
a b
each other.
s f er
• All jobs will execute based on the time zone that - t r an
is
specified in the start date of the job or will n
useonthe time
s a
zone of the source database. h a ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Scheduler Z i l
Multiple ic
lDestination Jobs: Overview
e l o
The
a rcmultiple destination jobs feature enables you to specify multiple targets on which the jobs
M should execute. You have the ability to monitor and control the jobs from the database at
which you created them. The following capabilities are included:
• Specifying several databases or machines on which a job must execute
• Modifying a job scheduled on multiple targets as a single entity
• Stopping or dropping jobs running on one or more remote targets
• Finding out the status of job instances on all of a job’s targets
Note that in the initial release of this feature, all destinations will run based on the time zone
that is specified in the start date of the job or will default to the time zone of the source
database.

Oracle Database 11g: New Features for Administrators B - 36


11.2

Scheduler Multiple Destination Jobs: Terminology


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Term Definition

Parent job Job created at the source

Child job Copies that execute at the various destinations

Job destination ID System-generated number that can be used to


ble
uniquely identify a job instance on a given
fe r a
destination
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Scheduler Z i l
Multiple ic
lDestination Jobs: Terminology
l o
rcedestination ID is a system-generated number that can be used to uniquely identify a job
Aajob
M instance on a given destination. It is a number that uniquely identifies a (job name, target,
credential) tuple.

Oracle Database 11g: New Features for Administrators B - 37


11.2

Scheduler Multiple Destination Job States


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Parent Job
State
SUCCEEDED All child jobs for the last scheduled start time
succeeded

FAILED All child jobs failed


ble
SOME Some failed and some succeeded fe r a
ans
FAILED
n - t r
o
INCOMPLETE One or more child jobs are still working on the
s an
previous scheduled run when the parent is ready to
start the next scheduled run. r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
Scheduler Z i l
Multiple ic
lDestination Jobs States
l o
e job state will be set as follows:
The
a rcparent
M • SUCCEEDED if all child jobs for the last scheduled start time succeeded
• FAILED if all child jobs failed
• SOME FAILED if some failed and some succeeded
• INCOMPLETE if one or more child jobs are still working on the previous scheduled run
when the parent is ready to start the next scheduled run

Oracle Database 11g: New Features for Administrators B - 38


11.2

Creating Multiple Destination Jobs


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

To create a multiple destination job, perform the following


steps:
1. Create a destination group that contains all the remote
destinations by using the
DBMS_SCHEDULER.CREATE_GROUP procedure.
2. Create the job by using le
a b
DBMS_SCHEDULER.CREATE_JOB and set the destination
s f er
ran
to the name of a previously created destination tgroup.
n -
o
3. Add additional destinations by using
s an
DBMS_SCHEDULER.ADD_GROUP_MEMBER.
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
l
Zi Destination
CreatingoMultiple lic Jobs
l
e create a multiple destination job as follows:
You
a rccan
M 1. Create a destination group that contains all the remote destinations:
CREATE_GROUP('group_name', 'group_type', 'member, member');
2. Create the job and set the destination:
CREATE_JOB(JOB_NAME=>'job_name', …,
CREDENTIAL_NAME=>'credential_name', DESTINATION_NAME=>
'destination_name');
Note: JOB_TYPE must be set to PLSQL_BLOCK, STORED_PROCEDURE, or
EXECUTABLE.
3. Add additional destinations:
ADD_GROUP_MEMBER('group_name', 'member');

Oracle Database 11g: New Features for Administrators B - 39


11.2

Using Destination Groups for Multiple Destination


Jobs
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• Destination group consists of a list of destinations.


• Destination group must be assigned to the
DESTINATION_NAME attribute of the job.
• Multiple destination jobs of type EXECUTABLE require
the DESTINATION_NAME attribute to be set to a
destination group of group type EXTERNAL_DEST. le
a b
• Multiple destination jobs of type PLSQL_BLOCK or sfer
STORED_PROCEDURE require the DESTINATION_NAME - t r an
on
ofntype
attribute to be set to a destination group a
DB_DEST. has ฺ r) uide
ฺ a
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Zi l
Using Destination lic for Multiple Destination Jobs
Groups
l o
rce
Aadestination group, which consists of a list of destinations, can be referenced when creating a
Mjob. The job runs on all destinations in the group.
When you want a job to run at multiple destinations, you must create a database destination
group or external destination group and assign it to the DESTINATION_NAME attribute of the
job.
Multiple destination jobs of type EXECUTABLE must have their DESTINATION_NAME
attribute set to a destination group of group type EXTERNAL_DEST. External destinations are
automatically created when a scheduler agent is registered with the database. All registered
external destinations are listed in the ALL_SCHEDULER_EXTERNAL_DESTS view. External
destinations are removed when the agent is unregistered or by using
DROP_AGENT_DESTINATION in situations where the host on which the agent runs is no
longer accessible.
Multiple destination jobs of type PLSQL_BLOCK or STORED_PROCEDURE must have their
DESTINATION_NAME attribute set to a destination group of type DB_DEST. Database
destinations are created by using the CREATE_DATABASE_DESTINATION procedure. All
created database destinations are listed in the ALL_SCHEDULER_DB_DESTS view. They are
removed by using DROP_DATABASE_DESTINATION.

Oracle Database 11g: New Features for Administrators B - 40


11.2

Using CREATE_GROUP
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Argument Data type Default

GROUP_NAME VARCHAR2 No default

GROUP_TYPE VARCHAR2 No default

MEMBER VARCHAR2 NULL


ble
fe r a
COMMENTS VARCHAR2 NULL
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Zi l lic
Using DBMS_SCHEDULER.CREATE_GROUP
l o
To
a ce a remote database job, you must first create a destination group by using the
rcreate
MDBMS_SCHEDULER.CREATE_GROUP procedure. It has the following arguments:
• GROUP_NAME: Name of the group
• GROUP_TYPE: Group type of WINDOW, EXTERNAL_DEST, or DB_DEST
• MEMBER: Optional list of names of group members with a format of
[[schema.]credential@][schema.]destination
• COMMENTS: Comments

Oracle Database 11g: New Features for Administrators B - 41


11.2

Using ADD_GROUP_MEMBER
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Argument Data type Default

GROUP_NAME VARCHAR2 No default

MEMBER_NAME VARCHAR2 No default

ble
fe r a
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Zi l lic
Using DBMS_SCHEDULER.ADD_GROUP_MEMBER
l o
To
a ce a member to a group, use the DBMS_SCHEDULER.ADD_GROUP_MEMBER procedure.
radd
MIt has the following arguments:
• GROUP_NAME: Name of the group
• MEMBER_NAME: Name of one or more members to add to the group
Members must match the type of the group.

Oracle Database 11g: New Features for Administrators B - 42


11.2

Using DROP_GROUP
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Argument Data type Default

GROUP_NAME VARCHAR2 No default

FORCE BOOLEAN No default

ble
fe r a
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Zi l lic
Using DBMS_SCHEDULER.DROP_GROUP
l o
To
a ce a group, use the DBMS_SCHEDULER.DROP_GROUP procedure. It has the following
rdrop
Marguments:
• GROUP_NAME: Name of the group
• FORCE: Future use

When a group of DESTINATION type is dropped, the jobs that have their DESTINATION
attribute set to this group will be disabled.
All of the group’s job instances will be removed from the *_SCHEDULER_JOB_DESTS view
when it is dropped.

Oracle Database 11g: New Features for Administrators B - 43


11.2

Using REMOVE_GROUP_MEMBER
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Argument Data type Default

GROUP_NAME VARCHAR2 No default

MEMBER_NAME VARCHAR2 No default

ble
fe r a
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Zi l lic
Using DBMS_SCHEDULER.REMOVE_GROUP_MEMBER
l o
To
a ce a member from a group, use the DBMS_SCHEDULER.REMOVE_GROUP_MEMBER
rremove
Mprocedure. It has the following arguments:
• GROUP_NAME: Name of the group
• MEMBER_NAME: Name of one or more members to remove from the group

If the member is a DESTINATION, any job instances that represent this destination will be
removed from the ALL_SCHEDULER_JOB_DESTINATIONS view.

Oracle Database 11g: New Features for Administrators B - 44


11.2

Modifications to Existing DBMS_SCHEDULER


Procedures
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• CREATE_JOB, SET_ATTRIBUTE, and GET_ATTRIBUTE


have two new arguments:
– CREDENTIAL_NAME: Fully qualified name of the credential
– DESTINATION_NAME: Fully qualified name of the
destination or destination group
• STOP_JOB: Use to stop an individual child job running
a b le
on a specific destination by providing the er
s f
JOB_DEST_ID of that child job.
- t r an
• ENABLE and DISABLE: Use to enable/disable n n
oexternal
destinations, database destinations h and
a
s groups.
) a e ฺ
• SOURCE_HOST and DESTINATION_HOST r i d
ฺa Guarguments of
o m
c specify
n t valid external
PUT_FILE and GET_FILE nmust
o ฺ d e
destination names.e@a s Stu
ฺ z ill t hi
eloCopyright e
u©s2009, Oracle. All rights reserved.
a r c t o
l e (m ense
Modifications
l
Zi to Existing
lic DBMS_SCHEDULER Procedures
l o
e of the CREATE_JOB procedures will have the following two additional
All
a rcversions
M arguments added to the end of the argument list:
• CREDENTIAL_NAME: Fully qualified name of the credential
• DESTINATION_NAME: Fully qualified name of the destination or destination group

All jobs and chain steps will have two new attributes that can be set and retrieved respectively
by using SET_ATTRIBUTE and GET_ATTRIBUTE:
• DESTINATION_NAME: Used to set the destinations for a particular job or chain step.
Specify either a single named destination or the name of a group of type.
• CREDENTIAL_NAME: Used to set the credential of a single destination for this job or job
step, or to set a default credential for all destinations when the destination attribute is the
name of a destination group.
When an external destination is disabled, all the database destinations that go through this
agent will automatically be disabled as well. When a destination is disabled, all job instances
that point to this destination will be disabled as well.
STOP_JOB can be used to stop an individual child job running on a specific destination by
providing JOB_DEST_ID of that child job instead of the job name.

Oracle Database 11g: New Features for Administrators B - 45


11.2

Multiple Destination Jobs: New Dictionary Views


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Query the following views for detailed information:


• *_SCHEDULER_DESTS: All destinations on which
remote jobs can be scheduled
• *_SCHEDULER_EXTERNAL_DESTS: All agents that have
registered with the database
• *_SCHEDULER_DB_DESTS: All databases on which b le
users can scheduler remote database jobs f er a
n s
• *_SCHEDULER_GROUPS: Group information n-tra
• *_SCHEDULER_GROUP_MEMBERS: Member a no
information
h a s ฺ
• *_SCHEDULER_JOB_DESTS: Stateaof r) a job e a remote
idat

m nt G u
database ฺco
a on tude
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Multiple o Zi l
Destination licJobs: New Dictionary Views
e l
The
a rcfollowing new views display information about multiple destination jobs:
M • *_SCHEDULER_DESTS: Shows all the destinations on which remote jobs can be
scheduled. The views contain both the external destinations (for remote external jobs) as
well as the database destinations for remote database jobs.
• *_SCHEDULER_EXTERNAL_DESTS: Shows all the agents that have registered with the
database and can be used as a destination for remote external jobs
• *_SCHEDULER_DB_DESTS: Shows all the databases on which you can schedule remote
database jobs
• *_SCHEDULER_GROUPS: Shows the groups in your schema or all groups in the
database
• *_SCHEDULER_GROUP_MEMBERS: Shows the group members in your schema or all
group members in the database
• *_SCHEDULER_JOB_DESTS: Shows the state of a job at a remote database

Oracle Database 11g: New Features for Administrators B - 46


11.2

Multiple Destination Jobs: New Columns in


Existing Dictionary Views
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

The following views have new columns providing


additional information for multiple destination jobs:
• *_SCHEDULER_JOBS
• *_SCHEDULER_RUNNING_JOBS
• *_SCHEDULER_JOB_RUN_DETAILS
• *_SCHEDULER_JOB_LOG bl e
fe r a
ans
n - t r
a no
h a s ฺ
ฺ a r) uide
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Multiple o Zi l
Destination licJobs: New Columns in Existing Dictionary Views
e l
The
a rcfollowing dictionary views contain new columns with information about multiple
M destination jobs:
• *_SCHEDULER_JOBS:
• CREDENTIAL_OWNER: Name of the credential owner
• CREDENTIAL_NAME: Name of the credential to be used for an external job
• DESTINATION_OWNER: Name of the destination owner
• NUMBER_OF_DESTINATIONS: Number of destinations associated with this job
• *_SCHEDULER_RUNNING_JOBS, *_SCHEDULER_JOB_RUN_DETAILS and
*_SCHEDULER_JOB_LOG:
- CREDENTIAL_OWNER: Name of the credential owner
- CREDENTIAL_NAME: Name of the credential
- DESTINATION_OWNER: Name of the destination owner
- DESTINATION: Name of the destination

Oracle Database 11g: New Features for Administrators B - 47


Summary
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

In this lesson, you should have learned how to:


• Use lightweight jobs
• Use Scheduler email notification
• Create a file watcher
• Create remote database jobs
• Create multiple destination jobs ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
i l lic
el oZ
Marc

Oracle Database 11g: New Features for Administrators B - 48


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Oracle Secure Backup Cloud Module

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
i l lic
el oZ
Marc
Objectives
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

After completing this lesson, you should be able to


describe the use of Oracle Secure Backup Cloud Module

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
i l lic
el oZ
Marc

Oracle Database 11g: New Features for Administrators C - 2


11.2

Oracle Database Backup in the Cloud


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Database
Oracle Secure
Backup Cloud
RMAN module

ble
fe r a
ans
n - t r
a no
h a s ฺ
RMAN ฺ a r) uide
ฺ c om ent G
Local Disk Backup a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
l
Zi Backup
Oracle Database lic in the Cloud
l o
ce Secure Backup Cloud module enables you to create offsite backups that are stored in the
TherOracle
a
MCloud.
Oracle Secure Backup Cloud module is implemented using the Oracle Recovery Manager (RMAN)
SBT interface.
You can use the Oracle Secure Backup Cloud module to stream backups directly to the cloud.
You can also use it to send local disk backups to the storage cloud for offsite storage. For on-premise
databases, Oracle recommends making a local disk based backup first and using the Cloud as an on-
demand accessible offsite backup location.

Oracle Database 11g: New Features for Administrators C - 3


11.2

Introducing Oracle Secure Backup Cloud Module


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• The Oracle Secure Backup Cloud module can be used


to back up all supported versions of Oracle Database.

bl e
fe r a
ns
• Existing interfaces can be used to create the backups.
a
o n
% rman @bu_command_file.txt -tr
n a
• Includes special-use licensing: a s
hRMAN ฺbackup
– Oracle Advanced Security Option r )
for i d e
encryption m ฺa Gu
ฺ c o e n t
– Oracle Advanced Compression n
ao StudOption for Fast Backup
Compression ille @ is
ฺ z e t h
c e loCopyright
u s2009,
a r t o © Oracle. All rights reserved.

l e (m ense
Introducing Z
l
i Secure
Oracle lic Backup Cloud Module
l o
e use the Oracle Secure Backup Cloud module to back up all supported versions of Oracle
Yourc
can
a
MDatabase.
You can continue to use Enterprise Manager and scripts to create backups when using the Oracle
Secure Backup Cloud module.
Oracle Secure Backup Cloud module includes special-use licensing:
• Oracle Advanced Security Option for RMAN backup encryption
• Oracle Advanced Compression Option for the Fast Backup Compression feature
Note: Encryption and compression are not available with Oracle Database 9i Release 2.

Oracle Database 11g: New Features for Administrators C - 4


11.2

Advantages of Backing Up to the Cloud


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

Backing up to the cloud provides the following advantages


over traditional tape-based offsite backups:
• Continuous Accessibility:
– Backups stored in the Cloud are always accessible in
much the same way local disk backups are.
• Better Reliability: e
r a bl
– Disk-based storage clouds are inherently more reliablefe
than tapes. t r a ns
o n -
– Cloud vendors typically keep multiple redundant n copies
of data for availability and scalability purposes.
a
s ฺ
h a
• Cost Savings by lowering or eliminating: ฺ a r) uide
– Upfront capital expenditures ฺ c om ent G
a on tud
– Offsite storage costs
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Cloud Backup
l
Zi Advantages
lic Over Tape-Based Offsite Backups
l o
rce up to the Cloud by using OSB Cloud module provides the following advantages over
Backing
a
Mtraditional tape-based offsite backups:
• Continuous Accessibility: Backups stored in the Cloud are always accessible, similar to local
disk backups. You do not need to call anyone for a restore, nor is there a need to ship or load
tapes before a restore can be performed. You can initiate a restore operation using standard tools
as if the offsite backup was stored locally. This helps to make the restoration of files faster and
can reduce down time.
• Better Reliability: Storage Clouds are disk based and inherently more reliable than tapes.
Additionally, the Cloud vendors typically keep multiple redundant copies of data for availability
and scalability purposes.
• Cost Savings: The use of Cloud storage lowers or eliminates upfront capital expenditures, as
well as offsite storage costs.

Oracle Database 11g: New Features for Administrators C - 5


11.2

What Is Amazon Simple Storage Service (S3)?


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

• Amazon Simple Storage Service (S3) provides access


to the highly scalable, reliable, fast, inexpensive data
storage infrastructure used by Amazon to run its own
global network of Web sites.
• Use Amazon S3 to store and retrieve any amount of
data from anywhere on the Web.
a b le
• Amazon S3 aims to maximize benefits of scale and tofer
s
pass the benefits on to subscribers. tran n -
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
What Is Amazon
l
Zi Simple lic Storage Service (S3)?
l o
rce Web Services (AWS) has provided companies of all sizes with an infrastructure Web
Amazon
a
Mservices platform in the cloud since 2006.
Amazon Simple Storage Service (S3) provides a highly scalable, reliable, inexpensive data storage
infrastructure that can be used to store any amount of data from anywhere on the Web.
Refer to the Amazon Web Services Web site for detailed information: http://aws.amazon.com.

Oracle Database 11g: New Features for Administrators C - 6


11.2

Installing the Oracle Secure Backup Cloud


Module
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

1. Register to use Amazon S3 Web services on the


Amazon Web Services Web site:
http://aws.amazon.com
2. Register for an Oracle.com or Oracle Technology
Network (OTN) account: http://otn.oracle.com
3. Download the Oracle Secure Backup Cloud module e
installer from OTN: r a bl
ns fe
http://www.oracle.com/technology/software/tech/cloud/index
r a
t
.html on-
s ฺ Backup
4. Run the installer to install the Oracle aSecure
an
h e
Cloud module and configure Cloud ฺar) backups
uid
ฺ c om ent G
a on tud
l l e@ is S
i
ฺz se th
l o
a rce Copyright
t o u© 2009, Oracle. All rights reserved.
l e (m ense
Using the Oracle
l
Zi Secure lic Backup Cloud Module
l o
rcethe Oracle Secure Backup Cloud module, perform the following steps:
To use
a
M 1. Register to use the Amazon S3 web services. You will be provided with an Access Key ID and a
Secret Access Key.
2. You need an account on Oracle.com or the Oracle Technology Network (OTN) to install the
Oracle Secure Backup Cloud module. If you do not have one of these accounts, you can register
on the OTN web site.
3. Download the Oracle Secure Backup Cloud module installer (osbws_install.jar) from
OTN. If the database to be backed up is on Amazon Elastic Compute Cloud (EC2), you will find
the osbws_install.jar file in the /home/oracle/scripts/osbws directory.
4. Invoke the installer to install the Oracle Secure Backup Cloud module and configure Cloud
backups.
Refer to the Oracle Database 11g R2: Availability – RMAN eStudy for detailed information about
installation and configuration of the Oracle Secure Backup Cloud Module.

Oracle Database 11g: New Features for Administrators C - 7


Summary
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ

In this lesson, you should have learned how to use Oracle


Secure Backup Cloud Module.

ble
fe r a
ans
n - t r
o
s an
r ) ha deฺ
m ฺa Gui
n ฺ co ent
@ ao Stud
z i l le this

loCopyright e
s2009,
r c e o u© Oracle. All rights reserved.
a t
l e (m ense
i l lic
el oZ
Marc

Oracle Database 11g: New Features for Administrators C - 8

Você também pode gostar