【Oracle】-【TWO_TASK】-TWO_TASK环境变量的作用
[oracle@liu admin]$ more tnsnames.ora
BISAL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = bisal)
)
)
TEST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.x)(PORT = 1524))
)
(CONNECT_DATA =
(SERVICE_NAME = star)
)
)
当前TWO_TASK环境变量为空:
[oracle@liu Desktop]$ echo $TWO_TASK [oracle@liu Desktop]$
当未指定服务名连接数据库时,默认是bisal这个本地数据库,即由系统的ORACLE_SID指定:
[oracle@liu Desktop]$ echo $ORACLE_SID bisal [oracle@liu Desktop]$ env | grep SID ORACLE_SID=bisal [oracle@liu Desktop]$
使用/的方式连接:
[oracle@liu Desktop]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 11 14:38:08 2013 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options SQL> select * from global_name; GLOBAL_NAME -------------------------------------------------------------------------------- BISAL SQL>
设定TWO_TASK=TESTTKT:
[oracle@liu Desktop]$ export TWO_TASK=TESTTKT [oracle@liu Desktop]$ echo $TWO_TASK TESTTKT [oracle@liu Desktop]$ [oracle@liu Desktop]$
使用TESTTKT的用户名登陆,但不指定服务名:
[oracle@liu Desktop]$ sqlplus star/star SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 11 14:39:31 2013 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production With the Partitioning, OLAP and Oracle Data Mining options JServer Release 9.2.0.7.0 - Production SQL> select * from global_name; GLOBAL_NAME -------------------------------------------------------------------------------- ALL9IT2 SQL>
此时默认连接的就是TESTTKT这个远程库了。
此时关闭本地库bisal的监听:
LSNRCTL> stop bisal
验证监听状态:
[oracle@liu Desktop]$ tnsping bisal TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 11-AUG-2013 15:06:18 Copyright (c) 1997, 2005, Oracle. All rights reserved. Used parameter files: /opt/oracle/102/network/admin/sqlnet.ora Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = bisal))) TNS-12541: TNS:no listener
再次连接bisal库:
[oracle@liu Desktop]$ sqlplus bisal/xxx@bisal SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 11 15:04:54 2013 Copyright (c) 1982, 2005, Oracle. All rights reserved. ERROR: ORA-12541: TNS:no listener Enter user-name:
打开监听,再用@bisal的方式连接bisal本地库:
[oracle@liu Desktop]$ sqlplus bisal/xxx@bisal
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 11 14:40:08 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Error accessing PRODUCT_USER_PROFILE
Warning: Product user profile information not loaded!
You may need to run PUPBLD.SQL as SYSTEM
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> select * from global_name;
GLOBAL_NAME
-------------------------------------------