Oracle监听出现的问题总结,以及解决办法

  1. ORA-12541: TNS: 无监听程序
C:\Users\Administrator>sqlplus sys/cape@orcl as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on 星期六 218 12:55:46 2017
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
ERROR:
ORA-12541: TNS: 无监听程序
请输入用户名:

出现该问题是当前的监听服务没有启动:

C:\Users\Administrator>lsnrctl status
LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Production on 18-2月 -2017 12:59:11
Copyright (c) 1991, 2010, Oracle.  All rights reserved.
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
TNS-12541: TNS: 无监听程序
 TNS-12560: TNS: 协议适配器错误
  TNS-00511: 无监听程序
   64-bit Windows Error: 2: No such file or directory
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
TNS-12541: TNS: 无监听程序
 TNS-12560: TNS: 协议适配器错误
  TNS-00511: 无监听程序
   64-bit Windows Error: 61: Unknown error

启动监听后:

C:\Users\Administrator>lsnrctl start

LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Production on 18-2月 -2017 13:00:45

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

启动tnslsnr: 请稍候...

TNSLSNR for 64-bit Windows: Version 11.2.0.1.0 - Production
系统参数文件为C:\app\Dyj\product\11.2.0\dbhome_1\network\admin\listener.ora
写入c:\app\dyj\diag\tnslsnr\dongyj\listener\alert\log.xml的日志信息
监听: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
监听: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))

正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
LISTENER 的 STATUS
------------------------
别名                      LISTENER
版本                      TNSLSNR for 64-bit Windows: Version 11.2.0.1.0 - Production
启动日期                  18-2月 -2017 13:00:50
正常运行时间              0 天 0 小时 0 分 5 秒
跟踪级别                  off
安全性                    ON: Local OS Authentication
SNMP                      OFF
监听程序参数文件          C:\app\Dyj\product\11.2.0\dbhome_1\network\admin\listener.ora
监听程序日志文件          c:\app\dyj\diag\tnslsnr\dongyj\listener\alert\log.xml
监听端点概要...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
服务摘要..
服务 "CLRExtProc" 包含 1 个实例。
  实例 "CLRExtProc", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
命令执行成功

这里需要注意,此处的监听没有监听实例ORCL是因为监听晚于实例启动,没有把实例注册到监听中,Oracle的PMON进程每隔1分钟(60S)就会重新扫描实例,将实例注册到监听中,参考如下【Database SQL Language Reference】,
如果需要马上将实例注册到监听中,需要使用语句:
alter system register

Specify REGISTER to instruct the PMON background process to register the instance with the listeners immediately. If you do not specify this clause, then registration of the instance does not occur until the next time PMON executes the discovery routine. As a result, clients may not be able to access the services for as long as 60 seconds after the listener is started.

使用alter system register或者一分钟过后

C:\Users\Administrator>lsnrctl status

LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Production on 18-2月 -2017 13:08:39

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

正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
LISTENER 的 STATUS
------------------------
别名                      LISTENER
版本                      TNSLSNR for 64-bit Windows: Version 11.2.0.1.0 - Production
启动日期                  18-2月 -2017 13:00:50
正常运行时间              00 小时 752 秒
跟踪级别                  off
安全性                    ON: Local OS Authentication
SNMP                      OFF
监听程序参数文件          C:\app\Dyj\product\11.2.0\dbhome_1\network\admin\listener.ora
监听程序日志文件          c:\app\dyj\diag\tnslsnr\dongyj\listener\alert\log.xml
监听端点概要...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
服务摘要..
服务 "CLRExtProc" 包含 1 个实例。
  实例 "CLRExtProc", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
服务 "orcl" 包含 1 个实例。
  实例 "orcl", 状态 READY, 包含此服务的 1 个处理程序...
服务 "orclXDB" 包含 1 个实例。
  实例 "orcl", 状态 READY, 包含此服务的 1 个处理程序...
命令执行成功

此时,重新连接数据库,数据库连接成功:


C:\Users\Administrator>sqlplus sys/cape@orcl as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 星期六 218 13:10:16 2017

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

在windows,也可以通过在服务中,启动监听,而不需要通过命令重新启动;
这里写图片描述
2. ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
先检查监听的监控状况:

C:\Users\Administrator>lsnrctl status

LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Production on 18-2月 -2017 13:21:36

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

正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
LISTENER 的 STATUS
------------------------
别名                      LISTENER
版本                      TNSLSNR for 64-bit Windows: Version 11.2.0.1.0 - Production
启动日期                  18-2月 -2017 13:14:41
正常运行时间              00 小时 658 秒
跟踪级别                  off
安全性                    ON: Local OS Authentication
SNMP                      OFF
监听程序参数文件          C:\app\Dyj\product\11.2.0\dbhome_1\network\admin\listener.ora
监听程序日志文件          c:\app\dyj\diag\tnslsnr\dongyj\listener\alert\log.xml
监听端点概要...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
服务摘要..
服务 "CLRExtProc" 包含 1 个实例。
  实例 "CLRExtProc", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
