listener.ora,tnsnames.ora中一个空格的威力
最近几天被网络监听配置搞得焦头烂额,有时候配置没问题,有时候就出莫名其妙的问题,今天专门花时间总结了一下,希望对大家有所帮助。
listener.ora,tnsnames.ora有时候没有netca,netmgr这样的图形工具来创建的时候,只能手工来做,手工做的时候会有一些格式的问题,多加一个空格,或者少一个空格,就会有不同的结果。
案例一
下面是一个监听的基本配置,我故意在前面多加了一个空格(黄色标记所示)。
LISTE1=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=oel1.oracle.com)(PORT=1521)
)
)
)
SID_LIST_LISTE1=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=PROD)
(ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)
(SID_NAME=PROD)
)
)
启动的时候非常缓慢,然后报出了没有监听liste1的信息。这种情况跟没有listener.ora的情况下直接起监听的结果一样,说明解析Listener.ora的时候,没有找到相关的listener信息。
LSNRCTL> start liste1
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/liste1.log
TNS-01151: Missing listener name, liste1, in LISTENER.ORA
Listener failed to start. See the error message(s) above...
然后删除那个空格后,监听启动就没有问题。
案例二
在倒数第2行的右括号,一个是顶格的,一个前面有一个空格。
LISTE1=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=oel1.oracle.com)(PORT=1521))
)
)
SID_LIST_LISTE1=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=PROD)
(ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)
(SID_NAME=PROD)
)
)
启动监听的时候,报出了另外的错误,说sid_list_liste1的地方有问题。错误信息如下:
LSNRCTL> start liste1
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/liste1.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oel1.oracle.com)(PORT=1521)))
TNS-01155: Incorrectly specified SID_LIST_liste1 parameter in LISTENER.ORA
NL-00303: syntax error in NV string
Listener failed to start. See the error message(s) above...
如果改成如下的形式,多加了一个空格,监听启动就没有问题了。
LISTE1=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=oel1.oracle.com)(PORT=1521))
)
)
SID_LIST_LISTE1=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=PROD)
(ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)
(SID_NAME=PROD)
)
)
案例三
有的朋友可能说你这个钻牛角尖了,如果是倒数第三行,第四行的话行不行?
LISTE1=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=oel1.oracle.com)(PORT=1521)
)
)
)
启动监听的时候还是报错,这次貌似指向的错误信息更明确了。
LSNRCTL> start liste1
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/liste1.log
TNS-01150: The address of the specified listener name is incorrect
Listener failed to start. See the error message(s) above...
LISTE1=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=oel1.oracle.com)(PORT=1521)
)
)
)
案例四
PROD=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=oel1.oracle.com)(PORT=1521))
(ADDRESS=(PROTOCOL=tcp)(HOST=oel1.oracle.com)(PORT=1525))
(CONNECT_DATA=(SERVICE_NAME=PROD)
)
)
[oracle@oel1 admin]$ sqlplus system/oracle@PROD
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Dec 1 16:55:03 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
案例五
多加一个空格,报错也是ora-12154PROD=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=oel1.oracle.com)(PORT=1521))
(ADDRESS=(PROTOCOL=tcp)(HOST=oel1.oracle.com)(PORT=1525))
(CONNECT_DATA=(SERVICE_NAME=PROD))
)
[oracle@oel1 admin]$ sqlplus system/oracle@PROD
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Dec 1 17:28:47 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
成功例子
最后贴出能够正确识别的Listener.ora和tnsnames.ora (格式当然不是很好)listener.ora
LISTE1=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=oel1.oracle.com)(PORT=1521)
)
)
)
SID_LIST_LISTE1=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=PROD)
(ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)
(SID_NAME=PROD)
)
)
tnsnames.ora
PROD=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=oel1.oracle.com)(PORT=1521))
(ADDRESS=(PROTOCOL=tcp)(HOST=oel1.oracle.com)(PORT=1525))
(CONNECT_DATA=(SERVICE_NAME=PROD))
)
[oracle@oel1 admin]$ sqlplus system/oracle@PROD
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Dec 1 17:00:46 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options