TWO_TASK

http://space.itpub.net/4227/viewspace-663069

在Unix和Linux环境下,可以设置TWO_TASK环境变量,当用户连接数据库且没有指定服务名时,会自动利用TWO_TASK的设置作为环境变量连接数据库。
 
当前主机有两个数据库在运行:
[oracle@bfapp2 ~]$ ps -ef|grep ora
ora_pmon_demo2
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和DEMO2两个服务名,分别对应DEMO和DEMO2两个数据库。

检查当前ORACLE_SID环境变量的设置:
[oracle@bfapp2 ~]$ env|grep SID
)IU+K6MM!H6A0ORACLE_SID=demo2
当前环境变量中设置的SID是DEMO2,下面不指定服务名连接数据库:
[oracle@bfapp2 ~]$ sqlplus test/test
SQL*Plus: Release9.2.0.4.0 - Production on星期二5月18 16:45:02 2010
Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

连接到:
Oracle9i Enterprise Edition Release9.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         

[oracle@bfapp2 ~]$ sqlplus test/test@demo
SQL*Plus: Release9.2.0.4.0 - Production on星期二5月18 16:45:27 2010
Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

连接到:
Oracle9i Enterprise Edition Release9.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

当不指定服务名时,由于设置了ORACLE_SID=demo2,因此连接到DEMO2数据库。如果指定DEMO服务名,可以连接到DEMO数据库中。
下面设置TWO_TASK环境变量为demo:
[oracle@bfapp2 ~]$ export TWO_TASK=demo
[oracle@bfapp2 ~]$ sqlplus test/test
SQL*Plus: Release9.2.0.4.0 - Production on星期二5月18 16:45:50 2010
Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
连接到:
Oracle9i Enterprise Edition Release9.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
--------------------------------------------------------------------------------
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:
(^u P.U0`0ORA-01031:权限不足

SQL> conn /@demo as sysdba
ERROR:
ORA-01031: insufficient privileges
SQL> exit
原因很简单,就是TWO_TASK环境变量的存在,使得SQLPLUS没有办法/ as sysdba登陆,而永远都是/@servicename as sysdba。
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值