Oracle Database import and export methods outlined

Description:
1, the database data import and export a variety of methods, can be derived by introducing exp / imp command can also be derived by third-party tools, such as: PLSQL
2, if familiar with command, import and export recommended by exp / imp command, to avoid the first tripartite tool version differences caused, at the same time more efficient, but special attention: pay attention to details such as users and their privileges to use when using the command.
3, the same user name (the same as far as possible) when you need to create and export import in the target database, and give the user permissions of not lower than export; at the same time the need to create the same table space as the original database name, if the local database already exists the same table space, table space can only be expanded.

First, import the preparatory work before (in the target database operations)

Knowledge added:
tablespace
  Oracle database table to store physical space by a table, a database instance can have N number of table space, a space under the table can have N tables.
Table space (TABLESPACE) is a logical division databases, each database table having at least a space (referred to as the SYSTEM tablespace). In order to facilitate management and improve operational efficiency, you can use some additional table space to divide users and applications.
For example: USER tablespace for general users, RBS tablespace used for rollback. A table space can only belong to a database.

1, the login server
    with Xshell, secureCRT, MobaXterm tools can be
2, query disk space is large enough
    to perform df -h df -H command or query, if enough free space is replaced with a new target environment and then continue with other operations.

 [oracle@orac ~]$ df -h

3, look-up table space details
(1) log on using a terminal, in turn execute the command:

[Oracle @ orac ~] $ su - oracle (switch to the oracle user (linux of a user name)) 

   New in / home / oracle / app / oradata directory folder, create a table space behind the need to use the path is not unique, the data file storage location based on the target database may be.

[oracle@orac ~]$ /home/oracle/app/oradata 
[oracle@orac ~]$ mkdir snail

(2) Log database

[oracle@orac ~]$ sqlplus / as sysdba 

Implementation of sql statement

