连接Linux服务器下Oracle数据库提示:ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务

该文章借鉴了https://www.cnblogs.com/nichoc/p/6417505.html的示例
连接Linux服务器下Oracle数据库提示:ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务_第1张图片
提示该异常说明了两个前提,第一是Oracle数据库是开启状态,第二是监听程序处于开启状态
解决步骤:
切换到Oracle用户

su – oracle

查看监听状态

lsnrctl status 

连接Linux服务器下Oracle数据库提示:ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务_第2张图片
READY说明为动态监听,UNKNOWN则为静态监听(该判断不够准确,具体要到/network/admin/目录下的listener.ora里查看,如果不存在该配置文件,或者未配置SID_LIST_[监听名](ps:SID_LIST_LISTENER)则为动态监听)

文章目录

    • (1) 当为READY(动态监听)
    • (2) 当为UNKNOWN(静态监听)

(1) 当为READY(动态监听)

Oracle会监听所有启用实例,启用动态监听却提示(监听程序当前无法识别连接描述符中请求服务)异常说明该实例被关闭了,所以我们要做的就是开启我们需要访问的实例即可

切换实例用户:

export ORACLE_SID=tbzg(实例名)

(不知道实例名去$ORACLE_HOME/dbs目录去查看)
连接服务:

sqlplus '/as sysdba'

启动服务:

Startup

退出服务

exit

查看当前有多少个已经启动的实例:

ps -ef|grep smon

在这里插入图片描述
发现tbzg已经启动
查看监听状态
连接Linux服务器下Oracle数据库提示:ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务_第3张图片
问题解决

(2) 当为UNKNOWN(静态监听)

修改listener.ora和tnsnames.ora,重启oracle,监听,并注册

Oracle11g64位软件的安装位置为data/oracle/product/11.2.0/db_1,数据库名为默认的orcl,
CentOS7虚拟机的IP设置为:192.168.78.130

为例
<1>修改listener.ora

vi /data/oracle/product/11.2.0/db_1/network/admin/listener.ora

/network/admin/目录下,查看自己Oracle的安装目录
原:

# listener.ora Network Configuration File: /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
  )
ADR_BASE_LISTENER = /data/oracle

改:

# listener.ora Network Configuration File: /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
#LIST_LISTENER 为监听名字
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl) ##listener.ora中GLOBAL_DBNAME的值  == tnsnames.ora中的SERVICE_NAME
(ORACLE_HOME = /data/oracle/product/11.2.0/db_1)
(SID_NAME = orcl) ##可通过env | grep ORACLE查看SID_NAME和$ORACLE_HOME的值,先切换到对应实例export ORACLE_SID=实例名
)
)
LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.78.130)(PORT = 1521)))
ADR_BASE_LISTENER = /data/oracle

[监听名]和SID_LIST_[监听名]配置是成对出现
配置listener.ora中GLOBAL_DBNAME的值等于tnsnames.ora中的SERVICE_NAME
<2>修改tnsnames.ora

vi /data/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora

/network/admin/目录下,查看自己Oracle的安装目录
原:

# tnsnames.ora Network Configuration File: /data/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

改:

# tnsnames.ora Network Configuration File: /data/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
orcl =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.78.130)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = orcl)
    )
  )

<3>重启监听更新注册

lsnrctl stop                #先关闭监听服务
lsnrctl start                    #开启监听服务

console:

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 19-FEB-2017 21:24:22
Copyright (c) 1991, 2009, Oracle.  All rights reserved.
Starting /data/oracle/product/11.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
Log messages written to /data/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.78.130)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.78.130)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                19-FEB-2017 21:24:22
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File         /data/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.78.130)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@localhost ~]$

注意看启动端口时候生效

sqlplus / as sysdba     #登入
shutdown immediate             #立即关闭数据库服务
startup                                    #开启数据库服务
alter system register;        #注册
 quit         #登出
lsnrctl status        #查看监听状态

console:

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 19-FEB-2017 21:37:20
Copyright (c) 1991, 2009, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.78.130)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                19-FEB-2017 21:24:22
Uptime                    0 days 0 hr. 12 min. 57 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File         /data/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.78.130)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@localhost ~]$

再次用plsql访问成功

你可能感兴趣的:(Linux,Oracle)