ORACLE_SID与ORACLE_HOME环境变量介绍及有趣的后台进程

            对于在Unix/Linux平台下部署过Oracle数据库、或者熟悉Oracle的人来讲,或许对这两个环境变量并不陌生。

            通常情况下,ORACLE_SID这个环境变量全称Oracle System Identifier,,用于在一台服务器上标识不同的实例,默认情况下,实例名就是ORACLE_SID的值(即INSTANCE_NAME=$ORACLE_SID。当然实例名也可以不同于ORACLE_SID这个环境变量,只要在初始化参数文件里显示指定INSTANCE_NAME参数值不同于ORACLE_SID环境变量的值即可)。在UNIX/Linux平台下,该环境变量主要作用是同ORACLE_HOME这个环境变量做hash运算,得到一个唯一值,用来标识共享内存段,及SGA。下面,摘录一段TOM大师光辉著作《Expert Oracle Database Architecture 》的原文:

              If you’re unfamiliar with the term SID or  ORACLE_SID, a full definition is called for. The SID is a  site identifier . It and  ORACLE_HOME (where the Oracle software is installed) are hashed together in UNIX to create a unique key name for attaching an SGA. If your  ORACLE_SIDor  ORACLE_HOME is not set correctly, you’ll get the  ORACLE NOT AVAILABLE error, since you can’t attach to a shared memory segment that is identified by this unique key. On Windows, shared memory isn’t used in the same fashion as UNIX, but the SID is still important. You can have more than one database on the same ORACLE_HOME, so you need a way to uniquely identify each one, along with their configuration files.

            ORACLE_HOME环境变量是Oracle软件的安装路径,顺带ORACLE_BASE环境变量是Oracle软件安装的基目录。

            知道了ORACLE_SID和ORACLE_HOME这两个环境变量的作用后,我们来看下面的案例:

            首先,来看在参数文件里只用一个db_name参数来启动实例的情况,即默认情况下,INSTANCE_NAME=$ORACLE_SID的情形:

[root@localhost ~]# su - oracle
[oracle@localhost ~]$ env | grep ORA
ORACLE_SID=phydb10g
ORACLE_BASE=/u01/app
ORACLE_TERM=xterm
ORACLE_HOME=/u01/app/oracle
[oracle@localhost ~]$ ps -ef | grep ora_
oracle   17938 17904  0 15:15 pts/1    00:00:00 grep ora_
[oracle@localhost ~]$ cd $ORACLE_HOME/dbs
[oracle@localhost dbs]$ pwd  
/u01/app/oracle/dbs
[oracle@localhost dbs]$ cat initphydb10g.ora 
*.db_name='glndb'
[oracle@localhost dbs]$ sqlplus

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 1 15:16:15 2012

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  171966464 bytes
Fixed Size                  2094832 bytes
Variable Size             113248528 bytes
Database Buffers           50331648 bytes
Redo Buffers                6291456 bytes
ORA-00205: error in identifying control file, check alert log for more info


SQL> set line 160
SQL> show parameter instance_name;

NAME                                 TYPE                              VALUE
------------------------------------ --------------------------------- ------------------------------
instance_name                        string                            phydb10g
SQL> !ps -ef | grep ora_
oracle   17946     1  0 15:16 ?        00:00:00 ora_pmon_phydb10g
oracle   17948     1  0 15:16 ?        00:00:00 ora_psp0_phydb10g
oracle   17950     1  0 15:16 ?        00:00:00 ora_mman_phydb10g
oracle   17952     1  0 15:16 ?        00:00:00 ora_dbw0_phydb10g
oracle   17954     1  0 15:16 ?        00:00:00 ora_lgwr_phydb10g
oracle   17956     1  0 15:16 ?        00:00:00 ora_ckpt_phydb10g
oracle   17958     1  0 15:16 ?        00:00:00 ora_smon_phydb10g
oracle   17960     1  0 15:16 ?        00:00:00 ora_reco_phydb10g
oracle   17962     1  0 15:16 ?        00:00:00 ora_mmon_phydb10g
oracle   17964     1  0 15:16 ?        00:00:00 ora_mmnl_phydb10g
oracle   17966 17943  0 15:16 pts/2    00:00:00 /bin/bash -c ps -ef | grep ora_
oracle   17968 17966  0 15:16 pts/2    00:00:00 grep ora_

