ITPub博客

首页 > 数据库 > Oracle > [20160310]神奇的斜线.txt

[20160310]神奇的斜线.txt

Oracle 作者:lfree 时间:2016-03-10 15:53:26 0 删除 编辑

[20160310]神奇的斜线.txt

--今天发现同事配置的数据库服务器,没有配置NLS_DATE_FORMAT环境变量,当打开.bash_profile时发现同事配置的-ORACLE_HOME环境变
--量结尾带有/,忍不住想说一番,还好我测试以下,发现11.2.0.4版本,ORACLE_HOME最后有没有/都可以正常进入连上数据库(当执行
--sqlplus / as sysdba).

--相关链接可以看我以前写的blog:

[20140513]ORACLE_HOME环境变量结尾的斜杠
http://blog.itpub.net/267265/viewspace-1160328/
[20150911]关于远程启动数据库问题.txt
http://blog.itpub.net/267265/viewspace-1797866/

1.测试1:

$ export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1/
$ rlsql
SQL*Plus: Release 11.2.0.4.0 Production on Thu Mar 10 14:57:44 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SYS@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

--正常,可以登录。

2.测试2:
[oracle@gxqyydg4 IP=100.78 ~/gdul 6]$ export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1
[oracle@gxqyydg4 IP=100.78 ~/gdul 7]$ rlsql
SQL*Plus: Release 11.2.0.4.0 Production on Thu Mar 10 14:58:48 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SYS@book> @ &r/ver1

PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

--正常,可以登录。也就是将从11.2.0.4,环境变量ORACLE_HOME无论后面有没有/,都不影响进入数据库。

3.我启动数据库是设置ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1(没有斜线的)。
--设置ORACLE_HOME结尾带斜线。
$ export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1/
SYS@book> @ &r/spid

       SID    SERIAL# SPID       PID  P_SERIAL# C50
---------- ---------- ------ ------- ---------- --------------------------------------------------
       112        519 1030        34        244 alter system kill session '112,519' immediate;

$ cat /proc/1030/environ | tr '=' '\n'|strings | grep -A1 ORACLE_HOME
ORACLE_HOME
/u01/app/oracle/product/11.2.0.4/dbhome_1/

$ ps -ef | grep ora_pmo[n]
oracle   53188     1  0 Mar08 ?        00:00:22 ora_pmon_book

$ cat /proc/53188/environ | tr '=' '\n'|strings | grep -A1 ORACLE_HOME
ORACLE_HOME
/u01/app/oracle/product/11.2.0.4/dbhome_1

--可以发现ORACLE_HOME不一样,但是都可以正常连接数据库。

4.看看ipc信息:

SYS@book> oradebug setmypid
Statement processed.
SYS@book> oradebug ipc
IPC information written to the trace file
*** 2016-03-10 15:10:31.001
Processing Oradebug command 'ipc'
Dump of unix-generic skgm context
areaflags            000000f7
realmflags           0000001f
mapsize              00000800
protectsize          00001000
lcmsize              00001000
seglen               00200000
largestsize  0000000480000000
smallestsize 0000000000400000
stacklimit     0x7fff5659d250
stackdir                   -1
mode                      640
magic                acc01ade
Handle:        0x7fd033e7e0b0 `/u01/app/oracle/product/11.2.0.4/dbhome_1book'

--注意看Handle:        0x7fd033e7e0b0 `/u01/app/oracle/product/11.2.0.4/dbhome_1book'。

5.设置ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1/
SYS@book> shutdown immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@book> exit

$ export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1/
SYS@book> startup
ORACLE instance started.
Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes
Database mounted.
Database opened.

SYS@book> oradebug setmypid
Statement processed.
SYS@book> oradebug ipc
IPC information written to the trace file

