Thursday, 18 February 2016

Oracle Data Export and Import utility

The Import and Export utilities work together; Export sends database definitions and actual data to an export file and Import can read the file to perform many different tasks. You can use Export and Import for many important database tasks, such as restoring a table, generating CREATE scripts, copying data among Oracle databases, migrating among Oracle versions, and moving tables from one schema to another.

Oracle’s export (exp) and import (imp) utilities are used to perform logical database backup and recovery. When exporting, database objects are dumped to a binary file which can then be imported into another Oracle database.
These utilities can be used to move data between different machines, databases or schema. However, as they use a proprietary binary file format, they can only be used between Oracle databases. One cannot export data and expect to import it into a non-Oracle database.
Various parameters are available to control what objects are exported or imported. To get a list of available parameters, run the exp or imp utilities with the help=yes parameter i.e. “exp help=yes” or “imp help=yes“.
The export/import utilities are commonly used to perform the following tasks:
  • Back up and recover objects. Perhaps the most widely used Export and Import feature is the capability to serve as a useful backup solution. Most Oracle installations use full online or hot backups to back up the entire database in the event of a CPU, network, or disk failure. This works well because all data can be restored to the very millisecond that the database crashed. However, Export and Import provide for extra safety. If just one table in the entire database needs to be recovered during a full backup, the entire database would have to be recovered on another machine, and the one table would be copied back over into the original database. This incredibly time- and resource-consuming task could become a real headache in distributed databases. Export and Import can save you this trouble by exporting the entire database and importing just the tables that need to be recovered. Now that point-in-time recovery is an option fortablespaces in Oracle8, Export and Import can also serve as a backup and recovery mechanism for the entire database.
  • Copy objects among schemas. You can use Export and Import to copy all object types such as tables, indexes, grants, procedures, and views from one schema to another. You can specify which objects you want to move, and provide the FROM and TO schemas. Oracle does the rest automatically.
  • Copy objects among Oracle databases. You can export a table in one Oracle database and import that table into another. Many businesses export key tables and send the export files to a remote office location, which can then use Import to load the data into its local database. This is a form of one-way data replication to remote locations.
  • Generate CREATE scripts. Export and Import contain powerful options that allow you to generate CREATE scripts for tables, partitions, indexes, object-type definitions, views, grants, constraints, rollback segments, tablespaces, and all other objects in the database. This safeguards the structure of your objects, in case one gets corrupted or deleted.
  • Migrate databases from one Oracle version to another. You can upgrade (or downgrade) the version of Oracle by using the Export and Import utilities. For example, you can export an Oracle7 database, copy the export file to an Oracle8 database server, and then import into the Oracle8 server. This process, calledmigration, makes the data and application function in an Oracle8 environment. Of course, we always recommend complete testing before relying on the results of a migration.
  • Defragment a tablespace. Fragmentation occurs when tables and indexes are created, dropped, enlarged, and reduced in size over time. Fragmentation also occurs when an object’s storage parameters are sized improperly. To defragment a tablespace, you can export a tablespace, coalesce the free space (or drop and recreate the tablespace), and import the objects again.
Because of the special binary format, files which had been created by the EXPORT utility can only be read by IMPORT. Both tools are only used to maintain ORACLE database objects.
SQL*Loader is similar to Import in that it can load data; the main difference is that Import can read only Oracle export files. SQL*Loader can read text files generated by non-Oracle databases.To load data from other systems into the database you have to use SQL*LOADER or other programs. To store data from database into readable operating system files you may use e.g. REPORTS, SQLPLUS.
While still supported on 10g the original import (imp) and export (exp) utilities were replaced in 10g with the faster and more advanced Data Pump-based import-export, impdp and expdp.
NOTE: It is generally advised not to use exports as the only means of backing-up a database. Physical backup methods (for example, when you use RMAN) are normally much quicker and supports point in time based recovery (apply archivelogs after recovering a database). Also, exp/imp is not practical for large database environments.
On 11g just imp will be still available, so if you using 10g, now is the time to starting using data pump.

Prerequisites/Requirements

