Documente Academic
Documente Profesional
Documente Cultură
ODBA (06/08)
As an extra precaution, a utility such as Export may be used to backup the database objects, but it does NOT take a copy of the parameter file, control file or the redo log file.
ODBA (06/08)
What to Backup?
The physical files to be backed up include, the parameter file, the password file, the control files, the data files and the redo log files.
ODBA (06/08)
ODBA (06/08)
ODBA (06/08)
Exercise
1. If one does not exist, create an ordinary user such as trn1 with connect and resource privileges. 2. Log in as the user and run the file createord.sql in order to create several user tables that may be backed up. 3. Compile a list of all the relevant files that need to be backed up for the instance. 4. Shut down the instance and create a new backup directory called backup1. 5. Copy the parameter file, SPFILE ( if in use ) and the password file to the backup directory. 6. Back up the control files, data files and log files to the backup directory using an operating system backup utility. Under Windows, copy the files or use a utility such as Winzip. Under UNIX, use the tar or cpio utility to copy the files. 7. Restart the instance and start an SQL*Plus session to ensure that the database has started correctly.
ODBA (06/08)
Types of Failure
There are many types of failure which may occur. Some require DBA intervention and some do not. The failure will be one of the following types: user process failure instance failure user error statement failure media failure other failure The procedure used to recover from the failure will depend on the type of failure.
ODBA (06/08)
ODBA (06/08)
Instance Failure
To recover from this type of failure restart the instance with the startup command. Common causes are: a power cut occurred a hardware problem, such as CPU failure or memory corruption a software problem, such as an operating system crash a failure of one of the Oracle background processes Such an error can be simulated by terminating one of the Oracle background processes or by doing a shutdown abort. The Oracle background process SMON performs instance recovery and rolls forward any committed changes in the redo log that have not yet been written to the database. Transactions that have not been committed are rolled back and any resources and locks that were held by the process are released. Investigate the cause of the failure by finding and examining the alert log file called orclalrt.log in the directory bdump.
Exercise
1. Connect as a normal user and update the Product table to set all selling prices to 100.00. 2. Simulate an Instance Failure by terminating the Oracle background process or doing a shutdown abort. 3. Restart the Oracle service and the instance will restart and perform recovery. 4. Connect in SQL*Plus and select from the Product table to confirm that the update to selling prices has been lost because the change was not committed. 5. Examine the alert log file to see any messages related to the instance recovery.
ODBA (06/08)
User Error
Action is usually required to recover from this type of failure. Common causes are that the user: deleted all the rows in a table dropped or truncated a table committed data changes in error Such an error can be easily simulated in an SQL*Plus session. Resolution of the error involves one of the following: recover the corrupt table from an Export backup recover the whole database from a valid backup
Exercise
1. Simulate a User Error as a normal user by deleting all the rows in a table, for example the Saleline table, and committing the changes. 2. Shut down the instance. 3. Recover the table by restoring all control, data and log files from the last offline backup. 4. Restart the instance and then start an SQL*Plus session to ensure that the deleted rows have been restored.
ODBA (06/08)
10
Statement Failure
This type of failure may or may not require actions to perform recovery. Common causes are: a logical error in an application entering invalid data, for example a duplicate key in an index attempting an operation with insufficient privilege creating a table and exceeding allotted quota limits an insert or update found insufficient free space in a table space Again, such an error can be easily simulated in an SQL*Plus session. Resolution of the error involves one of the following: fix the application error modify and re-issue the SQL statement provide sufficient privileges change the quota limits for the user increase the size of the table space Oracle or the operating system will return an error code and a message. The process is automatically rolled back and control is returned to the user.
ODBA (06/08)
11
Media Failure
Action is always required to recover from this type of failure, usually caused by a physical problem when reading from or writing to a file on disc. Common causes are: a head crash on a disc drive a physical problem with the file a file was accidentally deleted Such an error can be simulated by deleting a file or files. Resolution of the error normally involves restoring the complete database from a backup.
Exercise
1. Shut down the database. 2. Simulate a Media Failure by deleting ONE of the Control files. 3. Confirm the failure by trying to restart the instance. 4. Recover JUST the missing control file using the operating system backup. 5. Attempt to restart the instance. This will fail as the control file and data files are not now synchronised. 6. In this case, the database can be recovered by re-creating the missing control file from the DUPLEX copy. 7. Attempt to restart the instance. This will succeed.
ODBA (06/08)
12
Exercise
1. Shut down the database. 2. Simulate another Media Failure by renaming one of the data files in Windows Explorer. 3. Start up the database. This will fail as the renamed data file is missing. The database will be left in MOUNT mode. 4. Use the ALTER statement to RENAME the old data file to the new name. 5. Confirm the recovery by making the instance available to users.
ODBA (06/08)
13
Exercise
1. Shut down the database. 2. Simulate a Media Failure by deleting the data files for the users tablespace. 3. Confirm the failure by trying to restart the instance. 4. Recover JUST the missing data file using the operating system backup. 5. Attempt to restart the instance. This will fail as the control file and data files are not now synchronised. 6. Recover from the failure by restoring all control, data and log files from the last offline backup. 7. Attempt to restart the instance. This will succeed.
ODBA (06/08)
14
Other Failure
Action is always required to recover from this type of failure, usually caused by a problem with the Parameter file or with resources being offline. Common causes are: Parameter file errors rollback segments offline table space offline Such an error can be simulated by editing the parameter file or by putting one or more rollback segments or table spaces offline. Resolution of the error involves correcting the parameter file or putting the offending rollback segments or table spaces online.
ODBA (06/08)
15
Exercise
1. In the SQL*Plus session as user system, take on online backup of the Control file. It is vital that a copy of the control file is available in the event of a failure. As a precaution, multiple copies of the control file should be maintained by naming them in the parameter file. A trace file, which may be used to recreate the control file if a backup is not available, may be generated as follows: ALTER DATABASE BACKUP CONTROLFILE TO TRACE; The file is created in the directory udump which is pointed to by the parameter USER_DUMP_DEST. In SQL*Plus, this can be displayed as: SHOW PARAMETER user_dump_dest
Exercise
1. In the SQL*Plus session as user system, create a trace file which may be used to recreate the Control file. 2. View the trace file using an application such as Notepad.
ODBA (06/08)
16
Exercise
1. Shut down the database and then delete all of the control files. 2. Now confirm the failure by trying to restart the database. 3. When the startup fails, examine the alert log file, orclalrt.log, in the directory bdump. 4. Shut the database down with the abort option. 5. Now, copy the trace file to a new file, createcontrol.sql, in your SQL directory. 6. Edit this new file and remove all the lines not required. 7. In SQL*Plus as sys, run the control script file as follows: @createcontrol 8. Now login to the database and check that it is open OK.
ODBA (06/08)
17
ODBA (06/08)
18
ODBA (06/08)
19
Exercise
1. Start an SQL*Plus session and connect as sys as sysdba. 2. Check that the Archive status of the database is disabled. The following statement will also check the status in an using SQL: SELECT FROM log_mode v$database;
ODBA (06/08)
20
Exercise
1. Perform a normal shutdown of the database. 2. Start up the database in MOUNT mode: STARTUP MOUNT 3. Alter the database to run in ARCHIVE log mode: ALTER DATABASE ARCHIVELOG; 4. Alter the database to OPEN mode: ALTER DATABASE OPEN; 5. Check the Archive status of the database: ARCHIVE LOG LIST
ODBA (06/08)
21
ODBA (06/08)
22
Exercise
1. Compile a list of all the relevant files that need to be backed up for the instance. 2. Create a trace file which may be used to recreate the Control file. 3. Shut down the instance and create a new backup directory under ORACLE called backup3. 4. Copy the parameter file, SPFILE and the password file to the backup directory. 5. Back up the control files, data files and log files to the backup directory using an operating system backup utility. 6. Restart the instance.
ODBA (06/08)
23
Exercise
1. In SQL*Plus as user system, switch the log files twice and note the change in sequence number. ALTER SYSTEM SWITCH LOGFILE; ALTER SYSTEM SWITCH LOGFILE; ARCHIVE LOG LIST 2. Use a utility such as Windows Explorer to check for the new archive files in the archive directory.
ODBA (06/08)
24
ODBA (06/08)
25
Exercise
1. In the SQL*Plus session as system/oracle, identify the files used by the tablespace for users by running showdb.sql. 2. Inform Oracle that the tablespace for users is about to be backed up online: ALTER TABLESPACE users BEGIN BACKUP; 3. Now check the list of tablespaces in ACTIVE mode. 4. Backup ALL the files used by the tablespace into a new directory, backupHot. 5. Inform Oracle that the backup is complete: ALTER TABLESPACE users END BACKUP;
ODBA (06/08)
26
Media Failure
Action is always required to recover from this type of failure, usually caused by a physical problem when reading from or writing to a file on disc. Common causes are: a head crash on a disc drive a physical problem with the file a file was accidentally deleted Such an error can be simulated by corrupting or deleting a file or files. Resolution of the error involves restoring ALL data files for the tablespaces to be recovered and running the Recover command.
ODBA (06/08)
27
This is known as tablespace or COMPLETE recovery. Note the following: The database will, by default, be recovered to the PRESENT time as defined in the current Control file. The Control file holds the sequence number of the CURRENT redo log file Each database file header holds the sequence number of the EARLIEST redo log file to be applied to the restored data file When a data file is restored from a backup, the sequence number will not coincide with the current sequence number and Oracle will DETECT that recovery is required Log files from the earliest to the current will be APPLIED as required to each data file ALWAYS restore JUST the data files for the tablespaces to be recovered, whether from the latest online or offline backup, since the other data files are OK ALWAYS use the current Control file and redo log files The file showlogs.sql can be used to examine the log file sequence number and the archive status of the redo log files. The status of the data files can be examined by running the file showfiles.sql.
ODBA (06/08)
28
The sequence of actions to complete the recovery is as follows. Shutdown the corrupt database as follows in SQL*Plus: SHUTDOWN ABORT Restore ALL data files for the tablespaces from the most recent online or offline backup, but DO NOT restore the control file or any redo log files. Startup the database in mount mode as follows in SQL*Plus: STARTUP MOUNT Recover the data files with the command: RECOVER DATABASE; When the data files are recovered the database will use the current and the archived log files to apply changes to the restored data files. The user will be prompted for the archived log files, unless the following option is set: SET AUTORECOVERY ON When COMPLETE recovery has finished, open the database for the users: ALTER DATABASE OPEN;
ODBA (06/08)
29
Exercise
1. Ensure that you do have a recent COMPLETE offline backup and an ONLINE backup of the tablespace users. 2. Start a session as a normal user. 3. Make changes to the tablespace for users by DELETing all rows in the Saleline table with an ordid greater that 104. DELETE WHERE FROM saleline ordid > 104;
Confirm the changes with a SELECT statement and COMMIT the changes. 4. In SQL*Plus, SWITCH the log files TWICE and note the change in sequence number. ALTER SYSTEM SWITCH LOGFILE; 5. Change the tablespace for users by UPDATing the selling price of all rows with a prdid starting with M in the Product table by 100.00. UPDATE SET WHERE product sell = 100 prdid LIKE M%;
Confirm the changes with a SELECT statement and then COMMIT the changes. 6. Again SWITCH the log files TWICE and note the change in sequence number. ALTER SYSTEM SWITCH LOGFILE; There are now at least 2 archived log files and these will be used during recovery. 7. Shutdown the database as normal and then simulate a Media Failure by deleting the data file used by the tablespace for users. At this point in a live situation it is advisable to take a complete backup of all the database files.
ODBA (06/08)
30
8. If an attempt is now made to start the database as normal it will fail and the database will be left in MOUNT mode. 9. Examine the error message in the relevant trace file in ORACLE/admin/bdump. 10.Restore ALL of the data files for TABLESPACE for users from the latest online backup. These files do not contain the changes made to Saleline and Product. 11.Recover from the failure and If prompted for a log file name, press return: RECOVER DATABASE; 12.Open the database to make it available to users: ALTER DATABASE OPEN; Note that at this point in a live situation it is advisable to take another complete backup of all database files before making the database available to users. 13.Check that the changes made to the Saleline and Product tables are now back in place.
ODBA (06/08)
31
User Error
Action is usually required to recover from this type of failure. Common causes are that the user: deleted all the rows in a table dropped or truncated a table committed data changes in error Such an error can be easily simulated in an SQL*Plus session.
ODBA (06/08)
32
Resolution of the error involves restoring ALL data files and running the Recover command until a certain condition is true. This is known as partial or INCOMPLETE recovery. The steps are similar to those for recovery from a Media Failure but resolution of the error involves restoring ALL data files and running the Recover command. Note the following: The database will be recovered until one of the following is true: the user cancels the recovery a particular system change number is reached a particular point in time is reached The Control file holds the sequence number of the CURRENT redo log file Each database file header holds the sequence number of the EARLIEST redo log file to be applied to the restored data file When a data file is restored from a backup, the sequence number will not coincide with the current sequence number and Oracle will DETECT that recovery is required Log files from the earliest to the current will be APPLIED as required to each data file ALWAYS restore ALL data files from the latest backup, since all the files will need recovery ALWAYS use the current Control file and redo log files
ODBA (06/08)
33
The sequence of actions to complete the recovery is as follows. Shutdown the database as follows in SQL*Plus: SHUTDOWN Restore ALL data files from the most recent backup. Startup the database in mount mode as follows in SQL*Plus: STARTUP MOUNT Recover the data files until the condition is true. For example, to recover to a particular point in time, use the command: RECOVER DATABASE UNTIL TIME YYYY-MM-DD:HH:MI:SS; When the data files are recovered the database will use the restored and the archived log files to apply changes to the restored data files. The archived log files, if needed, will be prompted for interactively. When INCOMPLETE recovery has finished, the database may NOT be opened with: ALTER DATABASE OPEN; The database MUST be opened and the log file number reset to 1 with the following command: ALTER DATABASE OPEN RESETLOGS; The Oracle instance should now be shut down and all files backed up offline using the chosen operating system backup utility. Once the backup is complete, the ORACLE instance may be restarted.
ODBA (06/08)
34
Exercise
1. Start a session as a normal user. If using SQL*Plus, enter the command: SET TIME ON 2. Make changes to the tablespace for users by UPDATing the column dateord in the Saleord table to todays date for order numbers 101 and 102. UPDATE SET WHERE saleord dateord = SYSDATE ordid IN (101,102);
Confirm the changes with a SELECT statement and COMMIT the changes. 3. SWITCH the log files TWICE and note the change in sequence number: ALTER SYSTEM SWITCH LOGFILE; 4. Make a written note of the time using the prompt or the SQL statement: SELECT TO_CHAR(sysdate, 'HH24:MI:SS') FROM dual; 5. Make changes to the tablespace for users by UPDATing the cost price of all rows in the Product table to 150.00. UPDATE SET product cost = 150;
Confirm the changes with a SELECT statement and then COMMIT the changes. 6. The User Error is simulated by a wish to KEEP the changes to the Saleord table above but UNDO the changes just made to the Product table. 7. Shutdown the database. At this point in a live situation it is advisable to take a complete backup of all database files.
ODBA (06/08)
35
8. Restore ALL OF THE DATA files but NOT the control or log files from the offline or online backup. These files do not contain the changes made to Saleord and Product. 9. In an SQL*Plus session, start the database in MOUNT mode: STARTUP MOUNT 10.Recover from the failure by using the UNTIL parameter of the system time noted AFTER the change to the Saleord table but BEFORE the changes to the Product table: RECOVER DATABASE UNTIL TIME YYYY-MM-DD:HH:MI:SS; 11.Open the database and RESET the log files. Confirm that the log file sequence number has been reset to 1: ALTER DATABASE OPEN RESETLOGS; ARCHIVE LOG LIST At this point in a live situation it is advisable to take another complete offline backup of the database. 12.Check that the changes made to the Saleord table but NOT the Product table are back in place.
ODBA (06/08)
36