SQL> shutdown immediate;
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> 

            然后,来看INSTANCE_NAME<>$ORACLE_SID的情形

[oracle@localhost ~]$ env | grep ORA
ORACLE_SID=phydb10g
ORACLE_BASE=/u01/app
ORACLE_TERM=xterm
ORACLE_HOME=/u01/app/oracle
[oracle@localhost ~]$ cat /u01/app/oracle/dbs/initphydb10g.ora 
*.db_name='glndb'
*.instance_name='inst10g'
[oracle@localhost ~]$ ps -ef | grep ora_
oracle   18033 17996  0 15:23 pts/1    00:00:00 grep ora_
[oracle@localhost ~]$ sqlplus

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 1 15:23:19 2012

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  171966464 bytes
Fixed Size                  2094832 bytes
Variable Size             113248528 bytes
Database Buffers           50331648 bytes
Redo Buffers                6291456 bytes
ORA-00205: error in identifying control file, check alert log for more info


SQL> set line 160
SQL> show parameter instance_name

NAME                                 TYPE                              VALUE
------------------------------------ --------------------------------- ------------------------------
instance_name                        string                            inst10g
SQL> !ps -ef | grep ora_
oracle   18040     1  0 15:23 ?        00:00:00 ora_pmon_phydb10g
oracle   18042     1  0 15:23 ?        00:00:00 ora_psp0_phydb10g
oracle   18044     1  0 15:23 ?        00:00:00 ora_mman_phydb10g
oracle   18046     1  0 15:23 ?        00:00:00 ora_dbw0_phydb10g
oracle   18048     1  0 15:23 ?        00:00:00 ora_lgwr_phydb10g
oracle   18050     1  0 15:23 ?        00:00:00 ora_ckpt_phydb10g
oracle   18052     1  0 15:23 ?        00:00:00 ora_smon_phydb10g
oracle   18054     1  0 15:23 ?        00:00:00 ora_reco_phydb10g
oracle   18056     1  0 15:23 ?        00:00:00 ora_mmon_phydb10g
oracle   18058     1  0 15:23 ?        00:00:00 ora_mmnl_phydb10g
oracle   18060 18037  0 15:23 pts/2    00:00:00 /bin/bash -c ps -ef | grep ora_
oracle   18062 18060  0 15:23 pts/2    00:00:00 grep ora_

SQL> shutdown immediate;
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> 

            其次,来看在同一个ORACLE_HOME下启动两个不同实例的情形,即ORACLE_HOME相同,ORACLE_SID不同

[oracle@localhost ~]$ pwd
/home/oracle
[oracle@localhost ~]$ ps -ef | grep ora_
oracle   18187 18077  0 15:28 pts/1    00:00:00 grep ora_
[oracle@localhost ~]$ env | grep ORA
ORACLE_SID=phydb10g
ORACLE_BASE=/u01/app
ORACLE_TERM=xterm
ORACLE_HOME=/u01/app/oracle
[oracle@localhost ~]$ cat /u01/app/oracle/dbs/initphydb10g.ora 
*.db_name='glndb'
*.instance_name='inst10g'
[oracle@localhost ~]$ sqlplus

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 1 15:29:41 2012

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  171966464 bytes
Fixed Size                  2094832 bytes
Variable Size             113248528 bytes
Database Buffers           50331648 bytes
Redo Buffers                6291456 bytes
ORA-00205: error in identifying control file, check alert log for more info


