ORA-12154 TNS:无法解析安装APEX时指定的连接标识符

我在Azure上有RHEL 6.8 Oracle版本,我按照Microsoft的教程Create an Oracle Database in an Azure VMe在上面安装了数据库。教程进行得很顺利。现在我尝试用这个Oracle Application Express (APEX) 5.x Installation安装APEX,但我在CONN sys@pdb1 AS SYSDBA行被卡住了。

输入密码(是否正确无关紧要)后,我每次都会收到ERROR: ORA-12154: TNS:could not resolve the connect identifier specified

我已尝试:

  • 创建变量TNS_ADMIN
  • ORACLE_HOME/network/admin添加到PATH
  • 创建和编辑文件:

listener.ora:

# listener.ora Network Configuration File: /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = OracleDbVm)(PORT = 1521))
  )

ADR_BASE_LISTENER = /u01/app/oracle

sqlnet.ora:

NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME)

tnsnames.ora:

WINDOWNETSERVICE =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = OracleDbVm)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = cdb1)
    )
  )

lsnrctl状态输出

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 26-JUL-2017 09:02:06

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=OracleDbVm)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date                25-JUL-2017 23:19:33
Uptime                    0 days 9 hr. 42 min. 32 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/OracleDbVm/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=OracleDbVm.{some_values}.ax.internal.cloudapp.net)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=OracleDbVm.{some_values}.ax.internal.cloudapp.net)(PORT=5502))(Security=(my_wallet_directory=/u01/app/oracle/product/12.1.0/dbhome_1/admin/cdb1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "cdb1" has 1 instance(s).
  Instance "cdb1", status READY, has 1 handler(s) for this service...
Service "cdb1XDB" has 1 instance(s).
  Instance "cdb1", status READY, has 1 handler(s) for this service...
Service "pdb1" has 1 instance(s).
  Instance "cdb1", status READY, has 1 handler(s) for this service...
The command completed successfully

我的env输出:

[oracle@OracleDbVm admin]$ env
HOSTNAME=OracleDbVm
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
OLDPWD=/home/oracle
USER=oracle
LS_COLORS={colors_long_values}
ORACLE_SID=cdb1
TNS_ADMIN=/u01/app/oracle/product/12.1.0/dbhome_1/network/admin
MAIL=/var/spool/mail/oracle
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/u01/app/oracle/product/12.1.0/dbhome_1/network/admin:/u01/app/oracle/product/12.1.0/dbhome_1/bin:/home/oracle/bin
PWD=/u01/app/oracle/product/12.1.0/dbhome_1/network/admin
LANG=en_US.UTF-8
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
HISTCONTROL=ignoredups
SHLVL=1
HOME=/home/oracle
LOGNAME=oracle
LESSOPEN=||/usr/bin/lesspipe.sh %s
ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
G_BROKEN_FILENAMES=1
_=/bin/env

我还能做些什么来解决该问题?


解决方案

您的CONN sys@pdb1 AS SYSDBA正在尝试使用pdb1的SID(或tnsname条目)连接到一个实例,但在多租户环境中,您的所有数据库共享相同的SID(在您的情况下为cdb1),并且您的tnsname中没有pdb1条目。连接到PDB时,您需要在连接字符串中使用服务名称。

您可以这样更新您的tnsname:

WINDOWNETSERVICE =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = OracleDbVm)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = cdb1)
    )
  )

pdb1=
  (DESCRIPTION=
    (ADDRESS=
      (PROTOCOL=TCP)
      (HOST=OracleDbVm)
      (PORT=1521)
    )
    (CONNECT_DATA=
      (SERVICE_NAME=pdb1)
    )
  )

然后重试CONN sys@pdb1 AS SYSDBA...

或者您可以尝试使用带有服务名称的完整连接字符串,如:

conn sys@OracleDbVm:1521/pdb1 as sysdba

我认为您也可以连接到CDB,切换到pdb1,然后启动脚本。如果您需要有关该选项的更多详细信息,请与我联系。

相关文章