显示标签为“exp/expdp/imp/impdp相关”的博文。显示所有博文
显示标签为“exp/expdp/imp/impdp相关”的博文。显示所有博文

2012年6月27日星期三

11g数据导入到10g

用exp、imp命令时进行11g备份,导入10g的时候会抛错:不是有效的导出文件,头部验证失败;未成功终止导入。

实验步骤如下:

一、在11g服务器上,使用expdp命令备份数据

EXPDP USERID='SYS/abc@metar as sysdba' schemas=oa directory=DATA_PUMP_DIR dumpfile=dag.dmp logfile=dag.log version=10.2.0.1.0

例如我的sys密码是abc,数据库sid是metar,要导出的用户名是oa,要导入到10.2.0.1.0版本的Oracle数据库中去。aa.dmp和aa.log将会在11g的dpdump目录中生成,例如我的11g装在了D盘下面,于是dag.dmp将会在D:/app/Administrator/admin/cuc/dpdump目录下被生成。

二、在10g服务器上,使用impdp命令恢复数据

步骤:1.建库2.建表空间3.建用户并授权4.将dag.dmp拷贝到10g的dpdump目录下5.impdp导入数据库
1、建库:是在database configuration assistant 中直接新建一个数据库(实例)。
2、建表空间:create tablespace OA datafile 'D:\oracle\product\10.2.0\oradata\orcl\oa.dbf' size 400m autoextend on next 20m online;
3、建用户:
create user oa identified by oa;
授权:
Alter user OA default tablespace OA quota unlimited on OA;
grant create session to oa;
grant connect to oa;
grant connect, resource, dba to oa;
grant create table to oa;
grant create view to oa;
grant create trigger to oa;
grant select any table to oa;
grant create sequence to oa;
grant create procedure to oa;
grant create role to oa;
grant create type to oa;
grant GRANT ANY PRIVILEGE to oa;

4、创建目录:
sqlplus sys/abc@metar
sql>create directory dump_dir as 'C:\oracle\product\10.2.0\admin\daggis\udump';

IMPDP USERID='SYS/abc@metar as sysdba' schemas=oa directory=DATA_PUMP_DIR dumpfile=dag.dmp logfile=dag.log version=10.2.0.1.0
 
进行验证,在导出数据库的机器运行一次,在导入数据库后的机器运行一次,看看结果是否一样:sql>select count(*) from dba_objects where owner in ('xxx','xxx','xxx');

2012年6月21日星期四

exp/imp transport tablespace(传输表空间)

使用exp imp
transport tablespace
与使用expdp/impdp是步骤一样的 语法上有些不一样

限制条件与expdp/impdp一样 (查看expdp/impdp transport tablespace)
将db xh tablespace smallts transport 到db orcl
SQL> conntr/a123@xh
已连接。
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
TEMP
USERS
EXAMPLE
RMAN_TS
XHTEST
XHTR
OUTLINE_TS
SMALLTS
已选择11行。
SQL> select count(*) from t1;
COUNT(*)
----------
0
SQL> insert into t1 values(1);
已创建 1 行。
SQL> select count(*) from t1;
COUNT(*)
----------
1
SQL> commit;
提交完成。
SQL> select tablespace_name from user_tables where table_name='T1';
TABLESPACE_NAME
------------------------------
USERS
SQL> alter table t1 move tablespace smallts;
表已更改。
SQL> select tablespace_name from user_tables where table_name='T1';
TABLESPACE_NAME
------------------------------
SMALLTS

SQL> execute sys.dbms_tts.transport_set_check('smallts',true,true);
PL/SQL 过程已成功完成。
SQL> select * from sys.transport_set_violations;
VIOLATIONS
--------------------------------------------------------------------------------
Index TR.T1_IND in tablespace USERS points to table TR.T1 in tablespace SMALLTS

发现t1_ind 在USER TABLESPACE 与表不在同一个表空间
(expdp的话用TRANSPORT_FULL_CHECK 设置为N 可以导出时候不报告错误 成功导出 不过只导出INDEX 所在表空间 不导出依赖的表所在表空间还是会报错,impdp时也一样)(exp/imp时用 TTS_FULL_CHECK 一样) 在这里 我们还是手动解决下这个问题
SQL> alter index t1_IND REBUilD TABLESPACE smallts
2 ;
索引已更改。
SQL> execute sys.dbms_tts.transport_set_check('smallts',true,true);
PL/SQL 过程已成功完成。
SQL> select * from sys.transport_set_violations;
未选定行~~~~~~~~~~~~~~~~~可以了

C:\>set oracle_sid=orcl
C:\>sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on 星期二 9月 29 11:43:05 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.

