1、准备导入备份集合
从192.168.0.31上讲dmp文件scp到192.168.0.11上(含备份集和导出log)
经过查看日志可以使用的用户为count,imp表空间的话是tbsrb --来自于生产库
2、查看192.168.0.11上现有的用户和表空间
目的是为了在导入的时候避免已经存在的用户和表空间 PLAT,ENT:表空间是ENTTBS 、PLATTBS
3、确认选取的用户和表空间
在目标库上 192.168.0.11上 创建表空间 tbsrb 30G.
使用用户 count和imp
4、将备份集复制到目标库
[oracle@pdb1 expdp]$scp db20151106.dmp192.168.0.11:/backup/expdp/
The authenticity ofhost '192.168.0.11 (192.168.0.11)' can't be established.
RSA key fingerprintis ea:00:07:15:4a:d7:36:fc:bb:60:f4:cd:f1:56:53:d1.
Are you sure youwant to continue connecting (yes/no)? yes
Warning: Permanentlyadded '192.168.0.11' (RSA) to the list of known hosts.
oracle@192.168.0.11'spassword:
db20151106.dmp 100% 67GB 105.9MB/s 10:48
5、目标库上创建tbsrb表空间 30G
select instance_namefrom v$instance;
racdb1
6、查看备库上空间
ASMCMD> lsdg
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
MOUNTED EXTERN N 512 4096 1048576 127994 61425 0 61425 0 N DATA/
MOUNTED EXTERN N 512 4096 1048576 102398 83394 0 83394 0 N FRA/
MOUNTED EXTERN N 512 4096 4194304 5112 4680 0 4680 0 Y OCR/
SQL> archive loglist;
Database logmode Archive Mode
Automaticarchival Enabled
Archivedestination USE_DB_RECOVERY_FILE_DEST
Oldest online logsequence 159
Next log sequence toarchive 163
Current logsequence 163
SQL> showparameter DB_RECOVERY_FILE_DEST
NAME TYPE VALUE
----------------------------------------------- ------------------------------
db_recovery_file_dest string +FRA
db_recovery_file_dest_size big integer 60G
查询当前闪回日志使用情况
SQL> select *from v$recovery_file_dest;
NAME
-----
SPACE_LIMITSPACE_USED SPACE_RECLAIMABLE NUMBER_OF_FILES
--------------------- ----------------- ---------------
+FRA
6.4425E+10 1.6543E+10 1.4519E+10 313
7、做导入并查看alter日志
impdpsystem/system directory=EXPDP PARALLEL=4 schemas=count,impdumpfile=db20151106.dmp logfile=20151216countandimp.log
导入的过程中虽然后报错但是表空间和用户下已经有数据,可以继续进行测试。
检查空间情况
ASMCMD> lsdg
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
MOUNTED EXTERN N 512 4096 1048576 127994 50833 0 50833 0 N DATA/
MOUNTED EXTERN N 512 4096 1048576 102398 56873 0 56873 0 N FRA/
MOUNTED EXTERN N 512 4096 4194304 5112 4680 0 4680 0 Y OCR/
SQL> l
1* select * from v$recovery_file_dest
SQL> /
NAME
--------------------------------------------------------------------------------
SPACE_LIMITSPACE_USED SPACE_RECLAIMABLE NUMBER_OF_FILES
--------------------- ----------------- ---------------
+FRA
6.4425E+10 4.4353E+10 1.2166E+10 1045
确认当前 +/FRA/下闪回日志个数
284个
8、删除表中数据分批次生成日志
conn count/count12
select count(*) from count.transaction t whereto_char(t.date_created, 'YYYYMM')='201411';
SQL> selectcount(*) from count.transaction t whereto_char(t.date_created, 'YYYYMM')='201411';
COUNT(*)
----------
1229110
SQL> delete from count.transaction t whereto_char(t.date_created, 'YYYYMM')='201411';
1229110 rowsdeleted.
SQL> selectcount(*) from count.demot t whereto_char(t.date_created, 'YYYYMM')='201501';
COUNT(*)
----------
3323374
SQL> delete from count.demot t where to_char(t.date_created, 'YYYYMM')='201501';
3323374 rowsdeleted.
SQL>
SQL>
SQL> commit;
Commit complete.
SQL> selectcount(*) from count.demot t whereto_char(t.date_created, 'YYYYMM')='201502';
COUNT(*)
----------
2924600
SQL> delete fromcount.demot t whereto_char(t.date_created, 'YYYYMM')='201502';
2924600 rowsdeleted.
SQL> selectcount(*) from count.demot t whereto_char(t.date_created, 'YYYYMM')='201503';
COUNT(*)
----------
4741330
SQL> selectcount(*) from count.demot t whereto_char(t.date_created, 'YYYYMM')='201503';
COUNT(*)
----------
4741330
SQL> delete fromcount.demot t whereto_char(t.date_created, 'YYYYMM')='201503';
4741330 rowsdeleted.
此时 +FRA中闪回日志的个数为259个
继续删除:
SQL> selectcount(*) from count.demot t whereto_char(t.date_created, 'YYYYMM')='201504';
COUNT(*)
----------
4819826
SQL> delete fromcount.demot t whereto_char(t.date_created, 'YYYYMM')='201504';
此时 +FRA中闪回日志的个数为212个
NAME
--------------------------------------------------------------------------------
SPACE_LIMITSPACE_USED SPACE_RECLAIMABLE NUMBER_OF_FILES
--------------------- ----------------- ---------------
+FRA
6.4425E+10 5.1809E+10 0 1470
实验结果:
Oracle会在闪回区空间有压力的时候进行删除闪回日志回收空间。
alter日志中删除闪回日志的记录
DeletedOracle managed file +FRA/racdb/flashback/log_162.846.866771949
…………………….
Deleted Oracle managed file+FRA/racdb/flashback/log_503.1445.866772789
…………………….
Deleted Oracle managed file+FRA/racdb/flashback/log_57.1112.866771753
…………………….
Deleted Oracle managed file+FRA/racdb/flashback/log_59.1115.866771759
…………………….
8、后期处理
删除 count用户和 imp用户
删除表空间 tbsrb
drop user namecascade搜索对用户数据的删除属于DDL,就删除前的数据不会写入日志,也就不会被记录。
drop user imp cascade;
drop user count cascade;
drop tablespace tbsrb including contents anddatafiles;
注意事项:
1、删除表数据的时候,要关注 undo表空间的大小,如果undo空间不足,需要增加Unbo表空间文件
2、需要关注ASM磁盘组 FRA的空间使用情况,即结合 select * from v$recovery_file_dest的输出结果,进行有选择性的删除表,如果是测试环境则无所谓。
select * from v$recovery_file_dest的输出如下
SQL> /
NAME
--------------------------------------------------------------------------------
SPACE_LIMITSPACE_USED SPACE_RECLAIMABLE NUMBER_OF_FILES
--------------------- ----------------- ---------------
+FRA
6.4425E+10 4.4353E+10 1.2166E+10 1045
此处显示虽然FRA磁盘组有100多个G的空间,但是闪回区的大小 只有60G,因此在产生归档日志的时候,需要注意不要一下子删除太多的数据,否则归档日志会将闪回区填满。所以使用,建议使用闪回区做归档区域的时候,闪回区的大小建议为整个磁盘组的大小(如果该磁盘中如FRA是专门用来保存归档的)。因为修改闪回区的大小是需要重启数据库的。
3、如果是DG环境,同样需要关注DG环境的 FRA磁盘组大小和 闪回区的大小。
4、如果闪回区满了,可以将归档设置到其他目录,修改alter system set log_archive_dest =其他路径,将归档日志指到别处。