SQL> !ps -ef | grep ora_
oracle   18199     1  0 15:29 ?        00:00:00 ora_pmon_phydb10g
oracle   18201     1  0 15:29 ?        00:00:00 ora_psp0_phydb10g
oracle   18203     1  0 15:29 ?        00:00:00 ora_mman_phydb10g
oracle   18205     1  0 15:29 ?        00:00:00 ora_dbw0_phydb10g
oracle   18207     1  0 15:29 ?        00:00:00 ora_lgwr_phydb10g
oracle   18209     1  0 15:29 ?        00:00:00 ora_ckpt_phydb10g
oracle   18211     1  0 15:29 ?        00:00:00 ora_smon_phydb10g
oracle   18213     1  0 15:29 ?        00:00:00 ora_reco_phydb10g
oracle   18215     1  0 15:29 ?        00:00:00 ora_mmon_phydb10g
oracle   18217     1  0 15:29 ?        00:00:00 ora_mmnl_phydb10g
oracle   18219 18196  0 15:29 pts/2    00:00:00 /bin/bash -c ps -ef | grep ora_
oracle   18221 18219  0 15:29 pts/2    00:00:00 grep ora_

SQL> !
[oracle@localhost ~]$ export ORACLE_SID=phydb11g
[oracle@localhost ~]$ env | grep ORA
ORACLE_SID=phydb11g
ORACLE_BASE=/u01/app
ORACLE_TERM=xterm
ORACLE_HOME=/u01/app/oracle
[oracle@localhost ~]$ cat /u01/app/oracle/dbs/initphydb11g.ora 
*.db_name='glndb'
*.instance_name='inst11g'
[oracle@localhost ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 1 15:30:31 2012

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  171966464 bytes
Fixed Size                  2094832 bytes
Variable Size             113248528 bytes
Database Buffers           50331648 bytes
Redo Buffers                6291456 bytes
ORA-00205: error in identifying control file, check alert log for more info


SQL> set line 160
SQL> show parameter instance_name;

NAME                                 TYPE                              VALUE
------------------------------------ --------------------------------- ------------------------------
instance_name                        string                            inst11g
SQL> !ps -ef | grep ora_
oracle   18199     1  0 15:29 ?        00:00:00 ora_pmon_phydb10g
oracle   18201     1  0 15:29 ?        00:00:00 ora_psp0_phydb10g
oracle   18203     1  0 15:29 ?        00:00:00 ora_mman_phydb10g
oracle   18205     1  0 15:29 ?        00:00:00 ora_dbw0_phydb10g
oracle   18207     1  0 15:29 ?        00:00:00 ora_lgwr_phydb10g
oracle   18209     1  0 15:29 ?        00:00:00 ora_ckpt_phydb10g
oracle   18211     1  0 15:29 ?        00:00:00 ora_smon_phydb10g
oracle   18213     1  0 15:29 ?        00:00:00 ora_reco_phydb10g
oracle   18215     1  0 15:29 ?        00:00:00 ora_mmon_phydb10g
oracle   18217     1  0 15:29 ?        00:00:00 ora_mmnl_phydb10g
oracle   18258     1  0 15:30 ?        00:00:00 ora_pmon_phydb11g
oracle   18260     1  0 15:30 ?        00:00:00 ora_psp0_phydb11g
oracle   18262     1  0 15:30 ?        00:00:00 ora_mman_phydb11g
oracle   18264     1  0 15:30 ?        00:00:00 ora_dbw0_phydb11g
oracle   18266     1  0 15:30 ?        00:00:00 ora_lgwr_phydb11g
oracle   18268     1  0 15:30 ?        00:00:00 ora_ckpt_phydb11g
oracle   18270     1  0 15:30 ?        00:00:00 ora_smon_phydb11g
oracle   18272     1  0 15:30 ?        00:00:00 ora_reco_phydb11g
oracle   18274     1  0 15:30 ?        00:00:00 ora_mmon_phydb11g
oracle   18276     1  0 15:30 ?        00:00:00 ora_mmnl_phydb11g
oracle   18306 18255  0 15:30 pts/2    00:00:00 /bin/bash -c ps -ef | grep ora_
oracle   18308 18306  0 15:30 pts/2    00:00:00 grep ora_

SQL> 

            最后,不同的ORACLE_HOME,相同的ORACLE_SID的情况,该情况下,在同一台服务器上分别安装了10.2.0.5.0、11gR2两套不同的Oracle软件,ORACLE_HOME不同

[oracle@localhost ~]$ env | grep ORA
ORACLE_SID=phydb10g
ORACLE_BASE=/u01/app
ORACLE_TERM=xterm
ORACLE_HOME=/u01/app/oracle
[oracle@localhost ~]$ ps -ef | grep ora_
oracle   18324 18077  0 15:34 pts/1    00:00:00 grep ora_
[oracle@localhost ~]$ cat /u01/app/oracle/dbs/initphydb10g.ora                  
*.db_name='glndb'
*.instance_name='inst10g'
[oracle@localhost ~]$ sqlplus

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 1 15:35:16 2012

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  171966464 bytes
Fixed Size                  2094832 bytes
Variable Size             113248528 bytes
Database Buffers           50331648 bytes
Redo Buffers                6291456 bytes
ORA-00205: error in identifying control file, check alert log for more info


SQL> set line 160
SQL> show parameter instance_name;

NAME                                 TYPE                              VALUE
------------------------------------ --------------------------------- ------------------------------
instance_name                        string                            inst10g
SQL> !
[oracle@localhost ~]$ ps -ef | grep ora_
oracle   18333     1  0 15:35 ?        00:00:00 ora_pmon_phydb10g
oracle   18335     1  0 15:35 ?        00:00:00 ora_psp0_phydb10g
oracle   18337     1  0 15:35 ?        00:00:00 ora_mman_phydb10g
oracle   18339     1  0 15:35 ?        00:00:00 ora_dbw0_phydb10g
oracle   18341     1  0 15:35 ?        00:00:00 ora_lgwr_phydb10g
oracle   18343     1  0 15:35 ?        00:00:00 ora_ckpt_phydb10g
oracle   18345     1  0 15:35 ?        00:00:00 ora_smon_phydb10g
oracle   18347     1  0 15:35 ?        00:00:00 ora_reco_phydb10g
oracle   18349     1  0 15:35 ?        00:00:00 ora_mmon_phydb10g
oracle   18351     1  0 15:35 ?        00:00:00 ora_mmnl_phydb10g
oracle   18382 18355  0 15:35 pts/2    00:00:00 grep ora_
[oracle@localhost ~]$ export ORACLE_HOME=/u01/app/product/11.2.0/dbhome_1
[oracle@localhost ~]$ env | grep ORA
ORACLE_SID=phydb10g
ORACLE_BASE=/u01/app
ORACLE_TERM=xterm
ORACLE_HOME=/u01/app/product/11.2.0/dbhome_1
[oracle@localhost ~]$ cat /u01/app/product/11.2.0/dbhome_1/dbs/initphydb10g.ora 
*.db_name='GLNDB'
*.instance_name='inst11g'
[oracle@localhost ~]$ /u01/app/product/11.2.0/dbhome_1/bin/sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Thu Mar 1 15:37:41 2012

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

SQL> conn / as sysdba;
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area  217157632 bytes
Fixed Size                  2211928 bytes
Variable Size             159387560 bytes
Database Buffers           50331648 bytes
Redo Buffers                5226496 bytes
ORA-00205: error in identifying control file, check alert log for more info


SQL> set line 160
SQL> show parameter instance_name;

NAME                                 TYPE                              VALUE
------------------------------------ --------------------------------- ------------------------------
instance_name                        string                            inst11g
SQL> !
[oracle@localhost ~]$ ps -ef | grep ora_
oracle   18333     1  0 15:35 ?        00:00:00 ora_pmon_phydb10g
oracle   18335     1  0 15:35 ?        00:00:00 ora_psp0_phydb10g
oracle   18337     1  0 15:35 ?        00:00:00 ora_mman_phydb10g
oracle   18339     1  0 15:35 ?        00:00:00 ora_dbw0_phydb10g
oracle   18341     1  0 15:35 ?        00:00:00 ora_lgwr_phydb10g
oracle   18343     1  0 15:35 ?        00:00:00 ora_ckpt_phydb10g
oracle   18345     1  0 15:35 ?        00:00:00 ora_smon_phydb10g
oracle   18347     1  0 15:35 ?        00:00:00 ora_reco_phydb10g
oracle   18349     1  0 15:35 ?        00:00:00 ora_mmon_phydb10g
oracle   18351     1  0 15:35 ?        00:00:00 ora_mmnl_phydb10g
oracle   18402     1  0 15:37 ?        00:00:00 ora_pmon_phydb10g
oracle   18404     1  0 15:37 ?        00:00:00 ora_vktm_phydb10g
oracle   18408     1  0 15:37 ?        00:00:00 ora_gen0_phydb10g
oracle   18410     1  0 15:37 ?        00:00:00 ora_diag_phydb10g
oracle   18412     1  0 15:37 ?        00:00:00 ora_dbrm_phydb10g
oracle   18414     1  0 15:37 ?        00:00:00 ora_psp0_phydb10g
oracle   18416     1  0 15:37 ?        00:00:00 ora_dia0_phydb10g
oracle   18418     1  0 15:37 ?        00:00:00 ora_mman_phydb10g
oracle   18420     1  0 15:37 ?        00:00:00 ora_dbw0_phydb10g
oracle   18422     1  0 15:37 ?        00:00:00 ora_lgwr_phydb10g
oracle   18424     1  0 15:37 ?        00:00:00 ora_ckpt_phydb10g
oracle   18426     1  0 15:37 ?        00:00:00 ora_smon_phydb10g
oracle   18428     1  0 15:37 ?        00:00:00 ora_reco_phydb10g
oracle   18430     1  0 15:37 ?        00:00:00 ora_mmon_phydb10g
oracle   18432     1  0 15:37 ?        00:00:00 ora_mmnl_phydb10g
oracle   18470 18441  0 15:38 pts/2    00:00:00 grep ora_
[oracle@localhost ~]$ 

             顺带:我们甚至可以看到下述这些有趣的后台进程。

[oracle@localhost ~]$ ps -ef | grep ora_
oracle   18333     1  0 15:35 ?        00:00:00 ora_pmon_phydb10g
oracle   18335     1  0 15:35 ?        00:00:00 ora_psp0_phydb10g
oracle   18337     1  0 15:35 ?        00:00:00 ora_mman_phydb10g
oracle   18339     1  0 15:35 ?        00:00:00 ora_dbw0_phydb10g
oracle   18341     1  0 15:35 ?        00:00:00 ora_lgwr_phydb10g
oracle   18343     1  0 15:35 ?        00:00:00 ora_ckpt_phydb10g
oracle   18345     1  0 15:35 ?        00:00:00 ora_smon_phydb10g
oracle   18347     1  0 15:35 ?        00:00:00 ora_reco_phydb10g
oracle   18349     1  0 15:35 ?        00:00:00 ora_mmon_phydb10g
oracle   18351     1  0 15:35 ?        00:00:00 ora_mmnl_phydb10g
oracle   18402     1  0 15:37 ?        00:00:00 ora_pmon_phydb10g
oracle   18404     1  0 15:37 ?        00:00:00 ora_vktm_phydb10g
oracle   18408     1  0 15:37 ?        00:00:00 ora_gen0_phydb10g
oracle   18410     1  0 15:37 ?        00:00:00 ora_diag_phydb10g
oracle   18412     1  0 15:37 ?        00:00:00 ora_dbrm_phydb10g
oracle   18414     1  0 15:37 ?        00:00:00 ora_psp0_phydb10g
oracle   18416     1  0 15:37 ?        00:00:00 ora_dia0_phydb10g
oracle   18418     1  0 15:37 ?        00:00:00 ora_mman_phydb10g
oracle   18420     1  0 15:37 ?        00:00:00 ora_dbw0_phydb10g
oracle   18422     1  0 15:37 ?        00:00:00 ora_lgwr_phydb10g
oracle   18424     1  0 15:37 ?        00:00:00 ora_ckpt_phydb10g
oracle   18426     1  0 15:37 ?        00:00:00 ora_smon_phydb10g
oracle   18428     1  0 15:37 ?        00:00:00 ora_reco_phydb10g
oracle   18430     1  0 15:37 ?        00:00:00 ora_mmon_phydb10g
oracle   18432     1  0 15:37 ?        00:00:00 ora_mmnl_phydb10g
oracle   18491     1  0 15:41 ?        00:00:00 ora_pmon_phydb11g
oracle   18493     1  0 15:41 ?        00:00:00 ora_vktm_phydb11g
oracle   18497     1  0 15:41 ?        00:00:00 ora_gen0_phydb11g
oracle   18499     1  0 15:41 ?        00:00:00 ora_diag_phydb11g
oracle   18501     1  0 15:41 ?        00:00:00 ora_dbrm_phydb11g
oracle   18503     1  0 15:41 ?        00:00:00 ora_psp0_phydb11g
oracle   18505     1  0 15:41 ?        00:00:00 ora_dia0_phydb11g
oracle   18507     1  0 15:41 ?        00:00:00 ora_mman_phydb11g
oracle   18509     1  0 15:41 ?        00:00:00 ora_dbw0_phydb11g
oracle   18511     1  0 15:41 ?        00:00:00 ora_lgwr_phydb11g
oracle   18513     1  0 15:41 ?        00:00:00 ora_ckpt_phydb11g
oracle   18515     1  0 15:41 ?        00:00:00 ora_smon_phydb11g
oracle   18517     1  0 15:41 ?        00:00:00 ora_reco_phydb11g
oracle   18519     1  0 15:41 ?        00:00:00 ora_mmon_phydb11g
oracle   18521     1  0 15:41 ?        00:00:00 ora_mmnl_phydb11g
oracle   18585     1  0 15:43 ?        00:00:00 ora_pmon_phydb11g
oracle   18587     1  0 15:43 ?        00:00:00 ora_psp0_phydb11g
oracle   18589     1  0 15:43 ?        00:00:00 ora_mman_phydb11g
oracle   18591     1  0 15:43 ?        00:00:00 ora_dbw0_phydb11g
oracle   18593     1  0 15:43 ?        00:00:00 ora_lgwr_phydb11g
oracle   18595     1  0 15:43 ?        00:00:00 ora_ckpt_phydb11g
oracle   18597     1  0 15:43 ?        00:00:00 ora_smon_phydb11g
oracle   18599     1  0 15:43 ?        00:00:00 ora_reco_phydb11g
oracle   18601     1  0 15:43 ?        00:00:00 ora_mmon_phydb11g
oracle   18603     1  0 15:43 ?        00:00:00 ora_mmnl_phydb11g
oracle   18633 18606  0 15:43 pts/2    00:00:00 grep ora_
[oracle@localhost ~]$ 

             

有趣的后台进程
ORACLE_SID ORACLE_HOME INSTANCE_NAME PFILE Process ID 范围
phydb11g /u01/app/oracle inst11g /u01/app/oracle/initphydb11g.ora 18585…18603
phydb11g /u01/app/product/11.2.0/dbhome_1 phydb11g /u01/app/product/11.2.0/dbhome_1/dbs/initphydb11g.ora

18491…18521

phydb10g /u01/app/product/11.2.0/dbhome_1 inst11g /u01/app/product/11.2.0/dbhome_1/dbs/initphydb10g.ora  18402…18432
phydb10g /u01/app/oracle inst10g /u01/app/oracle/initphydb10g.ora 18333…18351

 

              结论:在UNIX、Linux平台上,相同的ORACLE_HOME下不可以同时运行ORACLE_SID相同的多个实例,不同的ORACLE_HOME下可以同时运行ORACLE_SID相同的多个实例!                 

            

发表评论

邮箱地址不会被公开。 必填项已用*标注