Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 15, 2016
0 parents
commit 8097231
Showing
127 changed files
with
2,337 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Freeware License, some rights reserved | ||
|
||
Copyright (c) 2011 Sam Alapati, Darl Kuhn, and Bill Padfield | ||
|
||
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. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#Apress Source Code | ||
|
||
This repository accompanies [*Oracle Database 11g Performance Tuning Recipes*](http://www.apress.com/9781430236627) by Sam Alapati, Darl Kuhn, and Bill Padfield (Apress, 2011). | ||
|
||
![Cover image](9781430236627.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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
CREATE DATABASE O11R2 | ||
MAXLOGFILES 16 | ||
MAXLOGMEMBERS 4 | ||
MAXDATAFILES 1024 | ||
MAXINSTANCES 1 | ||
MAXLOGHISTORY 680 | ||
CHARACTER SET AL32UTF8 | ||
DATAFILE | ||
'/ora01/dbfile/O11R2/system01.dbf' | ||
SIZE 500M REUSE | ||
EXTENT MANAGEMENT LOCAL | ||
UNDO TABLESPACE undotbs1 DATAFILE | ||
'/ora02/dbfile/O11R2/undotbs01.dbf' | ||
SIZE 800M | ||
SYSAUX DATAFILE | ||
'/ora03/dbfile/O11R2/sysaux01.dbf' | ||
SIZE 500M | ||
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE | ||
'/ora02/dbfile/O11R2/temp01.dbf' | ||
SIZE 500M | ||
DEFAULT TABLESPACE USERS DATAFILE | ||
'/ora01/dbfile/O11R2/users01.dbf' | ||
SIZE 50M | ||
LOGFILE GROUP 1 | ||
('/ora01/oraredo/O11R2/redo01a.rdo', | ||
'/ora02/oraredo/O11R2/redo01b.rdo') SIZE 200M, | ||
GROUP 2 | ||
('/ora01/oraredo/O11R2/redo02a.rdo', | ||
'/ora02/oraredo/O11R2/redo02b.rdo') SIZE 200M, | ||
GROUP 3 | ||
('/ora01/oraredo/O11R2/redo03a.rdo', | ||
'/ora02/oraredo/O11R2/redo03b.rdo') SIZE 200M | ||
USER sys IDENTIFIED BY topfoo | ||
USER system IDENTIFIED BY topsecrectfoo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
if [ $# -ne 1 ]; then | ||
echo "Usage: $0 SID" | ||
exit 1 | ||
fi | ||
# source oracle OS variables | ||
. /var/opt/oracle/oraset $1 | ||
# | ||
BOX=`uname -a | awk '{print$2}'` | ||
# | ||
sqlplus -s <<EOF | ||
mv_maint/foo | ||
spo $HOME/bin/log/seg.txt | ||
set lines 80 | ||
set pages 100 | ||
SELECT | ||
'Segment Advice --------------------------'|| chr(10) || | ||
'TABLESPACE_NAME : ' || tablespace_name || chr(10) || | ||
'SEGMENT_OWNER : ' || segment_owner || chr(10) || | ||
'SEGMENT_NAME : ' || segment_name || chr(10) || | ||
'ALLOCATED_SPACE : ' || allocated_space || chr(10) || | ||
'RECLAIMABLE_SPACE: ' || reclaimable_space || chr(10) || | ||
'RECOMMENDATIONS : ' || recommendations || chr(10) || | ||
'SOLUTION 1 : ' || c1 || chr(10) || | ||
'SOLUTION 2 : ' || c2 || chr(10) || | ||
'SOLUTION 3 : ' || c3 Advice | ||
FROM | ||
TABLE(dbms_space.asa_recommendations('FALSE', 'FALSE', 'FALSE')); | ||
EOF | ||
cat $HOME/bin/log/seg.txt | mailx -s "Seg. rpt. on DB: $1 $BOX" dkuhn@oracle.com | ||
exit 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
SELECT | ||
'Task Name : ' || f.task_name || chr(10) || | ||
'Segment Name : ' || o.attr2 || chr(10) || | ||
'Segment Type : ' || o.type || chr(10) || | ||
'Partition Name : ' || o.attr3 || chr(10) || | ||
'Message : ' || f.message || chr(10) || | ||
'More Info : ' || f.more_info TASK_ADVICE | ||
FROM dba_advisor_findings f | ||
,dba_advisor_objects o | ||
WHERE o.task_id = f.task_id | ||
AND o.object_id = f.object_id | ||
ORDER BY f.task_name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
select | ||
username | ||
,obj_name | ||
,to_char(timestamp,'dd-mon-yy hh24:mi') event_time | ||
,substr(ses_actions,4,1) del | ||
,substr(ses_actions,7,1) ins | ||
,substr(ses_actions,10,1) sel | ||
,substr(ses_actions,11,1) upd | ||
from dba_audit_object; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
create tablespace tools | ||
datafile '/ora01/dbfile/INVREP/tools01.dbf' | ||
size 100m -- Fixed datafile size | ||
extent management local -- Locally managed | ||
uniform size 128k -- Uniform extent size | ||
segment space management auto -- ASSM | ||
/ | ||
|
||
create bigfile tablespace tools_bf | ||
datafile '/ora01/dbfile/O11R2/tools_bf01.dbf' | ||
size 100m | ||
extent management local | ||
uniform size 128k | ||
segment space management auto | ||
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
SELECT | ||
'Segment Advice --------------------------'|| chr(10) || | ||
'TABLESPACE_NAME : ' || tablespace_name || chr(10) || | ||
'SEGMENT_OWNER : ' || segment_owner || chr(10) || | ||
'SEGMENT_NAME : ' || segment_name || chr(10) || | ||
'ALLOCATED_SPACE : ' || allocated_space || chr(10) || | ||
'RECLAIMABLE_SPACE: ' || reclaimable_space || chr(10) || | ||
'RECOMMENDATIONS : ' || recommendations || chr(10) || | ||
'SOLUTION 1 : ' || c1 || chr(10) || | ||
'SOLUTION 2 : ' || c2 || chr(10) || | ||
'SOLUTION 3 : ' || c3 Advice | ||
FROM | ||
TABLE(dbms_space.asa_recommendations('FALSE', 'FALSE', 'FALSE')); | ||
|
||
select | ||
segments_processed | ||
,end_time | ||
from dba_auto_segadv_summary | ||
order by end_time; | ||
|
||
select | ||
'Task Name : ' || f.task_name || chr(10) || | ||
'Start Run Time : ' || TO_CHAR(execution_start, 'dd-mon-yy hh24:mi') || chr (10) || | ||
'Segment Name : ' || o.attr2 || chr(10) || | ||
'Segment Type : ' || o.type || chr(10) || | ||
'Partition Name : ' || o.attr3 || chr(10) || | ||
'Message : ' || f.message || chr(10) || | ||
'More Info : ' || f.more_info || chr(10) || | ||
'------------------------------------------------------' Advice | ||
FROM dba_advisor_findings f | ||
,dba_advisor_objects o | ||
,dba_advisor_executions e | ||
WHERE o.task_id = f.task_id | ||
AND o.object_id = f.object_id | ||
AND f.task_id = e.task_id | ||
AND e. execution_start > sysdate - 1 | ||
AND e.advisor_name = 'Segment Advisor' | ||
ORDER BY f.task_name; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
DECLARE | ||
my_task_id number; | ||
obj_id number; | ||
my_task_name varchar2(100); | ||
my_task_desc varchar2(500); | ||
BEGIN | ||
my_task_name := 'F_REGS Advice'; | ||
my_task_desc := 'Manual Segment Advisor Run'; | ||
--------- | ||
-- Step 1 | ||
--------- | ||
dbms_advisor.create_task ( | ||
advisor_name => 'Segment Advisor', | ||
task_id => my_task_id, | ||
task_name => my_task_name, | ||
task_desc => my_task_desc); | ||
--------- | ||
-- Step 2 | ||
--------- | ||
dbms_advisor.create_object ( | ||
task_name => my_task_name, | ||
object_type => 'TABLE', | ||
attr1 => 'MV_MAINT', | ||
attr2 => 'F_REGS', | ||
attr3 => NULL, | ||
attr4 => NULL, | ||
attr5 => NULL, | ||
object_id => obj_id); | ||
--------- | ||
-- Step 3 | ||
--------- | ||
dbms_advisor.set_task_parameter( | ||
task_name => my_task_name, | ||
parameter => 'recommend_all', | ||
value => 'TRUE'); | ||
--------- | ||
-- Step 4 | ||
--------- | ||
dbms_advisor.execute_task(my_task_name); | ||
END; | ||
/ | ||
|
||
SELECT | ||
'Segment Advice --------------------------'|| chr(10) || | ||
'TABLESPACE_NAME : ' || tablespace_name || chr(10) || | ||
'SEGMENT_OWNER : ' || segment_owner || chr(10) || | ||
'SEGMENT_NAME : ' || segment_name || chr(10) || | ||
'ALLOCATED_SPACE : ' || allocated_space || chr(10) || | ||
'RECLAIMABLE_SPACE: ' || reclaimable_space || chr(10) || | ||
'RECOMMENDATIONS : ' || recommendations || chr(10) || | ||
'SOLUTION 1 : ' || c1 || chr(10) || | ||
'SOLUTION 2 : ' || c2 || chr(10) || | ||
'SOLUTION 3 : ' || c3 Advice | ||
FROM | ||
TABLE(dbms_space.asa_recommendations('TRUE', 'TRUE', 'FALSE')); | ||
|
||
SELECT | ||
'Task Name : ' || f.task_name || chr(10) || | ||
'Segment Name : ' || o.attr2 || chr(10) || | ||
'Segment Type : ' || o.type || chr(10) || | ||
'Partition Name : ' || o.attr3 || chr(10) || | ||
'Message : ' || f.message || chr(10) || | ||
'More Info : ' || f.more_info TASK_ADVICE | ||
FROM dba_advisor_findings f | ||
,dba_advisor_objects o | ||
WHERE o.task_id = f.task_id | ||
AND o.object_id = f.object_id | ||
AND f.task_name like 'F_REGS Advice' | ||
ORDER BY f.task_name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
select inst_id,p.server_name, | ||
p.status as p_status, | ||
p.pid as p_pid, | ||
p.sid as p_sid | ||
from gv$px_process p | ||
order by p.server_name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
select a.sid, a.serial#, b.spid, b.pid, | ||
a.username, a.osuser, a.machine | ||
from | ||
v$session a, | ||
v$process b | ||
where a.username IS NOT NULL | ||
and a.paddr=b.addr; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
select sid, serial#, username from v$session; | ||
|
||
execute dbms_monitor.session_trace_enable(session_id=>138,serial_num=>242,waits=>true,binds=>false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
select sql_id,sql_text | ||
from v$sql | ||
where sql_text='select sum(quantity_sold) from sales'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
select p.PID,p.SPID,s.SID | ||
from v$process p,v$session s | ||
where s.paddr = p.addr | ||
and s.sid = &SESSION_ID; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
create or replace trigger trace_my_user | ||
after logon on database | ||
begin | ||
if user='SH' then | ||
dbms_monitor.session_trace_enable(null,null,true,true); | ||
end if; | ||
end; | ||
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
SELECT client_name, status, consumer_group, window_group | ||
FROM dba_autotask_client | ||
ORDER BY client_name; | ||
|
||
SELECT task_name, status, TO_CHAR(execution_end,'DD-MON-YY HH24:MI') | ||
FROM dba_advisor_executions | ||
WHERE task_name='SYS_AUTO_SQL_TUNING_TASK' | ||
ORDER BY execution_end; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
BEGIN | ||
dbms_sqltune.create_sqlset( | ||
sqlset_name => 'IO_STS' | ||
description => 'STS from AWR'); | ||
END; | ||
/ | ||
|
||
SNAP_ID from DBA_HIST_SNAPSHOTS: | ||
select snap_id, begin_interval_time | ||
from dba_hist_snapshot order by 1; | ||
|
||
DECLARE | ||
base_cur dbms_sqltune.sqlset_cursor; | ||
BEGIN | ||
OPEN base_cur FOR | ||
SELECT value(x) | ||
FROM table(dbms_sqltune.select_workload_repository( | ||
26800,26900, null, null,'disk_reads', | ||
null, null, null, 15)) x; | ||
-- | ||
dbms_sqltune.load_sqlset( | ||
sqlset_name => 'IO_STS', | ||
populate_cursor => base_cur); | ||
END; | ||
/ | ||
|
||
SELECT | ||
sqlset_name | ||
,elapsed_time | ||
,cpu_time | ||
,buffer_gets | ||
,disk_reads | ||
,sql_text | ||
FROM dba_sqlset_statements | ||
WHERE sqlset_name = 'IO_STS'; | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- Create the tuning set | ||
EXEC DBMS_SQLTUNE.CREATE_SQLSET('HIGH_DISK_READS'); | ||
-- populate the tuning set from the cursor cache | ||
DECLARE | ||
cur DBMS_SQLTUNE.SQLSET_CURSOR; | ||
BEGIN | ||
OPEN cur FOR | ||
SELECT VALUE(x) | ||
FROM table( | ||
DBMS_SQLTUNE.SELECT_CURSOR_CACHE( | ||
'parsing_schema_name <> ''SYS'' AND disk_reads > 1000000', | ||
NULL, NULL, NULL, NULL, 1, NULL,'ALL')) x; | ||
-- | ||
DBMS_SQLTUNE.LOAD_SQLSET(sqlset_name => 'HIGH_DISK_READS', | ||
populate_cursor => cur); | ||
END; | ||
/ | ||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.