This discussion is archived
10 Replies Latest reply: Nov 29, 2012 4:03 PM by 977120 RSS

Difference between Service and Instance in Oracle Net Services

584429 Newbie
Currently Being Moderated
Hi,

I was reading the Oracle Net Services Documentation and found this:

" An Oracle database is represented to clients as a service; that is, the database
performs work on behalf of clients. A database can have one or more services
associated with it. ........................

A database has at least one instance. Like services, instances are identified by an instance name. The instance name defaults to the Oracle System Identifier (SID) of the instance. .........................

To connect to a database service, clients use a connect descriptor that provides the
location of the database and the name of the database service. The listener knows which services for which it can handle connection requests, because an Oracle database dynamically registers this information with the listener."

From this I couldn't understand the difference between a Service and an Instance. Also, what is the difference between the SID and DATABASE NAME.

Any clarification will be highly appreciated.
dula
  • 1. Re: Difference between Service and Instance in Oracle Net Services
    Madrid Oracle ACE
    Currently Being Moderated
    Database Name. It is the name of the physical database structure. It is stored at the controlfile and datafile header. It is used to identify all physical structures that belong to the same database. It can be defined at install time. It is originally defined by the static instance parameter database_name, and it cannot be changed, and the only way to change it is by means of rebuilding the controlfile and resetting the log sequence.

    Instance Name. It is the name of the memory structures + Background process (MEM + BGP) use to mount/open a database. In a RAC environment there are more than one instance opening the same database, and each instance has a different name. On a single instance (non rac) environments, the instance name and the database name are named (generallly) the same. There is no reason to name the instance and the database differently.
    Instance name is defined by the ORACLE_SID environment variable (unix) and by the windows service name (windows).
    In a connect string this can be used to establish connection to a database, however this is valid for pre-8i versions (8.0 compatible) and even though it can work with 10g databases, it is not a good practice as it reduces the functionality provided since 8i.

    Service Name. This is a way to identify a target instance to get connected to. It is defined by the dynamic instance parameter service_names, note the names word, it is plural, that is because an oracle instance can have several service names. The concept service is more frequently used in a single instance to refer to an instance with several alias. In a RAC environment it is used to balance power, create failed over / stand by instances and it is used in combination with resource manager.

    It is common to name all three the same, and there is no use in changing them (single instance), except for the service name, just in case there it can be created more than one alias to refer to the same instance.



    ~ Madrid
  • 2. Re: Difference between Service and Instance in Oracle Net Services
    584429 Newbie
    Currently Being Moderated
    Many thanks Madrid, the answer is short, precise and clear.

    dula
  • 3. Re: Difference between Service and Instance in Oracle Net Services
    Madrid Oracle ACE
    Currently Being Moderated
    Your welcome. I hope this has helped you.


    Best Regards.
  • 4. Re: Difference between Service and Instance in Oracle Net Services
    Hans Forbrich Oracle ACE Director
    Currently Being Moderated
    TO add to Madrid's excellent answer:

    The concept of Service is getting increasing importance. It is possible to have several services defined within one instances. In fact, there are a few basic services created, and ONE per AQ's Queue, up to a maximum of 64 sewrvices in 10g.

    WItrh 10g's Resource Manager, it becomes interesting (important?) to associate a program, user, session or application with a service. It is then possible to manage the resource utilitization on a per-service basis, up to and including quiescing an entire service with a single command.

    As a result, the Service concept is pointing us towards the Instance Consolidation utopia, although I admit there is still much to be done.
  • 5. Re: Difference between Service and Instance in Oracle Net Services
    576856 Journeyer
    Currently Being Moderated
    thank you madrid..nice explanation
  • 6. Re: Difference between Service and Instance in Oracle Net Services
    51034 Newbie
    Currently Being Moderated
    This old thread was linked to by a much newer one. Had I noticed this at the time, I would have written before now.

    The problem is your definition of Service Name: it misses the point by a mile.

    It most definitely is NOT a way "to identify a target instance to get connected to". That's it's whole point! If you want to identify an INSTANCE to connect to, you can simply specify SID=SOMETHING in your tnsnames.ora... and the fact that doing so has been deprecated since 8i tells you that identifying an instance to connect to is not such a good idea.

    A service is a[b] logical representation of one or more instances. When you specify SERVICE_NAME=SOMETHING in your tnsnames.ora, you are NOT asking to be connected to an instance at all. In fact, you're saying, "I don't care what instance I end up being connected to, so long as whatever one it happens to be is able to provide the SOMETHING service.

    In a single instance environment, service and instance are effectively synonymous: the collection of memory structures and processes we call an instance provides a service, so the service and instance can be viewed as the same thing. It would be unusual to allocate multiple service names to a single instance in a single instance environment, but it's certainly do-able: it's just rather pointless, since the only game in town is likely to be the only provider of any service you can think of! I have never seen people needing (or wanting) to alias their single instances, though, so I find your emphasis of that possibility rather peculiar. Besides which, aliasing things in a single instance environment is rather more simply achieved by having multiple tnsnames aliases in the one tnsnames.ora pointing to the same instance or service.

    The concept of a service makes a lot more sense in a multi-instance environment (RAC). There, a number of instances could offer one service, whilst a couple of spare instances could be offering another. A service therefore can be seen as a way of logically "partitioning" your RAC into separate functional areas, even though all instances have equal access to the same database. As such, the service is a good way of dividing and prioritising resources (not necessarily with resource manager, by the way) within the RAC.

    The service is key to failover precisely because it does NOT mean "connect me to an instance". If you said connect me to SID=INST1, then you have demanded a connection to a named instance and if that instance fails, tough luck: that's what you wanted, that's what you got. I won't be failing you over to surviving instance INST2. But if you had connected to SERVICE=SALES, which happens to be provided by INST1 and INST2, then whilst you may have -almost incidentally!- ended up connected to INST1, if that instance were to fail it would be permissable and legitimate and possible to fail you over to INST2, because that provides the same service you actually wanted to connect to.

    It is precisely because of this multi-instance subtlety that it is NOT common to name all three the same. It's impossible to do so, in fact, because my database sales cannot be opened by two instances both called SALES. One will have to be called SALES1 (or something similar) and the other SALES2... and immediately, your database name does not equal your instance names. Similarly, it would rather unusual to have instances SALES1 and SALES2 and yet have services SALES1 and SALES2. That would be to see service as the same thing as instance (the trap I think your description has fallen into, actually) and would negate the whole point of the service in the first place. More likely, you will have a service called SALES, comprised of instances SALES1 and SALES2 which both open a database called SALESDB... and at that point, not one of the three elements you discussed has the same name!

    RAC is not perhaps the most common environment to work in, so this multi-instance reality might not be something you'd call "common" -and certainly, in a single instance environment, there would be no great harm in calling all three the same thing. But RAC isn't exactly rare, either: so your statement "it's common to name all three the same" is deficient in specificity and accuracy.

    It would not be wise, I think, to start off learning that "service is a way of defining an instance to connect to" when it was invented precisely not to mean that and where such a definition will seriously lead you astray once you move to a RAC or Data Guard environment where understanding the profound but subtle difference between the two things becomes absolutely critical.
  • 7. Re: Difference between Service and Instance in Oracle Net Services
    718862 Newbie
    Currently Being Moderated
    howardjr !!!, your explanation REALLY links the two instance and service concepts.... there are many documents providing information combined on instance and service, like http://www.stanford.edu/dept/itss/docs/oracle/10g/network.101/b10775/concepts.htm,

    but they actually DONT link the two things....

    nice post.. thanks


    GUYS!
    i have a silly question... very basic. how do we specify that this instance will serve this particular service, which file? sample?

    thanks in advance.
  • 8. Re: Difference between Service and Instance in Oracle Net Services
    Hans Forbrich Oracle ACE Director
    Currently Being Moderated
    user11156470 wrote:
    i have a silly question... very basic. how do we specify that this instance will serve this particular service, which file? sample?
    Database's SERVICES initialization parameter. (See reference manual)
  • 9. Re: Difference between Service and Instance in Oracle Net Services
    718862 Newbie
    Currently Being Moderated
    Hi Hans Forbrich

    I hope you are reffering to "service_names" parameter. Right?
  • 10. Re: Difference between Service and Instance in Oracle Net Services
    977120 Newbie
    Currently Being Moderated
    howardjr wrote:
    It is precisely because of this multi-instance subtlety that it is NOT common to name all three the same. It's impossible to do so, in fact, because my database sales cannot be opened by two instances both called SALES. One will have to be called SALES1 (or something similar) and the other SALES2... and immediately, your database name does not equal your instance names. Similarly, it would rather unusual to have instances SALES1 and SALES2 and yet have services SALES1 and SALES2. That would be to see service as the same thing as instance (the trap I think your description has fallen into, actually) and would negate the whole point of the service in the first place. More likely, you will have a service called SALES, comprised of instances SALES1 and SALES2 which both open a database called SALESDB... and at that point, not one of the three elements you discussed has the same name!
    Eventhough I agree that it's a good custom to think and name like this I disagree about something in his naming.

    In my database structures there would be an abbreviation (of 3 or 4 characters) for the name of the organisation for whom a database is running. For instance a company named "Four Letter Company London" would have a database FLCL_DB. In this case I would name my instances flcl_1, flcl_2, flcl_3, etc. If two of these instances would offer the same service for the department sales, then I would reflect this in the database parameter service_names of two of these instances. Here the word SALES would pop up for the first time, not in the names of the instances. This would be because they are instances of a database that could offer services for several departments.

    If one would want to keep service names short, then the word service would be a bit long to have in the name of the service. It would have to become something like FLCL_SRVC_SALES. This would differentiate the name of the service from a name for a role or a user FLCL_SALES in the database. Now through this service name a connection to one of the instances could be established.

    Edited by: Ed R., A'dam on 29-nov-2012 16:01