exp and imp are utilities present in the $ORACLE_HOME/bin directory and are installed when Oracle is installed. Their prime purpose is to move logical objects out of and into the database respectively – for example dumping all of the tables owned by a user to a single file is achieved using the exp utility. It is important to distinguish between dumping data in this manner and backing up the database which is normally achieved using the rman utility.
$ORACLE_HOME, $ORACLE_SID and $PATH environment variables need to be set appropriately in a unix environment and the %ORACLE_SID% environment variable needs to be set in a windows environment, before executing these commands. If you login as the owner of the oracle software (usually the oracle user on unix) these are likely to have been set in the users profile. The Oracle Database instance needs to be up in order to export/import data. Type ‘imp help=y’ or ‘exp help=y’ for a detailed explanation of the available options for these utilities.
It is a prerequisite that oraenv or coraenv (if you are working in a c-shell) was executed before you export-import data. Consider, if you stored data in the database by using an national language support (NLS) other than AMERICAN you have to change your environment before import-export.
Example for a german environment:
NLS_LANG=GERMAN_GERMANY.WE8ISO8859P1
export NLS_LANG
In order to use exp and imp, the catexp.sql script must be run. catexp.sql basically creates theexp_full_database and imp_full_database roles. It is found under $ORACLE_HOME/rdbms/admin:
SQL> @?/rdbms/admin/catexp
catexp is called by catalog.sql. Note: SQL*Plus provides a shortcut to refer to the ORACLE_HOME directory: the question mark (?).
One must have the create session privilege for being able to use exp. If objects of another user’s schema need to be exported, the EXP_FULL_DATABASE role is required.
Before one imports rows into already populated tables, one needs to truncate or drop these tables to get rid of the old data. If not, the new data will be appended to the existing tables or it’ll get rejected. Either way, use the same syntax when you are ready to import the data. One must always DROP existing Sequences before re-importing. If the sequences are not dropped, they will generate numbers inconsistent with the rest of the database.
Note: It is also advisable to drop indexes before importing to speed up the import process. Indexes can easily be recreated after the data was successfully imported.
Control and Configure Export-Import
FULL, OWNER, and TABLE are the three types of exports. A FULL export exports all objects, structures, and data within the database for all schemas. OWNER exports only those objects owned by the specified user accounts. TABLE exports only the specified tables and partitions for specific user accounts.
Because dozens of object types can be exported, it’s important to distinguish what gets exported with each export category:
  • With TABLE, the specified table (or cluster or partition) is exported with its indexes, referential integrity constraints, synonyms, and triggers.
  • With OWNER specified, all the specified schema’s objects are exported. This includes database links, sequences, packages/procedures/functions, object-type definitions, clusters/tables/partitions, postable actions, synonyms, views, triggers, snapshots/snapshot logs, job queues, and refresh groups.
  • With the FULL option, all objects described in OWNER are exported for every user account, in addition to tablespace definitions, profiles, user definitions (and encrypted passwords), roles, resource costs, rollback segment definitions, directory aliases, user history table, and auditing options.
