0% found this document useful (0 votes)
11 views7 pages

Practice 13 - Using Database Service Performance Statistics

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views7 pages

Practice 13 - Using Database Service Performance Statistics

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Practice 13 - Using Database Service Performance Statistics P a g e |1

Practice 13

Using Database Service Performance Statistics

Practice Target
In this practice, you will perform the following:
• Obtain information about existing database services

• Retrieve service-level performance statistics

• Retrieve service-level wait events

• Retrieve service-level metrics

• Examine service statistics in AWR reports

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 13 - Using Database Service Performance Statistics P a g e |2

Exploring Service-level Performance Statistics

In this section of the practice, you will query the views that provide performance statistics at the
service-level.

Note: Service-level statistics views are normally used when the database hosts more than one
application service.

Obtaining general information about existing database services

1. Make sure srv1 is started. If it is not, start it up.

2. In the hosting PC, open a command prompt window and start Swingbench. Open the oltp.xml
configuration file then click on Start Benchmark button.
D:
cd D:\swingbench\winbin
set PATH=D:\oracle\product\12.1.0\client_1\jdk\jre\bin;%PATH%
swingbench.bat

3. Wait for three minutes.

4. Open Putty, login to srv1 as oracle. Invoke SQL*Plus and login to ORADB as sysdba.

sqlplus / as sysdba

5. Run the following query to obtain the services registered in the database.
Each service has a hash value. This is the value that are used in the other performance views to
identify the services.
Note: you can also query the view V$SERVICES.

set linesize 180


col NAME format a20
SELECT SERVICE_ID, NAME, NAME_HASH FROM DBA_SERVICES;

6. Run the following command to list the services registered in the listener.
If the services are not registered in the listener, the clients will not be able to connect to it.
Note: If the Oracle Grid Infrastructure is being used, this command should be run as grid user.
host lsnrctl services

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 13 - Using Database Service Performance Statistics P a g e |3

7. Obtain the number of sessions that are currently connected from Swingbench and the service
name they used to connect to the database.
col SERVICE_NAME format a30
SELECT SERVICE_NAME, COUNT(SID) CNT
FROM V$SESSION
WHERE CLIENT_INFO LIKE 'Swingbench%'
GROUP BY SERVICE_NAME;

8. Obtain the Services that have been connected to by the users in the past hour and the total
number of connections for each service.
For any statistics that you need on the sessions in the past hour, use the V$ ASH view.
Question: Which view would you use, if you want to obtain the same statistics for the last week?
SELECT S.NAME, V.CNT
FROM V$SERVICES S,
(SELECT SERVICE_HASH , COUNT(DISTINCT SESSION_ID) CNT
FROM V$ACTIVE_SESSION_HISTORY
WHERE SAMPLE_TIME >= CURRENT_TIMESTAMP - INTERVAL '30' MINUTE
GROUP BY SERVICE_HASH) V
WHERE S.NAME_HASH=V.SERVICE_HASH;

Displaying Service-level Statistics

9. Obtain the performance statistics aggregated in the view V$SERVICE_STATS for the service
ORADB.
Service level aggregation is enabled automatically in the database. This view provides service-
level statistics since last instance startup. By its own, it is not helpful on figuring out any
performance statistics spike.
Note: Unfortunately, this view does not display the unit of each displayed statistics. ‘DB time’
and ‘CPU time’ are displayed in microseconds.

col STAT_NAME format a35


SELECT STAT_NAME, VALUE
FROM V$SERVICE_STATS
WHERE SERVICE_NAME_HASH = (SELECT NAME_HASH FROM DBA_SERVICES WHERE NAME
='ORADB.localdomain')
ORDER BY 1;

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 13 - Using Database Service Performance Statistics P a g e |4

10. Obtain the performance statistics aggregated for the service ORADB that were collected at the
same current time yesterday. This is an example of how to retrieve service-level performance
statistics in a past time.
The history of V$SERVICE_STATS is saved into the view DBA_HIST_SERVICE_STAT.

The view DBA_HIST_SERVICE_STAT does not have the snapshot time. That is why we need to link
it to DBA_HIST_SNAPSHOT.

SELECT S.SNAP_ID, V.NAME, S.STAT_NAME, S.VALUE


FROM DBA_HIST_SERVICE_STAT S, DBA_HIST_SNAPSHOT N, DBA_SERVICES V
WHERE S.SNAP_ID=N.SNAP_ID
AND S.SERVICE_NAME_HASH = V.NAME_HASH
AND V.NAME='ORADB.localdomain'
AND N.BEGIN_INTERVAL_TIME BETWEEN SYSDATE-1.03 AND SYSDATE-1.01
ORDER BY 1,2,3;

Displaying Service-level Waiting Events

11. Query the top 10 waiting events on the service ORADB.