连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> select name from v$database;
NAME
---------
ORCL
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
TEMP
USERS
EXAMPLE
TEST
RMAN_TS
TESTXH
XHTEST
XHTR
已选择11行。
SQL> host exp'sys/a831115@xhas sysdba' transport_tablespace=y file=d:\exp\tablesp
ace.dmp tablespaces=smallts
Export: Release 10.2.0.1.0 - Production on 星期二 9月 29 11:47:43 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集
注: 将不导出表数据 (行)
即将导出可传输的表空间元数据...
EXP-00008: 遇到 ORACLE 错误 29335
ORA-29335: 表空间 'SMALLTS' 不为只读~~~~~~~~必须要 read only
ORA-06512: 在 "SYS.DBMS_PLUGTS", line 507
ORA-06512: 在 line 1
EXP-00000: 导出终止失败

另外必须 sysdba connect(EXP-00044: 必须以 'SYSDBA' 身份连接, 才能进行时间点恢复或可传输的表空间导入)
SQL> alter tablespace smallts read only;
表空间已更改。
SQL> host exp'sys/a831115@xhas sysdba' transport_tablespace=y file=d:\exp\tablesp
ace.dmp tablespaces=smallts
Export: Release 10.2.0.1.0 - Production on 星期二 9月 29 11:48:10 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集
注: 将不导出表数据 (行)
即将导出可传输的表空间元数据...
对于表空间 SMALLTS...
. 正在导出簇定义
. 正在导出表定义
. . 正在导出表 T1
. 正在导出引用完整性约束条件
. 正在导出触发器
. 结束导出可传输的表空间元数据
成功终止导出, 没有出现警告。
SQL> host copy d:\xhdatafile\smallfile.dbf E:\orcldatafile\smallfile.dbf
已复制 1 个文件。
SQL> alter tablespace smallts read write
2 ;
表空间已更改。
orcl db
SQL> host imp '/ as sysdba' transport_tablespace=y file=d:\exp\tablespace.dmp data
files=e:\orcldatafile\smallfile.dbf fromuser=tr touser=system
Import: Release 10.2.0.1.0 - Production on 星期二 9月 29 11:54:31 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
经由常规路径由 EXPORT:V10.02.01 创建的导出文件
即将导入可传输的表空间元数据...
已经完成 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集中的导入
. 正在将 TR 的对象导入到 SYSTEM
. . 正在导入表 "T1"
成功终止导入, 没有出现警告。
SQL> conn system/a831115
已连接。
SQL> select count(*) from t1;
COUNT(*)
----------
1
SQL> select tablespace_name from user_tables where table_name='T1';
TABLESPACE_NAME
------------------------------
SMALLTS
SQL> select file_name from dba_data_files where tablespace_name='SMALLTS';
FILE_NAME
--------------------------------------------------------------------------------
E:\ORCLDATAFILE\SMALLFILE.DBF

2012年6月3日星期日

Expdp的include导出procedure

SQL> SELECT * FROM dba_directories ;
OWN DIRECTORY_NAME DIRECTORY_PATH
------- ---------------------- ---------------
SYS DPUMPDIR /oracle/bakup
SQL>grant read ,write on directory DPUMPDIR to &user;
C:/Users/Liangwei>expdp help=y
...
INCLUDE
包括特定对象类型。
例如, INCLUDE=TABLE_DATA。

expdp user/password directory=DPUMPDIR dumpfile=prodedure.dmp include=PROCEDURE
当然PROCEDURE 也可以换成其它对象如:
INDEX,TABLE,FUNCTION,VIEW,DATABASE LINK,SYNONYM,PACKAGE BODY,SEQUENCE,LOB,PACKAGE
C:/Users/Liangwei>impdp help=y
...
SQLFILE
将所有的 SQL DDL 写入指定的文件。
impdp user/password directory=DPUMPDIR dumpfile=prodedure.dmp SQLFILE=procedure.sql
prodedure.dmp 中的信息导出为SQL语句,prodedure.dmp 中的存储过程并不会导入到数据库中。

2012年5月23日星期三

Oracle data pump expdp/impdp

Oracle Data Pump utility is used for exporting data and metadata into set of operating system files and it is newer, faster and flexible alternative to “export/import” utilities.

Oracle Datapump utility introduced in Oracle 10g Release1 and this utility can be invoked using expdp(export) and impdb(import) commands. User need to specify the export/import parameters to determine the operation and you can specify the parameters on the command line or in a parameter file.

The expdp and impdp uses the procedures provided in the DBMS_DATAPUMP package to execute the commands and DBMS_METADATA package is used to move the data.

Please note that it is not possible to start or restart data pump jobs on one instance in Oracle RAC if jobs currently running on other instances.

Oracle Data Pump Export :-

1. Create directory object as SYS user.
SQL> create or replace directory export_dir as '/oradata/export’;

