oracle 的2種訪問方式

 

動態註冊(Dynamic service Registration)

 

service_names =Global database name=db_name.db_domain

instance_name 默認是SID

修改spfileSID.ora文件方法如下:

先查看參數:

SQL> show parameter service

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
service_names                        string      guo

 

SQL> show parameter instance

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
active_instance_count                integer
cluster_database_instances           integer     1
instance_groups                      string
instance_name                        string      guo

 

增加這2個參數

SQL> alter system set service_names='guo' scope=spfile;

System altered.

 

SQL> alter system set instance_name='guo' scope=spfile;

System altered.

然後在strings spfileSID.ora。

 

動態註冊只需要在spfileSID.ora中註冊上上述的2個參數就可以直接連接到數據庫了。然後刪除掉$ORACLE_HOME/network/admin中的listener.ora文件。

先查看客戶端的tnsnames.ora中的信息

# tnsnames.ora Network Configuration File: E:\oracle\product\10.2.0\client_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

GUO =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.205)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = guo)
    )
  )

c:\>sqlplus hr/hr@guo

即可成功連接到數據庫。

查看監聽狀態如下:

[oracle@oral admin]$ lsnrctl status

LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 22-NOV-2011 03:02:34

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.205)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date                22-NOV-2011 02:21:12
Uptime                    0 days 0 hr. 41 min. 21 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Log File         /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=1521)))
Services Summary...
Service "guo" has 1 instance(s).
  Instance "guo", status READY, has 1 handler(s) for this service...
Service "guoXDB" has 1 instance(s).
  Instance "guo", status READY, has 1 handler(s) for this service...
Service "guo_XPT" has 1 instance(s).
  Instance "guo", status READY, has 1 handler(s) for this service...
The command completed successfully

 

 

靜態註冊(Static service Registration)

如果要使用Oracle Enterprise Manager (OEM)的話,就必須要使用靜態註冊(Static service configuration)

listener name     listener

Port                  1521

Protocols           TCP/IP

SID name          default instance

Host name         default host name

牛人可以記事本手工寫,本人只有netca或者Netmanager的方式來搞了。

在XWindows下,直接netca,直接Next到頭即可(但是也要看實際情況)。

netca只能簡單的配置下。

view listener.ora

# listener.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/n
etwork/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (PROGRAM = extproc)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.205)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
  )

通過 net manager可以配置更多參數。

直接netmgr。

其中 Global database name = db_name.db_domain

本人的參數如下:

show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      guo
db_unique_name                       string      guo
global_names                         boolean     FALSE
instance_name                        string      guo
lock_name_space                      string
log_file_name_convert                string
service_names                        string      guo
SQL> show parameter doma

SQL> show parameter doma

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_domain                            string

 

所以 我的Global database name就是 guo

通過net manager修改過後listener.ora如下

# listener.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/n
etwork/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (PROGRAM = extproc)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = guo)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (SID_NAME = guo)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.205)(PORT = 1521))
    )
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
  )

TRACE_LEVEL_LISTENER = USER

 

監聽如下:

[oracle@oral admin]$ lsnrctl start

LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 22-NOV-2011 03:02:52

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

Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 10.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Trace information written to /u01/app/oracle/product/10.2.0/db_1/network/trace/listener.trc
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.205)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.205)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date                22-NOV-2011 03:02:52
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               user
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listener Trace File       /u01/app/oracle/product/10.2.0/db_1/network/trace/listener.trc
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.205)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "guo" has 1 instance(s).
  Instance "guo", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

 

c:\>sqlplus hr/hr@guo

即可成功連接到數據庫。

 

用tail –f 可以查看實時日誌信息。

[oracle@oral admin]$ tail -f //u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listener completed notification to CRS on start

TIMESTAMP * CONNECT DATA [* PROTOCOL INFO] * EVENT [* SID] * RETURN CODE
WARNING: Subscription for node down event still pending
22-NOV-2011 03:02:52 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=oral)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=169869568)) * status * 0
WARNING: Subscription for node down event still pending
22-NOV-2011 03:07:06 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=oral)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=169869568)) * status * 0
WARNING: Subscription for node down event still pending
22-NOV-2011 03:22:00 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=oral)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=169869568)) * status * 0
22-NOV-2011 03:22:24 * (CONNECT_DATA=(SERVICE_NAME=guo)(CID=(PROGRAM=E:\oracle\product\10.2.0\client_1\bin\sqlplus.exe)(HOST=PC-201102141146)(USER=Administrator))) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.102)(PORT=2187)) * establish * guo * 0
22-NOV-2011 03:24:44 * (CONNECT_DATA=(SERVICE_NAME=guo)(CID=(PROGRAM=E:\oracle\product\10.2.0\client_1\bin\sqlplus.exe)(HOST=PC-201102141146)(USER=Administrator))) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.102)(PORT=2219)) * establish * guo * 0

我PC機名字 和IP 加粗顯示了。

 

lsnrctl 命令

lsnrctl start                         啓動默認的listener

lsnrctl start listener02         啓動listener.ora中新增的監聽

lsnrctl  stop

lsnrctl status 查看lsnrctl的現在狀態

lsnrctl > help

lsnrctl >reload 刷新

lsnrctl >trace

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章