Skip to Main Content
  • Questions
  • SID YES SERVICE_NAME NO in tnsnames.ora

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question.

Asked: February 17, 2009 - 9:27 am UTC

Last updated: August 15, 2018 - 11:58 pm UTC

Version: 9208

Viewed 50K+ times! This question is

You Asked

Hello Tom,

We use tnsnames.ora .

1) What is the difference between SID entry and SERVICE_NAME in the tnsnames.ora

2) When I put SID the connection is successful, when I put SERVICE_NAME it says tns could not resolve service name

So This works
MYDB.world =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = MYHOST.COM)(PORT = 1521))
)
(CONNECT_DATA =
(SID = MYDB)
(SERVER = DEDICATED)
)
)


But this doesnt

MYDB.world =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = MYHOST.COM)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = MYDB)
(SERVER = DEDICATED)
)
)

and Tom said...

A service name is more flexible than a SID would be.


A database can dynamically register with a listener using one or more service names. In fact, more than one database can register with a listener using the same service name (think about a clustered environment where you have multiple instances that all are the same database under the covers).

A database on the other hand has a single SID. And a single SID goes to a single database. It is a pure 1:1 relationship.

A service is a many to many relationship.


Service names are used with dynamic registration - the data registers with the listener after it starts up. Once it does that, you can connect.


With the SID - that is more like telling the listener "I want you to connect to this specific database, I know the 'address', here you go"

With the SERVICE - you are asking the listener to put you in touch with a database that can service your request, a database that registers using that service.



That you cannot connect using the service name MYDB means your database is not registering with that listener (see the Net Admin guide for dynamic registration) or if it is registered with that listener (lsnrctl services is a command you can use to see the registered services) then it is registering with a different name.

Rating

  (6 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Service_Name Parameter

JIm Cox, September 06, 2012 - 3:40 pm UTC

Hi Tom

plans here are to change the windows domain of my oracle server. The parameter service_name looks like it has the SID concatenated to the DB_DOMAIN parameter which is set in my PFile/SPFile. If i change the DB_DOMAIN value in the file will the service_name get updated to the sid and new domain or do i have to manually change the service_name parameter ?

Thanks
Jim

Service_Name Parameter - Thanks

Jim Cox, October 01, 2012 - 3:55 pm UTC

Thanks Tom

SID

William, August 14, 2014 - 7:58 pm UTC

as I understand, you can have multiple instance with same SID registered to one listener. So, one SID can be one to many databases/instances. Looks like, the issue is explained in CVE-2012-1675.
Is this correct?

example of same sid to multiple SID

William, August 14, 2014 - 8:01 pm UTC

SID vs SERVICE_NAME

Gabriel Stuart Lobo-Blanco, June 01, 2018 - 8:58 pm UTC

It is hard to believe how much confusion on this topic. I hope my comments help.

SID is a unique identifier of the instance. In a cluster/RAC configuration you can't have two intances of the same database with the same name. This makes it impossible for the cluster to provide load balancing and connection failover as each instanced has a unique id. This information is provided in the "instance_name" parameter. Thus SERVICE_NAME. In cluster/RAC configuration both instances can have the same service name. This makes it possible to provide transparent application fail-over as well as load balancing across instances. One additional benefit is that when the instance starts, it may register itself the the listener, provided the listener info is in the local_listener/remote_listener db parameter.
Connor McDonald
June 03, 2018 - 9:01 am UTC

So you gave *us* 1 star for that ?

ora-01034 and ora -27101

A reader, August 09, 2018 - 7:03 pm UTC

I am facing this problemand cant find solution to this. It would be dreat if you can help with this error.

SQL*Plus: Release 11.2.0.1.0 Production on Fri Aug 10 00:05:50 2018

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

Enter user-name: rew
Enter password:
ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Process ID: 0
Session ID: 0 Serial number: 0


Enter user-name: ewr
Enter password:
ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Process ID: 0
Session ID: 0 Serial number: 0


Enter user-name: ds
Enter password:
ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Process ID: 0
Session ID: 0 Serial number: 0


SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus

C:\Users\dcv>sqlplus

SQL*Plus: Release 11.2.0.1.0 Production on Fri Aug 10 00:06:06 2018

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

Enter user-name: system
Enter password:
ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Process ID: 0
Session ID: 0 Serial number: 0


Enter user-name: ds
C:\Users\dcv>
C:\Users\dcv>down vote
'down' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\dcv>Open command prompt and execute the below commands:
'Open' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\dcv>
C:\Users\dcv>set oracle_sid=DATABASE NAME

C:\Users\dcv>sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Fri Aug 10 00:21:49 2018

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

SQL> conn sys/sys as sysdba
ERROR:
ORA-12560: TNS:protocol adapter error


SQL> shutdown abort
ORA-12560: TNS:protocol adapter error
SQL> startup
ORA-12560: TNS:protocol adapter error
SQL>
C:\Users\dcv>set oracle_sid=orcl

C:\Users\dcv>sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Fri Aug 10 00:27:20 2018

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

SQL> conn
Enter user-name: system
Enter password:
ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Process ID: 0
Session ID: 0 Serial number: 0


SQL> select * from dual
2 ;
SP2-0640: Not connected
SQL> select * from dual;
SP2-0640: Not connected
SQL>
Connor McDonald
August 15, 2018 - 11:58 pm UTC

First thing we need to sort out:

If the database running on your OWN machine, or are you wanting to talk to a database on a DIFFERENT machine on your network ?