Why you should use Application Services with your Oracle Database

On a Single-Instance Oracle Database, Application Services offer benefits for Performance Monitoring & Tracing. That’s the focus of this posting. If you are on RAC respectively Data Guard already, you will use Services at least to provide Connect-Time Failover. You may find some additional useful things to do with them here. The playing field:

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE    11.2.0.3.0    Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production

My demo DB has no Application Services yet. In the most simple case, there is one Application running and we take backups, so that gives us two services to introduce:

SQL> exec dbms_service.create_service('app1','app1')

PL/SQL procedure successfully completed.

SQL> exec dbms_service.create_service('bk','bk')

PL/SQL procedure successfully completed.

With Grid Infrastructure installed, we would use srvctl add service instead. The services are not yet started. Subsequently, an after startup on database trigger should do that.

SQL> exec dbms_service.start_service('app1')

PL/SQL procedure successfully completed.

SQL> exec dbms_service.start_service('bk')

PL/SQL procedure successfully completed.

SQL> grant dba to adam identified by adam;

Grant succeeded.

SQL> exec dbms_workload_repository.create_snapshot

PL/SQL procedure successfully completed.

SQL> select snap_id,to_char(begin_interval_time,'yyyy-mm-dd:hh24:mi:ss') 
from dba_hist_snapshot order by 1;  

   SNAP_ID TO_CHAR(BEGIN_INTER
---------- -------------------
     2 2012-01-18:15:09:15
     3 2012-01-18:15:20:30
     4 2012-01-19:12:51:40
     5 2012-03-19:12:03:03
     6 2012-10-31:14:59:25

The following uses Easy Connect (my host is named uhesse1; my Listener Port is 1521) to attach to the services:

SQL> connect adam/adam@uhesse1/app1
Connected.
SQL> alter session set workarea_size_policy=manual;

Session altered.

SQL> alter session set sort_area_size=100000000;

Session altered.

SQL> create table sales as select 
rownum as id,
mod(rownum,5) as channel_id,
mod(rownum,1000) as cust_id,
5000 as amount_sold,
sysdate as time_id
from dual connect by level<=1e6;    

Table created.

SQL> update sales set amount_sold=amount_sold*1;

1000000 rows updated.

SQL> commit;

Commit complete.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
[oracle@uhesse1 ~]$ rman target sys/oracle@uhesse1/bk

Recovery Manager: Release 11.2.0.3.0 - Production on Wed Oct 31 15:13:04 2012

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: PRIMA (DBID=2003897072)

RMAN> backup database;

Starting backup at 31-OCT-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=50 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/home/oracle/prima/system01.dbf
input datafile file number=00002 name=/home/oracle/prima/sysaux01.dbf
input datafile file number=00003 name=/home/oracle/prima/undotbs01.dbf
input datafile file number=00004 name=/home/oracle/prima/users01.dbf
channel ORA_DISK_1: starting piece 1 at 31-OCT-12
channel ORA_DISK_1: finished piece 1 at 31-OCT-12
piece handle=/home/oracle/flashback/PRIMA/backupset/2012_10_31/o1_mf_nnndf_TAG20121031T151314_892dhwso_.bkp tag=TAG20121031T151314 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 31-OCT-12
channel ORA_DISK_1: finished piece 1 at 31-OCT-12
piece handle=/home/oracle/flashback/PRIMA/backupset/2012_10_31/o1_mf_ncsnf_TAG20121031T151314_892djcbb_.bkp tag=TAG20121031T151314 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 31-OCT-12

RMAN> exit

Recovery Manager complete.
[oracle@uhesse1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Wed Oct 31 15:13:41 2012

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

SQL> exec dbms_workload_repository.create_snapshot

PL/SQL procedure successfully completed.

SQL> select snap_id,to_char(begin_interval_time,'yyyy-mm-dd:hh24:mi:ss') 
from dba_hist_snapshot order by 1;   

   SNAP_ID TO_CHAR(BEGIN_INTER
---------- -------------------
     2 2012-01-18:15:09:15
     3 2012-01-18:15:20:30
     4 2012-01-19:12:51:40
     5 2012-03-19:12:03:03
     6 2012-10-31:14:59:25
     7 2012-10-31:15:06:13

6 rows selected.

Some „Application“ load was followed by an RMAN backup. We can now differentiate those loads. The AWR report for the last two snapshots show this section:

We can tell from the low values of DB Time for the bk service in relation to the app1 service that the (Online-)Backup has had almost no impact on performance for end users here. Also, we have v$-views for services:

SQL> set lines 200
set pages 300
col service_name for a10
select service_name,event,time_waited 
from v$service_event natural join v$event_name 
where service_name in ('app1','bk') 
and wait_class<>'Idle' 
order by 1,3; 

SERVICE_NA EVENT                                                            TIME_WAITED
---------- ---------------------------------------------------------------- -----------
app1       control file sequential read                                               0
app1       SQL*Net message to client                                                  0
app1       db file single write                                                       1
app1       db file scattered read                                                     1
app1       log file sync                                                              1
app1       control file parallel write                                                1
app1       direct path write                                                          2
app1       direct path sync                                                           3
app1       Data file init write                                                       3
app1       Disk file operations I/O                                                   4
app1       buffer busy waits                                                          5
app1       free buffer waits                                                         13
app1       log file switch (private strand flush incomplete)                         14
app1       db file sequential read                                                   26
app1       log file switch completion                                                28
app1       log buffer space                                                        1635
bk       Parameter File I/O                                                           0
bk       db file scattered read                                                       0
bk       SQL*Net message to client                                                    0
bk       SQL*Net break/reset to client                                                0
bk       db file single write                                                         0
bk       db file sequential read                                                      2
bk       control file parallel write                                                  7
bk       control file single write                                                    8
bk       Disk file operations I/O                                                    12
bk       control file sequential read                                                18
bk       events in waitclass Other                                                  217
bk       RMAN backup & recovery I/O                                                 757

28 rows selected.

SQL> select service_name,value 
from v$service_stats 
where service_name in ('app1','bk') 
and stat_name='physical reads';    

SERVICE_NA    VALUE
---------- ----------
app1            13422
bk                351

There are completely different Top Wait-Events for the two services. ‚physical reads‘ was just one example from the hundreds of available stats. In the very same manner, multiple applications running on the same DB could be differentiated. Furthermore, we can switch on tracing now for only certain services resp. applications:

SQL> exec dbms_monitor.serv_mod_act_trace_enable('app1')

PL/SQL procedure successfully completed.

SQL> connect adam/adam@uhesse1/app1
Connected.
SQL> select count(*) from sales;

  COUNT(*)
----------
   1000000

SQL> select distinct channel_id from sales;

CHANNEL_ID
----------
     1
     2
     4
     3
     0

SQL> connect / as sysdba
Connected.
SQL> exec dbms_monitor.serv_mod_act_trace_disable('app1')

PL/SQL procedure successfully completed.

This kind of service tracing produces potentially many trace files that we can consolidate (and identify) with trcsess like this:

[oracle@uhesse1 trace]$ trcsess output=app1.trc service=app1 *.trc

Afterwards, we can get a better readable output of the trace file with tkprof as usual, showing all the statements of the applications together with their execution plans.

Conclusion: You will always implement Application Services with RAC respectively Data Guard. For Single-Instance, you should use them also because

1) You may use RAC resp. Data Guard in the future and then you have everything in place already

2) You can do Performance Monitoring with a finer granule (on the Application layer) with them

3) You can trace with a finer granule as well

