ITPub博客

首页 > Linux操作系统 > Linux操作系统 > TWO_TASK环境变量

TWO_TASK环境变量

原创 Linux操作系统 作者:yangtingkun 时间:2010-05-18 23:56:16 0 删除 编辑

在Unix和Linux环境下,可以设置TWO_TASK环境变量,当用户连接数据库且没有指定服务名时,会自动利用TWO_TASK的设置作为环境变量连接数据库。

 

 

当前主机有两个数据库在运行:

[oracle@bfapp2 ~]$ ps -ef|grep ora
oracle    3899     1  0 May17 ?        00:00:00 ora_pmon_demo2
oracle    3901     1  0 May17 ?        00:00:00 ora_dbw0_demo2
oracle    3903     1  0 May17 ?        00:00:01 ora_lgwr_demo2
oracle    3905     1  0 May17 ?        00:00:01 ora_ckpt_demo2
oracle    3907     1  0 May17 ?        00:00:01 ora_smon_demo2
oracle    3909     1  0 May17 ?        00:00:00 ora_reco_demo2
oracle    3911     1  0 May17 ?        00:00:00 ora_cjq0_demo2
oracle    3913     1  0 May17 ?        00:00:18 ora_qmn0_demo2
oracle    3915     1  0 May17 ?        00:00:00 ora_s000_demo2
oracle    3917     1  0 May17 ?        00:00:00 ora_d000_demo2
oracle    3942     1  0 May17 ?        00:00:00 /oracle/ora9/product/9.2/bin/tnslsnr LISTENER -inherit
oracle    4787     1  0 May17 ?        00:00:00 ora_pmon_demo
oracle    4789     1  0 May17 ?        00:00:01 ora_dbw0_demo
oracle    4791     1  0 May17 ?        00:00:00 ora_lgwr_demo
oracle    4793     1  0 May17 ?        00:00:00 ora_ckpt_demo
oracle    4795     1  0 May17 ?        00:00:02 ora_smon_demo
oracle    4797     1  0 May17 ?        00:00:00 ora_reco_demo
oracle    4799     1  0 May17 ?        00:00:00 ora_cjq0_demo
oracle    4801     1  0 May17 ?        00:00:00 ora_s000_demo
oracle    4803     1  0 May17 ?        00:00:00 ora_d000_demo
oracle    4807     1  1 May17 ?        00:17:53 ora_j000_demo
oracle    5175     1  0 May17 ?        00:00:01 oracledemo (LOCAL=NO)
root      8812  3444  0 16:02 ?        00:00:00 sshd: oracle [priv]
oracle    8814  8812  0 16:02 ?        00:00:00 sshd: oracle@pts/1
oracle    8815  8814  0 16:02 pts/1    00:00:00 -bash
oracle    8841  8815  0 16:44 pts/1    00:00:00 ps -ef
oracle    8842  8815  0 16:44 pts/1    00:00:00 grep ora

一个实例名为demo,另一个为demo2。

看看tnsnames.ora中的配置:

[oracle@bfapp2 ~]$ more $ORACLE_HOME/network/admin/tnsnames.ora
demo =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.13.149)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = demo)
    )
  )

demo2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.13.149)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = demo2)
    )
  )

本地服务名中配置了DEMO和DEMO2两个服务名,分别对应DEMO和DEMO2两个数据库。

检查当前ORACLE_SID环境变量的设置:

[oracle@bfapp2 ~]$ env|grep SID
ORACLE_SID=demo2

当前环境变量中设置的SID是DEMO2,下面不指定服务名连接数据库:

[oracle@bfapp2 ~]$ sqlplus test/test

SQL*Plus: Release 9.2.0.4.0 - Production on 星期二 5月 18 16:45:02 2010

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.


连接到:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select * from global_name;

GLOBAL_NAME
--------------------------------------------------------------------------------
DEMO2.US.ORACLE.COM

SQL> exit          
从Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
中断开
[oracle@bfapp2 ~]$ sqlplus test/test@demo

SQL*Plus: Release 9.2.0.4.0 - Production on 星期二 5月 18 16:45:27 2010

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.


连接到:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select * from global_name;

GLOBAL_NAME
--------------------------------------------------------------------------------
DEMO

SQL> exit
从Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
中断开

当不指定服务名时,由于设置了ORACLE_SID=demo2,因此连接到DEMO2数据库。如果指定DEMO服务名,可以连接到DEMO数据库中。

下面设置TWO_TASK环境变量为demo:

[oracle@bfapp2 ~]$ export TWO_TASK=demo
[oracle@bfapp2 ~]$ sqlplus test/test

SQL*Plus: Release 9.2.0.4.0 - Production on 星期二 5月 18 16:45:50 2010

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.


连接到:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select * from global_name;

GLOBAL_NAME
--------------------------------------------------------------------------------
DEMO

SQL> conn test/test@demo2
已连接。
SQL> select * from global_name;

GLOBAL_NAME
--------------------------------------------------------------------------------
DEMO2.US.ORACLE.COM

由于设置了TWO_TASK,当不指定服务名,Oracle将TWO_TASK设置的变量作为默认服务名,因此连接到DEMO数据库中。如果指定服务名连接,则不受TWO_TASK环境变量的影响。

需要注意一点,使用了TWO_TASK环境变量后,无法使用操作系统验证登陆数据库:

SQL> conn / as sysdba
ERROR:
ORA-01031: insufficient privileges


警告: 您不再连接到 ORACLE。
SQL> conn /@demo2 as sysdba
ERROR:
ORA-01031:
权限不足


SQL> conn /@demo as sysdba
ERROR:
ORA-01031: insufficient privileges


SQL> exit

原因很简单,就是TWO_TASK环境变量的存在,使得SQLPLUS没有办法/ as sysdba登陆,而永远都是/@servicename as sysdba。

 

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

请登录后发表评论 登录
全部评论
暂无介绍

注册时间:2007-12-29

  • 博文量
    1964
  • 访问量
    11077106