Amount of Redo Generated During a User-Managed Backup

Categories: Oracle Database · Backup and recovery

Translated from Portuguese. Read the original

Let’s briefly talk about the amount of redo data generated during a user-managed backup, or as it’s popularly called, begin backup and end backup. RMAN is the most recommended tool for backup and recovery of an Oracle database, but we know that this doesn’t always happen, and many DBAs around the world still prefer to take their backups with the manual method. Of course there are scenarios where we can take a storage snapshot of the disks/filesystems where the database is stored, and that is usually much faster, but that’s a different discussion. RMAN has been in Oracle since version 8, and saying you don’t know the tool is no longer an excuse.

My goal with this article is to present a piece of information that is unknown to many. When we take a backup using the user-managed backup method, we generate much more redo data than necessary. The official Oracle documentation says that when the database or the tablespace is put in backup mode (begin backup), the first DML on a block takes the whole block into the redo log buffer, and not just the changes made.

Redo Data

Here’s what the documentation says:

In backup mode, the database copies whole changed data blocks into the redo stream.

Let’s simulate the scenario, then.

First I’ll create a table for us to test with:

SQL> create table teste tablespace users as select * from dba_objects;

Table created.

Now let’s enable autotrace in our session to see the statistics generated by each operation, and run an update:

SQL> set autotrace traceonly statistics
SQL> update teste set object_name='tablelore' where object_id=1000;

1 row updated.

Statistics
----------------------------------------------------------
	  9  recursive calls
	  3  db block gets
       1610  consistent gets
       1529  physical reads
	  0  redo size
	865  bytes sent via SQL*Net to client
	870  bytes received via SQL*Net from client
	  3  SQL*Net roundtrips to/from client
	  1  sorts (memory)
	  0  sorts (disk)
	  1  rows processed

As we can see above, no redo was generated. I’ll run a new update on object_id 1001:

SQL> update teste set object_name='tablelore' where object_id=1001;

1 row updated.

Statistics
----------------------------------------------------------
	  5  recursive calls
	  1  db block gets
       1603  consistent gets
	  0  physical reads
	  0  redo size
	865  bytes sent via SQL*Net to client
	870  bytes received via SQL*Net from client
	  3  SQL*Net roundtrips to/from client
	  1  sorts (memory)
	  0  sorts (disk)
	  1  rows processed

Again no redo was generated, but the physical reads dropped to zero, which means we’re talking about the same data block, which was now already in cache. Let’s move on…

I’ll disable autotrace and put the USERS tablespace in backup mode:

SQL> set autotrace off
SQL> alter tablespace users begin backup;

Tablespace altered.

I’ll enable autotrace again and re-run the updates with different values just to show that we really are changing data:

SQL> set autotrace traceonly statistics
SQL> update teste set object_name='loredatatable' where object_id=1000;

1 row updated.

Statistics
----------------------------------------------------------
	  4  recursive calls
	  2  db block gets
       1603  consistent gets
	  0  physical reads
       8740  redo size
	865  bytes sent via SQL*Net to client
	874  bytes received via SQL*Net from client
	  3  SQL*Net roundtrips to/from client
	  1  sorts (memory)
	  0  sorts (disk)
	  1  rows processed

Now we’re talking, this time a pretty large amount of redo was generated. Why do I say it’s large? Because the whole block was copied to the redo log buffer. Let’s run an update on the same block and see what happens:

SQL> update teste set object_name='tablelore' where object_id=1001;

1 row updated.

Statistics
----------------------------------------------------------
	  0  recursive calls
	  1  db block gets
       1534  consistent gets
	  0  physical reads
	388  redo size
	866  bytes sent via SQL*Net to client
	870  bytes received via SQL*Net from client
	  3  SQL*Net roundtrips to/from client
	  1  sorts (memory)
	  0  sorts (disk)
	  1  rows processed

See that? The value is low this time because the block was already copied to the redo log buffer, so Oracle only writes the changes (change vectors).
Let’s do the same thing but for another data block; I’ll now update object_id=35000:

SQL> update teste set object_name='tablelore' where object_id=35000;

1 row updated.

Statistics
----------------------------------------------------------
	  5  recursive calls
	  1  db block gets
       1603  consistent gets
	  0  physical reads
       8580  redo size
	866  bytes sent via SQL*Net to client
	871  bytes received via SQL*Net from client
	  3  SQL*Net roundtrips to/from client
	  1  sorts (memory)
	  0  sorts (disk)
	  1  rows processed

Once again, a good amount of redo.
To finish, let’s update object_id 35001 and confirm that only the changes will be written to the log buffer:

SQL> update teste set object_name='tablelore' where object_id=35001;

1 row updated.

Statistics
----------------------------------------------------------
	  5  recursive calls
	  1  db block gets
       1603  consistent gets
	  0  physical reads
	336  redo size
	866  bytes sent via SQL*Net to client
	871  bytes received via SQL*Net from client
	  3  SQL*Net roundtrips to/from client
	  1  sorts (memory)
	  0  sorts (disk)
	  1  rows processed

SQL> rollback;

Rollback complete.

SQL> alter tablespace users end backup;

Tablespace altered.

Interesting, right? You can run the same test and you’ll reach the same conclusion.
This was a very short article, but an interesting one about how the Oracle database works.

Regards, and see you next time,

Franky

Earlier comments

  1. Marco Peres

    Muito bom o artigo, Franky, esclarecedor.

    1. Franky Weber Faust

      Obrigado Marco.

Comments