connecting to remote db from unix script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting connecting to remote db from unix script
# 1  
Old 09-04-2007
Java connecting to remote db from unix script

Hi everybody,

My bash script is trying to connect to a remote database using the 'sqlplus' binary.For this i set(export) the variable TWO_TASK to the value of database name excluding the dot extension part.

Can anyone explain me what's the significance of this TWO_TASK variable while connecting to a remote database and how the flow is happening?

Your help is appreciated

With Regards
Dileep Pattayath
# 2  
Old 09-05-2007
It's very simple: the variable TWO_TASK defines the connect string used by sqlplus for connecting to a remote db.

For example, if you issue:

Code:
$ORACLE_HOME/bin/sqlplus scott/tiger@remote_db

will be the same as:

Code:
export TWO_TASK=remote_db
$ORACLE_HOME/bin/sqlplus scott/tiger

# 3  
Old 09-05-2007
Quote:
Originally Posted by robotronic
It's very simple: the variable TWO_TASK defines the connect string used by sqlplus for connecting to a remote db.

For example, if you issue:

Code:
$ORACLE_HOME/bin/sqlplus scott/tiger@remote_db

will be the same as:

Code:
export TWO_TASK=remote_db
$ORACLE_HOME/bin/sqlplus scott/tiger

So if i entered the command
Code:
$ORACLE_HOME/bin/sqlplus scott/tiger

