sqlplus无法使用tnsnames.ora中的信息连接到oracle

时间:2013-09-11 15:05:14

标签: linux oracle sqlplus tnsnames oracle12c

我可以通过

登录
sqlplus / as sysdba

然后我使用启动启动intance,我也可以使用

启动PDB
startup pluggable database pdborcl 

在终端中,echo $ ORACLE_SID获取ora12cr1

但我无法使用

登录
sqlplus  /@ora12cr1 as sysdba

我收到了ORA-01017:用户名/密码无效;登录被拒绝。下面是我的tnsnames.ora:

ORA12CR1=
  (DESCRIPTION=
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
    (CONNECT_DATA=
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl.cn.oracle.com)
    )
  )

PDBORCL =
 (DESCRIPTION =
   (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
     (CONNECT_DATA =
       (SERVICE_NAME = pdborcl.cn.oracle.com)
     )
 )

oracle 12cr1安装在我的本地计算机上。

lsnrctl status获取:

LSNRCTL for Linux: Version 12.1.0.1.0 - Production on 11-SEP-2013 23:02:57

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.1.0 - Production
Start Date                11-SEP-2013 22:40:09
Uptime                    0 days 0 hr. 22 min. 48 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=localhost.localdomain)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/orcl/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "orcl.cn.oracle.com" has 1 instance(s).
  Instance "ora12cr1", status READY, has 1 handler(s) for this service...
Service "orclXDB.cn.oracle.com" has 1 instance(s).
  Instance "ora12cr1", status READY, has 1 handler(s) for this service...
Service "pdborcl.cn.oracle.com" has 1 instance(s).
  Instance "ora12cr1", status READY, has 1 handler(s) for this service...
The command completed successfully

SQL> show pdbs

    CON_ID CON_NAME           OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
     3 PDBORCL            READ WRITE NO

alter session set container = pdborcl

也有效。

3 个答案:

答案 0 :(得分:0)

尝试

sqlplus /@localhost.localdomain/orcl.cn.oracle.com as sysdba

如果那是您要登录的服务(不确定我是否完全理解您的问题)。

答案 1 :(得分:0)

我正在使用

sqlplus sys@pdborcl as sysdba

并输入密码。

show con_name;

产生值

CON_NAME
------------------------------
PDBORCL

答案 2 :(得分:0)

使用/ AS SYSDBA将像在container database级别(CDB)的先前版本中那样工作。但它无法通过sqlplus连接到没有密码的pluggable database(PDB)。

实现此目的的最简单方法是继续使用" /作为SYSDBA"进行连接,但是使用ALTER SESSION SET CONTAINER命令在脚本中设置特定容器。

sqlplus / as sysdba <<EOF

ALTER SESSION SET CONTAINER = pdb1;

-- Perform actions as before...
SHOW CON_NAME;

EXIT;
EOF

您还可以参阅此文章以获取更多信息Multitenant : Running Scripts Against Container Databases (CDBs) and Pluggable Databases (PDBs) in Oracle Database 12c Release 1 (12.1)