大家都注意到用Oracle自带的dbstart脚本无法在系统启动时自动启动Oracle数据库,下面介绍oracle启动脚本的编写和设置!
最简单的脚本示例:
#!/bin/sh
sqlplus / as sysdba<<EOF
startup
EOF
$ ./mydbstart
SQL*Plus: Release 10.1.0.3.0 - Production on Sat Apr 19 13:12:46 2008
Copyright (c) 1982, 2004, Oracle. All rights reserved.
Connected to an idle instance.
SQL> ORACLE instance started.
Total System Global Area 281018368 bytes
Fixed Size 778756 bytes
Variable Size 95165948 bytes
Database Buffers 184549376 bytes
Redo Buffers 524288 bytes
Database mounted.
Database opened.
SQL> SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
$
最简单的脚本示例:
#!/bin/sh
sqlplus / as sysdba<<EOF
startup
EOF
$ ./mydbstart
SQL*Plus: Release 10.1.0.3.0 - Production on Sat Apr 19 13:12:46 2008
Copyright (c) 1982, 2004, Oracle. All rights reserved.
Connected to an idle instance.
SQL> ORACLE instance started.
Total System Global Area 281018368 bytes
Fixed Size 778756 bytes
Variable Size 95165948 bytes
Database Buffers 184549376 bytes
Redo Buffers 524288 bytes
Database mounted.
Database opened.
SQL> SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
$
下边是完整的脚本示例
#!/bin/sh
case "$1" in
start)
# start tsnlisnter
echo "start tsnlisnter"
su - oracle -c "lsnrctl start"
# start database
echo "Start Oracle database instance"
su - oracle -c "echo /"
connect / as sysdba
startup
exit /"|sqlplus /NOLOG"
# start enterprise manager
echo " Start Emterprise Manager"
su - oracle -c "emctl start dbconsole"
# start isqlplus
echo "Start isqlplus"
su - oracle -c "isqlplusctl start"
;;
stop)
# shutdown database
echo "Shutdown Oracle database instance"
su - oracle -c "echo /"
connect / as sysdba
shutdown immediate
exit /"|sqlplus /NOLOG"
# stop tsnlisnter
echo "Stop tsnlisnter"
su - oracle -c "lsnrctl stop"
# stop enterprise manager
echo " Stop Emterprise Manager"
su - oracle -c "emctl stop dbconsole"
# stop isqlplus
echo "Stop isqlplus"
su - oracle -c "isqlplusctl stop"
;;
*)
echo "Usage: $0 { start | stop }"
exit 1
;;
esac
exit 0
此脚本保存在 /etc/init.d/oracle10g
设置脚本连接!
#ln [-s] /etc/init.d/oracle10g /etc/rc2.d/S99oracle10g
#ln [-s] /etc/init.d/oracle10g /etc/rc0.d/K00oracle10g
case "$1" in
start)
# start tsnlisnter
echo "start tsnlisnter"
su - oracle -c "lsnrctl start"
# start database
echo "Start Oracle database instance"
su - oracle -c "echo /"
connect / as sysdba
startup
exit /"|sqlplus /NOLOG"
# start enterprise manager
echo " Start Emterprise Manager"
su - oracle -c "emctl start dbconsole"
# start isqlplus
echo "Start isqlplus"
su - oracle -c "isqlplusctl start"
;;
stop)
# shutdown database
echo "Shutdown Oracle database instance"
su - oracle -c "echo /"
connect / as sysdba
shutdown immediate
exit /"|sqlplus /NOLOG"
# stop tsnlisnter
echo "Stop tsnlisnter"
su - oracle -c "lsnrctl stop"
# stop enterprise manager
echo " Stop Emterprise Manager"
su - oracle -c "emctl stop dbconsole"
# stop isqlplus
echo "Stop isqlplus"
su - oracle -c "isqlplusctl stop"
;;
*)
echo "Usage: $0 { start | stop }"
exit 1
;;
esac
exit 0
此脚本保存在 /etc/init.d/oracle10g
设置脚本连接!
#ln [-s] /etc/init.d/oracle10g /etc/rc2.d/S99oracle10g
#ln [-s] /etc/init.d/oracle10g /etc/rc0.d/K00oracle10g