Processing Oradebug command 'ipc'
Dump of unix-generic skgm context
areaflags            000000f7
realmflags           0000001f
mapsize              00000800
protectsize          00001000
lcmsize              00001000
seglen               00200000
largestsize  0000000480000000
smallestsize 0000000000400000
stacklimit     0x7fff6e19ad40
stackdir                   -1
mode                      640
magic                acc01ade
Handle:        0x7f51a90520b0 `/u01/app/oracle/product/11.2.0.4/dbhome_1book'
--可以发现无论设置ORACLE_HOME带与不带结尾的斜线,ipc看到的Handle 都是一样的。

5.再看看看监听:
--注当前设置的 ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1/

$ ps -ef | grep tnslsn[r]
oracle   53211     1  0 Feb28 ?        00:00:21 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr LISTENER -inherit

$ cat /proc/53211/environ | tr '=' '\n'|strings | grep -A1 ORACLE_HOME
ORACLE_HOME
/u01/app/oracle/product/11.2.0.4/dbhome_1

--可以发现监听的ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1

--从远程使用sys用户连上数据库

d:\tools\rlwrap>sqlplus sys/xxxxxx@78 as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Thu Mar 10 15:25:24 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SYS@78> shutdown immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.

SYS@78> startup
ORACLE instance started.
Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes
Database mounted.
Database opened.

--注要远程连接关闭后启动数据库一定要配置静态监听。注意这个时候实际上因为监听进程的ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1
--这样远程启动的数据库环境变量ORACLE=/u01/app/oracle/product/11.2.0.4/dbhome_1,在服务器上看看。

$ ps -ef | grep dbw[0]
oracle    1559     1  0 15:35 ?        00:00:00 ora_dbw0_book

$ cat /proc/1559/environ | tr '=' '\n'|strings | grep -A1 ORACLE_HOME
ORACLE_HOME
/u01/app/oracle/product/11.2.0.4/dbhome_1

--可以发现ORACLE启动的进程已经是环境变量ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1.

$ export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1/

[oracle@gxqyydg4 IP=100.78 ~/gdul 19]$ rlsql
SQL*Plus: Release 11.2.0.4.0 Production on Thu Mar 10 15:39:50 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SYS@book> @ &r/spid

       SID    SERIAL# SPID       PID  P_SERIAL# C50
---------- ---------- ------ ------- ---------- --------------------------------------------------
        80          3 1638        31          2 alter system kill session '80,3' immediate;

SYS@book> host  cat /proc/1638/environ | tr '=' '\n'|strings | grep -A1 ORACLE_HOME
ORACLE_HOME
/u01/app/oracle/product/11.2.0.4/dbhome_1/

--可以发现现在ORACLE_HOME已经没有任何影响。换一句话讲从11.2.0.4开始,无论ORACLE_HOME结尾是否带/.

--ipc 看到的handle都是Handle:        0x7f51a90520b0 `/u01/app/oracle/product/11.2.0.4/dbhome_1book'.
--也就是 最后的连接就是没有斜线的。

6.补充11.2.0.3情况看看:

$ export ORACLE_HOME=/u01/app/oracle11g/product/11.2.0/db_2/

SYS@test> startup
ORACLE instance started.

Total System Global Area 1603411968 bytes
Fixed Size                  2228784 bytes
Variable Size             973082064 bytes
Database Buffers          620756992 bytes
Redo Buffers                7344128 bytes
Database mounted.
Database opened.
SYS@test> oradebug setmypid
Statement processed.
SYS@test> oradebug ipc
Information written to trace file.

*** 2016-03-10 15:47:35.443
Processing Oradebug command 'ipc'
Dump of unix-generic skgm context
areaflags            000000f7
realmflags           0000001f
mapsize              00000800
protectsize          00001000
lcmsize              00001000
seglen               00200000
largestsize  0000000080000000
smallestsize 0000000001000000
stacklimit       0x7fbe07e840
stackdir                   -1
mode                      640
magic                acc01ade
Handle:          0x2a970040b0 `/u01/app/oracle11g/product/11.2.0/db_2/test'

--最后的连接存在斜线。如果这个时候设置ORACLE_HOME没有斜线.

$ export ORACLE_HOME=/u01/app/oracle11g/product/11.2.0/db_2
$ rlsql
SQL*Plus: Release 11.2.0.3.0 Production on Thu Mar 10 15:51:00 2016
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to an idle instance.

--无法连接上打开的数据库。如果启动数据库:

SYS@test> startup
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size                  2228784 bytes
Variable Size             973082064 bytes
Database Buffers          620756992 bytes
Redo Buffers                7344128 bytes
ORA-01102: cannot mount database in EXCLUSIVE mode

SYS@test> shutdown immediate ;
ORA-01507: database not mounted

总结:
当然从这些小细节,可以看出oracle一直不断的改进进步。从管理角度讲最好不要结尾的斜线。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2055052/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4020
  • 访问量
    8006238