Best Methods for Oracle
(Internal Use only)
Author: Stephen Eade
Version: 1.0
Date of Knowledge Article creation: 28/12/07
Knowledge Article Number: 444
CONTENTS
Creation and Preparation...1
Installing a client:...1
Installing an Oracle 9 client ...2
Installing a Oracle 10g client ...17
Database Creation ...32
Some Basics about the way Oracle is structured ...32
Table space and User creation ready for Import...32
Importing and exporting tables within Oracle ...37
Importing...38
Exporting...39
Other information...40
Installing an alternative ODBC driver – via the Universal Installer...40
Running Scripts in Oracle...40
Other methods of setting up a TNS connection ...41
Current Touchpaper central server details ...49
Oracle 9...49
Oracle 10...49
Creation and Preparation
Installing a client:
When you install an Oracle client please install the administration level of the client
as this will give you the additional tools you will require for the implementation of an
Oracle Database. It is best to accept the defaults during this process as it will then
install all the required components for both OLE and ODBC.
During the install it will provide a chance to connect your client to a server, this can
be skipped at this point, but is best configured here as this will update your
TNSNAME.ORA file. I will later in this document also tell you other locations you
can use to alter this file using a GUI. (Note: The connection tool may appear behind
the install application resulting in you thinking that it has failed or hung, if you
ALT+Tab you should be able to move to java based configuration tool. (Formerly the
NET8 configuration tool))
This should of have been provided to you by your oracle database administrator,
normally you will point your Oracle client at the main oracle servers passed in the
main com room, this then will move the load that oracle creates onto those servers
rather than having it on your local machine.
I am going to now move on to cover the installation of Oracle 9 and Oracle 10 clients
with attached screenshots.
Installing an Oracle 9 client
Following are the screenshots showing the steps you need to take to install the client
for Oracle 9i
In order to launch the application install you will need to select the autorun.exe file
from the auto run folder. This will then open a menu, select install/de-install from the
list. This will then after a short period open the dialogue box below.
Select the Administrator level to install, we choose this level of the client install you
ensure we get all the tools and drivers that we will need to access and troubleshoot the
database.
This will then show us a listing of what is going to be installed and the process is ready to start, Press install and the client applications will start to be installed onto the client machine.
Once the installation of the files and the unpacking has completed it will then show
this screen and another will appear either over this one or behind it. Use ALT+TAB in
order to get the screen here to appear in front of above screen, you will not be able to
move the install forward until the Oracle Net Configuration Assistant completes.
Press Next
Select No to setting up a directory configuration, as this is not something that is
required for our products, or client connectivity. Select Next.
Select and move to the right Oracle Names and Host Name, Select Next
As you are connecting to and want to add an oracle 9 server connection you should
select the oracle 8i or later option. This covers Oracle 9i as well. Select Next
Input the service name – this will be the SID that has been provided by your server administrator. Select Next
Enter the IP address or hostname of the server that is running the Oracle 9i Server platform for you, this should have been given to you by your Administrator. Select Next
Select Yes, to perform a test. This will then allow us to make sure that the connectivity exists with the server. Select Next
You will note here that test has failed. This is due to at this point the user and password being set to something that does not have access rights to the server. Click Change login
A new dialogue appears, enter the user and password as given to you by your oracle administrator. Select OK
Once you have done that the value returned by the test should change so that it shows it to be successful. Select Next
Select Next
Select Next
Select Finish. This will close the Net Configuration, and the main setup will move forward (if nor press Next)
Select Exit it will confirm that you want to press exit, select Yes. It will then close the setup application.
The configuration will then be ready for you to proceed to the next step, Database Creation
Installing a Oracle 10g client
The steps for installing an Oracle 10g client are outlined below:
In order to launch the setup program you need to run the oui file from the install folder in the application if the setup file does not launch the java applet. A DOS box will appear and initialise the install of the Oracle universal Installer.
Ensure that Administrator is select in the radio buttons and then select Next (This is to ensure that you get all the tools needed to access the tables and run scripts etc.)
It will now move on and start the Oracle Net configuration section of the install this is where it will configure the access connection to the server, this should have been provided to you via your oracle administrator.
Select next
Select next
Select next
Select Yes, perform a test, Select Next
Adjust the login to that which was provided to you by your Administrator – Select OK
Leave the service name the same as the SID you created, Select Next
Select Next
10 client install.
Database Creation
Following is the methods that can be used to prepare a table space and user for the importing of a database into Oracle.
Some Basics about the way Oracle is structured
The key thing to realise is that Oracle has a very different structure and addressing method when compared to SQL. Oracle will always access the tables via the user – this means that the user is prefixed onto any accessing of a table within Oracle – therefore you can end up with tables in multiple table spaces and locations with the oracle server, and have it access those tables with no issues. The primary reason for this is to allow for clustering and load balancing over several servers, when dealing with large scale databases. As Oracle is a database application mainly designed with large corporate data stores and applications in mind it is geared to cover those styles of data requirements.
Having now understood that the primary access point is user rather than database name, it becomes clear that it is possible to have tables of the same name within the same table space or bucket. If you think of a table space as a container file for tables and data this also help with understanding the differences between Oracle and SQL. The diagram below gives you a good idea of the layers involved in the accessing of a table.
It should be noted that the term database for Oracle is a bit miss leading as the whole instance is the global database that you access, inside this Global Database you create table spaces that contain the tables and data you access.
these is the GUI method. This is the simplest and less risky of the two methods. The other is the use of scripts. Outlined below is the first of these methods.
Method One: GUI
Open your enterprise Manager Console and connect to the database server via your TNS connection – setup during your install. (or setup via the alternative methods stated at the end of this document.)
The create window will appear and give you the fields that need to be filled out in order to create a new table space (bucket) for the tables that you want to add. (This can be skipped as the tables could be placed into the Users table space, however it is best to try and get the tables into their own container so they can referenced by people more used to using SQL.) Input the name of the table space you want to create. Adjust the size of the table space so that it will be large enough for the tables you want to import.
Once you are happy with this then select Create.
Now go back to the tree and select Security and then right click the User item. A window will appear like below:
In this window fill out the username and password fields… I prefer to keep them the same so that we all know the access passwords to connect to that user. This can be done through the use of copy and paste (Crtl+C = copy, Crtl+V = paste)
Alter the default table space to the table space you just created this should then by default place the users tables into the correct table space. (Note: See the importing section of this document for further details.)
Ensure that the user you are creating has the Resource role also, it should have the connect role by default. DO NOT under any circumstances give a new user the DBA role – as this could cause you serious connectivity issues.
Select Create.
You are now ready to do the import of the tables.
Method Two: Scripts
Open the SQL Plus tool from the Application Development Program group on your Start menu programs group for Oracle.
In the window that appears enter the connection information it requests as per the details provided to you by your Oracle Administrator; for example:
User Name: System Password: Touchpaper Host String: <TNSNAME>
The TNSNAME here is the one that you created during your installation or via the other methods explained later.
Cut and paste the following scripts into the tool, replace the items within < > with the values you need to use.
create tablespace <NAME of Tablespace you want to create, for example TPAPER> nologging
datafile 'c:\<NAME of Tablespace you want to create >.dbf' size 50M
autoextend on
extent management local uniform size 64K;
create user <NAME of User you want to create> identified by <NAME of User you want to create>
default tablespace <NAME of Tablespace you want to create > temporary tablespace temp
quota unlimited on <NAME of Tablespace you want to create >;
This script will have then created a talble space and user for your use in the import of the tables and data into Oracle for your use. Both methods are acceptable and can be used to create the required items for your use. It is your own preference that is used to determine which method is used.
Importing and exporting tables within Oracle
Import and Exporting data in Oracle will be on of the key things that you will do in order to troubleshoot and alter customer databases. There are some very important things to
remember when doing this, as it could serious issues for both yourself and or your customer. I will now attempt to list these for you.
The user name that the tables were exported as will be the username that you will need in order import them into your schema without importing anything else that the customer has sent you, it is important to do this as it could serious impact the functioning of the oracle instance.
If a table space exists within the instance that matches the one that the tables were exported from it will place them back into that table space even if you have adjusted the default table for the user, this should not be an issue, but it is something you need to be aware of as it might impact your scripting or adjustments.
Often tables can only be restored into a table space the same as that on the customers oracle instance, this often is the result of the way that the User defined objects and tables are created with the application code. This is why it is important to get the user and table space name details from the customer. As you need to have this information to hand when doing the imports. NOTE: you do not need any of the customers oracle passwords – so do not ask for those – this will help your customer maintain their own security.
When it comes to doing exports it is quite straight forward, and this is the easy part of doing imports and exports.
Importing
The steps needed to use the import tool and some things you can do to help with the process, Open a Command window on a machine which has the Oracle client installed and a working connection to the server, complete the creation of a user and table space for the tables you want to restore.
Within the Command window browse to the location of the dump file that has been provided to you by the customer. (Ensure that this has been unpacked and is in a *.dmp format) Once there enter the following command into the dos prompt.
Imp system/<password>@< TNSSERVICENAME > file=<name of Dmp file> log=<logfile name>.log fromuser=<user that owns the tables> touser=<user created by you to hold tables>
This will restore the tables, sequences, and other items that are owned by a user into your schema on the server, it should be noted that import and export CANNOT transfer triggers. It should be noted that you may find that you get some errors during the import, these are often due to several factors, if you get errors, resolve the issue and then rerun the import using the parameters as above.
The table cannot be created due to being unable to create the initial extent, this means the table space you are importing into has run out of space, and you need to adjust it to give the tables the space to be restored into, this might be due to the table space being used not being the one expected.
The Table already exists, if this is a rerun of the import to get the missed tables then this is not an issue, however if you want to restore over the existing tables owned by the user you will need to drop those from the schema in enterprise manager or via script. It is important that you do this first. (This will be a common error when rerunning the import to resume the restore.)
Unable to create table due to <TABLESPACE> does not exist, this happens when the import is attempting to restore tables into a specific table space, due to the table reference being an integral part of the table, due to the application creation of the table. Create the missing
table space.
There are several other options and parameters that can be used to alter the import these are listed in the parameters section below:
UserID <USERNAME./<PASSWORD>@<TNSSERVICENAME>
This the user that you are logging onto the instance with – will normally be the System account at a TNS for example system/touchpaper@ora9ops
File = <FILENAME>.dmp
This the DMP that is to be restored to Oracle instance that you are working on, it contains the table and data exported by the customer.
Log= <FILENAME>.log
Output that records the output of the import process for future review, best to create this file as often errors can disappear from the command window before you can see them, best to review this log after the import to ensure all has worked as expected.
Fromuser =<USERNAME>
This is the user that owns the tables on the customers Oracle instance – Should be the user that the export was done as.
Touser = <USERNAME>
user were you want to import the tables into on the instance you are using, this should be the user you have just created
Full = y/n
Restores the whole contents of the DMP into your instance, this includes user passwords, schema changes and data from other users. This should ONLY be used with a show = as this can cause the complete Oracle Instance / Global Database to become inaccessible, and may result in the oracle instance needing to be rebuilt
Show = y/n
This will show the contents of the dmp file without actually importing the contents into the Oracle instance, the user of this parameter is the only time that you should ever use the full parameter.
Tables = (<tablename>, <tablename>)
This is the parameter that allows you import specific tables only, so if you decide you need to only replace a certain table this parameter can be used to restore just that table, if you should decide to only import just the tables but you want them all a (*) can be used.
There are many more errors and parameters that occur or can be used with regards to importing, but if the above problems do not cover the issues then I would suggest that you need to talk to your Oracle Administrator.
Exporting
Exporting can be done with the following statement from within the DOS command prompt window.
Browse to the location where you want to create the DMP and LOG file.
Exp <User that owns the tables>/<that users password>@<TNSSERVICENAME> file=<FILENAME>.dmp Log=<FILENAME>.log
This simple version of the export will export all the tables that belong to the user that owns the tables that you want to export. There are many more parameters that can be used but they
sending database back to them. It is always best to try and include the log file with any export when sending it out to anyone as this can then be used a reference for when doing the import.
Other information
Installing an alternative ODBC driver – via the Universal
Installer
You may find that you need to update or upgrade your Oracle ODBC drivers, (this tends to be on older versions of oracle like Oracle 9)
In order to do, this unpack the ODBC driver to a local directory like C:\ttemp
Once this has completed then launch the Universal Installer and proceed through the program until you get to the location as shown below:
Select browse on the Source location and browse to the unpacked files on your local machine. The Application is looking for the product.jar file
This should then alter the application that it is installing to the ODBC driver upgrade, Select Next and follow the basic defaults through the application until you get to the option to Exit.
Running Scripts in Oracle
Scripts can be run in oracle much like in SQL, however in order to do so you need to be able to access the tables and user you wish to alter the values in the data in.
The way to do this is via the SQL Plus tool – the thing to remember here is to log onto the Oracle tool with the USER that connects you to only the tables you need to adjust and not to logon to the Scripting tool with the System Account.
If you need to adjust the values of data in tables this can also be done via the Enterprise Manager, by going to the Schema section of the Tree and selecting the user you are looking at and then the tables that are associated with them, right click the table you need to adjust and then selecting View/Edit Contents – if you are interested in the Script needed to do the thing you just adjusted before you do so… you can click Show SQL and it will show you a script that will do that for you. – BE warned – those scripts can be very large and dangerous if used on for other adjustments.
Other methods of setting up a TNS connection
Database Enterprise Manager – Add Tree
Another of the methods that can be used to create a TNS connection is the Add Database To Tree window that is found inside the Oracle Enterprise Manager. From the Navigator menu – select the option of the same name this window will appear.
The addition of a database from details manually here will add it to the list of available connections in the ODBC, OLE and database listings for future use.
Note: you can add to the enterprise manger in this window connections you have created elsewhere for use. (see other options in this section.)
install)
The most common method for many is to use the Net Configuration Tool, this can be found in the Configuration and Migration Tools section of the Oracle Program Group.
Select Add then Select Next. As you can see here you can test, modify and delete
other TNS connections that you have, this is a good method of troubleshooting your
connections, as if this tool is unable to connect this is a serious issue with
connectivity, however if it can connect via a test then you can confirm that the Oracle
component of the connection is working as expected.
As you are connecting to and want to add an oracle 9 server connection you should
select the oracle 8i or later option. This covers Oracle 9i as well. Select Next
Input the service name – this will be the SID that has been provided by your server administrator. Select Next
Enter the IP address or hostname of the server that is running the Oracle 9i Server platform for you, this should have been given to you by your Administrator. Select Next
Select Yes, to perform a test. This will then allow us to make sure that the connectivity exists with the server. Select Next
You will note here that test has failed. This is due to at this point the user and password being set to something that does not have access rights to the server. Click Change login
A new dialogue appears, enter the user and password as given to you by your oracle administrator. Select OK
Once you have done that the value returned by the test should change so that it shows it to be successful. Select Next
Select Finish. This will close the Net Configuration
TNSNames.ora file
The other method is to directly adjust the tnsnames.ora file – this often is done as a last resort method of creating a connection, as an error in this file can cause errors in the connection to the servers you are using.