命令执行成功

查看服务窗口下的实例服务是否启动:
这里写图片描述
启动后,检查监听:

C:\Users\Administrator>lsnrctl status

LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Production on 18-2月 -2017 13:32:06

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

正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
LISTENER 的 STATUS
------------------------
别名                      LISTENER
版本                      TNSLSNR for 64-bit Windows: Version 11.2.0.1.0 - Production
启动日期                  18-2月 -2017 13:14:41
正常运行时间              00 小时 1728 秒
跟踪级别                  off
安全性                    ON: Local OS Authentication
SNMP                      OFF
监听程序参数文件          C:\app\Dyj\product\11.2.0\dbhome_1\network\admin\listener.ora
监听程序日志文件          c:\app\dyj\diag\tnslsnr\dongyj\listener\alert\log.xml
监听端点概要...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
服务摘要..
服务 "CLRExtProc" 包含 1 个实例。
  实例 "CLRExtProc", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
服务 "orcl" 包含 1 个实例。
  实例 "orcl", 状态 READY, 包含此服务的 1 个处理程序...
服务 "orclXDB" 包含 1 个实例。
  实例 "orcl", 状态 READY, 包含此服务的 1 个处理程序...
命令执行成功

数据库可以正常连接

C:\Users\Administrator>sqlplus sys/cape@orcl as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 星期六 218 13:32:44 2017

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> quit

还有一种情况是在tnsnames.ora里面配置的service_name不存在,如下:

ORCL1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl1)
    )
  )

其中SERVICE_NAME=orcl1,在数据库中就不存在orcl1的服务名

数据库的服务名,维护在参数文件中,默认和数据库的实例名一直,如下:
这里写图片描述

所以,在tnsnames.ora文件中配置的SERVICE_NAME必须能在参数中可以查到,配置文件维护的service_names参数可以设置为多个名称,用,分隔开即可,如上图,重新修改了该参数值,包含了orcl的值,则数据库可以正常的连接成功。
3.ORA-12560: TNS: 协议适配器错误

C:\Users\Administrator>sqlplus sys/cape as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 星期六 218 13:27:40 2017

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

ERROR:
ORA-12560: TNS: 协议适配器错误

请输入用户名:

请注意上方的数据库连接方式:

sqlplus sys/cape as sysdba(在cape单词后面没有@orcl连接符),此时是不需要请求监听文件的,遇到该问题,则是因为数据库实例没有启动,导致无法连接数据库
下面是加了@orcl连接符的情况

C:\Users\Administrator>sqlplus sys/cape@orcl as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 星期六 218 13:30:42 2017

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

ERROR:
ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务

请输入用户名:

查看监听,该实例也未监控;

C:\Users\Administrator>lsnrctl status

LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Production on 18-2月 -2017 13:31:25

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

正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
LISTENER 的 STATUS
------------------------
别名                      LISTENER
版本                      TNSLSNR for 64-bit Windows: Version 11.2.0.1.0 - Production
启动日期                  18-2月 -2017 13:14:41
正常运行时间              00 小时 1647 秒
跟踪级别                  off
安全性                    ON: Local OS Authentication
SNMP                      OFF
监听程序参数文件          C:\app\Dyj\product\11.2.0\dbhome_1\network\admin\listener.ora
监听程序日志文件          c:\app\dyj\diag\tnslsnr\dongyj\listener\alert\log.xml
监听端点概要...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
服务摘要..
服务 "CLRExtProc" 包含 1 个实例。
  实例 "CLRExtProc", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
命令执行成功

重启启动实例后,监听监控到了实例

C:\Users\Administrator>lsnrctl status

LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Production on 18-2月 -2017 13:32:06

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

正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
LISTENER 的 STATUS
------------------------
别名                      LISTENER
版本                      TNSLSNR for 64-bit Windows: Version 11.2.0.1.0 - Production
启动日期                  18-2月 -2017 13:14:41
正常运行时间              00 小时 1728 秒
跟踪级别                  off
安全性                    ON: Local OS Authentication
SNMP                      OFF
监听程序参数文件          C:\app\Dyj\product\11.2.0\dbhome_1\network\admin\listener.ora
监听程序日志文件          c:\app\dyj\diag\tnslsnr\dongyj\listener\alert\log.xml
监听端点概要...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
服务摘要..
服务 "CLRExtProc" 包含 1 个实例。
  实例 "CLRExtProc", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
服务 "orcl" 包含 1 个实例。
  实例 "orcl", 状态 READY, 包含此服务的 1 个处理程序...
服务 "orclXDB" 包含 1 个实例。
  实例 "orcl", 状态 READY, 包含此服务的 1 个处理程序...
