diff --git a/2976.pdf b/2976.pdf new file mode 100644 index 0000000..0fc4212 Binary files /dev/null and b/2976.pdf differ diff --git a/2977.pdf b/2977.pdf new file mode 100644 index 0000000..0e6f2a6 Binary files /dev/null and b/2977.pdf differ diff --git a/9781590595244.jpg b/9781590595244.jpg new file mode 100644 index 0000000..27d14a9 Binary files /dev/null and b/9781590595244.jpg differ diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..719d416 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,27 @@ +Freeware License, some rights reserved + +Copyright (c) 2006 John Shaw and Julian Dyke + +Permission is hereby granted, free of charge, to anyone obtaining a copy +of this software and associated documentation files (the "Software"), +to work with the Software within the limits of freeware distribution and fair use. +This includes the rights to use, copy, and modify the Software for personal use. +Users are also allowed and encouraged to submit corrections and modifications +to the Software for the benefit of other users. + +It is not allowed to reuse, modify, or redistribute the Software for +commercial use in any way, or for a user’s educational materials such as books +or blog articles without prior permission from the copyright holder. + +The above copyright notice and this permission notice need to be included +in all copies or substantial portions of the software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..3453549 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +#Apress Source Code + +This repository accompanies [*Pro Oracle Database 10g RAC on Linux*](http://www.apress.com/9781590595244) by John Shaw and Julian Dyke (Apress, 2006). + +![Cover image](9781590595244.jpg) + +Download the files as a zip using the green button, or clone the repository to your machine using Git. + +##Releases + +Release v1.0 corresponds to the code in the published book, without corrections or updates. + +##Contributions + +See the file Contributing.md for more information on how you can contribute to this repository. diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..f6005ad --- /dev/null +++ b/contributing.md @@ -0,0 +1,14 @@ +# Contributing to Apress Source Code + +Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. + +## How to Contribute + +1. Make sure you have a GitHub account. +2. Fork the repository for the relevant book. +3. Create a new branch on which to make your change, e.g. +`git checkout -b my_code_contribution` +4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. +5. Submit a pull request. + +Thank you for your contribution! \ No newline at end of file diff --git a/examples/ch23_ex1.sql b/examples/ch23_ex1.sql new file mode 100644 index 0000000..8d3121f --- /dev/null +++ b/examples/ch23_ex1.sql @@ -0,0 +1 @@ +SELECT time_id, channel_id, prod_id, ROUND (SUM(amount_sold)) AS TOTAL FROM SALES WHERE time_id BETWEEN '01-JAN-98' AND '31-JAN-98' AND prod_id IN (SELECT prod_id FROM products WHERE prod_name IN ('5MP Telephoto Digital Camera','17" LCD w/built-in HDTV Tuner','Envoy 256MB - 40GB','Y Box','Mini DV Camcorder with 3.5" Swivel LCD')) GROUP BY ROLLUP (time_id, (channel_id, prod_id)); diff --git a/examples/ch23_ex10.tcl b/examples/ch23_ex10.tcl new file mode 100644 index 0000000..91537e3 --- /dev/null +++ b/examples/ch23_ex10.tcl @@ -0,0 +1,49 @@ +#!/usr/local/bin/tclsh8.4 +package require Oratcl +#EDITABLEOPTIONS################################################## +set connect system/manager@rac1 +set rampup 2; #rampup time in minutes +set duration 10; #duration in minutes +#EDITABLEOPTIONS################################################## +set ramptime 0 +puts "Beginning rampup time of $rampup minutes" +set rampup [ expr $rampup*60000 ] +while {$ramptime != $rampup} { +after 60000 +set ramptime [ expr $ramptime+60000 ] +puts "Rampup [ expr $ramptime / 60000 ] minutes complete ..." +} +puts "Rampup complete, Taking start AWR snapshot." +set lda [oralogon $connect] +oraautocom $lda on +set curn1 [oraopen $lda ] +set sql1 "BEGIN dbms_workload_repository.create_snapshot(); END;" +oraparse $curn1 $sql1 +if {[catch {oraplexec $curn1 $sql1} message]} { error "Failed to create snapshot : $message" } +set sql2 "SELECT INSTANCE_NUMBER, INSTANCE_NAME, DB_NAME, DBID, SNAP_ID, TO_CHAR(END_INTERVAL_TIME,'DD MON YYYY HH24:MI') FROM ( SELECT DI.INSTANCE_NUMBER, INSTANCE_NAME, DB_NAME, DI.DBID, SNAP_ID, END_INTERVAL_TIME FROM DBA_HIST_SNAPSHOT DS, DBA_HIST_DATABASE_INSTANCE DI ORDER BY SNAP_ID DESC ) WHERE ROWNUM = 1" +if {[catch {orasql $curn1 $sql2} message]} { +error "SQL statement failed: $sql2 : $message" +} else { +orafetch $curn1 -datavariable firstsnap +split $firstsnap " " +puts "Start Snapshot [ lindex $firstsnap 4 ] taken at [ lindex $firstsnap 5 ] of instance [ lindex $firstsnap 1 ] ([lindex $firstsnap 0]) of database [ lindex $firstsnap 2 ] ([lindex $firstsnap 3])" +} +puts "Timing test period of $duration in minutes" +set testtime 0 +set duration [ expr $duration*60000 ] +while {$testtime != $duration} { +after 60000 +set testtime [ expr $testtime+60000 ] +puts -nonewline "[ expr $testtime / 60000 ] ...," +} +puts "Test complete, Taking end AWR snapshot." +oraparse $curn1 $sql1 +if {[catch {oraplexec $curn1 $sql1} message]} { error "Failed to create snapshot : $message" } +if {[catch {orasql $curn1 $sql2} message]} { +error "SQL statement failed: $sql2 : $message" +} else { +orafetch $curn1 -datavariable endsnap +split $endsnap " " +puts "End Snapshot [ lindex $endsnap 4 ] taken at [ lindex $endsnap 5 ] of instance [ lindex $endsnap 1 ] ([lindex $endsnap 0]) of database [ lindex $endsnap 2 ] ([lindex $endsnap 3])" +puts "Test complete: view report from SNAPID [ lindex $firstsnap 4 ] to [ lindex $endsnap 4 ]" +} diff --git a/examples/ch23_ex2.sql b/examples/ch23_ex2.sql new file mode 100644 index 0000000..f8f82c9 --- /dev/null +++ b/examples/ch23_ex2.sql @@ -0,0 +1,19 @@ + -- Listing hoex1.sql +variable t_id1 char(9); +execute :t_id1 := '01-JAN-98'; +variable t_id2 char(9); +execute :t_id2 := '31-JAN-98'; +variable pname1 varchar2(50); +execute :pname1 := '5MP Telephoto Digital Camera'; +variable pname2 varchar2(50); +execute :pname2 := '17" LCD w/built-in HDTV Tuner'; +variable pname3 varchar2(50); +execute :pname3 := 'Envoy 256MB - 40GB'; +variable pname4 varchar2(50); +execute :pname4 := 'Y Box'; +variable pname5 varchar2(50); +execute :pname5 := 'Mini DV Camcorder with 3.5" Swivel LCD'; +ALTER SESSION SET EVENTS '10046 trace name context forever, level 4'; +SELECT time_id, channel_id, prod_id, ROUND (SUM(amount_sold)) AS TOTAL FROM SALES WHERE time_id BETWEEN TO_DATE(:t_id1) AND TO_DATE(:t_id2) AND prod_id IN (SELECT prod_id FROM products WHERE prod_name IN (:pname1,:pname2,:pname3,:pname4,:pname5)) GROUP BY ROLLUP (time_id, (channel_id, prod_id)); +ALTER SESSION SET EVENTS '10046 trace name context off'; + diff --git a/examples/ch23_ex3.tcl b/examples/ch23_ex3.tcl new file mode 100644 index 0000000..729d8f6 --- /dev/null +++ b/examples/ch23_ex3.tcl @@ -0,0 +1,25 @@ + #!/usr/local/bin/tclsh8.4 +package require Oratcl +####UPDATE THE CONNECT STRING BELOW### +set connect user/password@rac1 +set lda [oralogon $connect] +set curn1 [oraopen $lda ] +set sql1 "ALTER SESSION SET EVENTS '10046 trace name context forever, level 4' " +orasql $curn1 $sql1 +set curn2 [oraopen $lda ] +set sql2 "SELECT time_id, channel_id, prod_id, ROUND +(SUM(amount_sold)) AS TOTAL FROM SALES WHERE time_id BETWEEN TO_DATE(:t_id1) AND TO_DATE(:t_id2) AND prod_id IN (SELECT prod_id FROM products WHERE prod_name IN (:pname1,:pname2,:pname3,:pname4,:pname5)) GROUP BY ROLLUP (time_id, (channel_id, prod_id)) " +orasql $curn2 $sql2 -parseonly +orabindexec $curn2 :pname3 {Envoy 256MB - 40GB} :pname4 {Y Box} :t_id1 {01-JAN-98} :pname5 {Mini DV Camcorder with 3.5" Swivel LCD} :pname1 {5MP Telephoto Digital Camera} :t_id2 {31-JAN-98} :pname2 {17" LCD w/built-in HDTV Tuner} +set row [orafetch $curn2 -datavariable output ] +while { [ oramsg $curn2 ] == 0 } { +puts $output +set row [orafetch $curn2 -datavariable output ] +} +oraclose $curn1 +set curn1 [oraopen $lda ] +set sql1 "ALTER SESSION SET EVENTS '10046 trace name context off' " +orasql $curn1 $sql1 +oraclose $curn1 +oralogoff $lda + diff --git a/examples/ch23_ex3_input1.txt b/examples/ch23_ex3_input1.txt new file mode 100644 index 0000000..00a562e --- /dev/null +++ b/examples/ch23_ex3_input1.txt @@ -0,0 +1,12 @@ +01-JAN-00:31-JAN-00:5MP Telephoto Digital Camera:17" LCD w/built-in HDTV Tuner:Envoy 256MB - 40GB:Y Box:Mini DV Camcorder with 3.5" Swivel LCD +01-FEB-00:29-FEB-00:Envoy Ambassador:Laptop carrying case:Home Theatre Package with DVD-Audio/Video Play:18" Flat Panel Graphics Monitor:Envoy External Keyboard +01-MAR-00:31-MAR-00:External 101-key keyboard:PCMCIA modem/fax 28800 baud:SIMM- 8MB PCMCIAII card:SIMM- 16MB PCMCIAII card:Multimedia speakers- 3" cones +01-APR-00:30-APR-00:Unix/Windows 1-user pack:8.3 Minitower Speaker:Mouse Pad:1.44MB External 3.5" Diskette:Multimedia speakers- 5" cones +01-MAY-00:31-MAY-00:PCMCIA modem/fax 19200 baud:External 6X CD-ROM:External 8X CD-ROM:Envoy External 6X CD-ROM:Envoy External 8X CD-ROM +01-JUN-00:30-JUN-00:Internal 6X CD-ROM:Internal 8X CD-ROM:O/S Documentation Set - English:O/S Documentation Set - German:O/S Documentation Set - French:O/S Documentation Set - Spanish +01-JUL-00:31-JUL-00:O/S Documentation Set - Italian:O/S Documentation Set - Kanji:Standard Mouse:Deluxe Mouse:Keyboard Wrist Rest:CD-R Mini Discs +01-AUG-00:31-AUG-00:Music CD-R:CD-RW, High Speed, Pack of 10:CD-RW, High Speed Pack of 5:CD-R, Professional Grade, Pack of 10:OraMusic CD-R, Pack of 10 +01-SEP-00:30-SEP-00:CD-R with Jewel Cases, pACK OF 12:DVD-R Disc with Jewel Case, 4.7 GB:DVD-RAM Jewel Case, Double-Sided, 9.4G:DVD-R Discs, 4.7GB, Pack of 5:DVD-R Discs, 4.7GB, Pack of 5 +01-OCT-00:31-OCT-00:DVD-RW Discs, 4.7GB, Pack of 3:3 1/2" Bulk diskettes, Box of 50:3 1/2" Bulk diskettes, Box of 100:Model CD13272 Tricolor Ink Cartridge:Model SM26273 Black Ink Cartridge +01-NOV-00:30-NOV-00:Model NM500X High Yield Toner Cartridge:Model A3827H Black Image Cartridge:Model K3822L Cordless Phone Battery:Model C9827B Cordless Phone Battery:Model K8822S Cordless Phone Battery +01-DEC-00:31-DEC-00:Model C93822D Wireless Phone Battery:S27273M Extended Use w/l Phone Batt.:64MB Memory Card:128MB Memory Card:256MB Memory Card diff --git a/examples/ch23_ex4.tcl b/examples/ch23_ex4.tcl new file mode 100644 index 0000000..29c6d13 --- /dev/null +++ b/examples/ch23_ex4.tcl @@ -0,0 +1,44 @@ + #!/usr/local/bin/tclsh8.4 +package require Oratcl +####UPDATE THE CONNECT STRING BELOW### +set connect sh/sh@rac +set lda [oralogon $connect] +set curn1 [oraopen $lda] +set sql1 "SELECT time_id, channel_id, prod_id, ROUND (SUM(amount_sold)) AS TOTAL FROM SALES WHERE time_id BETWEEN TO_DATE(:t_id1) AND TO_DATE(:t_id2) AND prod_id IN (SELECT prod_id FROM products WHERE prod_name IN (:pname1,:pname2,:pname3,:pname4,:pname5)) GROUP BY ROLLUP (time_id, (channel_id, prod_id)) " +orasql $curn1 $sql1 -parseonly +set fd [ open /home/oracle/input1.txt r ] +set flbuff [read $fd] +close $fd +set filelist [split $flbuff "\n"] +unset flbuff +foreach line $filelist { +set params [ split [ regsub -all {(\ \ )} $line {} ] ":" ] +set startdate [ string trim [ lindex $params 0 ] ] +set enddate [ string trim [ lindex $params 1 ] ] +set pname1 [ string trim [ lindex $params 2] ] +set pname2 [ string trim [ lindex $params 3] ] +set pname3 [ string trim [ lindex $params 4 ] ] +set pname4 [ string trim [ lindex $params 5 ] ] +set pname5 [ string trim [ lindex $params 6 ] ] +set value [ time { orabindexec $curn1 :t_id1 $startdate :t_id2 $enddate :pname1 $pname1 :pname2 $pname2 :pname3 $pname3 :pname4 $pname4 :pname5 $pname5 +set row [orafetch $curn1 -datavariable output ] +while { [ oramsg $curn1 ] == 0 } { +set row [orafetch $curn1 -datavariable output ] } } ] +regexp {([0-9]+)} $value all tim +lappend microsecs $tim +} +oraclose $curn1 +oralogoff $lda +set max 0 +foreach val $microsecs { +if { $val > $max } { set max $val } +} +puts "Maximum user response time was $max microseconds" +set sum 0 +foreach val $microsecs { +set sum [ expr { $sum+$val } ] +} +puts "Total user response time was $sum microseconds" +set N [ expr { [ llength $microsecs ] + 1 } ] +set average [ expr { $sum/$N } ] +puts "Average response time was $average microseconds" diff --git a/examples/ch23_ex5.tcl b/examples/ch23_ex5.tcl new file mode 100644 index 0000000..759a3b6 --- /dev/null +++ b/examples/ch23_ex5.tcl @@ -0,0 +1,6 @@ +proc RandomNumber { min max } { +set maxFactor [expr [expr $max + 1] - $min] +set value [expr int([expr rand() * 300000])] +set value [expr [expr $value % $maxFactor] + $min] +return $value +} diff --git a/examples/ch23_ex6.tcl b/examples/ch23_ex6.tcl new file mode 100644 index 0000000..4058d2d --- /dev/null +++ b/examples/ch23_ex6.tcl @@ -0,0 +1,4 @@ +set filelist [ list /home/oracle/input1.txt /home/oracle/input2.txt /home/oracle/input3.txt /home/oracle/input4.txt /home/oracle/input5.txt ] +set choice [ RandomNumber 0 [ expr $ll - 1 ] ] +set fc [ lindex $filelist $choice ] +set fd [ open $fc r ] diff --git a/examples/ch23_ex7.tcl b/examples/ch23_ex7.tcl new file mode 100644 index 0000000..dd26dd9 --- /dev/null +++ b/examples/ch23_ex7.tcl @@ -0,0 +1,9 @@ +set mythread [thread::id] +set allthreads [split [thread::names]] +set totalvirtualusers [expr [llength $allthreads] - 1] +set myposition [expr $totalvirtualusers - [lsearch -exact $allthreads $mythread]] +switch $myposition { +1 { puts "I am the first virtual user, I'll be inserting" } +2 { puts "I am the second virtual user, I'll be deleting" } +default { puts "I am a default virtual user, I'll be selecting" } +} diff --git a/examples/ch23_ex8.tcl b/examples/ch23_ex8.tcl new file mode 100644 index 0000000..314ebde --- /dev/null +++ b/examples/ch23_ex8.tcl @@ -0,0 +1,5 @@ +set start [ clock seconds ] +... +set end [ clock seconds ] +set wall [ expr $end - $start ] +puts "Wall time elapsed was $start to $end = $wall seconds" diff --git a/examples/ch23_ex9.tcl b/examples/ch23_ex9.tcl new file mode 100644 index 0000000..ea8feef --- /dev/null +++ b/examples/ch23_ex9.tcl @@ -0,0 +1,4 @@ +if {[ catch { ... } message] } { +puts $message +puts [ oramsg $curn1 all ] +}