Friday, October 3, 2008

Oracle Startup Oracle Database on Linux

1. คำสั่ง Start Oracle Console
Your_Server_Shell> $ORACLE_HOME/bin/emctl start dbconsole
http://localhost:1158/em
2. export ORACLE_HOME=path i.e. /opt/oracle/production/10gR2
export ORACLE_SID=instance database i.e. PROD or TEST
3. คำสั่ง Start Database Instance
- shell> $ORACLE_HOME/bin/sqlplus sys/password_sys as sysdba
- sqlplus>startup
- shell> $ORACLE_HOME/bin/lsnrctl start
- shell> $ORACLE_HOME/bin/emctl start dbconsole

การสร้าง auto startup เมื่อ boot เครื่อง ไว้ใน /etc/init.d/oracle ครับ
#!/bin/bash

ORA_HOME="/u01/app/oracle/product/10.1.0/Db\_1"
ORA_OWNR="oracle"
ORACLE_SID="dev"

# if the executables do not exist -- display error

if [ ! -f $ORA_HOME/bin/dbstart -o ! -d $ORA_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi

# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display

case "$1" in
start)
# Oracle listener and instance startup
echo -n "Starting Oracle: "
su - $ORA_OWNR -c "$ORA_HOME/bin/lsnrctl start"
su - $ORA_OWNR -c $ORA_HOME/bin/dbstart
su - $ORA_OWNR -c "$ORA_HOME/bin/emctl start dbconsole"
touch /var/lock/subsys/oracle
echo "OK"
;;
stop)
# Oracle listener and instance shutdown
echo -n "Shutdown Oracle: "
su - $ORA_OWNR -c "$ORA_HOME/bin/lsnrctl stop"
su - $ORA_OWNR -c $ORA_HOME/bin/dbshut
su - $ORA_OWNR -c "$ORA_HOME/bin/emctl stop dbconsole"
rm -f /var/lock/subsys/oracle
echo "OK"
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 start|stop|restart|reload"
exit 1
esac
exit 0

##อย่าลืมแก้ค่า ORA_OWNR, ORA_HOME, ORACLE_SID
แล้ว ln -s /etc/init.d/oracle /etc/rc{3,5}.d/S99oracle
และ ln -s /etc/init.d/oracle /etc/rc{0,6}.d/K01oracle
แล้วจะเลือกว่าจะให้ DB ไหน AutoStart บ้างก็ไปแก้ที่ /etc/oratab ครับ อันหลังสุดให้เปลี่ยนเป็น Y