首页 > 代码库 > Oracle 最简单的随系统自动启动

Oracle 最简单的随系统自动启动

Oracle 最简单的随系统自动启动


       俗话说用户是上帝,他们有时候提出一个问题非常的简单,就只需要一句话,一分钟就完事了,但是拿到我们DBA来说,可能至少得半个小时甚至半个月才能满足他的一句话,有没有更好更快的办法呢,我告诉大家这是有的;
       我就拿一个例子来说,用户通常都会为了维护简单,需要数据库自动随系统启动,一句非常简单的话,但是拿给DBA来说至少得多花半个小时的时间来配置实现这个功能。那么今天你看完这篇文档之后,可以在他的话还没有说完就可以完成自启动的配置,非常简单。


一、配置自动
1、添加启动项
[root@db01 ~]# cat >> /etc/rc.d/rc.local <<EOF

su - oracle -c "lsnrctl start"
su - oracle -c "sqlplus sys/oracle as sysdba @/home/oracle/.script/.startup"
su - oracle -c "emctl start dbconsole"
EOF

2、创建并编辑启动文件
[root@db01 ~]#su - oracle
[root@db01 ~]#mkdir -p /home/oracle/.script/

[root@db01 ~]# cat > /home/oracle/.script/.startup <<EOF
startup;
alter system register;
exit 0
EOF

二、重启验证:




三、确定数据库和EM以及监听是否都已经起来
###监听状态
[oracle@db01 ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 03-OCT-2014 07:26:22

Copyright (c) 1991, 2011, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                03-OCT-2014 07:13:54
Uptime                    0 days 0 hr. 12 min. 28 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /DBSoft/Product/11.2.3/db_1/network/admin/listener.ora
Listener Log File         /DBSoft/diag/tnslsnr/db01/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db01)(PORT=1521)))
Services Summary...
Service "woo" has 1 instance(s).
  Instance "woo", status READY, has 1 handler(s) for this service...
Service "wooXDB" has 1 instance(s).
  Instance "woo", status READY, has 1 handler(s) for this service...
The command completed successfully


###数据库状态
SQL> select instance_name,host_name,status from v$instance;

INSTANCE_N HOST_NAME  STATUS
---------- ---------- ------------
woo        db01       OPEN


###EM状态
[oracle@db01 ~]$ emctl status dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.3.0 
Copyright (c) 1996, 2011 Oracle Corporation.  All rights reserved.
https://db01:1158/em/console/aboutApplication
Oracle Enterprise Manager 11g is running. 
------------------------------------------------------------------
Logs are generated in directory /DBSoft/Product/11.2.3/db_1/db01_woo/sysman/log 

至此我们已经确定,这样也可以将数据库配置为自动启动,且比Oralce推荐的老方法更为简单,老方法见如下链接:

Linux 下 Oracle随系统自动启动和关闭(老方法)

Oracle 最简单的随系统自动启动