select a.tablespace_name,a.bytes/1024/1024 "sum MB", (a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB", round (((a.bytes-b.bytes)/a.bytes)*100,2) "used%" 
from (select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a, 
(select tablespace_name,sum(bytes) bytes,max (bytes) largest from dba_free_space group by tablespace_name)b 
where a.tablespace_name=b.tablespace_name order by ((a.bytes-b.bytes)/a.bytes) desc;

To obtain the current table of the database space, as shown below:

 Note: If you want to import the database table space name same as the current existing table space, you do not need a new table space (you can not build), but must be sufficient to determine the size of an existing table space, or has been set to automatically increase and automatically increase the maximum value is large enough, then no expansion space for the table, the table directly to stage space, the fourth step is skipped. Conversely if the name of the table space or table space large enough to store the data to be imported, the table needs to be expanded space, the implementation of the fourth step.

4, the expansion tablespace
  tablespaces augmented with a variety of methods, introduces a few common methods:
(1) directly increase the size of table space:

To view the table space data file storage location 
SQL> select tablespace_name, file_id, file_name , round (bytes / (1024 * 1024), 0) total_space from dba_data_files order by tablespace_name; 
determining the location of data files, execute the command: 
  the ALTER Database datafile 'data file path' to increase the size of a resize 
example: 
the SQL> ALTER Database datafile '/home/oracle/oradata/SPS_DATA.DBF' a resize 4000m 

     Note: This method is increased in the presence of table data table space will be given, suggesting increased fails, the next method is recommended
to increase the data file (2) the number of

alter tablespace tablespace name add datafile 'newly added data file path' file size of the size data 
, for example: 
the SQL> alter tablespace SPS_DATA add datafile '/home/oracle/app/oradata/snail/SPS_DATA02.dbf' size 2000m 

(3) set the table space is automatically extended

alter database datafile 'to expand tablespace' autoextend on next expansion unit expand the size of the maximum size maxsize 
example: 
the SQL> alter database datafile '/home/oracle/app/oradata/snail/SPS_DATA.dbf' autoextend on next maxsize 10000m 100m
Note: The method can be used in combination, particularly when the uncertainty introduced into the final recommended when the file size, such as: 
the SQL> ALTER TABLESPACE SPS_DATA the Add datafile '/home/oracle/app/oradata/snail/SPS_DATA02.dbf' ON Next 200M size 2000m AUTOEXTEND maxsize 12000M; 
can perform table space to expand again after step 3. View the table space size sql, confirm the success of table space to expand.

5, create a temporary table space and data table space
      creation must first create a temporary table space and database table space in front of two user table space, or use the default table space, it will cause other problems.
(1) create a temporary table space

create temporary tablespace temporary table space tempfile 'temporary tablespace position' size temporary table space autoextend on next 100m maxsize 10240m extent management local; 
for example: 
the SQL> create temporary tablespace SPS_DATA_temp tempfile '/ Home / Oracle / App / oradata / Snail / SPS_DATA_temp.dbf ' 
size 1024M AUTOEXTEND ON MAXSIZE 10240m 100m Next local Management extents;

(2) create a data table space

Create a temporary table with the parameter space substantially 
example: 
the SQL> Create TABLESPACE SPS_DATA the logging datafile '/ Home / Oracle / App / oradata / Snail / SPS_DATA01.dbf' 
size 1024M AUTOEXTEND ON MAXSIZE 10240m 100m Next local Management extents;

      Note: If, after the implementation of the first four steps, namely from the table space for the expansion rather than building new ones, you do not need to create a data table space (but also need to create a temporary table space - a personal point of view)

6, create a database user and specify the table space

The user management data for the forthcoming introduction also switched into the import user (if introduction imp command, preferably the username and user name used when deriving the same user name, it may also be of different mapping needs to be done), the format is: 
  the Create the user username identified by password default tablespace user specified table space name temporary tablespace temporary table space name; 
for example: 
SQL> identified by the Create the user abc ABC default tablespace SPS_DATA temporary tablespace SPS_DATA_temp;

7, giving users permission
for it takes the user to import, it should be given at least a user's privileges including dba, IMP_FULL_DATABASE authority, has also been suggested to be consistent with the user's privileges to export database data.

Sql :( authorization, as the case may be) 
Grant dba, IMP_FULL_DATABASE, EXP_FULL_DATABASE, Connect, Resource, the session to the Create a user name; 
for example: 
SQL> Grant the Create the User, the User drop, the ALTER the User, the Create the any View, drop the any View, EXP_FULL_DATABASE , 
IMP_FULL_DATABASE, dba, Connect, Resource, the Read, the Write, the Create the session to abc;

Second, the export / import command: exp / imp command
knowledge expansion:
Data Pump Export Import effect (EXPDP and IMPDP) of
(1) to implement logic logical backup and recovery.
(2) moving objects between the database user.
(3) moving objects between the database
(4) move to achieve the tablespace.
Data Pump Export Import difference with the traditional export import:
Before 10g, the traditional export and import tools were used and EXP IMP tool, 10g from the start, not only to retain the original EXP and IMP tools, also provides Data Pump Export Import EXPDP tools and IMPDP use EXPDP and IMPDP should be noted that matters:.
   EXP and IMP utilities customer segment, they can either use the client can also be used in the server segment.
   EXPDP and IMPDP are server-side utilities, they can only be used in the ORACLE server, the client can not use the
   IMP EXP applies only to the export file, does not apply to EXPDP export file; IMPDP EXPDP applies only to the export file, and not to EXP export file.

1, exp Export command
to export and import, respectively, have three ways:
(1) Full mode export (import):
         The entire contents of the database export, but need special permission to operation,

exp username / password buffer = 32000file = full = y exported directory 
example: 
exp System / File Manager Buffer = 32000 = D: \ iom.dmp full = y 

(2) User mode deriving (Import)
         of all the specified user to export objects such as:

exp iom/iom buffer=32000 file=d:\iom.dmp owner=iom

(3)表模式导出(导入)
          将用户的所有表数据进行导出,例如:

exp iom/iom buffer=32000 file=d:\iom.dmp owner=iom tables=(iom) 

备注:可以执行exp help=y、imp help=y查看帮助命令,以及执行exp或者imp查看对应版本号。

导出步骤:
首先切换到oracle用户(数据库超级管理员)

[oracle@orac ~]$ su - oracle 

根据所需要采用的导出模式进行导出

[oracle@orac~]$exp iom/iom file=iom.dmp log=oradb.log full=y compress=y direct=y 
COMPRESS参数将在导出的同时合并碎块,尽量把数据压缩到initial的EXTENT里,默认是N,一般建议使用。DIRECT参数将告诉EXP直接读取数据,而不像传统的EXP那样,使用SELECT来读取表中的数据,这样就减少了SQL语句处理过程。一般也建议使用。不过有些情况下DIRECT参数是无法使用的。 
其他参数可参照帮助命令,或者其他资料进行学习。在此不一一赘述。

2、导入命令
登录服务器,切换到oracle用户。

[oracle@orac ~]$ su - oracle 

执行导入命令:
导入时需要用准备工作中创建的新用户,如:用户名abc,密码ABC

imp 用户名/密码 file=dmp文件路径 log=输出日志路径full=y ignore=y; 
例如:
[oracle@orac ~]$imp abc/ABC file=/home/oracle/iom.dmp log=/home/oracle/iom.log full=y ignore=y;

温馨提示:采用数据泵导入过程经常会遇到问题,建议多查阅资料,总有方法解决。相信每一件事物都有它存在的必要性,问题只是暂时的,成功才是必然的!

 

转自:https://www.cnblogs.com/alsodzy/p/8675935.html

Guess you like

Origin www.cnblogs.com/shujk/p/12590326.html