ORA-12154:TNS:无法解析指定的连接标识符错误和解决方案

时间:2020-01-09 10:41:50  来源:igfitidea点击:

问题描述:我的Oracle XE安装工作正常,但是今天我在Ubuntu Linux下收到如下错误:

ORA-12154: TNS:could not resolve the connect identifier specified
ORA-12154:TNS:无法解析指定的连接标识符

如何在不重新安装Oracle的情况下解决此问题?

你可以尝试以下解决方案:

确保DNS /主机名解析正常

$ host oracle-server-ip
$ host oracle-server-hostname

确保正确配置了/etc/resolv.conf和/etc/hosts和/etc/host.conf。

确保正确配置了tnsnames.ora:

执行以下命令以oracle/dba用户身份登录:

$ su - oracle
$ cd /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/network/admin/
$ vi tnsnames.ora

确保正确定义了主机名/IP并正确解析:

# tnsnames.ora Network Configuration File:

XE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = Hyman-desktop)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  )

EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )

确保在listener.ora及以上文件中指定的主机,端口和服务名称正确:

$ cd /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/network/admin/
$ vi listener.ora

我的示例工作文件:

# listener.ora Network Configuration File:

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /usr/lib/oracle/xe/app/oracle/product/10.2.0/server)
      (PROGRAM = extproc)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
      (ADDRESS = (PROTOCOL = TCP)(HOST = Hyman-desktop)(PORT = 1521))
    )
  )

DEFAULT_SERVICE_LISTENER = (XE)

确保防火墙没有阻止TCP端口:

$ sudo iptables -L -n

如果其他所有方法都失败,请尝试通过运行strace来跟踪问题:

$ su - oracle
$ strace -o /tmp/debug.sqlplus sqlplus user/password