Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Connect to database with SQL*Plus: is TNSNAMES.ORA used?

vivalavidaNov 7 2013 — edited Nov 7 2013

Hi ,

we have a local database called DEV01 and a duplicate of this database in a datacenter. To be able to connect to both databases the TNSNAMES.ORA

on the local database server (not the one in the datacenter) has the following entries:

/* Entry for local database */

DEV01_local, DEV01_local.WORLD =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = server01)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SID= DEV01)
    )
   )

/* Entry for database in datacenter */

DEV01,DEV01.WORLD =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = server02)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SID = DEV01)
    )
  )

When I connect to the local database server I set the Oracle-environment as follows:

export ORACLE_SID=DEV01

export PATH=/opt/oracle/app/oracle/product/9.2.0/bin:$PATH

export ORACLE_HOME=/opt/oracle/app/oracle/product/9.2.0

Now I start SQL*Plus as follows:

oracle#> sqlplus user/user

SQL> select instance_name, host_name from v$instance;

INSTANCE_NAME    HOST_NAME

---------------- ----------------------------------------------------------------

DEV01            server01

Since the SID is on both databases the same (DEV01) I really do not understand how Oracle decides to which database SQL*Plus connects to.

Is it a matter of the entries in the TNSNAMES.ORA?

But when I start SQL*Plus as follows:

oracle#> sqlplus user/user@DEV01_local

SQL> select instance_name, host_name from v$instance;

INSTANCE_NAME    HOST_NAME

---------------- ----------------------------------------------------------------

DEV01            server01

or

oracle#> sqlplus user/user@DEV01

SQL> select instance_name, host_name from v$instance;

INSTANCE_NAME    HOST_NAME

---------------- ----------------------------------------------------------------

DEV01            server02

everything is as expected.

Does anybody know which database gets chosen when just connect with "sqlplus user/user" (without @DEV01 or @DEV01_local)?

Any help will be appriciated!

Rgds

Jan

This post has been answered by John Spencer on Nov 7 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 5 2013
Added on Nov 7 2013
5 comments
729 views