Practice 13 - Using Database Service Performance Statistics
Practice 13 - Using Database Service Performance Statistics
Practice 13
Practice Target
In this practice, you will perform the following:
• Obtain information about existing database services
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.
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
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.
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
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;
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.
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.
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.
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;
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.
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;
16. In the hosting PC, open the file normal_oltp.html and examine the 'Service Statistics' and '
Service Wait Class Stats' sections.
Summary
In this practice, you performed the following:
• Obtain information about existing database services (using DBA_SERVICES, V$SERVICES,
V$SESSION, and the listener)