, , , , ,

  1. #1 von Don Seiler am Oktober 31, 2012 - 17:31

    So this is completely unrelated to the service_names init parameter?

  2. #2 von Uwe Hesse am Oktober 31, 2012 - 18:04

    That’s a good point: SERVICE_NAMES is maintained automatically with DBMS_SERVICE.START_SERVICE resp. by the Grid Infrastructure. But not the other way round. In other words, you should not set SERVICE_NAMES, because this will not have the same effect.

  3. #3 von Don Seiler am Oktober 31, 2012 - 18:22

    So even on a single instance without GI, we should use the DBMS_SERVICE package and not explicitly set the init parameter. However the services are not automatically started in a single instance env unless we have something like an after startup db trigger?

  4. #4 von Uwe Hesse am Oktober 31, 2012 - 18:30

    Exactly. You need the trigger or Oracle Restart to start services on Single Instance

  5. #5 von Don Seiler am Oktober 31, 2012 - 18:31

    Would be nice if Oracle Restart was available without the entire GI install! Thanks again for the post.

  6. #6 von Uwe Hesse am November 1, 2012 - 10:27

    Don, I have just tested to only use SERVICE_NAMES (with alter system set service_names=’test‘) and it produces an entry in DBA_SERVICES as well as statistics in v$service* views.

    So maybe that is more a matter of taste. I just don’t like that way 🙂

    Furthermore, on Data Guard that method is not advisable – instead the trigger. With Grid Infrastructure you would avoid the alter system method also. So better not get used to it 😉

  7. #7 von Bjoern Rost (@brost) am November 3, 2012 - 01:08

    A fourth reason is that services make the use of resource manager so much easier because you can simply map services to consumer groups. In your example above you could guarantee that the app service receives more cpu shares than the backup service.

    And one more reason is that it makes it so much easier to move/migrate shemas between databases. we usually set things up like this: each schema gets its own service name and dns name. so later, when we need to move this schema to a different db we only need to update dns and start the service on the new db but never have to touch the clients.

  8. #8 von Uwe Hesse am November 3, 2012 - 08:48

    Bjoern, thanks for adding these good reasons why to use Application Services!

    The Resource Manager ability to map services to Consumer Groups is especially also important on Exadata, where we can do I/O Resource Management, by the way 🙂

  9. #9 von Andreas am Februar 3, 2013 - 10:03

    Just for your information: you don’t need a trigger to start services on a single instance. It’s enought to use the SERVICE_NAMES init.ora parameter. Just try it.

  10. #10 von Uwe Hesse am Februar 4, 2013 - 09:30

    Andreas, thank you for the comment! As you may have seen, I mentioned the same already, answering Don’s comment above.

    My recommendation not to use SERVICE_NAMES stands, though, as you will not want to have it in place subsequently with RAC, Oracle Restart (aka Grid Infrastructure for a Standalone Server) or Data Guard.

  11. #11 von Yousuf am Februar 19, 2013 - 18:26

    Excellent!!

    Thanks for sharing the details..

    Just one request.. Can you please shade some light on trace 10053 with deep dive session / artical including difinations of each and every bit of line of trace 10053.

    We wanted to hear from you this session /aritical on trace 10053.

    Really this will help to everybody …

    Thanks again

    Mohammed.
    Oracle SME.
    Oracle India.

  12. #12 von newbie01oracle am April 28, 2014 - 22:04

    Just a question if you don’t mind. This one has been confusing me all these times.

    If for example, in its simplest form, I have a 2-node Oracle RAC and one application service and it is always running on one-node only, does that mean, I don’t have load balancing in place? Does that mean to have load balancing in place, I need to have services running on all nodes?

    Thanks in advance.

  13. #13 von Uwe Hesse am April 29, 2014 - 11:12

    If you have just one Application Service running on one node then all end user sessions will be on that node – no need for load balancing. You use the second node as a spare node only and you probably configured that service as AVAILABLE on that node.

    This can be a perfectly valid setup, but yes, if you want a symmetric use and load balancing, you need to make the service PREFERRED on the second node also.

    Make sure to test how your application behaves if multiple nodes get sessions connected before you change that in production, I would recommend 🙂

  14. #14 von fidelinho am Oktober 6, 2014 - 20:25

    Reblogged this on Gruñidos sobre … and commented:
    Esto tengo que guardarlo.
    Sabía como hacerlo en RAC, pero me interesa bastante en sistemas con una instancia.

  15. #15 von Gerrit Haase am Februar 12, 2018 - 15:51

    Hello Uwe, it is not just a matter of taste, there is no way to have an autostarting service created with dbms_service package, without installation of Grid or Trigger, while a service listed in the parameter SERVICE_NAMES is started automatically.

    I think this is a great lack of the dbms_service implementation, that there is no option to create auto-starting services.
    I guess that the initial plan was to have this, since there is a column ‚ENABLED‘ in dba_servcies, however it is not used yet?

  1. Backup & Restore one Datafile in Parallel « The Oracle Instructor

Hinterlasse einen Kommentar

Diese Seite verwendet Akismet, um Spam zu reduzieren. Erfahre, wie deine Kommentardaten verarbeitet werden..