You can use the Export and Import utilities in interactive or non-interactive mode. In interactive mode, Oracle steps you through the process, prompting for basic Import/Export session information. This method, however, limits you to the simple prompts that Oracle provides. You have more flexibility in non-interactive mode because you can supply up to 23 parameters for the Export utility and 24 parameters for the Import utility. The parameters may be supplied at the command line or by specifying a command file that contains all parameters and values. You can automate Export and Import sessions by using a command file, or repeat them over and over again manually.
The syntax of running Export and Import is as follows:
EXP KEYWORD=value or keyword=(value1,value2,…,valueN)
IMP KEYWORD=value or keyword=(value1,value2,…,valueN)
Replace KEYWORD with the parameter, and value with what should be the parameter’s value. For example, use the following to export the entire database:
EXP USERID=SYSTEM/MANAGER FULL=Y
Use the following to import the EMP and DEPT tables owned by the SCOTT user account: IMP USERID=SYSTEM/MANAGER FROMUSER=SCOTT TABLES=(EMP,DEPT)The following examples demonstrate how the imp/exp utilities can be used:
exp scott/tiger file=emp.dmp log=emp.log tables=emp rows=yes indexes=no
exp scott/tiger file=emp.dmp tables=(emp,dept)
imp scott/tiger file=emp.dmp full=yes
imp scott/tiger file=emp.dmp fromuser=scott touser=scott tables=dept
Using a parameter file:
exp userid=scott/tiger@orcl parfile=export.txt
… where export.txt contains:
BUFFER=100000
FILE=account.dmp
FULL=n
OWNER=scott
GRANTS=y
COMPRESS=y
NOTE: If you do not like command line utilities, you can import and export data with the “Schema Manager” GUI that ships with Oracle Enterprise Manager (OEM).
———————————————————————————–
The EXPORT utility may be used in three ways:
  • Interactive dialogue
    Simply type exp. You will be prompted for your ORACLE userid, password. All other prompts answer by pressing the return key. This is the easiest way to export all data you stored in the ORACLE database. You may assign other values than the defaults to the parameters but in most cases it is unnecessary.
  • Controlled through bypassed parameters
    You may bypass parameters when you export data from the database. Type:
    exp <userid/password> <parameter>=<value>,<parameter>=<value>,…
    Example of exporting scott’s tables EMP and DEPT to file empdept.expdat and storing all messages to file empdept.log:
    exp scott/tiger file=empdept.expdat tables=(EMP,DEPT) log=empdept.log
  • Parameterfile controlled
    Instead of typing the parameters on the commandline you may use a parameter file where the parameters are stored. The syntax for this method is: exp <userid/password> parfile=<filename>
Do not ignore warnings and messages. Look at your logfile and repeat EXPORT until you get messages like:
About to export specified tables ...
. exporting table                            EMP       14 rows exported
. exporting table                           DEPT        4 rows exported
Export terminated successfully without warnings.
--------------------------------------------------------------------------------------
Like Export the Import utility is controlled by parameters. To get familiar with these parameters type: imp help=y
You will get a short description of usage and default settings of parameters.
To start IMPORT simply type imp. You will be prompted for your ORACLE userid, password. The next prompts depend on what you answer. In most cases you may answer the prompts by pressing the return key. But the following prompts you have to answer carefully.
Import file: expdat.dmp >
If your data was exported to file expdat.dmp press return, otherwise enter the filename where the exported data resides.
Ignore create error due to object existence (yes/no): yes >
This is a flag to indicate how object creation errors should be handeld. If you import into an existing table and you set IGNORE=Y, rows could be duplicated if they where already present in the table.
Import entire export file (yes/no): yes > no
Username:
If your exportfile consists of more objects than you want to import, enter no. In this case you will be prompted for the Username (this is normally your ORACLE account). Enter table names. Null list means all tables for user
Enter table name or . if done:
After entering the username you will be prompted for table names until you press the return key without entering a table name. Than IMPORT will be started.

Instead of the dialogue method you may use parameters. This is analogous to the methods described for EXPORT.
Examples:
imp <userid/password> tables=(table1,table2)
Tables table1, table2 will be imported from the default file export.dmp into the database.
imp <userid/password> parfile=<filename>
Import will be controlled by the named parameterfile.
After importing you should get messages like:
importing SCOTT's objects into SCOTT
. importing table "DEPT"                                     4 rows imported
. importing table "EMP"                                     14 rows imported
Import terminated successfully without warnings.
-----------------------------------------------------------------------------------
Parameters for the Export utility
Table below lists all parameters that can be used with the Export utility, along with their default values (if any).
Parameter
Default Value
Description
BUFFER
OS-dependent
The size of BUFFER (in bytes) determines the memory buffer through which rows are exported. This should be larger than the size of the largest record multiplied by the number of rows that you want to fit within the buffer.
COMPRESS
Y
If COMPRESS=Y, the INITIAL storage parameter is set to the total size of all extents allocated for the object. The change takes effect only when the object is imported.
CONSISTENT
N
Setting CONSISTENT=Y exports all tables and references in a consistent state. This slows the export, as rollback space is used. If CONSISTENT=N and a record is modified during the export, the data will become inconsistent.
CONSTRAINTS
N
Specifies whether table constraints are exported.
DIRECT
N
If DIRECT=Y, Oracle bypasses the SQL command-processing layer, improving the speed of the export. Unfortunately, the new object types endemic to Oracle8, such as LOBs, don’t get exported.
FEEDBACK
0
Oracle displays a period for each group of records inserted. FEEDBACK defines the size of the group. For example, if FEEDBACK=1000, a period will be displayed for every 1,000 records imported. This parameter is useful for tracking the progress of large imports.
FILE
expdat.dmp
By default, expdat.dmp (stands for EXPort DATa.DuMP) is the filename. For a more meaningful name, change the FILE parameter.
FULL
N
The entire database will be exported if FULL=Y, including tablespace definitions.
GRANTS
Y
Specifies whether all grant definitions are exported for the objects being exported.
HELP
N
No other parameters are needed if you specify HELP=Y. A basic help screen will appear.
INCTYPE

