🧠 Oracle Multi-Database Environment – Beginner Notes

πŸ“Œ Topics Covered

  • What is ORACLE_SID and why it matters
  • What is sqlplus /, /nolog, and as sysdba
  • Difference between PFILE and SPFILE
  • What are TNS and Listeners
  • Why root can’t connect as SYSDBA
  • How to manage multiple Oracle databases on one server
  • How to switch between databases

πŸ—οΈ Oracle Environment Basics

In Oracle, your shell environment defines which database you’re working with locally. The key variables are:

export ORACLE_HOME=/path/to/oracle
export ORACLE_SID=YourDBSID
export PATH=$ORACLE_HOME/bin:$PATH

πŸ”‘ ORACLE_SID

  • Stands for Oracle System Identifier
  • Tells Oracle tools (like sqlplus) which local DB instance you want to use
  • You must change it to work with different databases:
export ORACLE_SID=T00

βš™οΈ SQL*Plus Variants Explained

CommandMeaning
sqlplus /OS-auth login as your current user, no SYSDBA privileges
sqlplus / as sysdbaOS-auth login as SYSDBA, for DB admin tasks
sqlplus /nologStart SQL*Plus without connecting, useful for CONNECT later

Example:

sqlplus /nolog
SQL> CONNECT / AS SYSDBA

πŸ”₯ Why root Can’t Do This

Trying this:

sqlplus / as sysdba

As root gives:

ORA-01017: invalid username/password; logon denied

βœ… Only users in the dba group (like oracle, oraclesap) can connect as SYSDBA


πŸ”§ PFILE vs SPFILE

FeaturePFILE (init.ora)SPFILE (spfile.ora)
FormatText fileBinary file
EditableManuallyVia SQL only
Startup usageOptionalPreferred by Oracle

Use STARTUP PFILE='/path/to/init.ora' when no SPFILE is available.

Create SPFILE:

CREATE SPFILE FROM PFILE='/oradata/T00/sapprof/sapT00.ora';

🌐 TNS (Transparent Network Substrate)

TNS is Oracle’s network layer used for:

  • Mapping DB aliases to connection strings
  • Handling remote access to Oracle

TNS is configured in:

  • tnsnames.ora β†’ Maps names like HRDB to host/port/SID
  • listener.ora β†’ Defines how Oracle listens for connections

🎧 What is a Listener?

The Listener is a background process (tnslsnr) that:

  • Listens on a port (default: 1521)
  • Accepts remote connections
  • Hands them off to the correct Oracle DB instance

Check it:

lsnrctl status

πŸ§ͺ Hosting Multiple DBs on One Server

Yes, it’s supported! You can run:

  • Multiple DBs with different SIDs: T00, HRDB, FINDB, etc.
  • One shared ORACLE_HOME
  • One Listener for all

To switch DBs:

export ORACLE_SID=HRDB
sqlplus / as sysdba

πŸ›  Helpful Tools

πŸ” Switching Script

# ~/bin/switchdb
#!/bin/bash
export ORACLE_HOME=/oradata/T00/12201
export ORACLE_SID=$1
export PATH=$ORACLE_HOME/bin:$PATH
echo "Switched to ORACLE_SID=$ORACLE_SID"

Usage:

switchdb HRDB
sqlplus / as sysdba

πŸ” Recap: Local vs Remote

ActionNeeds Listener?Needs TNS?
sqlplus / as sysdba❌ No❌ No
sqlplus user/password@MYDBβœ… Yesβœ… Yes
sqlplus /nolog❌ No❌ No

βœ… Quick Test to Check Running DBs

ps -ef | grep pmon

Shows running Oracle instances by SID:

ora_pmon_T00
ora_pmon_HRDB
ora_pmon_FINDB

🧠 Final Tips

  • Always check $ORACLE_SID before connecting
  • Use sqlplus /nolog when troubleshooting startup
  • Use / as sysdba only as Oracle user (not root)
  • Create spfile from pfile once the DB is stable
  • Only one $ORACLE_SID is active per shell session

πŸ—ƒοΈ File created for beginner DBAs exploring Oracle internals on multi-instance servers

HealthCheck Script for OracleDB

#!/bin/bash
 
# Add timestamp
echo -e "\nπŸ“… $(date)"
echo "πŸ” Starting Oracle Environment Health Check..."
echo "--------------------------------------------------"
 
# Define colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
 
# Check ORACLE_HOME
echo -e "\nπŸ”§ Checking ORACLE_HOME..."
if [[ -z "$ORACLE_HOME" ]]; then
  echo -e "${RED}❌ ORACLE_HOME is not set.${NC}"
else
  echo -e "${GREEN}βœ… ORACLE_HOME is set to: $ORACLE_HOME${NC}"
  if [[ ! -d "$ORACLE_HOME" ]]; then
    echo -e "${YELLOW}⚠️  Warning: ORACLE_HOME directory does not exist.${NC}"
  fi
fi
 
# Check ORACLE_SID
echo -e "\nπŸ”§ Checking ORACLE_SID..."
if [[ -z "$ORACLE_SID" ]]; then
  echo -e "${RED}❌ ORACLE_SID is not set.${NC}"
