▲启动一个Oracle实例(nomount级别) 读取初始化参数文件初始化SGA,启动后台进程,创建一个Oracle实例,但尚未读取数据库的相关文件,数据库尚未打开。 任务: 创建数据库 创建控制文件 SQL> startup nomount; ORACLE instance started. Total System Global Area 171966464 bytes Fixed Size 1218316 bytes Variable Size 67111156 bytes Database Buffers 96468992 bytes Redo Buffers 7168000 bytes SQL> select status from v$instance; STATUS ------------------------ STARTED SQL> alter database mount; 在nomount状态下继续启动到mount状态。(不能直接启动到open状态) Database altered. SQL> alter database open; 在mount状态下继续启动到open状态。 Database altered. ▲由实例装载数据库(mount级别) 读取初始化参数文件初始化SGA,启动后台进程,创建一个Oracle实例,并且读入数据控制文件和口令文件,但数据库尚未打开。即由参数文件知道控制文件和口令文件在哪。 任务: 修改数据文件名(移动、绝对路径) 执行完全恢复 执行不完全恢复(特殊) 改变日志操作模式时 ▲打开数据库(open级别) 在mount状态下alter database open启动到open状态 根据控制文件的信息读入数据库的数据文件及日志文件,并打开数据库以供使用。 任务: 正常使用数据库 SQL> create pfile from spfile; 备份spfile文件,防止在sql下修改重启不了 File created. SQL> startup open pfile=$ORACLE_HOME/dbs/initora10.ora (只有pfile参数,无spfile)用指定参数 init$ORACLE_SID.ora启动数据库。 ORACLE instance started. Total System Global Area 171966464 bytes Fixed Size 1218316 bytes Variable Size 71305460 bytes Database Buffers 92274688 bytes Redo Buffers 7168000 bytes Database mounted. Database opened. SQL> create spfile from pfile; 恢复spfile文件。 File created. (2)数据库关闭 ▲shutdown normal 执行后不允许任何新的连接再连接到数据库,耐心等待目前所有用户从数据库中退出才开始关闭数据库,关闭后,在下次启动是无需进行任何的恢复操作。(redo、undo)温柔的关闭方式 ▲shutdown immediate 最常用关闭方式,执行后立即中断当前正被处理的sql语句,系统不等待连接到数据库的所有用户退出系统,即强行rollback当前所有未提交活动事务,再断开所有连接用户。 若系统中存在一个很大的未提交事务,则关闭数据库需较长时间(rollback time) ▲shutdown abort 数据库用问题使用其他参数关闭数据库失败时,或需要立即关闭数据库时,可用abort强制关闭,所有正在运行的sql语句都将立即终止,且所有未提交的事务将不rollback,强行断开所有连接立即关闭系统。 下次启动时实例恢复可能需要最长的启动时间。 (3)操作系统自动起停数据库 ▲修改启动脚本bug vi $ORACLE_HOME/bin/dbstart ORACLE_HOME_LISTINER=$ORACLE_HOME (line 78) ▲修改允许脚本调用启停参数 vi /etc/oratab ora10:/u01/app/oracle/product/10.1.0/db_1:Y ▲测试数据库启停 dbstart dbshut ▲定制操作系统引导脚本(操作系统验证) #vi /etc/init.d/dbora #!/bin/bash ORA_HOME=/u01/app/oracle/product/10.2.0/db_1 ORA_OWNER=oracle LOG=$ORA_HOME/startup.log touch $LOG chmod a+r $LOG if [ ! -f $ORACLE_HOME/bin/dbstart ]; then echo "oracle startup: cannot start" fi case $1 in 'start') echo "$0:starting up" >> $LOG date >> $LOG if [ -f $ORA_HOME/bin/tnslsnr ]; then echo "starting oracle net listener" su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >> $LOG 2 > $1 fi echo "starting oracle databases" su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >> $LOG 2 > $1 ;; 'stop') echo "$0:shutting down" >> $LOG date >> $LOG if [ -f $ORA_HOME/bin/tnslsnr ]; then echo "starting oracle net listener" su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >> $LOG 2 > $1 fi echo "stopping oracle databases" fi echo "stopping oracle databases" su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >> $LOG 2 > $1 ;; *) echo "usage:$0 {start|stop}" exit ;; esac 测试: [root@station31 ~]# chmod a+x /etc/init.d/dbora [root@station31 ~]# /etc/rc.d/init.d/dbora start oracle startup: cannot start starting oracle net listener starting oracle databases [root@station31 ~]# /etc/rc.d/init.d/dbora stop oracle startup: cannot start starting oracle net listener stopping oracle databases [root@station31 ~]# ln -s /etc/init.d/dbora /etc/rc3.d/S99dbora [root@station31 ~]# ln -s /etc/init.d/dbora /etc/rc3.d/K01dbora [root@station31 ~]# ln -s /etc/init.d/dbora /etc/rc5.d/S99dbora [root@station31 ~]# ln -s /etc/init.d/dbora /etc/rc5.d/K01dbora 转载请保留固定链接: https://linuxeye.com/database/651.html |