2. Grant Read/Write privilege on the directory to the user, who invokes the Data pump export.
SQL> grant read,write on directory export_dir to test_user;

3. Take Data Pump Export

Click here to see Roles/privileges required for Export modes.

Oracle data pump export examples for all 5 modes.

(i) Full Database Export
$ expdp test_user/test123 full=y directory=export_dir dumpfile=expdp_fulldb.dmp logfile=expdp_fulldb.log

(ii) Schema Export
$expdp test_user/test123 schemas=test_user directory= export _dir dumpfile=expdp_test_user.dmp logfile=expdp_test_user.log

If you want to export more than one schema then specify the schema names separated by comma.

(iii)Table Export
$ expdp test_user/test123 tables=emp,dept directory= export _dir dumpfile=expdp_tables.dmp logfile=expdp_tables.log

You can specify more than one table.

(iv) Tablespace Export
$ expdp test_user/test123 tablespaces=test_user_tbs directory= export _dir dumpfile=expdp_tbs.dmp logfile=expdp_tbs.log

You can specify more than one tablespace.

(v) Transportable tablespace
$ expdp test_user/test123 transport_tablespaces=test_user_tbs transport_full_check=y directory= export _dir dumpfile=expdp_trans_tbs.dmp logfile=expdp_trans_tbs.log

Click here to learn more on Transportable Tablespace with examples.

Oracle Data Pump Import :-
Data Pump Import utility is used for loading an export dump files into a target system and we can load one or more files.

Copy the dump file to the target system where you to import.

1. Create directory object as SYS user.
SQL> create directory import_dir as '/oradata/import';

2. Grant Read/Write privilege on the Directory to the user, who invokes the Data Pump import.
SQL> grant read,write on directory import_dir to test_user;

3. Import the data using Data Pump Import.

Oracle data pump import examples for all 5 modes.

(i) Full Database Import
$ impdp test_user/test123 full=Y directory=imp_dir dumpfile=expdp_fulldb.dmp logfile=imp_fulldb.log

(ii) Schema Import
$impdp test_user/test123 schemas=test_user directory=imp_dir dumpfile=expdp_test_user.dmp Logfile=impdp_test_user.log

(iii) Table Import
$ impdp test_user/test123 tables=emp,dept directory=imp_dir dumpfile=expdp_tables.dmp logfile=impdp_tables.log

From 11g, you can reaname a table during the import
REMAP_TABLE=[schema.]old_tablename[.partition]:new_tablename
$ impdp test_user/test123 remap_table=test_user.emp:emp1 directory=imp_dir dumpfile=expdp_tables.dmp logfile=impdp_tables.log

Tables will not be remapped if they already exist even if the TABLE_EXISTS_ACTION is set to TRUNCATE or APPEND

(iv) Tablespace Import
$ impdp test_user/test123 tablespaces=test_user_tbs directory=imp_dir dumpfile=expdp_tbs.dmp logfile=impdp_tbs.log

Above example imports all tables that have data in tablespaces test_user_tbs and it assumes that the tablespaces already exist.

(v) Transportable Tablespace
Click here to to import data using Transportable Tablespace method.

Common Errors with Data pump import (impdp) utility:-

1. ORA-31631: privileges are required
   ORA-39122: Unprivileged users may not perform REMAP_SCHEMA remapping
Cause: A user attempted to remap objects during an import but lacked the IMPORT_FULL_DATABASE privilege.
Action: Retry the job from a schema that owns the IMPORT_FULL_DATABASE privilege.

2. ORA-31631: privileges are required
    ORA-39161: Full database jobs require privileges
Cause: Either an attempt to perform a full database export without the EXP_FULL_DATABASE role or an attempt to perform a full database import over a network link without the IMP_FULL_DATABASE role.
Action: Retry the operation in a schema that has the required roles.

3. ORA-01950: no privileges on tablespace "string"
    Cause: User does not have privileges to allocate an extent in the specified tablespace.
   Action: Grant the user the appropriate system privileges or grant the user space resource on the tablespace.

Click here to learn Roles/ privileges required for Data pump Export and Import.

4. import done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
    IMP-00017: following statement failed with ORACLE error 3113:
    "BEGIN "
    "SYS.DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE   SYS.DBMS_RULE_ADM.CREATE_EVALUATIO" "N_CONTEXT_OBJ, 'SYS',TRUE);"
Cause: Import fails while executing the following command.
Action: Login as sys and run the following scripts
$ORACLE_HOME/rdbms/admin/dbmsread.sql
$ORACLE_HOME/rdbms/admin/prvtread.plb

5. Import failed with below errors
IMP-00003: ORACLE error 6550 encountered
ORA-06550: line 2, column 1:
PLS-00201: identifier 'CTXSYS.DRIIMP' must be declared
Cause: The user that you are importing does not have privileages on CTXSYS.DRIIMP package or CTXSYS user does not exists
Action: Create CTXSYS user or grant required permissions

