使用TWO_TASK或者LOCAL环境变量

简介: 使用TWO_TASK或者LOCAL环境变量 前一阵子,我遇到一个问题:rman target /链接如下:http://www.itpub.net/thread-1167136-1-1.

使用TWO_TASK或者LOCAL环境变量



前一阵子,我遇到一个问题:
rman target /
链接如下:
http://www.itpub.net/thread-1167136-1-1.html
执行错误,必须输入rman target sys/xxx@yyy 

我记得我以前学习安装oracle 8i的时候,遇到的一个问题,就是ora-12560错误,就是在通过远程桌面登录服务器执行无法执行sqlplus user/passwd,必须加入sqlplus user/passwd@net_name.

关于这个问题,如果google,在许多地方都可以看到这个问题的解决ora-12560,实际上当时我测试过,许多是无效的.如果使用远程桌面,至少在当时我没有解决这个问题的.今天测试终于知道答案,链接如下:

http://davidyu720.itpub.net/post/31716/470434
ORACLE8i本地登录错误ORA-12560: TNS: 协议适配器错误
Windows2003上的ORACLE817,在服务器上不使用连接串登录,直接用SQLPLUS或SVRMGRL本地登录,却报错误ORA-12560: TNS: 协议适配器错误。
找到原因:这是一台终端服务器,在远处终端中登录OS--再登录数据库时,会提示ORA-12560错误。直接在控制台中登录OS--再登录数据库时就正常。
解决办法:无--也许这是8i自己的问题吧。同样的Windows环境下,9i就没有问题--因此就懒得找解决办法了。

我通过vnc登录服务器,确实可以在服务端执行sqlplus user/passwd.而通过远程桌面确实不行.

我记得当时在新闻组提问,对方给出的解决就是定义LOCAL环境变量,当时一试验真的可以,也没有再去想这个问题.

这样在执行rman出错的时候,我自己也习惯的采用定义LOCAL变量的方式,至于这个变量的值是什么我自己也不清楚,我一直以为是oracle_sid. 在sqlplus时发现我发现连接的数据库是远程的数据库,因为我本机的10g,而远程的数据库是8i.

当时事情太多,心里仅仅想着快点解决rman target /的问题.

今天看书<Apress.Expert.Oracle.Database.10g.Administration.Sep.2005.pdf>,才发现P428页:
有如下论述:

Using the TWO_TASK Environment Variable
You can bypass the use of an Oracle Net name by setting the TWO_TASK environment variable (on UNIX/Linux) or the LOCAL environment variable (on Windows).
The TWO_TASK environment variable specifies the connect string for connecting to a remote machine. SQL*Net will check the value of the TWO_TASK environment variable and automatically
add it to your connect string, as shown in the following example:
$ export TWO_TASK=mydb
Once you set the TWO_TASK environment variable, you can connect to the mydb database in the
following way:
$ sqlplus scott/tiger
Note that you didn’t have to use the specification sqlplus scott/tiger@mydb, since you’re using the TWO_TASK variable.On a Windows server, the following is the equivalent for setting the TWO_TASK environment variable:
$ SET LOCAL=<mydb>
$ sqlplus scott/tiger

按照这个的介绍,如果我定义TWO_TASK(linux)或者LOCAL(windows)等于某个net_name,就可以实现在输入sqlplus 不需要在输入@net_name参数(当然服务端监听一定要起来的情况修下).测试一下,果然可以!


UnixLinux环境下,可以设置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)
    )
  )

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

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

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

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

[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,当不指定服务名,OracleTWO_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

 






About Me

...............................................................................................................................

● 本文整理自网络

● 本文在itpub(http://blog.itpub.net/26736162)、博客园(http://www.cnblogs.com/lhrbest)和个人微信公众号(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/

● 本文博客园地址:http://www.cnblogs.com/lhrbest

● 本文pdf版及小麦苗云盘地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 数据库笔试面试题库及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● QQ群:230161599     微信群:私聊

● 联系我请加QQ好友(646634621),注明添加缘由

● 于 2017-06-02 09:00 ~ 2017-06-30 22:00 在魔都完成

● 文章内容来源于小麦苗的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解

● 版权所有,欢迎分享本文,转载请保留出处

...............................................................................................................................

拿起手机使用微信客户端扫描下边的左边图片来关注小麦苗的微信公众号:xiaomaimiaolhr,扫描右边的二维码加入小麦苗的QQ群,学习最实用的数据库技术。

img_e3029f287d989cd04bd75432ecc1c172.png
DBA笔试面试讲解
欢迎与我联系

目录
相关文章
Cannot lock pid file /usr/local/freeswitch/run/freeswitch.pid.
Cannot lock pid file /usr/local/freeswitch/run/freeswitch.pid.
187 0
|
6月前
|
Kubernetes Shell 容器
starting container process caused “exec: \“/bin/bash\“: stat /bin/bash: no such file or directory
starting container process caused “exec: \“/bin/bash\“: stat /bin/bash: no such file or directory
122 0
未解决:lrelease: could not exec ‘/usr/lib/qt5/bin/lrelease‘: No such file or directory
未解决:lrelease: could not exec ‘/usr/lib/qt5/bin/lrelease‘: No such file or directory
137 0
|
JavaScript Unix 开发者
node环境中设置process环境变量
node环境中设置process环境变量
|
开发工具 git
/usr/bin/env: escript: No such file or directory的解决办法
/usr/bin/env: escript: No such file or directory的解决办法
372 0
sublime报错:<Anaconda.anaconda_lib.workers.local-worker>
sublime报错:<Anaconda.anaconda_lib.workers.local-worker>
144 0
sublime报错:<Anaconda.anaconda_lib.workers.local-worker>
|
JavaScript 安全 数据库
nodejs 环境变量process.env的使用
nodejs 环境变量process.env的使用

热门文章

最新文章