Escolar Documentos
Profissional Documentos
Cultura Documentos
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.
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
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ฺ
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ฺ
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ฺ
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ฺ
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ฺ
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ฺ
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ฺ
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
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ฺ
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ฺ
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ฺ
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ฺ
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
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ฺ
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ฺ
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ฺ
xviii
Appendix A: Practices and Solutions
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ฺ
xx
Appendix A
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
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ฺ
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
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
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
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.
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
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
ASMDISK12
ASMDISK13
#
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
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
# 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
#
$ asmca
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
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ฺ
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
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
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
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 ..
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
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.
$ . 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.
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 -
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
$
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
$ $ORACLE_HOME/OPatch/opatch lsinventory
Invoking OPatch 11.1.0.6.6
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.
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
$
connectString orcl:::
Invoking OPatch 11.1.0.6.6
OPatch succeeded.
$ $ORACLE_HOME/OPatch/opatch lsinventory
Invoking OPatch 11.1.0.6.6
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> 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ฺ
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
$
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
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
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
$
SQL> startup
ORACLE instance started.
$ 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.
--------------------------------------------------------------
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.
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
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
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.
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
$
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> 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
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
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
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
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.
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
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
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 /
Elapsed: 00:03:38.49
SQL> set timing off
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
COUNT(*)
----------
918843
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%';
2 rows selected.
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
Commit complete.
Elapsed: 00:00:00.10
SQL>
SQL> set timing off
SQL> select count(*) from sales_nocompress
2 /
COUNT(*)
----------
0
1 row selected.
COUNT(*)
----------
0
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
1 row selected.
SQL>
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
$
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
Grant succeeded.
Grant succeeded.
User altered.
User altered.
Grant succeeded.
Grant succeeded.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
Grant succeeded.
SQL>
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
Tablespace created.
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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'))
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 /
SQL>
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');
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
------------------------------ ------------------------- -----
--------------------------------------------------------------
------------------
'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
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ฺ
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.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
1 row created.
1 row created.
1 row created.
1 row created.
SQL> commit
2 /
Commit complete.
SQL>
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 /
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)
SQL>
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
------------------------------ ------------------------- -----
--------------------------------------------------------------
------------------
'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>
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
'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
'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
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
'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
'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;
Table altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
SQL>
SQL> drop tablespace x;
Tablespace dropped.
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
SQL>
SQL> drop table newsales
2 /
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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>
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.
1 row created.
1 row created.
2005','dd-mon-yyyy'),'I',9999,8,96) ;
1 row created.
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) ;
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.
7 rows selected.
SQL>
PARTITION_NAME HIGH_VALUE
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'))
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')
7 rows selected.
SQL>
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>
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.
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
$
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
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'))
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
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
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
$
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ฺ
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
21 ) virtual
22 )
23 /
Table created.
SQL>
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
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
SQL> commit
2 /
Commit complete.
SQL>
SQL>
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 )
(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>
;
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,
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,
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>
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
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
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 /
7 rows selected.
SQL>
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
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
$
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
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>
Grant succeeded.
SQL> SQL>
Grant succeeded.
SQL> SQL> SQL> SQL> SQL> SQL> SQL> DROP TABLE temp_table purge
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
Table created.
*
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> 2 3 4 5 6 7 8 9 10
PL/SQL procedure successfully completed.
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.
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
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)))
Connected to:
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:
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ฺ
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
Tablespace created.
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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...
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.
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ฺ
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.
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.
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;
Procedure created.
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...
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
??????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????
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 ==*/
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
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
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
Table dropped.
SQL>
SQL> pause Press [Enter] to continue...
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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
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 /
COLUMN_NAME
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
--------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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
=============================================
SQL>
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
…
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
Row 3 inserted.
…
Row 30 inserted.
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 /
Tablespace dropped.
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
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
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
--------------------------------------------------------------
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.
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
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> exit
$
verify_function_11g.
Execute cr_verification_funct.sql from the $HOME/solutions/SEC
directory.
$ pwd
/home/oracle/solutions/SEC
$ sqlplus / as sysdba
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
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>
User altered.
SQL>
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.
$ 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.
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
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>
Grant succeeded.
Grant succeeded.
Grant succeeded.
User altered.
SQL>
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 ----------------
--------------------------------------------------------------
------------------
----------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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.
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
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 |
--------------------------------------------------------------
------------------
----------------
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.
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
$
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
*
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>
Import: Release 10.2.0.3.0 - Production on Friday, 02 October,
2009 8:53:44
el oZ l
. . imported "APPS"."ADM_CC_FEATUREVALUE" 248.5
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
$ 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):
--------------------------------------------------------------
------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
OPatch succeeded.
$ opatch apply
Invoking OPatch 10.2.0.3.0
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')
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ฺ
plb"
ApplySession adding interim patch '6903335' to inventory
--------------------------------------------------------------
------------------
Installed Top-level Products (2):
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
Grant succeeded.
Grant succeeded.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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.
Synonym created.
Grant succeeded.
Library created.
No errors.
Library created.
Package created.
Synonym created.
Grant succeeded.
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.
No errors.
SQL>
SQL> grant all on dbms_sqlpa to system;
Grant succeeded.
SQL>
SQL> exit
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
*
ERROR at line 1:
ORA-06512: at line 1
*
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
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 -
Production
With the Partitioning, OLAP and Data Mining options
Elapsed: 00:09:04.90
SQL> No errors.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
Statistics
----------------------------------------------------------
957 recursive calls
0 db block gets
292 consistent gets
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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)
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> SQL>
PL/SQL procedure successfully completed.
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
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.
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
9) Start your 11g environment including your database instance and Enterprise Manager
Database Control.
$ . oraenv
ORACLE_SID = [db10g] ? orcl
$ sqlplus / as sysdba
SQL> startup
ORACLE instance started.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
ฺ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
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>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
@ 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
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
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
SQL> SQL>
System altered.
SQL>
System altered.
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.
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
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 -
Production
With the Partitioning, OLAP and Data Mining 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
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.
$ cd /home/oracle/solutions/SPM
$ ./spm_setup.sh
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
no rows selected
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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>
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
------------------------------ -------------- --- --- --- ---
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ฺ
Session altered.
*
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*/%';
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>
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>
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');
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,
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*/%''');
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>
/*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
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');
SQL>
SQL> print cnt;
CNT
----------
2
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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 | |
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 | |
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 /
SQL>
SQL> print sqlid;
SQL>
SQL> execute :cnt :=
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
SQL>
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:
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>
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
--------------------------------------------------------------
| 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>
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
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 |
--------------------------------------
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');
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
--------------------------------------------------------------
------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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_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 |
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');
SIGNATURE SQL_HANDLE
---------- ------------------------------
SQL_TEXT
--------------------------------------------------------------
------------------
PLAN_NAME ORIGIN ENA ACC FIX AUT
------------------------------ -------------- --- --- --- ---
7.6492E+17 SYS_SQL_0a9d872600ece455
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>
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
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 | | |
PLAN_TABLE_OUTPUT
--------------------------------------------------------------
------------------
--------------------------------------------------------------
------------------
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 /
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ฺ
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 /
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);
SQL>
SQL> exec dbms_sqltune.execute_tuning_task(:spmtune);
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')
--------------------------------------------------------------
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.
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.
Rationale
"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 | | |
DBMS_SQLTUNE.REPORT_TUNING_TASK(:SPMTUNE,'TEXT')
--------------------------------------------------------------
--------------------------------------------------------------
-------------------
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 |
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 |
| | |
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) */%';
SIGNATURE SQL_HANDLE
---------- ------------------------------
SQL_TEXT
--------------------------------------------------------------
PLAN_NAME ORIGIN ENA ACC FIX AUT
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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)
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 | |
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');
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>
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
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
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> 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.
SQL> SQL>
Commit complete.
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
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ฺ
Directory created.
SQL> exit
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
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
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.
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
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
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
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
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
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
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
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.
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
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
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition
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
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
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>
no rows selected
…
SQL>
no rows selected
a couple of minutes.
$ ./run_ast.sh
Tue Oct 6 07:21:08 UTC 2009
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
SQL>
no rows selected
…
SQL>
no rows selected
$ sqlplus ast/ast
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.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
SQL> SQL> 2 3 4
EXECUTION_NAME STATUS EXECUTION_START
------------------------------ ----------- -------------------
EXEC_298 COMPLETED 10/06/2009 07:21:18
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
--------------------------------------------------------------
FINDINGS SECTION (2 findings)
--------------------------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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.
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 | | |
--------------------------------------------------------------
-------------------
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 | | |
--------------------------------------------------------------
---------------------------------------
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)
--------------------------------------------------------------
---------------------------------------
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 |
--------------------------------------------------------------
---------------------------------------
4 - access("C"."CUST_ID"<2)
5 - access("S"."CUST_ID"="C"."CUST_ID")
filter("S"."CUST_ID"<2)
--------------------------------------------------------------
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
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.
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
--------------------------------- -------- ----------
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
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
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
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
$ 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>
Commit complete.
Database dismounted.
ORACLE instance shut down.
SQL> SQL> ORACLE instance started.
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ฺ
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
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ฺ
System altered.
System altered.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - Production
2009
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.”
2009
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
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
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
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
Connected to:
SQL> SQL>
OBJ
----------
76538
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
=========================
RMAN>
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
$ . oraenv
ORACLE_SID = [db10g] ? orcl
$
$ cd /home/oracle/solutions/SQL_Repair
$
$ sqlplus / as sysdba
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
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.
1 row created.
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ฺ
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 | | | |
|
|
PLAN_TABLE_OUTPUT
--------------------------------------------------------------
------------------
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")
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
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";
*
ERROR at line 1:
ORA-13605: The specified task or object sqldiag_bug_5869490
does not exist for the current user.
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);
"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)
--------------------------------------------------------------
-----------------
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>
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ฺ
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
--------------------------------------------------------------
…
--------------------------------------------------------------
-----------------------
| 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
*/
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');
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
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>
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'
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 /
SQL>
SQL> CREATE INDEX moni_test_c_indx on moni_test(c);
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.
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
$
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
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>
_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.
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>
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
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>
COMP CS US
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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>
COMP CS US
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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>
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;
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;
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;
$ 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.
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
SQL> SQL>
Grant succeeded.
SQL>
Commit complete.
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
no rows selected
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
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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'
no rows selected
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
9 rows selected.
SQL>
SQL>
SQL> -- Should be false: use public statistics
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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
--------------------------------------------------------------
---------------------------------------------
| 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 |
---------------------------------------------
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 /
SQL>
SQL> -- public statistics: still nothing
SQL> @ show_public_stats TABJFV
SQL>
SQL> set echo off
old 3: where table_name = '&1'
no rows selected
no rows selected
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
---------------------------------------------
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 /
SQL> commit;
Commit complete.
SQL>
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
--------------------------------------------------------------
--------------------------------------------
| Id | Operation | Name | Rows |
--------------------------------------------
| 0 | SELECT STATEMENT | | 100 |
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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 /
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>
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
no rows selected
10 rows selected.
SQL>
SQL>
SQL> -- Should be false: use public statistics
SQL> show parameter optimizer_use_pending_statistics
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
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'
no rows selected
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
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');
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
$
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
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
$ 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>
Table created.
SQL> 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
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
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
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 |
--------------------------------------------------------------
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')
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
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>
--------------------------------------------------------------
------------------------- ---------- ----------
ROW_SIZE_AVG
------------
Dependency Published QRC.CACHEJFV
76960 0
0
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;
76960 0
0
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
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);
COUNT(*)
----------
1
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ฺ
Elapsed: 00:00:00.00
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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 |
| 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
--------------------------------------------------------------
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.
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
Elapsed: 00:00:00.01
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;
Function created.
Elapsed: 00:00:01.26
SQL>
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
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ฺ
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
Elapsed: 00:00:00.01
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
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
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.
$ ./rman_archivelog.sh
*******************************************
For demo purposes ONLY:
* Enable ARCHIVELOG mode for database
SQL>
Database altered.
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
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.
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
Connected to:
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
$ 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>
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
RMAN>
RMAN> CREATE CATALOG TABLESPACE RCAT;
2>
3> REGISTER DATABASE;
4>
5> exit;
recovery catalog created
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>
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
2) Back up the EXAMPLE tablespace from the orcl database and log it in the RMAN
catalog.
/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
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
RMAN> exit
/u01/app/oracle
$
b) Execute the following commands:
rman catalog catowner/oracle_4U
IMPORT CATALOG catowner/oracle_4U@dbtest;
$ rman catalog catowner/oracle_4U
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.
Connected to:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
SQL>
Tablespace dropped.
SQL> SQL>
System altered.
SQL>
Database altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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
Tablespace created.
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.
Grant succeeded.
Grant succeeded.
Grant succeeded.
Grant succeeded.
Grant succeeded.
Grant succeeded.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
Grant succeeded.
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>
Grant succeeded.
SQL>
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;
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ฺ
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 "
oZ l
SQL> set lines 200
el SQL> set pages 44
1 row selected.
SQL>
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
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>
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...
1 row selected.
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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
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
4 rows selected.
SQL>
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;
SQL> COMMIT;
Commit complete.
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> /
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;
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
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)
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>
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
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>
SQL> /*== To list the tablespace(s), which are used for
flashback data archives ==*/
SQL>
SQL> SELECT *
1 row selected.
1 row selected.
SQL>
SQL> pause Press [Enter] to continue ...
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
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);
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
Tablespace created.
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>
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.
Tablespace dropped.
User dropped.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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
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
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>
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
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>
Database altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
Database altered.
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.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> COMMIT;
Commit complete.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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.
1 row updated.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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 ==*/
System altered.
SQL>
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
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ฺ
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ฺ
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.
1 row deleted.
SQL> COMMIT;
Commit complete.
SQL>
SQL> ALTER DATABASE DROP SUPPLEMENTAL LOG DATA (PRIMARY KEY)
COLUMNS;
Database altered.
Database altered.
Revoke succeeded.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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>
Database altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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
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
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.
*******************************************
2009
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.
SQL>
Table created.
SQL>
rc elo55 comment=NONE
Ma
Finished Control File and SPFILE Autobackup at 09-OCT-09
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
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
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 ...
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.
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.
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
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
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
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
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
REGION_ID REGION_NAME
---------- -------------------------
1 Europe
2 Americas
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
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
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
RMAN>
4) List failures and failure details.
RMAN> LIST FAILURE;
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
RMAN>
9) Initiate an automated repair, then restart your database, and exit RMAN.
RMAN> REPAIR FAILURE;
NO)? YES
executing repair script
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
RMAN> exit
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
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>
SQL>
System altered.
Database dismounted.
ORACLE instance shut down.
SQL> ORACLE instance started.
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
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ฺ
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.
• 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.
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.
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.
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.
• 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
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.
Using DBMS_SCHEDULER.CREATE_FILE_WATCHER
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
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.
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.
Using DBMS_SCHEDULER.DROP_FILE_WATCHER
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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.
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.
Using CREATE_DATABASE_DESTINATION
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
Using DROP_DATABASE_DESTINATION
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
Term Definition
Parent Job
State
SUCCEEDED All child jobs for the last scheduled start time
succeeded
Using CREATE_GROUP
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
Using ADD_GROUP_MEMBER
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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.
Using DROP_GROUP
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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.
Using REMOVE_GROUP_MEMBER
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
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.
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.
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ฺ
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
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.
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.
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