Import/export is the oldest two surviving Oracle command line tools. In fact, I never think exp/imp is a good backup method, the correct statement is that exp/IMP can only be a good dump tool, especially in small database dump, tablespace migration, table extraction, and detection of logical and physical conflicts. Of course, we can also use it as a logical secondary backup after physical backup of small databases, which is also a good suggestion. EXP/IMP becomes increasingly inadequate for larger databases, especially TB-level databases and more data warehouses. At this time, database backup is switched to RMAN and third-party tools. The following describes the use of exp/imp.
How to display exp help in different character sets: Set nls_lang = simplified chinese_china.zhs16gbk. By setting environment variables, you can display exp help in Chinese. If set nls_lang = american_america. character Set, the help is all exp parameters in English (the default value of the parameter in parentheses ):
Userid username/password, for example, userid = duanl/duanl
Full export the entire database (N)
Buffer data buffer size
Owner owner user name list. If you want to export the user's object, use owner = Username
File output file (expdat. dmp)
Tables Table Name List, specifying the name of the exported table, such as: tables = Table1, Table2
Compress imports an extent (y)
Recordlength Io record length
Grants export permission (y)
Inctype incremental export type
Indexes export index (y)
Incremental export of record tracking (y)
Rows export data rows (y)
Parfile parameter file name. If you have many exp parameters, you can save them as parameter files.
Constraints export constraint (y)
Consistent cross tabulation consistency
Log File output by log Screen
Statistics Analysis object (estimate)
Direct direct path (N)
Triggers export trigger (y)
Feedback displays the progress of each X row (0)
Filesize maximum size of each dump file
Query the clause of the selected export table subset
The following keywords are only used for table spaces that can be transferred.
Transport_tablespace export the table space metadata that can be transferred (N)
Table space list of tablespaces to be transmitted
All imp parameters (the default value of the parameter in parentheses ):
Userid username/password
Full import of the entire file (N)
Buffer data buffer size
Fromuser User Name List
File input file (expdat. dmp)
Touser User Name List
Show only lists file content (N)
Tables Table Name List
Ignore ignore creation error (N)
Recordlength Io record length
Grants import permission (y)
Inctype incremental Import Type
Indexes import index (y)
Commit submits array insert (N)
Rows import data rows (y)
Parfile parameter file name
Log File output by log Screen
Constraints import restrictions (y)
Destroy overwrite the tablespace data file (N)
Indexfile writes table/index information to the specified file
Skip_unusable_indexes skips maintenance of unavailable indexes (N)
Analyze executes the analyze Statement (y) in the dump file)
Feedback displays the progress of each X row (0)
Toid_novalidate skips the verification of the specified type ID
Filesize maximum size of each dump file
Recalculate_statistics recalculates the statistical value (N)
The following keywords are only used for table spaces that can be transferred.
Transport_tablespace import the deletable tablespace metadata (N)
Tablespaces tablespace to be transmitted to the database
Data files to be transmitted to the database
Tts_owners has users who can transmit table space centralized data.
Description of incremental parameters: the increment of exp/imp is not a real increment, so it is best not to use it.
Usage:
Exp parameter_name = value or exp parameter_name = (value1, value2 ......)
You only need to input help = y to view all the help information.
Common exp options
1. Full. This is used to export the entire database. When rows = N is used together, the structure of the entire database can be exported. For example:
Exp userid = test/test file =./db_str.dmp log =./db_str.log full = y rows = n compress = y direct = y
2. Owner and table. These two options are used to define the exp object. The owner defines to export the object of the specified user; the table specifies the table name of the exp, for example:
Exp userid = test/test file =./db_str.dmp log =./db_str.log owner = duanl
Exp userid = test/test file =./db_str.dmp log =./db_str.log table = nc_data, fi_arap
3. Buffer and feedback. When exporting a large amount of data, I will consider setting these two parameters. For example:
Exp userid = test/test file = yw97_2003.dmp log = yw97_2003_3.log feedback = 10000 buffer = 100000000 tables = wo4, OK _yt
4. File and log. The two parameters respectively specify the DMP name and log name of the backup, including the file name and directory. For example, see the preceding figure.
5. The compress parameter does not compress the exported data. Controls how the storage statement of the exported object is generated. The default value is Y. The default value is used. The init Extent of the Object Storage statement is equal to the total extent of the current exported object. Compress = N is recommended.
6. filesize this option is available in 8i. If the exported DMP file is too large, use the filesize parameter to limit the file size to 2 GB. For example:
Exp userid = duanl/duanl file = F1, F2, F3, F4, F5 filesize = 2G owner = Scott
In this way, a series of files such as f1.dmp and f2.dmp will be created, each of which is 2 GB. If the total exported amount is less than 10 Gb
Expdoes not have to create f5.bmp.
ICommon MP options
1. Use fromuser and touser to import data from one schema to another. For example, if we export the object 'test' as the exp, we want to import the object to the user:
IMP userid = test1/test1 file = expdat. dmp fromuser = test1 touser = test1
2. Ignore, grants, and indexes. The ignore parameter ignores the existence of the table and continues the import. This is useful when you need to adjust the storage parameters of the table, we can create a table with reasonable storage parameters according to the actual situation, and then import the data directly. Grants and indexes indicate whether to import authorization and indexes. If you want to use the new storage parameter to re-create the index, or to speed up the import, you can consider setting indexes to n, grants is generally y. Example: IMP userid = test1/test1 file = expdat. dmp fromuser = test1 touser = test1 indexes = N
Tablespace Transmission
Table space transfer is a newly added 8 I Method to quickly move data between databases. It is to attach the format data files of a database to another database, instead of exporting data to a DMP file, this is very useful in some cases, because the transfer of tablespace moving data is as fast as copying a file.
There are some rules for the tablespace to be transmitted, namely:
· The source database and target database must run on the same hardware platform.
· The source database and target database must use the same character set.
· The source database and target database must have data blocks of the same size
· The target database cannot have a tablespace with the same name as the migrated tablespace.
· Sys objects cannot be migrated.
· The self-contained object set must be transmitted
· Some objects, such as materialized views and function-based indexes, cannot be transmitted.
You can use the following methods to check whether a tablespace or a set of tablespaces meets the transmission standard:
Exec SYS. dbms_tts.transport_set_check ('tablespace _ name', true );
Select * From SYS. transport_set_violation;
If no row is selected, the tablespace only contains table data and is self-contained. Some non-self-contained tablespaces, such as data table spaces and index tablespaces, can be transmitted together.
The following is a brief procedure. For more information, see Oracle online help.
1. Set the tablespace to read-only (assuming the tablespace name is app_data and app_index)
Alter tablespace app_data read only;
Alter tablespace app_index read only;
2. Issue the exp command
SQL> host exp userid = "sys/password as sysdba """
Transport_tablespace = y tablespace = (app_data, app_index)
Note that
· To execute exp in SQL, userid must be enclosed in three quotation marks, and "/" must be avoided in UNIX.
· After 816 and later, you must use sysdba to operate
· This command must be placed in one row in SQL (this is because the display problem is placed in two rows)
3. copy the data file to another location, that is, the target database.
It can be CP (UNIX), copy (Windows), or transfer files through FTP (it must be in Bin Mode)
4. Set the local tablespace to read/write
5. append the data file to the target database.
IMP file = expdat. DMP userid = "sys/password as sysdba" transport_tablespace = y "datafile = (C: \ temp \ app_data, c: \ temp \ app_index )"
6. Set the tablespace of the target database to read/write.
Alter tablespace app_data read write;
Alter tablespace app_index read write;
Methods To optimize exp/IMP:
When the amount of data required for exp/imp is large, this process takes a long time. We can use some methods to optimize exp/IMP operations.
Exp: Use the direct path direct = y
Oracle will avoid the SQL statement processing engine, read data directly from database files, and then write the exported file.
The exp-00067: Table XXX will be exported in conventional path can be observed in the export log
If the direct path is not used, ensure that the value of the buffer parameter is large enough.
Some parameters are incompatible with direct = y and cannot be used to export movable tablespace directly or use query parameters to export database subsets.
When the imported and exported database runs under different operating systems, the value of the recordlength parameter must be consistent.
IMP: optimization through the following channels
1. Avoid disk sorting
Set sort_area_size to a large value, such as 100 m.
2. Avoid waiting for log Switching
Increase the number of redo log groups and the size of log files.
3. optimized the log buffer.
For example, increase the log_buffer capacity by 10 times (the maximum is 5 MB)
4. insert and submit Arrays
Commit = y
Note: arrays cannot process tables of the lob and long types. For such tables, if commit = y is used, a commit is executed for each row inserted.
5. Use nologging to reduce the size of redo logs
Specify the parameter indexes = N during the import. Only import data and ignore the index. After importing the data, create the index using the script and specify the nologging option.
Export/import and Character Set
When importing and exporting data, we should pay attention to the character set issue. In the exp/IMP process, we need to pay attention to the four character set parameters: the client character set at the export end, the database character set at the export end, the client character set at the import end, and the database character set at the import end.
First, we need to view the parameters of these four character sets.
View the character set information of the database:
SQL> select * From nls_database_parameters;
Parameter Value
--------------------------------------------------------------------------------------------------------------
Nls_language American
Nls_territory America
Nls_currency $
Nls_iso_currency America
Nls_numeric_characters .,
Nls_characterset zhs16gbk
Nls_calendar Gregorian
Nls_date_format DD-MON-RR
Nls_date_language American
Nls_sort binary
Nls_time_format HH. Mi. ssxff AM
Nls_timestamp_format DD-MON-RR HH. Mi. ssxff AM
Nls_time_tz_format HH. Mi. ssxff am tzh: tzm
Nls_timestamp_tz_format DD-MON-RR hh. mi. ssxff am tzh: tzm
Nls_dual_currency $
Nls_comp binary
Nls_nchar_characterset zhs16gbk
Nls_rdbms_version 8.1.7.4.1
Nls_characterset: zhs16gbk is the character set of the current database.
Let's check the character set information of the client:
The parameter nls_lang =_< territory>.
Language: Specifies the language in which Oracle messages are sent, including the date, day, And month.
Territory: Specifies the format of currency and number, region and the habit of calculating the week and date.
Characterset: Controls Client ApplicationsProgramThe character set used. Usually set or equal to the client'sCodePage. Or set the Unicode application to utf8.
In Windows, you can query and modify nls_lang in the registry:
HKEY_LOCAL_MACHINE \ SOFTWARE \ oracle \ homexx \
XX indicates the system number when multiple ORACLE_HOME exists.
In Unix:
$ ENV | grep nls_lang
Nls_lang = simplified chinese_china.zhs16gbk
Change availability:
$ Export nls_lang = american_america.utf8
Generally, it is best to set the character set of the client to the same as that of the database during export. When importing data, there are two main situations:
(1) The source database and target database have the same character set settings.
In this case, you only need to set the Export and Import client nls_lang to be equal to the database character set.
(2) The character sets of the source and target databases are different.
First, set the export client's nls_lang to be consistent with the export database character set, export data, and then set the import client's nls_lang to be consistent with the export client, import data, in this way, the conversion only occurs on the Database End and only occurs once.
In this case, data can be completely imported only when the character set of the importing database is a strict superset of the character set of the exporting database. Otherwise, data inconsistency or garbled characters may occur.
EXP/IMP problems of different versions
Generally, it is not a problem to import data from a lower version to a later version. The trouble is to import data from a later version to a lower version. Before Oracle9i, EXP/IMP between Oracle versions can be solved through the following methods:
1. Run catexp. SQL of the base version on the High Version database;
2. Use exp of a lower version to export data of a later version;
3. Use the imp of a lower version to import the database to a lower version;
4. Run the catexp. SQL script in the later version of the database.
But in 9i, the above method cannot solve the problem. If you use a lower version of exp/IMP directly, the following error occurs:
EXP-00008: Oracle error % lu encountered
OrA-00904: Invalid column name
This is a published bug that can be solved only after oracle10.0. The bug number is 2261722. You can go to Metalink to view details about this bug.
Bug is a bug. We still need to do our work. We should solve the bug by ourselves before we have Oracle Support. Execute the following SQL statement in Oracle9i to recreate the exu81rls view.
Create or replace view exu81rls
(Objown, objnam, policy, polown, polsch, polfun, mongots, chkopt, enabled, spolicy)
As select U. Name, O. Name, R. pname, R. pfschma, R. ppname, R. pfname,
Decode (bitand (R. stmt_type, 1), 0, '', 'select ,')
| Decode (bitand (R. stmt_type, 2), 0, '', 'insert ,')
| Decode (bitand (R. stmt_type, 4), 0, '', 'Update ,')
| Decode (bitand (R. stmt_type, 8), 0, '', 'delete ,'),
R. check_opt, R. enable_flag,
Decode (bitand (R. stmt_type, 16), 0, 0, 1)
From user $ U, OBJ $ o, RLS $ R
Where U. User # = O. Owner #
And R. OBJ # = O. OBJ #
And (uid = 0 or
Uid = O. Owner # Or
Exists (select * From session_roles where role = 'select _ catalog_role ')
)
/
Grant select on SYS. exu81rls to public;
/
You can use exp/IMP across versions, but you must use the exp and IMP versions correctly:
1. The IMP version is always used to match the database version. For example, to import data to analyticdb 817, use the IMP tool of analyticdb 817.
2. Always use the EXP version to match the lowest version of the two databases. For example, if you import data from 9201 to 817, use the exp tool of version 817.
This article is from 51cto. com technical blog