101communication LLC CertCities.com -- The Ultimate Site for Certified IT Professionals
   Certification Communities:  Home  Microsoft®  Cisco®  Oracle®  A+/Network+"  Linux/Unix  More  
Editorial
Choose a Cert
News
Exam Reviews
Features
Columns
Salary Surveys
Free Newsletter
Resources
Forums
Practice Exams
Cert Basics
Links Library
Tips
Pop Quiz
Industry Releases
Job Search
Conferences
Contributors
About Us
Search


Advanced Search
CertCities.com

CertCities.com
Let us know what you
think! E-mail us at:
.. Home .. Certifications .. Oracle .. Columns ..Column Story Thursday, July 03, 2003

TechMentor Conference & Expo PDF Brochure - Download It Now!

 SELECTions   Damir Bersinic
Damir Bersinic



 Have Data, Will Travel
Transporting tablespaces in Oracle 8i.
by Damir Bersinic  
2/14/2001 -- A client recently came to me to see if there was a better way to keep their regional offices updated with pricing on over a million part numbers that they have. The current method was not working, and the problem was compounded by the fact that bill of materials explosions required to price things properly in their manufacturing process changed on a regular basis and had a symbiotic relationship with the part numbers.

Up to this point they performed bulk loads of the changed data and objects at the regional offices on a monthly basis using SQL*Loader and scripts. Although the interval for updates was not going to change, to create indexes and other objects took the better part of a weekend and left almost no time to correct problems if they occurred. In a few cases, Monday morning operations, such as processing orders, had to wait until Tuesday because of problems with the load.

