读书人

写个脚正本启动数据库

发布时间: 2013-04-09 16:45:09 作者: rapoo

写个脚本来启动数据库
每次打开Linux总要做写重复的动作,那就是启动监听,启动数据库,查看数据库状态。麻烦还是写个shell脚本来控制方便些:在$ORACLE_HOME/bin下有个dbstart脚本可以启动数据库,但是执行之后提示:Failed to auto-start Oracle Net Listene using /ade/vikrkuma_new/oracle/bin/tnslsnr我们来查看下dbstart是怎么写的,直接查询查找文件中的报错来自哪里:/Failed to auto-start Oracle Net[oracle@localhost bin]$ grep "Failed to auto-start Oracle Net" dbstart echo "Failed to auto-start Oracle Net Listene using $ORACLE_HOME_LISTNER/bin/tnslsnr"在这之前有一句:ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle开来是路径设错了,修改为:ORACLE_HOME_LISTNER=$ORACLE_HOME报错重新执行下,没报错,但是数据库却没有起来,修改文件:vi /etc/oratab修改为:orclsid:/home/oracle/oracle/product/10.2.0/db_1:Y记住,后面为Y再起,报错:查看启动日志:$ORACLE_HOME/startup.log[oracle@localhost bin]$ cat $ORACLE_HOME/startup.log/home/oracle/oracle/product/10.2.0/db_1/bin/dbstart: Starting up database "orclsid"Sat Apr 6 21:58:21 CST 2013SQL*Plus: Release 10.2.0.1.0 - Production on Sat Apr 6 21:58:21 2013Copyright (c) 1982, 2005, Oracle. All rights reserved.SQL> ERROR:ORA-01031: insufficient privilegesSQL> ORA-01031: insufficient privilegesSQL> /home/oracle/oracle/product/10.2.0/db_1/bin/dbstart: Database instance "orclsid" warm started.看来是权限问题,突然想到我之前修改了Oracle的默认认证方式,禁用了操作系统登录,估计在脚本里面使用的是操作系统登录:一查,果然是这个问题:修改为:conn sys/lubinsu as sysdba重启下:[oracle@localhost bin]$ dbstartProcessing Database instance "orclsid": log file /home/oracle/oracle/product/10.2.0/db_1/startup.log/home/oracle/oracle/product/10.2.0/db_1/bin/dbstart: Starting up database "orclsid"Sat Apr 6 22:25:27 CST 2013

SQL*Plus: Release 10.2.0.1.0 - Production on Sat Apr 6 22:25:27 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> Connected to an idle instance.SQL> ORACLE instance started.
Total System Global Area 285212672 bytesFixed Size 1218968 bytesVariable Size 100664936 bytesDatabase Buffers 176160768 bytesRedo Buffers 7168000 bytesDatabase mounted.Database opened.SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionWith the Partitioning, OLAP and Data Mining options
/home/oracle/oracle/product/10.2.0/db_1/bin/dbstart: Database instance "orclsid" warm started.看来已经起起来了,查看进程是否存在[oracle@localhost bin]$ ps -ef | grep ora_pmonoracle 14658 1 0 22:25 ? 00:00:00 ora_pmon_orclsidoracle 14806 9470 0 22:26 pts/1 00:00:00 grep ora_pmonNICE我们继续来写脚本:#!/bin/bash # # chkconfig: 2345 89 20 # description: starts the oracle listener and instance
status() { pid=`ps -ef | grep ora_pmon | grep -v grep | awk '{print $8}'` if [ "X$pid" = "X" ] then echo "oracle10g is not running." exit 1 else echo "oracle10g is running." exit 0 fi}
case "$1" in start) #startup the listener and instance echo -n "oracle begin to startup: " su - oracle -c "lsnrctl start" su - oracle -c dbstart echo "oracle10g started" ;; stop) # stop listener, apache and database echo -n "oracle begin to shutdown:" su - oracle -c "lsnrctl stop" su - oracle -c dbshut echo "oracle10g shutdowned" ;; reload|restart) $0 stop $0 start ;; 'status') status ;; *) echo "Usage: ora10g [start|stop|reload|restart]" exit 1 esac exit 0
赋给执行权限chmod a+x oracle10g我们可以通过这个脚本来查看oracle的状态,启动,关闭或者重启数据库,方便许多。

读书人网 >其他数据库

热点推荐