There are two environment variables for Unix to connect an Oracle database.One of them is ORACLE_SID and the other one is TWO_TASK. ORACLE_SID is used for connecting a database which is installed to the same host. TWO_TASK is used for connecting an oracle database which is installed another host.

I must thank to my fellow DBA Pinto Das who provide this scenario and we both come out with below solution.

Database Details

CDB= orcl12c
PDB= orcl

I was trying to look at the container and pluggable databases when I hit my first hurdle trying to connect to the database using sqlplus.

[oracle@localhost admin]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Fri Oct 20 14:02:58 2017
Copyright (c) 1982, 2016, Oracle. All rights reserved.
ERROR:
ORA-01017: invalid username/password; logon denied
Enter user-name: sys
Enter password:
ERROR:
ORA-28009: connection as SYS should be as SYSDBA or SYSOPER

I tried to connect again by using the credentials and it worked but point to PDB not to CDB

[oracle@localhost admin]$ sqlplus sys/oracle as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Fri Oct 20 14:03:22 2017
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> show con_name
CON_NAME
------------------------------
ORCL

Being able to connect with the user id and password gave my the vital clue. As can be seen by the prompt ORCL we are connecting directly to the pluggable database and not the container. I wanted to connect to the container so I can view all pluggable databases.

Looking through the environment settings I noticed the TWO_TASK variable set in .bash_profile. TWO_TASK overrides the ORACLE_SID setting and uses sqlnet to connect.

[oracle@localhost ~]$ grep TWO_TASK .bash_profile
export TWO_TASK=ORCL

So now all I had to do was unset it and connect.

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

SQL*Plus: Release 12.2.0.1.0 Production on Fri Oct 20 14:03:22 2017
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT

And there you go. Now I’m connected to the container.

Source

Thank you for giving your valuable time to read the above information.

If you want to be updated with all our articles send us the Invitation or Follow us:

Skant Gupta’s LinkedIn: www.linkedin.com/in/skantali/

Joel Perez’s LinkedIn: www.linkedin.com/in/SirDBaaSJoelPerez

Anuradha’s LinkedIn: https://www.linkedin.com/in/dbaanuradhamudgal/

LinkedIn Group: Oracle Cloud DBAAS

Facebook Page: OracleHelp

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.