8/7/2019 Oracle 10g tutorial
1/83
1.Introduction:
An Oracle database is a collection of data treated as a unit. The purpose of a database is to store andretrieve related information. A database server is the key to solving the problems of informationmanagement. In general, a server reliably manages a large amount of data in a multiuser environment sothat many users can concurrently access the same data. All this is accomplished while delivering highperformance. A database server also prevents unauthorized access and provides efficient solutions forfailure recovery.
Oracle Database is the first database designed for enterprise grid computing, the most flexible and costeffective way to manage information and applications. Enterprise grid computing creates large pools ofindustry-standard, modular storage and servers. With this architecture, each new system can be rapidlyprovisioned from the pool of components. There is no need for peak workloads, because capacity can beeasily added or reallocated from the resource pools as needed.
The database has logical structures and physical structures. Because the physical and logicalstructures are separate, the physical storage of data can be managed without affecting the access tological storage structures.
Overview ofOracle Grid Architecture
The Oracle grid architecture pools large numbers of servers, storage, and networks into a flexible, on-demand computing resource for enterprise computing needs. The grid computing infrastructurecontinually analyzes demand for resources and adjusts supply accordingly.
For example, you could run different applications on a grid of several linked database servers. Whenreports are due at the end of the month, the database administrator could automatically provision moreservers to that application to handle the increased demand.
Grid computing uses sophisticated workload management that makes it possible for applications to share
resources across many servers. Data processing capacity can be added or removed on demand, andresources within a location can be dynamically provisioned. Web services can quickly integrateapplications to create new business processes.
Difference between a cluster and a grid
Clustering is one technology used to create a grid infrastructure. Simple clusters have static resources
for specific applications by specific owners. Grids, which can consist of multiple clusters, are dynamic
resource pools shareable among many different applications and users. A grid does not assume that all
servers in the grid are running the same set of applications. Applications can be scheduled and migrated
across servers in the grid. Grids share resources from and among independent system owners.
At the highest level, the idea of grid computing is computing as a utility. In other words, you should not
care where your data resides, or what computer processes your request. You should be able to request
information or computation and have it delivered - as much as you want, and whenever you want. This
is analogous to the way electric utilities work, in that you don't know where the generator is, or how the
electric grid is wired, you just ask for electricity, and you get it. The goal is to make computing a utility, a
8/7/2019 Oracle 10g tutorial
2/83
commodity, and ubiquitous. Hence the name, The Grid. This view of utility computing is, of course, a
"client side" view.
From the "server side", or behind the scenes, the grid is about resource allocation, information sharing,and high availability. Resource allocation ensures that all those that need or request resources are gettingwhat they need, that resources are not standing idle while requests are going unserviced. Informationsharing makes sure that the information users and applications need is available where and when it isneeded. High availability features guarantee all the data and computation is always there, just like a utilitycompany always provides electric power.
Responsibilities of Database Administrators
Each database requires at least one database administrator (DBA). An Oracle Database system can belarge and can have many users. Therefore, database administration is sometimes not a one-person job,but a job for a group of DBAs who share responsibility.
A database administrator's responsibilities can include the following tasks:
Installing and upgrading the Oracle Database server and application tools Allocating system storage and planning future storage requirements for the database system Creating primary database storage structures (tablespaces) after application developers have
designed an application Creating primary objects (tables, views, indexes) once application developers have designed
an application Modifying the database structure, as necessary, from information given by application
developers Enrolling users and maintaining system security Ensuring compliance with Oracle license agreements Controlling and monitoring user access to the database
Monitoring and optimizing the performance of the database Planning for backup and recovery of database information Maintaining archived data on tape Backing up and restoring the database Contacting Oracle for technical support
2.Creating and Oracle Database
This section presents the steps involved when you create a database manually. These steps should be
followed in the order presented. Before you create the database make sure you have done the planningabout the size of the database, number of tablespaces and redo log files you want in the database.
Regarding the size of the database you have to first find out how many tables are going to be created inthe database and how much space they will be occupying for the next 1 year or 2. The best thing is tostart with some specific size and later on adjust the size depending upon the requirement
Plan the layout of the underlying operating system files your database will comprise. Proper distribution offiles can improve database performance dramatically by distributing the I/O during file access. You candistribute I/O in several ways when you install Oracle software and create your database. For example,
8/7/2019 Oracle 10g tutorial
3/83
you can place redo log files on separate disks or use striping. You can situate datafiles to reducecontention. And you can control data density (number of rows to a data block).
Select the standard database block size. This is specified at database creation by the DB_BLOCK_SIZEinitialization parameter and cannot be changed after the database is created. For databases, block size of
4K or 8K is widely used
Before you start creating the Database it is best to write down the specification and then proceed
The examples shown in these steps create an example database my_ica_db
Let us create a database my_ica_db with the following specification
Database name and System IdentifierSID = myicadbDB_NAME = myicadb
TABLESPACES
(we will have 5 tablespaces in this database. With 1 datafile in each tablespace)
TablespaceNameDatafile Sizesystem /u01/oracle/oradata/myica/sys.dbf 250Musers /u01/oracle/oradata/myica/usr.dbf 100Mundotbs /u01/oracle/oradata/myica/undo.dbf 100Mtemp /u01/oracle/oradata/myica/temp.dbf 100Mindex_data /u01/oracle/oradata/myica/indx.dbf 100Msysaux /u01/oracle/oradata/myica/sysaux.dbf 100M
LOGFILES(we will have 2 log groups in the database)
Logfile Group Member SizeGroup 1 /u01/oracle/oradata/myica/log1.ora 50MGroup 2 /u01/oracle/oradata/myica/log2.ora 50M
CONTROL FILE /u01/oracle/oradata/myica/control.oraPARAMETER FILE /u01/oracle/dbs/initmyicadb.ora
(rememer the parameter file name should of the format init.ora and it should be inORACLE_HOME/dbs directory in Unix o/s and ORACLE_HOME/database directory in windows o/s)
Now let us start creating the database.
Step 1: Login to oracle account and make directories for your database.
$mkdir /u01/oracle/oradata/myica$mkdir /u01/oracle/oradata/myica/bdump$mkdir /u01/oracle/oradata/myica/udump$mkdir /u01/oracle/oradata/myica/cdump
Step 2: Create the parameter file by copying the default template (init.ora) and set the requiredparameters
8/7/2019 Oracle 10g tutorial
4/83
$cd /u01/oracle/dbs$cpinit.ora initmyicadb.ora
Now open the parameter file and set the following parameters
$viinitmyicadb.ora
DB_NAME=myicadbDB_BLOCK_SIZE=8192CONTROL_FILES=/u01/oracle/oradata/myica/control.oraBACKGROUND_DUMP_DEST=/u01/oracle/oradata/myica/bdumpUSER_DUMP_DEST=/u01/oracle/oradata/myica/udumpCORE_DUMP_DEST=/u01/oracle/oradata/myica/cdumpUNDO_TABLESPACE=undotbsUNDO_MANAGEMENT=AUTO
After entering the above parameters save the file by pressing Esc :wq
Step 3: Now set ORACLE_SID environment variable and start the instance.
$exportORACLE_SID=myicadb$sqlplusEnter User: / assysdbaSQL>startup nomount
Step 4: Give the create database command
Here I am not specfying optional setting such as language, characterset etc. For thesesettings oracle will use the default values. I am giving the barest command to create thedatabase to keep it simple.
The command to create the database is
SQL>createdatabasemyicadbdatafile /u01/oracle/oradata/myica/sys.dbfsize 250Msysauxdatafile /u01/oracle/oradata/myica/sysaux.dbfsize 100mundo tablespace undotbs
datafile /u01/oracle/oradata/myica/undo.dbfsize 100mdefaulttemporarytablespacetemp
tempfile /u01/oracle/oradata/myica/tmp.dbfsize 100mlogfile
group 1 /u01/oracle/oradata/myica/log1.orasize 50m,group 2 /u01/oracle/oradata/myica/log2.orasize 50m;
After the command fishes you will get the following message
Databasecreated.
If you are getting any errors then see accompanying messages. If no accompanying messages areshown then you have to see the alert_myicadb.log file located in BACKGROUND_DUMP_DEST directory,which will show the exact reason why the command has failed. After you have rectified the error pleasedelete all created files in /u01/oracle/oradata/myica directory and again give the above command.
8/7/2019 Oracle 10g tutorial
5/83
Step 5: After the above command finishes, the database will get mounted and opened. Nowcreate additional tablespaces
To createUSERS tablespace
SQL>create
tablespace
users
datafile /u01/oracle/oradata/myica/usr.dbfsize 100M;
To create INDEX_DATA tablespaceSQL>createtablespaceindex_data
datafile /u01/oracle/oradata/myica/indx.dbfsize 100M
Step 6: To populate the database with data dictionaries and to install procedural options executethe following scripts
First execute the CATALOG.SQL script to install data dictionariesSQL>@/u01/oracle/rdbms/admin/catalog.sql
The above script will take several minutes. After the above script is finished run theCATPROC.SQL script to install procedural option.SQL>@/u01/oracle/rdbms/admin/catproc.sql
This script will also take several minutes to complete.
Step 7: Now change the passwords forSYS and SYSTEM account, since the default passwordschange_on_install andmanager are known by everybody.
SQL>alter user sysidentifiedbymyica;
SQL>alter user systemidentifiedbymyica;
Step 8: Create Additional user accounts. You can create as many user account as you like. Let us createthe popular account SCOTT.
SQL>create user scottdefaulttablespace usersidentifiedbytiger quota 10M on users;
SQL>grantconnectto scott;
Step 9: Add this databaseSID in listener.ora file and restart the l istener process.
$cd /u01/oracle/network/admin
$vilistener.ora
(This file will already contain sample entries. Copy and paste one sample entry and edit the SIDsetting)
LISTENER =(DESCRIPTION_LIST =(DESCRIPTION =
(ADDRESS =(PROTOCOL = TCP)(HOST=200.200.100.1)(PORT = 1521)))
)SID_LIST_LISTENER =
8/7/2019 Oracle 10g tutorial
6/83
(SID_LIST =(SID_DESC =(SID_NAME = PLSExtProc)(ORACLE_HOME =/u01/oracle)(PROGRAM = extproc)
)(SID_DESC =
(SID_NAME=ORCL)(ORACLE_HOME=/u01/oracle)
)#Addtheselines
(SID_DESC =(SID_NAME=myicadb)(ORACLE_HOME=/u01/oracle)
)
)
Save the file by pressing Esc :wq
Now restart the listener process.
$lsnrctlstop$lsnrctlstart
Step 10: It is recommended to take a full database backup after you just created the database.How to take backup is deal in the Backup and Recovery Section.
Congratualtions you have just created an oracle database.
3. Managing Tablespaces and Datafiles
Using multiple tablespaces provides several Advantages
y Separate user data from data dictionary data to reduce contention among dictionary objects
and schema objects for the same datafiles.
y Separate data of one application from the data of another to prevent multiple applications from
being affected if a tablespace must be taken offline.
y Store different the datafiles of different tablespaces on different disk drives to reduce I/O
contention.
y Take individual tablespaces offline while others remain online, providing better overallavailability.
Creating New Tablespaces
8/7/2019 Oracle 10g tutorial
7/83
You can create Locally Managed or Dictionary Managed Tablespaces. In prior versions of Oracle only
Dictionary managed Tablespaces were available but from Oracle ver. 8i you can also create Locally
managed tablespaces. The advantages of locally managed tablespaces are
Locally managed tablespaces track all extent information in the tablespace itself by using bitmaps,
resulting in the following benefits:
y Concurrency and speed of space operations is improved, because space allocations and
deallocations modify locally managed resources (bitmaps stored in header files) rather than
requiring centrally managed resources such as enqueues
y Performance is improved, because recursive operations that are sometimes required during
dictionary-managed space allocation are eliminated
To create a locally managed tablespace give the following command
SQL>CREATE TABLESPACEica_lmtsDATAFILE '/u02/oracle/ica/ica01.dbf' SIZE 50M
EXTENT MANAGEMENT LOCALAUTOALLOCATE;
AUTOALLOCATE causes the tablespace to be system managed with a minimum extent size of 64K.
The alternative to AUTOALLOCATE is UNIFORM. which specifies that the tablespace is managed with
extents of uniform size. You can specify that size in the SIZE clause ofUNIFORM. If you omit SIZE, then
the default size is 1M. The following example creates a Locally managed tablespace with uniform extent
size of 256K
SQL>CREATE TABLESPACEica_lmtDATAFILE '/u02/oracle/ica/ica01.dbf'
SIZE 50MEXTENT MANAGEMENT LOCALUNIFORMSIZE 256K;
To Create Dictionary Managed Tablespace
SQL>CREATE TABLESPACEica_lmtDATAFILE '/u02/oracle/ica/ica01.dbf'
SIZE 50MEXTENT MANAGEMENT DICTIONARY;
Bigfile Tablespaces (Introduced in Oracle Ver. 10g)A bigfile tablespace is a tablespace with a single, but very large (up to 4G blocks) datafile.Traditional smallfile tablespaces, in contrast, can contain multiple datafiles, but the files cannotbe as large. Bigfile tablespaces can reduce the number of datafiles needed for a database.
To create a bigfile tablespace give the following command
8/7/2019 Oracle 10g tutorial
8/83
SQL>CREATEBIGFILE TABLESPACEica_bigtbs
DATAFILE '/u02/oracle/ica/bigtbs01.dbf' SIZE 50G;
To Extend the Size of a tablespace
Option 1
You can extend the size of a tablespace by increasing the size of an existing datafile by typing the
following command
SQL>alter databaseicadatafile /u01/oracle/data/icatbs01.dbf
resize 100M;
This will increase the size from 50M to 100M
Option 2
You can also extend the size of a tablespace by adding a new datafile to a tablespace. This is useful if the
size of existing datafile is reached o/s file size limit or the drive where the file is existing does not have
free space. To add a new datafile to an existing tablespace give the following command.
SQL>alter tablespaceadddatafile /u02/oracle/ica/icatbs02.dbf
size 50M;
Option 3
You can also use auto extend feature of datafile. In this, Oracle will automatically increase the size of a
datafile whenever space is required. You can specify by how much size the file should increase and
Maximum size to which it should extend.
To make a existing datafile auto extendable give the following command
SQL>alter databasedatafile /u01/oracle/ica/icatbs01.dbfauto
extendON next 5Mmaxsize 500M;
You can also make a datafile auto extendable while creating a new tablespace itself by giving the
following command.
SQL>createtablespaceicadatafile /u01/oracle/ica/icatbs01.dbf
size 50Mauto extendON next 5Mmaxsize 500M;
8/7/2019 Oracle 10g tutorial
9/83
To decrease thesize of a tablespace
You can decrease the size of tablespace by decreasing the datafile associated with it. You decrease a
datafile only up to size of empty space in it. To decrease the size of a datafile give the following
command
SQL>alter databasedatafile /u01/oracle/ica/icatbs01.dbf
resize 30M;
Coalescing Tablespaces
A free extent in a dictionary-managed tablespace is made up of a collection of contiguous free blocks.
When allocating new extents to a tablespace segment, the database uses the free extent closest in size
to the required extent. In some cases, when segments are dropped, their extents are deallocated and
marked as free, but adjacent free extents are not immediately recombined into larger free extents. The
result is fragmentation that makes allocation of larger extents more difficult.
You should often use the ALTER TABLESPACE...COALESCE statement to manually coalesce any
adjacent free extents. To Coalesce a tablespace give the following command
SQL> alter tablespace ica coalesce;
Taking tablespacesOffline or Online
You can take an online tablespace offline so that it is temporarily unavailable for general use. The rest of
the database remains open and available for users to access data. Conversely, you can bring an offlinetablespace online to make the schema objects within the tablespace available to database users. The
database must be open to alter the availability of a tablespace.
To alter the availability of a tablespace, use the ALTER TABLESPACE statement. You must have the ALTER
TABLESPACE or MANAGE TABLESPACE system privilege.
8/7/2019 Oracle 10g tutorial
10/83
To Take a Tablespace Offline give the following command
SQL>alter tablespaceica offline;
To again bring it back online give the following command.
SQL>alter tablespaceica online;
To take individual datafile offline type the following command
SQL>alter databasedatafile /u01/oracle/ica/ica_tbs01.dbf offline;
Again to bring it back online give the following command
SQL>alter databasedatafile /u01/oracle/ica/ica_tbs01.dbf online;
Note: You cant take individual datafiles offline it the database is running in NOARCHIVELOG mode. If
the datafile has become corrupt or missing when the database is running in NOARCHIVELOG mode then
you can only drop it by giving the following command
SQL>alter databasedatafile /u01/oracle/ica/ica_tbs01.dbf
offlinefor drop;
Making a TablespaceRead only.
Making a tablespace read-only prevents write operations on the datafiles in the tablespace. The primary
purpose of read-only tablespaces is to eliminate the need to perform backup and recovery of large,
static portions of a database. Read-only tablespaces also provide a way to protecting historical data so
that users cannot modify it. Making a tablespace read-only prevents updates on all tables in the
tablespace, regardless of a user's update privilege level.
To make a tablespace read only
SQL>alter tablespaceica read only
Again to make it read write
SQL>alter tablespaceica read write;
Renaming Tablespaces
Using the RENAME TO clause of the ALTER TABLESPACE, you can rename a permanent or temporary
tablespace. For example, the following statement renames the users tablespace:
8/7/2019 Oracle 10g tutorial
11/83
ALTER TABLESPACE users RENAME TO usersts;
The following affect the operation of this statement:
y The COMPATIBLE parameter must be set to 10.0 or higher.
y If the tablespace being renamed is the SYSTEM tablespace or the SYSAUX tablespace, then it will
not be renamed and an error is raised.
y If any datafile in the tablespace is offline, or if the tablespace is offline, then the tablespace is
not renamed and an error is raised.
Dropping Tablespaces
You can drop a tablespace and its contents (the segments contained in the tablespace) from the
database if the tablespace and its contents are no longer required. You must have the DROP
TABLESPACE system privilege to drop a tablespace.
Caution: Once a tablespace has been dropped, the data in the tablespace is not recoverable. Therefore,
make sure that all data contained in a tablespace to be dropped will not be required in the future. Also,
immediately before and after dropping a tablespace from a database, back up the database completely
To drop a tablespace give the following command.
SQL>droptablespaceica;
This will drop the tablespace only if it is empty. If it is not empty and if you want to drop it anyhow then
add the following keyword
SQL>droptablespaceicaincluding contents;
This will drop the tablespace even if it is not empty. But the datafiles will not be deleted you have to use
operating system command to delete the files.
But If you include datafiles keyword then, the associated datafiles will also be deleted from the disk.
SQL>droptablespaceicaincluding contentsanddatafiles;
Temporary Tablespace
Temporary tablespace is used for sorting large tables. Every database should have one temporary
tablespace. To create temporary tablespace give the following command.
SQL>createtemporarytablespacetemptempfile
/u01/oracle/data/ica_temp.dbfsize 100M
extentmanagementlocal uniformsize 5M;
8/7/2019 Oracle 10g tutorial
12/83
The extent management clause is optional for temporary tablespaces because all temporary tablespaces
are created with locally managed extents of a uniform size. The AUTOALLOCATE clause is not allowed
for temporary tablespaces.
Increasing or Decreasing thesize of a Temporary
Tablespace
You can use the resize clause to increase or decrease the size of a temporary tablespace. The following
statement resizes a temporary file:
SQL>ALTER DATABASE TEMPFILE '/u02/oracle/data/lmtemp02.dbf' RESIZE 18M;
The following statement drops a temporary file and deletes the operating system file:
SQL>ALTER DATABASE TEMPFILE '/u02/oracle/data/lmtemp02.dbf' DROPINCLUDING DATAFILES;
Tablespace Groups
A tablespace group enables a user to consume temporary space from multiple tablespaces. A
tablespace group has the following characteristics:
y It contains at least one tablespace. There is no explicit limit on the maximum number of
tablespaces that are contained in a group.
y
It shares the namespace of tablespaces, so its name cannot be the same as any tablespace.y You can specify a tablespace group name wherever a tablespace name would appear when you
assign a default temporary tablespace for the database or a temporary tablespace for a user.
You do not explicitly create a tablespace group. Rather, it is created implicitly when you assign the first
temporary tablespace to the group. The group is deleted when the last temporary tablespace it contains
is removed from it.
Using a tablespace group, rather than a single temporary tablespace, can alleviate problems caused
where one tablespace is inadequate to hold the results of a sort, particularly on a table that has many
partitions. A tablespace group enables parallel execution servers in a single parallel operation to use
multiple temporary tablespaces.
The view DBA_TABLESPACE_GROUPS lists tablespace groups and their member tablespaces.
Creating a Temporary Tablespace Group
8/7/2019 Oracle 10g tutorial
13/83
You create a tablespace group implicitly when you include the TABLESPACE GROUP clause in the
CREATE TEMPORARY TABLESPACE orALTER TABLESPACE statement and the specified
tablespace group does not currently exist.
For example, if neithergroup1 norgroup2 exists, then the following statements create those groups,
each of which has only the specified tablespace as a member:
CREATE TEMPORARY TABLESPACEica_temp2 TEMPFILE '/u02/oracle/ica/ica_temp.dbf'SIZE 50MTABLESPACE GROUP group1;
ALTER TABLESPACEica_temp2 TABLESPACE GROUP group2;
Assigning a Tablespace Group as the Default Temporary
TablespaceUse the ALTER DATABASE...DEFAULTTEMPORARYTABLESPACE statement to assign a
tablespace group as the default temporary tablespace for the database. For example:
ALTER DATABASEsampleDEFAULT TEMPORARY TABLESPACE group2;
Diagnosing and Repairing Locally Managed Tablespace
Problems
To diagnose and repair corruptions in Locally Managed Tablespaces Oracle has supplied a package called
DBMS_SPACE_ADMIN. This package has many procedures described below:
Procedure Description
SEGMENT_VERIFY Verifies the consistency of the extent map of the segment.
SEGMENT_CORRUPT Marks the segment corrupt or valid so that appropriate error
recovery can be done. Cannot be used for a locally managed
SYSTEM tablespace.
SEGMENT_DROP_CORRUPT Drops a segment currently marked corrupt (without reclaiming
space). Cannot be used for a locally managed SYSTEM
tablespace.
8/7/2019 Oracle 10g tutorial
14/83
Procedure Description
SEGMENT_DUMP Dumps the segment header and extent map of a given segment.
TABLESPACE_VERIFY Verifies that the bitmaps and extent maps for the segments in
the tablespace are in sync.
TABLESPACE_REBUILD_BITMAPS Rebuilds the appropriate bitmap. Cannot be used for a locally
managed SYSTEM tablespace.
TABLESPACE_FIX_BITMAPS Marks the appropriate data block address range (extent) as free
or used in bitmap. Cannot be used for a locally managed
SYSTEM tablespace.
TABLESPACE_REBUILD_QUOTASRebuilds quotas for given tablespace.
TABLESPACE_MIGRATE_FROM_LOCAL Migrates a locally managed tablespace to dictionary-managed
tablespace. Cannot be used to migrate a locally managed
SYSTEM tablespace to a dictionary-managed SYSTEM
tablespace.
TABLESPACE_MIGRATE_TO_LOCAL Migrates a tablespace from dictionary-managed format to
locally managed format.
TABLESPACE_RELOCATE_BITMAPS Relocates the bitmaps to the destination specified. Cannot beused for a locally managed system tablespace.
TABLESPACE_FIX_SEGMENT_STATES Fixes the state of the segments in a tablespace in which
migration was aborted.
Be careful using the above procedures if not used properly you will corrupt your database. Contact
Oracle Support before using these procedures.
Following are some of the Scenarios where you can use the above procedures
Scenario 1: Fixing Bitmap When Allocated Blocks are
Marked Free (No Overlap)
8/7/2019 Oracle 10g tutorial
15/83
The TABLESPACE_VERIFY procedure discovers that a segment has allocated blocks that are marked free
in the bitmap, but no overlap between segments is reported.
In this scenario, perform the following tasks:
1. Call the SEGMENT_DUMP procedure to dump the ranges that the administrator allocated to thesegment.
2. For each range, call the TABLESPACE_FIX_BITMAPS procedure with theTABLESPACE_EXTENT_MAKE_USED option to mark the space as used.
3. Call TABLESPACE_REBUILD_QUOTAS to fix up quotas.
Scenario 2: Dropping a Corrupted Segment
You cannot drop a segment because the bitmap has segment blocks marked "free". The system has
automatically marked the segment corrupted.
In this scenario, perform the following tasks:
1. Call the SEGMENT_VERIFY procedure with the SEGMENT_VERIFY_EXTENTS_GLOBAL option. Ifno overlaps are reported, then proceed with steps 2 through 5.
2. Call the SEGMENT_DUMP procedure to dump the DBA ranges allocated to the segment.3. For each range, call TABLESPACE_FIX_BITMAPS with the TABLESPACE_EXTENT_MAKE_FREE
option to mark the space as free.
4. Call SEGMENT_DROP_CORRUPT to drop the SEG$ entry.5. Call TABLESPACE_REBUILD_QUOTAS to fix up quotas.
Scenario 3: Fixing Bitmap WhereOverlap isReportedThe TABLESPACE_VERIFY procedure reports some overlapping. Some of the real data must be sacrificed
based on previous internal errors.
After choosing the object to be sacrificed, in this case say, table t1, perform the following tasks:
1. Make a list of all objects that t1 overlaps.2. Drop table t1. If necessary, follow up by calling the SEGMENT_DROP_CORRUPT procedure.3. Call the SEGMENT_VERIFY procedure on all objects that t1 overlapped. If necessary, call the
TABLESPACE_FIX_BITMAPS procedure to mark appropriate bitmap blocks as used.
4. Rerun the TABLESPACE_VERIFY procedure to verify the problem is resolved.
Scenario 4: Correcting Media Corruption ofBitmapBlocks
A set of bitmap blocks has media corruption.
In this scenario, perform the following tasks:
8/7/2019 Oracle 10g tutorial
16/83
1. Call the TABLESPACE_REBUILD_BITMAPS procedure, either on all bitmap blocks, or on a singleblock if only one is corrupt.
2. Call the TABLESPACE_REBUILD_QUOTAS procedure to rebuild quotas.3. Call the TABLESPACE_VERIFY procedure to verify that the bitmaps are consistent.
Scenario 5: Migrating from a Dictionary-Managed to aLocally Managed Tablespace
To migrate a dictionary-managed tablespace to a locally managed tablespace. You use the
TABLESPACE_MIGRATE_TO_LOCAL procedure.
For example if you want to migrate a dictionary managed tablespace ICA2 to Locally managed then give
the following command.
EXECDBMS_SPACE_ADMIN.TABLESPACE_MIGRATE_TO_LOCAL ('ica2');
Transporting Tablespaces
You can use the transportable tablespaces feature to move a subset of an Oracle Database and "plug" it
in to another Oracle Database, essentially moving tablespaces between the databases. The tablespaces
being transported can be either dictionary managed or locally managed. Starting with Oracle9i, the
transported tablespaces are not required to be of the same block size as the target database standard
block size.
Moving data using transportable tablespaces is much faster than performing either an export/import or
unload/load of the same data. This is because the datafiles containing all of the actual data are simply
copied to the destination location, and you use an import utility to transfer only the metadata of the
tablespace objects to the new database.
Starting with Oracle Database 10g, you can transport tablespaces across platforms. This functionality
can be used to Allow a database to be migrated from one platform to another. However not all
platforms are supported. To see which platforms are supported give the following query.
SQL>COLUMNPLATFORM_NAME FORMAT A30
SQL>SELECT * FROMV$TRANSPORTABLE_PLATFORM;
PLATFORM_IDPLATFORM_NAME ENDIAN_FORMAT
----------- ------------------------------ --------------
1 Solaris[tm]OE (32-bit) Big
8/7/2019 Oracle 10g tutorial
17/83
2 Solaris[tm]OE (64-bit) Big
7 Microsoft WindowsNT Little
10 LinuxIA (32-bit) Little
6 AIX-BasedSystems (64-bit) Big
3 HP-UX (64-bit) Big
5 HP Tru64 UNIX Little
4 HP-UXIA (64-bit) Big
11 LinuxIA (64-bit) Little
15 HPOpen VMS Little
10 rowsselected.
If the source platform and the target platform are of different endianness, then an additional step must
be done on either the source or target platform to convert the tablespace being transported to the
target format. If they are of the same endianness, then no conversion is necessary and tablespaces can
be transported as if they were on the same platform.
Important: Before a tablespace can be transported to a different platform, the datafile header must
identify the platform to which it belongs. In an Oracle Database with compatibility set to 10.0.0 or
higher, you can accomplish this by making the datafile read/write at least once.
SQL>alte
rtablespace
ica
read
only;
Then,
SQL>alter tablespaceica read write;
Procedure for transporting tablespaces
To move or copy a set of tablespaces, perform the following steps.
1. For cross-platform transport, check the endian format of both platforms by querying theV$TRANSPORTABLE_PLATFORM view.
If you are transporting the tablespace set to a platform different from the source platform, then
determine if the source and target platforms are supported and their endianness. If both
platforms have the same endianness, no conversion is necessary. Otherwise you must do a
conversion of the tablespace set either at the source or target database.
8/7/2019 Oracle 10g tutorial
18/83
Ignore this step if you are transporting your tablespace set to the same platform.
2. Pick a self-contained set of tablespaces.3. Generate a transportable tablespace set.
A transportable tablespace set consists of datafiles for the set of tablespaces being transportedand an export file containing structural information for the set of tablespaces.
If you are transporting the tablespace set to a platform with different endianness from the
source platform, you must convert the tablespace set to the endianness of the target platform.
You can perform a source-side conversion at this step in the procedure, or you can perform a
target-side conversion as part of step 4.
4. Transport the tablespace set.
Copy the datafiles and the export file to the target database. You can do this using any facility
for copying flat files (for example, an operating system copy utility, ftp, the DBMS_FILE_COPY
package, or publishing on CDs).
If you have transported the tablespace set to a platform with different endianness from the
source platform, and you have not performed a source-side conversion to the endianness of the
target platform, you should perform a target-side conversion now.
5. Plug in the tablespace.
Invoke the Export utility to plug the set of tablespaces into the target database.
Transporting Tablespace Example
These steps are illustrated more fully in the example that follows, where it is assumed thefollowing datafiles and tablespaces exist:
Tablespace Datafile:
ica_sales_1 /u01/oracle/oradata/ica_salesdb/ica_sales_101.dbf
ica_sales_2 /u01/oracle/oradata/ica_salesdb/ica_sales_201.dbf
Step 1: Determine if Platforms are Supported and Endianness
This step is only necessary if you are transporting the tablespace set to a platform different from
the source platform. Ifica_sales_1 and ica_sales_2 were being transported to a different
8/7/2019 Oracle 10g tutorial
19/83
platform, you can execute the following query on both platforms to determine if the platformsare supported and their endian formats:
SELECT d.PLATFORM_NAME,ENDIAN_FORMATFROMV$TRANSPORTABLE_PLATFORMtp,V$DATABASEdWHEREtp.PLATFORM_NAME = d.PLATFORM_NAME;
The following is the query result from the source platform:
PLATFORM_NAME ENDIAN_FORMAT------------------------- --------------
Solaris[tm]OE (32-bit) Big
The following is the result from the target platform:
PLATFORM_NAME ENDIAN_FORMAT
------------------------- --------------Microsoft WindowsNT Little
You can see that the endian formats are different and thus a conversion is necessary fortransporting the tablespace set.
Step 2: Pick a Self-Contained Set of Tablespaces
There may be logical or physical dependencies between objects in the transportable set and thoseoutside of the set. You can only transport a set of tablespaces that is self-contained. That is it
should not have tables with foreign keys referring to primary key of tables which are in othertablespaces. It should not have tables with some partitions in other tablespaces. To find outwhether the tablespace is self contained do the following
EXECUTEDBMS_TTS.TRANSPORT_SET_CHECK('ica_sales_1,ica_sales_2', TRUE);
After executing the above give the following query to see whether any violations are there.
SQL>SELECT * FROM TRANSPORT_SET_VIOLATIONS;
VIOLATIONS
---------------------------------------------------------------------------
ConstraintDEPT_FKbetween tableSAMI.EMPin tablespaceICA_SALES_1 andtable
8/7/2019 Oracle 10g tutorial
20/83
SAMI.DEPT in tablespaceOTHER
PartitionedtableSAMI.SALESispartiallycontainedin thetransportableset
These violations must be resolved before ica_sales_1 and ica_sales_2 are transportable
Step 3: Generate a Transportable Tablespace Set
After ensuring you have a self-contained set of tablespaces that you want to transport, generate a
transportable tablespace set by performing the following actions:
Make all tablespaces in the set you are copying read-only.
SQL>ALTER TABLESPACEica_sales_1 READONLY;
Tablespace altered.
SQL>ALTER TABLESPACEica_sales_2 READONLY;
Tablespace altered.
Invoke the Export utility on the host system and specify which tablespaces are in the transportable set.
SQL>HOST
$ expsystem/password FILE=/u01/oracle/expdat.dmp
TRANSPORT_TABLESPACES = ica_sales_1,ica_sales_2
Ifica_sales_1 and ica_sales_2 are being transported to a different platform, and theendianness of the platforms is different, and if you want to convert before transporting the
tablespace set, then convert the datafiles composing the ica_sales_1 and ica_sales_2tablespaces. You have to use RMAN utility to convert datafiles
$ RMAN TARGET /
RecoveryManager: Release 10.1.0.0.0Copyright (c) 1995, 2003,OracleCorporation. All rights reserved.
connectedto targetdatabase: ica_salesdb (DBID=3295731590)
Convert the datafiles into a temporary location on the source platform. In this example, assume that the
temporary location, directory /temp, has already been created. The converted datafiles are assigned
names by the system.
8/7/2019 Oracle 10g tutorial
21/83
RMAN>CONVERT TABLESPACEica_sales_1,ica_sales_2TOPLATFORM 'Microsoft WindowsNT' FORMAT '/temp/%U';
Starting backupat 08-APR-03
using targetdatabasecontrolfileinstead of recoverycatalog
allocatedchannel: ORA_DISK_1channelORA_DISK_1: sid=11 devtype=DISKchannelORA_DISK_1: starting datafileconversioninputdatafilefno=00005name=/u01/oracle/oradata/ica_salesdb/ica_sales_101.dbfconverteddatafile=/temp/data_D-10_I-3295731590_TS-ADMIN_TBS_FNO-5_05ek24v5
channelORA_DISK_1: datafileconversion complete,elapsedtime:00:00:15
channelORA_DISK_1: starting datafileconversioninputdatafilefno=00004name=/u01/oracle/oradata/ica_salesdb/ica_sales_101.dbfconverteddatafile=/temp/data_D-10_I-3295731590_TS-EXAMPLE_FNO-4_06ek24vl
channelORA_DISK_1: datafileconversion complete,elapsedtime:00:00:45
Finishedbackupat 08-APR-07
Step 4: Transport the Tablespace Set
Transport both the datafiles and the export file of the tablespaces to a place accessible to thetarget database. You can use any facility for copying flat files (for example, an operating system
copy utility, ftp, the DBMS_FILE_TRANSFER package, or publishing on CDs).
Step 5: Plug In the Tablespace Set
Plug in the tablespaces and integrate the structural information using the Import utility, imp:
IMPsystem/password FILE=expdat.dmp
DATAFILES=/ica_salesdb/ica_sales_101.dbf,/ica_salesdb/ica_sales_201.dbf
REMAP_SCHEMA=(smith:sami) REMAP_SCHEMA=(williams:john)
The REMAP_SCHEMA parameter changes the ownership of database objects. If you do not specify
REMAP_SCHEMA, all database objects (such as tables and indexes) are created in the same user schema
as in the source database, and those users must already exist in the target database. If they do not exist,
then the import utility returns an error. In this example, objects in the tablespace set owned by smith
8/7/2019 Oracle 10g tutorial
22/83
in the source database will be owned by sami in the target database after the tablespace set is plugged
in. Similarly, objects owned by williams in the source database will be owned by john in the target
database. In this case, the target database is not required to have users smith and williams, but must
have users sami and john.
After this statement executes successfully, all tablespaces in the set being copied remain in read-only mode. Check the import logs to ensure that no error has occurred.
Now, put the tablespaces into read/write mode as follows:
ALTER TABLESPACEica_sales_1 READ WRITE;
ALTER TABLESPACEica_sales_2 READ WRITE;
Viewing Information about Tablespaces and Datafiles
Oracle has provided many Data dictionaries to view information about tablespaces and datafiles. Some
of them are:
To view information about Tablespaces in a database give the following query
SQL>select * fromdba_tablespacesSQL>select * from v$tablespace;
To view information about Datafiles
SQL>select * fromdba_data_files;SQL>select * from v$datafile;
To view information about Tempfiles
SQL>select * fromdba_temp_files;SQL>select * from v$tempfile;
To view information about free space in datafiles
SQL>select * fromdba_free_space;
To view information about free space in tempfiles
SQL>select * fromV$TEMP_SPACE_HEADER;
8/7/2019 Oracle 10g tutorial
23/83
Relocating or Renaming Datafiles
You can rename datafiles to either change their names or relocate them.
Renaming or Relocating Datafiles belonging to a SingleTablespace
To rename or relocate datafiles belonging to a Single Tablespace do the following.
1. Take the tablespace offline
2. Rename or Relocate the datafiles using operating system command
3. Give the ALTER TABLESPACE with RENAME DATAFILE option to change the filenames within the
Database.
4. Bring the tablespace Online
For Example suppose you have a tablespace users with the following datafiles
/u01/oracle/ica/usr01.dbf
/u01/oracle/ica/usr02.dbf
Now you want to relocate/u01/oracle/ica/usr01.dbf to
/u02/oracle/ica/usr01.dbf and want to rename /u01/oracle/ica/usr02.dbf to
/u01/oracle/ica/users02.dbf then follow the given the steps
1. Bring the tablespace offline
SQL>alter tablespace users offline;
2. Copy the file to new location using o/s command.
$cp /u01/oracle/ica/usr01.dbf /u02/oracle/ica/usr01.dbf
Rename the file /u01/oracle/ica/usr02.dbf to
/u01/oracle/ica/users02.dbf using o/s command.
$mv /u01/oracle/ica/usr02.dbf /u01/oracle/ica/users02.dbf
3. Now start SQLPLUS and type the following command to rename and relocate these files
SQL>alter tablespace users renamefile/u01/oracle/ica/usr01.dbf, /u01/oracle/ica/usr02.dbf
to/u02/oracle/ica/usr01.dbf,/u01/oracle/ica/users02.dbf;
8/7/2019 Oracle 10g tutorial
24/83
4. Now bring the tablespace Online
SQL>alter tablespace users online;
Procedure for Renaming and Relocating Datafiles in
Multiple Tablespaces
You can rename and relocate datafiles in one or more tablespaces using the ALTER DATABASE
RENAME FILE statement. This method is the only choice if you want to rename or relocate
datafiles of several tablespaces in one operation. You must have the ALTER DATABASE systemprivilege
To rename datafiles in multiple tablespaces, follow these steps.
1. Ensure that the database is mounted but closed.
2. Copy the datafiles to be renamed to their new locations and new names, using theoperating system..
3. Use ALTER DATABASE to rename the file pointers in the database control file.
For example, the following statement renames the
datafiles/u02/oracle/rbdb1/sort01.dbf and /u02/oracle/rbdb1/user3.dbf to
/u02/oracle/rbdb1/temp01.dbf and /u02/oracle/rbdb1/users03.dbf,respectively:
ALTER DATABASERENAME FILE '/u02/oracle/rbdb1/sort01.dbf',
'/u02/oracle/rbdb1/user3.dbf'TO '/u02/oracle/rbdb1/temp01.dbf',
'/u02/oracle/rbdb1/users03.dbf;
Always provide complete filenames (including their paths) to properly identify the oldand new datafiles. In particular, specify the old datafile names exactly as they appear in
the DBA_DATA_FILES view.
4. Back up the database. After making any structural changes to a database, always perform
an immediate and complete backup.
5. Start the Database
8/7/2019 Oracle 10g tutorial
25/83
Managing REDO LOGFILES
Every Oracle database must have at least 2 redo logfile groups. Oracle writes all statementsexcept, SELECT statement, to the logfiles. This is done because Oracle performs deferred batchwrites i.e. it does write changes to disk per statement instead it performs write in batches. So in
this case if a user updates a row, Oracle will change the row in db_buffer_cache and records thestatement in the logfile and give the message to the user that row is updated. Actually the row isnot yet written back to the datafile but still it give the message to the user that row is updated.After 3 seconds the row is actually written to the datafile. This is known as deferred batch writes.
Since Oracle defers writing to the datafile there is chance of power failure or system crash beforethe row is written to the disk. Thats why Oracle writes the statement in redo logfile so that incase of power failure or system crash oracle can re-execute the statements next time when youopen the database.
Adding a NewRedo Logfile Group
To add a new Redo Logfile group to the database give the following command
SQL>alter databaseaddlogfile group 3/u01/oracle/ica/log3.orasize 10M;
Note: You can add groups to a database up to the MAXLOGFILES setting you have specified atthe time of creating the database. If you want to change MAXLOGFILE setting you have tocreate a new controlfile.
Adding Members to an existing groupTo add new member to an existing group give the following command
SQL>alter databaseaddlogfilemember/u01/oracle/ica/log11.orato group 1;
Note: You can add members to a group up to the MAXLOGMEMBERS setting you havespecified at the time of creating the database. If you want to change MAXLOGMEMBERSsetting you have create a new controlfile
Important: Is it strongly recommended that you multiplex logfiles i.e. have at least two logmembers, one member in one disk and another in second disk, in a database.
Dropping Members from a group
You can drop member from a log group only if the group is having more than one member and ifit is not the current group. If you want to drop members from the current group, force a log
8/7/2019 Oracle 10g tutorial
26/83
switch or wait so that log switch occurs and another group becomes current. To force a logswitch give the following command
SQL>alter systemswitchlogfile;
The following command can be used to drop a logfile member
SQL>alter databasedroplogfilemember/u01/oracle/ica/log11.ora;
Note: When you drop logfiles the files are not deleted from the disk. You have to use O/Scommand to delete the files from disk.
Dropping Logfile Group
Similarly, you can also drop logfile group only if the database is having more than two groups
and if it is not the current group.
SQL>alter databasedroplogfile group 3;
Note: When you drop logfiles the files are not deleted from the disk. You have to use O/Scommand to delete the files from disk.
Resizing Logfiles
You cannot resize logfiles. If you want to resize a logfile create a new logfile group with the new
size and subsequently drop the old logfile group.
Renaming or Relocating Logfiles
To Rename or Relocate Logfiles perform the following steps
For Example, suppose you want to move a logfile from /u01/oracle/ica/log1.ora
to /u02/oracle/ica/log1.ora, then do the following
Steps
1. Shutdown the database
SQL>shutdown immediate;
2. Move the logfile from Old location to new location using operating system command
8/7/2019 Oracle 10g tutorial
27/83
$mv /u01/oracle/ica/log1.ora /u02/oracle/ica/log1.ora
3. Start and mount the database
SQL>startupmount
4. Now give the following command to change the location in controlfile
SQL>alter database renamefile /u01/oracle/ica/log1.orato /u02/oracle/ica/log2.ora;
5. Open the database
SQL>alter database open;
Clearing REDO LOGFILES
A redo log file might become corrupted while the database is open, and ultimately stop database
activity because archiving cannot continue. In this situation the ALTER DATABASECLEAR
LOGFILE statement can be used reinitialize the file without shutting down the database.
The following statement clears the log files in redo log group number 3:
ALTER DATABASECLEAR LOGFILE GROUP 3;
This statement overcomes two situations where dropping redo logs is not possible:
y If there are only two log groupsy The corrupt redo log file belongs to the current group
If the corrupt redo log file has not been archived, use the UNARCHIVED keyword in the statement.
ALTER DATABASECLEAR UNARCHIVEDLOGFILE GROUP 3;
This statement clears the corrupted redo logs and avoids archiving them. The cleared redo logsare available for use even though they were not archived.
8/7/2019 Oracle 10g tutorial
28/83
If you clear a log file that is needed for recovery of a backup, then you can no longer recoverfrom that backup. The database writes a message in the alert log describing the backups fromwhich you cannot recover
Viewing Information About Logfiles
To See how many logfile groups are there and their status type the following query.
SQL>SELECT * FROMV$LOG;
GROUP# THREAD# SEQ BYTES MEMBERS ARCSTATUS FIRST_CHANGE# FIRST_TIM------ ------- ----- ------- ------- --- --------- ------------- ---------
1 1 20605 1048576 1 YESACTIVE 61515628 21-JUN-072 1 20606 1048576 1 NO CURRENT 41517595 21-JUN-073 1 20603 1048576 1 YESINACTIVE 31511666 21-JUN-074 1 20604 1048576 1 YESINACTIVE 21513647 21-JUN-07
To See how many members are there and where they are located give the following query
SQL>SELECT * FROMV$LOGFILE;
GROUP# STATUS MEMBER------ ------- ----------------------------------
1 /U01/ORACLE/ICA/LOG1.ORA2 /U01/ORACLE/ICA/LOG2.ORA
4. Managing Control Files
Every Oracle Database has a control file, which is a small binary file that records the physicalstructure of the database. The control file includes:
y The database name
y Names and locations of associated datafiles and redo log files
y The timestamp of the database creation
y The current log sequence number
y Checkpoint information
It is strongly recommended that you multiplex control files i.e. Have at least two control filesone in one hard disk and another one located in another disk, in a database. In this way if control
8/7/2019 Oracle 10g tutorial
29/83
file becomes corrupt in one disk the another copy will be available and you dont have to dorecovery of control file.
You can multiplex control file at the time of creating a database and later on also. If you havenot multiplexed control file at the time of creating a database you can do it now by following
given procedure.
Multiplexing Control File
Steps:
1. Shutdown the Database.
SQL>SHUTDOWNIMMEDIATE;
2. Copy the control file from old location to new location using operating system command. Forexample.
$cp /u01/oracle/ica/control.ora /u02/oracle/ica/control.ora
3. Now open the parameter file and specify the new location like this
CONTROL_FILES=/u01/oracle/ica/control.ora
Change it to
CONTROL_FILES=/u01/oracle/ica/control.ora,/u02/oracle/ica/control.ora
4. Start the Database
Now Oracle will start updating both the control files and, if one control file is lost you
can copy it from another location.
Changing the Name of a Database
If you ever want to change the name of database or want to change the setting of
MAXDATAFILES, MAXLOGFILES, MAXLOGMEMBERS then you have to create a new control
file.
8/7/2019 Oracle 10g tutorial
30/83
Creating A New Control File
Follow the given steps to create a new controlfile
Steps
1. First generate the create controlfile statement
SQL>alter databasebackupcontrolfileto trace;
After giving this statement oracle will write the CREATECONTROLFILE statement in a
trace file. The trace file will be randomly named something like ORA23212.TRC and it
is created in USER_DUMP_DEST directory.
2. Go to the USER_DUMP_DEST directory and open the latest trace file in text editor. This file will
contain the CREATECONTROLFILE statement. It will have two sets of statement one with
RESETLOGS and another without RESETLOGS. Since we are changing the name of the
Database we have to use RESETLOGS option ofCREATECONTROLFILE statement. Now copy
and paste the statement in a file. Let it be c.sql
3. Now open the c.sql file in text editor and set the database name from ica to prod shown in anexample below
CREATECONTROLFILESET DATABASEprodLOGFILE GROUP 1 ('/u01/oracle/ica/redo01_01.log',
'/u01/oracle/ica/redo01_02.log'),GROUP 2 ('/u01/oracle/ica/redo02_01.log',
'/u01/oracle/ica/redo02_02.log'),GROUP 3 ('/u01/oracle/ica/redo03_01.log',
'/u01/oracle/ica/redo03_02.log')RESETLOGSDATAFILE '/u01/oracle/ica/system01.dbf' SIZE 3M,
'/u01/oracle/ica/rbs01.dbs' SIZE 5M,'/u01/oracle/ica/users01.dbs' SIZE 5M,'/u01/oracle/ica/temp01.dbs' SIZE 5M
MAXLOGFILES 50MAXLOGMEMBERS 3
MAXLOGHISTORY 400MAXDATAFILES 200MAXINSTANCES 6ARCHIVELOG;
4. Start and do not mount the database.
SQL>STARTUPNOMOUNT;
8/7/2019 Oracle 10g tutorial
31/83
5. Now execute c.sql script
SQL>@/u01/oracle/c.sql
6. Now open the database with RESETLOGS
SQL>ALTER DATABASEOPEN RESETLOGS;
Cloning an Oracle Database.
You have a Production database running in one server. The company management wants todevelop some new modules and they have hired some programmers to do that. Now these
programmers require access to the Production database and they want to make changes to it. Youas a DBA cant give direct access to Production database so you want to create a copy of thisdatabase on another server and wants to give developers access to it.
Let us see an example of cloning a database
We have a database running the production server with the following files
PARAMETER FILElocatedin /u01/oracle/ica/initica.ora
CONTROL FILES=/u01/oracle/ica/control.ora
BACKGROUND_DUMP_DEST=/u01/oracle/ica/bdumpUSER_DUMP_DEST=/u01/oracle/ica/udumpCORE_DUMP_DEST=/u01/oracle/ica/cdumpLOG_ARCHIVE_DEST_1=location=/u01/oracle/ica/arc1
DATAFILES =/u01/oracle/ica/sys.dbf/u01/oracle/ica/usr.dbf/u01/oracle/ica/rbs.dbf/u01/oracle/ica/tmp.dbf
/u01/oracle/ica/sysaux.dbfLOGFILE=
/u01/oracle/ica/log1.ora/u01/oracle/ica/log2.ora
Now you want to copy this database to SERVER 2 and in SERVER 2 you dont have /u01
filesystem. In SERVER 2 you have /d01 filesystem.
To Clone this Database on SERVER 2 do the following.
8/7/2019 Oracle 10g tutorial
32/83
Steps :-
1. In SERVER 2 install the same version of o/s and same version Oracle as in SERVER 1.
2. In SERVER 1 generate CREATECONTROLFILE statement by typing the following command
SQL>alter databasebackupcontrolfileto trace;
Now, go to the USER_DUMP_DEST directory and open the latest trace file. This file will contain
steps and as well as CREATECONTROLFILE statement. Copy the CREATECONTROLFILE
statement and paste in a file. Let the filename be cr.sql
The CREATECONTROLFILE Statement will look like this.
CREATECONTROLFILESET DATABASEprodLOGFILE GROUP 1 ('/u01/oracle/ica/log1.ora'
GROUP 2 ('/u01/oracle/ica/log2.ora'DATAFILE '/u01/oracle/ica/sys.dbf' SIZE 300M,
'/u01/oracle/ica/rbs.dbf' SIZE 50M,
'/u01/oracle/ica/usr.dbf' SIZE 50M,'/u01/oracle/ica/tmp.dbf' SIZE 50M,/u01/oracle/ica/sysaux.dbfsize 100M;
MAXLOGFILES 50MAXLOGMEMBERS 3MAXLOGHISTORY 400MAXDATAFILES 200MAXINSTANCES 6
ARCHIVELOG;
3. In SERVER 2 create the following directories
$cd /d01/oracle
$mkdir ica
$mkdir arc1
8/7/2019 Oracle 10g tutorial
33/83
$cdica
$mkdir bdump udumpcdump
Shutdown the database on SERVER 1 and transfer all datafiles, logfiles and control file to
SERVER 2 in /d01/oracle/ica directory.
Copy parameter file to SERVER 2 in /d01/oracle/dbs directory and copy all archive log files
to SERVER 2 in /d01/oracle/ica/arc1 directory. Copy the cr.sql script file to
/d01/oracle/ica directory.
4. Open the parameter file SERVER 2 and change the following parameters
CONTROL FILES=//d01/oracle/ica/control.oraBACKGROUND_DUMP_DEST=//d01/oracle/ica/bdumpUSER_DUMP_DEST=//d01/oracle/ica/udumpCORE_DUMP_DEST=//d01/oracle/ica/cdumpLOG_ARCHIVE_DEST_1=location=//d01/oracle/ica/arc1
5. Now, open the cr.sql file in text editor and change the locations like this
CREATECONTROLFILESET DATABASEprodLOGFILE GROUP 1 ('//d01/oracle/ica/log1.ora'
GROUP 2 ('//d01/oracle/ica/log2.ora'DATAFILE '//d01/oracle/ica/sys.dbf' SIZE 300M,
'//d01/oracle/ica/rbs.dbf' SIZE 50M,'//d01/oracle/ica/usr.dbf' SIZE 50M,'//d01/oracle/ica/tmp.dbf' SIZE 50M,//d01/oracle/ica/sysaux.dbfsize 100M;
MAXLOGFILES 50MAXLOGMEMBERS 3MAXLOGHISTORY 400MAXDATAFILES 200MAXINSTANCES 6
ARCHIVELOG;
In SERVER 2 export ORACLE_SID environment variable and start the instance
8/7/2019 Oracle 10g tutorial
34/83
$exportORACLE_SID=ica
$sqlplus
Enter User:/ assysdba
SQL>startup nomount;
6. Run cr.sql script to create the controlfile
SQL>@/d01/oracle/ica/cr.sql
7. Open the database
SQL>alter database open;
5. Managing the UNDO TABLESPACE
Managing the UNDO TABLESPACE
Oracle Database AdministrationLearn Oracle 10g database administrationstep by step
Oracle DBA Interview QuestionsFrequently asked Oracle DBA InterviewQuestions
Download Oracle 10g SoftwareLinks for downloading Oracle 10g softwareInstallation guides for installing Oracle underLinux, Solaris
8/7/2019 Oracle 10g tutorial
35/83
Every Oracle Database must have a method of maintaining information that is used to roll back,
or undo, changes to the database. Such information consists of records of the actions oftransactions, primarily before they are committed. These records are collectively referred to asundo.
Undo records are used to:
y Roll back transactions when a ROLLBACK statement is issued
y Recover the databasey Provide read consistencyy Analyze data as of an earlier point in time by using Flashback Queryy Recover from logical corruptions using Flashback features
Earlier releases of Oracle Database used rollback segments to store undo. Oracle9i introducedautomatic undo management, which simplifies undo space management by eliminating thecomplexities associated with rollback segment management. Oracle strongly recommends thatyou use undo tablespace to manage undo rather than rollback segments.
Switching to Automatic Management of Undo Space
To go for automatic management of undo space set the following parameter.
Steps:-
1. If you have not created an undo tablespace at the time of creating a database then, createan undo tablespace by typing the following command
SQL>create undo tablespacemyundo datafile/u01/oracle/ica/undo_tbs.dbfsize 500M
autoextendON next 5M;
When the system is first running in the production environment, you may be unsure ofthe space requirements of the undo tablespace. In this case, you can enable automaticextension for datafiles of the undo tablespace so that they automatically increase in size
when more space is needed
2. Shutdown the Database and set the following parameters in parameter file.
UNDO_MANAGEMENT=AUTOUNDO_TABLESPACE=myundo
3. Start the Database.
8/7/2019 Oracle 10g tutorial
36/83
Now Oracle Database will use Automatic Undo Space Management.
Calculating the Space Requirements For Undo Retention
You can calculate space requirements manually using the following formula:
UndoSpace = UR * UPS + overhead
where:
y UndoSpace is the number of undo blocks
y UR is UNDO_RETENTION in seconds. This value should take into consideration long-running queries and any flashback requirements.
y UPS is undo blocks for each secondy overhead is the small overhead for metadata (transaction tables, bitmaps, and so forth)
As an example, ifUNDO_RETENTION is set to 3 hours, and the transaction rate (U
PS) is 100 undoblocks for each second, with a 8K block size, the required undo space is computed as follows:
(3 * 3600 * 100 * 8K) = 8.24GBs
To get the values forUPS, Overhead query the V$UNDOSTAT view. By giving the followingstatement
SQL>Select * fromV$UNDOSTAT;
Altering UNDO Tablespace
If the Undo tablespace is full, you can resize existing datafiles or add new datafiles to it
The following example extends an existing datafile
SQL> alter database datafile /u01/oracle/ica/undo_tbs.dbf resize 700M
Thefollowing exampleaddsa new datafileto undo tablespace
SQL>ALTER TABLESPACEmyundo
ADDDATAFILE '/u01/oracle/ica/undo02.dbf' SIZE 200MAUTOEXTENDONNEXT 1MMAXSIZEUNLIMITED;
8/7/2019 Oracle 10g tutorial
37/83
Dropping an Undo Tablespace
Use the DROP TABLESPACE statement to drop an undo tablespace. The following example drops
the undo tablespace undotbs_01:
SQL>DROP TABLESPACEmyundo;
An undo tablespace can only be dropped if it is not currently used by any instance. If the undotablespace contains any outstanding transactions (for example, a transaction died but has not yet
been recovered), the DROP TABLESPACE statement fails.
Switching Undo Tablespaces
You can switch from using one undo tablespace to another. Because the UNDO_TABLESPACE
initialization parameter is a dynamic parameter, the ALTER SYSTEMSET statement can be used toassign a new undo tablespace.
The following statement switches to a new undo tablespace:
ALTER SYSTEMSET UNDO_TABLESPACE = myundo2;
Assuming myundo is the current undo tablespace, after this command successfully executes, the
instance uses myundo2 in place ofmyundo as its undo tablespace.
Viewing Information about Undo Tablespace
To view statistics for tuning undo tablespace query the following dictionary
SQL>select * from v$undostat;
To see how many active Transactions are there and to see undo segment information give thefollowing command
SQL>select * from v$transaction;
To see the sizes of extents in the undo tablespace give the following query
SQL>select * fromDBA_UNDO_EXTENTS;
6. SQL Loader
8/7/2019 Oracle 10g tutorial
38/83
SQL LOADER utility is used to load data from other data source into Oracle. For example, ifyou have a table in FOXPRO, ACCESS or SYBASE or any other third party database, you canuse SQL Loader to load the data into Oracle Tables. SQL Loader will only read the data fromFlat files. So If you want to load the data from Foxpro or any other database, you have to firstconvert that data into Delimited Format flat file or Fixed length format flat file, and then use
SQL loader to load the data into Oracle.
Following is procedure to load the data from Third Party Database into Oracle using SQLLoader.
1. Convert the Data into Flat file using third party database command.2. Create the Table Structure in Oracle Database using appropriate datatypes3. Write a Control File, describing how to interpret the flat file and options to load the data.4. Execute SQL Loader utility specifying the control file in the command line argument
To understand it better let us see the following case study.
CASE STUDY (Loading Data from MS-ACCESS to Oracle)
Suppose you have a table in MS-ACCESS by name EMP, running under Windows O/S, with thefollowing structure
EMPNO INTEGERNAME TEXT(50)SAL CURRENCYJDATE DATE
This table contains some 10,000 rows. Now you want to load the data from this table into anOracle Table. Oracle Database is running in LINUXO/S.
Solution
Steps
Start MS-Access and convert the table into comma delimited flat (popularly known as csv) , by
clicking on File/SaveAs menu. Let the delimited file name be emp.csv
1. Now transfer this file to Linux Server using FTP command
a. Go to Command Prompt in windowsb. At the command prompt type FTP followed by IP address of the server runningOracle.
FTP will then prompt you for username and password to connect to the LinuxServer. Supply a valid username and password of Oracle User in LinuxFor example:-C:\>ftp 200.200.100.111
8/7/2019 Oracle 10g tutorial
39/83
Name: oraclePassword:oracleFTP>
c. Now give PUT command to transfer file from current Windows machine to Linuxmachine.
FTP>putLocalfile:C:\>emp.csvremote-file:/u01/oracle/emp.csvFiletransferredin 0.29 SecondsFTP>
d. Now after the file is transferred quit the FTP utility by typing bye command.
FTP>byeGood-Bye
2. Now come the Linux Machine and create a table in Oracle with the same structure as in
MS-ACCESS by taking appropriate datatypes. For example, create a table like this
$sqlplusscott/tigerSQL>CREATE TABLEemp (empno number(5),
name varchar2(50),sal number(10,2),jdatedate);
3. After creating the table, you have to write a control file describing the actions which SQL
Loader should do. You can use any text editor to write the control file. Now let us write
a controlfile for our case study
$viemp.ctl1 LOADDATA2 INFILE /u01/oracle/emp.csv3 BADFILE /u01/oracle/emp.bad4 DISCARDFILE /u01/oracle/emp.dsc5 INSERT INTO TABLEemp6 FIELDS TERMINATEDBY , OPTIONALLYENCLOSEDBY
TRAILING NULLCOLS7 (empno,name,sal,jdatedate mm/dd/yyyy)
Notes:(Do not write the line numbers, they are meant for explanation purpose)
1. The LOADDATA statement is required at the beginning of the control file.
2. The INFILE option specifies where the input file is located
3. Specifying BADFILE is optional. If you specify, then bad records found during loading will bestored in this file.
8/7/2019 Oracle 10g tutorial
40/83
4. Specifying DISCARDFILE is optional. If you specify, then records which do not meet a WHENcondition will be written to this file.
5. You can use any of the following loading option
1. INSERT : Loads rows only if the target table is empty
2. APPEND: Load rows if the target table is empty or not.
3. REPLACE: First deletes all the rows in the existing table and then, load rows.
4. TRUNCATE: First truncates the table and then load rows.
6. This line indicates how the fields are separated in input file. Since in our case the fields are separatedby , so we have specified , as the terminating char for fields. You can replace this by any charwhich is used to terminate fields. Some of the popularly use terminating characters are semicolon
;, colon :, pipe | etc. TRAILINGNULLCOLSmeans if the last column is null then
treat this as null value, otherwise, SQLLOADER will treat the record as bad if the last column isnull.
7. In this line specify the columns of the target table. Note how do you specify format for Date columns
4. After you have wrote the control file save it and then, call SQLLoader utility by typingthe following command
$sqlldr userid=scott/tiger control=emp.ctllog=emp.log
After you have executed the above command SQLLoader will shows you the output
describing how many rows it has loaded.
The LOG option ofsqlldr specifies where the log file of this sql loader session should
be created. The log file contains all actions which SQLloader has performed i.e. how
many rows were loaded, how many were rejected and how much time is taken to load the
rows and etc. You have to view this file for any errors encountered while running SQL
Loader.
CASE STUDY (Loading Data from Fixed Length file into Oracle)
Suppose we have a fixed length format file containing employees data, as shown below, and
wants to load this data into an Oracle table.
7782 CLARK MANAGER 7839 2572.50 10
7839 KING PRESIDENT 5500.00 10
7934 MILLER CLERK 7782 920.00 10
7566 JONES MANAGER 7839 3123.75 20
8/7/2019 Oracle 10g tutorial
41/83
7499 ALLEN SALESMAN 7698 1600.00 300.00 30
7654 MARTIN SALESMAN 7698 1312.50 1400.00 30
7658 CHAN ANALYST 7566 3450.00 20
7654 MARTIN SALESMAN 7698 1312.50 1400.00 30
SOLUTION:
Steps :-
1. First Open the file in a text editor and count the length of fields, for example in ourfixed length file, employee number is from 1st position to 4th position, employee nameis from 6th position to 15th position, Job name is from 17th position to 25th position.
Similarly other columns are also located.2. Create a table in Oracle, by any name, but should match columns specified in fixed
length file. In our case give the following command to create the table.
SQL>CREATE TABLEemp (empno NUMBER(5),nameVARCHAR2(20),job VARCHAR2(10),mgr NUMBER(5),sal NUMBER(10,2),commNUMBER(10,2),
deptno NUMBER(3));
3. After creating the table, now write a control file by using any text editor$viempfix.ctl1) LOADDATA2) INFILE '/u01/oracle/fix.dat'3) INTO TABLEemp4) (empno POSITION(01:04) INTEGER EXTERNAL,
name POSITION(06:15) CHAR,job POSITION(17:25) CHAR,
mgr POSITION(27:30) INTEGER EXTERNAL,sal POSITION(32:39) DECIMALEXTERNAL,comm POSITION(41:48) DECIMALEXTERNAL,
5) deptno POSITION(50:51) INTEGER EXTERNAL)
Notes:(Do not write the line numbers, they are meant for explanation purpose)
1. The LOAD DATA statement is required at the beginning of the control file.2. The name of the file containing data follows the INFILE parameter.
8/7/2019 Oracle 10g tutorial
42/83
3. The INTO TABLE statement is required to identify the table to be loaded into.4. Lines 4 and 5 identify a column name and the location of the data in the datafile to be loaded into that
column. empno, name, job, and so on are names of columns in table emp. The datatypes (INTEGEREXTERNAL, CHAR, DECIMAL EXTERNAL) identify the datatype of data fields in the file, not ofcorresponding columns in the emp table.
5. Note that the set of column specifications is enclosed in parentheses.
4. After saving the control file now start SQL Loader utility by typing the following command.
$sqlldr userid=scott/tiger control=empfix.ctllog=empfix.logdirect=y
After you have executed the above command SQLLoader will shows you the output
describing how many rows it has loaded.
Loading Data into Multiple Tables using WHEN condition
You can simultaneously load data into multiple tables in the same session. You can also useWHEN condition to load only specified rows which meets a particular condition (only equal to= and not equal to conditions are allowed).
For example, suppose we have a fixed length file as shown below
7782 CLARK MANAGER 7839 2572.50 10
7839 KING PRESIDENT 5500.00 10
7934 MILLER CLERK 7782 920.00 10
7566 JONES MANAGER 7839 3123.75 20
7499 ALLEN SALESMAN 7698 1600.00 300.00 30
7654 MARTIN SALESMAN 7698 1312.50 1400.00 30
7658 CHAN ANALYST 7566 3450.00 20
7654 MARTIN SALESMAN 7698 1312.50 1400.00 30
Now we want to load all the employees whose deptno is 10 into emp1 table and those
employees whose deptno is not equal to 10 in emp2 table. To do this first create the tables
emp1 and emp2 by taking appropriate columns and datatypes. Then, write a control file as
shown below
$viemp_multi.ctl
8/7/2019 Oracle 10g tutorial
43/83
LoadDatainfile /u01/oracle/empfix.datappendinto tablescott.emp1WHEN (deptno=10 )(empno POSITION(01:04) INTEGER EXTERNAL,name
POSITION
(06:15)
CHAR,
job POSITION(17:25) CHAR,mgr POSITION(27:30) INTEGER EXTERNAL,sal POSITION(32:39) DECIMALEXTERNAL,comm POSITION(41:48) DECIMALEXTERNAL,deptno POSITION(50:51) INTEGER EXTERNAL)
INTO TABLEscott.emp2WHEN (deptno10 )(empno POSITION(01:04) INTEGER EXTERNAL,name POSITION(06:15) CHAR,job POSITION(17:25) CHAR,mgr POSITION(27:30) INTEGER EXTERNAL,
sal POSITION(32:39) DECIMALEXTERNAL,comm POSITION(41:48) DECIMALEXTERNAL,deptno POSITION(50:51) INTEGER EXTERNAL)
After saving the file emp_multi.ctl run sqlldr$sqlldr userid=scott/tiger control=emp_multi.ctl
Conventional Path Load and Direct Path Load.
SQL Loader can load the data into Oracle database using Conventional Path method or Direct
Path method. You can specify the method by using DIRECT command line option. If you give
DIRECT=TRUE then SQL loader will use Direct Path Loading otherwise, if omit this option or
specify DIRECT=false, then SQL Loader will use Conventional Path loading method.
Conventional Path
Conventional path load (the default) uses the SQL INSERT statement and a bind array buffer to
load data into database tables.
When SQL*Loader performs a conventional path load, it competes equally with all otherprocesses for buffer resources. This can slow the load significantly. Extra overhead is added as
SQL statements are generated, passed to Oracle, and executed.
The Oracle database looks for partially filled blocks and attempts to fill them on each insert.Although appropriate during normal use, this can slow bulk loads dramatically.
8/7/2019 Oracle 10g tutorial
44/83
Direct Path
In Direct Path Loading, Oracle will not use SQL INSERT statement for loading rows. Instead it
directly writes the rows, into fresh blocks beyond High Water Mark, in datafiles i.e. it does notscan for free blocks before high water mark. Direct Path load is very fast because
y Partial blocks are not used, so no reads are needed to find them, and fewer writes areperformed.
y SQL*Loader need not execute any SQL INSERT statements; therefore, the processing
load on the Oracle database is reduced.y A direct path load calls on Oracle to lock tables and indexes at the start of the load and
releases them when the load is finished. A conventional path load calls Oracle once for
each array of rows to process a SQL INSERT statement.
y A direct path load uses multiblock asynchronous I/O for writes to the database files.y During a direct path load, processes perform their own write I/O, instead of using
Oracle's buffer cache. This minimizes contention with other Oracle users.
Restrictions on Using Direct Path Loads
The following conditions must be satisfied for you to use the direct path load method:
y Tables are not clustered.y Tables to be loaded do not have any active transactions pending.y Loading a parent table together with a child Table
y Loading BFILE columns
7. Export and Import
These tools are used to transfer data from one oracle database to another oracle database. YouExport tool to export data from source database, and Import tool to load data into the targetdatabase. When you export tables from source database export tool will extracts the tables andputs it into the dump file. This dump file is transferred to the target database. At the targetdatabase the Import tool will copy the data from dump file to the target database.
From Ver. 10g Oracle is recommending to use Data Pump Export and Import tools, which are
enhanced versions of original Export and Import tools.
The export dump file contains objects in the following order:
1. Type definitions2. Table definitions3. Table data4. Table indexes
8/7/2019 Oracle 10g tutorial
45/83
5. Integrity constraints, views, procedures, and triggers6. Bitmap, function-based, and domain indexes
When you import the tables the import tool will perform the actions in the following order, new
tables are created, data is imported and indexes are built, triggers are imported, integrityconstraints are enabled on the new tables, and any bitmap, function-based, and/or domainindexes are built. This sequence prevents data from being rejected due to the order in whichtables are imported. This sequence also prevents redundant triggers from firing twice on thesame data
Invoking Export and Import
You can run Export and Import tool in two modes
Command Line Mode
Interactive Mode
When you just type exp or imp at o/s prompt it will run in interactive mode i.e. these tools willprompt you for all the necessary input. If you supply command line arguments when calling expor imp then it will run in command line mode
Command Line Parameters of Export tool
You can control how Export runs by entering the EXP command followedby various arguments. To specify parameters, you use keywords:
Format: EXPKEYWORD=value or KEYWORD=(value1,value2,...,valueN)
Example: EXPSCOTT/TIGER GRANTS=Y TABLES=(EMP,DEPT,MGR)
or TABLES=(T1:P1,T1:P2),if T1 ispartitionedtable
Keyword Description (Default)
--------------------------------------------------------------
USERID username/password
BUFFER size of data buffer
8/7/2019 Oracle 10g tutorial
46/83
FILE output files (EXPDAT.DMP)
COMPRESS import into one extent (Y)
GRANTS export grants (Y)
INDEXES export indexes (Y)
DIRECT direct path (N)
LOG log file of screen output
ROWS export data rows (Y)
CONSISTENT cross-table consistency(N)
FU
LL export entire file (N)
OWNER list of owner usernames
TABLES list of table names
RECORDLENGTH length of IO record
INCTYPE incremental export type
RECORD track incr. export (Y)
TRIGGERS export triggers (Y)
STATISTICS analyze objects (ESTIMATE)
PARFILE parameter filename
CONSTRAINTS export constraints (Y)OBJECT_CONSISTENT transaction set to read only during object export (N)
FEEDBACK display progress every x rows (0)
FILESIZE maximum size of each dump file
FLASHBACK_SCN SCN used to set session snapshot back to
FLASHBACK_TIME time used to get the SCN closest to the specified time
QUERY select clause used to export a subset of a table
8/7/2019 Oracle 10g tutorial
47/83
RESUMABLE suspend when a space related error is encountered(N)
RESUMABLE_NAME text string used to identify resumable statement
RESUMABLE_TIMEOUT wait time for RESUMABLE
TTS_FULL_CHECK perform full or partial dependency check for TTS
TABLESPACES list of tablespaces to export
TRANSPORT_TABLESPACE export transportable tablespace metadata (N)
TEMPLATE template name which invokes iAS mode export
The Export and Import tools support four modes of operation
FULL :Exports all the objects in all schemas
OWNER :Exports objects only belonging to the given OWNER
TABLES :Exports Individual Tables
TABLESPACE :Export all objects located in a given TABLESPACE.
Example of Exporting Full Database
The following example shows how to export full database
$expUSERID=scott/tiger FULL=y FILE=myfull.dmp
In the above command, FILE option specifies the name of the dump file, FULL option specifies
that you want to export the full database, USERID option specifies the user account to connect to
the database. Note, to perform full export the user should have DBA orEXP_FULL_DATABASE
privilege.
Example of Exporting Schemas
To export Objects stored in a particular schemas you can run export utility with the followingarguments
$expUSERID=scott/tiger OWNER=(SCOTT,ALI) FILE=exp_own.dmp
The above command will export all the objects stored in SCOTT and ALIs schema.
Exporting Individual Tables
To export individual tables give the following command
8/7/2019 Oracle 10g tutorial
48/83
$expUSERID=scott/tiger TABLES=(scott.emp,scott.sales)FILE=exp_tab.dmp
This will export scotts emp and sales tables.
Exporting Consistent Image of the tables
If you include CONSISTENT=Y option in export command argument then, Export utility will
export a consistent image of the table i.e. the changes which are done to the table during exportoperation will not be exported.
Using Import Utility
Objects exported by export utility can only be imported by Import utility. Import utility can runin Interactive mode or command line mode.
You can let Import prompt you for parameters by entering the IMP command followed by yourusername/password:
Example: IMPSCOTT/TIGER
Or, you can control how Import runs by entering the IMP command followed
by various arguments. To specify parameters, you use keywords:
Format: IMPKEYWORD=value orKEYWORD=(value1,value2,...,valueN)
Example: IMPSCOTT/TIGER IGNORE=Y TABLES=(EMP,DEPT) FULL=N
or TABLES=(T1:P1,T1:P2),if T1 ispartitionedtable
USERID must be the first parameter on the command line.
Keyword Description (Default)USERID username/passwordBUFFER size of data buffer
FILE input files (EXPDAT.DMP)SHOW just list file contents (N)IGNORE ignore create errors (N)GRANTS import grants (Y)INDEXES import indexes (Y)ROWS import data rows (Y)LOG log file of screen outputFULL import entire file (N)
8/7/2019 Oracle 10g tutorial
49/83
FROMUSER list of owner usernamesTOUSER list of usernamesTABLES list of table namesRECORDLENGTH length of IO recordINCTYPE incremental import type
COMMIT commit array insert (N)PARFILE parameter filenameCONSTRAINTS import constraints (Y)DESTROY overwrite tablespace data file (N)INDEXFILE write table/index info to specified fileSKIP_UNUSABLE_INDEXES skip maintenance of unusable indexes (N)FEEDBACK display progress every x rows(0)TOID_NOVALIDATE skip validation of specified type idsFILESIZE maximum size of each dump fileSTATISTICS import precomputed statistics (always)RESUMABLE suspend when a space related error is encountered(N)
RESUMABLE_NAME text string used to identify resumable statementRESUMABLE_TIMEOUT wait time for RESUMABLECOMPILE compile procedures, packages, and functions (Y)STREAMS_CONFIGURATION import streams general metadata (Y)STREAMS_INSTANITATION import streams instantiation metadata (N)
Example Importing Individual Tables
To import individual tables from a full database export dump file give the following command
$impscott/tiger FILE=myfullexp.dmp FROMUSER=scott
TABLES=(emp,dept)
This command will import only emp, dept tables into Scott user and you will get a output
similar to as shown below
ExportfilecreatedbyEXPORT:V10.00.00 viaconventionalpath
importdonein WE8DECcharacter setandAL16UTF16 NCHAR character set
.importing SCOTT's objectsinto SCOTT
..importing table "DEPT" 4 rowsimported
..importing table "EMP" 14 rowsimported
Importterminatedsuccessfully without warnings.
8/7/2019 Oracle 10g tutorial
50/83
Example, Importing Tables of One User account into another User account
For example, suppose Ali has exported tables into a dump file mytables.dmp. Now Scott
wants to import these tables. To achieve this Scott will give the following import command
$impscott/tiger FILE=mytables.dmp FROMUSER=ali TOUSER=scott
Then import utility will give a warning that tables in the dump file was exported by user Ali andnot you and then proceed.
Example Importing Tables Using Pattern Matching
Suppose you want to import all tables from a dump file whose name matches a particular pattern.
To do so, use % wild character in TABLES option. For example, the following command will
import all tables whose names starts with alphabet e and those tables whose name contains
alphabet d
$impscott/tiger FILE=myfullexp.dmp FROMUSER=scottTABLES=(a%,%d%)
Migrating a Database across platforms.
The Export and Import utilities are the only method that Oracle supports for moving an existingOracle database from one hardware platform to another. This includes moving between UNIXand NT systems and also moving between two NT systems running on different platforms.
The following steps present a general overview of how to move a database between platforms.
1. As a DBA user, issue the following SQL query to get the exact name of all tablespaces.You will need this information later in the process.
SQL>SELECT tablespace_name FROMdba_tablespaces;
2. As a DBA user, perform a full export from the source database, for example:
>expsystem/manager FULL=y FILE=myfullexp.dmp
3. Move the dump file to the target database server. If you use FTP, be sure to copy it in
binary format (by entering binary at the FTP prompt) to avoid file corruption.4. Create a database on the target server.5. Before importing the dump file, you must first create your tablespaces, using the
information obtained in Step 1. Otherwise, the import will create the correspondingdatafiles in the same file structure as at the source database, which may not be compatiblewith the file structure on the target system.
6. As a DBA user, perform a full import with the IGNORE parameter enabled:
8/7/2019 Oracle 10g tutorial
51/83
>impsystem/manager FULL=yIGNORE=y FILE=myfullexp.dmp
Using IGNORE=y instructs Oracle to ignore any creation errors during the import and permit the importto complete.
7. Perform a full backup of your new database.
8. DATA PUMP Utility
tarting with Oracle 10g, Oracle has introduced an enhanced version of EXPORT and IMPORTutility known as DATA PUMP. Data Pump is similar to EXPORT and IMPORT utility but it hasmany advantages. Some of the advantages are:
yMost Data Pump export and import operations occur on the Oracle database server. i.e.all the dump files are created in the server even if you run the Data Pump utility fromclient machine. This results in increased performance because data is not transferredthrough network.
y You c
Top Related