天天看點

oracle學習筆記 Oracle資料庫及相關軟體的啟動和關閉 第一部分

oracle學習筆記

Oracle資料庫及相關軟體的啟動和關閉

第一部分 手動啟動和關閉及其指令

總共四個軟體oracle資料庫、資料庫監聽、Enterprise Manager、iSQL*Plus,

運作時它們之間存在依存關系:em和isqlplus通過監聽通路資料庫。

關閉的順序:em和isqlplus先關閉這兩個沒有順序,再關監聽,然後關閉資料庫。

啟動順序:先啟動監聽,再啟動oracle,然後啟動em和isqlplus.

一)關閉方法

1、關閉isqlplus

先檢視一下它的端口狀态:

[[email protected] ~]$ 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

可看出端口打開,程式正在運作

關閉它:

[[email protected] ~]$ isqlplusctl stop

iSQL*Plus 10.2.0.1.0

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

Stopping iSQL*Plus ...

iSQL*Plus stopped.

再次檢視它的端口:

[[email protected] ~]$ 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狀态

[[email protected] ~]$ 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

也可以檢視它使用的端口是否活動:

[[email protected] ~]$ 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:

[[email protected] ~]$ 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、關閉監聽

[[email protected] ~]$ 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

再檢視它的端口

[[email protected] ~]$ netstat -tulnp | grep 1521

已經沒有了

4、關閉資料庫

先進入sqlplus

[[email protected] ~]$ sqlplus / as sysdba

關閉資料庫

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

關閉成功,可以看到它進行了不少的操作。

再檢視一下程序

[[email protected] ~]$ ps -ef|grep ora

結果中和oracle相關的程序已經沒有了。

二)啟動方法

1、啟動監聽

[[email protected] ~]$ lsnrctl start

因為資料庫未打開,這時監聽狀态中沒有jiagulun 服務。

2、啟動資料庫

先進入sqlplus

[[email protected] ~]$ 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,已完全打開了。

這時再看一下監聽的狀态

[[email protected] ~]$ lsnrctl status

會發現服務jiagulun 已經READY.

3、啟動isqlplus 

[[email protected] ~]$ isqlplusctl start

iSQL*Plus 10.2.0.1.0

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

Starting iSQL*Plus ...

iSQL*Plus started.

檢視一下端口

[[email protected] ~]$ 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

[[email protected] ~]$ 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

從結果看,它的啟動過程,是這幾個裡面時間最長的一個了。

[[email protected] ~]$ 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

[[email protected] ~]$ 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的手動啟動關閉方法。