Performacne Tuning Vol2-2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Resource Allocation Methods 15-14

The Original Plan: SYSTEM_PLAN 15-16


Using Subplans 15-17
Administering the Database Resource Manager 15-18
Assigning the Resource Manager Privilege 15-20
Creating Database Resource Manager Objects 15-21
Assigning Users to Consumer Groups 15-25
Setting the Resource Plan for an Instance 15-26
Changing a Consumer Group Within a Session 15-27
Changing Consumer Groups for Sessions 15-28
Database Resource Manager Information 15-29
Current Database Resource Manager Settings 15-32
Guidelines 15-33
Summary 15-34

16 Workshop Overview
Objectives 16-2
Approach to Workshop 16-3
Company Information 16-4
Workshop Database Configuration 16-6
Workshop Procedure 16-7
Choosing a Scenario 16-8
Workshop Scenarios 16-9
Collecting Information 16-10
Generating a Workshop Load 16-11
Results 16-12
Summary 16-13

A Practices Solutions

B Tuning Workshop

C Example of STATSPACK Repot

D Redundant Arrays of Inexpensive Disks Technology (RAID)

xi
xii
A
Practice Solutions

Copyright © Oracle Corporation, 2001. All rights reserved.


Practice 2
The goal of this practice is to familiarize yourself with the different methods of collecting
statistical information.
1. Log on as directed by the instructor. If the database is not already started, connect to
sqlplus using “system/manager as sysdba” then start it using the STARTUP command.
Check that TIMED_STATISTICS has been set to true, if it has not then set it using the
init.ora file (located at $HOME/ADMIN/PFILE), or the alter system statement.
– SQL> show parameter timed_statistics
– If a value of true is return, continue to question 2. If a value of false is returned,
then either edit the init.ora and add the parameter TIMED_STATISTICS =
TRUE
– Or, set the parameter dynamically using
– SQL> alter system set timed_statistics = true;
2. Connect to SQLPLUS as user SYSTEM, and issue a command that will create a trace
file for this session. Run a query to count the number of rows in the dictionary view
DBA_TABLES. In order to locate your new trace file easier, if possible, delete all the
trace files in the USER_DUMP_DEST before running the trace. Disable the trace
command after running the query. Do not try to interpret the content of the trace file as
this is the topic of a later lesson.
– SQL> ALTER SESSION SET SQL_TRACE = TRUE;
– SQL> SELECT COUNT(*) FROM DBA_TABLES;
– SQL> ALTER SESSION SET SQL_TRACE = FALSE;
3. At the operating system level view the resulting trace file located in the directory set by
USER_DUMP_DEST
– $cd $HOME/ADMIN/UDUMP
– $ls –l
– -rw-r----- 1 user487 dba 4444 Apr 24 22:28 U487_ora_3270.trc
4. Open two sessions, the first as user HR/HR, and the second as user “sys/oracle as
sysdba”. From the second session generate a user trace file for the first session using
DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION procedure.
– From Session 1
– $ sqlplus hr/hr
– Change to Session 2
– $ sqlplus sys/oracle as sysdba
– SQL> select username, sid, serial# from v$session where username = ‘HR’;
– SQL> begin
– 2> dbms_system.set_sql_trace_in_session
– 3> (&SID,&SERIALNUM,TRUE);
– 4> end;
– 5> /
Oracle9i Performance Tuning A-2
Practice 2 (continued)
5. Change to Session 1
SQL> select * from employees;
6. Change to Session 2
SQL> begin
2> dbms_system.set_sql_trace_in_session
3> (&SID,&SERIALNUM,FALSE);
4> end;
5> /
7. Confirm that the trace file has been created in the directory set by
USER_DUMP_DEST
$cd $HOME/ADMIN/UDUMP
$ls –l
-rw-r----- 1 dba01 dba 4444 Apr 24 22:28 dba01_ora_3270.trc
-rw-r----- 1 dba01 dba 15443 Apr 24 22:42 dba01_ora_3281.trc
8. Connect to SQLPLUS using “sys/oracle as sysdba”, and create a new tablespace
(TOOLS) to hold the tables and other segments required by STATSPACK. This
tablespace needs to be 100M, and be dictionary managed (this will be used later in the
course). Name the datafile tools01.dbf and place in the $HOME/ORADATA/u05
directory.
Note: Dictionary managed is not the default.
SQL> connect sys/oracle as sysdba
SQL> create tablespace TOOLS
2> datafile ‘$HOME/ORADATA/u05/tools01.dbf’ size 100m
3> extent management dictionary;
9. Confirm, and record, the amount of free space available within the TOOLS tablespace
by querying the DBA_FREE_SPACE view.
SQL> select tablespace_name, sum (bytes)
2> from dba_free_space
3> where tablespace_name = 'TOOLS‘
4> group by tablespace_name;
10.Connect using “sys/oracle as sysdba”, then install STATSPACK using the spcreate.sql
script located in your $HOME/STUDENT/LABS directory. Use the following settings
when asked by the installation program:
User’s Default Tablespace = TOOLS
User’s Temporary Tablespace = TEMP
SQL > @$HOME/STUDENT/LABS/spcreate.sql

