Oracle Database: Key Differences Between SID, DB Name, DB Domain, Global DB Name, Service Name, Service Alias, and Instance Name


2 views

When working with Oracle databases, you'll encounter several naming concepts that serve different purposes in database administration and connectivity. Let's break down each term with technical precision.

The SID is a unique name that identifies a specific Oracle database instance. It's used primarily in pre-12c databases for local identification.

-- Checking SID in SQL*Plus
SELECT instance_name FROM v$instance;

This is the fundamental name of the database, specified during creation and stored in the control file.

-- Viewing DB_NAME
SELECT name FROM v$database;

A domain qualifier that makes the database name unique within a network environment, typically following DNS naming conventions.

-- Checking DB_DOMAIN
SELECT value FROM v$parameter WHERE name = 'db_domain';

A combination of DB_NAME and DB_DOMAIN that uniquely identifies a database across a network.

-- Viewing global database name
SELECT * FROM global_name;

Introduced in Oracle8i, this represents the logical database service used by clients to connect, especially in RAC environments.

-- Checking service names
SELECT name FROM v$services;

An alternative name for a service, often used in tnsnames.ora for connection abstraction.

# Example tnsnames.ora entry
ORCL_SRV =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dbserver)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl.example.com)
    )
  )

In RAC environments, this identifies individual instances accessing the same database.

-- Viewing instance name in RAC
SELECT instance_name, host_name FROM gv$instance;

Here's how these identifiers appear in different scenarios:

-- Creating a database with specific names
CREATE DATABASE orcl
  USER SYS IDENTIFIED BY password
  USER SYSTEM IDENTIFIED BY password
  LOGFILE GROUP 1 ('/u01/oradata/orcl/redo01.log') SIZE 100M,
          GROUP 2 ('/u01/oradata/orcl/redo02.log') SIZE 100M
  MAXLOGFILES 5
  MAXLOGMEMBERS 5
  MAXLOGHISTORY 1
  MAXDATAFILES 100
  CHARACTER SET AL32UTF8
  NATIONAL CHARACTER SET AL16UTF16
  EXTENT MANAGEMENT LOCAL
  DATAFILE '/u01/oradata/orcl/system01.dbf' SIZE 500M REUSE
  SYSAUX DATAFILE '/u01/oradata/orcl/sysaux01.dbf' SIZE 500M REUSE
  DEFAULT TABLESPACE users
    DATAFILE '/u01/oradata/orcl/users01.dbf' SIZE 500M REUSE
  DEFAULT TEMPORARY TABLESPACE temp
    TEMPFILE '/u01/oradata/orcl/temp01.dbf' SIZE 500M REUSE
  UNDO TABLESPACE undotbs
    DATAFILE '/u01/oradata/orcl/undotbs01.dbf' SIZE 500M REUSE
  SET DB_DOMAIN='example.com';

Different connection methods use different identifiers:

# Using SID (old style)
sqlplus username/password@host:port:SID

# Using Service Name (recommended)
sqlplus username/password@//host:port/service_name

When moving from SID-based to service-based connections:

-- Convert existing SID-based database to use services
ALTER SYSTEM SET service_names='orcl.example.com,orcl' SCOPE=BOTH;

When working with Oracle databases, several naming concepts often confuse developers and DBAs. Let's clarify each term with technical precision.

The SID is a unique name for an Oracle database instance. It's used internally by Oracle and must be unique on a server.

# Example in tnsnames.ora
ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = server1)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SID = ORCL)
    )
  )

This is the name specified during database creation in the CREATE DATABASE statement. It's stored in the control file and data dictionary.

-- SQL to check DB_NAME
SELECT name FROM v$database;

-- Creation example
CREATE DATABASE prod_db
  USER SYS IDENTIFIED BY password
  USER SYSTEM IDENTIFIED BY password;

A logical grouping of databases in a network, typically following DNS naming conventions (e.g., us.example.com). Combined with DB_NAME, it forms the Global Database Name.

-- Setting DB_DOMAIN parameter
ALTER SYSTEM SET db_domain='us.example.com' SCOPE=spfile;

The fully qualified name of a database: DB_NAME.DB_DOMAIN (e.g., prod_db.us.example.com). Used for database links and enterprise-wide identification.

-- Viewing global name
SELECT * FROM global_name;

-- Setting global name
ALTER DATABASE RENAME GLOBAL_NAME TO prod_db.us.example.com;

Introduced in Oracle 8i, this is more flexible than SID for connecting to databases, especially in RAC environments where multiple instances serve one database.

# tnsnames.ora with service name
SALES_SVC =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac-cluster)(PORT = 1521))
    (CONNECT_DATA =
      (SERVICE_NAME = sales.us.example.com)
    )
  )

An alternative name for a service, often used to abstract physical connection details from applications.

# listener.ora example with service aliasing
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = prod_db.us.example.com)
      (ORACLE_HOME = /u01/app/oracle/product/19c/dbhome_1)
      (SID_NAME = PROD1)
    )
  )

Identifies a specific database instance, especially important in RAC environments where multiple instances access the same database.

-- Checking instance name
SELECT instance_name FROM v$instance;

-- RAC example with multiple instances
INSTANCE1.prod_db.us.example.com
INSTANCE2.prod_db.us.example.com

Here's how these identifiers work together in a real scenario:

# JDBC connection string using service name
jdbc:oracle:thin:@//rac-cluster.us.example.com:1521/sales_svc.us.example.com

# SQL*Plus connection using SID
sqlplus system/password@'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
(HOST=server1)(PORT=1521))(CONNECT_DATA=(SID=ORCL)))'
  • Use SERVICE_NAME instead of SID for new applications
  • Maintain consistent naming across environments
  • In RAC, use service names for load balancing
  • Document all naming conventions for your organization