RMAN Block Compression for Backup Sets

O RMAN utiliza 2 tipos de compressão de blocos quando está realizando a criação dos backup sets:

  • Unused Block Compression (suportado nos backups em disco e em backups de fita via Oracle Secure Backup)
  • Null Block Compression (suportado em todos os tipos de backup)

Apesar dessa referência de compressão, nos bastidores o RMAN realiza um “block skipping”, ou seja, ao montar o backup set, os blocos em questão não são contemplados no backup. Na documentação oficial (link AQUI), vemos que o recurso de Unused Block Compression ocorre quando:

Além dos itens acima, também é considerado que o RMAN lerá aqueles blocos que atualmente são utilizados por algum segmento do banco de dados.

Já o “Null Block Compression” nada mais é do que a regra: blocos que nunca foram usados não serão contemplados no backup. Blocos que possuem ou já possuíram dados, serão contemplados.

Eu encontrei um post na internet de como simular esses recursos (link AQUI) e decidir reproduzir exatamente o mesmo processo, para ter passado pela experiência ver em funcionamento. Criando uma tablespace (com 100MB) e usuário:

[oracle@oel8 ~]$ sqlplus / as sysdba
 
SQL*Plus: Release 18.0.0.0.0 - Production on Fri Apr 30 04:50:57 2021
Version 18.13.0.0.0
 
Copyright (c) 1982, 2018, Oracle.  All rights reserved.
 
 
Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.13.0.0.0
 
SQL> CREATE TABLESPACE ASWAN;
 
Tablespace created.
 
SQL> CREATE USER LUXOR IDENTIFIED BY LUXOR DEFAULT TABLESPACE ASWAN;
 
User created.
 
SQL> ALTER USER LUXOR QUOTA UNLIMITED ON ASWAN;
 
User altered.
 
SQL> GRANT CREATE SESSION TO LUXOR;
 
Grant succeeded.
 
SQL> GRANT DBA TO LUXOR;
 
Grant succeeded.
 
SQL> col file_name for a50
SQL> select file_name, bytes/1024/1024 from dba_data_files where tablespace_name = 'ASWAN';
 
FILE_NAME                                          BYTES/1024/1024
-------------------------------------------------- ---------------
/oracle/dados/RMANDB/datafile/o1_mf_aswan_j8qfq313             100
_.dbf

Realizando um backup dessa tablespace, que até o momento, está vazia. O que podemos perceber? Apesar da tablespace ter 100MB, o backup tem pouco mais de 1MB. Ou seja, o RMAN usufruiu do recurso de Null Block Compression:

[oracle@oel8 ~]$ rman target /
 
Recovery Manager: Release 18.0.0.0.0 - Production on Fri Apr 30 04:53:03 2021
Version 18.13.0.0.0
 
Copyright (c) 1982, 2018, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database: RMANDB (DBID=3825250984)
 
RMAN> BACKUP TABLESPACE ASWAN;
 
Starting backup at 2021-04-30:04:53:19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=89 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=/oracle/dados/RMANDB/datafile/o1_mf_aswan_j8qfq313_.dbf
channel ORA_DISK_1: starting piece 1 at 2021-04-30:04:53:19
channel ORA_DISK_1: finished piece 1 at 2021-04-30:04:53:20
piece handle=/oracle/fra/RMANDB/backupset/2021_04_30/o1_mf_nnndf_TAG20210430T045319_j8qfvj5g_.bkp tag=TAG20210430T045319 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2021-04-30:04:53:20
 
Starting Control File and SPFILE Autobackup at 2021-04-30:04:53:20
piece handle=/oracle/fra/RMANDB/autobackup/2021_04_30/o1_mf_s_1071204801_j8qfvkm8_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2021-04-30:04:53:22
 
RMAN> LIST BACKUP OF TABLESPACE ASWAN;
 
 
List of Backup Sets
===================
 
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
260     Full    1.05M      DISK        00:00:01     2021-04-30:04:53:20
        BP Key: 260   Status: AVAILABLE  Compressed: NO  Tag: TAG20210430T045319
        Piece Name: /oracle/fra/RMANDB/backupset/2021_04_30/o1_mf_nnndf_TAG20210430T045319_j8qfvj5g_.bkp
  List of Datafiles in backup set 260
  File LV Type Ckp SCN    Ckp Time            Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- ------------------- ----------- ------ ----
  2       Full 2568238    2021-04-30:04:53:19              NO    /oracle/dados/RMANDB/datafile/o1_mf_aswan_j8qfq313_.dbf

Nesta etapa vamos criar alguns segmentos dentro da tablespace, que atingirá um tamanho de 88MB:

[oracle@oel8 ~]$ sqlplus LUXOR/LUXOR
 
SQL*Plus: Release 18.0.0.0.0 - Production on Fri Apr 30 04:58:56 2021
Version 18.13.0.0.0
 
Copyright (c) 1982, 2018, Oracle.  All rights reserved.
 
Last Successful login time: Fri Apr 30 2021 04:58:07 -03:00
 
Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.13.0.0.0
 
SQL> CREATE TABLE TESTE AS SELECT * FROM DBA_OBJECTS;
 
