oracle学习笔记 Oracle数据库及相关软件的启动和关闭 第一部分

来源:互联网 发布:绝世唐门升坐骑数据 编辑:程序博客网 时间:2024/03/29 05:39
oracle学习笔记

Oracle数据库及相关软件的启动和关闭

第一部分 手动启动和关闭及其指令

总共四个软件oracle数据库、数据库监听、Enterprise Manager、iSQL*Plus,
运行时它们之间存在依存关系:em和isqlplus通过监听访问数据库。

关闭的顺序:em和isqlplus先关闭这两个没有顺序,再关监听,然后关闭数据库。

启动顺序:先启动监听,再启动oracle,然后启动em和isqlplus.

一)关闭方法
1、关闭isqlplus
先查看一下它的端口状态:
[oracle@redhat4 ~]$ netstat -tulnp|grep 5560
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:5560                0.0.0.0:*                   LISTEN      11543/java

可看出端口打开,程序正在运行
关闭它:
[oracle@redhat4 ~]$ isqlplusctl stop
iSQL*Plus 10.2.0.1.0
Copyright (c) 2003, 2005, Oracle.  All rights reserved.
Stopping iSQL*Plus ...
iSQL*Plus stopped.

再次查看它的端口:
[oracle@redhat4 ~]$ netstat -tulnp | grep 5560
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
端口5560没有开启,说明isqlplus已经关闭。
如果不知道一个命令怎么用,输入命令后直接回车,会显示出它的用法,
linux也有专门的帮助指令可协助查询指令用法。

2、关闭em
查看em状态
[oracle@redhat4 ~]$ emctl status dbconsole
TZ set to PRC
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation.  All rights reserved.
http://redhat4:1158/em/console/aboutApplication
Oracle Enterprise Manager 10g is running.
------------------------------------------------------------------
Logs are generated in directory /u01/app/oracle/product/10.2.0/db_1/redhat4_jiagulun/sysman/log

也可以查看它使用的端口是否活动:
[oracle@redhat4 ~]$ netstat -tulnp | grep 1158
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:1158                0.0.0.0:*                   LISTEN      28633/java

关闭em:
[oracle@redhat4 ~]$ emctl stop dbconsole
TZ set to PRC
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation.  All rights reserved.
http://redhat4:1158/em/console/aboutApplication
Stopping Oracle Enterprise Manager 10g Database Control ...
 ...  Stopped.

再查看em使用的端口已经不活动了。

3、关闭监听
[oracle@redhat4 ~]$ lsnrctl stop


LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 29-APR-2016 06:23:47


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


Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=redhat4)(PORT=1521)))
The command completed successfully

再查看它的端口
[oracle@redhat4 ~]$ netstat -tulnp | grep 1521
已经没有了

4、关闭数据库

先进入sqlplus
[oracle@redhat4 ~]$ sqlplus / as sysdba

关闭数据库
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
关闭成功,可以看到它进行了不少的操作。

再查看一下进程
[oracle@redhat4 ~]$ ps -ef|grep ora
结果中和oracle相关的进程已经没有了。



二)启动方法

1、启动监听
[oracle@redhat4 ~]$ lsnrctl start

因为数据库未打开,这时监听状态中没有jiagulun 服务。

2、启动数据库
先进入sqlplus
[oracle@redhat4 ~]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.1.0 - Production on Fri Apr 29 06:30:13 2016


Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to an idle instance.
没有库打开,sqlplus连接到一个空闲实例。

启动数据库
SQL> startup
ORACLE instance started.


Total System Global Area  285212672 bytes
Fixed Size                  1218968 bytes
Variable Size              88082024 bytes
Database Buffers          188743680 bytes
Redo Buffers                7168000 bytes
Database mounted.
Database opened.
结果中Database opened.说明数据库已经打开了。

查看一下数据库的状态
SQL> select status from V$instance;


STATUS
------------
OPEN
数据库状态为OPEN,已完全打开了。

这时再看一下监听的状态
[oracle@redhat4 ~]$ lsnrctl status
会发现服务jiagulun 已经READY.

3、启动isqlplus 

[oracle@redhat4 ~]$ isqlplusctl start
iSQL*Plus 10.2.0.1.0
Copyright (c) 2003, 2005, Oracle.  All rights reserved.
Starting iSQL*Plus ...
iSQL*Plus started.

查看一下端口
[oracle@redhat4 ~]$ netstat -tulnp|grep 5560
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:5560                0.0.0.0:*                   LISTEN      30743/java
有5560端口,说明isqlplus已经工作。

这时在windows中使用ie访问
http://192.168.3.47:5560/isqlplus/
有网页结果,并且可以登录成功。

4、启动em
补充知识点:
em一旦建立以后,Linux服务器的主机名字就不要改变。
如果改变了,em服务就无法启动了。
因为em的创建时使用了主机名,运行时也依赖主机名。
若非要改变主机名,又要使用em,就必需在新主机名状态下重建em。

启动em

