Search

Thursday, June 23, 2016

How to fix ORA-12547 TNS lost contact when try to connect Oracle

Issue / Oracle error

sqlplus scott/tiger
SQL*Plus: Release 10.2.0.5.0 - Production on Wed May 18 09:32:35 2011
Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.
ERROR:
ORA-12547: TNS :lost contact when try to connect to Oracle.

Issue description

I saw that TNS connection issue along with ORA-12547 Oracle error several times, usually when trying to connect to Oracle database server on Unix / Linux host with an OS user that does not belong to oinstall group (Oracle binaries owner group).  In this case, interesting enough that local TNS connection to database (when using tnsnames alias) works fine:
sqlplus scott/tiger@orcl
and only local BEQ protocol connection through an Oracle error ORA-12547:

sqlplus scott/tiger
ERROR:
ORA-12547: TNS:lost contact

There can be different reasons of this issue, but usually the problem is in wrong privileges/ownership of some Oracle binaries located in $ORACLE_HOME/bin directory. Perhaps, Oracle database binaries were installed / linked not correctly or something or somebody has changed the files’ ownership.

Solution

    1. Ensure the DB is up and running and you can connect locally AS SYSDBA to the database using Oracle binaries owner (usually oracle:oinstall Unix / Linux user). If it does not work, probably you encounter a different problem.
    2. Check privileges of an Oracle file on Unix / Linux host where database is running:
cd $ORACLE_HOME/bin
ls -ltr oracle
-rwxr-xr-x    1 oracle   oinstall       136803483 Mar 16 20:32 oracle

    1. Change permissions as below:
chmod 6751 oracle
ls -ltr oracle
-rwsr-s--x    1 oracle   oinstall       136803483 Mar 16 20:32 oracle

    1. Usually the above operation should fix the issue but I suggest continue investigating privileges of other files to avoid further possible problems.  As the matter of fact these special rights of Oracle binaries are set by $ORACLE_HOME/root.sh script on Unix / Linux after the Oracle installation. You can run the script again as root user, if you see more files have wrong permissions or ownership (make backup before, just in case). For that I provide as an example 2 lists of oracle binary files in $ORACLE_HOME/bin directory with correct rights below.
Oracle 11gR2 (11.2.0.3) on Linux Redhat 6.x
-rwsr-s--x.  1 oramcelt oinstall 221227204 Aug 14 12:12 oracle
-rwsr-s--x.  1 oramcelt oinstall 221189362 Aug 14 11:03 oracleO
-rwsr-x---.  1 root     oinstall     71758 Sep 17  2011 oradism
-rws--x---.  1 root     oinstall     44437 Aug 14 11:02 nmo
-rws--x---.  1 root     oinstall     66324 Aug 14 11:02 nmhs
-rws--x---.  1 root     oinstall     34166 Aug 14 11:03 nmb
-rwsr-x---.  1 root     oinstall     43402 Aug 14 11:03 jssu
-rwsr-x---.  1 root     oinstall     43402 Aug 14 11:03 jssu
-rwsr-x---.  1 root     oinstall   1249349 Aug 14 11:03 extjob
-rwsr-s--x.  1 oramcelt oinstall     65799 Aug 14 11:02 emtgtctl2


Oracle 11gR2 (10.2.0.3) on Linux Redhat 4.x
-rwsr-x---  1 root   oinstall    64850 Nov  6  2007 extjob
-rwsr-s---  1 root   oinstall    18376 Mar  1  2006 nmb
-rwsr-s---  1 root   oinstall    19566 Mar  1  2006 nmo
-rwsr-s--x  1 oracle oinstall 95118102 Nov  6  2007 oracle
-r-sr-s---  1 root   oinstall    14456 Nov 15  2006 oradism

Good luck and feel free to add solutions of the same issue in your comments.