Oracle数据库数据恢复、性能优化

找回密码
注册
搜索
热搜: 活动 交友 discuz
发新帖

45

积分

0

好友

3

主题
1#
发表于 2012-6-11 16:01:06 | 查看: 10863| 回复: 7
请问:
1)如何计算RMAN备份时所需空间?
2)如何使用RMAN备份时不备份空块?只备份有数据的块?

谢谢!
2#
发表于 2012-6-11 16:11:55
FOR Question 1

1)如何计算RMAN备份时所需空间?


在不考虑 compress backupset 的情况下


oracle@vrh1 ~]$ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Mon Jun 11 04:05:24 2012

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: VPROD (DBID=896680541)

RMAN>

RMAN>

RMAN> report schema;

using target database control file instead of recovery catalog
Report of database schema for database with db_unique_name VPROD

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    780      SYSTEM               ***     +DATA/vprod/datafile/system.730.781835417
2    660      SYSAUX               ***     +DATA/vprod/datafile/sysaux.731.781835417
3    575      UNDOTBS1             ***     +DATA/vprod/datafile/undotbs1.732.781835419
4    1262     USERS                ***     +DATA/vprod/datafile/users.733.781835419
5    346      EXAMPLE              ***     +DATA/vprod/datafile/example.738.781835515
6    25       UNDOTBS2             ***     +DATA/vprod/datafile/undotbs2.739.781835687

SYSAUX                660MB

用 backup validate  不会产生实际的备份集

RMAN> backup validate datafile 2;

Starting backup at 11-JUN-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=32 instance=VPROD1 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=+DATA/vprod/datafile/sysaux.731.781835417
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
2    OK     0              21218        84482           3726636   
  File Name: +DATA/vprod/datafile/sysaux.731.781835417
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              19460           
  Index      0              15059           
  Other      0              28743           

Finished backup at 11-JUN-12


2    OK     0              21218        84482           3726636   

block 总数 84482           =》 660MB
empty block 21218         => 165.MB


660-165= 495MB


实际备份


RMAN> backup datafile 2 format '/s01/%U.bak';

Starting backup at 11-JUN-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=158 instance=VPROD1 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=+DATA/vprod/datafile/sysaux.731.781835417
channel ORA_DISK_1: starting piece 1 at 11-JUN-12
channel ORA_DISK_1: finished piece 1 at 11-JUN-12
piece handle=/s01/0gnd84ai_1_1.bak tag=TAG20120611T040642 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 11-JUN-12

RMAN>

Recovery Manager complete.


[oracle@vrh1 ~]$ ls -lh /s01/0gnd84ai_1_1.bak
-rw-r----- 1 oracle asmadmin 507M Jun 11 04:06 /s01/0gnd84ai_1_1.bak
[oracle@vrh1 ~]$


实际备份660MB empty block 165MB的数据文件,生成 507MB的backup piece ,因为备份集本身有一定的空间overhead

回复 只看该作者 道具 举报

3#
发表于 2012-6-11 21:45:59
FOR QUESTION 2

2)如何使用RMAN备份时不备份空块?只备份有数据的块?


RMAN 默认就不会备份空快, 只备份有“数据”的块! 这不需要任何设置


SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE    11.2.0.3.0      Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production

SQL> create tablespace IAMEMPTY datafile size 100M;

Tablespace created.


RMAN> backup validate tablespace IAMEMPTY;

Starting backup at 11-JUN-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=156 instance=VPROD1 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=+DATA/vprod/datafile/iamempty.742.785669531
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
7    OK     0              12673        12800           3749002   
  File Name: +DATA/vprod/datafile/iamempty.742.785669531
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              0               
  Index      0              0               
  Other      0              127            

Finished backup at 11-JUN-12


12800          个块中 12673个empty block

RMAN> backup tablespace IAMEMPTY format '/s01/%U.bak';

Starting backup at 11-JUN-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=+DATA/vprod/datafile/iamempty.742.785669531
channel ORA_DISK_1: starting piece 1 at 11-JUN-12
channel ORA_DISK_1: finished piece 1 at 11-JUN-12
piece handle=/s01/0ind8nev_1_1.bak tag=TAG20120611T093319 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-JUN-12


[oracle@vrh1 ~]$ ls -lh /s01/0ind8nev_1_1.bak
-rw-r----- 1 oracle asmadmin 1.1M Jun 11 09:33 /s01/0ind8nev_1_1.bak

实际大小仅 1.1MB 约等于 12800-12673=   0.99MB



SQL> create table maclean1 (t1 int) tablespace IAMEMPTY;  

Table created.

SQL> alter table maclean1 allocate extent (size 50M);

Table altered.


RMAN>  backup validate tablespace IAMEMPTY;

