I really should know this, but would someone tell me how to change the default database on Linux?
For example:
I have a database test1
on server1
with ORACLE_SID=test1
. So, to connect to test1
I can use:
sqlplus myuser/password
Connects to the default database, test1
I would now like the default sqlplus connection to go to database test2
on server server2
.
So, I've updated tnsnames so that the old test1
entry now points to test2@server2
. I've also added a separate entry for test2
that points to the same place. However, the default connection still seems to go to test1@server1
.
The following both work fine and go to database test2
on server2
:
sqlplus myuser/password@test1
sqlplus myuser/password@test2
But the default connection, sqlplus myuser/password
, goes to test1@server1
.
Any ideas?
Thanks.
Every Oracle database contains a SYSTEM tablespace and a SYSAUX tablespace. Oracle creates them automatically when the database is created. The system default is to create a smallfile tablespace, which is the traditional type of Oracle tablespace. The SYSTEM and SYSAUX tablespaces are created as smallfile tablespaces.
Answer: If you are on the Oracle server you can execute the "oraenv" script to re-set your ORACLE_SID and ORACLE_HOME to point to the new database. You can also use Linux command line alias settings for switching between Oracle databases.
Oracle Default Value A column can be given a default value using the DEFAULT keyword. The DEFAULT keyword provides a default value to a column when the Oracle INSERT INTO statement does not provide a specific value. The default value can be literal value, an expression, or a SQL Function, such as SYSDATE.
To expand on kerchingo's answer: Oracle has multiple ways to identify a database.
The best way -- the one that you should always use -- is USER/PASSWORD@SERVER
. This will use the Oracle naming lookup (tnsnames.ora) to find the actual server, which might be on a different physical host every time you connect to it. You can also specify an Oracle connection string as SERVER
, but pretend you can't.
There are also two ways to specify a default server via environment variables. The first is TWO_TASK
, which uses the naming lookup, and the second is ORACLE_SID
, which assumes that the server is running on the current machine. ORACLE_SID
takes precedence over TWO_TASK
.
The reason that you should always use an explicit connect string is that you have no idea whether the user has set TWO_TASK
, ORACLE_SID
, both, or neither; nor do you know what they might be set to. Setting both to different values is a particularly painful problem to diagnose, particularly over the phone with a person who doesn't really understand how Oracle works (been there, done that).
Assuming you're logged into server1, you'll need to connect to test2 using
sqlplus myuser/password@test2
because you have to go through a listener to get to server2. The string test2 identifies an entry in your tnsnames.ora file that specifies how to connect to test2. You won't be able to connect to a different server using the first form of your sqlplus command.
If both instances (test1, test2) were on server1, then you could, as @kerchingo states, set the ORACLE_SID environment variable to point at another instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With