命令执行成功

这里写图片描述

总结:
1、如果需要使用动态注册,让动态监听快速的监听实例(否则需要一分钟),可以通过执行语句【alter system register】(动态注册只能使用1521端口,因为动态注册实际上是由PMON进程来完成),手工加速实例监听过程
2、数据库连接过程中:如下:

 a.sqlplus / as sysdba 这是典型的操作系统认证,不需要listener进程    
 b.sqlplus sys/oracle 这种连接方式只能连接本机数据库,同样不需要listener进程 
 c.sqlplus sys/oracle@orcl 这种方式需要listener进程处于可用状态。最普遍的通过网络连接。 

针对上面描述的a和b场景,监听不启动也可以正常的连接数据库,并操作数据库
3、如何查看监听程序是否可以正常的通信,使用tnsping命令:
这里写图片描述


C:\Users\Administrator>tnsping orcl 3

TNS Ping Utility for 64-bit Windows: Version 11.2.0.1.0 - Production on 18-2月 -2017 16:01:59

Copyright (c) 1997, 2010, Oracle.  All rights reserved.

已使用的参数文件:
C:\app\Dyj\product\11.2.0\dbhome_1\network\admin\sqlnet.ora

已使用 TNSNAMES 适配器来解析别名
尝试连接 (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
OK (0 毫秒)
OK (0 毫秒)
OK (20 毫秒)

此处的orcl为tnsnames.ora文件中配置的:
这里写图片描述
如果监听是停止的,则tnsping orcl 3会提示无监听程序;

C:\Users\Administrator>lsnrctl stop

LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Production on 18-2月 -2017 16:04:25

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

正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
命令执行成功

C:\Users\Administrator>tnsping orcl 3

TNS Ping Utility for 64-bit Windows: Version 11.2.0.1.0 - Production on 18-2月 -2017 16:04:32

Copyright (c) 1997, 2010, Oracle.  All rights reserved.

已使用的参数文件:
C:\app\Dyj\product\11.2.0\dbhome_1\network\admin\sqlnet.ora

已使用 TNSNAMES 适配器来解析别名
TNS-12541: TNS: 无监听程序

4、sqlplus sys/cape@orcl 其中orcl必须在tnsnames.ora配置,同一个数据库实例在tnsnames.ora可以配置多个,如下:

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )
【连接数据库时,使用sqlplus sys/cape@orcl1 as sysdba】
ORCL11 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

5、监听的工作过程:

当你执行命令sqlplus username/password@tnsname的时,一般处理过程如下:
a) 查询sqlnet.ora看看名称的解析方式,发现是TNSNAME,或者hostname。
b) 则查询tnsnames.ora文件,从里边找tnsname的记录,并且找到主机名,端口和service_name。
c) 如果listener进程没有问题的话,建立与listener进程的连接。
d) 根据不同的服务器模式如专用服务器模式或者共享服务器模式,listener采取接下去的动作。默认是专用服务器模式,没有问题的话客户端就连接上了数据库的server process。
e) 这时候网络连接已经建立,listener进程的历史使命也就完成了。

6、为什么有了动态注册了,还需要静态注册呢?

  a.监听器不是最早启动,oracle实例先启动
  b.监听器重启
  c.oracle实例没有open

下面是静态注册的例子:
这里写图片描述
上述的例子可以解决问题:ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务,
测试步骤:lsnrctl stop->lsnrctl start->lsnrctl status
这里写图片描述
由于已经进行了静态注册,则执行以下脚本也可以正常的连接到数据库;

sqlplus sys/cape@orcl as sysdba【在动态监听未监控到orcl实例时,使用静态监听连接数据库】

7、连接其他服务器的数据库,则在tnsnames.ora中加入如下配置,即可:

PROD3 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.0.2.12)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PROD3)
    )
  )

使用以下脚本连接数据库,并且连接成功(由于此时连接另外一个服务器的数据库,则将本地的监听停止后,也可以正常的连接数据):

C:\Users\Administrator>sqlplus system/oracle@prod3

SQL*Plus: Release 11.2.0.1.0 Production on 星期六 218 18:33:11 2017

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

8、配置其他端口,连接数据库

请参考:
http://zhu8337797.blog.163.com/blog/static/1706175492011930113416194/

参考网址:
http://www.linuxidc.com/Linux/2014-05/101153.htm
http://www.linuxidc.com/Linux/2012-12/75568.htm【Oracle监听器出现的6种连接问题及其解决方法】
http://www.cnblogs.com/whgw/archive/2011/11/01/2230982.html【tnsnames.ora配置小结】
http://blog.itpub.net/519536/viewspace-684305【 【LISTENER】使用“alter system register;”解决动态监听注册缓慢问题 】

  • 11
    点赞
  • 44
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值