Oracle9i Performance Tuning A-3


Practice 2 (continued)
11.Query DBA_FREE_SPACE to determine the amount of free space space left in the
TOOLS tablespace. The difference between this value and the one records in question
(7) will be the spac e required for the initial installation of STATSPACK. Note that this
amount will increase in proportion to the amount of information stored within the
STATSPACK tables, i.e., the number of snapshots.
Subtract the value received now, from the value received in Step 7 to get the amount of
space required in order to install STATSPACK
12.Manually collect current statistics using STATSPACK by running the snap.sql script
located in $HOME/STUDENT/LABS. This will return the snap_id for the snapshot just
taken, which should be recorded.
SQL > @$HOME/STUDENT/LABS/snap.sql
13.In order to have STATSPACK automatically collect statistics every 3 minutes execute
the spauto.sql script located it your $HOME/STUDENT/LABS directory. Query the
database to confirm that the job has been registered using the user_jobs view..
SQL > @$HOME/STUDENT/LABS/spauto.sql
SQL > select job, next_date, next_sec, last_sec
2 > from user_jobs;
14.After waiting for a period in excess of 3 minutes query the stats$snapshot view in order
to list what snapshots have been collected. There must be at least two snapshots before
moving to the next step.
SQL> select snap_id, to_char(startup_time,’ dd Mon "at" HH24:mi:ss’) instart_fm,
2> to_char(snap_time,’dd Mon YYYY HH24:mi’) snapdat, snap_level "level"
3> from stats$snapshot
4> order by snap_id;
15.Once there are at least two snapshots, start to generate a report. This is performed using
the spreport.sql script found in the $HOME/STUDENT/LABS directory. The script list
the snapshot options available, and then requests the beginning snap id and the end snap
id. The user is then requested to give a filename for the report. It is often best left to the
default.
SQL> @$HOME/STUDENT/LABS/spreport.sql
16.Locate the report file in the users current directory, then using any text editor, open and
examine the report. The first page shows a collection of the most queried statistics.
$ vi sp_X_Y.lst
where X is the starting snapshot, and Y is the ending snapshot (this is true if the
default report filename was used).

Oracle9i Performance Tuning A-4


Practice 2 (continued)
Dynamic Performance Views
17.Connect to the database as a system administrator “sys/oracle as sysdba”.
SQL> Connect sys/oracle as sysdba
18.Query the database in order to determine what system wait events have been registered
since startup using v$system_event.
SQL> select event, total_waits, time_waited
2> from v$system_event;
19.Determine if there are any sessions actually waiting for resources, using
v$session_wait.
SQL> select sid, event, p1text, wait_time, state
2 > from v$session_wait;
20.Stop the automatic collection of statistics by removing the job. This is performed by
connecting as user perfstat/perfstat and querying the view user_jobs to get the job
number. Then execute DBMS_JOB.REMOVE (<job number>);
SQL> connect perfstat/perfstat
SQL> select job, log_user
2> from user_jobs;
SQL> execute dbms_job.remove ($job);

Oracle9i Performance Tuning A-5


