U of A University of Arkansas Division of Agriculture

Pictures of chickens, flowers, wheat, a boy looking through a magnifying glass, irrigation pipe, soybean pods, and fruits and vegetables.

Cooperative Extension Service

Cooperative Extension Service

Agricultural Experiment Station

Steve Rea's
Oracle Tips, Tricks, and Scripts

Link to Steve Rea's Oracle Certification graphic


Search | Publications | Jobs | Personnel Directory | Links

Accessing Remote Databases

If you just want to access a database on a different machine than sqlplus is running on (instead of having to append the link name to each SQL statement), you can create an sqlplus session directly to that other machine's database by appending the database connect string to the optional user ID/password parameters to sqlplus (along with setting up tnsnames.ora), such as if your test db is on another machine:

sqlplus myuserid@test_db
sqlplus myuserid/mypswd@test_db

You can also do something similar for Focus for UNIX sessions, appending the connect string to the password value.   If your profile.fex contains a user ID and password, you would have to edit your profile.fex to append that connect string before running Focus, such as in:

UNIX SQLORA CONNECT USER myuserid PASSWORD mypswd@test_db

If your profile.fex prompts for a password, just type in the password with the connect string appended to it (as in mypswd@test_db). You'll probably have to enlarge the password prompt field in your profile.fex file to around 30 characters to accomodate the password and potential connect string, such as in:

-DEFAULT &PASSWORD='                               '

Or, if you want sqlplus and Focus and other processes to always run against a remote database for a particular Oracle SID, you could use the TWO_TASK variable to have those processes to run against your SQL*Net connect string (tnsnames.ora file) for that ORACLE_SID.  This could be set up in your oraenv file so that your users wouldn't have to do anything special (such as appending the connect string) to run against the remote database.  To do this for TEST, put the following at the end of your oraenv file (such as /usr/lbin/oraenv) on your UNIX box (thanks to Dean Harris for this tip):

if [ "$ORACLE_SID" = "TEST" ] ; then
     export TNS_ADMIN=$ORACLE_HOME/network/admin
     export TWO_TASK=test_db
else
     export TNS_ADMIN=
     export TWO_TASK=
fi

(Note that some Oracle upgrades and installations require that TWO_TASK not be set, so, it would probably be best to run those types of tasks from a local Oracle SID.)

When using TWO_TASK, you can also use Server Manager on the local machine (such as on AIX) to shut down and start up a remote database (such as on NT).  To do this, you will need to set up a password file (using orapwd80 on NT; full file pathname must be like <ORACLE_HOME>\database\pwd<SID>.ora) on the remote database, put the "remote_login_passwordfile" parameter into it's init<SID>.ora file (otherwise, you would get "insufficient privileges" when you issued a startup or shutdown command in a local Server Manager session to that remote database), and copy (or ftp) it's init<SID>.ora file from the remote machine to the local machine.  The following example shows this on an NT for database TEST (with ORACLE_HOME being d:\oracle\v805), also deleting the original pwdTEST.ora file (which may be a "hidden" file) created by the initial Oracle Instance Manager run (oradim80) or by an earlier orapwd80 run:

Edit initTEST.ora parameter file (in the d:\oracle\v805\database directory on the NT) to add:
     remote_login_passwordfile = exclusive
Shutdown the database
In an NT Command Prompt shell:
     set ORACLE_SID=TEST
     cd d:\oracle\v805\database
     dir /a:h
     attrib -h pwdTEST.ora
     del pwdTEST.ora
     orapwd80 file=d:\oracle\v805\database\pwdTEST.ora password=<syspassword> entries=5
          (specifing the full file pathname and the SYS user password)
     attrib +h pwdTEST.ora
Startup the database

Then, to be able to issue a startup command on the remote database from a local Server Manager session, copy (or ftp) the init.ora file (initTEST.ora here) from the remote machine to the <ORACLE_HOME>/dbs directory on the local machine (AIX Oracle uses the "dbs" directory, NT Oracle uses the "database" directory).  That way, the local Server Manager session can find the local init.ora file matching that remote database to use for the startup (cute!).  Just be sure that you keep the local and remote copies of the init.ora file in sync!  One problem you might encounter with remote databases is that the "connect internal" command in Server Manager may request a password (which it doesn't do on a local database).  You will need to enter the password for the SYS user for that prompt.

This Page was Last Updated on 06/04/07

You Are Visitor Number

Hit Counter

Link to CES Home PageBack To CES Home Page

Link to Steve Rea's Oracle PageBack To Steve Rea's Oracle Page

Back to top of this pageBack To Top


© 2006
University of Arkansas
Division of Agriculture
All rights reserved.
Last Date Modified 02/09/2008
Webmaster

University of Arkansas • Division of Agriculture
Cooperative Extension Service
2301 South University Avenue
Little Rock, Arkansas 72204 • USA
Phone (501) 671-2000 • Fax (501) 671-2209
 

MissionDisclaimerEEO
PrivacyFOI