else
  echo -e "${GREEN}βœ… ORACLE_SID is set to: $ORACLE_SID${NC}"
fi
 
# Check sqlplus availability
echo -e "\nπŸ”§ Checking sqlplus command..."
if ! command -v sqlplus &> /dev/null; then
  echo -e "${RED}❌ sqlplus is not in your PATH.${NC}"
else
  echo -e "${GREEN}βœ… sqlplus is available at: $(which sqlplus)${NC}"
fi
 
# Check for listener.ora
echo -e "\nπŸ”§ Checking listener.ora..."
LISTENER_FILE="$ORACLE_HOME/network/admin/listener.ora"
if [[ -f "$LISTENER_FILE" ]]; then
  echo -e "${GREEN}βœ… Found listener.ora at: $LISTENER_FILE${NC}"
else
  echo -e "${YELLOW}⚠️  listener.ora not found in expected location.${NC}"
fi
 
# Check for tnsnames.ora
echo -e "\nπŸ”§ Checking tnsnames.ora..."
TNSNAMES_FILE="$ORACLE_HOME/network/admin/tnsnames.ora"
if [[ -f "$TNSNAMES_FILE" ]]; then
  echo -e "${GREEN}βœ… Found tnsnames.ora at: $TNSNAMES_FILE${NC}"
else
  echo -e "${YELLOW}⚠️  tnsnames.ora not found in expected location.${NC}"
fi
 
# Check for PMON process
echo -e "\nπŸ”§ Checking PMON processes (all SIDs)..."
PMON_LIST=$(pgrep -fl "ora_pmon_" | awk -F'_' '{print $NF}' | sort | uniq)
if [[ -n "$PMON_LIST" ]]; then
  echo -e "${GREEN}βœ… PMON processes running for SIDs: ${PMON_LIST// /, }${NC}"
else
  echo -e "${RED}❌ No PMON processes found.${NC}"
fi
 
# Check if listener is running
echo -e "\nπŸ”§ Checking if any listeners are running..."
if lsnrctl status > /dev/null 2>&1; then
  echo -e "${GREEN}βœ… Listener is running.${NC}"
else
  echo -e "${RED}❌ Listener is not running or not responding.${NC}"
fi
 
# Check current user and group membership
echo -e "\nπŸ”§ Checking user privileges..."
CURRENT_USER=$(whoami)
if id "$CURRENT_USER" | grep -q '\bdba\b'; then
  echo -e "${GREEN}βœ… User '$CURRENT_USER' is part of the 'dba' group.${NC}"
else
  echo -e "${RED}❌ User '$CURRENT_USER' is not in the 'dba' group.${NC}"
fi
 
# Try to determine datafile locations
echo -e "\nπŸ“‚ Checking datafile locations using SQL..."
SQL_OUTPUT=$(sqlplus -s / as sysdba <<EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
SELECT name FROM v\$datafile;
EXIT;
EOF
)
 
if echo "$SQL_OUTPUT" | grep -qi "/"; then
  echo -e "${GREEN}βœ… Datafiles found:${NC}"
  echo "$SQL_OUTPUT" | sed '/^$/d' | while read -r line; do
    echo "   - $line"
  done
else
  echo -e "${YELLOW}⚠️  Could not retrieve datafiles. Output:${NC}"
  echo "$SQL_OUTPUT"
fi
 
echo -e "\nπŸŽ‰ ${GREEN}Oracle environment check complete.${NC}"

Sample output

 
πŸ“… Tue Jun  3 12:43:30 EDT 2025
πŸ” Starting Oracle Environment Health Check...
--------------------------------------------------
 
πŸ”§ Checking ORACLE_HOME...
βœ… ORACLE_HOME is set to: /oradata/T00/12201
 
πŸ”§ Checking ORACLE_SID...
βœ… ORACLE_SID is set to: T00
 
πŸ”§ Checking sqlplus command...
βœ… sqlplus is available at: /oradata/T00/12201/bin/sqlplus
 
πŸ”§ Checking listener.ora...
βœ… Found listener.ora at: /oradata/T00/12201/network/admin/listener.ora
 
πŸ”§ Checking tnsnames.ora...
βœ… Found tnsnames.ora at: /oradata/T00/12201/network/admin/tnsnames.ora
 
πŸ”§ Checking PMON processes (all SIDs)...
βœ… PMON processes running for SIDs: t00
 
πŸ”§ Checking if any listeners are running...
βœ… Listener is running.
 
πŸ”§ Checking user privileges...
βœ… User 'oraclesap' is part of the 'dba' group.
 
πŸ“‚ Checking datafile locations using SQL...
βœ… Datafiles found:
   - /oradata/T00/sapdata1/system_1/system.data1
   - /oradata/T00/sapdata1/system_1/sysaux.dbf
   - /oradata/T00/sapdata1/undo_1/undo.data1
   - /oradata/T00/sapdata1/users_1/users.data1
   - /oradata/T00/sapdata1/temp_2/usertbs.data1
   - /oradata/T00/sapdata1/temp_2/appstbs.data1
   - /oradata/T00/sapdata1/temp_2/indxtbs.data1
   - /oradata/T00/sapdata2/t00_1/t00.data1
   - /oradata/T00/sapdata3/t00usr_1/t00usr.data1