测试环境上一同事反映在使用应用用户sqlplus本地登录数据库时有报错,报错信息如下:
(pcsfe@pcsweb-a)/app/pcsfe>echo $ORACLE_SID
PCSWEB
(pcsfe@pcsweb-a)/app/pcsfe>sqlplus crgfe/crgferun
SQL*Plus: Release 10.2.0.3.0 - Production on Tue Jun 14 15:52:37 2011
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Solaris-AMD64 Error: 2: No such file or directory
但是奇怪的是使用TNS别名登录就没有问题。
(pcsfe@pcsweb-a)/app/pcsfe>sqlplus crgfe/crgferun@PCSWEB
SQL*Plus: Release 10.2.0.3.0 - Production on Tue Jun 14 15:52:55 2011
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> ---可以正常登录
一般像ORA-27101这种错误都是由于ORACLE_HOME或者ORACLE_SID环境变量设置不当导致的。所以首先检查了ORACLE_SID:
(pcsfe@pcsweb-a)/app/pcsfe>echo $ORACLE_SID
PRECARD
没问题,然后是ORACLE_HOME:
(pcsfe@pcsweb-a)/app/pcsfe>echo $ORACLE_HOME
/oracle/oracle/product/10.2.0
(pcsfe@pcsweb-a)/app/pcsfe>cd /oracle/oracle/product/10.2.0
该目录确实也存在,没有问题。
那么既然都没有问题,为什么就是登录不了呢?
我们仔细再看看下面这段描述,摘自metalink:
Error ORA-27101 is reporting that the shared memory key generated by the client does not match any currently existing keys. This is to be expected if the ORACLE_HOME or ORACLE_SID used by the client is not the same as that used when starting up the database.
是不是在数据库启动后,有什么环境变量的设置被改了呢?带着这个问题,我首先检查了oracle的环境变量:
oracle@/oracle/oracle>echo $ORACLE_HOME
/oracle/product/10.2.0
看到了吗?原来ORACLE_HOME的环境变量设置不一致,少了一层oracle目录。
再追溯回去
oracle@/oracle/oracle>ls -rlt
total 4
drwxr-xr-x 7 oracle oinstall 512 Mar 29 2010 oraInventory
lrwxrwxrwx 1 oracle oinstall 15 Jun 14 15:34 product -> /oracle/product
原来在/oracle/oracle下做了软链接(ln -s /oracle/product product),将/oracle/oracle/product指向了/oracle/product目录。询问开发人员,确实为了应用程序移植方便,直接将文件目录做了链接。
至此,问题原因查明,解决的方法当然很简单:
方法一:修改应用用户ORACLE_HOME环境变量
export ORACLE_HOME=/oracle/product/10.2.0
方法二:修改数据库启动时的ORACLE_HOME环境变量
Database shutdown
export ORACLE_HOME=/oracle/oracle/product/10.2.0
Database startup