03 -Oracle 10g Performance Tuning
description
Transcript of 03 -Oracle 10g Performance Tuning
Oracle 10g DBA
Performance Tuning
JENiSOFT SOLUTIONS
#40A, G2 Ponnammal Street, Kumaran Colony,
Vadapalni Chennai-600026 Mobile: 98409 41415
Nearest Land Mark: SRM UNIVERCITY
JENiSOFT SOLUTIONS Oracle 10g PT1
Oracle Performance Tuning
Optimizer Mode:
The goal of the query optimizer is the best throughput. This means that it chooses the
least amount of resources necessary to process all rows accessed by the statement.
Oracle can also optimize a statement with the goal of best response time. This means
that it uses the least amount of resources necessary to process the first row accessed by
a SQL statement.
RBO – Rule Based Optimizer mode
CBO – Cost Based Optimizer mode
Default keyword is “Choose”
o RULE
o ALL_ROWS
o FIRST_ROWS_n
o FIRST_ROWS
Choose Optimizer Mode:
Oracle will execute the rule-based optimizer if there are no statistics present for the
table or execute the cost-based optimizer if statistics are present.
RULE:
This Optimizer used to decide how to execute a given SQL statement.
One rule stated than an index would be used in favor of a full table scan
The Rule Based Optimizer (RBO) would always use this index to perform the query
EMP
ENO NUMBER PRIMARY KEY
JENiSOFT SOLUTIONS Oracle 10g PT2
ENAME VARCHAR2(30)
GENDER CHAR(1)
SQL > select * from emp where eno=101;
SQL > select * from emp where gender='F';
OPTIMIZER_INDEX_COST_ADJ :
Set between 1 and 10 to force index use more frequently and would pretty much
guarantee index use.
The range of values is 1 to 10000. Default of this parameter value is 100
SQL > show parameter optimizer_index_cost_adj;
SQL > alter system set optimizer_index_cost_adj=10;
OPTIMIZER_INDEX_CACHING :
The range of values 0 to 100 for this parameter.
OPTIMIZER_INDEX_CACHING indicates percentage of index blocks in the buffer
cache,
A value of 100 infers that 100% of the index blocks are likely to be found in the
buffer cache
SQL > show parameter optimizer_index_caching;
SQL > alter system set optimizer_index_caching=100;
OPTIMIZER_DYNAMIC_SAMPLING
If no statistics are available then the optimizer uses dynamic sampling.
This parameter should be set to a value of 2 or higher. The default value is 2
The range of value is 0 to 10 for this parameter.
A certain number of blocks are read by the dynamic sampling query based on this
parameter value.
Level 1 : Samples tables that appear in join or sub query conditions that have no
JENiSOFT SOLUTIONS Oracle 10g PT3
indexes and have more blocks than 32, the default for dynamic sampling.
Level 2 : Samples all unanalyzed tables that have more than 32 blocks.
Level 3 : Samples tables using a single column that applies selectivity to the table
being sampled.(2 X32)
Level : Samples tables using two or more columns that apply selectivity to the
table being sampled.(2 X 32)
Level 5 : Doubles the dynamic sample size and samples 64 blocks on tables.
Level 6 : Quadruples the dynamic sample size and samples 128 blocks on tables.
Level 7 : Samples 256 blocks on tables.
Level 8 : Samples 1,024 blocks on tables.
Level 9 : Samples 4,096 blocks on tables.
Level 10 : Samples all of the block in the tables.
SQL > show parameter optimizer_dynamic_sampling
SQL > alter system set optimizer_dynamic_sampling=2;
SQL > alter system set timed_statistices=TRUE;
SQL > ALTER SYSTEM SET statistics_level=typical;
SQL > ALTER SYSTEM SET statistics_level=all;
FIRST_ROWS
This is a cost-based optimizer mode that will return rows as soon as possible, even if the
overall query runs longer or consumes more resources.
The first_rows mode favors index scans over full-table scans,
ALL_ROWS:
JENiSOFT SOLUTIONS Oracle 10g PT4
This is a cost-based optimizer mode that ensures that the overall query time is
minimized, even if it takes longer to receive the first row.
The all_rows mode favors full-table scans,
The all_rows mode is best suited for batch-oriented queries where intermediate rows
are not required for viewing.
FIRST_ROWS_n:
optimizes with a goal of best responsetime to return the first n number of rows;
n can equal 1, 10, 100,or 1000
The first_rows_n mode using either full-table scans or fast index full scan
SQL > show parameter optimizer_mode;
SQL > alter system set optimizer_mode=choose;
Query Tuning or SQL Tuning:
Step 1:
$ top
SQL > select addr from v$process where spid=123;
X123H023
SQL > select sid,sql_id,sql_Address from v$session Where paddr=’ X123H023’;
SID SQL_ID SQL_ADDRESS
15 XA234 XhA234
SQL > select sql_text from v$sqlarea where SQL_ID=’ XA234’ and address=’ XhA234’;
Step 2:
SQL > select sid,sql_id,start_time from v$session_longops order by start_time;
SID SQL_ID StART_TIME
15 XA234 21-Nov-2010 10:30:33
JENiSOFT SOLUTIONS Oracle 10g PT5
SQL > select sql_text from v$sqlarea where SQL_ID=’ XA234’ ;
Step 3:
SQL > select b.username, a.disk_reads ,a.executions , a.disk_reads /a.executions, a.sql_text
from V$sqlarea a, dba_users b
where a.parsing_user_id = b.user_id and a.disk_reads > 100000
order by a.disk_reads desc;
USERNAME READS EXEC RDS_EXEC_RATIO STATEMENT
ADHOC1 7281934 1 7281934 select custno, ordno
from cust, orders
Step 4:
AWR report or statspack report or ADDM report.
Buffer Gets Exec Gets per Exec CPU Time (s) ElapTime (s) Hash Value
16,177,286 1 16,177,286.0 209.00 297.91 342588312
select sf.satz_id, f1.feld, f2.feld feld20, substr(sf.fehler
,instr(sf.fehler,'geschrieben:')+13) feld30
SQL tuning Method:
Autotrace method
Tkprof
Explain plan
Auotmatic SQL tuning
JENiSOFT SOLUTIONS Oracle 10g PT6
AutoTrace Method:
SET AUTOTRACE {ON | OFF | TRACEONLY | EXPLAIN | STATISTICS }
Step 1:
SQL > set autotrace on;
SQL > select * from emp where eno = 101;
ENO ENAME
101 Stanly
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=7 Card=1 Bytes=12)
1 0 TABLE ACCESS* (FULL) OF 'ENO' (Cost=7 Card=1 Bytes=12)
Statistics
0 db block gets
0 consistent gets
0 physical reads
0 sorts (memory)
0 sorts (disk)
Step 2:
SQL > set autotrace on;
SQL > analyze table EMP compute statistics;
Or
SQL > exec DBMS_STATS.GATHER_TABLE_STATS ('STANLY', 'EMP');
SQL > select * from emp where eno = 101;
JENiSOFT SOLUTIONS Oracle 10g PT7
ENO ENAME
101 Stanly
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=7 Card=1 Bytes=12)
1 0 TABLE ACCESS* (FULL) OF 'ENO' (Cost=7 Card=1 Bytes=12)
Statistics
90 db block gets
110 consistent gets
100 physical reads
0 sorts (memory)
0 sorts (disk)
% Ratio = (1-(Physical reads/(consistent gets + db block gets)))*100
SQL > create index ind_eno on emp (eno);
SQL > set autotrace on;
SQL > analyze table EMP compute statistics;
Or
SQL > exec DBMS_STATS.GATHER_TABLE_STATS ('STANLY', 'EMP');
SQL > select * from emp where eno = 101;
ENO ENAME
101 Stanly
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=12)
JENiSOFT SOLUTIONS Oracle 10g PT8
1 0 INDEX ACCESS OF 'IND_ENO' (Cost=2 Card=1 Bytes=12)
Statistics
90 db block gets
110 consistent gets
10 physical reads
0 sorts (memory)
0 sorts (disk)
Index Tuning:
SQL > analyze index IND_ENO validate structure;
Or
SQL > exec DBMS_STATS.GATHER_INDEX_STATS ('STANLY', 'IND_ENO');
INDEX_STATS:
NAME : Name of the index
DEL_LF_ROWS : Number of deleted leaf rows in the index
DEL_LF_ROWS_LEN : Total length of all deleted rows in the index
LF_ROWS : Number of leaf rows (values in the index)
LF_ROWS_LEN : Sum of the lengths of all the leaf rows
SQL > select (del_lf_row_len / lf_row_len)*100 from Index_stats where name=’IND_ENO’;
SQL > alter index IND_ENO monitoring usage;
SQL > select index_name,used,monitoring from v$object_usage where index_name=’IND_ENO’;
INDEX_NAME USED MONITORING
IND_ENO NO YES
SQL > alter index IND_ENO nomonitoring usage;
JENiSOFT SOLUTIONS Oracle 10g PT9
SQL > alter index IND_ENO coalesce;
SQL > alter index IND_ENO rebuild;
SQL > alter index IND_ENO rebuild online;
Row Chaining and Row Migration :
Method 1:
SQL > ANALYZE TABLE emp COMPUTE STATISTICS;
SQL > SELECT chain_cnt FROM dba_tables WHERE table_name = 'EMP';
Method 2:
SQL > @?/rdbms/admin/UTLCHAIN.SQL
SQL > ANALYZE TABLE emp LIST CHAINED ROWS;
SQL > select count(*) from chained_rows where owner_name='STANLY' and
Table_name='EMP';
Solutions:
1. Alter table emp move tablespace <old tablespace> to <new tablespace>;
2. export table / drop or truncate table/ import table
High Water Mark:
SQL > SELECT segment_name, blocks, segment_owner
FROM dba_segments WHERE segment_name='BIG_EMP1';
SEGMENT_NAME BLOCKS SEGMENT_OWNER
BIG_EMP1 1024 STANLY
SQL > ANALYZE TABLE stanly.big_emp1 ESTIMATE STATISTICS;
SQL> SELECT table_name, blocks, empty_blocks FROM dba_tables
WHERE table_name='BIG_EMP1' and owner='STANLY';
TABLE_NAME BLOCKS EMPTY_BLOCKS
JENiSOFT SOLUTIONS Oracle 10g PT10
BIG_EMP1 700 323
BLOCKS + EMPTY_BLOCKS (700+323=1023)
SQL> SELECT COUNT (DISTINCT DBMS_ROWID.ROWID_BLOCK_NUMBER (rowid)) "Used"
FROM stanly.big_emp1;
Used
700
SQL> DELETE from stanly.big_emp1;
SQL> commit;
SQL> ANALYZE TABLE stanly.big_emp1 ESTIMATE STATISTICS;
SQL> SELECT table_name, blocks, empty_blocks FROM dba_tables
WHERE table_name='BIG_EMP1' and owner='STANLY';
TABLE_NAME BLOCKS EMPTY_BLOCKS
BIG_EMP1 700 323
SQL> SELECT COUNT (DISTINCT DBMS_ROWID.ROWID_BLOCK_NUMBER (rowid)) "Used"
FROM stanly.big_emp1;
Used
0
Solutions :
Method 1:
Export stanly.big_emp1 table
SQL > TRUNCATE TABLE stanly.big_emp1;
Import stanly.big_emp1 table
Method 2:
JENiSOFT SOLUTIONS Oracle 10g PT11
SQL > alter table stanly.big_emp1 enable row movement;
SQL > alter table stanly.big_emp1 shrink space;
SQL > ANALYZE TABLE big_emp1 ESTIMATE STATISTICS;
SQL> SELECT table_name, blocks, empty_blocks FROM dba_tables
WHERE table_name='BIG_EMP1' and owner='STANLY';
TABLE_NAME BLOCKS EMPTY_BLOCKS
BIG_EMP1 0 511
Tkprof Method:
SQL > alter session set sql_trace=true;
SQL > SELECT * FROM emp, dept WHERE emp.deptno = dept.deptno;
SQL > alter session set sql_trace=false
$ tkprof /u01/admin/prod/udump/ora_prod_124.trc /u01/emp_trace.txt
$ more /u01/emp_trace.txt
SELECT * FROM emp, dept WHERE emp.deptno = dept.deptno;
call count cpu elapsed disk query current rows
Parse 11 0.08 0.18 0 0 0 0
Execute 11 0.23 0.66 0 3 6 0
Fetch 35 6.70 6.83 100 12326 2 824
Total 57 7.01 7.67 100 12329 8 824
%Ratio = ( 1 - ( Disk / ( Query + Current ) ) ) * 100
Rows Execution Plan
JENiSOFT SOLUTIONS Oracle 10g PT12
14 MERGE JOIN
4 SORT JOIN
4 TABLE ACCESS (FULL) OF 'DEPT'
14 SORT JOIN
14 TABLE ACCESS (FULL) OF 'EMP'
Explain Plan Method:
SQL > @?/rdbms/admin/utlxplan.sql
SQL > EXPLAIN PLAN SET STATEMENT_ID = 'st1' FOR SELECT last_name FROM emp;
SQL > select operation, options, object_name, cost, cardinality, bytes, cpu_cost
from plan_table where statement_id='st1';
OPERATION OPTIONS OBJECTNAME COST CARD BYTES CPUCOST
Select statement Full Access EMP 7 100 1024 75
Automatic SQL Tuning:
SQL > exec DBMS_SQLTUNE.create_tuning_task
(
sql_text => 'SELECT e.eno,e.ename, d.dno,d.dname
FROM emp e, dept d where e.deptno = d.deptno ',
user_name => 'scott',
scope => DBMS_SQLTUNE.scope_comprehensive,
time_limit => 60,
task_name => 'emp_dept_tuning_task',
description => 'Tuning task for an EMP to DEPT join query.'
);
SQL > exec EXEC DBMS_SQLTUNE.execute_tuning_task (task_name => 'emp_dept_tuning_task');
JENiSOFT SOLUTIONS Oracle 10g PT13
SQL > SELECT task_name, status FROM dba_advisor_log WHERE owner = 'SCOTT';
TASK_NAME STATUS
emp_dept_tuning_task COMPLETED
SQL > SELECT DBMS_SQLTUNE.report_tuning_task('emp_dept_tuning_task') AS
recommendations FROM dual;
RECOMMENDATIONS
GENERAL INFORMATION SECTION
Tuning Task Name : emp_dept_tuning_task
Scope : COMPREHENSIVE
Time Limit(seconds) : 60
Completion Status : COMPLETED
Started at : 05/11/2010 09:29:13
Completed at : 05/11/2010 09:29:15
-------------------------------------------------------------------------------
SQL ID : 0wrmfv2yvswx1
SQL Text : SELECT e.eno,e.ename, d.dno,d.dname FROM emp e, dept d
where e.deptno = d.deptno
-------------------------------------------------------------------------------
FINDINGS SECTION (1 findings)
1- Statistics Finding
Table "SCOTT"."EMP" and its indices were not analyzed.
Recommendation
JENiSOFT SOLUTIONS Oracle 10g PT14
Consider collecting optimizer statistics for this table and its indices.
execute dbms_stats.gather_table_stats(ownname => 'SCOTT', tabname =>
'EMP', estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE,
method_opt => 'FOR ALL COLUMNS SIZE AUTO', cascade => TRUE)
SQL > execute dbms_stats.gather_table_stats(ownname => 'SCOTT',
tabname =>'EMP', estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE,
method_opt => 'FOR ALL COLUMNS SIZE AUTO', cascade => TRUE)
SQL > EXEC DBMS_SQLTUNE.reset_tuning_task (task_name => 'emp_dept_tuning_task');
SQL > exec EXEC DBMS_SQLTUNE.execute_tuning_task (task_name => 'emp_dept_tuning_task');
SQL > SELECT DBMS_SQLTUNE.report_tuning_task('emp_dept_tuning_task') AS
recommendations FROM dual;
RECOMMENDATIONS
GENERAL INFORMATION SECTION
Tuning Task Name : emp_dept_tuning_task
Scope : COMPREHENSIVE
Time Limit(seconds) : 60
Completion Status : COMPLETED
Started at : 05/11/2010 09:29:13
Completed at : 05/11/2010 09:29:15
There are no recommendations...
SQL > exec DBMS_SQLTUNE.drop_tuning_task (task_name => 'emp_dept_tuning_task');
Statspack Report:
SQL > @?/rdbms/admin/spcreate.sql
Choose the PERFSTAT user's password
JENiSOFT SOLUTIONS Oracle 10g PT15
Enter value for perfstat_password : perfstat
Choose the Default tablespace for the PERFSTAT user
TABLESPACE_NAME CONTENTS STATSPACK
PERFSTAT PERMANENT
SYSAUX PERMANENT *
USERS PERMANENT
Enter value for default_tablespace: PERFSTAT
Choose the Temporary tablespace for the PERFSTAT user
TABLESPACE_NAME CONTENTS DB
TEMP TEMPORARY *
Enter value for temporary_tablespace: TEMP
.....
Creating Package STATSPACK...
No errors.
NOTE:
SPCPKG complete. Please check spcpkg.lis for any errors.
SQL > show user;
User “PERFSTAT”
SQL> SELECT * FROM stats$level_description ORDER BY snap_level;
Level 0 : This level captures general statistics, including rollback segment, row
cache, SGA, system events, background events, session events, system
statistics, wait statistics, lock statistics, and Latch information.
Level 5 : This level includes capturing high resource usage SQL Statements, along
JENiSOFT SOLUTIONS Oracle 10g PT16
with all data captured by lower levels.
Level 6 : This level includes capturing SQL plan and SQL plan usage information for
high resource usage SQL Statements, along with all data captured by lower
levels.
Level 7 : This level captures segment level statistics, including logical and
physical reads, row lock, itl and buffer busy waits, along with all data
captured by lower levels.
Level 10 : This level includes capturing Child Latch statistics, along with all data
captured by lower levels.
SQL> exec statspack.snap(i_snap_level => 6, i_modify_parameter => 'true');
SQL> exec statspack.snap;
SQL> exec statspack.snap;
SQL> select snap_id,to_char(snap_time,'DD.MM.YYYY:HH24:MI:SS') "Date/Time"
from stats$snapshot ;
SNAP_ID Date/Time
1 13.11.2010:08:48:47
2 13.11.2010:09:00:01
3 13.11.2010:10:30:48
4 13.11.2010:11:00:01
SQL> @?/rdbms/admin/spreport.sql
SNAP_ID Date/Time
1 13.11.2010:08:48:47
2 13.11.2010:09:00:01
3 13.11.2010:10:30:48
4 13.11.2010:11:00:01
JENiSOFT SOLUTIONS Oracle 10g PT17
Enter Begin Snap Id : 3
Enter End Snap Id : 4
Enter statspack report Name : /u01/Prod_snap_3_4_report.txt
$ more /u01/Prod_snap_3_4_report.txt
STATSPACK report for
DB Name DB Id Instance Inst Num Release RAC Host
--------------------------------------------------------------------------------------------------------------------------------
PROD 2006521736 PROD 1 10.2.0.4.0 NO Linux1_prod
Snap Id Snap Time Sessions Curs/Sess Comment
--------------------------------------------------------------------------------------------
Begin Snap: 3 13-Nov-10 10:30:48 15 14.3
End Snap: 4 13-Nov-10 11:00:01 15 10.2
Elapsed: 30.00 (mins)
Cache Sizes (end)
~~~~~~~~~~~~~~~~~
Buffer Cache : 24M Std Block Size : 4K
Shared Pool Size : 764M Log Buffer : 1,000K
Instance Efficiency Percentages (Target 100%)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Buffer Nowait % : 100.00 Redo NoWait % : 99.99
Buffer Hit % : 95.39 In-memory Sort % : 100.00
Library Hit % : 99.42 Soft Parse % : 94.45
JENiSOFT SOLUTIONS Oracle 10g PT18
Execute to Parse % : 36.39 Latch Hit % : 100.00
Parse CPU to Parse Elapsd % : 59.15 % Non-Parse CPU : 99.31
Top 5 Timed Events
~~~~~~~~~~~~~~~~~~ % Total
Event Waits Time (s) Call Time
-------------------------------------------- ------------ ----------- ---------
CPU time 122 91.65
db file sequential read 1,571 2 1.61
db file scattered read 1,174 2 1.59
log file sequential read 342 2 1.39
control file parallel write 450 2 1.39
SQL ordered by Gets
---------------------------
Buffer Gets Executions Gets per Exec %Total CPU Time (s) Hash Value
--------------- ------------ -------------- ---------- ----------------- --------- ----------
16,926 1 16,926.0 2.3 2.36 1279400914
Module: SQL*Plus
create table test as select * from all_objects
SQL > @?/rdbms/admin/sprepsql.sql
Enter the Hash Value : 1279400914
SQL > @?/rdbms/admin/spauto.sql
SQL > @?/rdbms/admin/sppurge.sql
JENiSOFT SOLUTIONS Oracle 10g PT19
Enter lower snap id : 1
Enter upper snap id : 50
SQL > @?/rdbms/admin/spdrop.sql
AWR Report:
SQL > exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT ( );
SQL > exec DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS
( retention => 43200, interval => 30)
SQL > @?/rdbms/admin/awrrpt.sql
Enter value for report_type [ HTML / TEXT ] : text
Enter value for num_days : 2
SNAP_ID Date/Time
150 13.11.2010:08:48:47
151 13.11.2010:09:00:01
152 13.11.2010:10:30:48
153 13.11.2010:11:00:01
Enter value for begin_snap : 150
Enter value for end_snap : 153
Enter value for report_name : /u01/awrrpt_1_150_153
$ more /u01/awrrpt_1_150_153
SQL > select * from DBA_HIST_SNAPSHOT;
SQL > exec DBMS_WORKLOAD_REPOSITORY.DROP_SNAPSHOT_RANGE
(low_snap_id => 22, high_snap_id => 32)
JENiSOFT SOLUTIONS Oracle 10g PT20
ADDM Report:
SQL > @$?/rdbms/admin/addmrpt.sql
Instance DB Name Snap Id Snap Started
PROD PROD 136 20 Oct 2010 18:30
137 20 Oct 2010 19:00
138 20 Oct 2010 19:30
139 20 Oct 2010 20:00
140 20 Oct 2010 20:30
141 20 Oct 2010 21:00
142 20 Oct 2010 21:30
Enter value for begin_snap : 137
Enter value for end_snap : 141
Enter value for report_name : /u01/addmrpt_1_137_145.txt
$ more /u01/addmrpt_1_137_145.txt
FINDING 1 : 59% impact (944 seconds)
The buffer cache was undersized causing significant additional read I/O.
RECOMMENDATION 1: DB Configuration, 59% benefit (944 seconds)
ACTION: Increase SGA target size by increasing the value of parameter
"sga_target" by 28 M.
FINDING 2 : 31% impact (7798 seconds)
SQL statements were not shared due to the usage of literals. This resulted in
additional hard parses which were consuming significant database time.
JENiSOFT SOLUTIONS Oracle 10g PT21
RECOMMENDATION 1: Application Analysis, 31% benefit (7798 seconds)
ACTION: Investigate application logic for possible use of bind variables
instead of literals. Alternatively, you may set the parameter
"cursor_sharing" to "force".
Memory Tuning :
Database Buffer Cache
Redo log Buffer
Shared Pool
Database Buffer Cache:
V$sysstat
Statspack
AWR report
ADDM report
SQL > select (1 – ( p.value / ( d.value + c.value ) ) )*100 from v$sysstat p, v$sysstat d, v$sysstat c
Where p.name =’physical reads’ and d.name = ‘db block gets’ and
c.name = ‘consistent gets’ ;
Solutions :
Method 1:
SQL > alter system set db_cache_advice=on;
SQL > SELECT size_for_estimate, estd_physical_read_factor, estd_physical_reads
FROM V$DB_CACHE_ADVICE WHERE name = 'DEFAULT'
Size for Estimate Estd_physical read factor Estd_physical reads
243 1.33 13,720,149
273 1.13 11,583,180
304 1.00 10,282,475
JENiSOFT SOLUTIONS Oracle 10g PT22
334 .93 9,515,878
364 .87 8,909,026
395 .83 8,909,026
424 .79 8,909,026
SQL > alter system set db_cache_size=364M;
Method 2:
SQL > alter system set db_keep_cache_size=180M;
SQL > alter system set db_recycle_cache_size=364M;
SQL > SELECT o.OBJECT_NAME, COUNT(*) FROM DBA_OBJECTS o, V$BH bh
WHERE o.DATA_OBJECT_ID = bh.OBJD AND o.OWNER != 'SYS' GROUP BY o.OBJECT_NAME
Object_name Count
OM_EXT_HEADER 701
OM_SHELL 1,765
OM_HEADER 5,826
OM_INSTANCE 12,644
SQL > alter table OM_HEADER storage (buffer_pool keep);
SQL > alter table OM_INSTANCE storage (buffer_pool recycle);
SQL > select segment_name, buffer_pool from dba_segments;
SQL > SELECT NAME, 1 - (PHYSICAL_READS / (DB_BLOCK_GETS + CONSISTENT_GETS))
FROM V$BUFFER_POOL_STATISTICS order by name;
Redo log Buffer:
V$sysstat
Statspack
AWR report
ADDM report
SQL > SELECT SUM(value) "Redo Buffer Waits" FROM v$sysstat
JENiSOFT SOLUTIONS Oracle 10g PT23
WHERE name = 'redo log space wait time';
SQL > Select (r.value/e.value)*100 from v$sysstat r, v$sysstat e
Where r.name = 'redo buffer allocation retries' and e.name = 'redo entries';
SQL > alter system set log_buffer = scope=spfile;
SQL > shutdown immediate;
SQL > startup;
Checkpoint tuning:
LOG_CHECKPOINT_TIMEOUT = <no of sconds>
LOG_CHECKPOINT_INTERVAL = <no of OS blocks>
LOG_CHECKPOINTS_TO_ALERT = <TRUE / FALSE >
Thread 1 advanced to log sequence 248
Current log# 2 seq# 248 mem# 0: /prod1/oradata/logs/redologs02.log
Thread 1 cannot allocate new log, sequence 249
Checkpoint not complete
SQL > select name,value from v$sysstat where name like 'background checkpoint%'
NAME VALUE
Background checkpoint – start 30
Background checkpoint completed 27
SQL> select event, time_waited from v$system_event
where event = 'log file switch (checkpoint incomplete)';
SQL > alter system set FAST_START_MTTR_TARGET=120;
SQL > SELECT TARGET_MTTR, ESTIMATED_MTTR FROM V$INSTANCE_RECOVERY;
TARGET_MTTR ESTIMATED_MTTR
214 12
JENiSOFT SOLUTIONS Oracle 10g PT24
SQL > alter system set FAST_START_MTTR_TARGET=214;
SQL > SELECT OPTIMAL_LOGFILE_SIZE FROM V$INSTANCE_RECOVERY;
OPTIMAL_LOGFILE_SIZE
180
SQL> select event, time_waited from v$system_event
where event = 'log file switch (archiving needed)';
SQL > alter system set log_archive_max_processes=5;
Shared Pool Tuning:
V$librarycache
V$rowcache
Statspack Report
AWR Report
ADDM Report
SQL > select ( 1 - ( sum ( pinhits ) / sum( pins ) ) ) *100 from v$librarycache;
SQL > select ( 1 - ( sum ( reloads ) / sum ( pins ) ) ) * 100 from v$librarycache;
SQL > select ( 1 - ( sum ( getmiss ) / sum ( gets ) ) ) * 100 from v$rowcahce;
Solutions:
Method 1:
SQL > SELECT shared_pool_size_for_estimate ,shared_pool_size_factor,
estd_lc_time_saved, estd_lc_time_saved_factor FROM V$SHARED_POOL_ADVICE;
Size Size factor Time Saved Time Saved Factor
96 .8571 289654 .89
112 1 289660 .97
128 1.1429 289665 1
JENiSOFT SOLUTIONS Oracle 10g PT25
144 1.2857 289704 1.0002
160 1.4286 289707 1.0002
176 1.5714 289708 1.0002
SQL > alter system set shared_pool_size = 128M;
Method 2:
SQL > alter system set shared_pool_reserved_size=<10% of shared_pool size>
SQL > @?/rdbms/admin/dbmspool.sql
SQL > execute dbms_shared_pool.keep('PNAME');
SQL > execute dbms_shared_pool.keep('DBMS_DDL');
SQL > select name,sharable_mem,executions from v$db_object_cache where kept='YES';
SQL > execute dbms_shared_pool.unkeep('PNAME');
SQL > select (FREE_SPACE/1024/1024), REQUEST_MISSES, REQUEST_FAILURES
from V$SHARED_POOL_RESERVED;
FREE_SPACE REQUEST_MISSES REQUEST_FAILURES
47 0 0
Method 3:
SQL> ALTER SYSTEM FLUSH SHARED_POOL;
SQL > select * from emp where deptno=12;
SQL > select * from emp where deptno=13
SQL > select * from emp where deptno=14;
SQL> SELECT sql_text, executions FROM v$sqlarea
WHERE sql_text like 'select * from emp where deptno%'
SQL_TEXT EXECUTIONS
JENiSOFT SOLUTIONS Oracle 10g PT26
select * from emp where deptno=12 1
select * from emp where deptno=13 1
select * from emp where deptno=14 1
SQL> ALTER SYSTEM FLUSH SHARED_POOL;
SQL> variable a number
SQL> exec : a := 12
SQL> select * from emp where deptno = :a;
SQL> exec : a:= 13
SQL> select * from emp where deptno = :a;
SQL> exec : a := 14
SQL> select * from emp where deptno = :a;
SQL> SELECT sql_text, executions FROM v$sqlarea
WHERE sql_text like 'select * from emp where deptno%'
SQL_TEXT EXECUTIONS
select * from emp where deptno = :a 3
Method 4:
1. OPEN_CURSOR
SQL > alter system set OPEN_CURSOR=500;
SQL> select max(a.value) as Curr_Used_open_cur, p.value as max_open_cur
from v$sesstat a, v$statname b, v$parameter p
where a.statistic# = b.statistic# and b.name = 'opened cursors current'
and p.name= 'open_cursors' group by p.value;
Currently_Used_OPEN_CUR MAX_OPEN_CUR
JENiSOFT SOLUTIONS Oracle 10g PT27
490 500
2. CURSOR_SPACE_FOR_TIME = { TRUE | FALSE }
SQL > alter system set cursor_space_for_time=TRUE;
3. CURSOR_SHARING={ exact | similar | force }
SQL > alter system set cursor_sharing=similar;
Automatic Shared Memory Management (ASMM) :
SQL > show parameter SGA_MAX_SIZE;
SQL > show parameter SGA_TARGET;
SQL > alter system set sga_target=540M;
SQL > alter system set statistics_level=typical;
Auto Tuned parameter or Components
o DB_CACHE_SIZE
o SHARED_POOL_SIZE
o LARGE_POOL_SIZE
o JAVE_POOL_SIZE
o STREAMS_POOL_SIZE
Manual tuned parameter or Components
o LOG_BUFFER
o DB_KEEP_CACHE_SIZE
o DB_RECYCLE_CACHE_SIZE
SQL > select component, oper_type, initial_size/1024/1024 ,
TARGET_SIZE/1024/1024, FINAL_SIZE/1024/1024, status
from v$sga_resize_ops;
JENiSOFT SOLUTIONS Oracle 10g PT28
COMPONENT OPER_TYPE INITIAL TARGET FINAL STATUS
DEFAULT buffer cache SHRINK 160 148 148 COMPLETE
streams pool GROW 0 12 12 COMPLETE
SQL > select component, current_size/1024/1024, user_specified_size/1024/1024 ,
last_oper_type from v$sga_dynamic_components;
COMPONENT CURRENT_SIZE USER_SPECIFIED_SIZE TYPE
shared pool 80 80 STATIC
large pool 8 8 STATIC
java pool 48 48 STATIC
streams pool 12 12 GROW
DEFAULT buffer cache 48 24 SHRINK
SQL > select * from V$SGA_DYNAMIC_FREE_MEMORY;
Shows free memory available for future SGA memory resize.
SQL > select * from V$SGA_CURRENT_RESIZE_OPS
Currently SGA resize operations in progress.
SQL > select sga_size, (1 - estd_db_time_factor ) *100 “ESTD FACTOR”
from v$sga_target_advice order by sga_size;
SGA_SIZE ESTD FACTOR
171 -2,41
228 0
285 1,2
342 2,41
399 2,41
JENiSOFT SOLUTIONS Oracle 10g PT29
456 2,41
SQL > alter system set sga_target=342M;
Automatic PGA Memory Management (APMM) :
Session Data
Private SQL Area
Persistent Area Run Time Area
SQL work Area
Bitmap
Merge
Area
Create Bitmap
Area
Hash
Join
Area
Sort
Area
BITMAP_MERGE_AREA_SIZE = 1M
CREATE_BITMAP_AREA_SIZE = 8M
HASH_AREA_SIZE = (2 * SORT_AREA_SIZE)
SORT_AREA_SIZE = 64K
SQL > show parameter PGA_AGGREGATE_TARGET;
WORKAREA_SIZE_POLICY= { AUTO | MANUAL }
SQL > show parameter WORKAREA_SIZE_POLICY;
For OLTP : PGA_AGGREGATE_TARGET = (total_mem * 80%) * 20%
For DSS : PGA_AGGREGATE_TARGET = (total_mem * 80%) * 50%
JENiSOFT SOLUTIONS Oracle 10g PT30
SQL > SELECT * FROM V$PGASTAT;
NAME VALUE UNIT
aggregate PGA target parameter 41156608 bytes
cache hit percentage 98.15 percent
SQL > SELECT PGA_TARGET_FOR_ESTIMATE/1024/1024,
ESTD_PGA_CACHE_HIT_PERCENTAGE, ESTD_OVERALLOC_COUNT
FROM V$PGA_TARGET_ADVICE;
TARGET_MB CACHE_HIT_PERC ESTD_OVERALLOC_COUNT
63 60 367
125 84 30
250 95 0
375 100 0
500 100 0
600 100 0
Sort Area Tuning:
SQL > select ( 1 - ( d.value / m.value ) ) * 100 from v$sysstat d, v$sysstat m
where d.name='sorts (disk)' and m.name='sorts (memory)';
SORT_AREA_SIZE= (SORT_AREA_SIZE + (MAX_USED_BLOCKS * DB_BLOCK_SIZE))
SQL > show parameter SORT_AREA_SIZE;
SQL > show parameter DB_BLOCK_SIZE;
SQL > select MAX_USED_BLOCKS from v$sort_segment;
SQL > alter system set SORT_AREA_SIZE= ;
Disk IO Tuning:
JENiSOFT SOLUTIONS Oracle 10g PT31
SQL > select d.name, f.phyrds, f.readtim / f.phyrds,
f.phywrts, f.writetim / f.phywrts
from v$filestat f, v$database d where f.file# = d.file# ;
Oracle Locks:
Session 1
SQL> update emp set sal=sal+1 where empno=7566;
Session 2
SQL> update emp set sal=sal+1 where empno=7566;
Hanged….
Session 3
SQL> drop table emp ;
ORA-00054: resource busy and acquire with NOWAIT specified
SQL > select XIDUSN,object_id,session_id,oracle_username from v$locked_object;
XIDUSN OBJECT ID SESSION_ID ORACLE USERNAME
10 123 9 JOHN
15 147 12 ANTONY
0 123 15 BRITTO
0 147 21 STANLY
SQL > select sid,serial# from v$session where sid= 9;
SID SERIAL#
9 151
SQL > alter system kill session ‘ 9,151 ‘;
JENiSOFT SOLUTIONS Oracle 10g PT32
SQL > select sid,serial# from v$session where sid= 12;
SID SERIAL#
12 181
SQL > alter system kill session ‘ 12,181 ‘;
Data Migration from 8.1.7.0 to 10.2.0.1
Pre-check and post check :
SQL > select sum(bytes)/1024/1024/1024 from dba_data_files;
SQL > select sum(bytes)/1024/1024/1024 from dba_segments;
SQL > select tablespace_name,sum(bytes)/1024/1024 from dba_data_files
group by tablespace_name;
SQL > select tablespace_name,sum(bytes)/1024/1024 from dba_segments
group by tablespace_name;
SQL > select count(*) from dba_users where username not in ('SYS','SYSTEM');
SQL > select owner,count(*) from dba_tables where owner not in ('SYS','SYSTEM')
group by owner;
SQL > select owner,count(*) from dba_indexes where owner not in ('SYS','SYSTEM')
group by owner;
SQL > select owner,count(*) from dba_constraints where owner not in ('SYS','SYSTEM')
group by owner;
SQL > select owner,count(*) from dba_objects where owner not in ('SYS','SYSTEM')
group by owner;
SQL > select owner,count(*) from dba_objects where owner not in ('SYS','SYSTEM')
JENiSOFT SOLUTIONS Oracle 10g PT33
and status <> 'VALID' group by owner;
Target Sever 8.1.7.4.0
$ . oraenv
ORACLE_SID: prod
$ sqlplus “/ as sysdba”
SQL> shutdown immediate;
$ lsnrctl stop <Listener_name>
$ sqlplus “/ as sysdba”
SQL > startup restrict
SQL > exit;
$ exp \'/ as sysdba \' FULL=Y FILE=full_prod.dmp BUFFER=157286400 STATISTICS=NONE
LOG=full_prod.log
$ scp –r full_prod.dmp [email protected]:/opt/oradata
Destination Server 10.2.0.1.0
$ . oraenv
ORACLE_SID: prod
$ sqlplus “/ as sysdba”
SQL > select instance_name,status from v$instance;
SQL > select tablespace_name,sum(bytes)/1024/1024 from dba_data_files
JENiSOFT SOLUTIONS Oracle 10g PT34
group by tablespace_name;
$ imp \'/ as sysdba \' FULL=Y FILE=full_prod.dmp BUFFER=157286400 STATISTICS=NONE
LOG=full_prod.log
Upgrade 9.2.0.7.0 to 10.2.0.1.0
$ . oraenv
ORACLE_SID:prod
$ sqlplus “/ as sysdba”
SQL > @/opt/oracle/product/10.2.0/rdbms/admin/utlu102i.sql
(1) Logfiles: [make adjustments in the current environment]
*************************************************************************
The existing log files are adequate. No changes are required.
(2) Tablespaces: [make adjustments in the current environment]
********************************************************************** *******
--> SYSTEM tablespace is adequate for the upgrade ... minimum required size: 532 MB
--> TEMP tablespace is adequate for the upgrade. ... minimum required size: 58 MB
--> USERS tablespace is adequate for the upgrade ... minimum required size: 10199 MB
--> UNDO1 tablespace is adequate for the upgrade ... minimum required size: 185 MB
(3) Update Parameters: [Update Oracle Database 10.2 init.ora or spfile]
**********************************************************************
WARNING: --> "streams_pool_size" is not currently defined and needs a value of at least
JENiSOFT SOLUTIONS Oracle 10g PT35
50331648
WARNING: --> "pga_aggregate_target" needs to be increased to at least 25165824
WARNING: --> "session_max_open_files" needs to be increased to at least 20
(4) Renamed Parameters: [Update Oracle Database 10.2 init.ora or spfile]
**********************************************************************
-- No renamed parameters found. No changes are required.
(5) Obsolete/Deprecated Parameters: [Update Oracle Database 10.2 init.ora or spfile]
**********************************************************************
--> "hash_join_enabled"
--> "log_archive_start"
--> "parallel_automatic_tuning"
(6) SYSAUX Tablespace:
[Create tablespace in the Oracle Database 10.2 environment]
**********************************************************************
--> New "SYSAUX" tablespace .... minimum required size for database upgrade: 500 MB
SQL > create tablespace sysaux
datafile ‘/opt/oradata/sysaux01.dbf’ size 500M
extent management local
segment space management auto
online;
SQL > create pfile from spfile;
SQL > select comp_name, status, version from dba_registry;
SQL > shutdown immediate;
$ cp /opt/oracle/product/9.2.0/dbs/initprod.ora /opt/oracle/product/10.2.0/dbs
JENiSOFT SOLUTIONS Oracle 10g PT36
$ cp /opt/oracle/product/9.2.0/dbs/orapwprod /opt/oracle/product/10.2.0/dbs
# vi /etc/oratab
#prod:/opt/oracle/product/9.2.0:N
prod:/opt/oracle/product/10.2.0:N
$ lsnrctl stop <listener_name>
$ cd /opt/oracle/product/10.2.0/rdbms/admin/
$. oraenv
ORACLE_SID:prod
$ echo $ORACLE_HOME
/opt/oracle/product/10.2.0
$ sqlplus /nolog
SQL > conn sys/sys as sysdba
SQL > startup upgrade
SQL > spool upgrade.log
SQL > @?/rdbms/admin/catupgrd.sql
SQL > SPOOL OFF
SQL > shutdown immediate;
SQL > startup
SQL >@utlrp.sql
SQL > @utlu102s.sql TEXT
SQL > select comp_name, status, version from dba_registry;
BACKOUT FROM 10.2.0.1 to 9.2.0.7
$. oraenv
ORACLE_SID:prod
JENiSOFT SOLUTIONS Oracle 10g PT37
$ sqlplus “/ as sysdba”
SQL > STARTUP DOWNGRADE
SQL > SPOOL downgrade. log
SQL > @/opt/oracle/product/10.2.0/rdbms/admin/catdwgrd.sql
SQL > SPOOL OFF
SQL > SHUTDOWN IMMEDIATE
# vi /etc/oratab
prod:/opt/oracle/product/9.2.0:N
# prod:/opt/oracle/product/10.2.0:N
$. oraenv
ORACLE_SID:prod
$ echo $ORACLE_HOME
/opt/oracle/product/9.2.0
$ sqlplus /nolog
SQL > CONNECT SYS/SYS_password AS SYSDBA
SQL > STARTUP MIGRATE
SQL > SPOOL reload.log
SQL > @/opt/oracle/product/10.2.0/rdbms/admin/catrelod.sql
SQL > SPOOL OFF
SQL > SHUTDOWN IMMEDIATE
SQL > STARTUP
SQL > @/opt/oracle/product/9.2.0/rdbms/admin/UTLRP.SQL
SQL > select comp_name, status, version from dba_registry;
JENiSOFT SOLUTIONS Oracle 10g PT38
Apply CPU /PSU patches:
$. oraenv
ORACLE_SID : prod
SQL > sqlplus “/ as sysdba”
SQL > shutdown immediate
$ lsnrctl stop <Listener_name>
$ unzip p919293_1024_linux86.zip
$ cd p919293
$ opatch apply
$ opatch lsinventory
$ . oraenv
ORACLE_SID : prod
$ cd $ORACLE_HOME/rdbms/admin
$ sqlplus /nolog
SQL > CONNECT / AS SYSDBA
SQL > STARTUP
SQL > @?/rdbms/admin/catbundle.sql psu apply
SQL > @?/cpu/view_recompile/recompile_precheck_jan2008cpu.sql
SQL > shutdown immediate
SQL > CONNECT / AS SYSDBA
SQL > STARTUP UPGRADE
SQL > @?/cpu/view_recompile/view_recompile_jan2008cpu.sql
SQL > SHUTDOWN;
SQL > STARTUP;
JENiSOFT SOLUTIONS Oracle 10g PT39
SQL > @?/rdbms/admin/utlrp.sql
SQL > alter package schemaname.packagename compile;
SQL > select * from dba_registry_history;
Putty.exe Tool:
JENiSOFT SOLUTIONS Oracle 10g PT40
Xmanager Tool:
JENiSOFT SOLUTIONS Oracle 10g PT41
JENiSOFT SOLUTIONS Oracle 10g PT42