[oracle@redhat4 ~]$ emctl start dbconsole
TZ set to PRC
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation.  All rights reserved.
http://redhat4:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 10g Database Control ................................... started.
------------------------------------------------------------------
Logs are generated in directory /u01/app/oracle/product/10.2.0/db_1/redhat4_jiagulun/sysman/log

从结果看,它的启动过程,是这几个里面时间最长的一个了。

[oracle@redhat4 ~]$ netstat -tulnp|grep 1158
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:1158                0.0.0.0:*                   LISTEN      31747/java
端口已经在工作。

用ie访问一下:
http://192.168.3.47:1158/em
有网页,并且可登录。说明启动成功。

实际上这四个程序,启动顺序如何,都是能运行的,
只是按老师说的顺序,启动后已经连接正常了,不用考虑缓存问题和等待他们之间的连接正常。


三)纠正一个错误
1、说明
课程中老师在ie中启动em控制台,控制台出现了
java.lang.Exception: IOException in sending Request :: Connection refused
错误
这是一个经典错误,就是这个错误发生的几率很大。
它是由时区设置引起的。

学习环境中,linux系统有时区设置,em也有它的设置,当两个设置不一致时,就会发生错误。

经过测试我的环境中系统的时区值和em的时区值不一致em无法启动。但没能模拟出上面老师讲的错误。
网上找到了一些这种案例出现上述错误,修改em时区后,都恢复了正常。

下面讲一下如何修改时区:

这里修改的是时区值,并不是指城市名一致,而是两个时区的值在同一时区即可。
如Asia/Urumqi(乌鲁木齐)PRC(中华人名共和国)Asia/Shanghai(上海)Asia/Taipei(台北)Singapore(新加坡)Australia/West(西澳大利亚)Etc/GMT-8(格林威治时间减8小时)
这些名称都是在东8区,它们的时区值是相等的。

这里要用到系统时区和em时区

系统时区值是linux redhat系统中的设置,环境变量TZ的值优先,文件/etc/localtime次之,
系统中 系统设置-》日期和时间 中 时区 设置也可改变时区值,结果实际是替换localtime文件。

em的时区值存在oracle软件目录em.properties文件的agentTZRegion字段中。

两个时区值不一样在执行
emctl start dbconsole
会提示时区不一致,无法启动。

文件
/u01/app/oracle/product/10.2.0/db_1/sysman/admin/supportedtzs.lst
内有世界中主要城市所在时区的信息。

文件
/u01/app/oracle/product/10.2.0/db_1/redhat4_jiagulun/sysman/config/emd.properties
的最后一行
agentTZRegion=PRC
是em的时区值。

这两个文件路径中
/u01/app/oracle/product/10.2.0/db_1 是$ORACLE_HOME环境变量的值
redhat4_jiagulun是 主机名_数据库实例名
根据用户的环境不同和安装时设置的不同,会有区别。

2、具体方法
修改em的时区时要先停止控制台:
emctl stop dbconsole

然后:
第一种方法:
emctl resetTZ agent
按系统时区的值 设置emd.properties文件中的agentTZRegion字段。使系统和em的时区一致。

resetTZ执行完后,emd.properties文件修改完成

出现下面提示:
To complete this process, you must either:


connect to the database served by this DBConsole as user 'sysman', and execute:


SQL> exec mgmt_target.set_agent_tzrgn('redhat4:3938','PRC')


                        -- or --


connect to the database served by this DBConsole as user 'sys', and execute:


SQL> alter session set current_schema = SYSMAN;
SQL> exec mgmt_target.set_agent_tzrgn('redhat4:3938','PRC')

说明你还要进一步执行一个SQL语句,
以SYSMAN身份运行
exec mgmt_target.set_agent_tzrgn('redhat4:3938','PRC'),
目的使时区的更改在库中生效。
执行后修改完成。

第二种方法:
也可以直接手动修改emd.properties文件agentTZRegion,这样也可修改em的时区。
em启动只用到这个字段,不用改库。
但要时区在库中正常还是需要执行上面exec命令的。

修改完成后启动控制台
emctl start dbconsole

时区修改完成。



四)总结各软件启动和关闭的方法

1、监听
启动
lsnrctl start
关闭
lsnrctl stop
查看状态:
lsnrctl status

2、数据库
启动关闭都要先进入sqlplus
[oracle@redhat4 ~]$ sqlplus / as sysdba
启动关闭数据库,有多种方法,这里先讲一种安全关闭和一种全面启动的方法,其它方法以后会详细讲
启动
SQL> startup
关闭:
SQL> shutdown immediate
查看数据库的状态:
SQL> select status from V$instance;

3、em
开启
emctl start dbconsole
关闭
emctl stop dbconsole
查看状态:
emctl status dbconsole

4、isqlplus
开启
isqlplusctl start
关闭
isqlplusctl stop


以上是数据库、监听程序、企业管理器、iSQL*Plus的手动启动关闭方法。
0 0
原创粉丝点击