Unfortunately, V$SERVICE_EVENT is not sampled into the AWR. In other words, there is no
corresponding DBA_HIST view for this view.
However, DBA_HIST_SERVICE_WAIT_CLASS tracks the history of wait classes for the services. We
will have a look at its contents in an AWR report.
col EVENT format a50
SELECT EVENT, TIME_WAITED, AVERAGE_WAIT, MAX_WAIT
FROM V$SERVICE_EVENT E, V$EVENT_NAME N
WHERE E.EVENT_ID = N.EVENT_ID AND N.WAIT_CLASS<>'Idle' AND TIME_WAITED<>0
AND SERVICE_NAME_HASH = (SELECT NAME_HASH FROM DBA_SERVICES WHERE NAME
='ORADB.localdomain')
ORDER BY TIME_WAITED DESC FETCH FIRST 10 ROWS ONLY;

12. Using the view V$SERVICE_EVENT, obtain the total waiting time since instance startup for the
service ORADB.
TIME_WAITED in V$*EVENT views are given in centi seconds.

SELECT ROUND(SUM(TIME_WAITED/100/60),3) "Total Service Wait Time in Minutes"


FROM V$SERVICE_EVENT E, V$EVENT_NAME N
WHERE E.EVENT_ID = N.EVENT_ID
AND N.WAIT_CLASS<>'Idle'
AND TIME_WAITED<>0
AND SERVICE_NAME_HASH = (SELECT NAME_HASH FROM DBA_SERVICES WHERE NAME
='ORADB.localdomain');

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 13 - Using Database Service Performance Statistics P a g e |5

13. Using the view V$SERVICE_STATS, calculate the total service wait time. Compare the result with
the result of the preceding step.
Total waiting time equals to DB Time minus the DB CPU time.
‘DB time’ and ‘DB CPU’ time in V$SERVICE_STATS are in microseconds.
Observe that the total wait time obtained from V$SERVICE_EVENT is a little bit higher than the
total wait time calculated from V$SERVICE_STATS view.

SELECT
( SELECT ROUND(VALUE/1000000/60,3)
FROM V$SERVICE_STATS
WHERE SERVICE_NAME_HASH = (SELECT NAME_HASH FROM DBA_SERVICES WHERE NAME
='ORADB.localdomain') AND STAT_NAME='DB time' )
-
( SELECT ROUND(VALUE/1000000/60,3)
FROM V$SERVICE_STATS
WHERE SERVICE_NAME_HASH = (SELECT NAME_HASH FROM DBA_SERVICES WHERE NAME
='ORADB.localdomain') AND STAT_NAME='DB CPU')
AS SERVICE_WAIT_TIME
FROM DUAL;

Displaying Service-level Metrics

14. Display the service metrics for the service ORADB of the last 5 seconds and the last minute.
V$SERVICEMETRIC displays the service metrics for only the last 5 seconds and the last minute.

ALTER SESSION SET NLS_DATE_FORMAT ='DD-MON-YY HH24:MI:SS';


SELECT BEGIN_TIME, END_TIME, ROUND(INTSIZE_CSEC/100) INTERVAL_S,
ROUND(DBTIMEPERSEC) DBTIMEPERSEC , ROUND(DBTIMEPERCALL) DBTIMEPERCALL,
ROUND(CALLSPERSEC) CALLSPERSEC, ROUND(ELAPSEDPERCALL) ELAPSEDPERCALL,
ROUND(CPUPERCALL) CPUPERCALL
FROM V$SERVICEMETRIC
WHERE SERVICE_NAME_HASH = (SELECT NAME_HASH FROM DBA_SERVICES WHERE NAME
='ORADB.localdomain')
ORDER BY BEGIN_TIME ASC;

15. Display the service metrics for the service ORADB of the last hour.
V$SERVICEMETRIC view shows the most recent samples for the services while the
V$SERVICEMETRIC_HISTORY view exhibits metrics for all samples during the last hour.
None of them are sampled to AWR but ASH views contain metric statistics.
SELECT BEGIN_TIME, END_TIME, ROUND(INTSIZE_CSEC/100) INTERVAL_S,
ROUND(DBTIMEPERSEC) DBTIMEPERSEC , ROUND(DBTIMEPERCALL) DBTIMEPERCALL,
ROUND(CALLSPERSEC) CALLSPERSEC, ROUND(ELAPSEDPERCALL) ELAPSEDPERCALL,
ROUND(CPUPERCALL) CPUPERCALL
FROM V$SERVICEMETRIC_HISTORY
WHERE SERVICE_NAME_HASH = (SELECT NAME_HASH FROM DBA_SERVICES WHERE NAME
='ORADB.localdomain')
ORDER BY BEGIN_TIME ASC;

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 13 - Using Database Service Performance Statistics P a g e |6

Displaying Service Statistics in AWR Reports

16. In the hosting PC, open the file normal_oltp.html and examine the 'Service Statistics' and '
Service Wait Class Stats' sections.

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 13 - Using Database Service Performance Statistics P a g e |7

Summary
In this practice, you performed the following:
• Obtain information about existing database services (using DBA_SERVICES, V$SERVICES,
V$SESSION, and the listener)

• Retrieve service-level performance statistics (from V$SERVICE_STATS and


DBA_HIST_SERVICE_STAT)

• Retrieve service-level wait events (from V$SERVICE_EVENT)

• Retrieve service-level metrics (from V$SERVICEMETRIC and V$SERVICEMETRIC_HISTORY)

• Examine service statistics and wait class statistics in AWR reports

Oracle Database Performance Tuning, a course by Ahmed Baraka

You might also like