the value of TWO_TASK is identified and it will match the same in the tnsentry(tnsnames.oa file)and fetches the host name and port and then establish a connection to it.Correct me if am wrong.
My intention is to understand the flow of establishing the db connection.
# 4  
Old 09-05-2007
Yes it's right. The connect string's part after the "@" character (or the evaluated TWO_TASK variable) must always be resolved into 4 pieces of information: an IP address and port number of a remote listener, the network protocol and the instance name you wish to connect to. If you use local naming resolution (tnsnames.ora on the client side), then the alias you specify has all the informations oracle needs for contacting the remote site and asking the listener to spawn a new server process (or redirect your request to a dispatcher if you're using mts) and initiate a session for serving your request.
# 5  
Old 09-06-2007
Quote:
Originally Posted by robotronic
Yes it's right. The connect string's part after the "@" character (or the evaluated TWO_TASK variable) must always be resolved into 4 pieces of information: an IP address and port number of a remote listener, the network protocol and the instance name you wish to connect to. If you use local naming resolution (tnsnames.ora on the client side), then the alias you specify has all the informations oracle needs for contacting the remote site and asking the listener to spawn a new server process (or redirect your request to a dispatcher if you're using mts) and initiate a session for serving your request.
Ok.fine i understood,but i am confused at the line in red in your reply.What is mts?Is it any method of connecting to a remote database without using tnsnames.ora file?
# 6  
Old 09-06-2007
MTS are Multi-Threaded Servers, also called Shared Servers. It's an option you can configure on the db server (only if you really need it).

Usually, if MTS are not configured, your client contacts the remote listener, which spawns a Dedicated Server Process on an assigned port and puts in communication your user process with the server process. At this point the listener has finished its work and your client is in direct contact with a dedicated process (oracle<$SID>) on a dedicated port which serves only your session.

If you configure MTS on the server-side, instead, new processes are involved in the connection mechanism. First, at the instance startup, are spawned one or more Dispatcher Processes (ora_dNNN) and one or more Shared Server Processes (ora_sNNN). In this case, when your client asks the remote listener for establishing a session, the listener will not spawn any new process: it will simply tell your user process a port number on which a pre-started dispatcher process is listening. Your user process will then send the sql statements to the dispatcher, and the dispatcher puts the request in a common input queue. All the shared server processes are continuosly monitoring the common queue and pick up requests for executing the work. When the work is done, the result will be putted in the response queue of the dispatcher which made the request and the dispatcher fetches the result back to the user process.

MTS are used when the number of connections made to the db is so high that spawning a dedicated server process for each session will reduce the server performance due to the continuos context switches the OS has to do for mantaining all the processes active.
# 7  
Old 09-06-2007
Quote:
Originally Posted by robotronic
MTS are Multi-Threaded Servers, also called Shared Servers. It's an option you can configure on the db server (only if you really need it).

Usually, if MTS are not configured, your client contacts the remote listener, which spawns a Dedicated Server Process on an assigned port and puts in communication your user process with the server process. At this point the listener has finished its work and your client is in direct contact with a dedicated process (oracle<$SID>) on a dedicated port which serves only your session.

If you configure MTS on the server-side, instead, new processes are involved in the connection mechanism. First, at the instance startup, are spawned one or more Dispatcher Processes (ora_dNNN) and one or more Shared Server Processes (ora_sNNN). In this case, when your client asks the remote listener for establishing a session, the listener will not spawn any new process: it will simply tell your user process a port number on which a pre-started dispatcher process is listening. Your user process will then send the sql statements to the dispatcher, and the dispatcher puts the request in a common input queue. All the shared server processes are continuosly monitoring the common queue and pick up requests for executing the work. When the work is done, the result will be putted in the response queue of the dispatcher which made the request and the dispatcher fetches the result back to the user process.

MTS are used when the number of connections made to the db is so high that spawning a dedicated server process for each session will reduce the server performance due to the continuos context switches the OS has to do for mantaining all the processes active.
great!!I have some more queries related to this.In some of the scripts i saw some settings other than what we discussed till now as given below.Can you please give the instance when these was used and why?

export ORAENV_ASK=NO/YES
export ORACLE_SID="INRDELP1" (Oracle instance name)
export GLOBAL_NAME="INDBR432_INRDELP1.world" (Oracle database name with suffix)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Connecting to Windows server from UNIX through script

I am trying to connect to a Windows server say 10.1.1.10. This servers has a folder named RAJ in which there are multiple .zip files. All these zip files contain a text file called XYZ.txt. Now i have to merge the content of these XYZ.txt files from each of the .zip file and create a new text... (1 Reply)
Discussion started by: swapniljadav
1 Replies

2. Shell Programming and Scripting

Connecting to remote host

Checking crontab job entry in 3 different hosts Hi Gurus, I am trying to connect to remote host from current host to check crontab entries. I have started like this ssh -n -l db2psp 205.191.156.17 ". ~/.profile >/dev/null 2>/dev/null; cd log ;ls | wc -l" I got this error ? ssh:... (1 Reply)
Discussion started by: rocking77
1 Replies

3. UNIX for Dummies Questions & Answers

SQL block in a Shell Script connecting to a local and remote DB

Hi All, In a Shell scriipt with a SQL block I want to issue a query against a local DB and a remote DB on a remote server. The shell script is running locally. This is how I connect to the local server. But I want the query to reference remote table in the join. Question can I specify a... (1 Reply)
Discussion started by: daveu7
1 Replies

4. Shell Programming and Scripting

Triggering remote UNIX shell script from Remote desktop

I m trying to run a batch script in remote desktop which executes unix commands on the unix server...the problem is i wnt the output in HTML format.so in my batch script i m giving the cmd like ssh hostname path ksh HC_Report.ksh>out.html ...but it generates the HTML file in remote desktop .i... (2 Replies)
Discussion started by: navsan
2 Replies

5. Shell Programming and Scripting

connecting to table to extract multiple rows into file from unix script

I need to extract the data from oracle table and written the below code. But it is not working.There is some problem with the query and output is shown is No rows selected" . If I run the same query from sql developer there is my required output. And if I run the shell script with simple sql... (7 Replies)
Discussion started by: giridhar276
7 Replies

6. UNIX for Advanced & Expert Users

Unix FTP Script connecting through proxy Not working

Hi All, can some one please help me to solve this issue, its urgent:confused: We need to FTP a file form our Unix server to an external client FTP location. I am trying to connect to the proxy server first and then use the below USER comment to connect to the external FTP server, and its working... (3 Replies)
Discussion started by: JesusJoseph
3 Replies

7. Ubuntu

Connecting to a remote server

Hi, I have an interesting problem. I cannot connect to a personal server I set up. What's interesting is that I can connect to it from the LAN using its non-local IP address. However, I cannot seem to connect to it from anywhere else. Here's how my server is set up: My entire home has a... (8 Replies)
Discussion started by: Altay_H
8 Replies

8. Shell Programming and Scripting

ssh script for connecting unix system.

Hi All, I've a log file call netbackup.log in all the 5 servers in location usr/netbackup.log. I dont want to login in each server and check the log file. So i wanted to have a script written to have the log information at one place. I want to have the last 2 lines from the file... (2 Replies)
Discussion started by: suri.tyson
2 Replies

9. Shell Programming and Scripting

Connecting to remote unix server using java?

I need help writing java code that can connect to a remote unix server, and run a script on that server. I have scoured the internet, but I have been unable to find proper documentation on how this can be accomplished. Any help is appreciated thanks. (1 Reply)
Discussion started by: developncode
1 Replies

10. Shell Programming and Scripting

Connecting and Querying DB2 database from Unix Script?

I am trying to develop a script that can connect to a DB2 database mainframe and Query the database and display the results. I've been researching, but I have yet to find a definitive solution where I can enter in the Mainframe DB2 address db2:// and query the database and return the results. If... (2 Replies)
Discussion started by: developncode
2 Replies
Login or Register to Ask a Question