[20180509]配置靜態監聽服務與ORA-12514

lfree發表於2018-05-09

[20180509]配置靜態監聽服務與ORA-12514錯誤.txt

--//昨天幫別人解決ORA-12514錯誤問題.主要靜態監聽服務名不正確,
--//我一般配置靜態監聽服務名與例項名一樣.而對方配置的服務名使用地點(比如南大樓,北大樓之類的名字),還真不習慣.
--//透過例子說明,有一些概念還是很容易混亂的.

1.環境:
SYS@book> @ ver1
PORT_STRING         VERSION    BANNER
------------------- ---------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

SYS@book> create pfile='/tmp/@.ora' from spfile;
File created.

--//修改/tmp/book.ora檔案:
*.service_names='BOOK'

$ cat  listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

#SUBSCRIBE_FOR_NODE_DOWN_EVENT_LISTENER=OFF

SID_LIST_LISTENER =
   (SID_LIST =
    (SID_DESC =
      (SDU=32767)
      (GLOBAL_DBNAME = book123)
      (ARGV0=myapp0)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/dbhome_1)
      (SID_NAME=book)
      )
    )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(ARGV0=LLLLLL)(HOST = 0.0.0.0)(PORT = 1521)(ARGV0=KKKKK))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
  )
)

SECURE_REGISTER_LISTENER = (TCP)
ADR_BASE_LISTENER = /u01/app/oracle
DIAG_ADR_ENABLED_LISTENER=OFF
USE_NS_PROBES_FOR_DCD=true
#logging_listener=off
#DYNAMIC_REGISTRATION_LISTENER = off
#local_os_authentication_LISTENER=off
INBOUND_CONNECT_TIMEOUT_LISTENER=10
#CONNECTION_RATE_LISTENER=5

--//注:監聽配置的靜態服務名為book123.監聽已經重啟.

$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 09-MAY-2018 11:20:56

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(ARGV0=LLLLLL)(HOST=0.0.0.0)(PORT=1521)(ARGV0=KKKKK)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                03-MAY-2018 16:44:12
Uptime                    5 days 18 hr. 36 min. 44 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "book" has 1 instance(s).
  Instance "book", status READY, has 2 handler(s) for this service...
Service "book123" has 1 instance(s).
  Instance "book", status UNKNOWN, has 1 handler(s) for this service...
Service "bookXDB" has 1 instance(s).
  Instance "book", status READY, has 1 handler(s) for this service...
The command completed successfully

SYS@book> shutdown immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.

$ lsnrctl status
...
Services Summary...
Service "book123" has 1 instance(s).
  Instance "book", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
--//你可以Service book,bookXDB已經不存在的,因為資料庫已經關閉,僅僅剩下靜態監聽服務名.
--//這也是為什麼status UNKNOWN的原因,因為這個例項可以不存在.正是存在這樣的服務,你可以在
--//資料庫沒有啟動的情況下遠端連線例項,啟動資料庫例項.
R:\>sqlplus  sys/oracle@192.168.100.78:1521/book123 as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Wed May 9 11:26:39 2018
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to an idle instance.
SYS@192.168.100.78:1521/book123>

--//把/tmp/book.ora複製到本地的R盤.
SYS@192.168.100.78:1521/book123> startup pfile=r:/book.ora
ORACLE instance started.
Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes
Database mounted.
Database opened.

$ lsnrctl status
...
Services Summary...
Service "book" has 1 instance(s).
  Instance "book", status READY, has 2 handler(s) for this service...
Service "book123" has 1 instance(s).
  Instance "book", status UNKNOWN, has 1 handler(s) for this service...
Service "bookXDB" has 1 instance(s).
  Instance "book", status READY, has 1 handler(s) for this service...
The command completed successfully
--//這樣可以發現2個服務book,bookXDB. 注意status READY,表示動態註冊.

R:\>sqlplus -l scott/book@192.168.100.78:1521/Book123
SQL*Plus: Release 12.1.0.1.0 Production on Wed May 9 11:38:22 2018
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SCOTT@192.168.100.78:1521/Book123>
--//可以發現使用服務名book123 ok.(注:我故意大小寫混用).如果使用一個不存在的服務名如下:

