LoginSignup
1
0

More than 3 years have passed since last update.

RMANバックアップ検証1 バックアップセットの「未使用ブロック」とは何か?

Last updated at Posted at 2019-06-13

バックアップセットは「未使用ブロック」を含まない効率的なバックアップだと書かれている。

【Oracle Databaseバックアップおよびリカバリ・ユーザーズ・ガイド 11g リリース2(11.2)】

未使用ブロックの圧縮
RMANで、データ・ブロックをスキップすることによってデータファイル・
バックアップ・セットのサイズを小さくする機能。
RMANでは、一度も使用されていないブロックが常にスキップされます。

RMANバックアップにおける「未使用ブロック」とは具体的に何を指すのか? を検証した。

  1. 表領域内の使用可能エクステント(dba_free_spaceビューで表示される表領域の使用可能エクステント)は、「未使用ブロック」か?
  2. セグメントのHWM以後の空き領域は、「未使用ブロック」か?

この記事では11gリリース2 (11.2)を使っています。

■結論

  1. 表領域内の使用可能エクステント(dba_free_spaceビューで表示される表領域の使用可能エクステント)は、「未使用ブロック」に該当する。

    表領域内の使用可能エクステントは、バックアップセットには含まれない。
    ただし、Recyclebinで使用されているエクステントを除く。

    (RECYCLEBINに格納された領域に関してはRECYCLEBINがPurgeされない限り、バックアップセットに含まれる。)
    参照:RMANバックアップ検証2 RECYCLEBIN(ゴミ箱)はバックアップセットに含まれるのか?

    例えば、オブジェクトの再編成などでエクステントを縮小することによりバックアップファイルサイズを小さくすることが出来る。

  2. セグメントのHWM以後の空き領域は、「未使用ブロック」に該当しない。
    (エクステントが割り当てられているブロックは全てが使用されているブロックに該当する。)

    セグメントのHWM以後の空き領域は、バックアップセットに含まれる。

    例えば、テーブルをTRUNCATE REUSE STORAGE にて HWMを下げても、バックアップサイズは小さくならない。
    (TRUNCATE DROP STORAGE にて HWMを下げた場合は、バックアップサイズを小さくすることが出来る。)

■検証内容

▼ 以下の2つのパターンを検証

A) TRUNCATE TABLE DROP STORAGE (表からすべての行を削除しデータセグメント領域を解放)

` 10万件のランダムな大量の文字列をINSERTした状態で(dba_free_spaceを検索)
バックアップを取得し、バックアップファイルサイズを取得

` その10万件の表に対してTRUNCATE TABLE DROP STORAGE (dba_free_spaceを検索)
そしてバックアップを取得し、バックアップファイルサイズの違いを比較

B) TRUNCATE TABLE REUSE STORAGE (表からすべての行を削除してHWMを下げるがエクステントを解放しない)

` 10万件のランダムな大量の文字列をINSERTした状態で、(dba_free_spaceを検索)
バックアップを取得し、バックアップファイルサイズを取得

` その10万件の表に対してTRUNCATE TABLE REUSE STORAGE (dba_free_spaceを検索)
そしてバックアップを取得し、バックアップファイルサイズの違いを比較

▼ 結果として、

A) TRUNCATE TABLE DROP STORAGE では、 dba_free_space の空きは増え、バックアップサイズも小さくなった。

` 表領域内の使用可能エクステントは、バックアップセットには含まれないことが分かった。

B) TRUNCATE TABLE REUSE STORAGE では、 dba_free_space の空きは変わらず、バックアップサイズも変わらなかった。

` セグメントのHWM以後の空き領域は、バックアップセットには含まれることが分かった。

■検証結果

▼A) DROP STORAGE

表領域作成


  conn / as sysdba
  drop tablespace test including contents and datafiles;
  create tablespace test datafile 'test.DBF' size 300M;

ユーザ作成

  drop user userA cascade;
  create user userA identified by userA default tablespace test;
  grant dba to userA;

テーブル作成と10万件挿入


  conn userA/userA
  create table tab1(c1 varchar2(1000));
  insert into tab1 select DBMS_RANDOM.STRING('A',1000) from dual connect by rownum <= 6250;
  insert into tab1 select * from tab1;
  insert into tab1 select * from tab1;
  insert into tab1 select * from tab1;
  insert into tab1 select * from tab1;
  commit;

  SQL> select count(*) from tab1;

    COUNT(*)
  ----------
      100000

dba_free_spaceの確認


   SQL> select * from dba_free_space where tablespace_name = 'TEST' order by block_id;

   TABLESPACE_NAME                   FILE_ID   BLOCK_ID      BYTES     BLOCKS RELATIVE_FNO
   ------------------------------ ---------- ---------- ---------- ---------- ------------
   TEST                                    5      15488  187695104      22912            5