The valid options for this parameter are COMPLETE, CUMULATIVE, and INCREMENTAL. A COMPLETE export lays down a full export for which the other two options rely on for restores of the database. CUMULATIVE exports all tables and other objects that have changed since the last CUMULATIVE or COMPLETE export was taken; if one record in a table is altered, the entire table is exported. INCREMENTAL exports all tables and objects that have changed since the last INCREMENTAL, CUMULATIVE, or COMPLETE export.
How can you easily see the Export/Import parameters and syntax?
If you don’t have this book handy when necessary and haven’t memorized the dozens of parameters, the Export and Import utilities have a handy reference built in. Typing EXP HELP=Y or IMP HELP=Y at a command prompt brings up a nice one-page reference manual.
Parameter
Default Value
Description
INDEXES
Y
Specifies whether user-defined indexes are exported. System indexes created with constraints (primary key, unique key) and OID indexes are automatically exported, regardless of this parameter’s value.
LOG

Specifies the name of the file to spool the feedback from the export session. Unless otherwise specified, Oracle appends a .LOG extension to the file.
PARFILE

Rather than enter all parameters on the command line, some or all can be kept in a parameter file. This parameter specifies which file to use, if desired. This parameter is especially useful for non-interactive import sessions.
POINT_IN_TIME_RECOVER
N
Exports information for a point-in-time recovery for the tablespace listed with the TABLESPACES parameter.
RECORD
Y
If you use the INCTYPE parameter with RECORD=Y, the SYS data dictionary tables INCEXP, INCFIL, and INCVID are populated with export data such as owner, type of export, and the time of export.
RECORDLENGTH
OS-dependent
The RECORDLENGTH parameter is used only when you’ll import on a machine with a different byte count of the file than on the machine where the export occurs. The default should be used in most import sessions.
RECOVERY_TABLESPACES

Used with POINT_IN_TIME_RECOVER;specifies which tablespaces can be recovered by using point-in-time recovery. This is important because imports otherwise can’t recover transactions past the time of export.
ROWS
Y
Specifies whether table and object data will be exported. If ROWS=N, only object definitions are exported.
STATISTICS
ESTIMATE
Specifies whether table and index statistics are to be analyzed with COMPUTE or ESTIMATE when imported. Only those objects that already have statistics on them will be analyzed during import. Specify NONE if no objects should be analyzed.
TABLES

Specifies a comma-separated list of all tables to be exported. This parameter could be used with the OWNER parameter to specify which owner to associate the tables with. Tables can also be specified with the owner.table_name format. In a non-UNIX environment such as Windows NT, you must enclose the table list within parentheses.
TABLESPACES

List of tablespaces to be exported with the POINT_IN_TIME_RECOVER parameter.
USERID

Specifies the username and password for the user conducting the import. The format for the command is username/password. You can also use Net8’s @connect_string format if you want.
Parameters for the Import utility
You can use 24 parameters during an import session. They may be specified in the command line or any specified parameter file. Table below lists all the import parameters.
Parameter
Default Value
Description
ANALYZE
Y
Imported tables have their statistics analyzed if ANALYZE is set to Y. Only those tables that already had statistics on them during the export are computed. The tables will be ESTIMATED by default, unless the export was performed with the STATISTICS=COMPUTE parameter configuration.
BUFFER
OS-dependent
The BUFFER size (in bytes) determines the memory buffer through which rows are imported. This should be larger than the size of the largest record multiplied by the number of rows that you want to fit within the buffer.
CHARSET

