数据库版本11.2.0.3
因测试环境需要,需将正式环境下某用户下的所有对象都导入到测试环境中,这种情况expdp/impdp派上用场了!
因为expdp/impdp使用的是相当路径所以我们需要在生产环境和测试环境都要创建directory expdp/impdexpdp/impdp
p
SQL>SQL> create directory GT_DATA_SBU as '/oracle03/expdp_sbu';
SQL> create directory GT_DATA_SBU as '/oracle03/expdp_sbu';
正式环境:
SQL> create directory DIRECTORY01 as '/oraod/expdir';
利用select * from dba_directories;可以查看数据库已经创建的相对路径
在导出之前,我们利用下面的语句查询该用户下有多少数据需要我们导出
SELECT SUM(s.BYTES)/1024/1024/1024 "sizes(GB)"
FROM dba_segments s
WHERE s.owner= 'USER01'
sizes(GB)
----------
841.142395
可以看到有841G,我们可以用11G expdp带有的compression=ALL参数压缩数据:
一是考虑到生产环境的磁盘空间不够
二是等会要将这些数据SCP到测试环境,数据量太大需要很长的时间花在SCP上;
登陆服务器su到数据库用户
执行expdp system/123456 DIRECTORY=DIRECTORY01 DUMPFILE=schema_user01.dmp COMPRESSION=ALL SCHEMAS=USER01 PARALLEL=20 LOGFILE=schema_user01.log;
[prod@gtsbu expdp_dir]# ls -l
total 77345415
-rw-r----- 1 prod dba 79201562624 Apr 28 01:01 schemas_user01.dmp
-rw-r--r-- 1 prod dba 101206 Apr 28 01:01 schemas_user01.log
导出成功我们可以看到压缩导出一共才77G的数据,节省空间是相当可观的,但是导出的时间要比正常导出的时间多
[root@gtsbu expdp_dir]# scp * root@10.5.128.38:/orasbutmp/expdir 在测试环境中创建directory /orasbutmp/expdir就不在赘述
再使用SCP命令将导出的数据传到测试环已经建立好的相对路径中
测试环境:
从上面SCP过来的数据可以看出是root用户的,所以我们需要把这些导出数据属主改成数据库用户的
[root@gitibisbudb ~]#cd /orasbutmp/expdir
[root@gitibisbudb expdir]# chown prod:dba *
由于测试环境中用户数据已经和正式环境中的数据完全不一致的状态,导入的过程中所以我们先删除用户,再创建用户,重新导入
我们可以通过PL\SQL Developer工具导出这个用户的创建语句:
登陆PL\SQL Developer ----打开users----找到user01---右键view---再点右下角的View SQL
我们可以得到以下创建用户语句
create user USER01
identified by "" --创建的时候需要在""加入之前这个用户的密码
default tablespace USER01_DATA
temporary tablespace USER01_TEMP
profile DEFAULT;
-- Grant/Revoke object privileges
grant select, insert, update, delete, references, alter, index on EBS_R12.CUX_VEND_CUST_TMP_MV to USER01;
grant execute on SYS.DBMS_CRYPTO to USER01;
-- Grant/Revoke role privileges
grant connect to USER01;
grant dba to USER01;
grant resource to USER01;
-- Grant/Revoke system privileges
grant alter any materialized view to USER01;
grant create database link to USER01;
grant create materialized view to USER01;
grant create session to USER01;
grant create synonym to USER01;
grant create view to USER01;
grant debug connect session to USER01;
grant select any table to USER01;
grant unlimited tablespace to USER01;
删除用户SQL >drop user USER01 cascade;
创建用户
su到数据库用户下
执行 impdp system/123456 dumpfile=schemas_user01.dmp directory=DIRECTORY01 SCHAMES=USER01 parallel=20 LOGFILE=schemas_user01.log
导入导出的相关命令使用
1.Ctrl+C组合键 在执行过程中,可以按CTRL+C键退出当前交互模式,退出之后,导入导出操作不会停止
2.Export > status 查看当前JOB的状态及相关信息
3.Export > stop_job 暂停JOB
4.重新进入export模式: expdp system/123456 attach=system.SYS_IMPORT_TABLE_02; jobname可以通过select * from dba_datapump_jobs查询要终止的jobname
5.Export > start_job 打开暂停的job
6.Export > kill_job 取消当前的JOB并释放相关客户会话(将JOB删除同时删除dmp文件)
7.Export > exit_client 退出export模式
(导入的时候第4条就用impdp)
因测试环境需要,需将正式环境下某用户下的所有对象都导入到测试环境中,这种情况expdp/impdp派上用场了!
因为expdp/impdp使用的是相当路径所以我们需要在生产环境和测试环境都要创建directory expdp/impdexpdp/impdp
p
SQL>SQL> create directory GT_DATA_SBU as '/oracle03/expdp_sbu';
SQL> create directory GT_DATA_SBU as '/oracle03/expdp_sbu';
正式环境:
SQL> create directory DIRECTORY01 as '/oraod/expdir';
利用select * from dba_directories;可以查看数据库已经创建的相对路径
在导出之前,我们利用下面的语句查询该用户下有多少数据需要我们导出
SELECT SUM(s.BYTES)/1024/1024/1024 "sizes(GB)"
FROM dba_segments s
WHERE s.owner= 'USER01'
sizes(GB)
----------
841.142395
可以看到有841G,我们可以用11G expdp带有的compression=ALL参数压缩数据:
一是考虑到生产环境的磁盘空间不够
二是等会要将这些数据SCP到测试环境,数据量太大需要很长的时间花在SCP上;
登陆服务器su到数据库用户
执行expdp system/123456 DIRECTORY=DIRECTORY01 DUMPFILE=schema_user01.dmp COMPRESSION=ALL SCHEMAS=USER01 PARALLEL=20 LOGFILE=schema_user01.log;
[prod@gtsbu expdp_dir]# ls -l
total 77345415
-rw-r----- 1 prod dba 79201562624 Apr 28 01:01 schemas_user01.dmp
-rw-r--r-- 1 prod dba 101206 Apr 28 01:01 schemas_user01.log
导出成功我们可以看到压缩导出一共才77G的数据,节省空间是相当可观的,但是导出的时间要比正常导出的时间多
[root@gtsbu expdp_dir]# scp * root@10.5.128.38:/orasbutmp/expdir 在测试环境中创建directory /orasbutmp/expdir就不在赘述
再使用SCP命令将导出的数据传到测试环已经建立好的相对路径中
测试环境:
从上面SCP过来的数据可以看出是root用户的,所以我们需要把这些导出数据属主改成数据库用户的
[root@gitibisbudb ~]#cd /orasbutmp/expdir
[root@gitibisbudb expdir]# chown prod:dba *
由于测试环境中用户数据已经和正式环境中的数据完全不一致的状态,导入的过程中所以我们先删除用户,再创建用户,重新导入
我们可以通过PL\SQL Developer工具导出这个用户的创建语句:
登陆PL\SQL Developer ----打开users----找到user01---右键view---再点右下角的View SQL
我们可以得到以下创建用户语句
create user USER01
identified by "" --创建的时候需要在""加入之前这个用户的密码
default tablespace USER01_DATA
temporary tablespace USER01_TEMP
profile DEFAULT;
-- Grant/Revoke object privileges
grant select, insert, update, delete, references, alter, index on EBS_R12.CUX_VEND_CUST_TMP_MV to USER01;
grant execute on SYS.DBMS_CRYPTO to USER01;
-- Grant/Revoke role privileges
grant connect to USER01;
grant dba to USER01;
grant resource to USER01;
-- Grant/Revoke system privileges
grant alter any materialized view to USER01;
grant create database link to USER01;
grant create materialized view to USER01;
grant create session to USER01;
grant create synonym to USER01;
grant create view to USER01;
grant debug connect session to USER01;
grant select any table to USER01;
grant unlimited tablespace to USER01;
删除用户SQL >drop user USER01 cascade;
创建用户
su到数据库用户下
执行 impdp system/123456 dumpfile=schemas_user01.dmp directory=DIRECTORY01 SCHAMES=USER01 parallel=20 LOGFILE=schemas_user01.log
导入导出的相关命令使用
1.Ctrl+C组合键 在执行过程中,可以按CTRL+C键退出当前交互模式,退出之后,导入导出操作不会停止
2.Export > status 查看当前JOB的状态及相关信息
3.Export > stop_job 暂停JOB
4.重新进入export模式: expdp system/123456 attach=system.SYS_IMPORT_TABLE_02; jobname可以通过select * from dba_datapump_jobs查询要终止的jobname
5.Export > start_job 打开暂停的job
6.Export > kill_job 取消当前的JOB并释放相关客户会话(将JOB删除同时删除dmp文件)
7.Export > exit_client 退出export模式
(导入的时候第4条就用impdp)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29989552/viewspace-1608825/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29989552/viewspace-1608825/