Please see the Data pump Export and Import related documents:
Click here for Data Pump Export modes and Interfaces.

Regards,
Satishbabu Gunukula
http://www.oracleracexpert.com/

Transportable tablespace export and impot

Transportable tablespaces export and import is manageable across platforms and only Meta data will be exported. In Cross platform transportable tablespace the data movement is simpler and faster.

This mode requires that you have the EXP_FULL_DATABASE role.

Please note that
1. source and target database must use the same character set/national character set
2. You cannot transport a tablespace to a target database which already exists.
3. Transportable tablespace exports cannot be restarted once stopped
4. Target database must at same or higher release level as the source database.

Transportable tablespace export and import on same endian platforms
Step 1: Find the Operating system byte order on Source and Target Database
SQL > select * from v$transportable_platform order by platform_id;
PLATFORM_ID PLATFORM_NAME ENDIAN_FORMAT
----------------- ---------------------- ------- ----------------------
1 Solaris[tm] OE (32-bit) Big
2 Solaris[tm] OE (64-bit) Big
3 HP-UX (64-bit) Big
4 HP-UX IA (64-bit) Big
5 HP Tru64 UNIX Little
6 AIX-Based Systems (64-bit) Big
7 Microsoft Windows IA (32-bit) Little
8 Microsoft Windows IA (64-bit) Little
9 IBM zSeries Based Linux Big
10 Linux IA (32-bit) Little
11 Linux IA (64-bit) Little
12 Microsoft Windows 64-bit for AMD Little

For example, if you want to transport a tablespace “test_user_tbs” from a Linux 64 bit(Little endian) machine TESTLINUX to Microsoft Windows 64 bit (Little endian) machine TESTWIN. Both the source and target platforms are of LITTLE endian type. The data file for the tablespace “test_user_tbs” is “test_user_tbs01.dbff.

Step 2:- Make the tablespace “READ ONLY”
SQL> alter tablespace test_user_tbs read only;

Step 3: Export metadata
(i) Using export utility$ exp testuser/test123 tablespaces=test_user_tbs transport_tablespace=y file=exp_test_user_tbs.dmp log=exp_test_user_tbs.log

(ii) Using Export data pump utility$ expdp system/password TRANSPORT_TABLESPACES=test_user_tbs TRANSPORT_FULL_CHECK=Y DIRECTORY=export_dir DUMPFILE=expdp_test_user_tbs.dmp logfile= expdp_test_user_tbs.log

TRANSPORT_FULL_CHECK= Y Specifies that check for dependencies between those objects inside the transportable Tablespace and those outside the transportable Tablespace.

The file “exp_test_user_tbs.dmp” or ““expdp_test_user_tbs.dmp” contains only metadata.

Step 4: Copy the files to Target system
If you are using FTP use binary option.

Step 5: Initiate Import to plug the tablespace into the database.
(i) Using import utility $ imp test_user/test123 tablespaces=test_user_tbs transport_tablespace=y file=exp_test_user_tbs.dmp datafiles='test_user_tbs01.dbf' log=imp_test_user_tbs.log

(ii) Using impdp utility
Click here to see the Instructions to create Directory and grant privileges.

$ impdp test_user/test123 TRANSPORT_DATAFILES='test_user_tbs01.dbf' DIRECTORY=import_dir DUMPFILE=expdp_test_user_tbs.dmp log= impdp_test_user_tbs.log

You can use REMAP_SCHEMA= (source: target), if you want to import into another schema.

Step6: - Put the tablespace in read/write mode.
SQL> ALTER TABLESPACE TEST_USER_TBS READ WRITE;

Now the database has a tablespace named “test_user_tbs” and the objects of the tablespace will be available.

Transport Tablespace Import Common Errors:-
1. Oracle Error : EXP-00044: must be connected "AS SYSDBA" to do Point-in-time Recovery or Transportable Tablespace import
Cause: The user must log in "as SYSDBA" to perform transportable tablespace imports or Point-In-Time Recovery imports.
Action: Ask your database administrator to perform the Transportable Tablespace import or
the Tablespace Point-in-time Recovery import.

2. IMP-00017: following statement failed with ORACLE error
19721:IMP-00003: ORACLE error 19721 encountered
ORA-06512: at "SYS.DBMS_PLUGTS", line 2065
ORA-06512: at line 1
Cause: A duplicated data file name in the import parameters file was causing the issue
Action: Modify the import parameters file with the right datafile name

Please see the Data pump Export/Import related documents:

Click here for Data Pump Export modes and Interfaces.
Click here for Data Pump Export/Import with Examples.

Regards,
Satishbabu Gunukula
http://www.oracleracexpert.com/