R:\>sqlplus -l scott/book@192.168.100.78:1521/bookshare
SQL*Plus: Release 12.1.0.1.0 Production on Wed May 9 11:02:58 2018
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
SP2-0751: Unable to connect to Oracle.  Exiting SQL*Plus

--//對方的錯誤就是在這裡,服務名拼寫錯誤!!
--//可以發現如果要使用bookshare,2種方式,一種配置靜態監聽,一種方式寫入資料庫引數檔案加入對應的服務名.
--//配置靜態監聽必須修改引數*.service_names='BOOK','BOOKSHARE'.

SYS@book> alter system set service_names='book','bookshare' scope=memory;
System altered.

SYS@book> show  parameter service_names
NAME          TYPE   VALUE
------------- ------ ---------------
service_names string book, bookshare

--//注意我服務名使用引號,這樣建立的是小寫的服務名.如果alter system set service_names=book,bookshare scope=memory;
--//建立的就是大寫的服務名.不過好像在具體執行時不區分大小寫.

$ lsnrctl status | grep -A20 "^Services Summary."
Services Summary...
Service "BOOKSHARE" has 1 instance(s).
  Instance "book", status READY, has 1 handler(s) for this service...
Service "book" has 1 instance(s).
  Instance "book", status READY, has 2 handler(s) for this service...
Service "book123" has 1 instance(s).
  Instance "book", status UNKNOWN, has 1 handler(s) for this service...
Service "bookXDB" has 1 instance(s).
  Instance "book", status READY, has 1 handler(s) for this service...
The command completed successfully

--//oracle有時候很奇怪,這裡看到的Service BOOKSHARE(大寫!!)

--//補充測試:
--//修改/tmp/book.ora檔案:
*.service_names='BOOK','bookshare'

SYS@book> shutdown immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@book> startup pfile=/tmp/book.ora
ORACLE instance started.

Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes
Database mounted.
Database opened.

SYS@book> show  parameter service_names
NAME          TYPE   VALUE
------------- ------ ---------------
service_names string BOOK, bookshare

$ lsnrctl status | grep -A20 "^Services Summary."
Services Summary...
Service "book" has 1 instance(s).
  Instance "book", status READY, has 2 handler(s) for this service...
Service "book123" has 1 instance(s).
  Instance "book", status UNKNOWN, has 1 handler(s) for this service...
Service "bookXDB" has 1 instance(s).
  Instance "book", status READY, has 1 handler(s) for this service...
Service "bookshare" has 1 instance(s).
  Instance "book", status READY, has 1 handler(s) for this service...
The command completed successfully
--//這樣配置bookshare是小寫.

R:\>sqlplus -l scott/book@192.168.100.78:1521/BookShare
SQL*Plus: Release 12.1.0.1.0 Production on Wed May 9 11:45:08 2018
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SCOTT@192.168.100.78:1521/BookShare>

--//好在服務名不區分大小寫,問題不大.

--//修改監聽配置檔案listener.ora
SID_LIST_LISTENER =
   (SID_LIST =
    (SID_DESC =
      (SDU=32767)
      (GLOBAL_DBNAME = booK123)
      (ARGV0=myapp0)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/dbhome_1)
      (SID_NAME=book)
      )
    )

$ lsnrctl stop;lsnrctl start

SYS@book> alter system register;
System altered.

$ lsnrctl status | grep -A20 "^Services Summary."
Services Summary...
Service "booK123" has 1 instance(s).
  Instance "book", status UNKNOWN, has 1 handler(s) for this service...
Service "book" has 1 instance(s).
  Instance "book", status READY, has 2 handler(s) for this service...
Service "bookXDB" has 1 instance(s).
  Instance "book", status READY, has 1 handler(s) for this service...
Service "bookshare" has 1 instance(s).
  Instance "book", status READY, has 1 handler(s) for this service...
The command completed successfully

R:\>sqlplus -l scott/book@192.168.100.78:1521/Book123
SQL*Plus: Release 12.1.0.1.0 Production on Wed May 9 11:49:20 2018
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SCOTT@192.168.100.78:1521/Book123>

--//亂..

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2154220/,如需轉載,請註明出處,否則將追究法律責任。

相關文章