An obsolete Oracle6 parameter, indicating whether the export was done in ASCII or EBCDIC. This information is processed automatically in Oracle7 and Oracle8.
COMMIT
N
By default, a COMMIT occurs after each table, nested table, and partition. If you’re importing a large table, the rollback segments may grow large. To improve performance while loading large tables, you should set COMMIT=Y.
DESTROY
N
If you set DESTROY=Y and do a full import, Oracle will overwrite any data files that exist. If you use raw devices for your data files, they will be overwritten during a full import, as DESTROY=N won’t prevent the overwriting of datafiles! Don’t use this option unless you know what you’re doing.
FEEDBACK
0
Oracle displays a period for each group of records inserted. FEEDBACK defines the size of the group. For example, if FEEDBACK=1000, a period is displayed for every 1,000 records imported. This parameter is useful for tracking the progress of large imports.
Export/Import and non-Oracle databases
The export file (expdat.dmp by default) is a binary file that only Oracle databases can read. Many databases and PC software can export data into delimited text files, but the Export utility can’t. To transfer data from Oracle to a non-Oracle database, you must make a delimited file manually by spooling from within PL/SQL or SQL*Plus and running a custom-made script.
Parameter
Default Value
Description
FILE
expdat.dmp
By default, expdat.dmp (stands for EXPort DATa.DuMP) is the name of the file that Import will import from. If the file is something other than expdat.dmp, specify it with this parameter.
FROMUSER

Specifying this parameter imports only those objects owned by the FROMUSER user account.
FULL
N
The entire database will be imported if FULL=Y.
GRANTS
Y
Specifies whether all grants will be created for the exported objects.
HELP
N
No other parameters are needed if you specify HELP=Y. A basic help screen will appear.
IGNORE
N
If IGNORE=Y, object creation errors are ignored, and records are inserted into the table. Duplicate records can result, if no unique constraints exist for the table. Non-object creation errors are still reported, such as operating system problems.
INCTYPE

If you’re importing an incremental export, tables are dropped and recreated. You must first restore from the last SYSTEM export (specify INCTYPE=SYSTEM). Then import every incremental export (specify INCTYPE=RESTORE) until the desired changes are applied to the database.
INDEXES
Y
Specifies whether user-defined indexes are imported. System indexes created with constraints (primary key, unique key) and OID indexes are automatically imported, regardless of this parameter’s value.
INDEXFILE

Specifies the name of the file to generate CREATE INDEX statements. Unless otherwise specified, Oracle appends an .SQL extension to the file. (This parameter is explained in more detail later in this chapter.)
Using the LOG parameter
You can specify a log file for the Export and Import sessions with the LOG parameter. The file, which mimics what’s output to the screen, reports all successful and unsuccessful messages to be examined at a later point. Some Oracle experts use this file during an automated load process and then checks the file for errors. A database administrator is paged if any appear.
Parameter
Default Value
Description
LOG

Specifies the name of the file to spool the feedback from the import session. Unless otherwise specified, Oracle appends an .LOG extension to the file.
PARFILE

Rather than enter all parameters on the command line, some or all may be kept in a parameter file. The PARFILE parameter specifies which file to use, if desired. This parameter is especially useful for non-interactive import sessions.
POINT_IN_TIME_RECOVER
N
Performs a point-in-time recovery for the tablespace exported with the TABLESPACES parameter.
RECORDLENGTH
OS-dependent
Used only when importing on a machine with a different byte count of the file than on the machine where the export occurred. The default should be used in most Import sessions.
SHOW
N
Displays each SQL statement and doesn’t apply them to the database. The SQL statements can be viewed and modified when used with the FILE parameter. (The SHOW parameter is explained in more detail later in this chapter.)
SKIP_UNUSABLE_INDEXES
N
Allows the postponement of index creation until the record data is imported. The indexes affected are only those set to an unusable state, and all other indexes are created if INDEXES=Y (the default value) is set.
TABLES

