最近客户需要搭建一个测试库,折腾完,正好把的经验整理一下。
nls_database_parameter
和nls_instance_parameter
中的language保持一致alter database noarchivelog;
alter database flashback off;
alter system set processes=500 scope=spfile;
alter system set sessions=555 scope=spfile ;
alter profile default limit password_life_time unlimited;
alter profile default limit failed_login_attempts unlimited;
expdp system/test@test schemas=(hr,scott) directory=dumpdir parallel=5 estimate_only=Y estimate=blocks
#这个estimate可以选择根据blocks或者statics来计算
linux: which expdp
windows: where expdp
ORA-39064: 无法写入日志文件
ORA-29285: 文件写入错误
ALL, DATA_ONLY, [METADATA_ONLY] and NONE
. 一般就用ALL
就好。reuse_dumpfiles=Y
来重用之前的dump文件。%U
代表分片的编号。导出命令如下:
sqlplus sys/test@test as sysdba
SQL>create directory dumpdir as '~/dumpdir'
SQL>grant read,write on directory dumpdir to system
SQL>exit
expdp system/test@test schemas=(hr,scott) directory=dumpdir dumpfile=expdb_%U.dmp logfile=expdp.log parallel=5 filesize=5G compression=ALL reuse_dumpfiles=Y
remap_tablespace=prod_tbs:sit_tbs
来映射。添加的文件最好一次性指定大小,不要让数据库在导入的时候自动扩展,这样效率不高。create tablespace test datafile '/opt/app/oracle/data/test01.dbf' size 30G;
alter tablespace test add datafile '/opt/app/oracle/data/test02.dbf' size 30G;
........
–以下SQL在生产库中查出各表空间的大小
select a.tablespace_name,round(total_size,2),round(free_size,2),round(total_size-free_size,2) as use_size from
(select tablespace_name,sum(bytes)/power(1024,3) total_size from dba_data_files a group by tablespace_name) a,
(select tablespace_name,sum(bytes)/power(1024,3) free_size from dba_free_space a group by tablespace_name) b
where a.tablespace_name=b.tablespace_name
order by 2 desc
导入命令
sqlplus sys/test@test as sysdba
SQL>create directory dumpdir as '~/dumpdir'
SQL>grant read,write on directory dumpdir to system
SQL>exit
impdp system/test@test schemas=(hr,scott) directory=dumpdir dumpfile=expdb_%U.dmp logfile=impdp.log parallel=5
ORA-39002: invalid operation
ORA-39059: dump file set is incomplete
ORA-39246: cannot locate master table within provided dump files
在expdp时导出时提示已成功导出,且复制文件时也没有漏掉。后来在生产库重新创建了目录,然后重新导出,再导入时就没问题了。可能之前在这个目录执行了多次expdp,没有保证上一次expdp的进程完全结束就开始了新一次expdp导致的。也有说部分dump文件的权限oracle无法访问也会导致这种情况。