Table created.
 
SQL> INSERT INTO TESTE SELECT * FROM TESTE;
 
73407 rows created.
 
SQL> INSERT INTO TESTE SELECT * FROM TESTE;
 
146814 rows created.
 
SQL> INSERT INTO TESTE SELECT * FROM TESTE;
 
293628 rows created.
 
SQL> COMMIT;
 
Commit complete.
 
SQL> col segment_name for a30
SQL> select segment_name, bytes/1024/1024 from user_segments where tablespace_name = 'ASWAN';
 
SEGMENT_NAME                   BYTES/1024/1024
------------------------------ ---------------
TESTE                                       88

Realizando backup da tablespace (eu já deletei o backupset anterior para não termos uma visão poluída). Agora podemos notar que devido sua utilização por parte de segmentos de banco de dados, o tamanho do backup é o mesmo do tamanho da tablespace:

[oracle@oel8 ~]$ rman target /
 
Recovery Manager: Release 18.0.0.0.0 - Production on Fri Apr 30 05:03:41 2021
Version 18.13.0.0.0
 
Copyright (c) 1982, 2018, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database: RMANDB (DBID=3825250984)
 
RMAN> BACKUP TABLESPACE ASWAN;
 
Starting backup at 2021-04-30:05:03:50
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=93 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=/oracle/dados/RMANDB/datafile/o1_mf_aswan_j8qfq313_.dbf
channel ORA_DISK_1: starting piece 1 at 2021-04-30:05:03:51
channel ORA_DISK_1: finished piece 1 at 2021-04-30:05:03:54
piece handle=/oracle/fra/RMANDB/backupset/2021_04_30/o1_mf_nnndf_TAG20210430T050351_j8qgh805_.bkp tag=TAG20210430T050351 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 2021-04-30:05:03:54
 
Starting Control File and SPFILE Autobackup at 2021-04-30:05:03:54
piece handle=/oracle/fra/RMANDB/autobackup/2021_04_30/o1_mf_s_1071205434_j8qghc1c_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2021-04-30:05:03:55
 
RMAN> LIST BACKUP OF TABLESPACE ASWAN;
 
 
List of Backup Sets
===================
 
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
262     Full    89.05M     DISK        00:00:01     2021-04-30:05:03:52
        BP Key: 262   Status: AVAILABLE  Compressed: NO  Tag: TAG20210430T050351
        Piece Name: /oracle/fra/RMANDB/backupset/2021_04_30/o1_mf_nnndf_TAG20210430T050351_j8qgh805_.bkp
  List of Datafiles in backup set 262
  File LV Type Ckp SCN    Ckp Time            Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- ------------------- ----------- ------ ----
  2       Full 2571030    2021-04-30:05:03:51              NO    /oracle/dados/RMANDB/datafile/o1_mf_aswan_j8qfq313_.dbf

Dropando o segmento e fazendo o purge:

SQL> DROP TABLE LUXOR.TESTE;
 
Table dropped.
 
SQL> PURGE TABLE LUXOR.TESTE;
 
Table purged.

Com o exemplo abaixo, vemos implementado o recurso de Unused Block Compression:

RMAN> BACKUP TABLESPACE ASWAN;
 
Starting backup at 2021-04-30:05:09:13
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=00002 name=/oracle/dados/RMANDB/datafile/o1_mf_aswan_j8qfq313_.dbf
channel ORA_DISK_1: starting piece 1 at 2021-04-30:05:09:14
channel ORA_DISK_1: finished piece 1 at 2021-04-30:05:09:15
piece handle=/oracle/fra/RMANDB/backupset/2021_04_30/o1_mf_nnndf_TAG20210430T050914_j8qgsb4n_.bkp tag=TAG20210430T050914 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2021-04-30:05:09:15
 
Starting Control File and SPFILE Autobackup at 2021-04-30:05:09:15
piece handle=/oracle/fra/RMANDB/autobackup/2021_04_30/o1_mf_s_1071205755_j8qgscnl_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2021-04-30:05:09:16
 
RMAN> LIST BACKUP OF TABLESPACE ASWAN;
 
 
List of Backup Sets
===================
 
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
264     Full    1.05M      DISK        00:00:00     2021-04-30:05:09:14
        BP Key: 264   Status: AVAILABLE  Compressed: NO  Tag: TAG20210430T050914
        Piece Name: /oracle/fra/RMANDB/backupset/2021_04_30/o1_mf_nnndf_TAG20210430T050914_j8qgsb4n_.bkp
  List of Datafiles in backup set 264
  File LV Type Ckp SCN    Ckp Time            Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- ------------------- ----------- ------ ----
  2       Full 2571325    2021-04-30:05:09:14              NO    /oracle/dados/RMANDB/datafile/o1_mf_aswan_j8qfq313_.dbf

Limpando ambiente:

SQL> DROP USER LUXOR;
 
User dropped.
 
SQL> DROP TABLESPACE ASWAN INCLUDING CONTENTS AND DATAFILES;
 
Tablespace dropped.

Leave a Comment

Your email address will not be published.