Welcome

首页 / 数据库 / MySQL / Solairs系统中配置Oracle 12c 开机启动

安装完成Oracle 12c的数据库后,发现不能随机开启数据库。如何使用系统脚本完成数据库的随机启动呢?整理一下,Oracle Solaris系统中完Oracle 12c数据库自动的启动、关闭和重新启动的操作步骤。1、oratab文件对于非Oracle Solaris系统的oratab文件会保存在/etc/oratab,而solairs系统的oratab文件保存在/var/opt/oracle目录下。# cat /var/opt/oracle/oratab这个文件里面的内容很简短,格式$ORACLE_SID:$ORACLE_HOME:<Y|N>当$ORACLE_SID:$ORACLE_HOME:<N|Y>设置为Y时,允许实例自启动,当设置为N时,则不允许自启动# cat /var/opt/oracle/oratabdota:/export/home/oracle/app/product/12.1.0.2/dbhome_1:Y该oratab文件使用root.sh脚本创建,并且在使用DBCA命令时会更新这个文件。它的作用很简单,类似于房间里面电力系统总开关闸的作用。2、dbstart和dbshut对于数据库的启停还是oracle的$ORALCE_HOME/bin目录下,dbstart和dbshut两个脚本。dbstart和dbshut脚本中,对于oratab文件有这么一段描述。# This script will start all databases listed in theoratabfile# whose third field is a "Y".  If the third field is set to "Y" and# there is no ORACLE_SID for an entry (the first field is a *),# then this script will ignore that entry.3、创建dbora文件并加入系统环境中在/etc/init.d/目录下,创建文件dbora,内容如下#! /bin/sh# description: Oracle auto start-stop script.## Set ORACLE_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 ORACLE_HOME.#ORA_HOME=<Type your ORACLE_HOME in full path here>#ORA_OWNER=<Type your Oracle account name here>ORA_HOME=/export/home/oracle/app/product/12.1.0.2/dbhome_1ORA_OWNER=oraclecase "$1" in"start")# Start the Oracle databases:# The following command assumes that the oracle login# will not prompt the user for any values# Remove "&" if you don"t want startup as a background process.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 valuessu - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME" &rm -f /var/lock/subsys/dbora;;Esac我们可以在root用户下使用命令进行测试#  su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"即使切换到oracle用户执行./dbstart命令测试,发现无法执行成功并返回以下错误./bin/dbstart: dota: argument expected原因是在dbstart和dbshut文件中使用/bin/sh的shell,而脚本中含有bash格式的命令行,需要使用/bin/bash的shell。所以在dbstart和dbshut文件中,使用/bin/bash替换掉/bin/sh更改文件数组和权限、创建软连接# chgrp dba dbora# chmod 750 dbora# ln -s /etc/init.d/dbora /etc/rc0.d/K01dbora# ln -s /etc/init.d/dbora /etc/rc3.d/S99dbora重启服务器,测试成功。更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12本文永久更新链接地址