バックアップ実行


  rman target /
  backup tablespace "TEST";

バックアップファイルのサイズ確認


   $ ll
   -rw-r----- 1 oracle oinstall 120815616  6月 12 19:28 2019 o1_mf_nnndf_TAG20190612K192807_fskqkw85_.bkp

TRUNCATE TABLE (★ DROP STORAGE )


  sqlplus userA/userA
  TRUNCATE TABLE tab1 DROP STORAGE;

dba_free_spaceの確認


   SQL> select * from dba_free_space where tablespace_name = 'TEST' order by block_id;

   TABLESPACE_NAME                   FILE_ID   BLOCK_ID      BYTES     BLOCKS RELATIVE_FNO
   ------------------------------ ---------- ---------- ---------- ---------- ------------
   TEST                                    5        136  313458688      38264            5  
                                                                   ※空きが増えている

バックアップ実行(2回目)


  rman target /
  backup tablespace "TEST";

バックアップファイルのサイズ確認


   $ ll 
   -rw-r----- 1 oracle oinstall 120815616  6月 12 19:28 2019 o1_mf_nnndf_TAG20190612K192807_fskqkw85_.bkp
   -rw-r----- 1 oracle oinstall   1613824  6月 12 19:30 2019 o1_mf_nnndf_TAG20190612K193057_fskqq1dq_.bkp
                                  ~~~~~~~~~※バックアップサイズが減っている

▼B) REUSE STORAGE

表領域作成


  conn / as sysdba
  drop tablespace test including contents and datafiles;
  create tablespace test datafile 'test.DBF' size 300M;

ユーザ作成


  drop user userA cascade;
  create user userA identified by userA default tablespace test;
  grant dba to userA;

テーブル作成と10万件挿入


  conn userA/userA
  create table tab1(c1 varchar2(1000));
  insert into tab1 select DBMS_RANDOM.STRING('A',1000) from dual connect by rownum <= 6250;
  insert into tab1 select * from tab1;
  insert into tab1 select * from tab1;
  insert into tab1 select * from tab1;
  insert into tab1 select * from tab1;
  commit;

  SQL> select count(*) from tab1;

    COUNT(*)
  ----------
      100000

dba_free_spaceの確認


   SQL> select * from dba_free_space where tablespace_name = 'TEST' order by block_id;

   TABLESPACE_NAME                   FILE_ID   BLOCK_ID      BYTES     BLOCKS RELATIVE_FNO
   ------------------------------ ---------- ---------- ---------- ---------- ------------
   TEST                                    5      15488  187695104      22912            5

バックアップ実行


  rman target /
  backup tablespace "TEST";

バックアップファイルのサイズ確認


   $ ll 
   -rw-r----- 1 oracle oinstall 120668160  6月 12 19:22 2019 o1_mf_nnndf_TAG20190612T192208_fskt6jtb_.bkp

TRUNCATE TABLE ( ★ REUSE STORAGE )


  sqlplus userA/userA
  TRUNCATE TABLE tab1 REUSE STORAGE;

dba_free_spaceの確認


   SQL> select * from dba_free_space where tablespace_name = 'TEST' order by block_id;

   TABLESPACE_NAME                   FILE_ID   BLOCK_ID      BYTES     BLOCKS RELATIVE_FNO
   ------------------------------ ---------- ---------- ---------- ---------- ------------
   TEST                                    5      15488  187695104      22912            5  
                                                       ※値は変わっていない。

バックアップ実行(2回目)


  rman target /
  backup tablespace "TEST";

バックアップファイルのサイズ確認


   $ ll
   -rw-r----- 1 oracle oinstall 120668160  6月 12 19:22 2019 o1_mf_nnndf_TAG20190612T192208_fskt6jtb_.bkp
   -rw-r----- 1 oracle oinstall 120668160  6月 12 19:23 2019 o1_mf_nnndf_TAG20190612T192319_fskt8qd7_.bkp
                                ~~~~~~~~~※バックアップサイズも変わっていない。

■まとめ

  • オブジェクトの再編成などでエクステントを縮小することによりバックアップファイルサイズを小さくすることが出来る。

  • HWMを下げてもオブジェクトのサイズが変わらなければバックアップサイズは小さくならない。

  • deleteコマンドで行を削除してブロック内の空き領域を増やしてもバックアップサイズは小さくならない。

■関連リンク

RMANバックアップ検証2 RECYCLEBIN(ゴミ箱)はバックアップセットに含まれるのか?

以上

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0