# Oracle RMAN 11g Backup and Recovery- P2

Chia sẻ: Thanh Cong | Ngày: | Loại File: PDF | Số trang:50

0
146
lượt xem
37

## Oracle RMAN 11g Backup and Recovery- P2

Mô tả tài liệu
Download Vui lòng tải xuống để xem tài liệu đầy đủ

Oracle RMAN 11g Backup and Recovery- P2: Oracle, yet another edition of our RMAN backup and recovery book has hit the shelves! Oracle Database 11g has proven to be quite the release to be sure. RMAN has new functionality and whizbang new features that improve an already awesome product. RMAN has certainly evolved over the years, as anyone who started working with it in Oracle version 8 can attest to.

Chủ đề:

Bình luận(0)

Lưu

## Nội dung Text: Oracle RMAN 11g Backup and Recovery- P2

1. 18 Part I: Getting Started with RMAN in Oracle Database 11g ■ Inactive This is an online redo log that isn’t active and has been archived. ■ Unused This is an online redo log that has yet to be used by the Oracle database. The status of an online redo log group can be seen by querying the V$LOG view as seen here: SQL> select group#, status from v$Log; GROUP# STATUS ---------- ---------------- 1 INACTIVE 2 INACTIVE 3 INACTIVE 4 CURRENT Multiplexing Online Redo Logs If you want to have a really bad day, then just try losing your active online redo log. If you do, it’s pretty likely that your database is about to come crashing down and that you will have experienced some data loss. This is because recovery to the point of failure in an Oracle database is dependent on the availability of the online redo log. As you can see, the online redo log makes the database vulnerable to loss of a disk device, mistaken administrative delete commands, or other kinds of errors. To address this concern, you can create mirrors of each online redo log. When you have created more than one copy of an online redo log, the group that log is a member of is called a multiplexed online redo log group. Typically these multiplexed copies are put on different physical devices to provide additional protection for the online redo log groups. For highest availability, we recommend that you separate the members of each online redo log group onto different disk devices, different everything… Here is an example of creating a multiplexed online redo log group: alter database add logfile group 4 ('C:\ORACLE\ORADATA\BETA1\REDO04a.LOG','C:\ORACLE\ORADATA\BETA1\REDO04b.LOG') size 100m reuse; Each member of a multiplexed online redo log group is written to in parallel, and having multiple members in each group rarely causes performance problems. The Log Sequence Number As each online redo log group is written to, that group is assigned a number. This is the log sequence number. The first log sequence number for a new database is always 1. As the online redo log groups are written to, the number will increment by one during each log switch operation. So, the next online redo log being written to will be log sequence 2, and so on. During normal database operations, Oracle will open an available online redo log, write redo to it, and then close it once it has filled the online redo log. Once the online redo log has filled, the LGWR process switches to another online redo log group. At that time, if the database is in ARCHIVELOG mode, LGWR also signals ARCH to wake up and start working. This round-robin style of writing to online redo logs is shown in Figure 1-1. ARCH responds to the call from LGWR by making copies of the online redo log in the locations defined by the Oracle database parameter LOG_ARCHIVE_DEST_n and/or to the defined flash recovery area. Until the ARCH process has successfully completed the creation of at least one archived redo log, then the related online redo log file cannot be reused by Oracle. Depending Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
2. Chapter 1: Oracle Database 11g Backup and Recovery Architecture Tour 19 FIGURE 1-1 Writing to online redo logs on your system configuration, more than one archived redo log may need to be created before the associated online redo log can be reused. As archived redo logs are created, they maintain the log sequence number assigned to the parent online redo log. That log sequence number will remain unique for that database until the database is opened using the resetlogs operation. Once a resetlogs operation is executed, then the log sequence number is reset to 1. One final note about opening the database using the resetlogs command when performing recovery. If you are using Oracle Database 10g and later Oracle provides the ability to restore the database using a backup taken before the point in time that you issued the resetlogs command, when you issue the resetlogs command, Oracle will archive any remaining unarchived online redo logs, before the online redo logs are reset. This provides the ability to restore the database from a backup taken before the issuance of the resetlogs command. Using these backup files, and all the archived redo logs, you can now restore beyond the point of the resetlogs command. The ability to restore past the point of the resetlogs command relieves the DBA from the urgency of performing a backup after a resetlogs-based recovery (though such a backup is still important). This also provides for reduced mean-time-to-recover, as you can open the database to users after the restore, rather than having a requirement to back up the database first. Management of Online Redo Logs The alter database command is used to add or remove online redo logs. In this example, we are adding a new online redo log group to the database. The new logfile group will be group 4, and we define its size as 100m: alter database add logfile group 4 'C:\ORACLE\ORADATA\BETA1\REDO04.LOG' size 100m; Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
3. 20 Part I: Getting Started with RMAN in Oracle Database 11g You can see the resulting logfile group in the V$LOG and V$LOGFILE views: SQL> select group#, sequence#, bytes, members from v$log 2 where group# 4; GROUP# SEQUENCE# BYTES MEMBERS ---------- ---------- ---------- ---------- 4 0 104,857,600 1 SQL> select group#, member from v$logfile 2 where group# 4; GROUP# MEMBER ---------- ------------------------------------------------------------- 4 C:\ORACLE\ORADATA\BETA1\REDO04.LOG In this next example, we remove redo log file group 4 from the database. Note that this does not physically remove the physical files. You will still have to perform this function after removing the log file group. This can be dangerous, so be careful when doing so: alter database drop logfile group 4; NOTE If you are using the FRA or have set the DB_CREATE_ONLINE_LOG_ DEST_n, then Oracle will remove online redo logs for you after you drop them. To resize a logfile group, you will need to drop and then re-create it with the bigger file size. ARCHIVELOG Mode vs. NOARCHIVELOG Mode An Oracle database can run in one of two modes. By default, the database is created in NOARCHIVELOG mode. This mode permits normal database operations, but does not provide the capability to perform point-in-time recovery operations or online backups. If you want to do online (or hot) backups, then run the database in ARCHIVELOG mode. In ARCHIVELOG mode, the database makes copies of all online redo logs via the ARCH process, to one or more archive log destination directories. The use of ARCHIVELOG mode requires some configuration of the database beyond simply putting it in ARCHIVELOG mode. You must also configure the ARCH process and prepare the archived redo log destination directories. Note that once an Oracle database is in ARCHIVELOG mode, that database activity will be suspended once all available online redo logs have been used. The database will remain suspended until those online redo logs have been archived. Thus, incorrect configuration of the database when it is in ARCHIVELOG mode can eventually lead to the database suspending operations because it cannot archive the current online redo logs. This might sound menacing, but really it just boils down to a few basic things: ■ Configure your database properly (we cover configuration of your database for backup and recovery in this book quite well). ■ Make sure you have enough space available. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
4. Chapter 1: Oracle Database 11g Backup and Recovery Architecture Tour 21 ■ Make sure that things are working as you expect them to. For example, if you define a flash recovery area in your ARCHIVELOG mode database, make sure the archived redo logs are being successfully written to that directory. More coverage on the implications of ARCHIVELOG mode, how to implement it (and disable it), and configuration for ARCHIVELOG operations can be found in Chapter 3. Oracle Logical Structures There are several different logical structures within Oracle. These structures include tables, indexes, views, clusters, user-defined objects, and other objects within the database. Schemas own these objects, and if storage is required for the objects, that storage is allocated from a tablespace. It is the ultimate goal of an Oracle backup and recovery strategy to be able to recover these logical structures to a given point in time. Also, it is important to recover the data in these different objects in such a way that the state of the data is consistent to a given point in time. Consider the impact, for example, if you were to recover a table as it looked at 10 A.M., but only recover its associated index as it looked at 9 A.M. The impact of such an inconsistent recovery could be awful. It is this idea of a consistent recovery that really drives Oracle’s backup and recovery mechanism, and RMAN fits nicely into this backup and recovery architectural framework. The Combined Picture Now that we have introduced you to the various components of the Oracle database, let’s quickly put together a couple of narratives that demonstrate how they all work together. First, we look at the overall database startup process, which is followed by a narrative of the basic operational use of the database. Startup and Shutdown of the Database Our DBA, Eliza, has just finished some work on the database, and it’s time to restart it. She starts SQL*Plus and connects as SYS using the SYSDBA account. At the SQL prompt, Eliza issues the startup command to open the database. The following shows an example of the results of this command: SQL> startup ORACLE instance started. Total System Global Area 84700976 bytes Fixed Size 282416 bytes Variable Size 71303168 bytes Database Buffers 12582912 bytes Redo Buffers 532480 bytes Database mounted. Database opened. Recall the different phases that occur after the startup command is issued: instance startup, database mount, and then database open. Let’s look at each of these stages now in a bit more detail. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
5. 22 Part I: Getting Started with RMAN in Oracle Database 11g Instance Startup (startup nomount) The first thing that occurs when starting the database is instance startup. It is here that Oracle parses the database parameter file and makes sure that the instance is not already running by trying to acquire an instance lock. Then, the various database processes (as described in “The Oracle Processes,” earlier in this chapter), such as DBWn and LGWR, are started. Also, Oracle allocates memory needed for the SGA. Once the instance has been started, Oracle reports to the user who has started it that the instance has been started back, and how much memory has been allocated to the SGA. Had Eliza issued the command startup nomount, then Oracle would have stopped the database startup process after the instance was started. She might have started the instance in order to perform certain types of recovery, such as control file re-creation. Mounting the Database (startup mount) The next stage in the startup process is the mount stage. As Oracle passes through the mount stage, it opens the database control file. Having done that successfully, Oracle extracts the database datafile names from the control file in preparation for opening them. Note that Oracle does not actually check for the existence of the datafiles at this point, but only identifies their location from the control file. Having completed this step, Oracle reports back that it has mounted the database. At this point, had Eliza issued the command startup mount, Oracle would have stopped opening the database and waited for further direction. When the Oracle instance is started and the database is mounted but not open, certain types of recovery operations may be performed, including renaming the location of database datafiles and recovery system tablespace datafiles. Opening the Database Eliza issued the startup command, however, so Oracle moves on and tries to open the database. During this stage, Oracle verifies the presence of the database datafiles and opens them. As it opens them, it checks the datafile headers and compares the SCN information contained in those headers with the SCN stored in the control files. Let’s talk about these SCNs for a second. SCNs are Oracle’s method of tracking the state of the database. As changes occur in the database, they are associated with a given SCN. As these changes are flushed to the database datafiles (which occurs during a checkpoint operation), the headers of the datafiles are updated with the current SCN. The current SCN is also recorded in the database control file. When Oracle tries to open a database, it checks the SCNs in each datafile and in the database control file. If the SCNs are the same and the bitmapped flags are set correctly, then the database is considered to be consistent, and the database is opened for use. NOTE Think of SCNs as being like the counter on a VCR. As time goes on, the counter continues to increment, indicating a temporal point in time where the tape currently is. So, if you want to watch a program on the tape, you can simply rewind (or fast forward) the tape to the counter number, and there is the beginning of the program. SCNs are the same way. When Oracle needs to recover a database, it “rewinds” to the SCN it needs to start with and then replays all of the transactions after that SCN until the database is recovered. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
6. Chapter 1: Oracle Database 11g Backup and Recovery Architecture Tour 23 If the SCNs are different, then Oracle automatically performs crash or instance recovery, if possible. Crash or instance recovery occurs if the redo needed to generate a consistent image is in the online redo log files. If crash or instance recovery is not possible, because of a corrupted datafile or because the redo required to recover is not in the online redo logs, then Oracle requests that the DBA perform media recovery. Media recovery involves recovering one or more database datafiles from a backup taken of the database and is a manual process, unlike instance recovery. Assisting in media recovery is where RMAN comes in, as you will see in later chapters. Once the database open process is completed successfully (with no recovery, crash recovery, or media recovery), then the database is open for business. Shutting Down the Database Of course, Eliza will probably want to shut down the database at some point in time. To do so, she could issue the shutdown command. This command closes the database, unmounts it, and then shuts down the instance in almost the reverse order as the startup process already discussed. There are several options to the shutdown command. Note in particular that a shutdown abort of a database is basically like simulating a database crash. This command is used often, and it rarely causes problems. Oracle generally recommends that your database be shut down in a consistent manner, if at all possible. If you must use the shutdown abort command to shut down the database (and in the real world, this does happen frequently because of outage constraints), then you should reopen the database with the startup command (or even better, startup restrict). Following this, do the final shutdown on the database using the shutdown immediate command before performing any offline backup operations. Note that even this method may result in delays shutting down the database because of the time it takes to roll back transactions during the shutdown process. NOTE As long as your backup and recovery strategy is correct, it really doesn’t matter whether the database is in a consistent state (as with a normal shutdown) or an inconsistent state (as with a shutdown abort) when an offline backup occurs. Oracle does recommend that you do cold backups with the database in a consistent state, and we recommend that, too (because the online redo logs will not be getting backed up by RMAN). Finally, note that online backups eliminate this issue completely! Using the Database and Internals In this section, we are going to follow some users performing different transactions in an Oracle database. First, we provide you with a graphical roadmap that puts together all the processes, memory structures, and other components of the database for you. Then, we follow a user as the user makes changes to the database. We then look at commits and how they operate. Finally, we look at database checkpoints and how they work. Process and Database Relationships We have discussed a number of different processes, memory structures, and other objects that make up the Oracle database. Figure 1-2 provides a graphic that might help you better understand the interrelationships between the different components in Oracle. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
7. 24 Part I: Getting Started with RMAN in Oracle Database 11g FIGURE 1-2 A typical Oracle database Changing Data in the Database Now, assume the database is open. Let’s say that Fred needs to add a new record to the DEPT table for the janitorial department. So, Fred might issue a SQL statement like this: INSERT INTO DEPT VALUES (60, 'JANITOR','DALLAS'); The insert statements (as well as update and delete commands) are collectively known as Data Manipulation Language (DML). As a statement is executed, redo is generated and stored in the redo log buffer in the Oracle SGA. Note that redo is generated by this command, regardless of the presence of the commit command. The delete and update commands work generally the same way with respect to redo generation. One of the results of DML is that undo is generated and stored in rollback segments. Undo consists of instructions that allow Oracle to undo (or roll back) the statement being executed. Using undo, Oracle can roll back the database changes and provide read consistent images (also Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
8. Chapter 1: Oracle Database 11g Backup and Recovery Architecture Tour 25 known as read consistency) to other users. Let’s look a bit more at the commit command and read consistency. Committing the Change Having issued the insert command, Fred wants to ensure that this change is committed to the database, so he issues the commit command: COMMIT; The effects of issuing the commit command include the following: ■ The change becomes visible to all users who query the table at a point in time after the commit occurs. If Eliza queries the DEPT table after the commit occurs, then she will see department 60. However, if Eliza had already started a query before the commit, then this query would not see the changes to the table. ■ The change is recoverable if the database is in NOARCHIVELOG mode and if crash or instance recovery is required. ■ The change is recoverable if the database is in ARCHIVELOG mode (assuming a valid backup and recovery strategy) and media recovery is required and if all archived and online redo logs are available. The commit command causes the Oracle LGWR process to flush the online redo log buffer to the online redo logs. Uncommitted redo is flushed to the online redo logs regardless of a commit (in fact, uncommitted changes can be written to the datafiles, too). When a commit is issued, Oracle writes a commit vector to the redo log buffer, and the buffer is flushed to disk before the commit returns. It is this commit vector, and the fact that the commit issued by Fred’s session will not return until his redo has been flushed to the online redo logs successfully, that will ensure that Fred’s changes will be recoverable. The commit Command and Read Consistency Did you notice that Eliza was not able to see Fred’s change until he issued the commit command? This is known as read consistency. Another example of read consistency would be a case where Eliza started a report before Fred committed his change. Assume that Fred committed the change during Eliza’s report. In this case, it would be inconsistent for department 60 to show up in Eliza’s report, since it did not exist at the time that her report started. As Eliza’s report continues to run, Oracle checks the start SCN of the report query against the SCNs of the blocks being read in Oracle to produce the report output. If the time of the report is earlier than the current SCN on the data block, then Oracle goes to the rollback segments and finds undo for that block that will allow Oracle to construct an image consistent with the time that the report started. As Fred continues other work on the database, the LGWR process writes to the online redo logs on a regular basis. At some point in time, an online redo log will fill up, and LGWR will close that log file, open the next log file, and begin writing to it. During this transition period, LGWR also signals the ARCH process to begin copying the log file that it just finished using to the archive log backup directories. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
9. 26 Part I: Getting Started with RMAN in Oracle Database 11g Checkpoints Now, you might be wondering, when does this data actually get written out to the database datafiles? Recall that a checkpoint is an event in which Oracle (through DBWR) writes data out to the datafiles. There are several different kinds of checkpoints. Some of the events that result in a checkpoint are the following: ■ A redo log switch ■ Normal database shutdowns ■ When a tablespace is taken in or out of online backup mode (see “Oracle Physical Backup and Recovery” later in this chapter) Note that ongoing incremental checkpoints occur throughout the lifetime of the database, providing a method for Oracle to decrease the overall time required when performing crash recovery. As the database operates, Oracle is constantly writing out streams of data to the database datafiles. These writes occur in such a way as to not impede performance of the database. Oracle provides certain database parameters to assist in determining how frequently Oracle must process incremental checkpoints. Oracle Backup and Recovery Primer Before you use RMAN, you should understand some general backup and recovery concepts in Oracle. Backups in Oracle come in two general categories, logical and physical. In the following sections, we quickly look at logical backup and recovery and then give Oracle physical backup and recovery a full treatment. Logical Backup and Recovery Oracle Database 11g uses the Oracle Data Pump architecture to support logical backup and recovery. These utilities include the Data Pump Export program (expdp) and the Data Pump Import program (impdp). With logical backups, point-in-time recovery is not possible. RMAN does not do logical backup and recovery, so this topic is beyond the scope of this book. Oracle Physical Backup and Recovery Physical backups are what RMAN is all about. Before we really delve into RMAN in the remaining chapters of this book, let’s first look at what is required to manually do physical backups and recoveries of an Oracle database. While RMAN removes you from much of the work involved in backup and recovery, some of the principles remain the same. Understanding the basics of manual backup and recovery will help you understand what is going on with RMAN and will help us contrast the benefits of RMAN versus previous methods of backing up Oracle. We have already discussed ARCHIVELOG mode and NOARCHIVELOG mode in Oracle. In either mode, Oracle can do an offline backup. Further, if the database is in ARCHIVELOG mode, then Oracle can do offline or online backups. We will cover the specifics of these operations with RMAN in later chapters of this book. Of course, if you back up a database, it would be nice to be able to recover it. Following the sections on online and offline backups, we will discuss the different Oracle recovery options available. Finally, in these sections, we take a very quick, cursory look at Oracle manual backup and recovery. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.