Starting backup at 11-JUN-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=141 instance=VPROD1 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=+DATA/vprod/datafile/iamempty.742.785669531
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
7    OK     0              12570        12800           3749187   
  File Name: +DATA/vprod/datafile/iamempty.742.785669531
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              0               
  Index      0              0               
  Other      0              230            

Finished backup at 11-JUN-12

可以看到虽然分配了50MB extent给 表空间上的表对象, 但是实际这些块仍算作 empty block
SQL> alter table maclean1 pctfree 99 pctused 1;

Table altered.

SQL> insert into maclean1 select 1 from dual connect by level <=100000;
insert into maclean1 select 1 from dual connect by level <=100000
            *
ERROR at line 1:
ORA-01653: unable to extend table SYS.MACLEAN1 by 1024 in tablespace IAMEMPTY


SQL> insert into maclean1 select 1 from dual connect by level <=50000;

50000 rows created.

SQL> commit;

Commit complete.

RMAN> backup validate tablespace IAMEMPTY;

Starting backup at 11-JUN-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=141 instance=VPROD1 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=+DATA/vprod/datafile/iamempty.742.785669531
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
7    OK     0              377          12800           3874267   
  File Name: +DATA/vprod/datafile/iamempty.742.785669531
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              12150           
  Index      0              0               
  Other      0              273            

Finished backup at 11-JUN-12


实际插入数据到表后 empty block的数量大幅减少


SQL> truncate table maclean1 ;

Table truncated.


RMAN> backup validate tablespace IAMEMPTY;

Starting backup at 11-JUN-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=32 instance=VPROD1 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=+DATA/vprod/datafile/iamempty.742.785669531
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
7    OK     0              377          12800           3886817   
  File Name: +DATA/vprod/datafile/iamempty.742.785669531
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              12150           
  Index      0              0               
  Other      0              273            

Finished backup at 11-JUN-12


以上可以看到普通的 truncate 是无法让 empty block 变多的! 更不用说DELETE了,DELETE  甚至不会下降高水位!


SQL>  truncate table maclean1 drop all storage;

Table truncated.

SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
[oracle@vrh1 ~]$ rman target /      

Recovery Manager: Release 11.2.0.3.0 - Production on Mon Jun 11 09:43:28 2012

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: VPROD (DBID=896680541)

RMAN> backup validate tablespace IAMEMPTY;

Starting backup at 11-JUN-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=34 instance=VPROD1 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=+DATA/vprod/datafile/iamempty.742.785669531
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
7    OK     0              377          12800           3887038   
  File Name: +DATA/vprod/datafile/iamempty.742.785669531
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              12150           
  Index      0              0               
  Other      0              273            

Finished backup at 11-JUN-12




  truncate table drop all storage; 也无法做到 让empty block还原!

SQL> drop table maclean1 purge;

Table dropped.

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
7    OK     0              377          12800           3887121   
  File Name: +DATA/vprod/datafile/iamempty.742.785669531
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              12150           
  Index      0              0               
  Other      0              273            

Finished backup at 11-JUN-12


drop table 也是一样的 虽然 表空间实际上大把的FREE SPACE


SQL> select block_id,file_id,blocks from dba_free_space where TABLESPACE_NAME='IAMEMPTY';

  BLOCK_ID    FILE_ID     BLOCKS
---------- ---------- ----------
       128          7      12672

回复 只看该作者 道具 举报

4#
发表于 2012-7-16 15:45:29
刘大,我在使用RMAN> backup validate tablespace IAMEMPTY; 时,为什么不显示下面的信息?

=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
7    OK     0              377          12800           3874267   
  File Name: +DATA/vprod/datafile/iamempty.742.785669531
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              12150           
  Index      0              0               
  Other      0              273

回复 只看该作者 道具 举报

5#
发表于 2012-7-17 09:17:14
因为你的rman version 是10g,所以。。。。

回复 只看该作者 道具 举报

6#
发表于 2012-7-17 11:13:28
知道了,谢谢,北柏。

回复 只看该作者 道具 举报

7#
发表于 2012-7-17 14:07:15
学习了,谢谢!

回复 只看该作者 道具 举报

8#
发表于 2012-8-12 13:01:27
谢谢刘大,从测试上面看来,也就是说只要曾经在块上填充了数据的,即使是truncate或者drop掉了,RMAN依然会备份这些块?但我们看来,这些就是无数据的块,也就是空的,但RMAN不这样认为!!

回复 只看该作者 道具 举报

您需要登录后才可以回帖 登录 | 注册

QQ|手机版|Archiver|Oracle数据库数据恢复、性能优化

GMT+8, 2024-11-16 02:27 , Processed in 0.051396 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部
TEL/電話+86 13764045638
Email service@parnassusdata.com
QQ 47079569