Beginbackup
Upcoming SlideShare
Loading in...5
×
 

Beginbackup

on

  • 235 views

oracle foreign key primary key constraints performance tuning MTS IOT 9i block size backup rman corrupted column drop rename recovery controlfile backup clone architecture database archives export ...

oracle foreign key primary key constraints performance tuning MTS IOT 9i block size backup rman corrupted column drop rename recovery controlfile backup clone architecture database archives export dump dmp duplicate rows extents segments fragmentation hot cold blobs migration tablespace locally managed redo undo new features rollback ora-1555 shrink free space user password link TNS tnsnames.ora listener java shutdown sequence

Statistics

Views

Total Views
235
Views on SlideShare
235
Embed Views
0

Actions

Likes
0
Downloads
5
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Beginbackup Beginbackup Document Transcript

  • What does the "Begin Backup" command do? Backup and Recovery TipsWhat exactly does the "begin backup" command do?The command alter tablespace blah begin backup does two key things.First, it effectively locks the SCN stored in the header of the Data Files associated withthat tablespace. Second, it starts the generation of block-level redo for every transaction.Locking the SCNHow it actually achieves this is simple: first, a checkpoint is issued against the tablespaceso that any blocks in the Buffer Cache that come from that tablespace are flushed to disk,and the CKPT process updates the SCN in the headers of that tablespaces Data Files.Second, once the tablespace checkpoint is completed, a bit is set in the Control File toprevent CKPT from making any future updates to the headers of that tablespaces DataFiles. We can see this happening in the following short demo:SQL> SELECT T.NAME, H.FILE#, H.CHECKPOINT_CHANGE# 2 FROM V$TABLESPACE T, V$DATAFILE_HEADER H 3 WHERE T.TS#=H.TS#;NAME FILE# CHECKPOINT_CHANGE#------------------------------ ---------- ------------------SYSTEM 1 121923UNDOTBS 2 121923INDX 3 121923TOOLS 4 121923USERS 5 121923Note at this point how all tablespaces have the same checkpoint change number in theirheaders (as selected from v$datafile_header).SQL>ALTER TABLESPACE USERS BEGIN BACKUP;SQL> SELECT T.NAME, H.FILE#, H.CHECKPOINT_CHANGE# 2 FROM V$TABLESPACE T, V$DATAFILE_HEADER H 3 WHERE T.TS#=H.TS#;NAME FILE# CHECKPOINT_CHANGE#------------------------------ ---------- ------------------SYSTEM 1 121923UNDOTBS 2 121923INDX 3 121923TOOLS 4 121923USERS 5 121925Now notice that by putting just one tablespace into hot backup mode, that tablespacescheckpoint number has advanced, but the others remain at the same checkpoint changenumber as previously. Only the affected tablespace has been checkpointed, therefore.Copyright © Howard Rogers 2001 24/10/2001 Page 1 of 7
  • What does the "Begin Backup" command do? Backup and Recovery TipsNow well do some transactional activity on the database:INSERT INTO SCOTT.EMP VALUES (1,SMITH,500);INSERT INTO SCOTT.EMP VALUES (2,MOZART,1500);INSERT INTO SCOTT.EMP VALUES (3,BEETHOVEN,700);.AND SO ON AND ON..COMMIT;COMMIT COMPLETE.Ive abbreviated this for simplicitys sake, but the point is that weve been doing someinsert activity on the database, and thus advancing the databases checkpoint number.SQL> ALTER SYSTEM CHECKPOINT;SYSTEM ALTERED.This command is issued purely for demo purposes: it forces whatever checkpoint numberweve reached to be written to every Data File in the system...SQL> SELECT T.NAME, H.FILE#, H.CHECKPOINT_CHANGE# 2 FROM V$TABLESPACE T, V$DATAFILE_HEADER H 3 WHERE T.TS#=H.TS#;NAME FILE# CHECKPOINT_CHANGE#------------------------------ ---------- ------------------SYSTEM 1 121939UNDOTBS 2 121939INDX 3 121939TOOLS 4 121939USERS 5 121925...except, as we see, for the one tablespace that was put into hot backup mode earlier,which is still stubbornly pretending that its SCN is 121925, and not what the rest of thedatabase actually knows it to be(121939).Its important to realise that the SCN reported in v$datafile_header is a complete lie as faras the actual contents of the tablespace are concerned. By that I mean that whilst theheader reports the SCN to be 121925, the actual contents of the tablespace are actually atSCN 121939 -in this particular demo, thats definitely the case, since all the inserts shownin the text were actually performed to a table contained within the USERS tablespaceitself.The point of course is that if you are performing Operating System hot backups, the O/Swill copy which ever O/S block happen to spin into view under the disk read head at anyone time -and that might not be the files Header Block (in fact, the chances of it everCopyright © Howard Rogers 2001 24/10/2001 Page 2 of 7
  • What does the "Begin Backup" command do? Backup and Recovery Tipsbeing the Header Block are pretty small -in the order of thousands to one against). Thatsa problem for recovery purposes, since to pull off a recovery we need to know, reliably,what the earliest possible contents of our Data File backup might be, and take that as thepoint from which to start applying redo. By simply freezing the SCN in the header, in theway Ive shown here, at the time when the tablespace entered hot backup mode, weguarantee to be able to know this "earliest possible time" from which to start applying redo,and hence ensure a successful recovery.Block-level RedoAn Oracle Block is usually made up of several O/S blocks (an 8K block will usually contain16 O/S blocks, for example, since most file systems seem to use 512-byte O/S blocks).That poses another potential problem for hot O/S backups: we might copy 1 of the O/Sblocks in an Oracle block before a User performs an update, and the other O/S blocks afterthat update.This is a fractured or a "split block": the various components of a single Oracle block dontagree with each other.Fractured blocks are unusable, and we need a way of preventing them from happening -yetwe have no control over the order in which the O/S copies the constituent O/S blocks. Thesolution is to generate more or less a complete image of the Oracle block in the redo logsevery time a piece of DML affects it. That way, although the block contained within thecopied Data File might be fractured, we have a "snapshot" image of the block in the redostream which we can use to patch up the mess.This mechanism certainly works, and will mean that hot backups can be used reliably torecover a database, regardless of how much DML activity is taking place on the database atthe time the backup is taken.But theres a catch: Normally, redo contains before and after images of the actual data weare changing by issuing DML. If we update a persons salary, we store a relatively smallamount of redo describing just that one records changes. But in hot backup mode, thesame update requires us to store a complete image of the entire Oracle block -and suchblocks are several Kilobytes in size.What that means is that to avoid block fracturing, we are reduced to making the rate atwhich we generate redo during a hot backup shoot through the roof.Again, a small demo will indicate the size of the potential problem. For the purposes ofthis demo, be aware that the X$KCCCP table contains a column called CPODR_BNO, whichshows us the Redo block number we are currently writing to. Redo blocks are effectivelyidentical to O/S blocks, so the smallest piece of redo is going to take up an entire O/Sblock -i.e., 512 bytes on most systems.Copyright © Howard Rogers 2001 24/10/2001 Page 3 of 7 View slide
  • What does the "Begin Backup" command do? Backup and Recovery TipsSo, to begin with, we identify where were sitting in the current redo log:SQL> COL CPODR_BNO HEADING BLOCK NUMBERSQL> SELECT P.CPODR_BNO FROM SYS.X$KCCCP P;BLOCK NUMBER---------- 357SQL> INSERT INTO SCOTT.EMP VALUES (8,HARRIS,450);1 ROW CREATED.SQL> COMMIT;COMMIT COMPLETE.SQL> COL CPODR_BNO HEADING BLOCK NUMBERSQL> SELECT P.CPODR_BNO FROM SYS.X$KCCCP P;BLOCK NUMBER---------- 359And we see at this point that a simple insert of a single record has advanced the blockwhere were now writing compared to where we were originally by 2 O/S blocks -or 1K.Now lets re-run the same test, this time in hot backup mode. Well begin by deleting therow just inserted, so that we can insert exactly the same data (and hence exactly thesame amount of data) in the new test:SQL> DELETE FROM SCOTT.EMP WHERE EMPNO=8;1 ROW DELETED.SQL> COMMIT;COMMIT COMPLETE.SQL> COL CPODR_BNO HEADING BLOCK NUMBERSQL> SELECT P.CPODR_BNO FROM SYS.X$KCCCP P;BLOCK NUMBER---------- 363SQL> ALTER TABLESPACE USERS BEGIN BACKUP;TABLESPACE ALTERED.SQL> INSERT INTO SCOTT.EMP VALUES (8,HARRIS,450);1 ROW CREATED.SQL> COMMIT;COMMIT COMPLETE.Copyright © Howard Rogers 2001 24/10/2001 Page 4 of 7 View slide
  • What does the "Begin Backup" command do? Backup and Recovery TipsSQL> COL CPODR_BNO HEADING BLOCK NUMBERSQL> SELECT P.CPODR_BNO FROM SYS.X$KCCCP P;BLOCK NUMBER---------- 376And we see now that the write block has advanced from block 363 to block 376 -thats 13O/S blocks, or around 6.5K.So, in hot backup mode, were generating 6 to 7 times the amount of redo compared towhat would normally be generated for the identical transaction.For the record, on a 4K-Oracle block database, Ive measured deletes also generating about7 times the amount of redo when performed in hot backup mode compared to normal.And Ive measured updates generating an astonishing 30 times the amount of redo.This discrepancy between inserts/deletes (7 times the redo) and updates (30 times) iseasily understandable: one half of the redo entry for a delete or insert usually consists ofthe entire row affected (the before image of a delete is the entire row, as is the afterimage of an insert). But the before and after image of an update is only the field(s)actually affected by the update -and hence is relatively tiny. Yet in hot backup mode, allthree types of DML now must cause an entire Oracle block to be written into the redostream. Updates (which are usually relatively small) are thus going to be proportionatelymuch more affected than inserts or deletes (which are usually comparatively large).(Incidentally, you might wonder, if block-level redo is enabled by issuing the begin backupcommand, why my insert above generated 6.5K-worth of redo, when the database involvedwas using 4K Oracle blocks. Shouldnt the test have shown 4K of redo being generated?The answer is that there is always some additional house-keeping data required wheneverredo is generated, and were dealing with a minimum granularity of 512 bytes, becauseeven 1 byte of redo must use an entire 512 byte O/S block. For the record, a single inserton a 2K Oracle Block system (using Solaris) caused 4K of redo to be generated during hotbackup mode, which again suggests the Oracle block-sized redo itself, plus housekeepingoverhead and O/S-block size rounding issues are all coming into play).Whatever the precise numbers from these simplified tests show us, the implication is clear:switching into hot backup mode is going to flood your redo sub-system with anything from6 or 7, up to 30 or so, times the amount of data its usually having to cope with. Theprecise "inflation rate" will vary from database to database, but the general point shouldbe plain.Hot O/S-based backups therefore need to take this into account, since if redo logs fill up30 times more quickly than they otherwise would do, there is a real risk of them wantingto switch back to the first Online log before that log has been successfully checkpointedCopyright © Howard Rogers 2001 24/10/2001 Page 5 of 7
  • What does the "Begin Backup" command do? Backup and Recovery Tipsand/or archived. That would result in a temporary database-wide hang (i.e., thesuspension of all DML activity for all Users) until ARCH, DBWR and/or CKPT have caught up.This is the main reason to avoid placing all tablespaces into hot backup modesimultaneously, and attempting to back up all Data Files in one pass: one tablespacegenerating 30 times its normal amount of redo might be bearable. For the entire databaseto be doing so is almost certainly going to cause performance problems and temporaryhangs.One final question springs to mind: if you were to perform multiple DMLs affecting the oneblock, do we generate multiple block images in the redo stream, or just one when the finalcommit is issued?The answer appears to be that even when multiple updates are issued by the one session,only one block image is generated, as this simple test shows:SQL> SELECT P.CPODR_BNO FROM SYS.X$KCCCP P;BLOCK NUMBER---------- 433SQL> ALTER TABLESPACE USERS BEGIN BACKUP;TABLESPACE ALTERED.SQL> UPDATE SCOTT.EMP SET SAL=250 WHERE EMPNO=1;1 ROW UPDATED.SQL> SELECT P.CPODR_BNO FROM SYS.X$KCCCP P;BLOCK NUMBER---------- 446Clearly, the 13 O/S block redo entry has been made by doing a single update.SQL> UPDATE SCOTT.EMP SET SAL=250 WHERE EMPNO=2;1 ROW UPDATED.SQL> UPDATE SCOTT.EMP SET SAL=250 WHERE EMPNO=3;2 ROWS UPDATED.SQL> SELECT P.CPODR_BNO FROM SYS.X$KCCCP P;BLOCK NUMBER---------- 447Copyright © Howard Rogers 2001 24/10/2001 Page 6 of 7
  • What does the "Begin Backup" command do? Backup and Recovery TipsNote that three extra rows have been updated, but the amount of redo written has notincreased significantly as a result of the additional updatesSQL> UPDATE SCOTT.EMP SET SAL=250 WHERE EMPNO=5;1 ROW UPDATED.SQL> SELECT P.CPODR_BNO FROM SYS.X$KCCCP P;BLOCK NUMBER---------- 447SQL> COMMIT;COMMIT COMPLETE.SQL> SELECT P.CPODR_BNO FROM SYS.X$KCCCP P;BLOCK NUMBER---------- 449And again, at the end of the entire transaction, the amount of redo written has notincreased dramatically from the point it had reached after the very first update wasgenerated.Now all the above tests were done within the one session, but it remains the case evenwhen two separate sessions start performing transactions that affect different recordshoused within the same Oracle block: the block image is produced in the redo stream whenthe first update takes place, and subsequent updates do not add significantly to theamount of redo generated, regardless of which session is performing them.Copyright © Howard Rogers 2001 24/10/2001 Page 7 of 7