ORACLE TWO_TASK環境變數的使用
在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 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: 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
從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中斷開
[oracle@bfapp2 ~]$ sqlplus
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
從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中斷開
當不指定服務名時,由於設定了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
--------------------------------------------------------------------------------
DEMO
SQL> conn
已連線。
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 as sysdba
ERROR:
ORA-01031:許可權不足
SQL> conn as sysdba
ERROR:
ORA-01031: insufficient privileges
SQL> exit
原因很簡單,就是TWO_TASK環境變數的存在,使得SQLPLUS沒有辦法/ as sysdba登陸,而永遠都是 as sysdba。
總結:
1、未設定TWO_TASK環境變數時,不指定服務名連線的預設是ORACLE_SID的值。
2、當設定TWO_TASK環境變數時,不指定服務名連線的預設是TWO_TASK的值。
3、當使用@服務名方式連線時,會忽略ORACLE_SID或TWO_TASK的值。
4、當使用TWO_TASK環境變數時,作業系統驗證登入資料庫的方式被禁止,提示ORA-01031: insufficient privileges。
5、因為TWO_TASK設定後,遮蔽了ORACLE_SID的作用,因此即使對於本地庫,也需要透過SQLNet的方式連線,也就是需要監聽,一般對於從本機訪問本地庫可能不開啟監聽,但此時需要開啟監聽,才能透過@服務名的方式連線到本地庫。
6、補充:tnsnames.ora檔案預設採用的路徑如下:
$HOME(~)/.tnsnames.ora
$TNS_ADMIN/tnsnames.ora
/var/opt/oracle/tnsnames.ora or /etc/tnsnames.ora (depending on platform)
$ORACLE_HOME/network/admin/tnsnames.ora
7、關於TWO和TASK的來源,這個詞來源於20世紀80年代,TWO TASK表示兩個一起工作的含義,僅僅是意會,並不侷限於兩個。
8、個人理解,設定TWO_TASK,能夠覆蓋ORACLE_SID的作用,改變不帶@服務名預設連線的資料庫(本地or遠端),要求所有的sqlplus連線都是透過SQLNet的方式,禁止作業系統驗證。僅此而已。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/751371/viewspace-775363/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【Oracle】-【TWO_TASK】-TWO_TASK環境變數的作用Oracle變數
- TWO_TASK環境變數變數
- 使用TWO_TASK或者LOCAL環境變數變數
- 使用TWO_TASK或者LOCAL環境變數?變數
- 關於two_task,local,oracle_sid三個環境變數說明Oracle變數
- ORACLE 環境變數Oracle變數
- [Oracle] -- 配置Oracle環境變數Oracle變數
- oracle 環境變數 redhatOracle變數Redhat
- oracle環境變數設定Oracle變數
- Oracle環境變數NLS_LANGOracle變數
- oracle中的全域性環境變數配置Oracle變數
- 環境變數變數
- OpenMP 環境變數使用總結變數
- CentOS 6.5 Oracle 環境變數設定CentOSOracle變數
- Oracle 環境變數設定標準Oracle變數
- awk中使用shell的環境變數(轉)變數
- Linux 新增環境變數和刪除環境變數Linux變數
- 簡述SHELL全域性環境變數與局變環境變數變數
- Java 環境變數Java變數
- jdk環境變數JDK變數
- DOS環境變數變數
- env 環境變數變數
- 環境變數path變數
- Java環境變數Java變數
- 配置環境變數變數
- postman環境變數Postman變數
- linux下oracle設定環境變數LinuxOracle變數
- oracle裡面的幾個環境變數表Oracle變數
- java 環境變數的配置Java變數
- jdk環境變數的配置JDK變數
- Bash 中的環境變數變數
- Unix的環境變數(轉)變數
- Unix的環境變數 (轉)變數
- Mac 設定環境變數的位置、檢視和新增PATH環境變數Mac變數
- Rust 使用 dotenv 來設定環境變數Rust變數
- ubuntu JDK 環境變數UbuntuJDK變數
- 配置JDK環境變數JDK變數
- 環境變數詳解變數