Tuesday, May 10, 2011

Manually starting and stopping Oracle 11gR2 from the command line, and a shell script

A colleague of mine asked me how to start Oracle database from the command like without getting into SQL.

To start and stop the database, testora is the name of our database

bash-3.2$ srvctl start database -d testora
bash-3.2$ srvctl stop database -d testora

To shutdown the ASM instance

bash-3.2$ srvctl stop asm -f

Start the ASM instance and the diskgroups:

bash-3.2$ srvctl start asm

Script to startup Oracle(startup.ksh)
#!/usr/bin/ksh
SQLDBA="sqlplus /nolog"
$SQLDBA <<EOF
connect / as sysdba
startup
quit
EOF

Script to shutdown Oracle(shutdown.ksh)
#!/usr/bin/ksh
SQLDBA="sqlplus /nolog"
$SQLDBA <<EOF
connect / as sysdba
shutdown abort
quit
EOF 

Script to startup Oracle ASM(startup_asm.ksh)
#!/usr/bin/ksh
export ORACLE_SID=+ASM
SQLDBA="sqlplus /nolog"

$SQLDBA <<EOF
connect / as sysdba
connect sys/test123 as sysasm
startup
quit
EOF
 
Script to shutdown Oracle ASM(shutdown_asm.ksh)
#!/usr/bin/ksh
ORACLE_SID="+ASM"
export ORACLE_SID
SQLDBA="sqlplus / as sysdba"

$SQLDBA <<EOF
connect sys as sysdba
connect sys/test123 as sysasm
shutdown abort
quit
EOF

No comments: