Before using Oracle with a Unix / Linux user account you need to get the Unix environment set correctly.  This includes things like common environment variables, and the Unix search PATH.  In addition if you are wanting to avoid hard-coding within any database maintenance scripts, you will need to set a range of additional environment variables.

Oracle provide as standard a script called "oraenv" which works for the bourne, korn & bash shells.  This script uses the data in /etc/oratab to setup the ORACLE_HOME, ORACLE_SID & PATH environment variables.  Whilst this is sufficient for most standalone oracle servers & databases, there is a lot more information that you might need when running a more complex environment.  This includes things related to any RAC environment, dataguard statuses, what host the database is running on, etc.  Also the "oraenv" script is not configured to take the database SID (ORACLE_SID) as a command line argument, it thus needs some sort of wrapper to get this functionality.  Further it requires that you are on the host that the database is running on, in a clustered environment, or one running dataguard, this may not always be obvious.

The solution to all this is a custom script that sets everything about an Oracle environment that you could ever need.  It uses the data in tnsnames.ora (returned via tnsping) to start the exploration for the various bits and pieces in an Oracle environment.  It can also hold environment settings for things like standard directory and file locations (set these based on your environment standards).  This script is then used in all other scripts to correctly set the environment & variables for any given database.

The following assumptions are made -

  • That there is a management server (OEM) that centrally manages the databases
  • All servers share a common tnsnames.ora file with all databases in it
  • that there is ssh equivalence between the management server and hosts
  • that there is a standard management account on all the database servers
  • that the primary and standby dataguard database unique names are suffixed "_A" or "_B" (site A & site B)

The following variables are set by this script -

	echo "Database BASE_SID is                  : $BASE_SID"
	echo "Database DB_NAME is                   : $DB_NAME"
	echo "Database DB_UNIQUE_NAME is            : $DB_UNIQUE_NAME"
	echo "Script & log BASE_DIR0 is             : $BASE_DIR0"
	echo "Script & log BASE_DIR is              : $BASE_DIR"
	echo "Log LOG_DIR is                        : $LOG_DIR"
	echo "Log file Date (LOGDATE) is            : $LOGDATE"
	echo "Base RMAN_DIR is                      : $RMAN_DIR"
	echo "Base Host (HOST1) is                  : $HOST1"
	echo "Is this RAC ?                         : $ISRAC"
	echo "Cluster Node 1 is (NODE1)             : $NODE1"
	echo "Cluster Node list is (NODES)          : $NODES"
	echo "Cluster Name is (CLUSTER_NAME)        : $CLUSTER_NAME"
	echo "Primary Cluster is (PRIMARY_CLUSTER)  : $PRIMARY_CLUSTER"
	echo "Standby Cluster is (STANDBY_CLUSTER)  : $STANDBY_CLUSTER"
	echo "Primary site is (PRIMARY_SITE)        : $PRIMARY_SITE"
	echo "Standby site is (STANDBY_SITE)        : $STANDBY_SITE"
	echo "Database INSTANCE 1 is                : $INSTANCE1"
	echo "Database INSTANCE list is             : $INSTANCES"
	echo "Database Role DATABASE_ROLE is        : $DATABASE_ROLE"
	echo "PRIMARY_DB is                         : $PRIMARY_DB"
	echo "STANDBY_DB is                         : $STANDBY_DB"
	echo "PRIMARY_SERVICE is                    : $PRIMARY_SERVICE"
	echo "STANDBY_SERVICE is                    : $STANDBY_SERVICE"
	echo "Standby Node list (STANDBY_NODES) is  : $STANDBY_NODES"
	echo "STANDBY_NODE1 is                      : $STANDBY_NODE1"
	echo "Management Server MGT_SVR is          : $MGT_SVR"
	echo "Link for log files LOG_LINK is        : $LOG_LINK"
	echo "Lower case SID LC_SID is              : $LC_SID"
	echo "Running on current host RUN_HOST      : $RUN_HOST"
	echo "Number of database nodes/instances is : $NUM_NODES"
	echo "Days to keep various types of files for..."
	echo "Log files (KEEP_LOG)                  : $KEEP_LOG"
	echo "Daily Backup files (KEEP_DAILY)       : $KEEP_DAILY"
	echo "Weekly Backup files (KEEP_WEEKLY)     : $KEEP_WEEKLY"
	echo "Monthly Backup files (KEEP_MONTHLY)   : $KEEP_MONTHLY"
	echo "Yearly Backup files (KEEP_YEARLY)     : $KEEP_YEARLY"
	echo "DATAGUARD_BROKER is                   : $DATAGUARD_BROKER"
	echo "Is this a Dataguard db (ISDATAGUARD)? : $ISDATAGUARD"
	echo "Is this using CMAN (CMAN) ?           : $CMAN"



Download this file ([Set Oracle Database Environment]9 kB