Specifies a comma-separated list of all tables to be imported. You should use this parameter with the FROMUSER parameter. In a non-UNIX environment, such as Windows NT, enclose the table list within parentheses.
TOUSER

Specifies the user account into which tables should be imported, if you want it to be different from the original owner of the tables. This parameter needs to be used with the FROMUSER parameter.
USERID

Specifies the username and password for the user conducting the import. The format for the command is username/password. You may also use Net8’s @connect_string format if desired.

————————————————————————————–Using imp/exp across different Oracle version

If exp and imp are used to export data from an Oracle database with a different version than the database in which is imported, then the following rules apply:
  • 1. exp must be of the lower version
  • 2. imp must match the target version
——————————————————————————————–Common Export/Import Errors
  • ORA-00001: Unique constraint (…) violated
    You are importing duplicate rows. Use IGNORE=YES to skip tables that already exist (imp will give an error if the object is re-created) OR Perform the following actions:
  • 1. Back up the target table.
  • 2. Try deleting the target table.
  • 3. Run the import for this table again in overwrite mode.
  • ORA-01555: Snapshot too old
    Ask your users to STOP working while you are exporting or try using parameter CONSISTENT=NO
  • ORA-01562: Failed to extend rollback segment
    Create bigger rollback segments or set parameter COMMIT=Y while importing
  • IMP-00015: Statement failed … object already exists…
    Use the IGNORE=Y import parameter to ignore these errors, but be careful as you might end up with duplicate rows.
——————————————————————————————–
To Improve performance
Export
  • Set the BUFFER parameter to a high value (e.g. 2Mb — entered as an integer “2000000”)
  • Set the RECORDLENGTH parameter to a high value (e.g. 64Kb — entered as an integer “64000”)
  • Use DIRECT=yes (direct mode export)
  • Stop unnecessary applications to free-up resources for your job.
  • If you run multiple export sessions, ensure they write to different physical disks.
  • DO NOT export to an NFS mounted filesystem. It will take forever.
Import
  • Create an indexfile so that you can create indexes AFTER you have imported data. Do this by setting INDEXFILE to a filename and then import. No data will be imported but a file containing index definitions will be created. You must edit this file afterwards and supply the passwords for the schemas on all CONNECT statements.
  • Place the file to be imported on a separate physical disk from the oracle data files
  • Increase DB_CACHE_SIZE (DB_BLOCK_BUFFERS prior to 9i) considerably in the init$SID.ora file
  • Set the LOG_BUFFER to a big value and restart oracle.
  • Stop redo log archiving if it is running (ALTER DATABASE NOARCHIVELOG;)
  • Create a BIG tablespace with a BIG rollback segment inside. Set all other rollback segments offline (except the SYSTEM rollback segment of course). The rollback segment must be as big as your biggest table (I think?)
  • Use COMMIT=N in the import parameter file if you can afford it
  • Use STATISTICS=NONE in the import parameter file to avoid time consuming to import the statistics
  • Remember to run the indexfile previously created
———————————————————————————————–
Good practices
  • Always take care about CHARSETS when you do export and import. Using the wrong ones can convert your data in a lossy manner. The best situation is when your source and destination database have the same character sets, so you can avoid completely any character conversion. You control this behavior by setting NLS_LANG environment variable appropriately. When not set properly you may see ‘Exporting questionable statistics’ messages.
  • After doing an export, it is better to check your dump by doing an import with the parameter SHOW=Y. This checks the validity of your dump file.
——————————————————————————————Other considerations
  • You may need to patch your Oracle client (where you are running exp/imp) to the same level as the Oracle server to prevent errors
  • When importing large amounts of data consider dropping indexes prior to the import to speed up the process and re-creating them once the import is completed
  • The amount of archive logs that may be created on a large import may fill up your disk
  • On INSERT triggers will fire, consider whether these need to be disabled
  • Increasing the RECORDLENGTH (max 65535) parameter can improve the length of time to perform an import/export as well as DIRECT=y for export
