配置靜態監聽解決ORA-12514錯誤的案例
今天做Linux下DG配置的時候,遇到一個現象,tnsname.ora文件配置都正常,tnsping也正常,監聽也正常,但是仍然報ORA-12514錯誤:
SQL> set lin 130 pages 130
SQL> select dest_id,error from v$archive_dest;
DEST_ID ERROR
---------- -----------------------------------------------------------------
1
2 ORA-12514: TNS:listener does not currently know of service
requested in connect descriptor
3
4
5
6
7
8
9
10
--查看主庫監聽
SQL> !lsnrctl status
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:31:46
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=prd)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date 08-OCT-2014 10:34:51
Uptime 0 days 1 hr. 56 min. 54 sec
Trace Level off
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
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=prd)(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 "prd" has 1 instance(s).
Instance "prd", status READY, has 1 handler(s) for this service...
Service "prdXDB" has 1 instance(s).
Instance "prd", status READY, has 1 handler(s) for this service...
Service "prd_XPT" has 1 instance(s).
Instance "prd", status READY, has 1 handler(s) for this service...
The command completed successfully
--tnsnames.ora文件內容
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
PRD =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = prd)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = prd)
)
)
STD =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = std)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = prd)
)
)
--主庫tnsping測試網絡服務名是否正常
SQL> !tnsping prd
TNS Ping Utility for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:32:35
Copyright (c) 1997, 2010, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = prd)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = prd)))
OK (10 msec)
SQL> !tnsping std
TNS Ping Utility for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:32:43
Copyright (c) 1997, 2010, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = std)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = prd)))
OK (20 msec)
--查看備庫監聽
[oracle@std ~]$ lsnrctl status
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:29:52
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=std)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date 08-OCT-2014 09:41:41
Uptime 0 days 2 hr. 48 min. 11 sec
Trace Level off
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
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=std)(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 "std" has 1 instance(s).
Instance "prd", status READY, has 1 handler(s) for this service...
Service "std_XPT" has 1 instance(s).
Instance "prd", status READY, has 1 handler(s) for this service...
The command completed successfully
--查看備庫遠程歸檔路徑
SQL> set lin 130 pages 130
SQL> col error for a20
SQL> select dest_id,error,status from v$archive_dest;
DEST_ID ERROR STATUS
---------- -------------------- ---------
1 VALID
2 VALID
3 INACTIVE
4 INACTIVE
5 INACTIVE
6 INACTIVE
7 INACTIVE
8 INACTIVE
9 INACTIVE
10 INACTIVE
11 VALID
--備庫tnsping測試網絡服務器名是否正常
SQL> !tnsping prd
TNS Ping Utility for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:39:40
Copyright (c) 1997, 2010, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = prd)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = prd)))
OK (20 msec)
SQL> !tnsping std
TNS Ping Utility for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:39:44
Copyright (c) 1997, 2010, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = std)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = prd)))
OK (10 msec)
tnsping測試下來也都是通的,這就比較奇怪了,但是ORA-12514錯誤很明顯是指監聽方面的問題,導致服務名無法解析,由於主備庫采用的是同一個實例名,因此兩邊的instance_name用的都是prd,乍一看好像很正常,但是解析確實出現了問題,那麼怎麼辦呢?
之前僅僅只是給服務器配置了一個動態監聽,內容如下:
--主庫監聽listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/network/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 = prd)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
--主庫監聽listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/network/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 = std)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
可以看到,區別僅僅是主機名不同而已,一個是prd,另一個是std,靜態監聽並未配置,即SID_LIST_LISTENER這一項裡面的欄目,那麼現在為主備庫都配置一個監聽。靜態監聽可以用netmgr配置,這裡為了方便,不再進入圖形界面執行該命令,而是直接通過修改listener.ora文件來達到目的,其效果是一樣的,在原來的listener.ora文件中的SID_LIST_LISTENER中添加如下內容(紅色部分):
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = prd)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(SID_NAME = prd)
)
(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 = std)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
注意,加上的內容中,SID_NAME,即instance_name,而GLOBAL_DBNAME,即tnsnames.ora中的SERVICE_NAME,由於tnsnames.ora中的SERVICE_NAME都是prd,因此這裡的兩個名字是一樣的,不會有什麼影響,把修改好的文件替換掉原文件,再重新加載監聽文件
SQL> !
[oracle@prd ~]$ lsnrctl reload
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:55:17
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=prd)(PORT=1521)))
The command completed successfully
[oracle@prd ~]$ lsnrctl status
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:55:24
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=prd)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date 08-OCT-2014 10:34:51
Uptime 0 days 2 hr. 20 min. 33 sec
Trace Level off
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
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=prd)(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 "prd" has 2 instance(s).
Instance "prd", status UNKNOWN, has 1 handler(s) for this service...
Instance "prd", status READY, has 1 handler(s) for this service...
Service "prdXDB" has 1 instance(s).
Instance "prd", status READY, has 1 handler(s) for this service...
Service "prd_XPT" has 1 instance(s).
Instance "prd", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@prd ~]$
注意,這個UNKNOW的prd實例對應的服務名prd就是剛才我們通過靜態監聽發現的服務名,同那樣地,備庫也重新加載監聽:
[oracle@std ~]$ lsnrctl reload
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:57:15
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=std)(PORT=1521)))
The command completed successfully
[oracle@std ~]$ lsnrctl status
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:57:25
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=std)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date 08-OCT-2014 09:41:41
Uptime 0 days 3 hr. 15 min. 44 sec
Trace Level off
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
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=std)(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 "prd" has 1 instance(s).
Instance "prd", status UNKNOWN, has 1 handler(s) for this service...
Service "std" has 1 instance(s).
Instance "prd", status READY, has 1 handler(s) for this service...
Service "std_XPT" has 1 instance(s).
Instance "prd", status READY, has 1 handler(s) for this service...
The command completed successfully
可以看到,此時備庫也多了一個UNKNOWN的,和實例名prd對應的服務prd
--再次查看主庫遠程歸檔路徑狀態
SQL> select dest_id,status,error from v$archive_dest_status;
DEST_ID STATUS ERROR
---------- --------- --------------------
1 VALID
2 VALID
3 INACTIVE
4 INACTIVE
5 INACTIVE
6 INACTIVE
7 INACTIVE
8 INACTIVE
9 INACTIVE
10 INACTIVE
原來dest_id=2的那個遠程歸檔路徑的ORA-12514的問題解決了,此時歸檔日志就可以通過網路遠程傳輸到備庫相應的歸檔路徑中了,再執行redo apply也不會有任何問題了。
總結:
這個案例是由於主備庫都采用了同一個實例名產生的問題,當我們只配置一個默認的動態監聽,會發現主庫無法監聽到遠程備庫的相應服務,通過靜態監聽手動添加上與實例名對應的服務,才能解決這個問題。使用靜態監聽的另一個好處是,當Oracle數據庫實例還沒有啟動的時候,就會先把對應的服務和實例名,通過靜態配置的監聽文件給啟動起來,而不是等啟動實例後由pmon進程再去啟動,這樣速度更快。不用再等待若干秒,我們的客戶端就可以通過靜態監聽立即臉上數據庫服務器了,也就是說,可以不依賴服務器進程,完成監聽的工作。