go to http://oracle.in.th

Thursday, June 10, 2010

มาลดเวลาการ Start Oracle Database ด้วย Auto Start กันเถอะ

โดยปกติ เวลาผมจะ Start Database นั้น ผมจะ Start แบบ manual มีวันนึงผมก็เริ่มขี้เกียจมา อยากจะให้ Database มัน Start เองเลยหลังจาก Boot OS เสร็จ...ผมเลยไปหาวิธีที่จะให้มัน Auto Start Database หลังจากการ boot OS เลยโดยที่ผมไม่ต้องไปทำ manual start อีกต่อไป วันนี้เลยอยากจะแชร์บทความนี้ไว้ เผื่อใครอยากทำบ้างนะครับ

มาดูวิธีที่จะทำให้ Oracle Database auto start ขึ้นมาหลังจากการ boot OS โดยที่ admin ไม่ต้อง manual start กันเลยดีกว่า

1. login root

2. เข้าไปแก้ที่ /etc/oratab
โดยสังเกตุที่บรรทัด orcl:/oracle/db11201:N
ถ้าเป็น N อยู่ให้เปลี่ยนเป็น Y ดังนี้ orcl:/oracle/db11201:Y

3.สร้างไฟล์ใหม่ชื่อ dbora ไว้ที่ /etc/init.d/ โดยรายละเอียดตามด้านล่าง

#!/bin/sh
#chkconfig: 345 99 10
#description: Oracle auto start-stop script.
#
#Set ORA_HOME to be equivalent to the $ORACLE_HOME
#from which you wish to execute dbstart and dbshut;
#
#Set ORA_OWNER to the user id of the owner of the
#Oracle database in ORA_HOME.

ORA_HOME=/oracle/db11201
ORA_OWNER=oracle

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

case "$1" in
'start')
#Start the Oracle databases:
#The following command assumes that the oracle login
#will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole" &
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
touch /var/lock/subsys/dbora
;;
'stop')
#Stop the Oracle databases:
#The following command assumes that the oracle login
#will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole" &
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
rm -f /var/lock/subsys/dbora
;;
esac

ข้อควรระวัง ต้องแก้ส่วน path ORA_HOME ให้ตรงตามที่เราเซ็ต $ORACLE_HOME ไว้ด้วย

4. ทำการ execute โดยใช้คำสั่งตามด้านล่างนี้

#chmod 750 /etc/init.d/dbora
#ln -s /etc/init.d/dbora /etc/rc.d/rc0.d/K01dbora
#ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora
#ln -s /etc/init.d/dbora /etc/rc.d/rc4.d/S99dbora
#ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora
#ln -s /etc/init.d/dbora /etc/rc.d/rc6.d/K01dbora

5. ทำการ reboot เครื่องใหม่ ก็เป็นอันเสร็จ

เราจะทราบได้อย่างไรว่าสิ่งที่เราทำไป database ได้ start หรือ shutdown ได้ถูกต้องจริงๆ
  • ตรวจสอบ log file เมื่อเปิดเครื่อง ที่ $ORACLE_HOME/startup.log
  • ตรวจสอบ log file ไฟล์เมื่อปิดเครื่อง ที่ $ORACLE_HOME/shutdown.log

Credit by Bie

อ้างอิงจาก
ข้อเขียนนี้ช่วยฉัน:  

No comments:

Post a Comment