Client Server archives - SA-DBA

SA-DBA:

client server

Jul 14 2009   1:52PM GMT

TWO_TASK… an oldie but a goodie…



Posted by: Richard Evans
environment variable, TWO_TASK, connection string, client server

TWO_TASK is a very useful but often forgotten environment variable. We actually just used it again the other day and we’re always scratching our head saying “ok, I remember there is this variable we can set to do that… umm… it’s… hmm, let me google and I’ll get right back to you.”

Because it’s an obscure name — maybe someone could explain to me why it’s named TWO_TASK? — it’s often hard to locate.

From the same document I referenced in my last post, the SQL*Plus User’s Guide and Reference, TWO_TASK is:

UNIX environment variable to specify a connection string. Connections that do not specify a database will connect to the database specified in TWO_TASK.

Example

TWO_TASK=MYDB
export TWO_TASK
sqlplus hr
is the same as:

sqlplus hr@MYDB

We use this a lot when we separate an application from the DB. We try to keep applications on their own servers (in their own zones) and our DBs on their own servers (in their own zones as well). Often times, by default, vendor software doesn’t want to play nice when it isn’t on the same machine as the DB. TWO_TASK is often a clever way to get around that!

In this scenario, I’m logged on to a Solaris Zone with Oracle 10g Client software installed.

[oracle: /oracle] echo $TWO_TASK

[oracle: /oracle] sqlplus system

SQL*Plus: Release 10.2.0.4.0 - Production on Tue Jul 14 08:48:16 2009

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Enter password:
ERROR:
ORA-12545: Connect failed because target host or object does not exist

Enter user-name: ^C
[oracle: /oracle] export TWO_TASK=DDSC1
[oracle: /oracle] sqlplus system

SQL*Plus: Release 10.2.0.4.0 - Production on Tue Jul 14 08:48:27 2009

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Enter password:

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

Now my application can be tricked into thinking the database is local. You don’t need to try to muck with any “@DBNAME” connection string.