Practice 3
The objective of this practice is to use diagnostic tools to monitor and tune the shared pool.
1. Connect using ‘sys/oracle as sysdba” and check the size of the shared pool.
SQL> show parameter shared_pool
NAME TYPE VALUE
---------------------------- ----------- ---------------
shared_pool_reserved_size big integer 2516582
shared_pool_size big integer 50331648
2. Connect as perfstat/perfstat user, execute the $HOME/STUDENT/LABS/snap.sql script
to collect initial snapshot of statistics, and note the snapshot number by
SQL> connect perfstat/perfstat
SQL> @$HOME/STUDENT/LABS/snap.sql
3. To simulate user activity against the database open two operating system sessions. In
session 1 connect as hr/hr and run the $HOME/STUDENT/LABS/lab03_03_1.sql
script. In the second session connect as hr/hr and run the script
$HOME/STUDENT/LABS/lab03_03_2.sql.
In session 1
SQL> connect hr/hr
SQL> @$HOME/STUDENT/LABS/lab03_03_1.sql
In session 2
SQL> connect hr/hr
SQL> @$HOME/STUDENT/LABS/lab03_03_2.sql
4. Connect as “system/manager” and measure the pin-to-reload ratio for the library cache
by querying v$librarycache. Determine if it is a good ratio or not.
Using the dynamic view:
SQL> connect system/manager
SQL> select sum(pins), sum(reloads),
2> sum(pins) * 100 / sum(pins+reloads) “Pin Hit%”
3> from v$librarycache;

Oracle9i Performance Tuning A-6


Practice 3 (continued)
5. Connect as “system/manager” and measure the get-hit ratio for the data dictionary
cache by querying v$rowcache. Determine if it is a good ratio or not using the dynamic
view.
SQL> connect system/manager
SQL> SELECT SUM(getmisses), SUM(gets),
2 SUM(getmisses )*100/SUM(gets)“MISS %”
3 FROM v$rowcache;
If GETMISSES are lower than 15% of the GETS, it is a good ratio.
6. Connect as perfstat/perfstat and run the script $HOME/STUDENT/LABS/snap.sql to
collect a statistic snap shot and obtain the snapshot number. Record this number.
SQL> connect perfstat/perfstat
SQL> @$HOME/STUDENT/LABS/snap.sql
7. As user perfstat/perfstat obtain the statistics report between the two recorded
snapshot_ids (from questions 2 and 6) by running the script
$HOME/STUDENT/LABS/spreport.sql.
SQL> connect perfstat/perfstat
SQL> @$HOME/STUDENT/LABS/spreport.sql

The following is an example of using a beginning


snapshot_id of 3, and an ending snapshot_id of 5.
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 3

Enter value for end_snap: 5


End Snapshot Id specified: 5

Specify the Report Name


~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is sp_3_5. To use this
name,press <return> to continue, otherwise enter an
alternative.
Enter value for report_name:

Oracle9i Performance Tuning A-7


Practice 3 (continued)
8. Analyze the generated report in the current directory (named sp_3_5.lst in the previous
example). What would you consider to address if the library hit ratio (found under the
heading “Instance Efficiency Percentages) is less than 98%?
Increase the SHARED_POOL_SIZE parameter.
9. Determine which packages, procedures, and triggers are pinned in the shared pool by
querying v$db_object_cache.
SQL> select name,type,kept
2> from v$db_object_cache
3> where type IN
4> ('PACKAGE‘, 'PROCEDURE‘, 'TRIGGER‘, 'PACKAGE
BODY‘);
10.Connect using “sys/oracle as sysdba” and pin one of the Oracle supplied packages that
needs to be kept in memory, such as SYS.STANDARD using the procedure
DBMS_SHARED_POOL.KEEP, that is created by running the script
$ORACLE_HOME/rdbms/admin/dbmspool.sql.
SQL> CONNECT sys/oracle AS SYSDBA
SQL> @?/rdbms/admin/dbmspool
SQL> execute DBMS_SHARED_POOL.KEEP(’SYS.STANDARD’);
SQL> select distinct owner, name
2> from v$db_object_cache
3> where kept=’YES’
4> and name like ‘%STAND%’;
11.Determine the amount of session memory used in the shared pool for your session by
querying the v$mystat view. Limit the output by including the clause where name =
‘session uga memory’
SQL> select a.name, b.value
2> from v$statname a, v$mystat b
3> where a.statistic# = b.statistic#
4> and name = ’session uga memory’;
12.Determine the amount of session memory used in the shared pool for all sessions, using
V$SESSTAT and V$STATNAME views:
SQL> select SUM(value)||' bytes' "Total session memory“
2 from v$sesstat, v$statname
3 where name = 'session uga memory‘
4 and v$sesstat.statistic# = v$statname.statistic#;

Oracle9i Performance Tuning A-8

You might also like