您的位置:首页 > 数据库 > Oracle

oracle非归档不停机迁移数据的方法---expdp/impdp

2014-08-20 22:29 429 查看
迁移之前的准备工作在需要导出的数据库执行:1. 检查Oracle实例状态 ,sidSQL< select instance_name,host_name,startup_time,status,database_status from v$instance;2.查看用户和默认表空间的关系。selectusername, DEFAULT_TABLESPACE from dba_users;3.切换到你需要导出的账户,查看表对应的表空间。select table_name,tablespace_namefrom user_all_tables;select tablespace_name,count(tablespace_name) from user_all_tables group by tablespace_name;4.检查表空间使用情况selectf.tablespace_name,a.total,f.free,(a.total-f.free)/1024 "usedSIZE(G)",round((f.free/a.total)*100) "% Free"from(select tablespace_name, sum(bytes/(1024*1024))total from dba_data_files group by tablespace_name) a,(select tablespace_name,round(sum(bytes/(1024*1024))) free from dba_free_space group by tablespace_name) fWHERE a.tablespace_name =f.tablespace_name(+)order by "% Free"
5.创建dump directory目录: create  or replace directory test_dir as '/home/oracle/dump';
在操作系统上药创建相应的目录。 ho mkdir /home/oracle/dump
6.授权:Grant read,write on directory test_dir to cesm;
7.导出数据:
导出全库:ho expdp \'/ as sysdba\' full=y directory=test_dir dumpfile=full.dmp
导出指定用户:ho expdp \'/ as sysdba\' schemas=bankuser directory=test_dir dumpfile=bank.dmp
windows下是:ho expdp '/ as sysdba' schemas=bankuser directory=test_dir dumpfile=bank.dmp
导出指定表空间:ho expdp bankuser/bankuser tablespaces=bank  directory=test_dir dumpfile=tablespace.dmp
导出指定表: ho expdp bankuser/bankuser tables=emp% directory=test_dir dumpfile=table.dmp  (emp%:以emp开头的表)
带条件导出单个表:ho expdp scott/cat tables=emp query=\'where deptno=10\' directory=test_dir dumpfile=emp.dmp
带条件导出多个表:ho expdp scott/cat tables=emp,emp1,dept query=\'where deptno=10\' directory=test_dir dumpfile=emp3.dmp
或 expdp \"testuser/testuser\" DIRECTORY=test_dir dumpfile=cu.dmp tables=test query=\"where cust like \'066%\'\"
query="where cust_no like '066%'"  注意转义字符
只导出定义:
expdp system/<password> DIRECTORY=datamove DUMPFILE=schema_exp.dmp SCHEMAS=scott content=metadata_only

导出表
Linux/Unix Platform
expdp system/<password> DIRECTORY=datamove DUMPFILE=export.dmp logfile=export.log schemas=scott INCLUDE=table:\"LIKE \'%EMP%\'\"
Windos Platform
expdp system/<password> DIRECTORY=datamove DUMPFILE=export.dmp logfile=export.log schemas=scott INCLUDE=table:\"LIKE '%EMP%'\"
8.导入数据:
2)按用户导入, 这里由david执行导入scott的数据表(切莫在末尾加上分号)impdp david/abc123 directory=dirdp dumpfile=expdp.dmp remap_schema=scott:david
impdp david/abc123 directory=dirdp dumpfile=expdp.dmp schemas=scott remap_schema=scott:david
ho impdp system/oracle schemas=bankuser (remap_schema=bankuser:bankuser) directory=test_dir dumpfile=bank.dmp  如果是导入原用户名都不用创建用户,不是原用户名创建后需要改密码。但都要创建对应表空间。
按表导入:
ho impdp scott/cat tables=emp directory=test_dir dumpfile=emp.dmp
按查询条件导入impdp david/abc123@orcl schemas=scott remap_schema=scott:david directory=dirdp dumpfile=expdp.dmp query='dept:"WHERE DEPTNO=20"';
按表空间导出入impdp system/oracle directory=dirdp dumpfile=tablespace.dmp tablespaces=users;
导入整个数据库impdp system/oracle directory=dirdp dumpfile=full.dmp full=y;
并行导入:expdp scott/tiger@orcl schemas=scott directory=dirdp dumpfile=expdp_%U.dmp logfile=expdp.log parallel=12 job_name=jobname_parallel
并行导出
目标库建表空间,用户。
revoke取消授权
查看所有目录:select * from dba_directories;
--查看目录及权限Sql代码   SELECT PRIVILEGE, DIRECTORY_NAME, DIRECTORY_PATH    FROM USER_TAB_PRIVS T, ALL_DIRECTORIES D   WHERE T.TABLE_NAME(+) = D.DIRECTORY_NAME   ORDER BY 2, 1;
注:非归档模式不能实现一致性备份。非归档,没归档日志,基本上没办法恢复,只能恢复到rman冷备那个时间点。非归档下,RMAN只以冷备不能热备,且需要停机。如果数据重要,还是打开归档吧。查看oracle数据库是否归档和修改归档模式:Oracle分为非归档模式(NOARCHIVELOG)和归档模式(ARCHIVELOG)。非归档模式不产生归档日志,虽然节省了硬盘空间,但是备份方案选择很有限,通常只能选择冷备份。还原也只能还原到备份那一时刻的数据,通常也仅在开发时使用(据说在数据仓库中也使用),Oracle安装默认就是非归档模式。在生产环境中我们因该使用归档模式,它会产生归档日志,可以使用多种备份和还原方案,对与Oracle管理员来说应该更改模式是必然的选择。1.查看数据库现有模式可使用以下语句select name,log_mode from v$database;也可以用下面的语句archive log list;(该方法需要as sysdba)2.关闭数据库SQL> shutdown immediate;3.启动数据库到mount模式SQL> startup mount;4.修改数据库为归档模式SQL> alter database archivelog;5,打开数据库库SQL> alter database open;SQL> SELECT NAME,created,log_mode FROM v$database;NAME CREATED LOG_MODE--------- --------- ------------ORCL 04-JUN-12 ARCHIVELOG6,查看归档日志的路径和目录SQL> show parameter db_recovery_file_dest;NAME TYPE VALUE------------------------------------ ----------- ------------------------------db_recovery_file_dest string /data/app/oracle/flash_recovery_areadb_recovery_file_dest_size big integer 2G修改方法:SQL> alter system set db_recovery_file_dest_size=20g;SQL> alter system set db_recovery_file_dest='/app/arc';
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: