Forum Stats

  • 3,752,912 Users
  • 2,250,585 Discussions
  • 7,868,049 Comments

Discussions

Difference between Service Name and SID.

Psystec
Psystec Member Posts: 5
edited Jun 2, 2017 1:37AM in General Database Discussions

Hello Fellow Earthlings

I'm a bit new when it comes to creating Oracle drivers and I was the lucky winner assigned to make an oracle driver.

My driver works but, the connection string that the driver creates bypasses TNSnames, meaning its a bit of a manual string creation.

Currently my driver only replaces the SID variable and does not cater for Service_Names.

I know that Service Names are used in Cluster's and SID is a unique DB name usually, but beyond this is know nothing more.

Questions:

What is the difference between a Service Name and SID in the TNSnames? (technical answer if possible)

Can I use both in the TNSnames?

Kind Regards and thanks in advance.

Tagged:
PsystecJuanMCharles M

Best Answer

  • ddf_dba
    ddf_dba Member Posts: 1,398 Bronze Trophy
    edited May 26, 2017 9:53AM Accepted Answer

    An SID is specific to a database, it is unique in an environment and 'points' to one, and only one, database in that environment. A service name can be associated with one or more SIDs; think about a RAC environment where each instance is uniquely named yet all can be accessed through the SERVICE_NAME:

    SID                  SERVICE_NAME

    bob1                 bob

    bob2                 bob

    bob3                 bob

    bob4                 bob

    Through the 'magic' of the tnsnames.ora file all four of those SIDs can be associated with the SERVICE_NAME bob, and if load balancing is configured, the listener will 'balance' the workload across all four SIDs.  This doesn't stop you from connecting to bob1 all of the time if you want to, you just need to NOT use the SERVICE_NAME and use the SID.

    Think of the SERVICE_NAME as a town and each SID as a house in that town;  you can choose to drive to town and see who's home (using the SERVICE_NAME) or you can make a direct trip to one of those houses (using the SID).  SERVICE_NAME is a much more flexible choice.  Dynamic registration uses the SERVICE_NAME and allows one or more SIDs to be serviced by that SERVICE_NAME (no pun intended).  If you run ''lsnrctl services' you'll see how the SERVICE_NAME and SID relate:

    Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

    Services Summary...

    Service "fnorg" has 1 instance(s).    <==== SERVICE_NAME

      Instance "fnorg", status READY, has 1 handler(s) for this service...   <==== SID

        Handler(s):

          "DEDICATED" established:0 refused:0 state:ready

             LOCAL SERVER

    In a 2-node RAC environment it could look like this:

    Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

    Services Summary...

    Service "fnorg" has 1 instance(s).

      Instance "fnorg1", status READY, has 1 handler(s) for this service...

        Handler(s):

          "DEDICATED" established:0 refused:0 state:ready

             LOCAL SERVER

      Instance "fnorg2", status READY, has 1 handler(s) for this service...

        Handler(s):

          "DEDICATED" established:0 refused:0 state:ready

             LOCAL SERVER

    Multiple SIDs can be associated with a single SERVICE_NAME which is why SERVICE_NAME is much more flexible.

    David Fitzjarrell

    PsystecPsystecCharles M
«13

