Sei sulla pagina 1di 36

About The Presenter

Robert Freeman

<Insert Picture Here>

Oracle Certified Professional Exam (OCP) 1Z0-053


Robert G Freeman Master Principal Sales Consultant Public Sector

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.

Schedule For Today

0900 1000 Class 1030 1045 Break 1045 1200 Class 1200 1300 Lunch 1300 1500 Class 1500 1530 Break 1530 1700 Class

Becoming an Oracle OCP


Requires 3 tests SQL Fundamentals OCA OCP Requires 1 Oracle course If you are already an OCP Take the upgrade exams 8i to 9i 8i to 10g 9i to 10g 10g to 11g

Becoming an Oracle OCP


The Oracle Database 11g OCP Exam 11g 1Z0-053 Perhaps the loooongest beta exam period ever!! Finally in production. Passing score 66% Cost - $195.00 Find the details at:

http://education.oracle.com

Anyone here for something other than this? Questions before we get started?

Becoming an Oracle OCP


To prepare for the exam Education.oracle.com Exam objectives Other exam related information Practice Exams Self-Test Software Transcender Links to both companies can be found

Becoming an Oracle OCP


Prepare for the fire hose! Topics in the OCP Exam we will cover today
ASM

on Oracles education/certification web site.

User Managed Backup and Recovery RMAN Backup and Recovery Flashback Database Features Diagnosing The Database And Performance Managing Database Resources The Oracle Scheduler

Becoming an Oracle OCP


OCP Exam topics we do not cover in this session due to time constraints.
Database Resource Manager Create Windows and Job Classes Use advanced Scheduler concepts to prioritize jobs Globalization Support

ASM OCP Objectives


Describe Automatic Storage Management (ASM) Set up initialization parameter files for ASM and database instances Start up and shut down ASM instances Administer ASM disk groups

ASM What is ASM?


Automated Storage Management (ASM) is designed to simplify Oracle database file administration. ASM is somewhat like a logical volume manager. ASM also provides Redundancy configurations Automated rebalancing operations We use this feature to pre-create databases, and later provision additional disks! When using RAC and Oracle Clusterware, ASM provides the ability to share database related files.

ASM Other Features


Automatic software data striping (RAID 0) Load balancing across physical disks Software RAID 1 data redundancy with double or triple mirrors External Redundancy (No mirror) Normal Redundancy (1 mirror) High Redundancy (2 mirror) Elimination of fragmentation Elimination of file management Ease of maintenance

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 Restrictions and Limits


ASM limits you to 63 disk groups in a given storage system. You can have up to a maximum of 10,000 ASM disks in a given storage system. Each ASM disk (LVM, etc) can be up to a maximum of 4 petabytes in size. Each ASM instance can manage up to 40 Exabytes of storage. Each disk group can contain up to one million files

Creating the ASM Instance ASM Restrictions and Limits


Maximum ASM file sizes vary on the type of disk group: External redundancy disk group 140 PB Maximum file size Normal redundancy disk group 42 PB maximum file size High redundancy disk group 15 PB maximum file size Created using DBCA or manually (Oracle recommends using DBCA). Parameter file for ASM instance is not unlike a database parameter file Can be PFILE or SPFILE. Uses a combination of parameters Only one required parameter - instance_type Can contain a combination of ASM specific parameters (start with ASM_) Some database parameters (memory_target)

Creating the ASM Instance


Created using DBCA or manually (Oracle recommends using DBCA). Parameter file for ASM instance is a basic parameter file.

Creating the ASM Instance


Example:
############################################## # ASM Parameter File - UNIX # ASM_DISKGROUPs='DISK GROUP_ROB1' ############################################## # Diagnostics and Statistics ########################################### background_dump_dest=/u01/app/oracle/admin/+ASM/bdump core_dump_dest=/u01/app/oracle/admin/+ASM/cdump user_dump_dest=/u01/app/oracle/admin/+ASM/udump ########################################### # Miscellaneous # Of course set compatible to your version of Oracle ########################################### instance_type=asm compatible=11.1.0.6.0 remote_login_passwordfile=exclusive

Starting the ASM Instance


You use SQL*Plus to start the ASM instance. Use the startup mount command to start the ASM instance. No need to backup the ASM instance. This is done when databases are backed up.

ASM Disk Discovery


