Oracle Developer VM – How to Connect to Root

containersoracleoracle-12c

I have the Oracle Database App Development VM (12c) and am trying to create a new container. Specifically:

conn / as sysdba
create pluggable database pdborcl admin user system identified by oracle FILE_NAME_CONVERT=('/u01/app/oracle/oradata/cdb1/pdbseed/', '/u01/app/oracle/oradata/cdb1/pdb2'');

However, I cannot connect to the root container. The above conn spits out:

  URL           = jdbc:oracle:oci8:@(DESCRIPTION =    (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = orcl)    )  )
  Error Message = ORA-01017: invalid username/password; logon denied
  USER          = 
  URL           = jdbc:oracle:thin:@(DESCRIPTION =    (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = orcl)    )  )
  Error Message = ORA-01017: invalid username/password; logon denied

Warning: You are no longer connected to ORACLE.

And sqlplus / as sysdba returns:

ERROR:
ORA-01017: invalid username/password; logon denied

Logging in with sqlplus system as sysdba logs into the connection ORCL.

Best Answer

The reason for sqlplus / as sysdba not working is:

[oracle@localhost ~]$ grep -i two_task .bashrc
if test "m$DONOTSETTWO_TASK" = "m"
        export TWO_TASK=ORCL
[oracle@localhost ~]$ grep -i two_task .bashrc -A 1
if test "m$DONOTSETTWO_TASK" = "m"
        then
        export TWO_TASK=ORCL
        fi
[oracle@localhost ~]$ echo $TWO_TASK 
ORCL

SQL*Plus connections automatically connect to the TNS alias defined in the TWO_TASK environment variable. When it is set, sqlplus / as sysdba does not work.

It is like trying this (will not work):

sqlplus /@ORCL as sysdba

To "fix" this:

[oracle@localhost ~]$ unset TWO_TASK
[oracle@localhost ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Fri May 11 15:20:59 2018

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> 

You can not connect to a PDB directly with SQL*Plus, you need to use a TNS alias or EZCONNECT. Setting TWO_TASK takes care of this, so you can login with for example sqlplus hr/hr directly to the PDB, without manually specifying its address.

I guess Oracle just wanted to make simple to connect to the ORCL PDB - instead of actually explaining how things work.