Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Robert Freeman
Oracle OCP Over 20 years experience in IT. Oracle DBA for over 20 years. Master Principal Consultant for Oracle Corp. Presents frequently. Have worked at many large Oracle clients. I have a number of Oracle Books published including OCP: Oracle Database 11g Oracle Certified Professional Exam Preparation Guide.
Agenda
We will discuss the major objectives covered in the Oracle Database 11g OCP Exam (1Z0-053). As a consequence of time and the number of topics covered in the exam we will only cover specific topics in this class. The topics we will cover are those with the most coverage in the exam.
0900 1000 Class 1030 1045 Break 1045 1200 Class 1200 1300 Lunch 1300 1500 Class 1500 1530 Break 1530 1700 Class
http://education.oracle.com
Anyone here for something other than this? Questions before we get started?
User Managed Backup and Recovery RMAN Backup and Recovery Flashback Database Features Diagnosing The Database And Performance Managing Database Resources The Oracle Scheduler
ASM - Architecture
ASM runs in the form of the ASM instance. Each database server has one ASM instance. Each ASM instance can be used by one or more databases on the server. The ASM instance is called +ASM.
ASM - Architecture
ASM stores files in disk groups. Logical entities made up of one or more physical disk drives (LUNS, etc) that are assigned to that disk group.
ASM - Architecture
ASM is designed to store all sorts of database related files including Oracle datafiles Database tempfiles Online redo logs Archived redo logs Control files SPFILES RMAN Backup Sets The flash recovery area (FRA) Datapump dump sets
ASM Views
V$ASM_DISKGROUP V$ASM_DISK
Describes a given disk group. Note that discovery will occur each time query this view. Describes each disk that was discovered by the ASM instance. Discovery will occur each time query this view.
V$ASM_FILE
V$ASM_CLIENT
Displays each database that is using at least one disk group managed by the ASM instance.
ASM Administration
Use the alter diskgroup command to:
Add disks to an ASM disk group Remove disks from an ASM disk group Adding and Dropping disks from an ASM disk group Undrop disks from an ASM disk group Resize disks in a disk group Manually rebalance a disk group Mount and unmount disk groups Check the consistency of a disk group Create ASM disk group directories Manage ASM disk group directories
If the disk group has files in it then you need to use the including contents parameter as seen here:
Drop diskgroup sp_dgroup2 including contents;
ASM Files
ASM files are physical files stored within ASM disk
groups. ASM files can be created in a number of different ways. Example execution of the CREATE TABLESPACE command using an ASM disk group as the datafile location will result will be the creation of ASM files in that ASM disk group. create tablespace another_test datafile +COOKED_DGROUP1 size 100k;
ASM Files
You can set ASM disk groups as default locations.
DB_CREATE_FILE_DEST DB_CREATE_ONLINE_LOG_DEST_n DB_RECOVERY_FILE_DEST CONTROL_FILES LOG_ARCHIVE_DEST_n LOG_ARCHIVE_DEST STANDBY_ARCHIVE_DEST Alter system set db_create_file_dest=+cooked_dgroup1 scope=both;
ASM Files
Example ASM File Name
+sp_dgroup2/mydb/controlfile/Current.56.544956473 {disk group} {DB} {file_type} {file_name}
ASM Files
Other types of ASM file names
ASM Numeric File name ASM Filename Alias
ASM Templates
When you create an ASM disk group, Oracle will assign a default template to that disk group. A template is simply a named collection of attributes. Each attribute is matrixed to a specific file type. IE: Controlfile or datafile. The template used defines the level of striping Fine 128k stripe size Coarse AU Size for disk group is selected.
Rename an alias
Alter diskgroup cooked_dgroup1 Rename alias +cooked_dgroup1/alias_dir/alias_tbs_01.dbf To +cooked_dgroup1/datafiles/alias_tbs_01.dbf;
ASM Templates
,The template also define the amount of mirroring that is used. No mirroring, 2-way mirroring and 3way mirroring are supported. For example, if you create a disk group using the default template and then create datafiles in that disk group, the datafile template will define the redundancy and striping for that data
SQL> select group_number, file_number, type, blocks, bytes from v$asm_file; GROUP_NUMBER FILE_NUMBER TYPE BLOCKS BYTES ------------ ----------- -------------------- ---------- ---------1 256 DATAFILE 14 114688
ASMCMD Commands
ASMCMD commands are much like UNIX commands. Examples:
Command
Cd Du Find Help Ls Mkdir Pwd Rm
Purpose
Change ASM directory Disk Used Find directory or file Display the help screen List files in directory. Create an ASM directory Locate where you are on the ASM directory tree. Remove an ASM directory or file.
Example
cd +group1 Du Find + rob11g Help Ls l Mkdir old Pwd Rm r current*
Or from UNIX:
/opt/oracle>export ORACLE_SID=+ASM /opt/oracle>asmcmd
Describe what redundancy is and how its implemented in ASM. Understand what a failure group is and how they are created. Understand about ASM Fast Disk Resync and about preferred mirror read.
Configure Backup Settings Configure multiple archive log file destinations to increase availability. Identify the need of backup mode. Perform user-managed backups Backup a Control File
Define multiple failure groups for new disk groups and make sure you understand how the number of failure groups is different for two-way and three-way mirroring. Show how disk rebalancing can be controlled or rolled back. Understand the ASM disk group attributes and how they are used.
Identify the steps involved in converting nonASM files to ASM files using RMAN.
Migrate a database to ASM disk groups by shutting down the database, editing the SPFILE, running an RMAN script for each file to be converted, and opening the database with RESETLOGS.
Main Oracle processes related to backup and recovery DBWR LGWR ARCH SMON/PMON CKPT
The Data Dictionary Key role in user managed backups. Different dictionary views V$ DBA/USER/ALL_*
Physical File Structures Related to Backup and Recovery Oracle Datafiles Oracle Tablespaces Online redo logs Control Files Parameter Files
Database Modes Impact the kind of recovery that you can do. NOARCHIVELOG ARCHIVELOG
The Oracle Instance The Oracle Database Backup and Recovery, the big picture
Backup operations while the instance is down and the database is not open. Copy the SPFILE to a PFILE (any mode) Copy the PFILE to a SPFILE (any mode) Manual cold backups. Backup operations while the instance is down and the database is not open. Online backups.
Locate Datafiles Control Files Online redo logs Database Down Recommended Consistent Shutdown Shutdown Shutdown immediate Shutdown transactional
Backup Datafiles Control Files Online redo logs Recommend Control file backups Bring Database Back Up. Startup Control file backups Backup control file Trace file Create controlfile
Online backups Backup the database while its running. Understanding the mechanics of online backups. ARCHIVELOG Mode Archived Redo logs
ARCHIVELOG Mode Configuring Archivelog Destination Directories LOG_ARCHIVE_DEST_n LOG_ARCHIVE_FORMAT Flash Recovery Area (FRA) DB_RECOVERY_FILE_DEST DB_RECOVERY_FILE_DEST_SIZE
User Managed Backup Online Backups ARCHIVELOG Mode Put the database in ARCHIVELOG mode Shutdown consistently Normal Immediate Transactional Startup mount Issue Alter database archivelog command. Issue alter database open command. Test with alter system switch logfile command.
User Managed Backup Executing an Online Backup Steps for manual online backups Put tablespaces in hot backup mode Alter database begin backup Alter tablespace begin backup Backup datafiles Take tablespaces out of hot backup mode Alter database end backup; Alter tablespace end backup; Perform a log switch. Wait for it to complete Backup archived redo logs. Backup control file.
User Managed Backups Exam Cram What do you need to know? Be able to configure a database for user initiated online backups Understand the different parameters that need to be configured when you are going to backup a database with user based online backups. You will need to understand parameters such as LOG_ARCHIVE_DEST_1 and how to configure them. You will need to understand what happens if you have two archivelog destination directories defined.
User Managed Backups Exam Cram What do you need to know? Backup your database with an offline backup Understand the steps that need to be performed with an offline backup and do an offline backup. Understand the difference between an offline backup and an online backup, and how these differences can be used to decide the optimal backup strategy.
10
User Managed Backups Exam Cram What do you need to know? Backup your database with an online backup Know how to configure your database for an online backup. Understand how to put the database in ARCHIVELOG mode so you can do online backups. Do an online backup. Understand how to determine which archived redo logs you will need to backup when doing an online backup. Backup your database control file Understand why it is important to backup your control file. Understand the different method of backing up your control file. Understand what a backup control file is.
Perform User-managed complete database recovery Perform user-managed incomplete database recovery Backup and Recover a Control File Recover from a lost TEMP file Recover from a lost redo log group Recover from the loss of a password file
User Managed Recovery User-Managed Complete Database Recovery in NOARCHIVELOG Mode Only full recovery available on NOARCHIVELOG mode. If the database is not already down shut it down. Replace all database files previously backed up: Datafiles Control Files Online redo logs. Startup the database
User Managed Recovery User-Managed Complete Database Recovery in ARCHIVELOG Mode What is ARCHIVELOG mode? Archived redo logs ARCH process Rules Oracle follows
User Managed Recovery User-Managed Complete Database Recovery in ARCHIVELOG Mode Many recovery options in ARCHIVELOG mode Full All Datafiles Specific Tablespaces (some online) Specific Datafiles (some online) Loss of online redo logs Point-in-time (entire database)
User Managed Recovery User-Managed Complete Database Recovery in ARCHIVELOG Mode Full ARCHIVELOG Mode Database Recovery Shutdown database Restore control file if required Restore all datafiles Recover database Open the database. Assumes online redo logs are intact.
11
Backup the control file alter database backup controlfile to trace; alter database backup controlfile to filename;
Recover from a lost control file Using Trace File Using backup control file
Loss of an inactive archived online redo log. Loss of an inactive, unarchived online redo log. Loss of the active online redo log.
RMAN Backup OCP Objectives Configure channels to use in backing up. Configure backup optimization. Define, apply and use a retention policy Configure and use the Flash Recovery Area Create image file backups Allocate channels to use in backing up. Create a whole database backup Enable fast incremental backup Create duplex backup and back up backup sets. Create an archival backup for long-term retention Create a multi-section compressed and encrypted backup.
Once configured, RMAN is ready to back up. RMAN is a command line driven client. OEM interface into RMAN. Not present in the exam. RMAN always connects as SYSDBA! Examples:
Rman target=/ Rman target=/ catalog=cat_user/robert@catalog
12
RMAN Backup Configuring RMAN RMAN Architecture in brief The RMAN client interface The database server The database control file The optional recovery catalog Database pfile or spfile Backup Media and the Media Management Library (MML) Backup sets and Backup set pieces RMAN Channels Snapshot Control File Flash Recovery Area (FRA)
Persistent configuration settings make RMAN easier to use. Example of setting RMAN persistent configuration settings:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
Parallelism
Configure device type disk parallelism 2;
What do we configure? Backup (database and archivelog) retention criteria None Redundancy (the default) Recovery window
configure retention policy to redundancy 1 ;
RMAN Backup Configuring RMAN Datafile and Archivelog backup copy configuration Known as duplexing Creates multiple copies of backup at the same time.
Configure datafile backup copies for device type disk to 2;
What do we configure? Backup optimization Tells RMAN that you dont want to backup a database file if that backup is not needed. Applies to: Datafiles Archived redo logs Backup Sets
Configure backup optimization on;
13
RMAN Backup RMAN Backups Once configured, RMAN is ready to back up. Terms you need to know: Backup Set Logical At least one per channel. Backup Set Piece Physical One or more per backup set. Multiplexed Multi database datafiles in backup set pieces. One database datafile in only one backup set. Exception Multi-section backups. May be in multiple backup set pieces.
More terms you need to know: Image copies Offline backup Online backup
Offline backups occur with the database mounted. Mount mode allows access to the control file. Control file maintains records related to RMAN. Use the backup command Example:
Backup database;
Online backups occur with the database open. Database in ARCHIVELOG mode To put in ARCHIVELOG mode Configure FRA/Backup locations Shutdown (consistent) Startup mount alter database archivelog alter database open
Online backups occur with the database open. Control file maintains records related to RMAN. Use the backup command Must backup archived redo logs Example:
Backup database plus archivelog delete input;
14
Incremental backups can decrease the overall time that it takes to backup your database. Level 0 backups Full backup. Backup as compressed backupset incremental
Backup level 0 database plus archivelog delete input;
Block change tracking file reduces time required for level 1 backups. To create:
alter database enable block change tracking using file 'c:\oracle\block_change_tracking\orcl_block_change.fil';
Block change tracking file reduces time required for level 1 backups.
RMAN Backup
RMAN Backups Incrementally Updated Backups
RMAN Backup
RMAN Backups Incrementally Updated Backups
A combination of a full image backup of the database and then subsequent level 1 incremental backups of the database which are applied to the image copy backup. The result is a new full backup. No need to restore level 1 backups. Faster restores. Bigger backup images.
Example
RUN { # the recover copy command does not really recover anything. # it simply tells RMAN that the incremental # to be executed should # be applied to the database copy we made above. Recover copy of database with tag Jacob_Jared_Lizzie; Backup incremental level 1 for recover of copy with tag Jacob_Jared_Lizzie Database; }
RMAN Backup
RMAN Backups Multi-Section Backups
RMAN Backup
RMAN Backups Archive log backups
Splits datafiles into separate backup pieces. Allows datafiles to be backed using different channels in parallel. Example backup section size 40m database;
15
RMAN Backup
RMAN Backups Control file and SPFILE autobackups
RMAN Backup
RMAN Backups Control file backups
RMAN can be used to backup control files You can backup the current control file
backup as copy current controlfile; backup as copy current controlfile format c:\oracle\controlfilebackup\contrf_backup.ctl;
Identify situations that require the RMAN recovery catalog. Create and configure a recovery catalog Synchronize the recovery catalog Create and use RMAN stored scripts Back up the recovery catalog Create and use a virtual private catalog
Acts as a single location to store all your RMAN backup related information. Offers global scripting of RMAN operations. Redundant storage of RMAN backup records. Longer term storage of RMAN backup records. Oracle Data Guard requires the use of a recovery catalog.
RMAN Recovery Catalog Create a Recovery Catalog Create RC database or use existing database. Create a tablespace for the RC data. Create a user that will be the RC user. Assign to RC tablespace. Grant RECOVERY_CATALOG_OWNER role. Create the recovery catalog schema
C:>Rman catalog=rcat_user/rcat_user@rcat Recovery Manager: Release 11.1.0.6.0 - Production on Mon Sep 15 23:10:13 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved. connected to recovery catalog database RMAN> create catalog recovery catalog created
Use the register database command to register a database with the RC.
Set oracle_sid=orcl Rman target=sys/Robert catalog=rcat_user/rcat_user@rcat Recovery Manager: Release 11.1.0.6.0 - Production on Mon Sep 15 23:12:51 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved. connected to target database: ORCL (DBID=1190537904, not open) connected to recovery catalog database RMAN> register database; database registered in recovery catalog starting full resync of recovery catalog full resync complete
16
Use the unregister database command to unregister a database with the RC.
Rman target=sys/Robert catalog=rcat_user/rcat_user@rcat Recovery Manager: Release 11.1.0.6.0 - Production on Mon Sep 15 23:13:45 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved. connected to target database: ORCL (DBID=1190537904, not open) connected to recovery catalog database RMAN> unregister database; database name is "ORCL" and DBID is 1190537904 Do you really want to unregister the database (enter YES or NO)? yes database unregistered from the recovery catalog
Sometimes the control file and recovery catalog will get out of synchronization. Backup when the RC is not available for example. Use the resync catalog command to resynchronize the recovery catalog with the control file. Example:
RMAN> resync catalog;
The recovery catalog can store scripts for use by RMAN. Use the create script command to create a script: Use the global keyword if using VPD if you wish the script to be usable across all databases. Example: create global script db_delete_obsolete { delete obsolete;} Use the delete script command to remove a script: delete script db_delete_obsolete { delete obsolete;} Use the replace script command to replace scripts
Replace script db_delete_obsolete { delete noprompt obsolete;}
Use the execute script command to execute scripts Run { execute script db_delete_obsolete; }
The recovery catalog can be backed up using manual backup methods or you can use RMAN. With an RMAN backup, you must make sure the control file gets backed up.
Restrict users of the catalog to seeing specific records. Uses VPD to secure the catalog records. Setup Create the VPC Catalog owner account. This is a unique account for a specific owner. Note this is NOT the main recovery catalog owner account.
sqlplus rcat_user/rcat_user@rcat SQL> create user rcat_001 identified by rcat_001 2 default tablespace rcat_data 3 quota unlimited on rcat_data; User created. SQL> grant recovery_catalog_owner to rcat_001; Grant succeeded.
17
From RMAN, while connected to the VPC Catalog owner account created above, create the VP Catalog using the create virtual catalog command. (like the create catalog command).
rman catalog=rcat_001/rcat_001@rcat RMAN> Create virtual catalog; found eligible base catalog owned by RCAT_USER created virtual catalog against base catalog owned by RCAT_USER
Now, grant access to the recovery catalog objects to the VPC catalog owner:
rman catalog=rcat_user/rcat_user@rcat Recovery Manager: Release 11.1.0.6.0 - Production on Tue Sep 16 20:25:32 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved. connected to recovery catalog database RMAN> grant catalog for database orcl to rcat_001; Grant succeeded.
Note this grant gives the rcat_001 rights to see the ORCL database records.
Perform complete recovery from a critical or non-critical data file loss using RMAN. Perform incomplete recovery using RMAN Recover using incrementally updated backups Switch to image copies for fast recovery. Recover using a backup control file.
RMAN Recovery
Basics of RMAN recovery in NOARCHIVELOG mode.
RMAN Recovery
Basics of RMAN recovery in NOARCHIVELOG mode.
Determine extent of recovery required. Restore SPFILE if required. Restore control file if required. Mount database Restore database Recover database (noredo) Open database
Example
RMAN> RMAN> RMAN> RMAN> RMAN> shutdown abort startup mount restore database; recover database noredo; alter database open;
18
RMAN Recovery
Basics of RMAN recovery in ARCHIVELOG mode.
RMAN Recovery
Basics of RMAN recovery in ARCHIVELOG mode.
Determine extent of recovery required. Restore SPFILE if required. Restore control file if required. If recovering critical files Mount database. Restore critical files (or all files) as required. Recover database Open database (resetlogs as required) If recovering non-critical files (database open) Take datafiles offline. Restore datafiles. Recover datafiles Bring datafiles online.
If recovering non-critical files (database down) Mount database. Take datafiles offline. Restore datafiles. Recover datafiles Bring datafiles online.
RMAN Recovery
Basics of RMAN recovery in ARCHIVELOG mode.
RMAN Recovery
Basics of RMAN recovery in ARCHIVELOG mode.
RMAN Recovery
Incomplete Recovery
RMAN Recovery
Incomplete Recovery
Incomplete recovery allows recovery to a point-intime other than the point-in-time of the failure. Used to recover from user failures. Used to recover from software failures. Used to re-create databases (like test databases). Entire database must be restored to the same point-in-time. Process is similar to a full database restore. Define the time to restore too. Use restore and recover commands.
Different kinds of incomplete based recoveries Time based SCN based Log sequence based
19
RMAN Recovery
Incomplete Recovery
RMAN Recovery
Incomplete Recovery
SCN Based point-in-time recovery What is an SCN? Counter in database Current_SCN in V$DATABASE contains the current SCN value. Example
RMAN> Restore database until SCN 55555; RMAN> Recover database until SCN 55555; RMAN> Alter database open resetlogs;
RMAN Recovery
Incomplete Recovery
RMAN Recovery
Incomplete Recovery
Log sequence number based point-in-time recovery What are log sequence numbers? Track individual redo logs Starts with 1. Reset with resetlogs command. Increments with each log switch. Several views show you the log sequence numbers: v$log Current redo logs v$log_history Archived redo logs
Example
RMAN> Restore database until sequence 55555; RMAN> Recover database until sequence 55555; RMAN> Alter database open resetlogs;
RMAN Recovery
Recovery with Incrementally updated backups.
RMAN Recovery
Fast Recovery with Image Copies
Oracle/RMAN will automatically use the correct backup sets (full, incremental, copies) for the fastest restore possible.
If you use image copies, you can quickly switch to those copies for faster restores. Still have to apply incrementals and/or archived redo logs with the recover command. Example Restore a datafile quickly!
Sql alter database datafile 4 offline; Switch datafile 4 to copy /oracle/backup/users_01.dbf; Recover datafile 4; Sql alter database datafile 4 online;
20
RMAN Recovery
Recover using a Backup Control File
RMAN provides automatic backups of control files. Must be configured first. Control file autobackups make for easy recovery of control files and SPFILES. Control file recoveries require the instance be started. Example:
RMAN> Startup nomount; RMAN> Restore controlfile from autobackup; RMAN> alter database open resetlogs;
Configure, Monitor Flashback Database and Perform Flashback Database operations Restore dropped tables from the recycle bin Perform Flashback Query Use Flashback Transaction Query Perform Flashback Table Operations Set up and use a Flashback Data Archive
Oracle Flashback Technologies Configure Flashback Database Configuring to use Flashback Database Database mounted Set the DB_FLASHBACK_RETENTION_TARGET parameter. Determines how long you can flashback the database too.
alter system set db_flashback_retention_target=4320;
What are the Oracle Flashback Features? Flashback Flashback Flashback Flashback Flashback Flashback Flashback Drop (and the Recycle Bin) Query Versions Query Transaction Table Database Data Archive
Oracle Flashback Technologies Configure Flashback Database Configuring to use Flashback Database Open the database
Alter database open;
Oracle Flashback Technologies Configure Flashback Database How far can you flashback? V$FLASHBACK_DATABASE_LOG select oldest_flashback_scn, oldest_flashback_time, retention_target, estimated_flashback_size from v$flashback_database_log;
OLDEST_FLASH_SCN OLDEST_FLASH_TIME RET_TARGET EST_FLASHBACK_SIZE ---------------- ----------------- ---------- -----------------979720 20-JUL-08 4320 298967040
21
Determine what point-in-time you want to flashback too. Determine if you can flashback that far.
select oldest_flashback_scn, oldest_flashback_time from v$flashback_database_log; OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TIME -------------------- --------------------979720 20-JUL-08
Oracle Flashback Technologies Using Flashback Database Put the database in MOUNT mode.
Startup mount
When you drop a table it goes to the recycle bin! See whats in the recycle bin
SQL> show recyclebin ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME ---------------- ----------------------------------------- ------------------JOB_HISTORY BIN$F2JFfMq8Q5unbC0ceE9eJg==$0 TABLE 2008-04-07:11:52:36
Flashback the database Flashback to Time SCN Restore point Before the last resetlogs operation.
flashback database to scn 979721;
Can still select from the table. Its still there, just renamed.
Recycle bin views DBA_RECYCLEBIN USER_RECYCLEBIN Purge the recycle bin purge table employees; Purge tablespace users; Purge recyclebin; Drop table my_table purge;
Recover a table from the recycle bin Use flashback drop command
flashback table job_history to before drop rename to job_hist; flashback table "BIN$F2JFfMq8Q5unbC0ceE9eJg==$0" to before drop;
22
Oracle Flashback Technologies Flashback Query Flashback query allows you to see table data as it existed at a different point-in-time. Use to Recover from user error. Compare current data with historical data. Allow user to correct certain kinds of mistakes. Use the AS OF clause for a Flashback Query Example
select * from job_history as of timestamp( to_timestamp('08-MAY-2008 11:50:00', 'DD-MON-YYYY HH24:MI:SS')) where employee_id = 102;
Oracle Flashback Technologies Flashback Versions Query Provides the ability to query a table and retrieve all of the versions of the data that have existed between two specific points in time (specified by a timestamp or an SCN). Uses the VERSIONS BETWEEN clause.
select salary from employees versions between scn minvalue and maxvalue where employee_id = 193; SALARY ---------2108.93 4217.85 4017 3900
Oracle Flashback Technologies Flashback Versions Query Some Pseudo columns are available too!
select to_char(versions_starttime,DD-MON HH:MI) START DATE, to_char (versions_endtime, DD-MON HH:MI) END DATE, versions_operation, employee_id, salary from employees versions between scn minvalue and maxvalue where employee_id = 123; START DATE -----------08-MAY 09:13 08-MAY 09:12 08-MAY 09:08 08-MAY 08:15 END DATE -----------08-MAY 09:13 08-MAY 09:12 08-MAY 09:08 V EMPLOYEE_ID SALARY - ----------- ---------U 123 2108.93 U 123 4217.85 U 123 4017 I 123 3900
Oracle Flashback Technologies Flashback Transaction Query Used to identify changes made to the database at the transaction level. Uses FLASHBACK_TRANSACTION_QUERY view. View includes the UNDO_SQL used to undo a specific SQL operation.
Roll back data in a table (or tables) to a specific point in time. Dependent objects (IE: indexes) are also rolled back. Benefits Faster than a complete point-in-time restore. Allows more tactical response to problems. Keeps the database up and running. The object(s) being flashed back are still available.
23
Table to be flashed back must have row movement enabled. Flashback to SCN or Time. Use flashback table command as seen here:
flashback table employees to scn 623411;
Flashback Data Archive Also known as Oracle Total Recall, Provides the ability to retain and track all transactional changes to a record over its lifetime Use tablespaces to store the archives. To configure for Flashback Data Archive use Create flashback archive command:
create flashback archive default audit_flash_archive tablespace audit_archive quota 20g retention 7 year;
DBA_FLASHBACK_ARCHIVE_TABLES
Set Up Automatic Diagnostic Repository Using Support Workbench Perform Block Media Recovery Use the SQL Tuning Advisor Use the SQL Access Advisor to tune a workload Understand Database Replay
24
ADR_BASE ADR_HOME
Whats Support Workbench do? View Critical Error Alerts View Problem Details Gather Additional Diagnostic Information Create a Service Request Package and Upload Diagnostic Data to Oracle Support Track the Service Request and Implement Any Repairs Close the Incident
How to use Support Workbench OEM Interface ADRCI Command line interface
Block Media Recovery provides the ability to recover corrupted database blocks online. RMAN provides an interface into BMR. Use the V$DATABASE_BLOCK_CORRUPTION to determine if/where corruption exists
SQL> SELECT NAME, VALUE FROM V$DIAG_INFO; SQL> SELECT FILE#, BLOCK#, BLOCKS, CORRUPTION_TYPE TYPE FROM V$DATABASE_BLOCK_CORRUPTION; FILE# BLOCK# BLOCKS TYPE ---------- ---------- ---------- --------1201 1968 2 PHYSICAL
Diagnosing The Database And Maintaining Performance Use the SQL Tuning Advisor
Analyzes SQL statements for performance improvements Suggests performance improving changes including: New Indexes SQL Profiles Changing your SQL statement Gathering statistics Runs automatically in Oracle Database 11g. DBMS_SQLTUNE Views DBMS_SQLTUNE_* DBMS_ADVISOR_* DBMS_SQLSET_* Manual runs via OEM or PL/SQL package calls.
25
Diagnosing The Database And Maintaining Performance Use SQL Access Advisor
OEM and manual interfaces. Suggests objects that might improve performance. Provides recommendations on: New Indexes BTREE Bitmap FBIs Materialized views Materialized view logs Partitioned objects
Determine the impact of change on your system. New indexes Upgrades Change to optimizer related parameters Application SQL changes OEM and manual interfaces. Four basic steps: Capture the database workload Preprocess the workload Replay the workload Analyze the results
Capture the Workload Used to capture real-time workload events. Preprocess the workload Used to indicate the end of the workload capture. Prepares the workload for replay Several files associated with workload capture are created.
Replay the workload Can occur on any database. Move files to replay server. Workload clients State of the schema Analyze the results OEM Manual PL/SQL procedures
Implementing Automatic Memory Management Manually configure SGA parameters Configuring automatic PGA memory management Managing resumable space allocation Describe the concepts of transportable tablespaces and databases Reclaim wasted space from tables and indexes by using the segment shrink functionality Understand the database resource manager Create and use Database Resource Manager Components
26
Set with alter system command Scope parameter of alter system command Dynamic Scope not needed in most cases. Static Use scope=spfile. Examples
Alter system set db_cache_size=250m scope=spfile; Alter system set sga_target=250m;
Configure with PGA_AGGREGATE_TARGET Do not need to configure if using Automatic Memory Management (MEMORY_TARGET). Configure if using SGA memory management (SGA_TARGET). Manual memory parameters (ie: DB_CACHE_SIZE)
Monitoring PGA Memory Management V$PGASTAT V$PROCESS V$PROCESS_MEMORY V$SQL_WORKAREA_ACTIVE V$SQL_WORKAREA V$SQL_WORKAREA_HISTOGRAM V$PGA_TARGET_ADVICE V$PGA_TARGET_ADVICE_HISTOGRAM
Reduces the likelihood of failure of database operations due to lack of space. Configured using the RESUMABLE_TIMEOUT parameter Set at the session or instance level Set in terms of seconds. Defaults to 0 seconds in 11g. Enabled if RESUMABLE_TIMEOUT set at the instance level OR the alter session enable resumable command is issued. Use
alter session enable resumable
to disable.
27
Will cause sessions to be suspended in these cases: Out of space condition Maximum extents reached condition Space quota exceeded condition. DBA/User notified of suspension of system via various methods: The error is reported in the alert log. Resumable Session Suspended alert issued. A trigger can be registered to execute on a suspension event. DBMS_RESUMABLE PL/SQL package *_RESUMABLE view.
Transportable tablespaces allow you to unplug a tablespace in one database and plug it into another. Transportable Tablespaces are good for a number of things: Database migrations Sharing tablespaces with other databases (ie: from OLTP to warehouse) Tablespace point-in-time recovery (TSPITR) Archiving data from one database to another Exporting and importing partitions.
Things to remember about transportable tablespaces If there is a tablespace on the destination database that has the same name of the tablespace to be transported, then that tablespace needs to be renamed before the transport can take place. The SYSTEM tablespace can not be transported. A tablespace with objects owned by SYS can not be transported.
Use Data Pump on the source system to specify which tablespaces are included in the transportable set.
expdp dumpfile=expdat.dmp DIRECTORY=exp_dir TRANSPORT_TABLESPACES=user_data
If converting to a different endian format, use RMAN convert to convert the files in a temporary location on the source system
28
Basic steps 4. Transport the tablespace set Physically move the datafiles to the target database. Put the source tablespace in read write mode. 5. Import the tablespace set Use the Datapump IMP utility to import the database metadata into the target database.
IMPDP DUMPFILE=expdat.dmp DIRECTORY=imp_dir TRANSPORT_DATAFILES=/oracle/oradata/LNEB/user_data 01.dbf
Transportable databases are much like transportable tablespaces. Provides the ability to move an entire database across platforms. Uses RMAN for the conversions. Basic steps: 1. Verify the prerequisites. 2. Identify all external files and directories. 3. Start the source database in READ ONLY mode. 4. Verify the source database is ready for migration. 5. Run RMAN CONVERT DATABASE. 6. Move files to the destination system. 7. Complete the migration.
1. Verify the pre-requisites. 1. Determine if a platform conversion is required. 2. Verify that there are no restrictions or limitations that the source or destination database may encounter. 3. Verify that the destination and source systems have the same Oracle version, critical patch updates, patch set version, and patch set exceptions. Verify using the Opatch utility program. 4. Determine if you will use the source or destination system to perform the conversion
2. Determine what external files and directories exist and plan for the migration. 1. Use the dbms_tdb.check_external procedure to determine this information. 2. Example:
SQL> set serveroutput on SQL> declare tdb_check boolean; begin tdb_check := dbms_tdb.check_external(); end; / The following external tables exist in the database: SYS.WRR$_REPLAY_CONN_DATA_EXT, SYS.WRR$_REPLAY_SEQ_DATA_EXT, SYS.WRR$_REPLAY_SCN_ORDER_EXT, SH.SALES_TRANSACTIONS_EXT The following directories exist in the database: SYS.EM_TTS_DIR_OBJECT, SYS.EXP_DIR, SYS.IDR_DIR, SYS.CAPTURE_DIR, SYS.SUBDIR, SYS.XMLDIR, SYS.MEDIA_DIR, SYS.LOG_FILE_DIR, SYS.DATA_FILE_DIR, SYS.AUDIT_DIR, SYS.DATA_PUMP_DIR The following BFILEs exist in the database: PM.PRINT_MEDIA
29
5. Run the RMAN Convert Database command to convert the database. Can convert on source or target database. Platform must be exactly the name contained in the PLATFORM_NAME column in the view V$DB_TRANSPORTABLE_PLATFORM
convert database [on destination platform ] transport script 'c:\temp\transport_db_orclnx.sql' new database 'orclnx' to platform 'Linux IA (64-bit)' parallelism 4 format 'c:\temp\%d%f' db_file_name_convert 'c:\oracle\oradata\orcl\','c:\temp\stage\';
6. Move the converted files to the target system. Or you may have moved them before the convert as an option. Also you will need to copy pfile, external table files, bfiles and the SQL script created by the CONVERT DATABASE command. 7. Complete the migration After the files are move, adjust the parameter file as required. Create a new password file if required. Adjust networking files as required. Start the database.
Space in tables and indexes can be wasted. Created too large initially. Contained a large amount of data at one time, but now only has a small amount of data. Objects that have been allowed to grow to large can impact performance. High water mark causes full table scans to take too long. Indexes can become inefficient in certain cases.
Oracle Database 11g provides the ability to rebuild segments in-place, and on-line. OEM Automatic Segment Advisor Manual Requirements: Row movement is enabled All rowid-based triggers defined on the object are disabled. Determine if the application uses any rowid based DML or queries. These will fail after the rebuild. (pretty rare).
Online segment rebuild will: Compact the segment, defragmenting as a result. Resets the high water mark Releases the reclaimed free space Rebuilding a table:
ALTER TABLE HR.EMPLOYEES ENABLE ROW MOVEMENT; ALTER TABLE HR.EMPLOYEES SHRINK SPACE;
Options Cascade Rebuilds all associated objects (indexes) Compact Rebuilds but does reset the HWM.
30
Job - Instructs the Scheduler to run a specific program at a specific time on a specific date. Program - Contains the code (or a reference to the code) that needs to be run to accomplish a task. Can be stored as an independent object that can be referenced by many jobs. Schedule - Contains a start date, an optional end date, and a repeat interval. Can be stored as an independent object that can be referenced by many jobs.
Windows - Identifies a recurring block of time during which a specific resource plan should be enabled to govern resource allocation for the database. Job Classes - A logical method of classifying jobs with similar attributes. Simplifies management by allowing collections of jobs to be manipulated as one object. Window Groups - A logical method of grouping windows. Simplifies management of windows by allowing the members of the group to be manipulated as one object.
Chains - Consists of two or more Scheduler programs that are linked together to meet an objective. An implementation of dependency scheduling.
Architecture The job table is the master container for all enabled jobs in the database. Exposed through the *_SCHEDULER_JOBS views.
SQL> select owner, job_name, state 2 from dba_scheduler_jobs; OWNER JOB_NAME STATE ---------- -------------------- -----------SYS PURGE_LOG SCHEDULED SYS GATHER_STATS_JOB RUNNING
31
32
Use the DROP_PROGRAM_ARGUMENT procedure to drop program arguments. Use the DROP_PROGRAM procedure to drop programs.
33
A lightweight job has the following characteristics: They are not schema objects Lower overhead Better create and drop time when compared to regular jobs. They store less metadata and job runtime data than regular jobs. They must reference an enabled PLSQL_BLOCK or STORED_PROCEDURE program to specify a job action.
Lightweight jobs inherit their privileges from the program You cannot grant privileges to lightweight jobs. Consider using a lightweight job when you have a high-frequency short-duration job.
34
Define the chain steps with the DEFINE_CHAIN_STEP procedure. Each step can point to A program Another chain An inline event An event schedule.
After the chain is created, you define the steps and any rules.
If you have a chain step that needs to wait for an event use the DEFINE_CHAIN_EVENT_STEP procedure:
BEGIN DBMS_SCHEDULER.DEFINE_CHAIN_EVENT_STEP ( chain_name => 'lne_chain', step_name => 'lne_step4', event_schedule_name => 'lne_event_schedule'); END; /
35
36