数据量不多时,手动复制粘贴就可以解决,但是遇到10万条以上的表,甚至无法打开,亦无法导出
select count(1) from core_wf_workitem t
这时候要做数据比对迁移无疑工作量巨大,使用emp和imp命令可以节省很多时间(给强大佬递茶)
方法:
从数据库1导出表,导入表到数据库2
单表导出
exp name1/pass1@service1 file=/u01/app/oracle/table.dmp log=/u01/app/oracle/table.log tables=\(table\);
name1:数据库1的用户名
pass1:数据库1的密码
service1:数据库1的服务名
file:导出的dmp文件存放地址
log:导出时的日志文件存放地址
tables:需要导出的表,若不使用则全库导出
单表导入
imp name2/pass2 fromuser=user1 touser=user2 file=/u01/app/oracle/table.dmp log=/u01/app/oracle/table.log ignore=y tables=table;
name2:导入目标数据库2的用户名
pass2:导入目标数据库2的密码
fromuser:导出的dmp文件中使用的用户名,即数据库1的用户名
touser:导入目标数据库2的用户名
file:导入文件的地址
log:导入日志的地址
ignore:忽略报错
tables:导入到数据库2的目标表名
还遇到错误
ORA-01654: unable to extend index BO.INDEX_indexname by 311072 in tablespace
一般情况是目标表空间不足,无法继续扩展
表空间查看方法
select a.tablespace_name as "表空间名",
a.bytes / 1024 / 1024 as "表空间大小(M)",
(a.bytes - b.bytes) / 1024 / 1024 as "已使用空间(M)",
b.bytes / 1024 / 1024 "空闲空间(M)",
round(((a.bytes - b.bytes) / a.bytes) * 100, 2) "使用比"
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;
解决方法:扩展表空间
alter tablespace mytablespace
add datafile '/u01/app/oracle/oradata/xe/mytablespace01.dbf'
size 2048m;
# 将mytablespace的表空间扩展2G,扩展文件放在/u01/app/oracle/oradata/xe下