Answers

  • Dude!
    Dude! Member Posts: 22,826 Blue Diamond
    edited May 26, 2017 5:17AM

    From what I understand, SID is the name of the Oracle Instance, meaning the server process in memory. The net Service Name in TNS is an alias to the instance for remote connections and using TCP/IP.

  • ddf_dba
    ddf_dba Member Posts: 1,398 Bronze Trophy
    edited May 26, 2017 9:53AM Accepted Answer

    An SID is specific to a database, it is unique in an environment and 'points' to one, and only one, database in that environment. A service name can be associated with one or more SIDs; think about a RAC environment where each instance is uniquely named yet all can be accessed through the SERVICE_NAME:

    SID                  SERVICE_NAME

    bob1                 bob

    bob2                 bob

    bob3                 bob

    bob4                 bob

    Through the 'magic' of the tnsnames.ora file all four of those SIDs can be associated with the SERVICE_NAME bob, and if load balancing is configured, the listener will 'balance' the workload across all four SIDs.  This doesn't stop you from connecting to bob1 all of the time if you want to, you just need to NOT use the SERVICE_NAME and use the SID.

    Think of the SERVICE_NAME as a town and each SID as a house in that town;  you can choose to drive to town and see who's home (using the SERVICE_NAME) or you can make a direct trip to one of those houses (using the SID).  SERVICE_NAME is a much more flexible choice.  Dynamic registration uses the SERVICE_NAME and allows one or more SIDs to be serviced by that SERVICE_NAME (no pun intended).  If you run ''lsnrctl services' you'll see how the SERVICE_NAME and SID relate:

    Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

    Services Summary...

    Service "fnorg" has 1 instance(s).    <==== SERVICE_NAME

      Instance "fnorg", status READY, has 1 handler(s) for this service...   <==== SID

        Handler(s):

          "DEDICATED" established:0 refused:0 state:ready

             LOCAL SERVER

    In a 2-node RAC environment it could look like this:

    Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

    Services Summary...

    Service "fnorg" has 1 instance(s).

      Instance "fnorg1", status READY, has 1 handler(s) for this service...

        Handler(s):

          "DEDICATED" established:0 refused:0 state:ready

             LOCAL SERVER

      Instance "fnorg2", status READY, has 1 handler(s) for this service...

        Handler(s):

          "DEDICATED" established:0 refused:0 state:ready

             LOCAL SERVER

    Multiple SIDs can be associated with a single SERVICE_NAME which is why SERVICE_NAME is much more flexible.

    David Fitzjarrell

    PsystecPsystecCharles M
  • User_WVSC7
    User_WVSC7 Member Posts: 258 Blue Ribbon
    edited May 26, 2017 10:13AM

    if you have the Oracle RAC always use the Service name to connect to the database  to have the load balancing across all nodes in the cluster,if not All you can use is the SID to connect to the Database.

    Hope this helps

    -Bhavani Dhulipalla

  • ddf_dba
    ddf_dba Member Posts: 1,398 Bronze Trophy
    edited May 26, 2017 10:30AM
  • Mark D Powell
    Mark D Powell Member Posts: 5,914 Blue Diamond
    edited May 26, 2017 11:16AM

    Dude, even though it is getting rare to see any other protocol besides TCP being specified I believe that other network protocols are still technically possible.  I expect that both SNA and Decnet are still supported on the appropriate platforms.

    - -

    To address the idea that you should always use the database service name with RAC I will disagree.  With some applications it is desirable to direct specific DML tasks to specific instances to reduce cross instance contention.  You can do this by referencing the SID in the connection or better yet creating a service in the database that connects to only specific instances.  In the tnsnames.ora file you can create an alias for a failover (as opposed to load balancing) connection so that the connections always go one instance if available and another instance if the first instance is not available.

    - -

    HTH -- Mark D Powell --

  • tarfu_dba
    tarfu_dba Member Posts: 134
    edited May 26, 2017 1:43PM

    Let me add to the confusion...from an 11.2 EE perspective if things have changed in 12c...

    Service names can be used with both single instance and clustered databases.  Yes, you can specify both in a single TNS entry, but it's more flexible to use only a service name, especially with a RAC database.  I didn't do any extensive testing, but it appears that the service_name takes precedence over the SID, and will work even if the SID is configured but doesn't actually exist; if the service_name is incorrect, the connection fails even if the SID is correct.

    SID identifies a database instance on a server, the SID name showing up on the instance process names (i.e. ora_smon_<SID>).  On a server, SIDs are unique, but, the same SID can be active on different servers.  It's the combination of hostname and SID that points to a single instance.  SID is more like a single mailbox number in a post office; many post offices can have that same mailbox number, but a mailbox number is unique in one post office.

    SERVICE_NAME is a logical name that an instance registers with the listener when it starts (the default being the database global name db_name dot db_domain).  The name is just a convenience: the Finance users can configure service name FINANCE.WORLD in their TNS entry, the HR users can configure HR.WORLD, etc., but both service names get them connected to database CORP whose instances are started with init.ora service_names='FINANCE.WORLD','HR.WORLD'.  To make things more flexible (and confusing) different instances for the same cluster database can register different service names; for example, instances 1 and 2 can register FINANCE.WORLD, instance 3 can register HR.WORLD, and instance 4 can be left unconfigured in which case it will default to CORP.WORLD (the database global name).  All instances will accept connections to CORP.WORLD regardless of what other specific service_names have been configured for them.

    When the listener gets a connection attempt with a SID, it looks to see if that SID has registered with it and passes off the connection to it.

    When the listener gets a connection attempt with a service name, it looks up what instances (SIDs) have registered with that service name and passes the connection off to one of those instances.  Many instances, even related to different databases, can register the same service name with a listener; which one a connection is established with will be determined by other factors such as how busy a particular instance is (more accurately how busy an instance tells its listener that it is) or simply round-robin.  Typically, you have a service name related to a single database if you want to be sure of what database you're getting into.

    PsystecPsystec
  • Dude!
    Dude! Member Posts: 22,826 Blue Diamond
    edited May 26, 2017 6:38PM

    Where is the documentation when you need it?

    https://docs.oracle.com/cd/E11882_01/server.112/e40540/startup.htm#CNCPT955

    The system identifier (SID) is a unique name for an Oracle database instance on a specific host. On UNIX and Linux, Oracle Database uses the SID and Oracle home values to create a key to shared memory.

    Application and Networking Architecture

    In the context of net services, a service is a set of one or more database instances. A service name is a logical representation of a service used for client connections.

    When a client connects to a listener, it requests a connection to a service. When a database instance starts, it registers itself with a listener as providing one or more services by name. Thus, the listener acts as a mediator between the client and instances and routes the connection request to the right place.

    I think that pretty much corroborates my 1st response.

    Perhaps interesting for the OP could also be EZCONNECT - Oracle FAQ

  • Dude!
    Dude! Member Posts: 22,826 Blue Diamond
    edited May 27, 2017 1:17AM

    I have an AS4100 at home, collecting only dust though.

  • Mark D Powell
    Mark D Powell Member Posts: 5,914 Blue Diamond
    edited May 29, 2017 8:02PM

    I had to hit the internet to check out exactly what that was and after ignoring the Australian Steel standards I found Dec Alpha 4100.  There is one for sale on Amazon.

    - -

    https://www.amazon.com/DEC-AS4100-Alphaserver-Flickr-Sharing/dp/B017O2A71S

    - -

    we ran RAC on DEC Alphas though I cannot remember the model.

    - -

    -- Mark D Powell --

  • Psystec
    Psystec Member Posts: 5
    edited May 31, 2017 9:31AM

    Thank you, you where also very helpful.

This discussion has been closed.