代码改变世界

案例:使用sqlplus登录报ORA-12547错误

2020-11-11 09:52  AlfredZhao  阅读(1144)  评论(0编辑  收藏  举报

现象:Exadata刷机之后grid/oracle用户的环境变量是没有设置的,需要手工进行设置,设置完成后发现grid用户执行报错ORA-12547:

[grid@dbm0dbadm01 ~]$ sqlplus / as sysasm

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Nov 11 09:09:37 2020
Version 19.8.0.0.0

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

ERROR:
ORA-12547: TNS:lost contact


Enter user-name: ^C

使用oerr查看错误描述:

[grid@dbm0dbadm01 ~]$ oerr ora 12547
12547, 00000, "TNS:lost contact"
// *Cause: Partner has unexpectedly gone away, usually during process
// startup.
// *Action: Investigate partner application for abnormal termination. On an
// Interchange, this can happen if the machine is overloaded.

这个oerr的描述在这里有些迷惑性,我们知道实际新刷机环境也没有什么负载,根据经验查看基本信息:

[grid@dbm0dbadm01 ~]$ ps -ef|grep pmon
grid     138569      1  0 Nov06 ?        00:00:21 asm_pmon_+ASM1
oracle   148750      1  0 Nov06 ?        00:00:47 ora_pmon_cdb1db11
grid     219063 217084  0 09:09 pts/0    00:00:00 grep --color=auto pmon
[grid@dbm0dbadm01 ~]$ echo $ORACLE_SID
+ASM1
[grid@dbm0dbadm01 ~]$ env|grep ORA
ORACLE_SID=+ASM1
ORACLE_BASE=/u01/app/grid
ORACLE_HOME=/u01/app/19.0.0.0/grid/
[grid@dbm0dbadm01 ~]$ env|grep PATH
PATH=/u01/app/19.0.0.0/grid//bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin
PYTHONPATH=:/opt/oracle.cellos/lib/python

确认进程ok,环境变量看起来是最后多了一个斜杠,修正:

[grid@dbm0dbadm01 ~]$ vi ~/.bash_profile

去掉ORACLE_HOME变量值最后多余的/,然后再次登录,检查ok后重新执行可以成功。

[grid@dbm0dbadm01 ~]$ env|grep ORA
ORACLE_SID=+ASM1
ORACLE_BASE=/u01/app/grid
ORACLE_HOME=/u01/app/19.0.0.0/grid
[grid@dbm0dbadm01 ~]$ env|grep PATH
PATH=/u01/app/19.0.0.0/grid/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin
PYTHONPATH=:/opt/oracle.cellos/lib/python
[grid@dbm0dbadm01 ~]$ sqlplus / as sysasm

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Nov 11 09:13:04 2020
Version 19.8.0.0.0

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


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

SQL>

之前其实遇到过类似问题,还对比了不同版本下有无斜杠是否都会发生问题,确实证明在某些版本下多写斜杠不会有问题。
总结:这个案例固然非常简单且初级,但也有警醒的意义:千万不要寄希望于某些特定版本是否可以智能识别处理,保持细心,按最佳规范来做事。