This problem is really one of "What's the fastest and easiest way to get data from one Oracle database to another with the lowest possibility of failure?" In looking at the problem, at least four ways exist to solve it:

  • Using Oracle's Export and Import utilities -- This method will extract the tables and its dependent objects from the source database (using the EXP utility) and create an Oracle proprietary file that can be imported into the target database (using the IMP utility). This method can be scripted and is conceptually simple. However, it will need to drop and re-create the objects in the target system making it slow. Probably not a good choice for this problem.

  • Using scripts and the SQL*Loader utility -- Similar to Export and Import, this method can be scripted and will work. However, the client already indicated that it takes too long so it is not appropriate. However, if we needed to get data from a third-party data source into Oracle, this would be a good way of doing it.

  • Using Distributed Database and Replication -- While this method will ensure that data exists on both servers, based upon how distribution is configured, it may require permanent network connections and may generate a lot of traffic on the pipe between the head office and the regional offices. If you've tried to configure replication and/or distributed database with Oracle before, you'll know that this is not the easiest thing to do. In any case, it won't work for this client as regional offices do not have much available bandwidth, and they're not likely to get more in the short term.

  • Using Transportable Tablespaces -- In Oracle 8i you can transport an entire tablespace, including its contents (tables, indexes, etc.), from one database to another. Because the data for the part numbers, bill of materials, and other required elements were contained on a single tablespace (or could be moved there by using Oracle 8i's ALTER TABLE … MOVE command) this was the chosen method. Let's look at this in more detail.

Oracle 8i's Tablespace Enhancements
Prior to Oracle 8i, management of extents allocated to segments was done by making changes to the data dictionary every time a new extent had to be allocated to a table, index or cluster. This created inefficiency as the act of allocating additional storage to an object required a hit on the SYSTEM tablespace, which now became a potential point of contention. Ways to avoid this were to carefully size extents and allocate them manually to minimize the hit.

With 8i, it is now possible to manage the extents on a tablespace locally on that tablespace. This is done by specifying the EXTENT MANAGEMENT LOCAL option when issuing the CREATE TABLESPACE command. This tells Oracle to manage the allocation of extents to objects on the tablespace by using a set of bitmaps on the tablespace instead of in the data dictionary. This also has the added benefit of allowing the tablespace to exist as a self-contained unit with all the information about storage allocation for objects created on the tablespace within the contents of the data files that it is composed of. In other words, it now becomes possible to take the tablespace on the road and transport it.

Just Like Airfares, Transporting Tablespaces Has Rules
Before you can take the contents of a tablespace on the road, you need to make sure that all the pieces on it are O.K. -- kinda like making sure the whole family is in the car before starting to drive off (and that nobody chained the bumper to the house!). To transport a tablespace, the databases for the source and destination need to be almost identical, which means:
  • Same DB_BLOCK_SIZE for both databases.
  • Same Character Set and National Language Character Set for both databases.
  • Same operating system for both databases.
  • The tablespace to be transported must not have any function-based indexes, scoped REFs, domain indexes or use any Oracle 8.0 advanced queuing functionality.
  • All data must be self-contained: indexes and tables on the same tablespace, BLOBs and data segments on the same tablespace, parent and child tables in a primary key-foreign key relationship on the same tablespace (though you can choose not to transport all of the PK-FK data), all partitions for a table must be on the same tablespace, etc.
  • The tablespace name must not exist on the target database. If it does, it needs to be deleted before the source tablespace is attached to the destination database.

In the case of my client, not all of these were true, but the major ones (same operating systems, dB_BLOCK_SIZE, character set, etc.) were, so all we had to do was move indexes to the tablespace from their previous location and ensure that all the elements needed were in one spot.

The Car is Loaded, Lets Move that Tablespace!!
In order to transport a tablespace from one database to another, you perform the following steps:

  1. Ensure that the data on the tablespace is self-contained. This is done by running the DBMS_TTS.TRANSPORT_SET_CHECK procedure passing it the name of the tablespaces you want to transport. This procedure populates a view called TRANSPORT_SET_VIOLATIONS that you can query to see if you have any errors that would cause the transport to fail. If you do, correct them and try again.
  2. Generate a Transportable Tablespace Set that includes a list of all the objects on the tablespace that can be imported on the destination database. This is done by first altering the tablespace to be transported to READ ONLY and making a copy of the data files belong to the tablespace after doing so.
  3. You then run the EXP utility to extract the data dictionary information to be imported into the destination database. To do this, pass the EXP utility the TRANSPORT_TABLESPACE=y parameter, along with the names of tablespaces to be transported, and whether or not to export constraints, security, and other settings. You now have a set of data files (with all the data) that can be copied to the destination database, as well as an Oracle export file that can used to create the data dictionary information about the objects in the datafiles.
  4. Alter the tablespace back to READ WRITE mode in the source database so that the next round of updates can be started.
  5. Transport the export file and data files to the destination database. You can use CD, tape, ZIP file or any other method that makes sense, based upon your data size.
  6. If the tablespace to be attached to the destination database already exists, drop it along with its contents. This will be true where you are frequently updating data transferred from a central office to a branch office, as is the case here. Issue the DROP TABLESPACE command with the INCLUDING CONTENTS CASCADE CONSTRAINTS parameters.
  7. Copy the data files from the source system to the hard disk on the destination (make a note of where they are as you will need this later).
  8. Run the IMP utility to import data dictionary information. You need to specify the TRANSPORT_TABLESPACE=y parameter and the DATAFILES parameter, followed by the physical location of the datafiles on the destination computer's hard disk. If the users who own the objects in the tablespace do not exist in the destination database, you may also need to use the FROMUSER and TOUSER parameters. This is a relatively quick process, as only the data dictionary information about the objects on the tablespace is added since the data is already in the datafiles.

If you want to make modifications on the destination database, you can alter the tablespace to READ WRITE, although in this client's case we left the tablespace READ ONLY as all updates were made at the central office.

Still Seems Like a Lot of Work To Me!
While the steps required to move the entire contents of a tablespace from one database to another may appear restrictive, keep in mind that you can move more than one tablespace at a time to ensure all data is self-contained. It is also easier to copy files and run an IMP command on the destination database than to use SQL*Loader or a series of export files, and SQL scripts to create the indexes after the fact. Furthermore, the central office can now specify the storage parameters for tables and indexes ensuring that space is used efficiently and not leave this up to the regional admins or Oracle defaults.

The end result in my client's case? More control and fewer errors. It also allowed them to keep a copy of each update sent to the regional offices on a CD-ROM, along with the export files in case they needed to go to an earlier incarnation of the database structure -- an added bonus.

By the way, did you notice that the database instances never had to be shut down to do this in either the source or destination?

Damir Bersinic is an independent consultant, trainer, and author of Oracle 8i DBA: SQL & PL/SQL Certification Bible (ISBN 0764548328), Oracle 8i DBA: Architecture and Administration Certification Bible (ISBN 0764548174) from Wiley & Sons, as well as a number of titles on Windows, Active Directory and SQL Server. He holds several industry designations including Oracle OCP DBA (in 4 Oracle versions), MCSE, MCDBA, MCT and CTT+. He can be reached at .

 

More articles by Damir Bersinic:

Post your comment below, or better yet, go to our Discussion Forums and really post your mind.
Current CertCities.com user Comments for "Have Data, Will Travel "
3/1/01 - Manoj  says: Damir, Its really Great !!!
8/26/01 - Raj  says: The Provided information is very helpfull in all the ways.This is really a good site..
9/10/01 - mohamed  says: i look for oracle developer training cource may you help me?
10/24/01 - Eman  says: i look for oracle8i materials?
12/12/01 - R.G.Senthil  says: Respectsd sir, Iam from india,my name R.G.Senthil kumar Please tell the detailse about oracle administrator , Gide ,And tell the features ,And exam detailse Thanking Yoy, urs faithfully R.G.Senthil kumar
1/11/02 - Yash  from India says: Excellent
2/3/02 - Vivek Arora  from Hardwar, India says: Respected Sir, Please send more features of Oracle 8i that can enhance working in Oracle 8i. Thank You
2/28/02 - Senthilnathan  from Malaysia says: I have few doubts in oracle datafile storage, First I have to create database with no tables except system tables. After that I created one table and reload data from backup, then I checked datafile size is 2 GB. Then I deleted that table records used truncate method, then i saw the datafile size remain 2 GB. I would like to know why datafile not shrinking after deleted records. What is the mechnism using oracle for storing reocrds into datafile(users01.dbf). Please give me the answer.
11/14/02 - Shahrukh Khan  from India says: Superb, and I am looking for oracle8i materials?
2/1/03 - Srinivasan  from Doha - Qatar says: For the Question of Senthilnathan from Malaysia you have to specify the option of autoshrink for your datafiles to automatically reducde after deleting records
Add your comment here:
Name: (optional)
Location: (optional)
E-mail Address: (optional)
Comments:  
 
top

Sponsored Links:
Cert21.com: free online practice exams. Register now
Question of the day: sign up to receive free practice questions
Exchange Server 2003: FREE special report from ENTmag.com
Windows Server 2003 Workshop: TechMentor, Sept. 2-6, San Diego
Free CertCities.com Newsletter: The best source for weeekly IT certification news!
Turn Up the Volume on IT: Listen to MCP Radio
Home | Microsoft | Cisco | Oracle | A+/Network+ | Linux/Unix | MOUS | List of Certs
Advertise | Certification Basics | Conferences | Contact Us | Contributors | Features | Forums | Links | News | Pop Quiz | Industry Releases | Tips
Search | Site Map | MCPmag.com | TCPmag.com | OfficeCert.com | TechMentor Conferences | 101communications | Privacy Policy
This Web site is not sponsored by, endorsed by or affiliated with Cisco Systems, Inc., Microsoft Corp., Oracle Corp., The Computing Technology Industry Association, Linus Torvolds, or any other certification or technology vendor. Cisco® and Cisco Systems® are registered trademarks of Cisco Systems, Inc. Microsoft, Windows and Windows NT are either registered trademarks or trademarks of Microsoft Corp. Oracle® is a registered trademark of Oracle Corp. A+®, i-Net+™, Network+™, and Server+™ are trademarks and registered trademarks of The Computing Technology Industry Association. (CompTIA). Linux™ is a registered trademark of Linus Torvalds. All other trademarks belong to their respective owners.
All content copyright 2000-03 101communications LLC, unless otherwise noted. All rights reserved.
Reprints allowed with written permission from the publisher. For more information, e-mail