——————————————————————————-
Tablespace fragmentation occurs when objects are created, dropped, enlarged, and shrunk. The more often this occurs, the more fragmented the tablespace becomes. This causes free space to be broken into many separated island-like chunks of space. In addition, if an object has multiple extents, they could be spread out over different parts of the tablespace; this causes performance and maintenance problems. With many small blocks of free space instead of fewer large free spaces, you may be unable to create some objects that you otherwise could have. By defragmenting the tablespace, the data is reorganized so that all free space is put into one contiguous area, and each object’s extents are grouped next to each other.
  • The Export and Import utilities can fix fragmentation in two ways:
    They can take a table with multiple extents and resize it into a table with one larger extent. This larger single extent will encompass the total size of all previous table extents.
  • They can make all objects within the tablespace adjacent to each other with no island-like characteristics, while at the same time merging all the free space into one larger free space.
The easiest and most dramatic method fixes both fragmentation problems for the entire database. The database is shut down during the process. This forces all sessions against the database to stop (which is why it’s the most dramatic method).
Fixing a table’s storage parameter is fairly easy compared to the entire tablespace, as only one table is affected. To fix an entire tablespace, you’ll have to drop and recreate it, along with all the tables within it.
Fix both fragmentation problems quickly
  • Export the entire database, specifying FULL=Y and COMPRESS=Y. FULL=Y exports the entire database;COMPRESS=Y changes the INITIAL storage parameter of each table in the database (if necessary) to fit within one extent each. For example, if a table has five 10M extents, the COMPRESS=Y specification changes the table to one 50M extent when imported.
  • Drop and recreate the entire database.
  • Import the entire database with the FULL=Y parameter.
Defragment just one tablespace (a less dramatic method)
  • Determine which tables exist in the tablespace and export just those tables.
  • Drop all the tables in the tablespace.
  • Issue the ALTER TABLESPACE COALESCE command (or drop and recreate the tablespace). This will coalesce all the free space within the tablespace into one contiguous area.
  • Import the tables. Oracle will create the tables adjacent to each other within the tablespace, and all free space will still be contiguous in one chunk of space.
——————————————————————————-
Some more examples
EXP
To dump a single schema to disk (we use the scott example schema here)
– Login to server which has an Oracle client
exp <user>/<password> FILE=scott.dmp OWNER=scott
To export specific tables to disk: Login to server which has an Oracle client
exp SYSTEM/password FIlE=expdat.dmp TABLES=(scott.emp,hr.countries)
The above command uses two users : scott and hr
exp <user>/<password> FILE=scott.dmp TABLES=(emp,dept)
the above is only for one user : scott
IMPTo import the full database exported in the example above.
imp SYSTEM/password FULL=y FIlE=dba.dmp
To import just the dept and emp tables from the scott schema
imp SYSTEM/password FIlE=dba.dmp FROMUSER=scott TABLES=(dept,emp)
To import tables and change the owner
imp SYSTEM/password FROMUSER=blake TOUSER=scott FILE=blake.dmp TABLES=(unit,manager)
To import just the scott schema exported in the example above:
imp <user>/<password> FIlE=scott.dmp
If you do not supply any parameters then you enter an interactive session as illustrated below. (Responses to prompts are shown in blue. from the prompt type imp and press enter
$>imp
Import: Release 9.2.0.6.0 – Production on Thu Mar 29 15:07:43 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Username: SYSTEM
Password: password
Connected to: Oracle9i Enterprise Edition Release 9.2.0.6.0 – Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.6.0 – Production
Import file: expdat.dmp > /mention/path/of/dumpFile/includingFileName.dmp
Enter insert buffer size (minimum is 8192) 30720> (press enter to accept default)
Export file created by EXPORT:V09.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
List contents of import file only (yes/no): no > press enter
Ignore create error due to object existence (yes/no): no > press enter
Import grants (yes/no): yes > press enter
Import table data (yes/no): yes > press enter
Import entire export file (yes/no): no > press enter or type no
Username: give the userName for which you want the data to be imported
Enter table(T) or partition(T:P) names. Null list means all tables for user
Enter table(T) or partition(T:P) name or . if done: press enter
. importing TST_001_V2’s objects into TST_001_V2

No comments:

Post a Comment