Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

Oracle

Posted Sep 4, 2003

What's In A Name - Naming and Idenifying Oracle Databases and Instances - Page 2

By James Koopmann





GLOBAL_NAMES




While this variable does not directly store a value that you can identify your database with, it does dictate how you might connect to a database. This variable is either TRUE or FALSE and if it is set to TRUE it enforces database links to have the same name as the remote database to which they are linking. In Listing 5, you can see a sequence of events where I first set GLOBAL_NAMES to TRUE and then created a database link. The interesting thing is that Oracle lets you create a database link that goes against the GLOBAL_NAMES parameter setting. It 'is not until you actually try to use it that you get an ORA-02085 error. After setting GLOBAL_NAMES to FALSE, I am able to use the database link.





Listing 5
Use of GLOBAL_NAMES parameter




SQL> alter system set global_names=true;
System altered.
SQL> create database link alink connect to <user> identified by <pass> 
  1   using 'hcmc.den.dbdoctor.net';
Database link created.
SQL> select table_name from user_tables@alink;
select table_name from user_tables@alink
                                *

ERROR at line 1:
ORA-02085: database link ALINK.DEN.DBDOCTOR.NET connects to HCMC.DEN.DBDOCTOR.NET


SQL> alter system set global_names=false;
System altered.
SQL> select * from global_name@alink;
GLOBAL_NAME
---------------------------------------------------------
HCMC.DEN.DBDOCTOR.NET


INSTANCE_NAME



The INSTANCE_NAME is the name given to the set of processes that are running on the database server. This parameter is set in the INIT.ORA and can be seen by querying the V$INSTANCE table. The SQL is given in Listing 6.

Listing 6
SQL for extracting the INSTANCE_NAME

SQL> select instance_number,instance_name,host_name from v$instance


INSTANCE_NUMBER INSTANCE_NAME    HOST_NAME
--------------- ---------------- ---------------------------------------
              1 hcmc1            JKOOPMANN1

SERVICE_NAMES

This parameter will default to the GLOBAL_NAME. Remember the GLOBAL_NAME is a combination of DB_NAME and DB_DOMAIN. This parameter can take on multiple names that are comma separated. This allows you to give different service names to the same instance or a single service name for multiple instances that access the same database, as in Oracle's real application cluster environment. The point here is that the service name will not give you a unique name for the instance to which you are connected.

DBID

While DBID is not a "name" of a database, it does have the quality of uniquely identifying a database be a unique number. The DBID number is generated at database creation. Don't ask me how this number is generated, I wish I knew. All I can say is that it is supposed to be unique across databases. Well we all know that nothing in this world can be trusted to be absolutely unique across all databases. I know of one instance where if you were to clone a database, the DBID will be the same for the cloned database as the original. At least Oracle has given us a work-around in the form of a utility to change the DBID. Listing 7 will give you the SQL to extract the DBID. There are two tables you can get this information from, the V$DATABASE and the GV$DATABASE. If you are not aware of the 'GV' tables, they are GLOBAL across clustered instances.

Listing 7
SQL for getting DBID

HCMC-SQL> select dbid,name from v$database;
      DBID NAME
---------- --------------------
3060884937 HCMC


SQL> select inst_id,dbid,name from gv$database;

   INST_ID       DBID NAME
---------- ---------- ---------
         1 3060884937 HCMC
         2 3060884937 HCMC

INST_ID

You should have noticed in Listing 6 and Listing 7 that when selecting from the V$ table there was no INST_ID. That is because the V$ tables act on the current instance connected to and the GV$ tables acts on all instances for the database as in a cluster environment. The other GV$ table to get some information from is the GV$INSTANCE table. By executing the SQL in Listing 8, you can get the INST_ID, INSTANCE_NUMBER, INSTANCE_NAME and HOST_NAME for determining what machine you are on.

Listing 8
SQL for extracting the HOST_NAME

SQL> select instance_number,instance_name,host_name from v$instance

INSTANCE_NUMBER INSTANCE_NAME    HOST_NAME
--------------- ---------------- ---------------------------------------
              1 hcmc1            JKOOPMANN1

SQL> select inst_id,instance_number,instance_name,host_name from gv$instance INST_ID INSTANCE_NUMBER INSTANCE_NAME HOST_NAME ---------- --------------- ---------------- --------------------------------------- 1 1 hcmc1 JKOOPMANN1 2 2 hcmc2 JKOOPMANN2

When we as DBA(s) start working in a distributed environment where there are replicated environments, Real Application Clusters, standby databases, cloned databases and a variety of other configurations, it is imperative that we are able to distinguish the database instance that we are connected to and the database it is connected to. Go forth and name properly so that you won't get lost in the sea of confusion.

» See All Articles by Columnist James Koopmann



Oracle Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
Oracle Forum
Topic By Replies Updated
Oracle Data Mining: Classification jan.hasller 0 July 5th, 07:19 AM
Find duplicates - Unique IDs Lava 5 July 2nd, 08:30 AM
no matching unique or primary key rcanter 1 April 25th, 12:32 PM
Update values of one table based on condition of values in other table using Trigger Gladiator 3 February 29th, 06:01 PM


















Thanks for your registration, follow us on our social networks to keep up-to-date