ORA-12547: TNS:lost contact

This post is also available at: Português

Ao tentar conectar-se com sqlplus / as sysdba é apresentado o erro de ORA-12547: TNS:lost contact. Abaixo apresento algumas formas de correção que aconteceram comigo.

oracle@orcleserver [scprbr07] /home/oracle> sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Sat Dec 2 01:54:17 2023
Version 19.3.0.0.0

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

ERROR:
ORA-12547: TNS:lost contact


Enter user-name: ^C
oracle@orcleserver [scprbr07] /home/oracle>
SQL

Solução 1:

ORACLE_HOME está configurada de forma errada como podemos ver abaixo, tem um “/” a mais na linha.

oracle@oracleserver [scprbr07] /home/oracle> cat /etc/oratab
#Backup file is  /u01/app/oracle/crsdata/oracleserver/output/oratab.bak.oracleserver.oracle line added by Agent
#
# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third field indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
+ASM:/u01/app/19.0.0.0/grid:N
scprbr07:/u01/app/oracle/product/19.3.0.0/dbhome_1/:N           # line added by Agent
Bash

Corrigir a entrada no /etc/oratab e tentar realizar novamente a conexão.

oracle@oracleserver [scprbr07] /home/oracle> . oraenv
ORACLE_SID = [scprbr07] ? scprbr07
The Oracle base remains unchanged with value /u01/app/oracle
oracle@oracleserver [scprbr07] /home/oracle> sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Sat Dec 2 02:06:33 2023
Version 19.3.0.0.0

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


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL>
SQL

Caso o banco estivesse cadastrado srvctl, provavelmente será necessário corrigir lá também.

oracle@oracleserver [scprbr07] /u01/app/oracle/diag/rdbms/scprbr07/scprbr07/trace> srvctl config database -d scprbr07
Database unique name: scprbr07
Database name:
Oracle home: /u01/app/oracle/product/19.3.0.0/dbhome_1/
Oracle user: oracle
Spfile: +DATA/SCPRBR07/PARAMETERFILE/spfile.257.1145122115
Password file: +DATA/SCPRBR07/PASSWORD/pwdscprbr07.278.1088971723
Domain:
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Disk Groups: DATA
Services: scprbr07_serv
OSDBA group:
OSOPER group:
Database instance: scprbr07
Bash

Realizando a alteração.

srvctl modify database -d scprbr07 -o /u01/app/oracle/product/19.3.0.0/dbhome_1
Bash

Se estiver errado no srvctl, terá de fazer stop / start no banco para subir com a variável correta.
Você consegue ver a variável que o banco de dados está utilizando com o comando abaixo.

ps -ef | grep pmon
oracle   42456     1  0 Dec01 ?        00:00:01 asm_pmon_+ASM
oracle   51812     1  0 02:35 ?        00:00:00 ora_pmon_scprbr07    <<-- pegar  o PID
oracle   55320 43687  0 02:42 pts/0    00:00:00 grep --color=auto pmon


xargs -0 -L1 -a /proc/51812/environ | grep ORACLE_HOME   <<<--- usar o PID aqui
ORACLE_HOME=/u01/app/oracle/product/19.3.0.0/dbhome_1/
Bash

Solução 2:

As permissões nos binários do oracle estão incorretas.

cd $ORACLE_HOME/bin
ls -ltr oracle
-rwxr-xr-x    1 oracle oinstall 441253104 Dec  2 02:03 oracle
Bash

Altere as permissões do arquivo oracle, conforme abaixo.

chmod 6751 oracle
ls -ltr oracle
-rwsr-s--x 1 oracle oinstall 441253104 Dec  2 02:03 oracle
Bash
Previous Article

OEM agent is not collecting metrics

Next Article

OPATCHAUTO-72115

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *