-
Notifications
You must be signed in to change notification settings - Fork 2
/
start_db.ksh
149 lines (131 loc) · 4.72 KB
/
start_db.ksh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/ksh
#
#
##########################################################################
#
# USAGE: start_db.ksh ORACLE_SID
#
# PARAMETER(S): 1
#
# AUTHOR: Satya Sridhar @ Kelloggs
#
# DESCRIPTION: Start up the specified Oracle Instance.
#
# REQUIREMENTS: This script has to be run as the "oracle"/"dba" user.
# This script requires 1 argument/parameter.
# Requires the standard Oracle "/etc/oratab" file.
# Assumes the existence of the /oracle/sqlutils directory (can be changed) and
# Must have read/write access to that directory.
#
# COMMENTS: SS - 02/11/2004 - Created.
#
# UPDATE #1: Abdul Mohammed - Feb/2016
#
# Added logic to support Data guard. If DB role is PRIMARY then open database
# If DB role is Physical standby, start media recovery..
#
##########################################################################
##########################################################################
# Check usage.
##########################################################################
#
if [ ! $# -eq 1 ]; then
echo
echo "Error: Usage = `basename ${0}` SID"
echo
return -1
fi
##########################################################################
# Save script parameter(s) into variables.
##########################################################################
SID=$1
##########################################################################
# Set environment/other variables.
##########################################################################
LOGDIR=/oracle/sqlutils/logs
LOG=${LOGDIR}/start_db_"$SID"_`date "+%m%d%y_%H%M%S"`.log
SPOOL_FILE=${LOGDIR}/spool_dbstart.log
ORATAB=/etc/oratab
export ORACLE_SID=$SID
export ORACLE_HOME=`grep -i $ORACLE_SID: $ORATAB | grep -v "^#" | cut -f2 -d:`
export PATH=$ORACLE_HOME/bin:$PATH
export SHLIB_PATH=$ORACLE_HOME/lib
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
##########################################################################
# Change directory to the desired location of the logs.
##########################################################################
cd /oracle/sqlutils
rm ${LOGDIR}/start_db_"$ORACLE_SID"*.log
##########################################################################
# Check if the temporary spool file exists. Perform cleanup before starting.
##########################################################################
if [ -f $SPOOL_FILE ]; then
rm $SPOOL_FILE >/dev/null 2>&1
fi
##########################################################################
# Startup the database in mount mode and record startup time.
##########################################################################
echo | tee -a $LOG
sqlplus -s /nolog << EOF | tee -a $LOG
connect / as SYSDBA
startup mount;
set echo off
set head off
set feedback off
set verify off
set linesize 80
set pagesize 1
spool $SPOOL_FILE
select 'Started database in MOUNT mode...' from dual;
select 'DataBase : ' || instance_name || ' - Started at -> ' || to_char(startup_time,'MM-DD-YYYY HH24:MI:SS') from v\$instance;
spool off
exit
EOF
# Start of new update, added logic to support data guard
DB_ROLE='select database_role from v$database;'
LOCAL_DB_ROLE=`echo $DB_ROLE | sqlplus -S / as sysdba | tail -2|head -1`
if [ "$LOCAL_DB_ROLE" = "PRIMARY" ]
then
echo "Database Role is PRIMARY"
sqlplus -s /nolog << EOF | tee -a $LOG
connect / as SYSDBA
set echo off
set head off
set feedback off
set verify off
set linesize 80
set pagesize 1
select 'Starting database in OPEN mode...' from dual;
alter database open;
spool $SPOOL_FILE append;
select 'Started database in OPEN mode...' from dual;
spool off
exit
EOF
elif [ "$LOCAL_DB_ROLE" = "PHYSICAL STANDBY" ]
then
echo "Database Role is PHYSICAL STANDBY"
sqlplus -s /nolog << EOF | tee -a $LOG
connect / as SYSDBA
set echo off
set head off
set feedback off
set verify off
set linesize 80
set pagesize 1
select 'Starting database recovery as its a Physical Staandby....' from dual;
alter database recover managed standby database using current logfile disconnect;
spool $SPOOL_FILE append;
select 'Started database recovery....' from dual;
spool off
exit
EOF
fi
#
##########################################################################
# Save database startup time info in a cumulative file.
##########################################################################
#
cat $SPOOL_FILE >> ${LOGDIR}/`hostname`_db_start.log
rm $SPOOL_FILE
exit