Here you can obtain the scripts and examples from Oracle Performance Survival Guide by Guy Harrison.
An archive containing the full set of scripts can be downloaded here. Individual files can be downloaded below.
The archive contains both utility scriptsand all of the SQL files that I used to create various test loads while writing the book. The utility scripts are described in the index.html file contained within the archive. These scripts provide reports on various aspects of database health and performance.
The rest of the SQL files are provided as is, and without descriptions. You might find them useful if you are trying to replicate my workloads.
Some of the scripts will only work if you install some packages, views and permissions. In particular, the OPSG_PKG package provides an ability to generate short term delta and rate reports against the time model and wait interface. See installation, below, for instructions.
I hope you find these scripts - and my book - useful. If you have any problems please contact me at [email protected].
Regards,
Many scripts can be run without any installation providing that the user has access to V$ views. However, a few require specialized views and that the OPSG_PKG be installed. To install the package:
1. Open a command prompt within the "install" directory
2. execute either install_opsg.bat (Windows) or install_opsg.sh (Linux/Unix)
3. Respond to the prompts
Here is an example session:
C:\tmp\opsg\install>sqlplus /nolog @install_opsg
SQL*Plus: Release 11.1.0.7.0 - Production on Thu Sep 10 10:55:02 2009
Copyright (c) 1982, 2008, Oracle. All rights reserved.
Enter password for the (new) OPSG user:opsg
Enter SYS password:
Enter TNSNAMES entry:g11r2ga
The script creates a user OPSG which has privileges to run all of the scripts and which has appropriate permissions. You can modify the script if you want to install a different user. You do need the SYS password to install the user.
I found the data volumes in Oracle's SH schema too low to illustrate some of the SQL tuning principles. The script extend_sh_schema.sql in the scripts directory will add about 2 million rows to the SALES and COSTS tables. These updates are applied directly to the SH schema.
Chapter 3: Tools of the Trade
p 41 topsql1.sql Top 10 cached sql statements by elapsed time
p 58 loginTrigger.sql Example of a login trigger that activates SQL trace
p 70
Non-idle wait times sorted by time waited
p 73
Time model unioned with wait data to show waits combined with CPU timings
p 55
Show the full name and path of the trace file for the current session
Chapter 5: Indexing and Clustering
p 122
Turn on monitoring for all indexes
p 122
Show usage statistics for indexes
p 133
Report on indexes that are not found in any cached execution plan
Chapter 6: Application Design and Implementation
p 157
Identify SQLs that are identical other than for literal values (Force matching candidates)
Chapter 7: Optimizing the Optimizer
p 194
Show optimizer parameters in effect for the curren session
p 198
Disable automatic statistics collection
Chapter 11: Sorting Grouping and Set Operations
p 332
Show statistics onsort and hash workareas (from V$SQL_WORKAREA)
Chapter 12: Using and Tuning PL/SQL
p 355
Query to reveal the overhead of PLSQL within the database
p 356
Show statements in the cache with PLSQL component and show pct of time spent in PLSQL
p 357
Report on data held in the PLSQL_PROFILER tables
p 360
Query agains the DBMSHP (hierarchical profiler) tables
Chapter 13: Parallel SQL
p 414
Show real time view of current parallel executions
p 413
Example of using v$pq_tqstat to reveal PQO workload distribution
p 422
Example of using v$pq_tqstat to show inster-instance parallel in RAC
Chapter 15: Lock Contention
p 460
Show definition of all lock codes
p 461
View definition that will show all locks held by the current user
p 467
Show lock waits compared to other waits and CPU over a short time period
p 466
Show lock waits compared to other waits and CPU
p 468
Show lock wait information from Active Session History (ASH)
p 468
Show lock wait information from Active Workload Repository (AWR)
p 470
Show SQLs with the highest lock waits
p 471
Show segments with the highest lock waits
p 472
Show SQLs for a particular module with lock waits
p 472
Show sessions with a specific USERNAME and their lock waits
p 476
Simple blocking locks script
p 477
Lock tree built up from V$SESSION
p 477
Blocking row level locks at the session level
p 478
Lock tree built up from V$wait_chains
Chapter 16: Latch and Mutex contention
p 494
Latch/mutex waits compared to other non-idle waits and to CPU
p 496
"Latch statistics - gets
p 497
Latch statistics from Active Session History (ASH)
p 495
Latch/mutex waits over a short duration compared to other waits
p 497
SQLs with the highest concurrency waits (possible latch/mutex-related)
p 500
SQLs not using bind variables - possibly causing library cache mutex contention
p 499
Library cache statistics
p 503
"Number of Cache Buffers Chains latches & number of buffers covered
p 504
Blocks with the highest touch counts and latches involved
p 505
Rowcache latch statistics
p 510
Adjusting spin count for an individual latch class
p 511
Query to show latch class configuration
Chapter 17: Shared Memory Contention
p 519
Status of ansynchronous IO
p 521
Size of the flashback log buffer
p 526
Buffer busy waits by buffer type
p 526
Buffer busy waits by segment
Chapter 18: Buffer Cache Tuning
p 538
Direct path IO and buffered IO
p 540
Segments cached in the buffer pools
p 541
"""hit rates"" for direct and cached IOs "
p 542
"""hit rates"" calculated over a time interval "
p 544
logical and physical IO for specific SQLs
p 546
Buffer pool IO statistics
p 547
Query on V$DB_CACHE_ADVICE
p 548
DB cache advise shown as a histogram
p 552
Query on V$SGA_DYNAMIC_COMPONENTS
p 551
Query on V$SGA_RESIZE_OPS
Chapter 19: Optimizing PGA Memory
p 562
PGA parameters and configuration from v$pgastat
p 566
temporary direct path IO compared to CPU and other non-idle waits
p 565
Top consumers of PGA memory
p 567
Direct path temp IO over a time interval
p 570
SQL workarea statistics
p 571
PGA target advice report
p 572
PGA target advice histogram
Chapter 20: Other Memory Management Topics
p 578
IO wait breakdown
p 581
IO wait breakdown over a time period
p 582
Perl script to calculate average direct path IO time from a trace file
p 583
PGA target converted to elapsed times
p 584
Combined (PGA+SGA) memory advice report for 10g
p 586
Combined (PGA+SGA) memory advice report for 11g
p 590
V$MEMORY_DYNAMIC_COMPONENTS report
p 590
V$MEMORY_RESIZE_OPS report
p 591
Memory target advice report
p 593
Query against X$KMSGSBSMEMADV (basis of V$MEMORY_TARGET_ADVICE)
p 594
Report on memory related parameters
p 599
Result set cache statistics
p 600
Result set cache efficiency
p 600
Result set cache statistics for SQL statements
p 601
Result set cache dependencies
p 605
Shared pool advisory
Chapter 21: Disk IO Tuning fundamentals
p 617
IO waits compared to other waits and CPU
p 618
IO waits reported for an interval
p 619
Summary report from v$iostat_file
p 620
Summary report of v$iostat_function
p 622
Summary report from v$filestat
p 622
Short term IO statistics from v$filemetric
p 624
PL/SQL reoutine to calibrate IO
p 623
IO service time histogram
p 625
Query IO calibration data
p 634
Size of an average redo log IO
p 636
Report of redo log related waits
p 637
Log switch rates from v$log_history
Chapter 22: Advanced IO techniques
p 645
ASM diskgroup IO throughput and service time
p 646
ASM disk-level throughput and service time
p 647
ASM rebalance operations in progress
p 647
ASM file level IO statistics
p 654
List all ASM templates
Chapter 23: Optimizing RAC
p 669
Break down of top level WAITCLASS waits
p 670
Break out of cluster waits compared to other categories
p 671
RAC waits over an interval of time
p 673
Global cache latency report
p 674
Global cache latency over a time period
p 675
Private interconnect IP address
p 677
Lost blocks report
p 681
LMS latency breakdown
p 682
redo log flush frequency and wait times
p 684
Cluster balance report
p 685
Cluster balance over a time period
p 689
Report on service workload by instance
p 693
"Global cache ""miss rate"" by instance "
p 694
Segments with the highest Global Cache activity