When the ASM instance is started disk discovery begins. The ASM_DISKSTRING parameter is used to identify candidate disks for the ASM instance. The process of finding candidate disks is known as discovery. ASM_DISKSTRING can identify multiple candidate disks. Example setting ASM_DISKSTRING.
Alter system set ASM_DISKSTRING=?/disks/d1/*,?/disks/d21/*';

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.

Creating ASM Disk Groups


Once disk discovery has found disks, you can create disk groups. Use the create diskgroup command to create disk groups. Example
CREATE DISKGROUP dgroup1 NORMAL REDUNDANCY failgroup diskcontrol1 DISK '/devices/diska1' failgroup diskcontrol2 DISK '/devices/diskb1';

V$ASM_FILE

Displays each ASM file contained in the ASM instance.

V$ASM_CLIENT

Displays each database that is using at least one disk group managed by the ASM instance.

Dropping ASM Disk Groups


Use the drop diskgroup command to drop an ASM disk group Example
DROP DISKGROUP dgroup1 ;

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

+sp_dgroup2.56.544956473 +Group_name/your_assigned_alias +sp_dgroup2/ctrl_files/control_file_01(special)

This is known as a fully qualified ASM Filename.

ASM Filename Alias with Templates Incomplete ASM Filenames

+Sp_dgroup1 Incomplete ASM Filenames With Templates +Sp_dgroup1(special_template)

ASM File Aliases


Create an alias with the alter disk group command:
Alter diskgroup cooked_dgroup1 add alias +cooked_dgroup1/alias_dir/alias_tbs_01.dbf FOR +cooked_dgroup1/11GDB/datafile/alias_tbs.260.61316861 1;

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

Creating Tablespaces Using ASM Examples


Uses default location
create tablespace test_rgf datafile size 100k;
Select tablespace_name, file_name from dba_data_files Where tablespace_name=TEST_RGF; TABLESPACE FILE_NAME ---------- -------------------------------------------------------TEST_RGF +COOKED_DGROUP1/11gDB/datafile/test_rgf.256.613064385

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

Creating Tablespaces Using ASM Examples


Specific location
create tablespace another_test datafile +COOKED_DGROUP1 size 100k;
Select tablespace_name, file_name from dba_data_files Where tablespace_name=ANOTHER_TEST; TABLESPACE_NAME FILE_NAME --------------- ---------------------------------------------------------ANOTHER_TEST +COOKED_DGROUP1/11GDB/datafile/another_test.256.613065911

ASM The ASMCMD Command


The asmcmd tool is a command line utility that allows you to manage ASM instances and the disk structures and files within those instances. With asmcmd you can: List contents of ASM disk groups Perform searches (like directory listings) Add or remove directories Display space availability and utilization

ASM Starting ASMCMD


Starting ASMCMD
C:\>Set ORACLE_SID=+ASM C:\>asmcmd

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

ASM Exam CRAM What do you need to know?


Enumerate the benefits and characteristics of Automatic Storage Management (ASM). Understand how ASM can relieve you of manually optimizing I/O across all files in the tablespace by using ASM disk groups. Show how ASM operations can be performed online with minimal impact to ongoing database transactions.

ASM Exam Cram What do you need to know?


Be able to create an ASM instance and configure its initialization parameters. Understand the initialization parameters INSTANCE_TYPE, ASM_POWER_LIMIT, ASM_DISKSTRING, and ASM_DISKGROUPS. Configure DB_UNIQUE_NAME for an ASM instance. Start up and shut down an ASM instance, noting the dependencies with database instances that are using the ASM instances disk groups.

ASM Exam Cram What do you need to know?


Understand the architecture of an ASM instance.
Enumerate the different states for an ASM instance. Describe what happens when an ASM instance is shut down normally or is aborted. Understand and describe the differences between an RDBMS instance and an ASM instance.

ASM Exam Cram What do you need to know?


Understand how ASM filenames are constructed and used when creating Oracle objects. Differentiate how different ASM filename formats are used and files are created depending on whether the file is an existing ASM file, whether a new ASM file is being created, or whether multiple ASM files are being created. Understand the different system templates for creating ASM files with the associated filename and how the characteristics are applied to the ASM files. Show how ASM files are used in SQL commands.

Understand Redundancy and Resync

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.

ASM Exam Cram What do you need to know?


Be able to create, drop, and alter ASM disk groups.

User Managed Backup OCP Objectives

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.

User Managed Backup Configure Backup Settings

User Managed Backup Configure Backup Settings

Main Oracle processes related to backup and recovery DBWR LGWR ARCH SMON/PMON CKPT

Oracle memory structures related to backup and recovery SGA

User Managed Backup Configure Backup Settings

User Managed Backup Configure Backup Settings

The Data Dictionary Key role in user managed backups. Different dictionary views V$ DBA/USER/ALL_*

The Data Dictionary Demonstrate the use of the data dictionary

User Managed Backup Configure Backup Settings

User Managed Backup Configure Backup Settings

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

User Managed Backup Configure Backup Settings

User Managed Backup Key Things To Remember

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.

User Managed Backup Offline Cold Backups

User Managed Backup Offline Cold 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

User Managed Backup Online Backups

User Managed Backup Online Backups

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.

User Managed Recovery OCP Objectives

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

User Managed Recovery User-Managed Control File Backups

User Managed Recovery User-Managed Control File Backups

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

User Managed Recovery Redo Log Loss

User Managed Recovery Other User-Managed Recovery Issues

Loss of an inactive archived online redo log. Loss of an inactive, unarchived online redo log. Loss of the active online redo log.

Restoring a lost TEMPFILE Restoring a lost password file

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.

RMAN Backup Starting RMAN

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)

RMAN Backup Configuring RMAN

Persistent configuration settings make RMAN easier to use. Example of setting RMAN persistent configuration settings:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;

RMAN Backup Configuring RMAN

RMAN Backup Configuring RMAN

What do we configure? Channels Example (Note the %U format option!)


CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/oracle01/backup/orcl/%U';

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 ;

FRA DB_RECOVERY_FILE_DEST DB_RECOVERY_FILE_DEST_SIZE

CONTROL_FILE_RECORD_KEEP_TIME Parameter Independent of retention criteria! Control File autobackup configuration


Configure controlfile autobackup on;

RMAN Backup Configuring RMAN

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;

Default encryption settings Available encryption algorithms in V$RMAN_ENCRYPTION_ALGORITHMS Configure as follows:


RMAN> Configure encryption algorithm "AES128"; RMAN> Configure encryption for database on;

Default channel/device configuration


configure channel 1 device type sbt;

13

RMAN Backup Configuring RMAN

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.

Default compression settings


configure device type disk backup type to compressed backupset;

Default location for the snapshot control file.


Configure snapshot controlfile name to /oracle01/backup/sncf/sncforcl.ora;

Demo of configuring RMAN persistent settings.

RMAN Backup RMAN Backups

RMAN Backup RMAN Backups Offline Backups

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;

RMAN Backup RMAN Backups Online Backups

RMAN Backup RMAN Backups Online Backups

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

RMAN Backup RMAN Backups Incremental Backups

RMAN Backup RMAN Backups Incremental Backups

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';

Level 1 backups Only changed blocks are backed up.


Backup level 1 database plus archivelog delete input;

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;

You can backup archived redo logs. Example


backup archivelog time between "sysdate-1" and "sysdate";

15

RMAN Backup
RMAN Backups Control file and SPFILE autobackups

RMAN Backup
RMAN Backups Control file backups

RMAN can be configured to automatically backup SPFILES and control files.

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;

RMAN Recovery Catalog OCP Objectives

RMAN Recovery Catalog Recovery Catalog Benefits

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

RMAN Recovery Catalog


Register a database with the Recovery Catalog

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

RMAN Recovery Catalog


Unregister a database with the Recovery Catalog

RMAN Recovery Catalog


Synchronizing the Recovery Catalog

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;

RMAN Recovery Catalog


Using Stored Scripts

RMAN Recovery Catalog


Using Stored Scripts

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; }

RMAN Recovery Catalog


Backup the Recovery Catalog

RMAN Recovery Catalog


Virtual Private Catalog

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

RMAN Recovery Catalog


Virtual Private Catalog

RMAN Recovery Catalog


Virtual Private Catalog

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.

RMAN Recovery Catalog


Virtual Private Catalog

RMAN Recovery OCP Objectives

The revoke command is used to remove privileges:


Revoke catalog for database abcs from rcat_001;

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.

Example All files lost


RMAN> RMAN> RMAN> RMAN> RMAN> shutdown abort startup mount restore database; recover database; alter database open;

Example Loss of single, non-critical datafile. Database still running.


RMAN> RMAN> RMAN> RMAN> sql 'alter database datafile 3 offline'; restore datafile 3; recover datafile 3; sql 'alter database datafile 3 online';

Example SYSTEM tablespace lost


RMAN> RMAN> RMAN> RMAN> RMAN> shutdown abort startup mount restore tablespace system; recover tablespace system; alter database open;

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

Time based recovery example


RMAN> Restore database until time 09/30/2008:18:00:00; RMAN> Recover database until time 09/30/2008:18:00:00; RMAN> Alter database open resetlogs;

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

Oracle Flashback Technologies OCP Objectives

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

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

Enable the flashback capability:


alter database flashback on;

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

Determine that the database is in flashback mode.


select flashback_on from v$database; FLASHBACK_ON -----------YES

21

Oracle Flashback Technologies Configure Flashback Database

Oracle Flashback Technologies Using Flashback Database

How much flashback log space is required? V$FLASHBACK_DATABASE_STAT


select * from v$flashback_database_stat; BEGIN_TIM END_TIME FLASHBACK_DATA DB_DATA REDO_DATA --------- --------- -------------- ---------- ---------ESTIMATED_FLASHBACK_SIZE -----------------------20-JUL-08 20-JUL-08 61784064 35880960 99203072 100010

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

Shutdown the database (Consistent)


Shutdown immediate

Oracle Flashback Technologies Using Flashback Database Put the database in MOUNT mode.
Startup mount

Oracle Flashback Technologies The Recycle Bin

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;

Open the database with resetlogs.


Alter database open resetlogs;

Can still select from the table. Its still there, just renamed.

Oracle Flashback Technologies The Recycle Bin

Oracle Flashback Technologies The Recycle Bin

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.

Oracle Flashback Technologies Flashback Transaction Query Example


select table_name, operation, undo_sql from flashback_transaction_query t, (select versions_xid as xid from employees versions between scn minvalue and maxvalue where employee_id = 123) e where t.xid = e.xid and operation = UPDATE; TABLE_NAME OPERATION UNDO_SQL ---------- --------- -------------------------------------EMPLOYEES UPDATE update "HR"."EMPLOYEES" set "SALARY" = '2108.93' where ROWID = 'AAARAgAAFAAAABYABd'; EMPLOYEES UPDATE update "HR"."EMPLOYEES" set "SALARY" = 4217.85' where ROWID = 'AAARAgAAFAAAABYABd'; EMPLOYEES UPDATE update "HR"."EMPLOYEES" set "SALARY" = '4017' where ROWID = 'AAARAgAAFAAAABYABd';

Oracle Flashback Technologies Flashback Table

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

Oracle Flashback Technologies Flashback Table

Oracle Flashback Technologies Flashback Data Archive

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;

Oracle Flashback Technologies Flashback Data Archive

Oracle Flashback Technologies Flashback Data Archive

Flashback Data Archive Assign a table to an archive Using Create Table


create table shipments (ship_id number(9), shipper number(9), ship_date date), flashback archive;

Flashback Data Archive Views


View Name DBA_FLASHBACK_ARCHIVE DBA_FLASHBACK_ARCHIVE_TS Description Information about flashback data archives Tablespaces used for flashback data archives

Using Alter Table


alter table employee_history flashback archive audit_flash_archive; alter table shipments no flashback archive;

DBA_FLASHBACK_ARCHIVE_TABLES

Tables that are enabled for archive

Diagnosing The Database And Maintaining Performance - OCP Objectives

Diagnosing The Database And Maintaining Performance Setup ADR

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

What is ADR? Setting up ADR DIAGNOSTIC_DEST parameter Defaults to $ORACLE_BASE


alter system set diagnostic_dest="c:\temp";

24

Diagnosing The Database And Maintaining Performance Setup ADR

Diagnosing The Database And Maintaining Performance Using Support Workbench

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

Diagnosing The Database And Maintaining Performance Using Support Workbench

Diagnosing The Database And Maintaining Performance Block Media Recovery

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 Block Media Recovery

Diagnosing The Database And Maintaining Performance Use the SQL Tuning Advisor

Now, recover the block:


RECOVER DATAFILE 1201 BLOCK 1968;

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

Diagnosing The Database And Maintaining Performance Understand Database Replay

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

Diagnosing The Database And Maintaining Performance Understand Database Replay

Diagnosing The Database And Maintaining Performance Understand Database Replay

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

Managing Database Resources OCP Objectives

Managing Database Resources Automatic Memory Management


Provides the ability to manage SGA and PGA memory in one memory allocation. Parameters MEMORY_TARGET MEMORY_MAX_TARGET Still need to set the following buffer pools KEEP buffer pool RECYCLE buffer pool Non-default block size Buffer cache pools Fixed SGA and other intern memory structures Log buffer

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

Managing Database Resources


Manually Configure SGA Parameters Can use SGA memory management SGA_TARGET SGA_MAX_SIZE Manual parameter settings DB_CACHE_SIZE SHARED_POOL_SIZE LARGE_POOL_SIZE JAVA_POOL_SIZE LOG_BUFFER Dynamic/Static parameters Dynamic Can be set without restarting database. Static Must restart database.

Managing Database Resources


Manually Configure SGA Parameters

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;

Managing Database Resources


Configure Automatic PGA Memory Management

Managing Database Resources


Configure Automatic PGA Memory Management

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)

Eliminates needing to set these parameters SORT_AREA_SIZE HASH_AREA_SIZE BITMAP_MERGE_AREA_SIZE CREATE_BITMAP_AREA_SIZE

Managing Database Resources


Configure Automatic PGA Memory Management

Managing Database Resources


Configure Resumable Space Allocation

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

Managing Database Resources


Configure Resumable Space Allocation

Managing Database Resources


Transportable Tablespaces and Databases

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.

Managing Database Resources


Transportable Tablespaces and Databases

Managing Database Resources


Transportable Tablespaces and Databases

Things to remember about transportable tablespaces


Must be self-contained. Tablespace to be transported will temporarily be made readonly. Tablespaces can come from databases of different block sizes. Tablespaces can be transported across different Endian byte formats. The source and target databases must have the same character set and national character set.

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.

Managing Database Resources


Transportable Tablespaces and Databases

Managing Database Resources


Transportable Tablespaces and Databases

Basic steps 1. Determine compatibility between source and target.


Check the compatibility parameter.

Basic steps 3. Generate the transportable tablespace set


Put all of the tablespaces in the transportable set readonly.

Show parameter compatible

alter tablespace user_data read only;

Check Endian (byte ordering) compatibility v$transportable_platform

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

1. Choose the tablespaces for the transportable tablespace set


Ensure they are self-contained DBMS_TTS.TRANSPORT_SET_CHECK

If converting to a different endian format, use RMAN convert to convert the files in a temporary location on the source system

28

Managing Database Resources


Transportable Tablespaces and Databases

Managing Database Resources


Transportable Tablespaces and Databases

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.

Managing Database Resources


Transportable Tablespaces and Databases

Managing Database Resources


Transportable Tablespaces and Databases

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

Managing Database Resources


Transportable Tablespaces and Databases

Managing Database Resources


Transportable Tablespaces and Databases

3. Put the source database in READ-ONLY mode. Shutdown must be consistent.


SQL> shutdown immediate; SQL> startup mount; SQL> alter database open read only;

4. Verify the database is ready for migration Use DBMS_TDB.CHECK_DB procedure.


SQL> set serveroutput on SQL> declare tdb_check boolean; begin tdb_check := dbms_tdb.check_db ('Linux IA (64-bit)',dbms_tdb.skip_none); end; Database is not open in READ-ONLY mode. Open the database in READ-ONLY mode and retry. PL/SQL procedure successfully completed.

29

Managing Database Resources


Transportable Tablespaces and Databases

Managing Database Resources


Transportable Tablespaces and Databases

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.

Managing Database Resources


Reclaim Wasted Space from Tables/Indexes

Managing Database Resources


Reclaim Wasted Space from Tables/Indexes

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).

Managing Database Resources


Reclaim Wasted Space from Tables/Indexes

The Database Scheduler OCP Objectives


Create a job, program, and schedule. Use a time-based or event-based schedule for executing Scheduler jobs Create lightweight jobs Use job chains to perform a series of related tasks

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

The Database Scheduler


Create a Job, Program and Schedule

The Database Scheduler


Create a Job, Program and Schedule

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.

The Database Scheduler


Create a Job, Program and Schedule

The Database Scheduler


Create a Job, Program and Schedule

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

The Database Scheduler


Create a Job, Program and Schedule Architecture The job coordinator. An Oracle background process with the responsibility of ensuring that jobs are run on schedule. Process name is cjqNNN. One per instance. The job slave processes Tasked with carrying out the execution of job programs assigned to them by the job Scheduler . Executes jobs in a new session as the owner of the job.

The Database Scheduler


Create a Job, Program and Schedule Architecture The DBMS_SCHEDULER package is used to manage the job scheduler. ENABLED procedure Enable jobs DISABLED procedure Disable jobs Jobs can have attributes Set with SET_ATTRIBUTE procedure. Attributes include: Start Date Enabled Disabled OEM also has interfaces into the job scheduler.

31

The Database Scheduler


Create a Job, Program and Schedule Create a job DBMS_SCHEDULER.CREATE_JOB Combines a job and a program. May need to set job arguments calling SET_JOB_ARGUMENT and/or SET_JOB_ANYDATA_VALUE procedures.

The Database Scheduler


Create a Job, Program and Schedule Create a job Jobs have attributes JOB_NAME JOB_TYPE PLSQL_BLOCK STORED_PROCEDURE EXECUTABLE JOB_ACTION Code to be executed (ie: Name of executable, or PL/SQL code to be executed). NUMBER_OF_ARGUMENTS PROGRAM_NAME START_DATE

The Database Scheduler


Create a Job, Program and Schedule Create a job Jobs have attributes REPEAT_INTERVAL SCHEDULE_NAME END_DATE COMMENTS ENABLED AUTO_DROP

The Database Scheduler


Create a Job, Program and Schedule Create a job Using CREATE_JOB Example
begin dbms_scheduler.create_job ( job_name => LNEB_job, job_type => PLSQL_BLOCK, job_action => update employee set salary = salary*1.05;, start_date => 10-OCT-2008 06:00:00 AM, repeat_interval => FREQ=YEARLY, comments => Cost of living adjustment); end; /

The Database Scheduler


Create a Job, Program and Schedule Was the job created?
SQL> select job_name, enabled, run_count from user_scheduler_jobs; JOB_NAME ENABLED RUN_COUNT ------------------------- ---------LNEB_JOB FALSE 0

The Database Scheduler


Create a Job, Program and Schedule We can stop the job
begin dbms_scheduler.stop_job(job_name=>LNEB_JOB, force=>TRUE); end; /

We can run the job


begin dbms_scheduler.run_job(LNEB_JOB,TRUE); end; /

We can drop the job


begin dbms_scheduler.drop_job(job_name=>LNEB_JOB, force=>TRUE); end; /

32

The Database Scheduler


Create a Job, Program and Schedule Programs A program defines the action that will occur when a job runs. A program can be PL/SQL Block Stored Procedure OS Executable Programs can be created when jobs are defined or independently with the DBMS_SCHEDULER.CREATE_PROGRAM procedure.

The Database Scheduler


Create a Job, Program and Schedule Programs A program has many attributes, much like a job. PROGRAM_NAME PROGRAM_TYPE PLSQL_BLOCK STORED_PROCEDURE EXECUTABLE PROGRAM_ACTION NUMBER_OF_ARGUMENTS ENABLED COMMENTS

The Database Scheduler


Create a Job, Program and Schedule Create a program Use the DBMS_SCHEDULER.CREATE_PROGRAM procedure.
begin dbms_scheduler.create_program( program_name => STATS_PROGRAM, program_type => STORED_PROCEDURE, program_action => DBMS_STATS.GATHER_SCHEMA_STATS, number_of_arguments => 1, comments => Gather stats for a schema); end; / -- Define the argument begin dbms_scheduler.define_program_argument( program_name => STATS_PROGRAM, argument_position => 1, argument_type => VARCHAR2); end; /

The Database Scheduler


Create a Job, Program and Schedule Create a program We also need to define the argument
-- Define the argument begin dbms_scheduler.define_program_argument( program_name => STATS_PROGRAM, argument_position => 1, argument_type => VARCHAR2); end; /

Use the DROP_PROGRAM_ARGUMENT procedure to drop program arguments. Use the DROP_PROGRAM procedure to drop programs.

The Database Scheduler


Create a Job, Program and Schedule A schedule defines when jobs run as well as when windows are opened. A schedule also defines the repeat interval of a job. Schedules can be: Time-based Event-based Dependency

The Database Scheduler


Create a Job, Program and Schedule Attributes of a schedule SCHEDULE_NAME START_DATE END_DATE REPEAT_INTERVAL COMMENTS

33

The Database Scheduler


Create a Job, Program and Schedule Create a schedule:
begin dbms_scheduler.create_schedule( schedule_name => NIGHTLY_8_SCHEDULE, start_date => SYSTIMESTAMP, repeat_interval => FREQ=DAILY; BYHOUR=20, comments => Runs nightly at 8:00 PM); end; /

The Database Scheduler


Create Lightweight Jobs

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.

Note the use of the calendaring syntax.

The Database Scheduler


Create Lightweight Jobs

The Database Scheduler


Create Lightweight Jobs

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.

Example of a lightweight job:


BEGIN DBMS_SCHEDULER.CREATE_JOB ( job_name => 'example_lightweight_job', program_name => 'lne_prog', repeat_interval => 'FREQ=SECONDLY;INTERVAL=30', job_style => 'LIGHTWEIGHT', comments => 'Heartbeat monitor job'); END; /

The Database Scheduler


Using Job Chains Job chains are used to implement dependency scheduling. A job chain consists of two or more Scheduler programs that are linked together to meet an objective. A job chain can contain logic with respect to the jobs that are executed and the order in which they are executed in. A Scheduler job, referred to as a chain job, can reference a chain instead of a program to start the process.

The Database Scheduler


Using Job Chains Example Run program A If program A completes successfully, run program B If both program A and B complete successfully, run program C If program A or B does not succeed, run program F Run program ZZ. Monitor job Chain jobs *_SCHEDULER_RUNNING_JOBS *_SCHEDULER_JOB_LOG *_SCHEDULER_JOB_RUN_DETAILS *_SCHEDULER_RUNNING_CHAINS views.

34

The Database Scheduler


Using Job Chains

The Database Scheduler


Using Job Chains

Create a chain using the CREATE_CHAIN procedure.


BEGIN DBMS_SCHEDULER.CREATE_CHAIN ( chain_name => 'lne_chain', rule_set_name => NULL, evaluation_interval => NULL, comments => 'Never break the chain'); END; /

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.

The Database Scheduler


Using Job Chains Example Adds three steps, each of which point to a specific program.
BEGIN DBMS_SCHEDULER.DEFINE_CHAIN_STEP ( chain_name => 'lne_chain', step_name => 'lne_step1', program_name => 'start_lne'); DBMS_SCHEDULER.DEFINE_CHAIN_STEP ( chain_name => 'lne_chain', step_name => 'lne_step2', program_name => 'lne_run_stage1'); DBMS_SCHEDULER.DEFINE_CHAIN_STEP ( chain_name => 'lne_chain', step_name => 'lne_step3', program_name => 'lne_run_stage2'); END; /

The Database Scheduler


Using Job Chains

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; /

The Database Scheduler


Using Job Chains We will also need to define chain rules. Use the DEFINE_CHAIN_RULE procedure.
BEGIN DBMS_SCHEDULER.DEFINE_CHAIN_RULE ( chain_name => 'lne_chain', condition => 'TRUE', action => 'START lne_step1', rule_name => 'lne_rule1', comments => 'start the chain'); DBMS_SCHEDULER.DEFINE_CHAIN_RULE ( chain_name => 'lne_chain', condition => 'lne_step1 completed', action => 'START lne_step2', rule_name => 'lne_rule2'); END; /

The Database Scheduler


Using Job Chains

You must enable a chain before a job can run it:


BEGIN DBMS_SCHEDULER.ENABLE ('lne_chain'); END; /

35

The Database Scheduler


Using Job Chains Creating jobs that use chains Use the RUN_CHAIN procedure to run a chain Use the CREATE_JOB procedure to create a job that runs a chain
BEGIN DBMS_SCHEDULER.CREATE_JOB ( job_name => 'lne_chain_job1', job_type => 'CHAIN', job_action => 'lne_chain', repeat_interval => 'freq=daily;byhour=7;byminute=30;bysecond=0', enabled => TRUE); END; /

The Database Scheduler


Using Job Chains

Monitor jobs with the following views: *_SCHEDULER_RUNNING_JOBS *_SCHEDULER_JOB_LOG *_SCHEDULER_JOB_RUN_DETAILS

Where to go from here?

Read! Surf! Take sample tests! Use Oracle!

36

Potrebbero piacerti anche