<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-599273791400702751</id><updated>2012-01-05T11:29:16.681-08:00</updated><category term='OCP logo'/><category term='interview SQL questions'/><category term='dynamic_sampling hint'/><category term='create temporary tablespace group'/><category term='display ref cursor result through SQL*PLUS'/><category term='DIRECT PATH'/><category term='dbms_stats.gather_index_stats'/><category term='create spfile'/><category term='EXCLUDE'/><category term='sample SQL'/><category term='delete obsolete'/><category term='v$sort_usage'/><category term='sga'/><category term='REMAP_SCHEMA'/><category term='NESTED LOOPS (ANTI)'/><category term='pga'/><category term='BIN$'/><category term='DCD'/><category term='height balanced histogram'/><category term='when do we use snowflake schema'/><category term='DBMS_STATS.drop_stat_table'/><category term='utl_smtp.helo'/><category term='snowflake schema'/><category term='resetting HWM in two steps'/><category term='HASH_SJ'/><category term='fact'/><category term='backup crosscheck'/><category term='describe'/><category term='default temporary tablespace'/><category term='what is dynamic sampling query in oracle'/><category term='integer is slower then number'/><category term='&apos;ALTER SYSTEM KILL SESSION'/><category term='space quota exceeded'/><category term='restriction on resetting HWM in oracle10g'/><category term='LMT and SSM is AUTO'/><category term='ORA-20005: object statistics are locked'/><category term='TIMESTAMP WITH LOCAL TIME ZONE'/><category term='ORA-08182'/><category term='ORA-01450: maximum key length (6398) exceeded'/><category term='PURGE'/><category term='ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION'/><category term='DROP TABLESPACE temp INCLUDING CONTENTS AND DATAFILES'/><category term='NL_AJ'/><category term='variable size'/><category term='NOT IN'/><category term='ASSM'/><category term='Cartesian join'/><category term='FINISH_REDEF_TABLE'/><category term='content of PGA'/><category term='hash partition'/><category term='declare ref cursor'/><category term='ORA-02091'/><category term='TKPROF'/><category term='Privileges'/><category term='alter user'/><category term='oracle memory structure'/><category term='DBMS_STATS.create_stat_table'/><category term='dbms_profiler'/><category term='NOT IN and NOT EXISTS'/><category term='Oracle Utility'/><category term='TIMESTAMP'/><category term='shutdown'/><category term='advantage of snowflake'/><category term='dbms_streams_adm.set_up_queue'/><category term='enhancements'/><category term='RECOVER MANAGED STANDBY DATABASE CANCEL'/><category term='global partition index'/><category term='dynamic sampling levels in oracle10g'/><category term='disable resumable'/><category term='http://tkyte.blogspot.com/2006/11/see-you-just-cannot-make-this-stuff-up.html'/><category term='ETL'/><category term='KEEP_MASTER'/><category term='nested loop'/><category term='DBMS_SCHEDULER.ENABLE'/><category term='creating index in oracle10g with statistics'/><category term='Performance Tuning'/><category term='SYNC_INTERIM_TABLE'/><category term='how to reset the HWM'/><category term='Row source generation'/><category term='DBMS_STATS.RESTORE_TABLE_STATS'/><category term='enable archive log'/><category term='SQL apply'/><category term='oracle memory components'/><category term='AMM feature in oracle11g'/><category term='ON COMMIT DELETE ROWS'/><category term='ALTER_STATS_HISTORY_RETENTION'/><category term='No insert/update/delete'/><category term='Hash Join'/><category term='CONTINUE_CLIENT'/><category term='NLS_LENGTH_SEMANTICS'/><category term='profload.sql'/><category term='ORA-32004'/><category term='Metalink Note: 251412.1'/><category term='TRACEONLY'/><category term='Benefits of RMAN Backup vs. Scripted Backups'/><category term='purge recyclebin'/><category term='Transaction recovery'/><category term='OLAP'/><category term='cloning db'/><category term='HASH_JOIN_ENABLED'/><category term='IOT'/><category term='tips to prepare oracle OCP exam'/><category term='startup'/><category term='CURSOR_SHARING'/><category term='SQLLOADER'/><category term='v$transaction'/><category term='user_ind_statistics'/><category term='High Degree of Parallelism'/><category term='register database'/><category term='RMAN'/><category term='ideal place to use reverse key index'/><category term='SET CONSTRAINTS'/><category term='ORA-06512: at &quot;SYS.DBMS_STATS&quot;'/><category term='drop database in oracle10g'/><category term='flashback query'/><category term='ORA-01919'/><category term='STATISTICS'/><category term='when do we use FIRST_ROWS'/><category term='plsql_profiler_units'/><category term='SAMPLE'/><category term='HWM in two phase'/><category term='DELETE'/><category term='TKPROF output v$sqlplan versus EXPLAIN PLAN'/><category term='dbms_rule_adm'/><category term='Oracle certified Professional logo'/><category term='Anti-join algorithm'/><category term='COPY_TABLE_DEPENDENTS'/><category term='alter index'/><category term='DB_CACHE_ADVICE'/><category term='interval partition'/><category term='recover database'/><category term='UPSERT'/><category term='GET_STATS_HISTORY_AVAILABILITY'/><category term='catalog database'/><category term='DBMS_STATS.AUTO_INVALIDATE'/><category term='HASH_AJ'/><category term='dbms_aqadm'/><category term='db_cache_size'/><category term='v$temp_space_header'/><category term='INCLUDING'/><category term='for all column size 1'/><category term='roll backward'/><category term='DICTIONARY'/><category term='STREAMBUFFER'/><category term='CLOB'/><category term='alter table shrink space compact'/><category term='KILL_JOB'/><category term='orapwd'/><category term='THRESHOLD'/><category term='slowly changing dimension'/><category term='PLUSTRACE'/><category term='archive log'/><category term='ref partition'/><category term='OCA logo'/><category term='GLOBAL AND PARTITION'/><category term='oracle dba Interview Question'/><category term='TUNING PARAMETERS IN SQLLOADER'/><category term='alter table monitoring nomonitoring'/><category term='instance recovery'/><category term='set_param'/><category term='drop any table'/><category term='SMON'/><category term='download logo'/><category term='SKIP TABLESPACE'/><category term='reverse'/><category term='enable row moment'/><category term='user_tab_modifications'/><category term='bulk collect into'/><category term='Full Table Scan Hints'/><category term='ENCRYPTION_PASSWORD'/><category term='utl_smtp.quit'/><category term='Oracle SQL Questions for learners'/><category term='START_REDEF_TABLE'/><category term='COLUMNARRAY'/><category term='user_resumable'/><category term='/*+ all_rows */'/><category term='save'/><category term='restore database'/><category term='BMR'/><category term='PLSQL_OPTIMIZE_LEVEL = 2'/><category term='OCP exam preparation'/><category term='global index'/><category term='user_part_histograms'/><category term='show all'/><category term='IN'/><category term='global index versus local index on partition table'/><category term='how do we kill inactive session'/><category term='what is ref cursor'/><category term='INITIALLY DEFERRED'/><category term='V$SESSION'/><category term='how do we profile PLSQL code'/><category term='ORA-38029: object statistics are locked'/><category term='INITIALLY IMMEDIATE'/><category term='DBMS_SCHEDULER.DISABLE'/><category term='alter database open'/><category term='DBCA'/><category term='CHARACER'/><category term='DATE_CACHE'/><category term='&apos;DEFAULT_TEMP_TABLESPACE'/><category term='Oracle external table'/><category term='expdp'/><category term='glogin.sql'/><category term='CLOB update is very slow'/><category term='ORA-00845: MEMORY_TARGET not supported on this system'/><category term='login.sql'/><category term='PLSQL_OPTIMIZE_LEVEL = 1'/><category term='GATHER_STATS_JOB'/><category term='V$DB_CACHE_ADVICE'/><category term='TIMESTAMP WITH TIME ZONE'/><category term='READBUFFER'/><category term='Transferring statistics from one server to another server'/><category term='index skip scan'/><category term='histogram buckets'/><category term='UPDATE'/><category term='BLOCK_SAMPLE'/><category term='dbms_stats.lock_table_stats'/><category term='Parse'/><category term='create catalog tablespace'/><category term='install dbms_profiler in oracle'/><category term='DBMS_STATS.import_schema_stats'/><category term='global_name'/><category term='star schema example'/><category term='ENABLE VALIDATE'/><category term='dbms_flashback.disable'/><category term='bulk collects'/><category term='flashback table to before drop'/><category term='cursor_sharing = similar'/><category term='dbms_flashback.enable_at_time'/><category term='ALL_ROWS'/><category term='streams_pool_size'/><category term='block media recovery'/><category term='incremental backup'/><category term='HWM'/><category term='DBMS_STATS'/><category term='after suspend trigger'/><category term='$ORACLE_HOME/sqlplus/admin'/><category term='alter database open resetlogs'/><category term='purge index'/><category term='PLSQL_OPTIMIZE_LEVEL'/><category term='spfile'/><category term='RESTRICTION ON MERGE'/><category term='INTEGER VERSUS NUMBER'/><category term='drop database'/><category term='oracle9i RMAN feature'/><category term='ORACLE_LOADER'/><category term='create synonym'/><category term='virtual column based partition'/><category term='CONVENTIONAL PATH'/><category term='AUTO'/><category term='what is automatic statistics gathering in oracle10g'/><category term='151972.1'/><category term='redo buffers'/><category term='monitoring'/><category term='Bulk binds'/><category term='ORA-02291'/><category term='SET NEWNAME FOR DATAFILE'/><category term='real time apply enabled'/><category term='what should DBA look in tkprof'/><category term='roll forward'/><category term='MULTIBYTE'/><category term='ENABLE NOVALIDATE'/><category term='PLSQL_OPTIMIZE_LEVEL = 0'/><category term='DBMS_STATS.GATHER_DATABASE_STATS_JOB_PROC'/><category term='fixed size'/><category term='NESTED LOOPS (SEMI)'/><category term='CURSOR_SHARING=EXACT'/><category term='Resize temporary tablespace'/><category term='dba_temp_files'/><category term='df -k /dev/shm'/><category term='testking question papers'/><category term='temporary tablespace'/><category term='ESTIMATE_PERCENT'/><category term='backup database plus archivelog'/><category term='shutdown abort'/><category term='SP2-0333'/><category term='395505.1'/><category term='When the Optimizer Uses Full Table Scans'/><category term='GATHER_DATABASE_STATS'/><category term='user_recyclebin'/><category term='set termout off'/><category term='MERGE_AJ'/><category term='ORA-02091: transaction rolled back'/><category term='primary database'/><category term='INTEGER'/><category term='b-tree index versus reverse key index'/><category term='SYS_REFCURSOR'/><category term='ORA-14039'/><category term='NOT EXISTS'/><category term='DISABLE VALIDATE'/><category term='utl_smtp.close_data'/><category term='temporary tablespace groups'/><category term='How do we reset the HWM'/><category term='recovery scenarios'/><category term='RMAN corrupted block'/><category term='utl_smtp.open_connection'/><category term='dbms_stats.get_param'/><category term='logical standby database'/><category term='spool'/><category term='HASH_AREA_SIZE'/><category term='startup restrict mount'/><category term='ORA-02298'/><category term='ORA-24372'/><category term='duplicate target database'/><category term='create session'/><category term='enable row movement'/><category term='gather statistics while creating index in oracle'/><category term='trail recovery'/><category term='oracle sql question for beginners'/><category term='oracle sql questions for newbies'/><category term='DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER'/><category term='EXISTS'/><category term='impdp'/><category term='how do we find stale statistics'/><category term='readonly user'/><category term='utl_smtp.write_data'/><category term='SP2-0611'/><category term='CHAR'/><category term='DEFERRED'/><category term='v$object_usage'/><category term='flashback version query'/><category term='ORA-01466'/><category term='OCM logo'/><category term='configure controlfile'/><category term='dba_tablespace_groups'/><category term='select any catalog'/><category term='idle_time'/><category term='GATHER_TABLE_STATS'/><category term='GATHER EMPTY'/><category term='large_pool_size'/><category term='INTERVAL YEAR TO MONTH'/><category term='range partition'/><category term='CONSTRAINED'/><category term='forall'/><category term='ORA-01110'/><category term='Inactive session'/><category term='What is stale statistics'/><category term='ORA-01157'/><category term='resetting HWM in oracle10g'/><category term='compute statistics'/><category term='noreverse'/><category term='DBMS_REDEFINITION'/><category term='memory_max_target'/><category term='proftab.sql'/><category term='METHOD_OPT'/><category term='utl_smtp.connection'/><category term='SP2-0613'/><category term='OPTIMIZER_MODE'/><category term='MULTITHREADING'/><category term='ADD_TABLE_PROPAGATION_RULES'/><category term='star schema'/><category term='SCD'/><category term='utl_smtp.mail'/><category term='ORA-25128'/><category term='utl_smtp.open_data'/><category term='Index'/><category term='DBMS_LOGMNR_D.SET_TABLESPACE(&apos;LOGMNRTS&apos;)'/><category term='GATHER AUTO'/><category term='FTS'/><category term='creating index with statistics'/><category term='resumable timeout'/><category term='factless fact'/><category term='difference between logical standby and physical standby'/><category term='NETWORK_LINK'/><category term='purge dba_recyclebin'/><category term='steps to setup RMAN'/><category term='Execute'/><category term='append'/><category term='Sort-Merge Join'/><category term='SGA_MAX_SIZE'/><category term='line 10640'/><category term='SYS'/><category term='db_recovery_file_dest_size'/><category term='explain_plan'/><category term='BYTE'/><category term='PERSISTENT CONFIGURATION'/><category term='clustering factor'/><category term='Large Amount of Data'/><category term='dead connection deduction'/><category term='recover tablespace'/><category term='sys.col_usage$'/><category term='OPTIMIZER_DYNAMIC_SAMPLING'/><category term='restore tablespace'/><category term='log_file_name_convert'/><category term='rebuild reverse'/><category term='V$SQLAREA'/><category term='Global temporary table'/><category term='standby database'/><category term='DISABLE NOVALIDATE'/><category term='strmadmin'/><category term='sysdba'/><category term='ON COMMIT PRESERVE ROWS'/><category term='gv$parameter'/><category term='SORT_AREA_SIZE'/><category term='run'/><category term='DBA_TAB_PARTITIONS'/><category term='SKEWONLY'/><category term='TABLE_EXISTS_ACTION'/><category term='how does plsql_optimize_level work'/><category term='technique to pass oracle11g OCP exam'/><category term='uncomitted data'/><category term='NL_SJ'/><category term='local index'/><category term='Oracle SQL questions for newbie&apos;s'/><category term='VARCHAR2'/><category term='recover datafile'/><category term='oracle8i constraint stat'/><category term='DBWR'/><category term='memory_target'/><category term='MATCHED'/><category term='SKIP READONLY'/><category term='INSERT'/><category term='dimension'/><category term='GATHER STALE'/><category term='list partition'/><category term='STREAMSIZE'/><category term='Recyclebin'/><category term='difference between ref cursor and normal cursor'/><category term='Oracle9i memory feature'/><category term='startup force'/><category term='learndatamodel'/><category term='OVERFLOW'/><category term='log_archive_dest'/><category term='physical standby database'/><category term='ORADIM'/><category term='db buffers'/><category term='drop database including backups'/><category term='dynamic sampling query'/><category term='GATHER_SCHEMA_STATS'/><category term='use of RMAN backup'/><category term='Automatic shared memory management in oracle10g'/><category term='Saving and restoring old statistics in oracle10g'/><category term='PARAMETER'/><category term='v$version'/><category term='show recyclebin'/><category term='truncate table privilege'/><category term='dbms_flashback.enable_at_system_change_number'/><category term='oracle memory feature'/><category term='autotrace'/><category term='oracle10g performance tuning optimization parameter'/><category term='SYSTEM'/><category term='How do we prepare the oracle11g 1ZO-050 exam'/><category term='/*+ first_rows */'/><category term='SINGLEBYTE'/><category term='Lack of Index'/><category term='COMPRESSION'/><category term='Cache recovery'/><category term='weakly typed ref cursor'/><category term='High water mark'/><category term='READSIZE'/><category term='Cloning Database through RMAN'/><category term='dba_resumabe'/><category term='oracle'/><category term='quick split partitions'/><category term='Hint'/><category term='http://asktom.oracle.com'/><category term='index organized table'/><category term='resource_limit'/><category term='NOT IN (Vs) NOT EXISTS'/><category term='v$sort_segment'/><category term='PGA_AGGREGATE_TARGET'/><category term='MERGE'/><category term='user_subpart_histograms'/><category term='archive log list'/><category term='select any dictionary'/><category term='MERGE_SJ'/><category term='Convert Non-Partitioned to Partitioned Table - using Online Re-definition feature'/><category term='how can i download OCP logo'/><category term='dbms_resumable'/><category term='read consistency'/><category term='private sql area'/><category term='download OCP logo'/><category term='index monitoring'/><category term='configure retention policy'/><category term='shared_pool_size'/><category term='db_recovery_file_dest'/><category term='enable resumable'/><category term='frequency histogram'/><category term='sga_target'/><category term='v$instance'/><category term='create directory'/><category term='oracle streams'/><category term='Good for OLAP'/><category term='Oracle SQL questions'/><category term='DBMS_SPACE.UNUSED_SPACE'/><category term='dbms_datapump'/><category term='Fetch'/><category term='REPEAT'/><category term='automated backup'/><category term='Full table scan'/><category term='WORK_AREA_SIZE_POLICY'/><category term='oracle certified exam'/><category term='ATTACH'/><category term='strongly typed ref cursor'/><category term='java_pool_size'/><category term='ORACLE_DATAPUMP'/><category term='DBMS_STATS.export_schema_stats'/><category term='RMAN auxiliary'/><category term='content of SGA'/><category term='log_archive_format'/><category term='FIRST_ROWS'/><category term='DBMS_STATS.GATHER_SCHEMA_STATS'/><category term='unregister database'/><category term='COLUMNARRAYROWS'/><category term='v$tempfile'/><category term='purge tablespace'/><category term='DBA_PART_TABLES'/><category term='DEFERRABLE'/><category term='semi-join algorithm'/><category term='create pfile'/><category term='scale -84 to 127'/><category term='SHUTDOWN IMMEDIATE'/><category term='SQL * PLUS'/><category term='Nested loop Joins'/><category term='LOCK_SGA'/><category term='plsql_profiler_data'/><category term='nomonitoring'/><category term='dbms_stats.lock_schema_stats'/><category term='CONFIGURE'/><category term='CREATE GLOBAL TEMPORARY TABLE'/><category term='Character and Byte Semantics'/><category term='cursor_sharing = force'/><category term='what is instance recovery in oracle'/><category term='plan_table'/><category term='deferred constraint'/><category term='reclaim the wasted space in a segment'/><category term='configure default device'/><category term='when do we use ALL_ROWS'/><category term='archived redo log'/><category term='v$sga_ops_resize'/><category term='INTERVAL DAY TO SECOND'/><category term='MOUNT STANDBY'/><category term='dbms_space.space_usage'/><category term='user_objects'/><category term='plsql_profiler_runs'/><category term='send email'/><category term='space_error_info'/><category term='POL'/><category term='flashback_transaction_query'/><title type='text'>My Oracle</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>75</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-8082907770496013668</id><published>2010-03-17T09:42:00.002-07:00</published><updated>2010-03-29T13:22:58.920-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DB_CACHE_ADVICE'/><category scheme='http://www.blogger.com/atom/ns#' term='SGA_MAX_SIZE'/><category scheme='http://www.blogger.com/atom/ns#' term='PGA_AGGREGATE_TARGET'/><category scheme='http://www.blogger.com/atom/ns#' term='V$DB_CACHE_ADVICE'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle9i memory feature'/><category scheme='http://www.blogger.com/atom/ns#' term='WORK_AREA_SIZE_POLICY'/><title type='text'>Memory Parameters in oracle9i</title><content type='html'>&lt;span style="color:#ff0000;"&gt;Oracle9i new features on Memory Management :&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1.&lt;/span&gt; Oracle9i introduced new parameter PGA_AGGREGATE_TARGET to tune portion of the memory in PGA. This new parameter dynamically adjust sort_area_size, hash_area_size, create_bitmap_area_size and bitmap_merge_area_size. The WORK_AREA_SIZE_POLICY should be set to AUTO to enable this feature.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2.&lt;/span&gt; Prior to oracle9i, shared pool size was static parameter. DBA has to restart the instance if shared pool size parameter needs to be changed. But in oracle9i introduced a new capability to change the shared_pool_size parameter dynamically without restarting the instance. But this parameter size should be less than or equal to SGA_MAX_SIZE.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3.&lt;/span&gt; Oracle9i introduced new approach to determine how the buffer cache is being using and how much memory has to be added or released from the buffer cache for optimal performance. Here are the steps to enable to feature.&lt;br /&gt;&lt;br /&gt;a) Set the DB_CACHE_ADVICE parameter to ON. It gather statistics on the buffer cache by setting the value of this parameter. This is dynamic paramter and can be changed by using ALTER SYSTEM command.&lt;br /&gt;&lt;br /&gt;b) Display the statistics gathered by querying the new dynamic performance view, V$DB_CACHE_ADVICE. This view contains information about the physical reads for the different cache sizes.&lt;br /&gt;&lt;br /&gt;select id, name, block_size,buffers_for_estimate, estd_physical_reads, estd_physical_read_factor from v$db_cache_advice&lt;br /&gt;&lt;br /&gt;c) We can change the buffer cache size based on the observation in step b.&lt;br /&gt;&lt;br /&gt;The source of this article is &lt;a href="http://www.oracle.com/technology/products/oracle9i/daily/dec31.html"&gt;click&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here are other related link to this topic.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://myorastuff.blogspot.com/2010/03/memory-parameter-in-oracle10g.html"&gt;Oracle10g Memory feature&lt;/a&gt;&lt;br /&gt;&lt;a href="http://myorastuff.blogspot.com/2010/03/memory-parameter-in-oracle11g.html"&gt;Oracle11g Memory feature&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.blogger.com/Oracle%20Memory%20components"&gt;Oracle Memory components&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-8082907770496013668?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/8082907770496013668/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=8082907770496013668' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/8082907770496013668'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/8082907770496013668'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2010/03/memory-parameters-in-oracle9i.html' title='Memory Parameters in oracle9i'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-3029827547797019455</id><published>2010-03-17T09:42:00.001-07:00</published><updated>2010-03-29T15:36:35.946-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sga_target'/><category scheme='http://www.blogger.com/atom/ns#' term='SGA_MAX_SIZE'/><category scheme='http://www.blogger.com/atom/ns#' term='db_cache_size'/><category scheme='http://www.blogger.com/atom/ns#' term='Automatic shared memory management in oracle10g'/><category scheme='http://www.blogger.com/atom/ns#' term='shared_pool_size'/><category scheme='http://www.blogger.com/atom/ns#' term='v$sga_ops_resize'/><category scheme='http://www.blogger.com/atom/ns#' term='streams_pool_size'/><category scheme='http://www.blogger.com/atom/ns#' term='large_pool_size'/><category scheme='http://www.blogger.com/atom/ns#' term='java_pool_size'/><title type='text'>Memory Parameter in Oracle10g</title><content type='html'>&lt;span style="color:#ff0000;"&gt;Oracle10g new feature on Memory Management :&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Oracle10g introduced memory management feature to make DBA's life much easy. Automatic shared memory management(ASMM) is another self management enhancement in oracle10g. In previous release of oracle, we had to manually configure the shared pool size, java pool size, large pool size and data base buffer cache. It was often challenge to optimally configure these components because sizing them too small could cause memory errors and sizing them too large could lead to waste of memory.&lt;br /&gt;&lt;br /&gt;In oracle10g, you need to specify only the SGA_TARGET parameter, which specifies the total size of the SGA. Individual components of the SGA are automatically allocated by the database based on the workload and history information. so during the normal online operations,the buffer cache and java pool may be bigger. During the batch window, the database can automatically increase the large pool and reduce the buffer cache.&lt;br /&gt;&lt;br /&gt;When ASMM is enabled, then the following memory pools are automatically sized:&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1 .Buffer cache (DB_CACHE_SIZE)&lt;br /&gt;2. Shared pool (SHARED_POOL_SIZE)&lt;br /&gt;3. Large pool (LARGE_POOL_SIZE)&lt;br /&gt;4. Java pool (JAVA_POOL_SIZE) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If above automatically tuned memory pools are set to non-zero values, then those values are used as minimum levels by Automatic Shared Memory Management. You would set minimum values if an application component needs a minimum amount of memory to function properly.&lt;br /&gt;&lt;br /&gt;The following pools are manually sized components and are not affected by ASMM.&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. DB_KEEP_CACHE_SIZE&lt;br /&gt;2. DB_RECYCLE_CACHE_SIZE&lt;br /&gt;3. DB_nK_CACHE_SIZE (non-default block size)&lt;br /&gt;3. STREAMS_POOL_SIZE&lt;br /&gt;4. LOG_BUFFER &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;For instance, SGA_TARGET is 400MB, LOG_BUFFER is 1M, DB_KEEP_CACHE_SIZE is 50M, then the memory available for automatically configured components is 349MB.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Questions and Answers :&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. How does ASMM work?&lt;/span&gt; ASMM automatically allocate the memory based on the work load and type of DB activities. We do not need to size the SGA parameters. The sga_target parameter will not dynamically manage all the sub component of the SGA memory. Some of the memory areas need to be sized by DBA as i explained above.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2. How do we switch the DB from non-ASMM to ASMM?&lt;/span&gt; Switching to ASSM can be done by changing SGA_TARGET parameter to non-zero value. STATISTICS_LEVEL should be TYPICAL or ALL. We need to allocate proper memory size for SGA_TARGET parameter. But this should not be greater then SGA_MAX_SIZE. Again, we need to reset the automatically tunable memory parameter to zero or minimum values. If we set minimum values for automatically tuned parameters, then oracle always maintain the minimum values all the time.&lt;br /&gt;&lt;br /&gt;Here my DB is running in Non-ASMM. Let us switch this to ASMM.&lt;br /&gt;&lt;br /&gt;SQL&gt; select name,value from v$parameter where&lt;br /&gt;2 name in('shared_pool_size','large_pool_size','java_pool_size','db_cache_size','sga_target');&lt;br /&gt;&lt;br /&gt;NAME VALUE&lt;br /&gt;------------------------------ ------------------------------&lt;br /&gt;shared_pool_size 163577856&lt;br /&gt;large_pool_size 4194304&lt;br /&gt;java_pool_size 4194304&lt;br /&gt;db_cache_size 432013312&lt;br /&gt;sga_target 0&lt;br /&gt;&lt;br /&gt;SQL&gt; alter system set sga_target=1000M scope=both;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter system set shared_pool_size=500M scope=both;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; show sga&lt;br /&gt;&lt;br /&gt;Total System Global Area 1048576000 bytes&lt;br /&gt;Fixed Size 1252976 bytes&lt;br /&gt;Variable Size 553648528 bytes&lt;br /&gt;Database Buffers 486539264 bytes&lt;br /&gt;Redo Buffers 7135232 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;Database opened.&lt;br /&gt;&lt;br /&gt;SQL&gt; select target_size from v$sga_resize_ops&lt;br /&gt;2 where component='shared pool';&lt;br /&gt;&lt;br /&gt;TARGET_SIZE&lt;br /&gt;-----------&lt;br /&gt;528482304&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now SGA parameters will be automatically tuned based on the workload and DB activities. But it always retain the minimum values, since we set shared_pool_size, large_pool_size, java_pool_size, db_cache_size set to non-zero values. &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;3. How do we disable ASMM?&lt;/span&gt; Disabling ASSM can be done by chaning SGA_TARGET parameter to zero value. But we need to set the below parameter with proper sizing when we disable ASMM&lt;/p&gt;1. shared_pool_size&lt;br /&gt;2. large_pool_size&lt;br /&gt;3. java_pool_size&lt;br /&gt;4. db_cache_size&lt;br /&gt;&lt;br /&gt;SQL&gt; alter system set sga_target=0 scope=both;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;System altered.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;4. When do we think that, ASMM should be disabled in oracle10g?&lt;/span&gt; We can disable ASMM if there is significant amount of memory resizing activity that cause the performance issue in database. This frequent memory resizing might happen when the environment is mixed of DSS and OLTP environment.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;5. What is the best environment to enable the ASMM feature?&lt;/span&gt; Based on my knowledge, i would recommend to go for ASMM feature when DB is running on OLTP mode during the day time and DB is running on DSS more during the night time. In this scenario, ASMM feature will resize the memory based on the DB activities. DBA does not need to resize the memory for day time and night time differently.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Here are the relevant link to this topic.&lt;/p&gt;&lt;p&gt;&lt;a href="http://myorastuff.blogspot.com/2010/03/memory-parameter-in-oracle11g.html"&gt;Oracle9i Memory feature&lt;br /&gt;Oracle11g Memory feature&lt;/a&gt;&lt;br /&gt;&lt;a href="http://myorastuff.blogspot.com/2010/03/oracle-memory-management.html"&gt;Oracle Memory components&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-3029827547797019455?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/3029827547797019455/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=3029827547797019455' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/3029827547797019455'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/3029827547797019455'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2010/03/memory-parameter-in-oracle10g.html' title='Memory Parameter in Oracle10g'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-8355733972615604103</id><published>2010-03-16T17:10:00.000-07:00</published><updated>2010-04-04T06:31:28.702-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='df -k /dev/shm'/><category scheme='http://www.blogger.com/atom/ns#' term='LOCK_SGA'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-00845: MEMORY_TARGET not supported on this system'/><category scheme='http://www.blogger.com/atom/ns#' term='memory_target'/><category scheme='http://www.blogger.com/atom/ns#' term='memory_max_target'/><category scheme='http://www.blogger.com/atom/ns#' term='AMM feature in oracle11g'/><title type='text'>Memory Parameter in Oracle11g</title><content type='html'>Oracle is enhancing the memory management in each version starting from oracle9i. Oracle9i introduced pga_aggregate_target to dynamically manage the memory for PGA. Oracle went one step further in 10g and introduced sga_target parameter to dynamically allocate the SGA memory. Oracle introduced memory_target parameter in oracle11g and dynamically allocate both SGA and PGA memory. This is one of exciting features that takes care of SGA as well as PGA in one parameter. We let Oracle to adjust the memory as the workload needs it.&lt;br /&gt;&lt;br /&gt;I would like to write how this memory parameter works in oracle11g. How the memory is configured on each sub component when memory_target parameter is set to non zero?&lt;br /&gt;&lt;br /&gt;Oracle11g introduced two memory parameters(memory_target, memory_max_target). oracle has become smart as in exchanging memory between SGA and PGA. This feature helps DBA to allocate chunk of memory to a particular instance without worrying about the subcateogary allocations of different components.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Question and Answers :&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;1. What is the advantage of memory_target parameter?&lt;/span&gt; I do not see any reason to not to use this memory management parameter. If we set this parameter, then we do not need to size all other sub component of this parameter. Sub component parameters are like SGA_TARGET, PGA_AGGREGATE_TARGET etc. These memory area can be managed dynamically.&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;2. What is the best place to leverage this feature? &lt;/span&gt;If your database running in mixed load, Oracle will adjust all your memory setting accordingly to DB load. Let us say, your database is running on OLTP mode in the day time, and running batch job during the night time. DBA can not adjust the different component of the memory according to Database activity. This memory_target parameter balance the memory between shared_pool_size, redolog_buffer, large_pool_size, java_pool_size etc. This is ideal scenario to use this feature.&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;3. How do we enable AMM feature ?&lt;/span&gt; This feature can be enabled by setting memory_target and max_memory_target to non-zero values. LOCK_SGA parameter should be set to FALSE to enable this feature.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;4. How do we disable AMM feature ?&lt;/span&gt; This feature can be disabled by setting zero for memory_target parameter. Please remember, sga_target, pga_aggregate_target parameter should be sized according to DB activities.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;5. Do we need to check the Shared memory in server before implementing AMM?&lt;/span&gt; &lt;span style="color:#000000;"&gt;Yes. We need to check the current size of your shared memory file system before we set the AMM feature. On linux, we need to use the below command to check the shared memory.&lt;/span&gt; &lt;/p&gt;&lt;p&gt;[oracle@rate9812~]$ df -k /dev/shm &lt;/p&gt;&lt;p&gt;Filesystem 1k-blocks Used Available Use% Mounted on tmpfs &lt;/p&gt;&lt;p&gt;2023256 1065000 958256 53% /dev/shm &lt;/p&gt;&lt;p&gt;[oracle@rate9812~]$&lt;/p&gt;&lt;p&gt;Here the shared memory is around 2GB. So the memory target can be more than 2GB. If it is more than 2GB, the we get the below error.&lt;/p&gt;&lt;p&gt;ORA-00845: MEMORY_TARGET not supported on this system &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;6. Do we have any new data dictionary views to monitor AMM? &lt;/span&gt;&lt;span style="color:#000000;"&gt;Yes. we do have new views. Here are some. These views helps to monitor the Memory utilization.&lt;/span&gt; &lt;/p&gt;&lt;p&gt;V$MEMORY_CURRENT_RESIZE_OPS&lt;br /&gt;V$MEMORY_DYNAMIC_COMPONENTS&lt;br /&gt;V$MEMORY_RESIZE_OPS&lt;br /&gt;V$MEMORY_TARGET_ADVICE&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;6. How does this feature differ from Oracle10g memory feature? &lt;/span&gt;&lt;span style="color:#000000;"&gt;This parameter covers both SGA and PGA. In Oracle10g, we use individual parameter for SGA and PGA. Now it is not required to define or size the memory for SGA and PGA seperately.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;span style="color:#ff0000;"&gt;7.&lt;/span&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;&lt;span style="color:#ff0000;"&gt;Do we need to take care of any memory parameters after AMM feature is enabled? &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Log buffer and the non-default block size caches not part of dynamic memory allocation. These memory should be taken care manually.  &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;The new data dictionary V$MEMORY_DYNAMIC_COMPONENTS will give the list of components which is taken care by database when we enable AMM feature.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Here are relevant topic to this article.&lt;/p&gt;&lt;p&gt;&lt;a href="http://myorastuff.blogspot.com/2010/03/memory-parameters-in-oracle9i.html"&gt;Oracle9i Memory feature&lt;/a&gt;&lt;br /&gt;&lt;a href="http://myorastuff.blogspot.com/2010/03/memory-parameter-in-oracle10g.html"&gt;Oracle10g Memory feature&lt;/a&gt;&lt;br /&gt;&lt;a href="http://myorastuff.blogspot.com/2010/03/oracle-memory-management.html"&gt;Oracle Memory components&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-8355733972615604103?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/8355733972615604103/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=8355733972615604103' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/8355733972615604103'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/8355733972615604103'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2010/03/memory-parameter-in-oracle11g.html' title='Memory Parameter in Oracle11g'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-3040957347620241377</id><published>2010-03-09T19:43:00.001-08:00</published><updated>2010-03-28T10:52:58.940-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='variable size'/><category scheme='http://www.blogger.com/atom/ns#' term='pga'/><category scheme='http://www.blogger.com/atom/ns#' term='fixed size'/><category scheme='http://www.blogger.com/atom/ns#' term='content of SGA'/><category scheme='http://www.blogger.com/atom/ns#' term='redo buffers'/><category scheme='http://www.blogger.com/atom/ns#' term='private sql area'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle memory structure'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle memory feature'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle memory components'/><category scheme='http://www.blogger.com/atom/ns#' term='content of PGA'/><category scheme='http://www.blogger.com/atom/ns#' term='sga'/><category scheme='http://www.blogger.com/atom/ns#' term='db buffers'/><title type='text'>Oracle Memory Management</title><content type='html'>It has been a few months since i added a new post in my blog. I moved to Austin, TX last December 2009 and since that time, i have been busy with my new job, settling down with new place, buying new home etc. I am going to discuss about Oracle Memory components and their function of each component. I am writing this article based on my experience, reading oracle websites, books and other blogs.&lt;br /&gt;&lt;br /&gt;First let me explain about each memory component in oracle. Oracle Memory is divided into two portion. One is System Global Area(SGA) and another one is Program Global Area(PGA). Let us now discuss about SGA now. Then we will talk about PGA in the later portion of this article.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;System Global Area &lt;/span&gt;&lt;/strong&gt;consists of following Memory component.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. Fixed size&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2. Variable size&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3. DB Buffer cache&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;4. Redo log buffer&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production&lt;br /&gt;With the Partitioning option&lt;br /&gt;&lt;br /&gt;SQL&gt; show sga&lt;br /&gt;&lt;br /&gt;Total System Global Area 1654013952 bytes&lt;br /&gt;Fixed Size 2103048 bytes&lt;br /&gt;Variable Size 1342179576 bytes&lt;br /&gt;Database Buffers 301989888 bytes&lt;br /&gt;Redo Buffers 7741440 bytes&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;SGA = Fixed size + Variable size + DB buffers + Redo buffers&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What is Fixed size?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;The size of the fixed portion is constant for a release and a platform of Oracle, that is, it cannot be changed through any means such as altering the initialization parameters. This memory varies in size from platform to platform and release to release. This is something over which we have no control and it is generally very small. Think of this area as a bootstrap section of the SGA, something Oracle uses internally to find the other bits and pieces of the SGA.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What is Variable size?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Variable size is sum of shared pool, java pool, large pool and streams pool. The streams pool is added in oracle10g.&lt;br /&gt;&lt;br /&gt;Shared pool = library cache + dictionary cache&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Variable size = Shared pool + Java pool + large pool + streams pool&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Let us briefly talk about each component in variable size. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Shared pool : It consists of Library cache and Dictonary cache. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The library cache stores shared SQL, caching the parse tree and the execution plan for every unique SQL statement. If multiple applications issue the same SQL statement, each application can access the shared SQL area. This reduces the amount of memory needed and reduces the processing-time used for parsing and execution planning.&lt;br /&gt;&lt;br /&gt;The dictionary cache stores dictionary information in order to parse the SQL statement. It also contains user information, integrity constraints defined for tables etc.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Java pool : &lt;span style="color:#000000;"&gt;It is used for &lt;/span&gt;&lt;span style="color:#000000;"&gt;caching parsed java programs. &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Large pool :&lt;/span&gt; is used in shared/MTS server systems for session memory, by parallel execution for message buffers, and by RMAN backup processes for disk I/O buffers.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Stream pool :&lt;/span&gt; is used for streams.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What is DB buffer cache?&lt;/span&gt; It stores the recently executed database blocks. When other user fires the same query, oracle reads from buffer cache instead of accessing physical files.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What is Redo log buffer? &lt;/span&gt;&lt;span style="color:#000000;"&gt;It stores all the changes made in the database. It will be stored in archive log files for recovery purpose.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Please &lt;a href="http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/memory.htm#i10093"&gt;click&lt;/a&gt; to know more info about SGA&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Program Global Area(PGA)&lt;/strong&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;A PGA is allocated by Oracle when a user connects to an Oracle database and a session is created. PGA contains session information and Private SQL area. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;Content of PGA :&lt;br /&gt;&lt;br /&gt;1. Session information. For instance, Logon info, session related info.&lt;br /&gt;&lt;br /&gt;2. Private SQL area. Please remember, this is part of PGA only if the DB is dedicated server. This memory will be part of SGA if the DB is shared server. Private SQL area contains informatoin about the cursor, query execution status info, sql work area(sort area). &lt;span style="color:#000000;"&gt;Please &lt;a href="http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/memory.htm#i14490"&gt;click &lt;/a&gt;here to know more about PGA memory.&lt;br /&gt;&lt;br /&gt;Oracle keep introducing new features in the memory management side to make DBA's life easy.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Let us talk about new oracle memory management features in each new version since from Oracle9i.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. &lt;a href="http://myorastuff.blogspot.com/2010/03/memory-parameters-in-oracle9i.html"&gt;Oracle9i Feature&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;span style="color:#ff0000;"&gt;2. &lt;a href="http://myorastuff.blogspot.com/2010/03/memory-parameter-in-oracle10g.html"&gt;Oracle10g Feature&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;span style="color:#ff0000;"&gt;3. &lt;a href="http://myorastuff.blogspot.com/2010/03/memory-parameter-in-oracle11g.html"&gt;Oracle11g Feature&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;&lt;span style="color:#ff0000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-3040957347620241377?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/3040957347620241377/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=3040957347620241377' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/3040957347620241377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/3040957347620241377'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2010/03/oracle-memory-management.html' title='Oracle Memory Management'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-1227763240775799490</id><published>2009-11-08T07:03:00.001-08:00</published><updated>2009-11-08T17:32:55.995-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dynamic sampling query'/><category scheme='http://www.blogger.com/atom/ns#' term='dynamic sampling levels in oracle10g'/><category scheme='http://www.blogger.com/atom/ns#' term='what is dynamic sampling query in oracle'/><category scheme='http://www.blogger.com/atom/ns#' term='OPTIMIZER_DYNAMIC_SAMPLING'/><category scheme='http://www.blogger.com/atom/ns#' term='dynamic_sampling hint'/><title type='text'>Dynamic Sampling in Oracle</title><content type='html'>I started my career with oracle 7.0 and i remember, in oracle7.x/8.x version, optimizer use Rule based optimizer if one or all of the tables does not have any statistics in the join query. In oracle9i R2, dynamic sampling query is introduced and it has ability to sample the table and collect the better statistics dynamically during the hard parse. This sampling takes place only at hard parse time and is used to dynamically generate better statistics for the optimizer to use, hence the name dynamic sampling.&lt;br /&gt;&lt;br /&gt;Oracle optimizer use the default statistic values when table does not have any statistics and dynamic sampling query feature is disabled. The default statistics values are well documented in &lt;a href="http://download.oracle.com/docs/cd/B28359_01/server.111/b28274/stats.htm#i41866"&gt;Performance Tuning Guide&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we set Dynamic sampling parameter? &lt;/span&gt;&lt;span style="color:#000000;"&gt;There are couple of ways, we can set the parameter.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. We can set this in session level or instance level.&lt;br /&gt;2. Dynamic sampling query hint in query level. (&lt;u&gt;&lt;span style="color:#800080;"&gt;&lt;a href="http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/sql_elements006.htm#SQLRF50913"&gt;Hint&lt;/a&gt;&lt;/span&gt;&lt;/u&gt;)&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; alter session set OPTIMIZER_DYNAMIC_SAMPLING = 2;&lt;br /&gt;&lt;br /&gt;Session altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter system set OPTIMIZER_DYNAMIC_SAMPLING = 2;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; select /*+ dynamic_sampling(emp 0) */ * from scott.emp;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;When does dynamic sampling is useful? &lt;/span&gt;&lt;br /&gt;1. It is useful when table data is drastically changing and statistic becomes stale very often.&lt;br /&gt;2. Global temporary table is good place to use dynamic sampling feature.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Dynamic sampling Levels? &lt;/span&gt;&lt;span style="color:#000000;"&gt;Optimizer Dynamic Sampling has 11 levels between 0 to 10. What are these levels? The answer is pretty straight forward and it is clearly documented in &lt;a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/stats.htm#i43032"&gt;Oracle Performance Tuning Guide&lt;/a&gt;. In Oracle9i R2, the default setting for dynamic sampling level is 1.&lt;/span&gt; At this setting, the optimizer will tend to use dynamic sampling only in some cases when a table is unanalyzed. This includes the case of global temporary tables without statistics but doesn’t ensure that dynamic sampling will be used against all unanalyzed tables. In Oracle Database 10g Release 1 and above, the default setting is 2. This setting ensures that the optimizer will have a good estimate whenever it optimizes a query that accesses a table with no statistics.&lt;br /&gt;&lt;br /&gt;The source of this Article is &lt;a href="http://www.oracle.com/technology/oramag/oracle/09-jan/o19asktom.html"&gt;Asktom&lt;/a&gt;. Please read this link and this link has very pretty good information about Dynamic sampling.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-1227763240775799490?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/1227763240775799490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=1227763240775799490' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1227763240775799490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1227763240775799490'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/11/dynamic-sampling-in-oracle.html' title='Dynamic Sampling in Oracle'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-1559576626935818209</id><published>2009-11-04T09:06:00.000-08:00</published><updated>2009-11-11T19:09:29.609-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DBMS_STATS.RESTORE_TABLE_STATS'/><category scheme='http://www.blogger.com/atom/ns#' term='Saving and restoring old statistics in oracle10g'/><category scheme='http://www.blogger.com/atom/ns#' term='GET_STATS_HISTORY_AVAILABILITY'/><category scheme='http://www.blogger.com/atom/ns#' term='ALTER_STATS_HISTORY_RETENTION'/><title type='text'>Restoring old statistics</title><content type='html'>I see some DBA's, they won't backup the statistics before collect the new statistics. If we don't have backup, and optimizer behaves differently with new statistics, then we are in trouble. If we have old statistic backup, then we can resolve the performance issue by restoring the old statistics. Oracle highly recommends to take the backup of current statistics before we collect new statistics.&lt;br /&gt;&lt;br /&gt;Oracle10g has a new feature which will save the statistics before overwriting the new statistics.&lt;br /&gt;&lt;br /&gt;There are couple of ways, we can backup the statistics.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. We can export the statistics in a table and import back when ever we need. I discussed this approach in different thread. This approach is mostly useful when we transfer the statistics from one server to another server. Please refer this thread &lt;/span&gt;&lt;a href="http://myorastuff.blogspot.com/2009/10/transfering-statistics-between-database.html"&gt;&lt;span style="color:#000000;"&gt;Post&lt;/span&gt;&lt;/a&gt;&lt;span style="color:#ff0000;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2. Since Oracle10g, whenever statistics are modified, old version of statistics are saved automatically before overwriting the new statistics. However automatic saving of old statistics will not take place if you use ANALYZE in 10g for statistics collection.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I am going to discuss how the statistics are saved and how do we restore the old statistics in Approach 2.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Where does oracle store the statistics? &lt;/span&gt;&lt;span style="color:#000000;"&gt;Oracle DBA_OPTSTAT_OPERATIONS table contains a log history of statistics collected on the database at various level such as table, schema or database. We can restore older statistics anytime by making use of START_TIME and END_TIME values from DBA_OPTSTAT_OPERATIONS table.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How does Oracle maintain the Statistics History? &lt;/span&gt;GET_STATS_HISTORY_AVAILABILITY is a Function in DBMS_STATS package that returns oldest timestamp where statistics history is available. Users cannot restore statistics to a time stamp older than the oldest time stamp. Here is the query to find the statistics history starting timestamp.&lt;br /&gt;SQL&gt; select dbms_stats.get_stats_history_availability from dual;&lt;br /&gt;&lt;br /&gt;GET_STATS_HISTORY_AVAILABILITY&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;06-OCT-09 09.52.45.351000000 PM -05:00&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;Oracle maintain the history statistics based on the retention value. Oracle Purge the statistics automatically if it exceeds the statistics retention setting. By defualt, oracle purge the statistics if it is older then 31 days. We can also alter this retention period by using DBMS_STATS.ALTER_STATS_HISTORY_RETENTION procedure. PURGE_STATS is procedure in DBMS_STATS package that enables you to manually purge old statistics beyond a time stamp.&lt;br /&gt;&lt;br /&gt;SQL&gt; execute dbms_stats.alter_stats_history_retention(20);&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;As per the above code, oracle keep 20 days statistics history.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; execute dbms_stats.purge_stats('06-OCT-09 09.52.45.351000000 PM -05:00');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;As per the above code, oracle purge the statistics prior to 06-OCT-09.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we recover the statistics? &lt;/span&gt;Oracle RESTORE_TABLE_STATS procedure restores statistics of a table as of a specified timestamp. It also restores the statistics of associated indexes and columns.  Let me take EMP table in scott Schema and restore previous statistics.&lt;br /&gt;&lt;br /&gt;Here are the steps to restore the previous timestamp statistics:&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step1:&lt;/span&gt;  Let us check the past statistics and what date the statistics were collected.&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; select STATS_UPDATE_TIME from dba_tab_stats_history where table_name='EMP';&lt;br /&gt;&lt;br /&gt;STATS_UPDATE_TIME&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;30-OCT-09 06.25.54.809000 PM -04:00&lt;br /&gt;07-NOV-09 07.23.23.504000 AM -05:00&lt;br /&gt;07-NOV-09 07.27.31.709000 AM -05:00&lt;br /&gt;07-NOV-09 07.29.54.324000 AM -05:00&lt;br /&gt;&lt;br /&gt;SQL&gt; select last_analyzed from dba_tables where&lt;br /&gt;  2  table_name='EMP' and owner='SCOTT';&lt;br /&gt;&lt;br /&gt;LAST_ANAL&lt;br /&gt;---------&lt;br /&gt;11-NOV-09&lt;br /&gt;&lt;br /&gt;SQL&gt; select sysdate from dual;&lt;br /&gt;&lt;br /&gt;SYSDATE&lt;br /&gt;---------&lt;br /&gt;11-NOV-09&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step2 :&lt;/span&gt;  Let us restore the statistics which we collected on 30-OCT-2009.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;SQL&gt; execute dbms_stats.restore_table_stats('SCOTT','EMP','30-OCT-09 06.25.54.809000 PM -04:00');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; select last_analyzed from dba_tables where&lt;br /&gt;  2  table_name='EMP' and owner='SCOTT';&lt;br /&gt;&lt;br /&gt;LAST_ANAL&lt;br /&gt;---------&lt;br /&gt;30-OCT-09&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;At what circumstances, do we restore the Statistics? &lt;/span&gt;We have performance issue in the database and DB was fine yesterday and since yesterday, there is no major change on database. Oracle10g automatic statistic gathering is turned on and last statistics gathering was close to the time that users started complanining about performance. At this circumstances, may be new statistics could be a culprit. We can restore the old statistics and see if we have any performance issue.&lt;br /&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Restriction on restoring the statistics: &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;1. &lt;/span&gt;It does not have ability to restore user-defined statistics.&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;2.&lt;/span&gt; Old statistics will not be saved if we use ANALYZE command to gather statistics. Hence, we can recover the statistics.&lt;/p&gt;&lt;p&gt;Here is the input(&lt;a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/stats.htm#i41814"&gt;Help&lt;/a&gt;) to write this topic.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-1559576626935818209?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/1559576626935818209/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=1559576626935818209' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1559576626935818209'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1559576626935818209'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/11/restoring-old-statistics.html' title='Restoring old statistics'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-6656423651302903892</id><published>2009-11-02T12:41:00.000-08:00</published><updated>2009-11-12T13:42:55.815-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dbms_stats.get_param'/><category scheme='http://www.blogger.com/atom/ns#' term='DBMS_STATS.GATHER_DATABASE_STATS_JOB_PROC'/><category scheme='http://www.blogger.com/atom/ns#' term='DBMS_SCHEDULER.DISABLE'/><category scheme='http://www.blogger.com/atom/ns#' term='what is automatic statistics gathering in oracle10g'/><category scheme='http://www.blogger.com/atom/ns#' term='GATHER_STATS_JOB'/><category scheme='http://www.blogger.com/atom/ns#' term='set_param'/><category scheme='http://www.blogger.com/atom/ns#' term='DBMS_SCHEDULER.ENABLE'/><title type='text'>Automatic Statistics Gathering in Oracle10g</title><content type='html'>Oracle10g has one of the automated feature which is called &lt;span style="color:#ff0000;"&gt;Automatic Statistics gathering.&lt;/span&gt;&lt;span style="color:#000000;"&gt; Oracle gathers statistics on all database objects automatically and maintains those statistics in a regularly scheduled maintenance job. When the DB is created, job is automatically created and started to collect statistics on database object with missing or stale statistics. &lt;/span&gt;The job GATHER_STATS_JOB calls the procedure dbms_stats.gather_database_stats_job_proc to gather statistics during the maintenance window.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;What does GATHER_DATABASE_STATS_JOB_PROC do?&lt;/span&gt;&lt;span style="color:#000000;"&gt; Unfortunately, the package body is wrapped, so without access to the original source code, the implementation details are obscured. &lt;/span&gt;&lt;span style="color:#000000;"&gt;This procedure collects statistics on database objects when the object has no previously gathered statistics or the existing statistics are stale because the underlying object has been modified significantly (more than 10% of the rows).&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;This is an internal procedure, but its operates in a very similar fashion to the DBMS_STATS.GATHER_DATABASE_STATS procedure using the GATHER AUTO option. The primary difference is that the DBMS_STATS.GATHER_DATABASE_STATS_JOB_PROC procedure prioritizes the database objects that require statistics, so that those objects which most need updated statistics are processed first. This ensures that the most-needed statistics are gathered before the maintenance window closes.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;How do we enable this feature?&lt;/span&gt; Automatic statistics gathering is enabled by default when a database is created, or when a database is upgraded from an earlier database release. The following condition should be met to enable this feature.&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;1. GATHER_STATS_JOB should be enabled.&lt;br /&gt;2. statistics_level should be TYPICAL or ALL. &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;We can enable the job as below when the job is already disabled for any reason.&lt;/p&gt;&lt;p&gt;&lt;a name="40698"&gt;&lt;/a&gt;&lt;span style="color:#000000;"&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; connect sys/password@orcl as sysdba&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; BEGIN&lt;br /&gt;2 DBMS_SCHEDULER.ENABLE('GATHER_STATS_JOB');&lt;br /&gt;3 END;&lt;br /&gt;4 /&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;What time does automatic statistic collection run? &lt;/span&gt;&lt;span style="color:#000000;"&gt;By default this job runs within a maintenance window between 10 P.M to 6 A.M week nights and all day on weekends. But in oracle11g, i believe, the maintenance window is not same as Oracle10g.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Do we need to collect statistics in other then the scheduled window? &lt;/span&gt;&lt;span style="color:#000000;"&gt;In few Scenario's, it would be required to gather statistics manually.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;&lt;span style="color:#ff0000;"&gt;1. &lt;/span&gt;&lt;span style="color:#000000;"&gt;In &lt;/span&gt;some cases, we might need to collect the statistics in specific objects other than this maintenance window. If the table data are changed rapidly and optimizer behaves differently due to data changes, then we need to gather statistics manually. We can not wait till the maintenance window open. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;&lt;span style="color:#ff0000;"&gt;2.&lt;/span&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;If the table is bigger and it is failing in the maintenance window for some reason, then you can lock that table during the maintenance window and unlock the table and gather the statistics manually and lock back again.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;3.&lt;/span&gt; If you have specific table and you want to gather statistics with different option, then you can lock those tables during the maintenance window and gather statistics manually during day time.&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Should we change the parameter values in Automatic statistic collection? &lt;/span&gt;&lt;span style="color:#000000;"&gt;Oracle recommends not to change the default values for automatic statistics collection. In case, if you need to gather statistics something differently, then lock the table during the maintenance window and unlock the table and gather statistics manually with specfic parameter and lock the table back again. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;We have &lt;a href="http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_stats.htm#i1048775"&gt;get_param&lt;/a&gt; function to find out the parameter values. Also &lt;a href="http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_stats.htm#i1048566"&gt;set_param &lt;/a&gt;procedure to change the default values for dbms_stats pacakge parameters.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-6656423651302903892?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/6656423651302903892/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=6656423651302903892' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/6656423651302903892'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/6656423651302903892'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/11/automatic-statistics-gathering-in.html' title='Automatic Statistics Gathering in Oracle10g'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-2035876847685270244</id><published>2009-10-30T19:19:00.000-07:00</published><updated>2009-11-12T10:17:36.369-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='user_ind_statistics'/><category scheme='http://www.blogger.com/atom/ns#' term='creating index with statistics'/><category scheme='http://www.blogger.com/atom/ns#' term='creating index in oracle10g with statistics'/><category scheme='http://www.blogger.com/atom/ns#' term='dbms_stats.gather_index_stats'/><category scheme='http://www.blogger.com/atom/ns#' term='gather statistics while creating index in oracle'/><category scheme='http://www.blogger.com/atom/ns#' term='compute statistics'/><title type='text'>Compute Oracle Index Statistics</title><content type='html'>&lt;span style="color:#ff0000;"&gt;&lt;span style="color:#000000;"&gt;Many times, we forget to gather index statistics after creating the index. Optimizer will not use the index effectively if index does not have  statistics.&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Prior to Oracle9i, we have to issue two commands for creating index and gathering index statistics.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; create index idx on test(object_name);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; exec dbms_stats.gather_index_stats(null, 'IDX');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Starting in Oracle 9i, we have a &lt;strong&gt;compute statistics&lt;/strong&gt; clause. We can both creating index and gathering index statistics in one command.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP and Oracle Data Mining options&lt;br /&gt;JServer Release 9.2.0.8.0 - Production&lt;br /&gt;&lt;br /&gt;SQL&gt; create table test as select * from user_objects;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt; create index idx on test(object_name);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; select table_name, num_rows, last_analyzed&lt;br /&gt;2 from user_tables&lt;br /&gt;3 where table_name ='TEST'&lt;br /&gt;4 /&lt;br /&gt;&lt;br /&gt;TABLE_NAME NUM_ROWS LAST_ANAL&lt;br /&gt;------------------------------ ---------- ---------&lt;br /&gt;TEST&lt;br /&gt;&lt;br /&gt;SQL&gt; drop index idx;&lt;br /&gt;&lt;br /&gt;Index dropped.&lt;br /&gt;&lt;br /&gt;SQL&gt; create index idx on test(object_name) compute statistics;&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; select table_name, num_rows, last_analyzed&lt;br /&gt;2 from user_tables&lt;br /&gt;3 where table_name ='TEST'&lt;br /&gt;4 /&lt;br /&gt;&lt;br /&gt;TABLE_NAME NUM_ROWS LAST_ANAL&lt;br /&gt;------------------------------ ---------- ---------&lt;br /&gt;TEST 184 31-OCT-09&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;In Oracle10g, we do not need to use &lt;strong&gt;compute statistics&lt;/strong&gt; clause at all. Oracle gather statistics while creating index automatically. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; create index idx on test(object_name);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; select num_rows, last_analyzed from user_ind_statistics where index_name ='IDX';&lt;br /&gt;&lt;br /&gt;NUM_ROWS LAST_ANAL&lt;br /&gt;---------- ---------&lt;br /&gt;50484 30-OCT-09&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-2035876847685270244?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/2035876847685270244/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=2035876847685270244' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2035876847685270244'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2035876847685270244'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/10/compute-oracle-index-statistics.html' title='Compute Oracle Index Statistics'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-1484027356055077727</id><published>2009-10-30T11:06:00.000-07:00</published><updated>2009-11-02T12:27:18.252-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ORA-06512: at &quot;SYS.DBMS_STATS&quot;'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-38029: object statistics are locked'/><category scheme='http://www.blogger.com/atom/ns#' term='dbms_stats.lock_schema_stats'/><category scheme='http://www.blogger.com/atom/ns#' term='dbms_stats.lock_table_stats'/><category scheme='http://www.blogger.com/atom/ns#' term='line 10640'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-20005: object statistics are locked'/><title type='text'>Statistics Lock in Oracle10g</title><content type='html'>Oracle10g has one of the useful feature that we can lock the table statistics. When statistics on a table are locked, all the statistics depending on the table, including table statistics, column statistics, histograms and statistics on all dependent indexes, are considered to be locked. No one can gather statistics on a table when it is locked. But ofcourse, we can overwrite the statistics with force option. How does it useful for DBA's on day to day activities? At what circumstances, this feature is useful?&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;We can use this feature in the following circumstances...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. &lt;/span&gt;&lt;span style="color:#000000;"&gt;There are tables where you want to setup gathering statistics manually. You can stop gathering statistics during the regular schedule by locking the statistics.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2. &lt;/span&gt;&lt;span style="color:#000000;"&gt;Some cases, Queries works fine with old statistics. You can avoid gathering statistics at this situation.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3.&lt;/span&gt; Some time, tables are bigger and automatic gathering statistics might fail silently. In this scenario, we might need to lock the table and collect the statistics seperately. Refer these links &lt;a href="http://mwidlake.wordpress.com/2009/07/20/automated-statistics-gathering-silently-fails/"&gt;Post1&lt;/a&gt;, &lt;a href="http://mwidlake.wordpress.com/2009/07/23/automated-statistics-gathering-silently-fails-2/"&gt;Post2&lt;/a&gt;, &lt;a href="http://mwidlake.wordpress.com/2009/07/29/automatic-statistics-gathering-fails-3/"&gt;Post3&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;4.&lt;/span&gt; &lt;span style="color:#000000;"&gt;Sometime, gathering statistics, creating histograms takes very long time on bigger table and we can avoid such a bigger table while collecting statistics for all the tables in schema or DB level.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;5. &lt;/span&gt;&lt;span style="color:#000000;"&gt;For some reason, i&lt;/span&gt;&lt;span style="color:#000000;"&gt;f we want to use any specific parameter to gather statistics on particular table, then we can use this option to lock the statistics and gather statistics in different time.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we lock the statistics?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Connected to:Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;&lt;p&gt;SQL&gt; execute dbms_stats.lock_table_stats('SCOTT','EMP');&lt;/p&gt;&lt;p&gt;PL/SQL procedure successfully completed.&lt;/p&gt;&lt;p&gt;SQL&gt; execute dbms_stats.lock_schema_stats('SCOTT');&lt;/p&gt;&lt;p&gt;PL/SQL procedure successfully completed.&lt;/p&gt;&lt;p&gt;SQL&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Index Creation on Locked tables :&lt;/span&gt;&lt;span style="color:#000000;"&gt; In oracle10g, when you create index, the statistics also will be generated automatically. (Please refer my another &lt;a href="http://myorastuff.blogspot.com/2009/10/compute-oracle-index-statistics.html"&gt;Post&lt;/a&gt; for gathering statistics while creating index) . When the table is locked, statistics will not be generated while creating the index. We need to use FORCE option to gather the statistics while creating index for locked objects. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; create table test as select * from dba_objects;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt; exec dbms_stats.lock_table_stats(null, 'TEST');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; create index idx on test(object_name);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; select num_rows, last_analyzed from user_ind_statistics where index_name ='IDX';&lt;br /&gt;&lt;br /&gt;NUM_ROWS LAST_ANAL&lt;br /&gt;---------- ---------&lt;br /&gt;&lt;br /&gt;SQL&gt; drop index idx;&lt;br /&gt;&lt;br /&gt;Index dropped.&lt;br /&gt;&lt;br /&gt;SQL&gt; create index idx on test(object_name) compute statistics;&lt;br /&gt;create index idx on test(object_name) compute statistics&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-38029: object statistics are locked&lt;br /&gt;&lt;br /&gt;SQL&gt; create index idx on test(object_name);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; exec dbms_stats.gather_index_stats(null, 'IDX');&lt;br /&gt;BEGIN dbms_stats.gather_index_stats(null, 'IDX'); END;&lt;br /&gt;&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-20005: object statistics are locked (stattype = ALL)&lt;br /&gt;ORA-06512: at "SYS.DBMS_STATS", line 10640&lt;br /&gt;ORA-06512: at "SYS.DBMS_STATS", line 10664&lt;br /&gt;ORA-06512: at line 1&lt;br /&gt;&lt;br /&gt;SQL&gt; exec dbms_stats.gather_index_stats(null, 'IDX',force=&gt;true);&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; select num_rows, last_analyzed from user_ind_statistics where index_name ='IDX';&lt;br /&gt;&lt;br /&gt;NUM_ROWS LAST_ANAL&lt;br /&gt;---------- ---------&lt;br /&gt;50484 30-OCT-09&lt;br /&gt;&lt;br /&gt;SQL&gt; alter index idx rebuild compute statistics;&lt;br /&gt;alter index idx rebuild compute statistics&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-38029: object statistics are locked&lt;br /&gt;&lt;br /&gt;SQL&gt; alter index idx rebuild;&lt;br /&gt;&lt;br /&gt;Index altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; exec dbms_stats.gather_index_stats(null, 'IDX',force=&gt;true);&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-1484027356055077727?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/1484027356055077727/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=1484027356055077727' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1484027356055077727'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1484027356055077727'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/10/statistics-lock-in-oracle10g.html' title='Statistics Lock in Oracle10g'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-7688538164603291304</id><published>2009-10-26T11:30:00.000-07:00</published><updated>2009-11-12T14:26:13.603-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PLSQL_OPTIMIZE_LEVEL = 1'/><category scheme='http://www.blogger.com/atom/ns#' term='POL'/><category scheme='http://www.blogger.com/atom/ns#' term='PLSQL_OPTIMIZE_LEVEL'/><category scheme='http://www.blogger.com/atom/ns#' term='PLSQL_OPTIMIZE_LEVEL = 2'/><category scheme='http://www.blogger.com/atom/ns#' term='how does plsql_optimize_level work'/><category scheme='http://www.blogger.com/atom/ns#' term='PLSQL_OPTIMIZE_LEVEL = 0'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle10g performance tuning optimization parameter'/><title type='text'>PLSQL_OPTIMIZE_LEVEL</title><content type='html'>I came to Austin for interview and i am on my way to Newjersy. I am hanging in the Austin Airport and i have another three hours for my flight departure. I thought, i write about one of the new Oracle10g optimization parameter PLSQL_OPTIMIZE_LEVEL.&lt;br /&gt;&lt;br /&gt;This parameter determine the optimization level to compile the PLSQL code. The higher setting, oracle use more efforts to compile the code. This parameter will eliminate the dead code and moving the code out of the loop which does the same thing for each iteration. This has three valid values, which are 0,1 and 2. But default value for this parameter is 2.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Let us discuss about each value for this parameter. Please note, Oracle has not provided any detail level example for each value of this parameter. So i can't demonstrate exactly what oracle does for each level. Indeed, we can see the performance improvement in each level.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;PLSQL_OPTIMIZE_LEVEL = 0 &lt;/span&gt;&lt;span style="color:#000000;"&gt;The value 0 works some what as pre 10g release. Oracle documentation says it works better than 9i. Let me write a procedure and run in oracle10g with value 0.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; alter session set plsql_optimize_level =0;&lt;br /&gt;&lt;br /&gt;Session altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; set serveroutput on&lt;br /&gt;SQL&gt; create or replace procedure test as&lt;br /&gt;2 a integer;&lt;br /&gt;3 b integer;&lt;br /&gt;4 c integer;&lt;br /&gt;5 d integer;&lt;br /&gt;6 v_time integer;&lt;br /&gt;7 begin&lt;br /&gt;8 v_time := Dbms_Utility.GET_CPU_TIME();&lt;br /&gt;9 for j in 1..10000000 loop&lt;br /&gt;10 a:= 100;&lt;br /&gt;11 b:= null;&lt;br /&gt;12 c:= nvl(b,1)+a;&lt;br /&gt;13 end loop;&lt;br /&gt;14 Dbms_Output.Put_Line(Dbms_Utility.GET_CPU_TIME()-v_time);&lt;br /&gt;15 end;&lt;br /&gt;16 /&lt;br /&gt;&lt;br /&gt;Procedure created.&lt;br /&gt;&lt;br /&gt;SQL&gt; execute test;&lt;br /&gt;770&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;The above procedure runs in 770 mseconds in oracle10g with plsql_optimize_level=0.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;PLSQL_OPTIMIZE_LEVEL = 1 &lt;/span&gt;&lt;span style="color:#000000;"&gt;It eliminates unnecessary computation and exceptions. Since oracle has not given any example for the each value, i guess, it removes the statement b:=NULL in the TEST procedure. It does not make any sense to assign NULL value for each iteration of the loop in the TEST Procedure.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; alter procedure test compile plsql_optimize_level = 1;&lt;br /&gt;&lt;br /&gt;Procedure altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; execute test;&lt;br /&gt;502&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;The above procedure executes in 502 seconds and it is better then the plsql_optimize_level=0.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;PLSQL_OPTIMIZE_LEVEL = 2 &lt;/span&gt;&lt;span style="color:#333333;"&gt;It moves the unnecessary dead code relatively far from its original location. I guess, it moves the assignment statement out of loop. Since it assigns the same value for each iteration which is not meaningful. Be aware that, some time, oracle takes long time to compile the procedure when we have value 2. Since oracle has to rewrite the code during the compilation stage and not during the execution stage.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;SQL&gt; alter procedure test compile plsql_optimize_level = 2;&lt;br /&gt;&lt;br /&gt;Procedure altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; execute test;&lt;br /&gt;301&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;The above procedure runs in 301 seconds and performance is far better then the value 1. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-7688538164603291304?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/7688538164603291304/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=7688538164603291304' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/7688538164603291304'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/7688538164603291304'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/10/plsqloptimizelevel.html' title='PLSQL_OPTIMIZE_LEVEL'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-1796169522823730723</id><published>2009-10-19T07:01:00.000-07:00</published><updated>2009-11-12T13:21:25.791-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='user_part_histograms'/><category scheme='http://www.blogger.com/atom/ns#' term='METHOD_OPT'/><category scheme='http://www.blogger.com/atom/ns#' term='histogram buckets'/><category scheme='http://www.blogger.com/atom/ns#' term='SKEWONLY'/><category scheme='http://www.blogger.com/atom/ns#' term='frequency histogram'/><category scheme='http://www.blogger.com/atom/ns#' term='sys.col_usage$'/><category scheme='http://www.blogger.com/atom/ns#' term='AUTO'/><category scheme='http://www.blogger.com/atom/ns#' term='REPEAT'/><category scheme='http://www.blogger.com/atom/ns#' term='user_subpart_histograms'/><category scheme='http://www.blogger.com/atom/ns#' term='height balanced histogram'/><category scheme='http://www.blogger.com/atom/ns#' term='for all column size 1'/><title type='text'>How to use histogram in Oracle</title><content type='html'>I would like to write about Oracle Histogram today. Histogram is very nice feature to help cost based optimizer to make right decision.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What is Histogram? &lt;/span&gt;Histograms are feature in CBO and it helps to optimizer to determine how data are skewed(distributed) with in the column. Histogram is good to create for the column which are included in the WHERE clause where the column is highly skewed. Histogram helps to optimizer to decide whether to use an index or full-table scan or help the optimizer determine the fastest table join order.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What are the advantage of Histogram?&lt;/span&gt;&lt;span style="color:#000000;"&gt; Histograms are useful in two places. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. Histograms are useful for Oracle optimizer to choose the right access method in a table.&lt;br /&gt;&lt;br /&gt;2. It is also useful for optimizer to decide the correct table join order. When we join multiple tables, histogram helps to minimize the intermediate result set. Since the smaller size of the intermediate result set will improve the performance.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Type of Histograms: &lt;/span&gt;&lt;span style="color:#000000;"&gt;Oracle uses two types of histograms for column statistics: height-balanced histograms and frequency histograms. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. Height - balanced Histograms : &lt;/span&gt;&lt;span style="color:#000000;"&gt;The column values are divided into bands so that each band contains approximately the same number of rows. For instances, we have 10 distinct values in the column and only five buckets. It will create height based(Height balanced) histograms and it will evenly spread values through the buckets. A height-based histogram is when there are more distinct values than the number of buckets and the histogram statistics shows a range of rows across the buckets &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2. Frequency Histograms : &lt;/span&gt;&lt;span style="color:#000000;"&gt;Each value of the column corresponds to a single bucket of the histogram. This is also called value based histogram. Each bucket contains the number of occurrences of that single value. Frequency histograms are automatically created instead of height-balanced histograms when the number of distinct values is less than or equal to the number of histogram buckets specified. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Method_opt Parameter: &lt;/span&gt;&lt;span style="color:#000000;"&gt;This is the parameter which tells about creating histogram while collecting the statistics. The default is FOR ALL COLUMNS SIZE AUTO in Oracle10g. But in oracle9i, the default is FOR ALL COLUMN SIZE 1 which will turn off the histogram collection. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;FOR ALL [INDEXED HIDDEN] COLUMNS [size_clause]&lt;br /&gt;FOR COLUMNS [size clause] columnattribute [size_clause] [,columnattribute [size_clause]...]&lt;br /&gt;&lt;br /&gt;size_clause is defined as size_clause := SIZE {integer REPEAT AUTO SKEWONLY}&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;integer&lt;/span&gt; : Number of histogram buckets. Must be in the range [1,254]&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;REPEAT&lt;/span&gt; : Collects histograms only on the columns that already have histograms.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;AUTO &lt;/span&gt;: Oracle determines the columns to collect histograms based on data distribution and the workload of the columns. We have a table called sys.col_usage$ that stores information about column usage. dbms_stats use this information to determine whether histogram is required for the columns.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;SKEWONLY&lt;/span&gt; : Oracle determines the columns to collect histograms based on the data distribution of the columns.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Let me demonstrate how optimizer works with and without histogram as below two scenario. We take the emp table for this demonstration. The table has around 3.6 million records. The table emp_status column is highly skewed. It has two distinct values(Y,N). We have bitmap index on emp_status column.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario 1 &lt;/span&gt;Let us generate the statistics without any histogram and see what kind of execution path optimizer is using. Without the histogram, oracle assume that, the data is evenly distributed and optimizer think that, we will have around 1.8 million record for emp_status Y and around another 1.8 million records for emp_status N.&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; select count(*),emp_status from scott.emp&lt;br /&gt;2 group by emp_status;&lt;br /&gt;&lt;br /&gt;COUNT(*) E&lt;br /&gt;---------- -&lt;br /&gt;1 N&lt;br /&gt;3670016 Y&lt;br /&gt;&lt;br /&gt;SQL&gt; execute DBMS_STATS.GATHER_TABLE_STATS(OWNNAME =&gt; 'SCOTT', TABNAME =&gt; 'EMP',ESTIMATE_PERCENT =&gt;&lt;br /&gt;10, METHOD_OPT =&gt; 'FOR ALL COLUMNS SIZE 1',CASCADE =&gt; TRUE);&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; select ename from scott.emp where emp_status='Y';&lt;br /&gt;&lt;br /&gt;3670016 rows selected.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;--------------------------------------------------------------------------&lt;br /&gt;Id Operation Name Rows Bytes Cost (%CPU) Time&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;0 SELECT STATEMENT 1832K 15M 5374 (5) 00:01:05&lt;br /&gt;* 1 TABLE ACCESS FULL EMP 1832K 15M 5374 (5) 00:01:05&lt;br /&gt;--------------------------------------------------------------------------&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;SQL&gt; select ename from scott.emp where emp_status='N'; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;--------------------------------------------------------------------------&lt;br /&gt;Id Operation Name Rows Bytes Cost (%CPU) Time&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;0 SELECT STATEMENT 1832K 15M 5374 (5) 00:01:05&lt;br /&gt;* 1 TABLE ACCESS FULL EMP 1832K 15M 5374 (5) 00:01:05&lt;br /&gt;--------------------------------------------------------------------------&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Conclusion: Optimizer is using full table scan for the query which returns 3670016 records as well as it using full table scan for query which returns just only one record. This is obvisouly incorrect. This problem will be resolved by collecting histogram. Let us see in the next scenario.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Scenario 2 : &lt;/span&gt;&lt;span style="color:#000000;"&gt;Let us generate the statistics with histogram and see what kind of execution path optimizer is using. FOR COLUMN SIZE 2 EMP_STATUS will create two bucket for column emp_status. If we are not sure the distinct number of values in the column, then we can use AUTO option to collect histogram. With this histogram, oracle optimizer knows that, the column emp_status is highly skewed and it has two bucket and one bucket has around 3.6 million records with emp_status Y and another bucket has only one record with emp_status N. Now depends upon the query, optimizer decides whether to use index or Full table scan.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;SQL&gt; execute DBMS_STATS.GATHER_TABLE_STATS(OWNNAME =&gt; 'SCOTT', TABNAME =&gt; 'EMP',ESTIMATE_PERCENT =&gt;&lt;br /&gt;10, METHOD_OPT =&gt; 'FOR COLUMNS SIZE 2 EMP_STATUS',CASCADE =&gt; TRUE);&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; select ename from scott.emp where emp_status='Y';&lt;br /&gt;&lt;br /&gt;3670016 rows selected.&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;Id Operation Name Rows Bytes Cost (%CPU) Time&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;0 SELECT STATEMENT 3681K 31M 5375 (5) 00:01:05&lt;br /&gt;* 1 TABLE ACCESS FULL EMP 3681K 31M 5375 (5) 00:01:05&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;SQL&gt; select ename from scott.emp where emp_status='N';&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;Id Operation Name Rows Bytes Cost (%CPU) Time&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;0 SELECT STATEMENT 1 9 1 (0) 00:00:01&lt;br /&gt;1 TABLE ACCESS BY INDEX ROWID EMP 1 9 1 (0) 00:00:01&lt;br /&gt;2 BITMAP CONVERSION TO ROWIDS&lt;br /&gt;* 3 BITMAP INDEX SINGLE VALUE IDX_EMP&lt;br /&gt;-------------------------------------------------------------------------- &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Conclusion: Optimizer is using full table scan for the query which returns 3670016 records. At the same time, optimizer is using index scan when for other query which returns one record. This scenario, the optimizer choose the right execution plan based on the query WHERE clause.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Data dictionary objects for Histogram: &lt;/span&gt;&lt;br /&gt;user_histograms&lt;br /&gt;user_part_histograms&lt;br /&gt;user_subpart_histograms&lt;br /&gt;user_tab_histograms&lt;br /&gt;user_tab_col_statistics&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-1796169522823730723?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/1796169522823730723/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=1796169522823730723' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1796169522823730723'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1796169522823730723'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/10/histogram.html' title='How to use histogram in Oracle'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-666451224634491380</id><published>2009-10-08T12:28:00.000-07:00</published><updated>2009-11-13T06:47:29.560-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DBMS_STATS.drop_stat_table'/><category scheme='http://www.blogger.com/atom/ns#' term='DBMS_STATS.export_schema_stats'/><category scheme='http://www.blogger.com/atom/ns#' term='DBMS_STATS'/><category scheme='http://www.blogger.com/atom/ns#' term='DBMS_STATS.import_schema_stats'/><category scheme='http://www.blogger.com/atom/ns#' term='DBMS_STATS.create_stat_table'/><category scheme='http://www.blogger.com/atom/ns#' term='Transferring statistics from one server to another server'/><title type='text'>Transferring statistics between database</title><content type='html'>In general, development DB usually will have only portion of the data when we compared to Production database. In such a scenario, when we fix any production issues, obviously we make the changes in Dev DB and test the code and move to Prod DB. While testing the code in Dev DB, if we want to compare the execution plan between Dev and Prod, then we can copy the Prod DB statistics into Dev DB and forcast the optimizer behaviour in development server.&lt;br /&gt;&lt;br /&gt;DBMS_STATS has an ability to transfer statistics between servers allowing consistent execution plans between servers with varying amounts of data. This article is tested in oracle10g. Here are the steps to transfer the statistics.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Source database : orcl&lt;br /&gt;Source schema : sales&lt;br /&gt;Target database : oradev&lt;br /&gt;Target schema : sales&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now our goal is to copy the statistics from &lt;a href="mailto:sales@orcl"&gt;sales@orcl&lt;/a&gt; to &lt;a href="mailto:sales@ordev"&gt;sales@ordev&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Let us follow the below steps to copy the statistics from source(production) to target(development). I am running all the steps in System Schema..&lt;br /&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;step1.&lt;/span&gt; First create a stat table in the source database. The statistics table is created in SYSTEM schema.&lt;/p&gt;&lt;p&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; connect system/password@orcl&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; EXEC DBMS_STATS.create_stat_table('SYSTEM','STATS_TABLE');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Step2.&lt;/span&gt; Export the sales schema statistics.&lt;/p&gt;&lt;p&gt;SQL&gt; EXEC DBMS_STATS.export_schema_stats('SALES','STATS_TABLE',NULL,'SYSTEM');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Step3.&lt;/span&gt; Export the STATS_TABLE by using expdp or exp utility and move the dump file to target(ordev) server.&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Step4.&lt;/span&gt; Import the dump file into target database by using impdp or imp utility. Here i imported the dump file in system schema at target server.&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Step5.&lt;/span&gt; Import the statistics into application schema(&lt;a href="mailto:sales@ordev"&gt;sales@ordev&lt;/a&gt;). Please remember, previous step, we imported the stats_table content into system schema by using impdp method. But this step, we are importing the statistics into relevant data dictionary table by using dbms_stats pacakge.&lt;/p&gt;&lt;p&gt;SQL&gt; EXEC DBMS_STATS.import_schema_stats('SALES','STATS_TABLE',NULL,'SYSTEM');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Step6.&lt;/span&gt; Drop the stats_table in target server.&lt;/p&gt;&lt;p&gt;SQL&gt; EXEC DBMS_STATS.drop_stat_table('SYSTEM','STATS_TABLE');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Note :&lt;/span&gt; We can follow step1 and step2 to backup the statistics before we gather new statistics. It is always good to backup the statistics before we overwrite the new statistics. In case, if we see any performance problem with new statistics, then we can import the old statistics. This option is very useful to transfer the statistics from one DB to another DB. &lt;/p&gt;&lt;p&gt;In oracle10g, it automatically save the statistics for last 31 days by default. We can restore the past statistics within the database at any time. This option is useful to restore the statistics in the same database. Please refer this &lt;a href="http://myorastuff.blogspot.com/2009/11/restoring-old-statistics.html"&gt;Restoring statistics&lt;/a&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-666451224634491380?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/666451224634491380/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=666451224634491380' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/666451224634491380'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/666451224634491380'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/10/transfering-statistics-between-database.html' title='Transferring statistics between database'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-4573535199935059333</id><published>2009-10-07T14:11:00.000-07:00</published><updated>2009-11-13T08:07:29.000-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DBMS_STATS.GATHER_SCHEMA_STATS'/><category scheme='http://www.blogger.com/atom/ns#' term='What is stale statistics'/><category scheme='http://www.blogger.com/atom/ns#' term='alter table monitoring nomonitoring'/><category scheme='http://www.blogger.com/atom/ns#' term='GATHER AUTO'/><category scheme='http://www.blogger.com/atom/ns#' term='how do we find stale statistics'/><category scheme='http://www.blogger.com/atom/ns#' term='user_tab_modifications'/><category scheme='http://www.blogger.com/atom/ns#' term='GATHER STALE'/><title type='text'>Refreshing Stale Statistics</title><content type='html'>Oracle optimizer use the statistics information to choose the right path and execute the query efficiently. It is important to maintain the recent statistics to run the reports efficiently. Oracle highly recommends to use DBMS_STATS to gather statistics. &lt;span style="color:#ff0000;"&gt;Why oracle recommends to use DBMS_STATS?&lt;/span&gt; Click &lt;a href="http://myorastuff.blogspot.com/2009/10/analyze-versus-dbmsstats.html"&gt;here&lt;/a&gt; to answer your question. This article is based on Oracle10g.&lt;br /&gt;&lt;br /&gt;DBMS_STATS package has wonderful feature that capable of analyzing the stale statistics. I am going to discuss about collecting stale statistics in dbms_stats package.&lt;br /&gt;&lt;br /&gt;In general, Gathering statistics consumes lot of resource and CPU time. Once we gathered statistics on a table, we do not need to collect the statistics on the same table until we make reasonable amount of data changes. Let us say, we have a schema called sales. This schema has lot of tables and many table has huge number of records. We schedule to analyze the entire schema every day at 2AM. In day to day DML activities, some of the tables are not having any changes or very minimum changes. In this scenario, we do not need to analyze the tables which are having very minimum changes or no changes. But scheduler automatically start analyzing all the tables in the schema at 2AM every day. This process unnecessarily consuming extra resource and degrade the server performance.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we stop analyzing the tables when there is no DML activity or very minimal DML activity? &lt;/span&gt;Yes... We can... Oracle introduced feature in DBMS_STATS package where oracle collect statistics on schema level or database level, only when the statistics are stale or out of date.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What is stale statistics? &lt;/span&gt;Oracle will record an approximate count of the number of rows that have been inserted,updated, and deleted in a table. The information will be recorded in user_tab_modifications view. When that count reaches a &lt;span style="color:#ff0000;"&gt;threshold percentage&lt;/span&gt; of the number of rows in the table , then the statistics are considered stale. The table monitoring should be enabled for recording the DML changes in user_tab_modification view. In oracle10g, Oracle automatically enable table monitoring and record the DML changes in user_tab_modifications view. Prior to oracle10g, we need to enable the table monitoring manually.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we enable table monitoring? &lt;/span&gt;&lt;span style="color:#000000;"&gt;In oracle10g, the table monitoring is default when statistic_level parameter is TYPICAL. Prior to Oracle10g, we need to enable table monitoring manually. Prior to Oracle10g, the below command is used to enable or disable the table monitoring. But since Oracle10g, the below command does not have any effect. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;ALTER TABLE table_name MONITORING[NOMONITORING]&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What is threshold percentage?&lt;/span&gt; Oracle automatically determines the threshold. Oracle doesn't officially document the threshold, so the threshold, and the entire algorithm, is subject to change over time.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Let me give an example how to analyze stale statistics :&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; BEGIN&lt;br /&gt;2 DBMS_STATS.GATHER_SCHEMA_STATS (&lt;br /&gt;3 ownname =&gt; 'SALES',&lt;br /&gt;4 estimate_percent =&gt; 20,&lt;br /&gt;5 block_sample =&gt; TRUE,&lt;br /&gt;6 method_opt =&gt; 'FOR COLUMNS SIZE 10',&lt;br /&gt;7 options =&gt; 'GATHER AUTO',&lt;br /&gt;8 cascade =&gt; TRUE);&lt;br /&gt;9 END;&lt;br /&gt;10 /&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Note : It is very important that, we should use GATHER AUTO or GATHER STALE to analyze the stale statistics. Also table monitoring is mandatory. Since oracle10g, the table monitoring is enabled by default. So we do not need to worry about table monitoring since oracle10g.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;This feature is very useful for large and complex databases where refreshing statistics for all objects can cause a heavy drain on server resources.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-4573535199935059333?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/4573535199935059333/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=4573535199935059333' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/4573535199935059333'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/4573535199935059333'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/10/refreshing-stale-statistics.html' title='Refreshing Stale Statistics'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-3414615037541858011</id><published>2009-10-01T14:00:00.000-07:00</published><updated>2009-11-12T09:38:51.746-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='METHOD_OPT'/><category scheme='http://www.blogger.com/atom/ns#' term='GATHER EMPTY'/><category scheme='http://www.blogger.com/atom/ns#' term='DBMS_STATS.AUTO_INVALIDATE'/><category scheme='http://www.blogger.com/atom/ns#' term='GATHER AUTO'/><category scheme='http://www.blogger.com/atom/ns#' term='GATHER_DATABASE_STATS'/><category scheme='http://www.blogger.com/atom/ns#' term='GATHER_TABLE_STATS'/><category scheme='http://www.blogger.com/atom/ns#' term='GLOBAL AND PARTITION'/><category scheme='http://www.blogger.com/atom/ns#' term='BLOCK_SAMPLE'/><category scheme='http://www.blogger.com/atom/ns#' term='GATHER_SCHEMA_STATS'/><category scheme='http://www.blogger.com/atom/ns#' term='ESTIMATE_PERCENT'/><category scheme='http://www.blogger.com/atom/ns#' term='GATHER STALE'/><title type='text'>Analyze Versus DBMS_STATS</title><content type='html'>Cost based optimizer is preferred method for oracle optimizer. In order to make good use of the CBO, you need to create accurate statistics. Prior to oracle8i, we use ANALYZE command to gather statistics.&lt;br /&gt;&lt;br /&gt;DBMS_STATS package is introduced in oracle8i. Since Oracle8i, Oracle highly recommeds to use DBMS_STATS instead of ANALYZE command. This article is written in oracle10g. I am going to address below topics in this thread....&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1.&lt;/span&gt; Why oracle recommends to use DBMS_STATS package?&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2.&lt;/span&gt; What are the advantages of DBMS_STATS compared to ANALYZE?&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3.&lt;/span&gt; How do we use DBMS_STATS package to analyze the table?&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;4.&lt;/span&gt; What are new features in each version for DBMS_STATS?&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Why oracle recommends to use DBMS_STATS since Oracle8i?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. &lt;/span&gt;&lt;span style="color:#000000;"&gt;Gathering statistics can be done in Parallel. This option is not available in ANALYZE command.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2.&lt;/span&gt; It is used to collect the stale statistics. I discussed about collecting stale statistics in another topic. Please refer &lt;a href="http://myorastuff.blogspot.com/2009/10/refreshing-stale-statistics.html"&gt;stale statistics&lt;/a&gt; to know more about collecting stale statistics.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3.&lt;/span&gt; DBMS_STATS is a PLSQL pacakge. So it is easy to call. But ANALYZE does not.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;4.&lt;/span&gt; It is used to collect statistics for external tables. But ANALYZE does not.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;5.&lt;/span&gt; DBMS_STATS used to collect system statistics. But ANLAYZE does not.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;6.&lt;/span&gt; Some time, ANALYZE does not produce accurate statistics. But DBMS_STATS does.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;7.&lt;/span&gt; We can not use ANLAYZE command to gather statistics for partition or sub partition level. But we can use DBMS_STATS to analyze any specific partition or sub partition. This is especially useful for partition table. We do not need to analyze the Historical data whenever we refresh the current partition.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;8.&lt;/span&gt; We can transfer statistics from one DB to another DB when we collected statistics through DBMS_STATS. But it can not be done when we use ANALYZE command to collect the statistics. Please refer &lt;a href="http://myorastuff.blogspot.com/2009/10/transfering-statistics-between-database.html"&gt;statistics transfer&lt;/a&gt; to know more about trasferring statistics.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What force you to use ANALYZE command in all Oracle versions? &lt;/span&gt;&lt;span style="color:#000000;"&gt;ANALYZE can be used to collect the statistics like CHAIN_CNT, AVG_SPACE, and EMPTY_BLOCKS. DBMS_STATS will not collect these statistics. We might need to use ANALYZE in case if we want to see chained rows, average space and empty blocks.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;There are several parameter exists for collecting statistics on table level, schema level, database level and system level. But i do not want to explain all the parameters which are already in Oracle help. Still i would like to explain some parameters. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;estimate_percent: &lt;/span&gt;&lt;span style="color:#000000;"&gt;Percentage of rows or blocks to estimate. The valid rage is 0.000001 to 100. &lt;/span&gt;&lt;span style="color:#000000;"&gt;when we pass NULL for this parameter, then it computes. Compute is same as 100% sample. For instance, if we pass 20%, then it takes roughly around 20% of rows or 20% blocks depends on the BLOCK_SAMPLE parameter. This Parameter is used for analyzing on table, index, schema level and database level.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;block_sample:&lt;/span&gt;&lt;span style="color:#000000;"&gt; This determines whether or not to use random block sampling instead of random row sampling. Block sampling would be slightly less accurate in the case where rows have roughly the same lifecycle and, thus, values are spread non-uniformly throughout the table. In case if you want to drive in deep on this, D&lt;/span&gt;avid Aldridge has a nice article on &lt;a href="http://oraclesponge.blogspot.com/2005/06/statistics-by-block-sampling.html"&gt;block sampling&lt;/a&gt;. This Parameter is used for analyzing on table, schema level and database level.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;method_opt: &lt;/span&gt;&lt;span style="color:#000000;"&gt;This parameter tells about histogram in table. It determine which column should have histogram and number of histogram created for the table columns. This Parameter is used for analyzing on table, schema level and database level. Please refer &lt;a href="http://myorastuff.blogspot.com/2009/10/histogram.html"&gt;histogram&lt;/a&gt; to know more about Histogram in Oracle.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;granularity:&lt;/span&gt;&lt;span style="color:#000000;"&gt;This parameter is useful when you want to gather statistics on specific partition or sub partition in a table.&lt;/span&gt; The valid parameters are ALL, AUTO, GLOBAL, GLOBAL AND PARTITION, PARTITION, SUBPARTITION. This Parameter is used for analyzing on table, index, schema level and database level only if the table or index is partitioned.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;no_invalidate: &lt;/span&gt;&lt;span style="color:#000000;"&gt;Does not invalidate the dependent cursors or currently parsed SQL statement if set to TRUE. The procedure invalidates the dependent cursors immediately if set to FALSE. Use DBMS_STATS.AUTO_INVALIDATE to have Oracle decide when to invalidate dependent cursors.&lt;/span&gt; This Parameter is used for analyzing or deleting statistics on table, index, schema level, database level.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Degree: &lt;/span&gt;&lt;span style="color:#000000;"&gt;Degree of parallelism. It has three valid values. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;NULL : Oracle takes the value which is specified in degree clause of create or alter table statement. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;DBMS_STATS.DEFAULT_DEGREE : It takes the value based on number of CPU's and init parameters.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;DBMS_STATS.AUTO_DEGREE : It determines the value automatically. It is either 1 or default degree according to the size of the object.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Options:&lt;/span&gt; This parameter is used only for analyzing the data on schema level or DB level. There are multiple values for this parameters. The valid value for this parameters are GATHER, GATHER AUTO, GATHER STALE, GATHER EMPTY, LIST AUTO, LIST STALE, LIST EMPTY. Let me explain these valid values in short. Since these values are important to gather statistics on schema level.&lt;br /&gt;&lt;br /&gt;GATHER-Gather statistics for all the objects in a schema or database.&lt;br /&gt;&lt;br /&gt;GATHER AUTO-Gather statistics when the statistics are stale or when there is no statistics. It does both GATHER STALE and GATHER EMPTY.&lt;br /&gt;&lt;br /&gt;GATHER STALE-Gather statistics only when it is stale. Does not collect when there is no statistics.&lt;br /&gt;&lt;br /&gt;GATHER EMPTY-Gather statistics only when no statistics.&lt;br /&gt;&lt;br /&gt;LIST AUTO: Returns a list of objects to be processed with GATHER AUTO.&lt;br /&gt;&lt;br /&gt;LIST STALE: Returns list of stale objects as determined by looking at the user_tab_modifications&lt;br /&gt;&lt;br /&gt;LIST EMPTY: Returns list of objects which currently have no statistics.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Gathering_mode : &lt;span style="color:#000000;"&gt;This parameter is used only for gathering system statistics. &lt;/span&gt;&lt;span style="color:#000000;"&gt;The valid modes are NOWORKLOAD, INTERVAL,START and STOP. The default is NOWORKLOAD. The START and STOP is used to stop and start the system statistics.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Example for collecting statistics on table: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;DBMS_STATS.GATHER_TABLE_STATS(&lt;br /&gt;OWNNAME =&gt; 'TANDEB',&lt;br /&gt;TABNAME =&gt; 'CUSTOMER',&lt;br /&gt;PARTNAME =&gt; 'PART092009'&lt;br /&gt;GRANULARITY =&gt; 'PARTITION',&lt;br /&gt;ESTIMATE_PERCENT =&gt; 10,&lt;br /&gt;METHOD_OPT =&gt; 'FOR ALL COLUMNS SIZE 1',&lt;br /&gt;CASCADE =&gt; TRUE,&lt;br /&gt;NO_INVALIDATE =&gt; TRUE);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Example for collecting statistics on Schema: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;DBMS_STATS.GATHER_SCHEMA_STATS(&lt;br /&gt;OWNNAME =&gt; 'SCOMPPRD',&lt;br /&gt;ESTIMATE_PERCENT =&gt; 10,&lt;br /&gt;METHOD_OPT =&gt; 'FOR ALL COLUMNS SIZE 1',&lt;br /&gt;OPTIONS =&gt; 'GATHER',&lt;br /&gt;CASCADE =&gt; TRUE,&lt;br /&gt;NO_VALIDATE =&gt; TRUE);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Example for collecting system statistics: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;DBMS_STATS.GATHER_SYSTEM_STATS(&lt;br /&gt;GATHERING_MODE =&gt; 'INTERVAL',&lt;br /&gt;INTERVAL =&gt; 10);&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Example for collecting database statistics: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;DBMS_STATS.GATHER_DATABASE_STATS(&lt;br /&gt;ESTIMATE_PERCENT =&gt; 10,&lt;br /&gt;METHOD_OPT =&gt; 'FOR ALL COLUMNS SIZE 1',&lt;br /&gt;CASCADE =&gt; TRUE,&lt;br /&gt;NO_VALIDATE =&gt; TRUE,&lt;br /&gt;GATHER_SYS =&gt; FALSE)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;New feature in Oracle9i:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1.&lt;/span&gt; Introduced to gather system statistics. Such as I/O and CPU utilization.&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2.&lt;/span&gt; It can direct the database to select the appropriate sample size to generate accurate statistics. A new value for the ESTIMATE_PERCENT parameter, DBMS_STATS.AUTO_SAMPLE_SIZE will let Oracle decide the sample size necessary to ensure generation of accurate statistics.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;3.&lt;/span&gt; Oracle9i introduced new values for the size clause in the METHOD_OPT parameter automate the decisions regarding the columns on which histograms need to be created while letting administrators control the factors affecting such decisions. Besides specifying a numeric value for the size clause, administrators have the new options (AUTO, SKEWONLY, REPEAT)&lt;/p&gt;&lt;span style="color:#ff0000;"&gt;4.&lt;/span&gt; Oracle9i introduced new feature to enable or disable the table monitoring in schema level or DB level in one command.&lt;br /&gt;&lt;br /&gt;DBMS_STATS.alter_schema_tab_monitoring('MYSCHEMA', TRUE); DBMS_STATS.alter_schema_tab_monitoring('MYSCHEMA', FALSE);&lt;br /&gt;&lt;br /&gt;DBMS_STATS.alter_database_tab_monitoring(TRUE); DBMS_STATS.alter_database_tab_monitoring(FALSE);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;New feature in Oracle10g:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1.&lt;/span&gt; Oracle10g enable table monitoring automatically. Table monitoring is required to collect the stale statisics. We do not need to enable monitoring explicitly. This feature is disabled when statistics_level is BASIC. It enables the table monitoring feature when statistics_level is TYPICAL. ALTER TABLE [NO] MONITORING clauses as well as alter_schema_tab_monitoring and alter_database_tab_monitoring procedures of the dbms_stats package are now obsolete in oracle10g. But still it runs without any error. But there is no effect.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2.&lt;/span&gt; Oracle10g introduced two new values for Granularity parameter. These are AUTO and GLOBAL AND PARTITION. This parameter is applicable for analyzing partitioning tables.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;AUTO : &lt;/span&gt;&lt;span style="color:#000000;"&gt;O&lt;/span&gt;racle collect statistics GLOBAL level, Partition level, and sub-partition level only if sub partition method is LIST. If sub parition is not a LIST, then it collects only GLOBAL, Partition level.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;GLOBAL AND PARTITION : &lt;/span&gt;Oracle gathers the global and partition level statistics. No sub-partition level statistics are gathered.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3. &lt;/span&gt;Oracle10g introduced new value DBMS_STATS.AUTO_DEGREE for Degree parameter. When you specify the auto_degree, Oracle will determine the degree of parallelism automatically. It will be either 1 (serial execution) or default_degree (the system default value based on number of CPUs and initialization parameters), according to the size of the object.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;4. &lt;/span&gt;Oracle10g has ability to restore the previous statistics. Oracle saves last 31 days statistics by default. We can recover previous days statistics in case, optimizer behaves differently with current statistics. Please refer my another post &lt;a href="http://myorastuff.blogspot.com/2009/11/restoring-old-statistics.html"&gt;restoring statistics&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;5.&lt;/span&gt; We can lock the table statistics. This would be helpful if you want to avoid gathering statistics during the maintenance window. Please refer my another post &lt;a href="http://myorastuff.blogspot.com/2009/10/statistics-lock-in-oracle10g.html"&gt;Locking statistics&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;6.&lt;/span&gt; Oracle10g has automatic statistics gathering feature. Oracle gather statistics for the entire database every day during the maintenance window. Please refer my another post &lt;a href="http://myorastuff.blogspot.com/2009/11/automatic-statistics-gathering-in.html"&gt;automatic statistics gathering&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;7.&lt;/span&gt; The statistics will be collected automatically when we create index. In oracle9i, we need to use compute statistics clause to collect statistics while creating index. Please refer my another post &lt;a href="http://myorastuff.blogspot.com/2009/10/compute-oracle-index-statistics.html"&gt;compute index statistics&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What is impact when we analyze the tables during the peak hours?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. &lt;/span&gt;&lt;span style="color:#000000;"&gt;Oracle consume more resource when we gather statistics. This will slow down the overall performance in the sever.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2. &lt;/span&gt;&lt;span style="color:#000000;"&gt;When statistics are updated for a database object, Oracle invalidates any currently parsed SQL statements that access the object. The next time such a statement executes, the statement is re-parsed and the optimizer automatically chooses a new execution plan based on the new statistics. This will degrade the server performance during the peak hours. But we can control this by using the parameter NO_INVALIDATE. This has three values(TRUE, FALSE, DBMS_STATS.AUTO_INVALIDATE). TRUE will not invalidate the already parsed SQL statement. NO will invalidate parsed SQL statement immediately. AUTO_INVALIDATE decides when to invalidate the already parsed Statement.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here is the oracle help to know more about dbms_stats procedure. &lt;a href="http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_stats.htm"&gt;Oracle Help&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-3414615037541858011?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/3414615037541858011/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=3414615037541858011' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/3414615037541858011'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/3414615037541858011'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/10/analyze-versus-dbmsstats.html' title='Analyze Versus DBMS_STATS'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-2981604484905511208</id><published>2009-09-29T07:42:00.000-07:00</published><updated>2009-10-20T14:15:54.511-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='resetting HWM in oracle10g'/><category scheme='http://www.blogger.com/atom/ns#' term='resetting HWM in two steps'/><category scheme='http://www.blogger.com/atom/ns#' term='enable row moment'/><category scheme='http://www.blogger.com/atom/ns#' term='restriction on resetting HWM in oracle10g'/><category scheme='http://www.blogger.com/atom/ns#' term='High water mark'/><category scheme='http://www.blogger.com/atom/ns#' term='HWM in two phase'/><category scheme='http://www.blogger.com/atom/ns#' term='alter table shrink space compact'/><title type='text'>Resetting High Water Mark in Oracle10g</title><content type='html'>I would like to write how to reset HWM in oracle10g. Prior to Oracle10g, resetting high water mark is painful procedure in busy environment. Oracle made our life easy to reset the High Water Mark in oracle10g. I am not going to discuss about what is HWM. Since i already discussed this in another topic. Please &lt;a href="http://myorastuff.blogspot.com/2008/07/hwm-high-water-mark.html"&gt;click&lt;/a&gt; to read about what is HWM and what are the various options available to reset the HMW.&lt;br /&gt;&lt;br /&gt;We have traditional ways to reset the HWM prior to Oracle10g. We might need Table downtime when we use below traditional methods....&lt;br /&gt;&lt;br /&gt;1. Imp/exp&lt;br /&gt;2. Alter tablespace move&lt;br /&gt;3. truncate and insert&lt;br /&gt;4. user dbms_redefinition package to copy the table&lt;br /&gt;&lt;br /&gt;Okay... Let us talk about resetting HWM in Oracle10g. The tablespace should be ASSM(Automatic segment space Management) enabled to leverge this feature. In oracle10g, we do not need table downtime to reset the HWM. It would be easy to reset the HWM in 24/7 environment.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What does Oracle do while using Oracle10g feature to reset the HMW?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Oracle split this process as two phase. Let me explain what is happening in each phase.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Phase I.&lt;/span&gt; &lt;span style="color:#000000;"&gt;Oracle move the rows which are located in the middle or at the end of a segment further more down to the beginning of the segment and make the segment more compact. This shrinking process is kind of delete and insert. But it is not really!!!. This process is moving the data row by row. It acquires a row level lock when the row is moved down to the begining of the segment. The corresponding index data will be handled like any other row level DML. So we do not need to worry about rebuilding the indexes for the row. Also row level lock will happen for very short moment. Before we start this phase, we need to enable row movement. Here is the command to complete the &lt;span style="color:#ff0000;"&gt;phase I&lt;/span&gt;. Here i am using the table called &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;bookings.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; alter table bookings enable row movement;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter table bookings shrink space compact;&lt;br /&gt;&lt;br /&gt;Table altered&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Phase II &lt;/span&gt;&lt;span style="color:#000000;"&gt;This step will reset the high water mark. This will acquire table level lock for very short moment while resetting the HWM. Here is the command to accomplish this task.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; alter table bookings shrink space;&lt;br /&gt;&lt;br /&gt;Table altered&lt;br /&gt;&lt;br /&gt;SQL&gt; alter table bookings shrink space cascade; (it is for all dependent objects as well)&lt;br /&gt;&lt;br /&gt;Table altered&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;If we want to reset the HWM in one go, then below command will accomplish the task. The below command moves the rows and reset the HWM.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; alter table bookings shrink space;&lt;br /&gt;&lt;br /&gt;Table altered&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What are the advantages of using Oracle10g new feature to reset the HWM?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;There are serveral advantages over traditional methods. Let me list the advantages here.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. It can be done in online. There is a table level lock for very short moment. Traditional methods are not supporting to reset the HWM in online.&lt;br /&gt;&lt;br /&gt;2. It does not take extra space while resetting the HWM. If we use traditional method, DBMS_REDEFINITION package use double the amount of space.&lt;br /&gt;&lt;br /&gt;3. It does acquire only row level lock while performing majority of the shrinking(moving rows) work. It acquires table level lock only when it resets the HWM which is in phase II. But traditional methods requires table down time for resetting the HWM except using dbms_redefinition package.&lt;br /&gt;&lt;br /&gt;4. Index will be maintained and remain usable. But in traditional methods, we need to rebuild the index. Especially when we use ALTER TABLESPACE MOVE command.&lt;br /&gt;&lt;br /&gt;5. It can be made in one command(alter table emp shrink space). In traditional method, there are multiple steps.&lt;br /&gt;&lt;br /&gt;6. If you are not sure that you can afford table level lock at specific time, then you can do the majority of the shriniking work and later we can reset the HWM. Since table level lock is required only while resetting the HWM. The whole process can be done in two steps as i explained above. This advantage is not available in traditional methods.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What are the restriction of using Oracle10g new feature to reset the HWM? &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;1. It is only possible in ASSM tablespace&lt;/span&gt;&lt;br /&gt;2. Not supporting for clustered tables, tables with column data type LONG&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What circumstances we can reset the HWM as two phase?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;The table is not frequently used(insert/update/delete) and it can afford to have table level lock, then we can reset the HWM in one go. We can reset the HWM as two steps when the table is used by several people and it is always busy and it does not permit the table level lock even for short moment at specific time. This scenario, we can move the rows to shrink the table. Then in the night time or off peak hours, we can reset the HWM. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-2981604484905511208?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/2981604484905511208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=2981604484905511208' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2981604484905511208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2981604484905511208'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/09/high-water-mark-in-oracle10g.html' title='Resetting High Water Mark in Oracle10g'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-6736584028435098851</id><published>2009-09-15T13:24:00.000-07:00</published><updated>2009-10-20T13:32:45.309-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='TKPROF'/><category scheme='http://www.blogger.com/atom/ns#' term='plsql_profiler_runs'/><category scheme='http://www.blogger.com/atom/ns#' term='how do we profile PLSQL code'/><category scheme='http://www.blogger.com/atom/ns#' term='plsql_profiler_units'/><category scheme='http://www.blogger.com/atom/ns#' term='install dbms_profiler in oracle'/><category scheme='http://www.blogger.com/atom/ns#' term='profload.sql'/><category scheme='http://www.blogger.com/atom/ns#' term='proftab.sql'/><category scheme='http://www.blogger.com/atom/ns#' term='plsql_profiler_data'/><category scheme='http://www.blogger.com/atom/ns#' term='explain_plan'/><category scheme='http://www.blogger.com/atom/ns#' term='dbms_profiler'/><title type='text'>DBMS_PROFILER</title><content type='html'>DBMS_PROFILER is introduced in oracle8i. It is powerful tool to find the PLSQL execution time and determine the bottleneck of the program unit. This tool provides information about how many times each line is executing and how much time it is spending to execute for each line of the code. The basic idea behind the profiling is, developers can understand where the code is taking most time and they can detect and optimize the PLSQL code. We use SQL trace to determine the bottleneck for SQL code. But for PLSQL code, we can use dbms_profiler utility to profile the run time behaviour. Steps might very for other oracle versions.&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we set up dbms_profiler utility?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Please remember, the dbms_profiler setup is not part of Oracle installation. We need to setup manually if we want to profile the PLSQL code. There are five simple steps to configure the dbms_profiler. Let us start configure the profiler.&lt;/span&gt; This article is tested in oracle10g R2.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step1.&lt;/span&gt; The dbms_profiler package can be loaded by running the $ORACLE_HOME/rdbms/admin/profload.sql script as the SYS user. Execute profload.sql in sys schema.&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; connect sys/password@orcl as sysdba&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; start c:/oracle/product/10.2.0/db_1/rdbms/admin/profload.sql&lt;br /&gt;&lt;br /&gt;Package created.&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;Synonym created.&lt;br /&gt;&lt;br /&gt;Library created.&lt;br /&gt;&lt;br /&gt;Package body created.&lt;br /&gt;&lt;br /&gt;Testing for correct installation&lt;br /&gt;SYS.DBMS_PROFILER successfully loaded.&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step2.&lt;/span&gt; dbms_profiler package requires some schema objects which should be created in central schema or application schema. Create a new schema called &lt;span style="color:#ff0000;"&gt;profiler.&lt;/span&gt; We can either create a new schema or use existing schema. In this case, i created new schema, named &lt;strong&gt;Profiler&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;SQL&gt; create user profiler&lt;br /&gt;2 identified by profiler;&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant create session,resource,connect to profiler;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step3.&lt;/span&gt;&lt;span style="color:#000000;"&gt; Run the $ORACLE_HOME/rdbms/admin/proftab.sql file on the profiler schema to create some schema objects to store profiler information. This proftab.sql file creates below three tables with some other objects.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1.PLSQL_PROFILER_RUNS&lt;br /&gt;2.PLSQL_PROFILER_UNITS&lt;br /&gt;3.PLSQL_PROFILER_DATA&lt;br /&gt;&lt;br /&gt;SQL&gt; connect profiler/profiler@orcl&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; start c:/oracle/product/10.2.0/db_1/rdbms/admin/proftab.sql&lt;br /&gt;drop table plsql_profiler_data cascade constraints&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-00942: table or view does not exist&lt;br /&gt;&lt;br /&gt;drop table plsql_profiler_units cascade constraints&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-00942: table or view does not exist&lt;br /&gt;&lt;br /&gt;drop table plsql_profiler_runs cascade constraints&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-00942: table or view does not exist&lt;br /&gt;&lt;br /&gt;drop sequence plsql_profiler_runnumber&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-02289: sequence does not exist&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;Comment created.&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;Comment created.&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;Comment created.&lt;br /&gt;&lt;br /&gt;Sequence created.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step4.&lt;/span&gt; Connect into profiler schema and grant the below privileges.&lt;br /&gt;&lt;br /&gt;GRANT SELECT ON plsql_profiler_runnumber TO PUBLIC;&lt;br /&gt;GRANT SELECT, INSERT, UPDATE, DELETE ON plsql_profiler_data TO PUBLIC;&lt;br /&gt;GRANT SELECT, INSERT, UPDATE, DELETE ON plsql_profiler_units TO PUBLIC;&lt;br /&gt;GRANT SELECT, INSERT, UPDATE, DELETE ON plsql_profiler_runs TO PUBLIC;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;SQL&gt; connect profiler/profiler@orcl&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; GRANT SELECT ON plsql_profiler_runnumber TO PUBLIC;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; GRANT SELECT, INSERT, UPDATE, DELETE ON plsql_profiler_data TO PUBLIC;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; GRANT SELECT, INSERT, UPDATE, DELETE ON plsql_profiler_units TO PUBLIC;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; GRANT SELECT, INSERT, UPDATE, DELETE ON plsql_profiler_runs TO PUBLIC;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="color:#ff0000;"&gt;Step5.&lt;/span&gt; Connect into sys schema and grant the below privileges for dbms_profiler package.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;CREATE PUBLIC SYNONYM plsql_profiler_runs FOR profiler.plsql_profiler_runs;&lt;br /&gt;CREATE PUBLIC SYNONYM plsql_profiler_units FOR profiler.plsql_profiler_units;&lt;br /&gt;CREATE PUBLIC SYNONYM plsql_profiler_data FOR profiler.plsql_profiler_data;&lt;br /&gt;CREATE PUBLIC SYNONYM plsql_profiler_runnumber FOR profiler.plsql_profiler_runnumber; &lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;SQL&gt; connect sys/password@orcl as sysdba&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; CREATE PUBLIC SYNONYM plsql_profiler_runs FOR profiler.plsql_profiler_runs;&lt;br /&gt;&lt;br /&gt;Synonym created.&lt;br /&gt;&lt;br /&gt;SQL&gt; CREATE PUBLIC SYNONYM plsql_profiler_units FOR profiler.plsql_profiler_units;&lt;br /&gt;&lt;br /&gt;Synonym created.&lt;br /&gt;&lt;br /&gt;SQL&gt; CREATE PUBLIC SYNONYM plsql_profiler_data FOR profiler.plsql_profiler_data;&lt;br /&gt;&lt;br /&gt;Synonym created.&lt;br /&gt;&lt;br /&gt;SQL&gt; CREATE PUBLIC SYNONYM plsql_profiler_runnumber FOR profiler.plsql_profiler_runnumber;&lt;br /&gt;&lt;br /&gt;Synonym created.&lt;br /&gt;&lt;br /&gt;SQL&gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;Once we are successful with five steps, we can start profiling the PLSQL code.&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we profile the PLSQL Procedure? &lt;/span&gt;&lt;/p&gt;&lt;p&gt;Let us create sample procedure and profile the procedure. &lt;/p&gt;&lt;p&gt;1. start profiler&lt;br /&gt;2. run the procedure&lt;br /&gt;3. stop profiler&lt;br /&gt;4. flush data from memory and save into table&lt;br /&gt;5. Analyze the data and see where it is taking more time&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;Here i create a procedure called do_something in SCOTT schema. You can also profile the procedure which is existing in any schema in the database.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;SQL&gt; CREATE OR REPLACE PROCEDURE do_something (p_times IN NUMBER) AS&lt;br /&gt;2 v_cnt NUMBER;&lt;br /&gt;3 BEGIN&lt;br /&gt;4 FOR i IN 1 .. p_times LOOP&lt;br /&gt;5 SELECT count(*) + p_times&lt;br /&gt;6 INTO v_cnt&lt;br /&gt;7 FROM EMP;&lt;br /&gt;8 END LOOP;&lt;br /&gt;9 END;&lt;br /&gt;10 /&lt;br /&gt;&lt;br /&gt;Procedure created. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;The below unnamed PLSQL code starts the profiler and call the procedure. Once the procedure is executed, it stop the profiler. It flush the data from memory and save into table. &lt;/p&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;SQL&gt; DECLARE&lt;br /&gt;2 l_result BINARY_INTEGER;&lt;br /&gt;3 BEGIN&lt;br /&gt;4 l_result := DBMS_PROFILER.start_profiler(run_comment =&gt; 'do_something: ' SYSDATE);&lt;br /&gt;5 do_something(p_times =&gt; 100);&lt;br /&gt;6 l_result := DBMS_PROFILER.stop_profiler;&lt;br /&gt;7 dbms_profiler.flush_data;&lt;br /&gt;8 END;&lt;br /&gt;9 /&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Here is query to check the profiler result.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;SQL&gt; SET LINESIZE 200&lt;br /&gt;SQL&gt; SET TRIMOUT ON&lt;br /&gt;SQL&gt;&lt;br /&gt;SQL&gt; COLUMN runid FORMAT 99999&lt;br /&gt;SQL&gt; COLUMN run_comment FORMAT A50&lt;br /&gt;SQL&gt; SELECT runid,&lt;br /&gt;2 run_date,&lt;br /&gt;3 run_comment,&lt;br /&gt;4 run_total_time&lt;br /&gt;5 FROM plsql_profiler_runs&lt;br /&gt;6 ORDER BY runid;&lt;br /&gt;&lt;br /&gt;RUNID RUN_DATE RUN_COMMENT RUN_TOTAL_TIME&lt;br /&gt;------ --------- -------------------------------------------------- --------------&lt;br /&gt;4 15-SEP-09 do_something: 15-SEP-09 686370753&lt;br /&gt;&lt;br /&gt;SQL&gt; SELECT d.line#,&lt;br /&gt;2 d.total_occur,&lt;br /&gt;3 d.total_time&lt;br /&gt;4 FROM plsql_profiler_units u&lt;br /&gt;5 JOIN plsql_profiler_data d ON u.runid = d.runid AND u.unit_number = d.unit_number&lt;br /&gt;6 WHERE u.runid = 4&lt;br /&gt;7 and unit_name='DO_SOMETHING'&lt;br /&gt;8 and unit_owner='SCOTT'&lt;br /&gt;9 and unit_type='PROCEDURE'&lt;br /&gt;10 ORDER BY u.unit_number, d.line#;&lt;br /&gt;&lt;br /&gt;LINE# TOTAL_OCCUR TOTAL_TIME&lt;br /&gt;---------- ----------- ----------&lt;br /&gt;1 1 199466&lt;br /&gt;4 101 2247771&lt;br /&gt;5 100 513261322&lt;br /&gt;9 1 85485&lt;br /&gt;&lt;br /&gt;SQL&gt; SELECT line ' : ' text&lt;br /&gt;2 FROM all_source&lt;br /&gt;3 WHERE owner = 'SCOTT'&lt;br /&gt;4 AND type = 'PROCEDURE'&lt;br /&gt;5 AND name = 'DO_SOMETHING';&lt;br /&gt;&lt;br /&gt;LINE':'TEXT&lt;br /&gt;----------------------------------------------------------------------------------------------------&lt;br /&gt;1 : PROCEDURE do_something (p_times IN NUMBER) AS&lt;br /&gt;2 : v_cnt NUMBER;&lt;br /&gt;3 : BEGIN&lt;br /&gt;4 : FOR i IN 1 .. p_times LOOP&lt;br /&gt;5 : SELECT count(*) + p_times&lt;br /&gt;6 : INTO v_cnt&lt;br /&gt;7 : FROM EMP;&lt;br /&gt;8 : END LOOP;&lt;br /&gt;9 : END;&lt;br /&gt;&lt;br /&gt;9 rows selected.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Conclusion :&lt;/span&gt; The line number 4 runs 101 times and line number 5 runs 100 times. The procedure spends most of the time at line number 5. Now we figured out exactly where it is taking longer time. We can focus on tuning the line 5 in case if we want to....&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Where do we use dbms_profiler? &lt;/span&gt;&lt;span style="color:#000000;"&gt;TKPROF and Explain plan helps to find where it is taking long time to complete the SQL. Dbms_profiler is useful, if we want to find out which line is consuming most time in entire PLSQL. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;The source of this article is &lt;a href="http://www.oracle-base.com/articles/9i/DBMS_PROFILER.php#"&gt;oracle-base&lt;/a&gt;. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-6736584028435098851?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/6736584028435098851/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=6736584028435098851' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/6736584028435098851'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/6736584028435098851'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/09/dbmsprofiler.html' title='DBMS_PROFILER'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-1665066146292761174</id><published>2009-09-10T18:38:00.000-07:00</published><updated>2009-09-14T08:19:31.335-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='oracle sql questions for newbies'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle SQL Questions for learners'/><category scheme='http://www.blogger.com/atom/ns#' term='sample SQL'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle sql question for beginners'/><category scheme='http://www.blogger.com/atom/ns#' term='interview SQL questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle SQL questions for newbie&apos;s'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle SQL questions'/><title type='text'>Oracle SQL Questions for Newbies</title><content type='html'>I thought, it would be useful if i post some sample SQL questions for newbies. These bunch of SQL questions would be helpful for beginners who wanted to learn Oracle SQL.&lt;br /&gt;&lt;br /&gt;Here are some tables which needs to be created to practice SQL questions. Just for learning process, you could use SCOTT schema to practice SQL questions. I am posting 101 Oracle SQL questions with answers.&lt;br /&gt;&lt;br /&gt;First step would be, we need to create the below tables and insert relevant data to practice the questions.&lt;br /&gt;&lt;br /&gt;Create the below tables:&lt;br /&gt;&lt;br /&gt;CREATE TABLE DEPT (&lt;br /&gt;DEPTNO NUMBER(2),&lt;br /&gt;DNAME VARCHAR2(14),&lt;br /&gt;LOC VARCHAR2(13));&lt;br /&gt;&lt;br /&gt;INSERT INTO DEPT VALUES (10, 'ACCOUNTING', 'NEW YORK');&lt;br /&gt;INSERT INTO DEPT VALUES (20, 'RESEARCH', 'DALLAS');&lt;br /&gt;INSERT INTO DEPT VALUES (30, 'SALES', 'CHICAGO');&lt;br /&gt;INSERT INTO DEPT VALUES (40, 'OPERATIONS', 'BOSTON');&lt;br /&gt;&lt;br /&gt;ALTER TABLE DEPT ADD PRIMARY KEY(DEPTNO);&lt;br /&gt;&lt;br /&gt;CREATE TABLE EMP (EMPNO NUMBER(4) NOT NULL,&lt;br /&gt;ENAME VARCHAR2(10),&lt;br /&gt;JOB VARCHAR2(9),&lt;br /&gt;MGR NUMBER(4),&lt;br /&gt;HIREDATE DATE,&lt;br /&gt;SAL NUMBER(7,2),&lt;br /&gt;COMM NUMBER(7,2),&lt;br /&gt;DEPTNO NUMBER(2));&lt;br /&gt;&lt;br /&gt;ALTER TABLE EMP ADD CONSTRAINT FK_EMP_01&lt;br /&gt;FOREIGN KEY(DEPTNO) REFERENCES DEPT;&lt;br /&gt;&lt;br /&gt;INSERT INTO EMP VALUES (7369, 'SMITH', 'CLERK', 7902, TO_DATE('17-DEC-1980', 'DD-MON-YYYY'), 800, NULL, 20);&lt;br /&gt;INSERT INTO EMP VALUES (7499, 'ALLEN', 'SALESMAN', 7698, TO_DATE('20-FEB-1981', 'DD-MON-YYYY'), 1600, 300, 30);&lt;br /&gt;INSERT INTO EMP VALUES (7521, 'WARD', 'SALESMAN', 7698, TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250, 500, 30);&lt;br /&gt;INSERT INTO EMP VALUES (7566, 'JONES', 'MANAGER', 7839, TO_DATE('2-APR-1981', 'DD-MON-YYYY'), 2975, NULL, 20);&lt;br /&gt;INSERT INTO EMP VALUES (7654, 'MARTIN', 'SALESMAN', 7698,TO_DATE('28-SEP-1981', 'DD-MON-YYYY'), 1250, 1400, 30);&lt;br /&gt;INSERT INTO EMP VALUES (7698, 'BLAKE', 'MANAGER', 7839,TO_DATE('1-MAY-1981', 'DD-MON-YYYY'), 2850, NULL, 30);&lt;br /&gt;INSERT INTO EMP VALUES (7782, 'CLARK', 'MANAGER', 7839,TO_DATE('9-JUN-1981', 'DD-MON-YYYY'), 2450, NULL, 10);&lt;br /&gt;INSERT INTO EMP VALUES (7788, 'SCOTT', 'ANALYST', 7566,TO_DATE('09-DEC-1982', 'DD-MON-YYYY'), 3000, NULL, 20);&lt;br /&gt;INSERT INTO EMP VALUES (7839, 'KING', 'PRESIDENT', NULL,TO_DATE('17-NOV-1981', 'DD-MON-YYYY'), 5000, NULL, 10);&lt;br /&gt;INSERT INTO EMP VALUES (7844, 'TURNER', 'SALESMAN', 7698,TO_DATE('8-SEP-1981', 'DD-MON-YYYY'), 1500, 0, 30);&lt;br /&gt;INSERT INTO EMP VALUES (7876, 'ADAMS', 'CLERK', 7788,TO_DATE('12-JAN-1983', 'DD-MON-YYYY'), 1100, NULL, 20);&lt;br /&gt;INSERT INTO EMP VALUES (7900, 'JAMES', 'CLERK', 7698,TO_DATE('3-DEC-1981', 'DD-MON-YYYY'), 950, NULL, 30);&lt;br /&gt;INSERT INTO EMP VALUES (7902, 'FORD', 'ANALYST', 7566,TO_DATE('3-DEC-1981', 'DD-MON-YYYY'), 3000, NULL, 20);&lt;br /&gt;INSERT INTO EMP VALUES (7934, 'MILLER', 'CLERK', 7782,TO_DATE('23-JAN-1982', 'DD-MON-YYYY'), 1300, NULL, 10);&lt;br /&gt;&lt;br /&gt;CREATE TABLE SALGRADE(&lt;br /&gt;GRADE NUMBER(2),&lt;br /&gt;LOSAL NUMBER,&lt;br /&gt;HISAL NUMBER);&lt;br /&gt;&lt;br /&gt;INSERT INTO SALGRADE VALUES(1, 700,1200);&lt;br /&gt;INSERT INTO SALGRADE VALUES(2, 1201,1400);&lt;br /&gt;INSERT INTO SALGRADE VALUES(3, 1401,2000);&lt;br /&gt;INSERT INTO SALGRADE VALUES(4, 2001,3000);&lt;br /&gt;INSERT INTO SALGRADE VALUES(5, 3001,9999);&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Question &amp;amp; Answers:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1) Display all the records in emp table?&lt;/span&gt;&lt;br /&gt;&lt;p&gt;select * from emp;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;2) Display all the records in emp table where employee belongs to deptno 10?&lt;/span&gt;&lt;/p&gt;select * from emp where deptno = 10&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3) Display all the records in emp table where employee does not belong to deptno 30?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where deptno != 30;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;4) Display total number of records in Emp table?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select count(*) from emp;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;5) Display emp table with salary descending order?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp order by sal desc&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;6) Display first five records in employee table?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where rownum &lt;= 5&lt;br /&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;7) Display all the records in emp table order by ascending deptno, descending salary?&lt;/span&gt;&lt;/p&gt;&lt;p&gt;select * from emp order by deptno asc, sal desc&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;8) Display all employees those who were joined in year 1981?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where to_char(hiredate,'YYYY') = 1981;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;9) Display COMM in emp table. Display zero in place of null.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select nvl(comm,0) from emp&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;10) Display the records in emp table where MGR in 7698,7566 and sal should be greater then 1500&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where mgr in(7698,7566) and sal &gt; 1500&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;11) Display all employees where employees hired before 01-JAN-1981&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where hiredate &lt; '01-JAN-1981' &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;12) Display all employees with how many years they have been servicing in the company?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select hiredate,round((sysdate-hiredate)/360) as years from emp&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;13) Display all employees those were not joined in 1981?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where to_char(hiredate,'YYYY') != 1981;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;14) Display all employees where their hiredate belongs to third quarter?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where to_char(hiredate,'Q') = 3;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;15) Display all employees where their salary is less then the Ford’s salary?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where sal &lt;(select sal from emp where ename='FORD'); &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;16) Display all the records in EMP table along with the rowid?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select ename,rowid from emp;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;17) Display all records in EMP table those were joined before SCOTT joined?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where hiredate &lt;(select hiredate from emp where ename='SCOTT') &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;18) Display all employees those who were joined in third quarter of 1981?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where to_char(hiredate,'Q') = 3 and to_char(hiredate,'YYYY') = 1981&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;19) Add 3 months with hiredate in EMP table and display the result?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select hiredate, add_months(hiredate,3) from emp&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;20) Display the date for next TUESDAY in hiredate column?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select next_day(hiredate,'TUESDAY') from emp;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;21) Find the date, 15 days after today’s date.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select sysdate+15 from dual&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;22) Write a query to display current date?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select sysdate from dual;&lt;br /&gt;select current_date from dual;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;23) Display distinct job from emp table?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select distinct job from emp&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;24) Display all the records in emp table where employee hired after 28-SEP-81 and before 03-DEC-81?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where hiredate between '28-SEP-81' and '03-DEC-81'&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;25) Write a query that displays the employee’s names with the first letter capitalized and all other letters lowercase for all employees whose name starts with J, A, or M&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select initcap(ename) from emp where ename like 'J%' or ename like 'A%' or ename like 'M%'&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;26) Display all jobs that are in department 10. Include the location of department in the output.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select job, loc from emp,dept where emp.deptno = dept.deptno and emp.deptno =10&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;27) Write a query to display the employee name, department name of all employees who earn a commission&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select ename,dname from emp,dept where emp.deptno = dept.deptno and comm is not null;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;28) Display the empno, ename, sal, and salary increased by 15%.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select empno, ename, sal actual_sal, (sal * 15/100) as Increased_sal from emp&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;29) Display ename, sal, grade. Use emp, salgrade table&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select ename,sal,grade from emp,salgrade where sal between losal and hisal;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;30) Display all employees and corresponding managers&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select w.ename,w.sal,m.ename,m.sal from emp w, emp m where w.mgr = m.empno;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;31) Display all the departments where employee salary greater then average salary of that department. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select ename,deptno, sal from emp a where sal &gt; (select avg(sal) from emp where emp.deptno = a.deptno) order by deptno;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;32) Display all employees whose salary greater then the manager salary?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select w.ename,w.sal,m.ename,m.sal from emp w, emp m where w.mgr = m.empno and w.sal &gt; m.sal&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;33) Display employees where length of ename is 5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where length(ename) =5&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;34) Display all employees where ename start with J and ends with S&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where ename like 'J%S'&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;35) Display all employees where employee does not belong to 10,20,40&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where deptno not in(10,20,40)&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;36) Display all employees where jobs does not belong to PRESIDENT and MANAGER?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where job not in('PRESIDENT','MANAGER');&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;37) Display the maximum salary in the emp table&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select max(sal) from emp&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;38) Display average salary for job SALESMAN&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select avg(sal) from emp where job = 'SALESMAN'&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;39) Display all three figures salary in emp table&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where sal &lt; = 999; &lt;/p&gt;&lt;p&gt;select * from emp where length(sal) = 3; &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;40) Display all records in emp table for employee who does not receive any commission&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where comm is not null&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;41) Display all ename where first character could be anything, but second character should be L?&lt;/span&gt;&lt;br /&gt;select * from emp where ename like '_L%'&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;42) Display nth highest and nth lowest salary in emp table?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SELECT DISTINCT (a.sal) FROM EMP A WHERE &amp;amp;N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal&lt;=b.sal); &lt;/p&gt;&lt;p&gt;select distinct sal from (select ename,sal,dense_rank() over(order by sal desc) dr from emp) where dr = &amp;amp;x ;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;43) Display all the departments where department has 3 employees?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select deptno from dept a where deptno in(select deptno from emp group by deptno having count(*)=3)&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;44) Display emp name and corresponding subordinates. Use CONNECT BY clause.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select lpad(' ',level+12)+ename from emp connect by prior empno = mgr start with mgr is null&lt;br /&gt;&lt;br /&gt;Note: Please replace pipe symbol in the place of + sign for question 44. Pipe symbol is not displaying the blog. This is the reason, i used Plus sign here.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;45) Display sum of salary for each department. The output should be in one record&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select sum(decode(deptno,10,sal)) dept10, sum(decode(deptno,20,sal)) dept20, sum(decode(deptno,30,sal)) dept30, sum(sal) total_sal from emp&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;46) Display all department with Minimum salary and maximum salary?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select min(sal),max(sal) from emp;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;47) Display all ename, sal, deptno,dname from emp, dept table where all department which has employees as well as department does not have any employees. This query should include non matching rows.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select dname,b.deptno, ename,sal from emp a, dept b where a.deptno(+) = b.deptno;&lt;/p&gt;&lt;p&gt;select dname,b.deptno, ename,sal from emp a right outer join dept b on a.deptno = b.deptno;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;48) Display all ename, sal, deptno from emp, dept table where all employees which has matching department as well as employee does not have any departments. This query should include non matching &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;rows.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Note: In the below query, employee will always have matching record in dept table. Emp, dept table may not be good example to answer this question.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;select dname,b.deptno, ename,sal from emp a, dept b where a.deptno = b.deptno(+);&lt;/p&gt;&lt;p&gt;select dname,b.deptno, ename,sal from emp a left outer join dept b on a.deptno = b.deptno;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;49) Display all ename, sal, deptno from emp, dept table where all employees which has matching and non matching department as well as all departments in dept table which has matching and non matching employees. This query should include non matching rows on both the tables. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Note: In the below query, employee will always have matching record in dept table. Emp, dept table may not be good example to answer this question.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;select dname,b.deptno, ename,sal from emp a full outer join dept b on a.deptno = b.deptno&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;50) Display all ename, empno, dname, loc from emp, dept table without joining two tables&lt;/span&gt;&lt;/p&gt;select * from emp,dept;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;51) Display all the departments where department does not have any employees&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select deptno from dept where not exists(select 1 from emp where emp.deptno = dept.deptno);&lt;br /&gt;&lt;br /&gt;select deptno from dept where deptno not in(select deptno from emp);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;52) Display all the departments where department does have atleast one employee&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from dept a where exists(select 1 from emp b where b.deptno = a.deptno)&lt;br /&gt;&lt;br /&gt;select * from dept a where deptno in(select deptno from emp b where a.deptno = b.deptno)&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;53) Display all employees those who are not managers?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select ename from emp a where not exists (select 1 from emp b where b.mgr = a.empno);&lt;br /&gt;&lt;br /&gt;select ename from emp a where empno not in (select mgr from emp b where b.mgr = a.empno and mgr is not null);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;54) Display ename, deptno from emp table with format of {ename} belongs to {deptno}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select ename+' belongs to '+deptno from emp&lt;br /&gt;&lt;br /&gt;Note: Please replace pipe symbol in the place of + sign for question 44. Pipe symbol is not displaying the blog. This is the reason, i used Plus sign here.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;55) Display total number of employees hired for 1980,1981,1982. The output should be in one record.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select&lt;br /&gt;count(decode(to_char(hiredate,'YYYY'), 1980,hiredate)) total_hire_1980,&lt;br /&gt;count(decode(to_char(hiredate,'YYYY'), 1981,hiredate)) total_hire_1981,&lt;br /&gt;count(decode(to_char(hiredate,'YYYY'), 1982,hiredate)) total_hire_1982&lt;br /&gt;from emp&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;56) Display ename, deptno from employee table. Also add another column in the same query and it should display ten for dept 10, twenty for dept 20, thirty for dept 30, fourty for dept 40&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select ename,deptno, (case deptno&lt;br /&gt;when 10 then 'Ten'&lt;br /&gt;when 20 then 'Twenty'&lt;br /&gt;when 30 then 'Thirty'&lt;br /&gt;when 40 then 'fourty'&lt;br /&gt;else 'others' end) as dept&lt;br /&gt;from emp&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;57) Display all the records in emp table. The ename should be lower case. The job first character should be upper case and rest of the character in job field should be lower case.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select lower(ename) as ename, initcap(job) as job from emp&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;58) Display all employees those who have joined in first week of the month ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where to_char(hiredate,'W') = 1;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;59) Display all empoyees those who have joined in the 49th week of the year?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where to_char(hiredate,'WW') = 49;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;60) Display empno, deptno, salary, salary difference between current record and previous record in emp table. Deptno should be in descending order.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SELECT empno,&lt;br /&gt;ename,&lt;br /&gt;job,&lt;br /&gt;sal,&lt;br /&gt;LAG(sal, 1, 0) OVER (ORDER BY sal) AS sal_prev,&lt;br /&gt;sal - LAG(sal, 1, 0) OVER (ORDER BY sal) AS sal_diff&lt;br /&gt;FROM emp;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;61) Create table emp1 and copy the emp table for deptno 10 while creating the table&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create table emp1 as select * from emp where deptno=10&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;62) Create table emp2 with same structure of emp table. Do not copy the data&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;create table emp2 as select * from emp where 1=2&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;63) Insert new record in emp1 table, Merge the emp1 table on emp table.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;insert into emp1 values(9999,'PAUL','MANAGER',7839,SYSDATE,8900,NULL,10);&lt;br /&gt;&lt;br /&gt;MERGE&lt;br /&gt;INTO emp tgt&lt;br /&gt;USING emp1 src&lt;br /&gt;ON ( src.empno = tgt.empno )&lt;br /&gt;WHEN MATCHED&lt;br /&gt;THEN&lt;br /&gt;UPDATE&lt;br /&gt;SET tgt.ename = src.ename,&lt;br /&gt;tgt.job = src.job,&lt;br /&gt;tgt.mgr = src.mgr,&lt;br /&gt;tgt.hiredate = src.hiredate,&lt;br /&gt;tgt.sal = src.sal,&lt;br /&gt;tgt.deptno = src.deptno&lt;br /&gt;WHEN NOT MATCHED&lt;br /&gt;THEN&lt;br /&gt;Insert(&lt;br /&gt;Tgt.empno,&lt;br /&gt;Tgt.Ename,&lt;br /&gt;Tgt.Job,&lt;br /&gt;Tgt.Mgr,&lt;br /&gt;Tgt.Hiredate,&lt;br /&gt;Tgt.Sal,&lt;br /&gt;Tgt.Comm,&lt;br /&gt;Tgt.Deptno)&lt;br /&gt;values (src.empno,&lt;br /&gt;src.ename,&lt;br /&gt;src.job,&lt;br /&gt;src.mgr,&lt;br /&gt;src.hiredate,&lt;br /&gt;src.sal,&lt;br /&gt;src.comm,&lt;br /&gt;src.deptno);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;64) Display all the records for deptno which belongs to employee name JAMES? &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where deptno in(select deptno from emp where ename = 'JAMES')&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;65) Display all the records in emp table where salary should be less then or equal to ADAMS salary?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where sal &lt;= (select sal from emp where ename='ADAMS')&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;66) Display all employees those were joined before employee WARD joined?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where hiredate &lt; (select hiredate from emp where ename='WARD')&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;67) Display all subordinate those who are working under BLAKE?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Select ename from emp where mgr = (select empno from emp where ename='BLAKE')&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;68) Display all subordinate(all levels) for employee BLAKE?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select ename from emp start with empno = (select empno from emp where ename='BLAKE')&lt;br /&gt;connect by prior empno = mgr&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;69) Display all record in emp table for deptno which belongs to KING's Job? &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where deptno in(select deptno from emp where job= (select job from emp where ename = 'KING'))&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;70) Display the employees for empno which belongs to job PRESIDENT?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where empno in(select empno from emp where ename in(select ename from emp where JOB = 'PRESIDENT'));&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;71) Display list of ename those who have joined in Year 81 as MANAGER?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where to_char(hiredate,'YYYY') = 1981 and job = 'MANAGER';&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;72) Display who is making highest commission?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where comm = (select max(comm) from emp);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;73) Display who is senior most employee? How many years has been working?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where trunc(sysdate-hiredate)/365 = (select max(trunc(sysdate-hiredate)/365) from emp);&lt;br /&gt;&lt;br /&gt;select * from emp where hiredate =(select min(hiredate) from emp)&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;74) Display who is most experienced and least experienced employee?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select * from emp where trunc(sysdate-hiredate)/365 = (select min(trunc(sysdate-hiredate)/365) from emp);&lt;br /&gt;&lt;br /&gt;select * from emp where hiredate =(select max(hiredate) from emp)&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;75) Display ename, sal, grade, dname, loc for each employee.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select empno,ename,b.deptno,dname,grade from&lt;br /&gt;emp a,dept b, salgrade c&lt;br /&gt;where a.deptno = b.deptno&lt;br /&gt;and sal between losal and hisal;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;76) Display all employee whose location is DALLAS?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SELECT emp.ename, emp.JOB, emp.deptno&lt;br /&gt;FROM emp&lt;br /&gt;WHERE EXISTS&lt;br /&gt;(SELECT 'x'&lt;br /&gt;FROM dept d&lt;br /&gt;WHERE d.DEPTNO = emp.DEPTNO&lt;br /&gt;AND d.LOC = 'DALLAS') ;&lt;br /&gt;&lt;br /&gt;select emp.ename, emp.job, emp.deptno&lt;br /&gt;from emp&lt;br /&gt;where deptno in(select deptno from dept where loc='DALLAS');&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;77) Display ename, job, dname, deptno for each employee by using INLINE view?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SELECT emp.ename,&lt;br /&gt;emp.JOB,&lt;br /&gt;emp.deptno,&lt;br /&gt;dnames.dname&lt;br /&gt;FROM emp&lt;br /&gt;JOIN (select dname, deptno&lt;br /&gt;from dept ) dnames ON emp.deptno = dnames.deptno&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;78) List ename, job, sal and department of all employees whose salary is not within the salary grade?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;select ename, job, sal, dname&lt;br /&gt;from emp, dept&lt;br /&gt;where emp.deptno = dept.deptno&lt;br /&gt;and not exists&lt;br /&gt;(select ‘x’ from salgrade&lt;br /&gt;where emp.sal between losal and hisal);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;79) Use EMP and EMP1 table. Query should have only three columns. Display empno,ename,sal from both tables inluding duplicates.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;select empno, ename, sal from emp&lt;br /&gt;union all&lt;br /&gt;select empno, ename, sal from emp1&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;80) Delete emp table for detpno 10 and 20.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;delete emp where deptno in(10,20);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;81) Delete all employees those are not getting any commission?&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;delete emp where comm is null;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;82) Delete all employees those who employeed more then 28 years&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;delete emp where trunc(sysdate - hiredate)/365 &gt; 28;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;83) Add duplicate records in emp1 table. Delete the duplicate records in emp1 table.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;insert into emp1 select * from emp1 where rownum &lt;=1; commit; delete emp1 a where a.rowid &lt;&gt;(select min(b.rowid) from emp1 b where a.empno = b.empno);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;84) Delete the employees where employee salary greater then average salary of department salary?&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;delete emp a where sal &gt; (select avg(sal) from emp where emp.deptno = a.deptno);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;85) Delete all employees those who are reporting to BLAKE?&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Delete emp where ename in(Select ename from emp where mgr = (select empno from emp where ename='BLAKE'))&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;86) Delete all levels of employees those who are under BLAKE?&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;span style="color:#666666;"&gt;Delete emp where ename in(select ename from emp start with empno = (select empno from emp where ename='BLAKE')&lt;br /&gt;connect by prior empno = mgr)&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;87) Delete all employees those who are only managers?&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;delete emp where ename in(select ename from emp a where empno in (select mgr from emp b where b.mgr = a.empno and mgr is not null))&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;br /&gt;88) Remove the department in dept table where dept does not have any employees?&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;delete dept where deptno not in(select deptno from emp where deptno is not null)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;89) Remove all grade 2 employees in emp table?&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;delete emp where empno in(select empno from emp,salgrade where sal between losal and hisal and grade = 2)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;90) Remove all the employees in SMITH's department&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;delete emp where deptno = (select deptno from emp where ename = 'SMITH')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;91) Remove least paid employee who are reporting to BLAKE ?&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;delete emp where sal = (select min(sal) from emp where mgr =&lt;br /&gt;(select empno from emp where ename = 'BLAKE')) and&lt;br /&gt;ename in(select ename from emp where mgr =&lt;br /&gt;(select empno from emp where ename = 'BLAKE'))&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;92) Remove all employees who were joined before SMITH joined?&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;span style="color:#000000;"&gt;delete emp where hiredate &lt; (select hiredate from emp where ename='SMITH');&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;&lt;br /&gt;93) Rename the employee name JONES to ANDY&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;update emp set ename = 'ANDY' where ename = 'JONES'&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;94) Change the WARD's hiredate to one day ahead&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;update emp set hiredate = hiredate + 1 where ename = 'WARD'&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;95) Update MARTIN salary same as SMITH's salary&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;update emp set sal = (select sal from emp where ename = 'SMITH') where ename='MARTIN'&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;96) Increase the salary 5% for employee those who are earning commission less then 1000&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;update emp set sal = sal + (sal * (5/100)) where comm between 0 and 1000&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;97) Increase 250$ commission for BLAKE's team&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;update emp set comm = nvl(comm,0)+250 where mgr = (select empno from emp where ename='BLAKE');&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;98) Increase 100$ for employee who is making more then averge salary of his department?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;update emp a set sal = sal + 150 where sal &gt; (select avg(sal) from emp b where b.deptno = a.deptno)&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;99) Increase 1% salary for employee who is making lowest salary in dept 10&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;update emp set sal = sal + (sal* 1/100)&lt;br /&gt;where&lt;br /&gt;sal = (select min(sal) from emp where deptno = 10)&lt;br /&gt;and deptno = 10&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;100) Reduce the commission amount from employee salary for each employee who were joined after ALLEN joined. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;update emp set sal = sal - NVL(comm,0)&lt;br /&gt;where empno in(select empno from emp where hiredate &gt; (select hiredate from emp where&lt;br /&gt;ename = 'ALLEN'))&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;101) Increase commission 10$ for employees those who are located in NEW YORK.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;update emp a set comm = NVL(COMM,0) + 10&lt;br /&gt;where deptno = (select deptno from dept where loc='NEW YORK');&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Hope you enjoy all these questions... Please let me know if you have any comments or clarification... Feel free to click advertisement to maintain this blog. Thank you for visiting my Bog!!!.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-1665066146292761174?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/1665066146292761174/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=1665066146292761174' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1665066146292761174'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1665066146292761174'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/09/oracle-sql-questions.html' title='Oracle SQL Questions for Newbies'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-2729146821763681592</id><published>2009-08-12T11:17:00.000-07:00</published><updated>2009-09-27T09:54:23.296-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='technique to pass oracle11g OCP exam'/><category scheme='http://www.blogger.com/atom/ns#' term='OCP exam preparation'/><category scheme='http://www.blogger.com/atom/ns#' term='tips to prepare oracle OCP exam'/><category scheme='http://www.blogger.com/atom/ns#' term='testking question papers'/><category scheme='http://www.blogger.com/atom/ns#' term='How do we prepare the oracle11g 1ZO-050 exam'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle certified exam'/><title type='text'>Oracle11g OCP Exam Passed</title><content type='html'>I am glad that, i just passed my Oracle11g OCP exam last week. I just wanted to share my preparation with other folks...&lt;br /&gt;&lt;br /&gt;Here are the my preparation steps.&lt;br /&gt;&lt;br /&gt;1. Read Oracle11g New features Ebook(Download the book &lt;a href="http://rs224.rapidshare.com/files/167618360/OCP_Oracle_Database_11g.rar"&gt;here&lt;/a&gt;)&lt;br /&gt;2. Read the oracle-base link. &lt;a href="http://www.oracle-base.com/articles/11g/Articles11g.php"&gt;Click&lt;/a&gt;&lt;br /&gt;3. Went through testking question (Please contact me if you need)&lt;br /&gt;4. Ofcourse, My practical experience helped me to pass this exam.&lt;br /&gt;&lt;br /&gt;At the end, i successfully passed 1ZO-050 exam with 99% score.&lt;br /&gt;&lt;br /&gt;Hope it helps.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-2729146821763681592?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/2729146821763681592/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=2729146821763681592' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2729146821763681592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2729146821763681592'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/08/oracle11g-ocp-exam-passed.html' title='Oracle11g OCP Exam Passed'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-515591282717225909</id><published>2009-08-12T11:01:00.000-07:00</published><updated>2009-08-12T11:45:57.061-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='download logo'/><category scheme='http://www.blogger.com/atom/ns#' term='OCP logo'/><category scheme='http://www.blogger.com/atom/ns#' term='OCM logo'/><category scheme='http://www.blogger.com/atom/ns#' term='OCA logo'/><category scheme='http://www.blogger.com/atom/ns#' term='download OCP logo'/><category scheme='http://www.blogger.com/atom/ns#' term='how can i download OCP logo'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle certified Professional logo'/><title type='text'>Where to download OCP Logo?</title><content type='html'>Some of the folks, they customize the logo to upload in their resume without knowing the oracle registered logo. I thought, it would be useful to provide the links to download the logo. There are several source which we can use to download the logo.&lt;br /&gt;&lt;br /&gt;Here is the google link to download the logo... &lt;a href="http://images.google.com/images?um=1&amp;amp;hl=en&amp;amp;sa=X&amp;amp;oi=spell&amp;amp;resnum=0&amp;amp;ct=result&amp;amp;cd=1&amp;amp;q=oracle+ocp+logo&amp;amp;spell=1"&gt;Google Link&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Hope you enjoy this link to download the OCP logo...  Have a fun.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-515591282717225909?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/515591282717225909/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=515591282717225909' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/515591282717225909'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/515591282717225909'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/08/where-to-download-ocp-logo.html' title='Where to download OCP Logo?'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-2871711248711181631</id><published>2009-06-17T09:47:00.000-07:00</published><updated>2009-06-20T15:11:45.374-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='strongly typed ref cursor'/><category scheme='http://www.blogger.com/atom/ns#' term='SYS_REFCURSOR'/><category scheme='http://www.blogger.com/atom/ns#' term='display ref cursor result through SQL*PLUS'/><category scheme='http://www.blogger.com/atom/ns#' term='weakly typed ref cursor'/><category scheme='http://www.blogger.com/atom/ns#' term='declare ref cursor'/><category scheme='http://www.blogger.com/atom/ns#' term='what is ref cursor'/><category scheme='http://www.blogger.com/atom/ns#' term='difference between ref cursor and normal cursor'/><title type='text'>How do we use Ref Cursor?</title><content type='html'>&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;What is REF CURSOR?&lt;/strong&gt; &lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;A REF CURSOR is basically a data type. A variable created based on such a data type is generally called a cursor variable. A cursor variable can be associated with different queries at run-time. The main purpose of the ref cursor is, we can return the query result in the front end(Java, .Net, VB, reporting tools etc). For instance, if we want to return the query result set in Cognos reporting tool, then we can use the ref cursor to return the values. The primary use of ref cursor is to pass the result set back to calling application. Ref cursor can be passed as a variable to another subroutine. The powerful cabability in ref cursor is, cursor can be opened and passed to another block for processing, then returned to original block to be closed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This article is tested in oracle9i and it should work in oracle10g and further versions... All the below PLSQL code in this article is successfully tested in oracle 9.2.0.8. I tested the code in Scott schema with emp and dept tables.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;What is the difference between REF CURSOR and Normal Cursor? &lt;/span&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;span style="color:#ff0000;"&gt;1. &lt;/span&gt;The cursor concept is same between regular cursor(PLSQL cursor) and ref cursor. But normal cursor, we can declare and define the cursor in the declaration part. In the declaration itself, the select statement is tied up with the cursor. So the cursor structure is known in the compile time. It is static in definition.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In ref cursor, we just declare the variable as SYS_REFCURSOR data type. We are not tying with any select statement in the declaration. But inside the procedure, we can tie up the same ref cursor variable with any number of select statement. It is dynamic and dynamically opened in the procedure, based on the logic or condition.&lt;br /&gt;&lt;br /&gt;Let us demonstrate this... I have stored procedure and i am passing input 1 or 2. If i pass 1, then i wanted to display emp table records. If i pass input 2, then i wanted to display dept table. I am demonstrating this in normal cursor and ref cursor.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Here is the way to accomplish this in Normal cursor. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;create or replace procedure Test_refcursor(p_choice NUMBER) is&lt;br /&gt;cursor c1 is select * from emp;&lt;br /&gt;cursor c2 is select * from dept;&lt;br /&gt;begin&lt;br /&gt;if p_choice = 1 then&lt;br /&gt;for i in c1 loop&lt;br /&gt;dbms_output.put_line(i.ename);&lt;br /&gt;end loop;&lt;br /&gt;elsif p_choice = 2 then&lt;br /&gt;for i in c2 loop&lt;br /&gt;dbms_output.put_line(i.dname);&lt;br /&gt;end loop;&lt;br /&gt;end if;&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Here is the way to accomplish this in ref cursor. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create or replace procedure test_refcursor(p_choice number) is&lt;br /&gt;c1 sys_refcursor;&lt;br /&gt;v_ename emp.ename%type;&lt;br /&gt;v_dname dept.dname%type;&lt;br /&gt;procedure gen_cur(chc IN number,b IN OUT sys_refcursor) is&lt;br /&gt;str varchar2(1000);&lt;br /&gt;begin&lt;br /&gt;if chc = 1 then&lt;br /&gt;str:= 'select ename from emp';&lt;br /&gt;elsif chc = 2 then&lt;br /&gt;str:= 'select dname from dept';&lt;br /&gt;end if;&lt;br /&gt;open b for str;&lt;br /&gt;end;&lt;br /&gt;begin&lt;br /&gt;gen_cur(p_choice,c1);&lt;br /&gt;if p_choice = 1 then&lt;br /&gt;loop&lt;br /&gt;fetch c1 into v_ename;&lt;br /&gt;exit when c1%notfound;&lt;br /&gt;dbms_output.put_line(v_ename);&lt;br /&gt;end loop;&lt;br /&gt;elsif p_choice = 2 then&lt;br /&gt;loop&lt;br /&gt;fetch c1 into v_dname;&lt;br /&gt;exit when c1%notfound;&lt;br /&gt;dbms_output.put_line(v_dname);&lt;br /&gt;end loop;&lt;br /&gt;end if;&lt;br /&gt;end;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2. &lt;/span&gt;&lt;span style="color:#000000;"&gt;Ref cursor output can be returned to client(java, .Net, VB, reporting tool etc) application. But normal cursor(PLSQL cursor) output can not be returned to client application.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3. &lt;/span&gt;&lt;span style="color:#000000;"&gt;Normal cursor can be global. For example, we can declare the normal cursor in the package specification. It can be used in all procedure/functions in the same package as well as outside the package. But ref cursor can not be declared outside of the procedure. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;4.&lt;/span&gt; Normal cursor can not be passed from one subroutine to another subroutine. But ref cursor can be passed from one subroutine to another subroutine.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;How do we declare ref cursor?&lt;/strong&gt;&lt;/span&gt; &lt;span style="color:#000000;"&gt;There are two type of ref cursor variable declaration. One is weak type declaration and another one is strong type declaration. Weak typed declaration does not tell us return data structure. Strong type declaration will tell us what type of data will be returned. Strongly typed cursor has less flexibilities and less prone to programming errors. Weakly typed cursors has more flexibilities and it can return different structure of of the data.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;type emp_cursor is ref cursor; -- Weak typed declaration&lt;br /&gt;&lt;br /&gt;type emp_cursor is ref cursor&lt;br /&gt;returning emp%rowtype; -- Strong typed declaration&lt;br /&gt;&lt;br /&gt;Once cursor type is defined, then cursor variable can be assigned to cursor type.&lt;br /&gt;c1 emp_cursor;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Sample program for ref cursor... &lt;/span&gt;&lt;span style="color:#000000;"&gt;Pass the employee name as a input to procedure and return all subordinates. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;CREATE OR REPLACE PROCEDURE testrefcursor(&lt;br /&gt;p_ename IN VARCHAR2,&lt;br /&gt;curename OUT SYS_REFCURSOR) IS&lt;br /&gt;sql_text VARCHAR2(4000);&lt;br /&gt;BEGIN&lt;br /&gt;sql_text := 'SELECT ENAME&lt;br /&gt;FROM EMP&lt;br /&gt;WHERE ENAME != :1&lt;br /&gt;START WITH ENAME = :2&lt;br /&gt;CONNECT BY PRIOR EMPNO = MGR';&lt;br /&gt;IF curename%ISOPEN THEN&lt;br /&gt;CLOSE curename;&lt;br /&gt;END IF ;&lt;br /&gt;OPEN curename&lt;br /&gt;FOR sql_text USING p_ename,p_ename;&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Let us accomplish the same above task through Function.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;CREATE OR REPLACE FUNCTION testrefcursor(p_ename IN VARCHAR2)&lt;br /&gt;RETURN SYS_REFCURSOR IS&lt;br /&gt;sql_text VARCHAR2(4000);&lt;br /&gt;curename SYS_REFCURSOR;&lt;br /&gt;BEGIN&lt;br /&gt;sql_text := 'SELECT ENAME&lt;br /&gt;FROM EMP&lt;br /&gt;WHERE ENAME != :1&lt;br /&gt;START WITH ENAME = :2&lt;br /&gt;CONNECT BY PRIOR EMPNO = MGR';&lt;br /&gt;IF curename%ISOPEN THEN&lt;br /&gt;CLOSE curename;&lt;br /&gt;END IF ;&lt;br /&gt;OPEN curename&lt;br /&gt;FOR sql_text USING p_ename,p_ename;&lt;br /&gt;RETURN curename;&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;How do we display ref cursor result through SQL*PLUS? &lt;/span&gt;&lt;span style="color:#000000;"&gt;It is simple. Let us go with some sample code and demonstrate how to display the output in SQL*PLUS? Let us display the output for the above procedure testrefcursor.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; DECLARE&lt;br /&gt;2 refcursor SYS_REFCURSOR;&lt;br /&gt;3 v_ename EMP.ENAME%TYPE;&lt;br /&gt;4 BEGIN&lt;br /&gt;5 testrefcursor('KING',refcursor);&lt;br /&gt;6 loop&lt;br /&gt;7 fetch refcursor into v_ename;&lt;br /&gt;8 exit when refcursor%notfound;&lt;br /&gt;9 dbms_output.put_line(v_ename);&lt;br /&gt;10 end loop;&lt;br /&gt;11 end;&lt;br /&gt;12 /&lt;br /&gt;JONES&lt;br /&gt;SCOTT&lt;br /&gt;ADAMS&lt;br /&gt;FORD&lt;br /&gt;SMITH&lt;br /&gt;BLAKE&lt;br /&gt;ALLEN&lt;br /&gt;WARD&lt;br /&gt;MARTIN&lt;br /&gt;TURNER&lt;br /&gt;JAMES&lt;br /&gt;CLARK&lt;br /&gt;MILLER&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Here is the way, we can display the above function output....&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; select testrefcursor('KING') from dual;&lt;br /&gt;&lt;br /&gt;TESTREFCURSOR('KING'&lt;br /&gt;--------------------&lt;br /&gt;CURSOR STATEMENT : 1&lt;br /&gt;&lt;br /&gt;CURSOR STATEMENT : 1&lt;br /&gt;&lt;br /&gt;ENAME&lt;br /&gt;----------&lt;br /&gt;JONES&lt;br /&gt;SCOTT&lt;br /&gt;ADAMS&lt;br /&gt;FORD&lt;br /&gt;SMITH&lt;br /&gt;BLAKE&lt;br /&gt;ALLEN&lt;br /&gt;WARD&lt;br /&gt;MARTIN&lt;br /&gt;TURNER&lt;br /&gt;JAMES&lt;br /&gt;CLARK&lt;br /&gt;MILLER&lt;br /&gt;&lt;br /&gt;13 rows selected.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;We can also define SQL*PLus variables of type REFCURSOR...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; create or replace function getemplist(dno in number)&lt;br /&gt;2 return sys_refcursor&lt;br /&gt;3 is&lt;br /&gt;4 return_value sys_refcursor;&lt;br /&gt;5 begin&lt;br /&gt;6 open return_value for&lt;br /&gt;7 select ename from emp where deptno = dno;&lt;br /&gt;8 return return_value;&lt;br /&gt;9 end;&lt;br /&gt;10 /&lt;br /&gt;&lt;br /&gt;Function created.&lt;br /&gt;&lt;br /&gt;SQL&gt; var rc refcursor&lt;br /&gt;SQL&gt; exec :rc := getemplist(30)&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; print rc&lt;br /&gt;&lt;br /&gt;ENAME&lt;br /&gt;----------&lt;br /&gt;ALLEN&lt;br /&gt;WARD&lt;br /&gt;MARTIN&lt;br /&gt;BLAKE&lt;br /&gt;TURNER&lt;br /&gt;JAMES&lt;br /&gt;&lt;br /&gt;6 rows selected.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;When and what circumstances we should use ref cursor? &lt;/strong&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Ref cursor is classic option when we want to return the query output into any front end application. We can use ref cursor when you are not able to accomplish the task through normal cursor. REF CURSOR is flexibility feature, but not performance feature. Ref cursor is bad choice when performance is a concern and able to accomplish the task by using regular cursor. Ref cursor always consumes time to process the query compared to normal cursor. So ref cursor should be used only place where it is required. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Performance comparision between ref cursor and regular cursor?&lt;/strong&gt;&lt;/span&gt; Ref cursor is not a good option if performance is a concern. but ofcourse, there are place you can not avoid ref cursor. Ref cursor is not an option when you want to process the records inside the PLSQL procedure. Ref cursor is always slower then explicit cursor and implicit cursor. Let me demonstrate how process time between ref cursor, explicit cursor and implicit cursor...&lt;br /&gt;&lt;br /&gt;As per the below example, the ref cursor consumes more time then the explicit cursor and implicit cursor.... So in netshell, use ref cursor only if it is required. otherwise, try to use regular cursor..&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Note : For some reason, in the below code, pipe symbol is not appearing in the blog. So i replaced the pipe symbol with # symbol. In case if you want to run the below code in your database, please replace back # with pipe sign.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; CREATE OR REPLACE PROCEDURE stp_refcursor_comparison AS&lt;br /&gt;2 l_loops NUMBER := 10000;&lt;br /&gt;3 l_dummy dual.dummy%TYPE;&lt;br /&gt;4 l_start NUMBER;&lt;br /&gt;5 CURSOR c_dual IS&lt;br /&gt;6 SELECT dummy&lt;br /&gt;7 FROM dual;&lt;br /&gt;8 l_cursor SYS_REFCURSOR;&lt;br /&gt;9 BEGIN&lt;br /&gt;10 -- Time explicit cursor.&lt;br /&gt;11 l_start := DBMS_UTILITY.get_time;&lt;br /&gt;12 FOR i IN 1 .. l_loops LOOP&lt;br /&gt;13 OPEN c_dual;&lt;br /&gt;14 FETCH c_dual&lt;br /&gt;15 INTO l_dummy;&lt;br /&gt;16 CLOSE c_dual;&lt;br /&gt;17 END LOOP;&lt;br /&gt;18 DBMS_OUTPUT.put_line('Explicit: ' #&lt;br /&gt;19 (DBMS_UTILITY.get_time - l_start));&lt;br /&gt;20 -- Time ref cursor.&lt;br /&gt;21 l_start := DBMS_UTILITY.get_time;&lt;br /&gt;22 FOR i IN 1 .. l_loops LOOP&lt;br /&gt;23 OPEN l_cursor FOR SELECT dummy FROM dual;&lt;br /&gt;24 FETCH l_cursor&lt;br /&gt;25 INTO l_dummy;&lt;br /&gt;26 CLOSE l_cursor;&lt;br /&gt;27 END LOOP;&lt;br /&gt;28 DBMS_OUTPUT.put_line('REF CURSOR: ' #&lt;br /&gt;29 (DBMS_UTILITY.get_time - l_start));&lt;br /&gt;30 -- Time implicit cursor.&lt;br /&gt;31 l_start := DBMS_UTILITY.get_time;&lt;br /&gt;32 FOR i IN 1 .. l_loops LOOP&lt;br /&gt;33 SELECT dummy&lt;br /&gt;34 INTO l_dummy&lt;br /&gt;35 FROM dual;&lt;br /&gt;36 END LOOP;&lt;br /&gt;37 DBMS_OUTPUT.put_line('Implicit: ' #&lt;br /&gt;38 (DBMS_UTILITY.get_time - l_start));&lt;br /&gt;39 END stp_refcursor_comparison;&lt;br /&gt;40 /&lt;br /&gt;&lt;br /&gt;Procedure created.&lt;br /&gt;&lt;br /&gt;SQL&gt; set serveroutput on&lt;br /&gt;SQL&gt; execute stp_refcursor_comparison;&lt;br /&gt;Explicit: 53&lt;br /&gt;REF CURSOR: 67&lt;br /&gt;Implicit: 35&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-2871711248711181631?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/2871711248711181631/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=2871711248711181631' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2871711248711181631'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2871711248711181631'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/06/how-do-we-use-ref-cursor.html' title='How do we use Ref Cursor?'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-8610379431524890894</id><published>2009-06-09T09:06:00.000-07:00</published><updated>2009-06-22T16:17:04.050-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dimension'/><category scheme='http://www.blogger.com/atom/ns#' term='star schema'/><category scheme='http://www.blogger.com/atom/ns#' term='fact'/><category scheme='http://www.blogger.com/atom/ns#' term='when do we use snowflake schema'/><category scheme='http://www.blogger.com/atom/ns#' term='star schema example'/><category scheme='http://www.blogger.com/atom/ns#' term='factless fact'/><category scheme='http://www.blogger.com/atom/ns#' term='learndatamodel'/><category scheme='http://www.blogger.com/atom/ns#' term='slowly changing dimension'/><category scheme='http://www.blogger.com/atom/ns#' term='snowflake schema'/><category scheme='http://www.blogger.com/atom/ns#' term='advantage of snowflake'/><category scheme='http://www.blogger.com/atom/ns#' term='SCD'/><title type='text'>Star schema vs Snowflake Schema</title><content type='html'>&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;What is star schema?&lt;/strong&gt; &lt;/span&gt;Star schema is data warehousing data model which resembles to star. There are one or more fact table connected with multiple dimensional tables. Center of the star consist of one or more fact table and fact is pointing to different dimension tables. Dimension tables have a simple primary key, while fact tables have a composit primary key consisting of the aggregate of relevant dimension keys.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Fact table&lt;/span&gt; consists of Measurements or facts of business process. It is centeralized table in star schema, called FACT. A fact table typically has two types of columns: those that contain facts and those that are foreign keys to dimension tables. The primary key of a fact table is usually a composite key that is made up of all of its foreign keys. Fact table contains the content of the Datawarehouse. A fact table might contain either detail level facts or facts that have been aggregated (fact tables that contain aggregated facts are often instead called summary tables). In the real world, it is possible to have a fact table that contains no measures or facts. These tables are called as Factless Fact tables.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Factless Fact &lt;span style="color:#000000;"&gt;means only the key available in the Fact and there are no measures available. Factless fact can have only keys or keys with count of occurrences/ events (For instance, no of accident in a month, no of policies has been closed in a month). It is used to support negative analysis report. For example a Store that did not sell a product for a given period. It is used to join the dimension tables.&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Dimension table&lt;/span&gt; is a parent table which is connected with Fact table. Dimension has attributes which are normally descriptive and textual values. For instance, SALES table is fact table and possible dimension tables are TIME, PRODUCT, REGION, SALESPERSON, etc. Dimension never have foreign key in star schema data model.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Slowly changing dimension(SCD) &lt;/span&gt;&lt;span style="color:#000000;"&gt;applies to cases where the attribute for a record varies over time. We have three type of SCD, Type1, Type2 and Type3.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Type1:&lt;/span&gt; The new record replaces the original record. No trace of the old record exists&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Type2:&lt;/span&gt; A new record is added into the customer dimension table. Therefore, the customer is treated essentially as two people.&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Type3: &lt;/span&gt;&lt;span style="color:#000000;"&gt;The original record is modified to reflect the change&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;span style="color:#000000;"&gt;To learn more about SCD, please click&lt;/span&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;&lt;a href="http://www.learndatamodeling.com/sl_dim.htm"&gt;SCD&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Here is sample data model for star schema&lt;/span&gt;. In the below data model, the dimensions are products, customers, time and locations. The fact table is sales and it is connected with all dimension. Now we can see the fact data with different dimensions. The fact table Foreign key will be connected with primary key of dimension table. We never connect the one dimension table to another dimension table. Oracle optimizer understand the star query and generate the different execution plan to improve the performance.&lt;br /&gt;&lt;/p&gt;&lt;a href="http://4.bp.blogspot.com/_b-90-vOW7is/SjEDV07ZrnI/AAAAAAAAADM/eZN7iPR8iDo/s1600-h/star+schema.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5346057906185416306" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 220px; TEXT-ALIGN: center" alt="" src="http://4.bp.blogspot.com/_b-90-vOW7is/SjEDV07ZrnI/AAAAAAAAADM/eZN7iPR8iDo/s320/star+schema.jpg" border="0" /&gt;&lt;/a&gt; &lt;span style="color:#ff0000;"&gt;&lt;strong&gt;What is snowflake schema?&lt;/strong&gt;&lt;/span&gt; The snowflake schema is an extension of the star schema, where each point of the star explodes into more points. In a star schema, each dimension is represented by a single dimensional table, whereas in a snowflake schema, that dimensional table is normalized into multiple lookup tables, each representing a level in the dimensional hierarchy.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Here is sample data model for snowflake schema..&lt;/span&gt; Here customer dimension is normalized into another lookup table customertype. The same way, we can also normalize the customer dimension into another lookup table as country. Location dimension is normalized into territory. Product dimension can also be normalized into another lookup table as supplier...&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_b-90-vOW7is/SjEDOzfBDDI/AAAAAAAAADE/MuAmBRkVijM/s1600-h/snowflake.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5346057785538841650" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 214px; TEXT-ALIGN: center" alt="" src="http://4.bp.blogspot.com/_b-90-vOW7is/SjEDOzfBDDI/AAAAAAAAADE/MuAmBRkVijM/s320/snowflake.jpg" border="0" /&gt;&lt;/a&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Advantages of Snowflake...&lt;/span&gt; &lt;div&gt;&lt;div&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;&lt;span style="color:#ff0000;"&gt;1.&lt;/span&gt; No redundancy and hence more easy to maintain and change.&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2.&lt;/span&gt; When we normalize the dimension, the dimension will not be sparsed.&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3.&lt;/span&gt; It reduce the disk space since there is no redundancy. But in real world scenario, dimension is small table and disk space is not a major issue.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Disadvantages of Snowflake...&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;1.&lt;/span&gt; You need to join more tables when we write the query. It is less easy to understand.&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2.&lt;/span&gt; In snowflake model, query process time will increase, since we are joining multiple tables. &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;When should we go for snowflake schema? &lt;/span&gt;&lt;span style="color:#000000;"&gt;Dimension has many columns, &lt;/span&gt;&lt;span style="color:#000000;"&gt;and the data are very sparse, most of the fields has no data, also disk space is a concern, then we can think of snowflake. Since dimension tables hold less space, snow flake schema approach may be avoided in some organization. We can go for snowflake model when we have small data mart or datawarehouse. Star schema model is good for bigger data mart/warehouse. To learn more about snowflake schema, please &lt;a href="http://en.wikipedia.org/wiki/Snowflake_schema"&gt;click.&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;To learn more about dimensional data modeling, please see these links. &lt;a href="http://blog.oaktonsoftware.com/"&gt;Link1&lt;/a&gt; and &lt;a href="http://learndatamodeling.com/"&gt;Link2&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-8610379431524890894?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/8610379431524890894/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=8610379431524890894' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/8610379431524890894'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/8610379431524890894'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/06/star-schema-vs-snowflake-schema.html' title='Star schema vs Snowflake Schema'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_b-90-vOW7is/SjEDV07ZrnI/AAAAAAAAADM/eZN7iPR8iDo/s72-c/star+schema.jpg' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-4959840453462301588</id><published>2009-06-08T14:05:00.000-07:00</published><updated>2009-06-22T16:36:03.188-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='create temporary tablespace group'/><category scheme='http://www.blogger.com/atom/ns#' term='v$tempfile'/><category scheme='http://www.blogger.com/atom/ns#' term='default temporary tablespace'/><category scheme='http://www.blogger.com/atom/ns#' term='dba_temp_files'/><category scheme='http://www.blogger.com/atom/ns#' term='v$temp_space_header'/><category scheme='http://www.blogger.com/atom/ns#' term='temporary tablespace groups'/><category scheme='http://www.blogger.com/atom/ns#' term='v$sort_segment'/><category scheme='http://www.blogger.com/atom/ns#' term='dba_tablespace_groups'/><title type='text'>Temporary tablespace</title><content type='html'>&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;What is temporary tablespace? &lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Temporary tablespace is used to store temporary information which is used for sort operation. Data that is only used for the duration of a session is stored in a temporary tablespaces. Let us say, we are joining two large tables, then sorting may not be able to complete in memory. Apparently oracle use the temporary segment to complete the sorting. Here are some SQL statement which might require disk sorting.&lt;br /&gt;&lt;br /&gt;CREATE INDEX, ANALYZE, Select DISTINCT, ORDER BY, GROUP BY, UNION, INTERSECT, MINUS, Sort-Merge joins, etc&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;How do we create temporary tablespace?&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;CREATE TEMPORARY TABLESPACE temp2&lt;br /&gt;TEMPFILE 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEMP.DBF'&lt;br /&gt;SIZE 20M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 16M;&lt;br /&gt;&lt;br /&gt;TEMPFILEs are not recorded in the database's control file. This implies that one can just recreate them whenever you restore the database, or after deleting them by accident. RMAN never backup the temporary tablespace data files.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;How do we monitor temp tablespace?&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Temp files are listed in V$TEMPFILE and DBA_TEMP_FILES. V$SORT_SEGMENT and V$SORT_USAGE can be used to find out who occupies the space in temporary Tablespaces. DBA_FREE_SPACE does not record free space for temporary tablespaces. We can use V$TEMP_SPACE_HEADER to find out the free space and used space.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Default temporary tablespace(Oracle9i feature)&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;When DBA create user, he/she should assign temporary tablespace. Prior to oracle9i, if DBA forgot to assign the temporary tablespace, then oracle use SYSTEM tablespace for sorting. To avoid overloading SYSTEM tablespace, oracle9i introduced default temporary tablespace. So every database has default temporary tablespace since Oracle9i. In case, if we forgot to assign temporary tablespace while creating user, then oracle use default temporary tablespace for sorting. Here is the way, we can assign default temporary tablespace for entire database.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database default temporary tablespace temp1;&lt;br /&gt;&lt;br /&gt;To see the default temporary tablespace for a database, execute the following query:&lt;br /&gt;&lt;br /&gt;SQL&gt; select property_value from DATABASE_PROPERTIES where PROPERTY_NAME='DEFAULT_TEMP_TABLESPACE';&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Restriction on Default temporary tablespace:&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;1. You can drop a default temporary tablespace until after you have&lt;br /&gt;created new default temporary tablespace.&lt;br /&gt;&lt;br /&gt;2. You can not take default temporary tablespace offline&lt;br /&gt;&lt;br /&gt;3. You can not change a default temporary tablespace into a permanent tablespace&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Temporary tablespace Groups(Oracle10g feature)&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;In nutshell, temporary tablespace group is a shortcut or synonym for a list of temporary tablespaces. A temporary tablespace group can have only temporary tablespaces as members. A temporary tablespace group consist of at least one temporary tablespace. A temporary tablespace group can not be empty. After last member of a temporary tablespace group has been dropped, the temporary tablespace group no longer exists. The temporary tablespace group is created when the first temporary tablespace is added to the group.&lt;br /&gt;&lt;br /&gt;When ever a temporary tablespace can be referenced, a temporary tablespace group can be referenced as well. Therefore, temporary tablespace, temporary tablespace group share the same namespace. Temporary tablespace can not have the same name as a temporary tablespace group. The new view DBA_TABLESPACE_GROUPS shows the members of each temporary tablespace.&lt;br /&gt;&lt;br /&gt;The advantage of this feature is, we can tailor user load to individual temporary tablespaces. We can allow large sort operations to span and consume multiple temporary tablespaces if needed. We can Reduce contention when multiple temporary tablespaces are defined.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How temporary tablespace group works?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;Temporary tablespaces allow a single user with multiple session to potentially use a different temporary tablespace in each session. The user SCOTT is assigned the temporary tablespace group TEMPGRP consisting of TEMP1, TEMP2, TEMP3. The user SCOTT in session #1 may use actual temporary tablespace TEMP1, and user SCOTT in session#2 may use the actual temporary tablespace TEMP3. Not only does this prevent large tablespace operations from running out of temporary space, it also allows parallel operations within a single session to potentially use more than one actual temporary tablespace, even though in all the previous scenarios, SCOTT was assigned the TMPGRP temporary tablespace group. Logically the same temporary tablespace was used in every session.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Creating and Dropping temporary tablespace Groups:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;CREATE TEMPORARY TABLESPACE temp1 TEMPFILE&lt;br /&gt;'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEMP1.DBF' SIZE 20M;&lt;br /&gt;&lt;br /&gt;CREATE TEMPORARY TABLESPACE temp3 TEMPFILE&lt;br /&gt;'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEMP3.DBF' SIZE 20M;&lt;br /&gt;&lt;br /&gt;CREATE TEMPORARY TABLESPACE temp4 TEMPFILE&lt;br /&gt;'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEMP4.DBF' SIZE 20M;&lt;br /&gt;&lt;br /&gt;alter tablespace temp1 tablespace group tempgrp;&lt;br /&gt;alter tablespace temp3 tablespace group tempgrp;&lt;br /&gt;alter tablespace temp4 tablespace group tempgrp;&lt;br /&gt;alter database default temporary tablespace tempgrp;&lt;br /&gt;&lt;br /&gt;You can not drop the temporary tablespace group, but however, we can drop one of the members of the group as below.&lt;br /&gt;&lt;br /&gt;alter tablespace temp3 tablespace group '';&lt;br /&gt;&lt;br /&gt;We can also create temporary tablespace and we can immediately add it to an existing group, or create new group with one member as below.&lt;br /&gt;&lt;br /&gt;CREATE TEMPORARY TABLESPACE temp6 TEMPFILE&lt;br /&gt;'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEMP6.DBF' SIZE 20M&lt;br /&gt;tablespace group tempgrp2;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Assigning temporary tablespace group to users:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;br /&gt;&lt;/span&gt;Assigning a temporary tablespace group to a user is identical to assigning a temporary tablespace to user.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Create user test identified by test&lt;br /&gt;Default tablespace users&lt;br /&gt;Temporary tablespace tempgrp;&lt;br /&gt;&lt;br /&gt;Note that, if you did not specify a temporary tablespace for TEST, then we can still assign the temporary tablespace group.&lt;br /&gt;&lt;br /&gt;Alter user test temporary tablespace tempgrp;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;How do we resize the temporary data file?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;In many database configurations, the DBA will choose to allow their temporary tablespace to auto extend. A bad query can easily chew up valuable space on the disk. The DBA will often want to resize the temporary tablespace to a more reasonable size in order to reclaim that extra space. The obvious action would be to resize the tempfiles using the following statement:&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database tempfile&lt;br /&gt;'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEMP6.DBF' resize 250M;&lt;br /&gt;alter database tempfile 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEMP6.DBF'&lt;br /&gt;resize 250M&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:ORA-03297: file contains used data beyond requested RESIZE value&lt;br /&gt;&lt;br /&gt;Ooops.... It did not work!!!. There are several other method exists to resize the temp files. But there is obvious method exists in all the version which is dropping and recreating temp files. Dropping and recreating the temp file is straight forward when the temporary tablespace is not a default temporary tablespace.&lt;br /&gt;&lt;br /&gt;Since there are several method exists, i am going to discuss few ways about how to drop and recreate the temp files when temp file becomes bigger..... It is recommended to do this operation in off peak hours...&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Method1a... &lt;/span&gt;&lt;span style="color:#000000;"&gt;Let us assume, some one ran the bad query and the temp file is bigger. Now how do we resize the temp file to smaller size. The temporary tablespace is default temporary tablespace. In this scenario, temporary tablespace is not part of tempoary tablespace group. The temporary tablespace name is TEMP. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Step1:&lt;/span&gt; create a new temporary tablespace with reasonable size.&lt;br /&gt;&lt;br /&gt;CREATE TEMPORARY TABLESPACE tempspace TEMPFILE&lt;br /&gt;'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEMPSPACE.DBF' SIZE 20M;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step2:&lt;/span&gt; Modify the newly created temporary tablepsace as default temporary tablespace&lt;br /&gt;&lt;br /&gt;ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMPSPACE&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step3:&lt;/span&gt; Drop the bigger temporary tablespace. But before dropping, make sure, no one is using the temporary tablespace. Just make sure, the below query returns zero records.&lt;br /&gt;&lt;br /&gt;SELECT COUNT(*) FROM v$sort_usage WHERE tablespace = 'TEMP'&lt;br /&gt;SELECT COUNT(*) FROM v$tempseg_usage WHERE tablespace = 'TEMP'&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step4:&lt;/span&gt; Once the above(step3) query returns zero records, then drop the temporary tablespace.&lt;br /&gt;&lt;br /&gt;DROP TABLESPACE temp INCLUDING CONTENTS AND DATAFILES;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Method1b... &lt;/span&gt;&lt;span style="color:#000000;"&gt;Let us assume, some one ran the bad query and the temp file is bigger. Now how do we resize the temp file to smaller size. The temporary tablespace is default temporary tablespace. In this scenario, temporary tablespace is part of temporary tablespace group. The temporary tablespace name is TEMP and group name is TEMPGRP.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step1:&lt;/span&gt; Unlink the bigger tablespace from temporary tablespace group.&lt;br /&gt;&lt;br /&gt;alter tablespace temp tablespace group '';&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step2:&lt;/span&gt; Just make sure, no one is using temporary tablespace. Below query should return zero records.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;SELECT COUNT(*) FROM v$sort_usage WHERE tablespace = 'TEMP'&lt;br /&gt;SELECT COUNT(*) FROM v$tempseg_usage WHERE tablespace = 'TEMP'&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step3:&lt;/span&gt; Once the above(step3) query returns zero records, then drop the temporary tablespace.&lt;br /&gt;&lt;br /&gt;DROP TABLESPACE temp INCLUDING CONTENTS AND DATAFILES;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step4:&lt;/span&gt; Create new tablespace and add the tablespace to group.&lt;br /&gt;&lt;br /&gt;CREATE TEMPORARY TABLESPACE temp&lt;br /&gt;TEMPFILE 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEMP.DBF' SIZE 20M tablespace group tempgrp;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;How do we recover the temporary data file?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When ever, we the temporary tablespace temp file is corrupted or deleted accidently, then it is easy to recover. RMAN never backup the temporary tablespace. Till oracle9i, we make the temp file offline and drop the temp file at the database level(alter database datafile 'c:/oracle/oradata/temp.dbf' offline drop). Once it is dropped, then drop the temporary tablespace and recreate new one. Oracle10g introduced new feature which we will create the temp file automatically when we restart the database.&lt;br /&gt;&lt;br /&gt;Here is the steps in oracle10g. The database is running in windows OS.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step1:&lt;/span&gt; Let us delete the temp file to simulate that the temp file is corrupted.&lt;br /&gt;&lt;br /&gt;D:\oracle\product\10.2.0\oradata\orcl&gt;dir *.dbf&lt;br /&gt;Volume in drive D has no label.&lt;br /&gt;Volume Serial Number is 70AE-6E52&lt;br /&gt;&lt;br /&gt;Directory of D:\oracle\product\10.2.0\oradata\orcl&lt;br /&gt;&lt;br /&gt;06/14/2009 08:55 PM 104,865,792 EXAMPLE01.DBF&lt;br /&gt;06/14/2009 08:55 PM 251,666,432 SYSAUX01.DBF&lt;br /&gt;06/14/2009 08:55 PM 503,324,672 SYSTEM01.DBF&lt;br /&gt;06/14/2009 08:50 PM 20,979,712 TEMP01.DBF&lt;br /&gt;06/14/2009 08:55 PM 31,465,472 UNDOTBS01.DBF&lt;br /&gt;06/14/2009 08:55 PM 5,251,072 USERS01.DBF&lt;br /&gt;6 File(s) 917,553,152 bytes&lt;br /&gt;0 Dir(s) 15,348,064,256 bytes free&lt;br /&gt;&lt;br /&gt;D:\oracle\product\10.2.0\oradata\orcl&gt;del TEMP01.DBF&lt;br /&gt;&lt;br /&gt;D:\oracle\product\10.2.0\oradata\orcl&gt;dir *.dbf&lt;br /&gt;Volume in drive D has no label.&lt;br /&gt;Volume Serial Number is 70AE-6E52&lt;br /&gt;&lt;br /&gt;Directory of D:\oracle\product\10.2.0\oradata\orcl&lt;br /&gt;&lt;br /&gt;06/14/2009 08:55 PM 104,865,792 EXAMPLE01.DBF&lt;br /&gt;06/14/2009 08:55 PM 251,666,432 SYSAUX01.DBF&lt;br /&gt;06/14/2009 08:55 PM 503,324,672 SYSTEM01.DBF&lt;br /&gt;06/14/2009 08:55 PM 31,465,472 UNDOTBS01.DBF&lt;br /&gt;06/14/2009 08:55 PM 5,251,072 USERS01.DBF&lt;br /&gt;5 File(s) 896,573,440 bytes&lt;br /&gt;0 Dir(s) 15,369,043,968 bytes free&lt;br /&gt;&lt;br /&gt;D:\oracle\product\10.2.0\oradata\orcl&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step2:&lt;/span&gt; Let us restart the database. In oracle9i, the database will not open. But in oracle10g, when we start the database, it creates the temp file automatically and open the database. Just &lt;a href="http://download.oracle.com/docs/cd/B19306_01/backup.102/b14192/recov002.htm#BRBSC03607"&gt;click&lt;/a&gt; to know more info.&lt;br /&gt;&lt;br /&gt;D:\oracle\product\10.2.0\oradata\orcl&gt;set oracle_sid=orcl&lt;br /&gt;&lt;br /&gt;D:\oracle\product\10.2.0\oradata\orcl&gt;sqlplus sys/password as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 10.2.0.1.0 - Production on Sun Jun 14 21:41:51 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;Connected to an idle instance.&lt;br /&gt;&lt;br /&gt;SQL&gt; startup&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area 281018368 bytes&lt;br /&gt;Fixed Size 1248552 bytes&lt;br /&gt;Variable Size 88081112 bytes&lt;br /&gt;Database Buffers 188743680 bytes&lt;br /&gt;Redo Buffers 2945024 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;Database opened.&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step 3: &lt;/span&gt;&lt;span style="color:#000000;"&gt;Database opened successfully. Let us check the DB directory...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;D:\oracle\product\10.2.0\oradata\orcl&gt;dir *.dbf&lt;br /&gt;Volume in drive D has no label.&lt;br /&gt;Volume Serial Number is 70AE-6E52&lt;br /&gt;&lt;br /&gt;Directory of D:\oracle\product\10.2.0\oradata\orcl&lt;br /&gt;&lt;br /&gt;06/14/2009 08:55 PM 104,865,792 EXAMPLE01.DBF&lt;br /&gt;06/14/2009 08:55 PM 251,666,432 SYSAUX01.DBF&lt;br /&gt;06/14/2009 08:55 PM 503,324,672 SYSTEM01.DBF&lt;br /&gt;06/14/2009 09:42 PM 20,979,712 TEMP01.DBF&lt;br /&gt;06/14/2009 08:55 PM 31,465,472 UNDOTBS01.DBF&lt;br /&gt;06/14/2009 08:55 PM 5,251,072 USERS01.DBF&lt;br /&gt;6 File(s) 917,553,152 bytes&lt;br /&gt;0 Dir(s) 15,348,047,872 bytes free&lt;br /&gt;&lt;br /&gt;D:\oracle\product\10.2.0\oradata\orcl&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-4959840453462301588?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/4959840453462301588/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=4959840453462301588' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/4959840453462301588'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/4959840453462301588'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/06/temporary-tablespace.html' title='Temporary tablespace'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-634314980605579008</id><published>2009-06-01T15:13:00.000-07:00</published><updated>2009-06-23T13:07:50.923-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='standby database'/><category scheme='http://www.blogger.com/atom/ns#' term='physical standby database'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL apply'/><category scheme='http://www.blogger.com/atom/ns#' term='real time apply enabled'/><category scheme='http://www.blogger.com/atom/ns#' term='logical standby database'/><category scheme='http://www.blogger.com/atom/ns#' term='difference between logical standby and physical standby'/><category scheme='http://www.blogger.com/atom/ns#' term='primary database'/><category scheme='http://www.blogger.com/atom/ns#' term='archived redo log'/><title type='text'>Logical standby vs Physical standby</title><content type='html'>Standby database was introduced in oracle8i for high availability solution. Oracle9i enhanced the standby database and introduced Data Guard. Generally there are two type of standby database. One is physical standby and another one is logical standby. This article is written as per the version Oracle10gR2.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. What is physical standby database?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2. What is logical standby database?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3. What is the difference between logical standby and physical?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;4. At what circumstances, physical standby is useful?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;5. At what circumstances, logical standby is useful?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. What is physical standby database?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Physical standby database is physically identical to the primary database. It is block by block copy of the primary images. The archived redo log files are shipped to standby database and applied the archived redo log files on the standby database. So standby database should be always in recovery mode. This is like, DBA is sitting in remote location and recovering the primary database in different server by applying the archived redo log files.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2. What is logical standby database?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Logical standby database is logically identical to the primary database. Oracle use the &lt;/span&gt;logminer technology to transforms standard archived redo logs(by default) or redo logs(if real-time apply enabled) into SQL statements and applies them to the logical stand by database. A logical standby database can remain open and the same time its tables are updated from the primary database, and those tables are simultaneously available for read access. Oracle9i introduced logical standby database.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3. What is the difference between logical standby and physical standby?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Physical standby database is always in managed recovery mode. We can only open the physical standby database in read only mode. But archive redo logs can not be applied while physical standby database is in read only mode.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Logical standby database is always in open mode. The SQL statements which is generated from primary database is applied on logical standby while the database is in open mode. We can have additional materialized views, indexes and tables added for faster performance in logical standby.&lt;br /&gt;&lt;br /&gt;Physical standby schema matches exactly the source database. Logical standby database does not have to match the schema structure of the source database.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3. At what circumstances, physical standby is useful?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We can use Physical standby when we need to go for High availability solutions. Physical standby is the most commonly used for disaster recovery or failure.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;5. At what circumstances, logical standby is useful?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We can use logical standby if we want to off-load some of the reporting overhead in primary database. The logical standby database is an excellent choice to do queries, summations, and reporting activities, thereby off-loading the primary database from those tasks and saving valuable CPU and I/O cycles.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Note: Oracle recommends not to apply by DML operations on logical standby tables maintained by SQL Apply. This will introduce deviations between the primary and standby databases that will make it impossible for the logical standby database to be maintained.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;As per Oracle10gR2, Some of the SQL statments will not be shipped from primary database to logical standby database. Some sample SQL statements are......&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. CREATE or ALTER or DROP MATERIALIZED VIEW&lt;br /&gt;2. CREATE or ALTER or DROP MATERIALIZED VIEW LOG&lt;br /&gt;3. ALTER SESSION&lt;br /&gt;4. CREATE PFILE&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;5. CREATE or DROP DATABASE LINK&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;span style="color:#000000;"&gt;Please &lt;a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14239/manage_ls.htm#i1045623"&gt;click&lt;/a&gt; this link if you need to read more about standby DB.&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-634314980605579008?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/634314980605579008/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=634314980605579008' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/634314980605579008'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/634314980605579008'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/06/logical-standby-versus-physical-standby.html' title='Logical standby vs Physical standby'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-4331465865481117368</id><published>2009-05-28T10:33:00.000-07:00</published><updated>2009-06-20T09:01:19.532-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='orapwd'/><category scheme='http://www.blogger.com/atom/ns#' term='create spfile'/><category scheme='http://www.blogger.com/atom/ns#' term='SET NEWNAME FOR DATAFILE'/><category scheme='http://www.blogger.com/atom/ns#' term='cloning db'/><category scheme='http://www.blogger.com/atom/ns#' term='SKIP TABLESPACE'/><category scheme='http://www.blogger.com/atom/ns#' term='log_file_name_convert'/><category scheme='http://www.blogger.com/atom/ns#' term='Cloning Database through RMAN'/><category scheme='http://www.blogger.com/atom/ns#' term='duplicate target database'/><category scheme='http://www.blogger.com/atom/ns#' term='RMAN auxiliary'/><category scheme='http://www.blogger.com/atom/ns#' term='ORADIM'/><category scheme='http://www.blogger.com/atom/ns#' term='SKIP READONLY'/><title type='text'>Cloning Database through RMAN</title><content type='html'>A wonderful feature in RMAN to clone or duplicate the database on the same server or remote server. This feature is useful when someone truncated or dropped the table and they wanted to recover the table. In that case, we can clone the database in different location and recover the database until point of time. This feature is very useful to recover the selected object from the RMAN backup rather than roll back a whole database. It is possible to create a duplicate database on a remote server with the same file structure or remote server with different file structure or the local server with a different file structure.&lt;br /&gt;&lt;br /&gt;This article is tested in windows environment. Now I am going to clone the ORCL database and restore in different location on the same server. The new database name is called CLONEDB. Please remember, the directory, file names, Database names may varry between environment to environment. So you might need to change the scripts based on your database name, file structure when you follow the below steps.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Prerequisite:&lt;/span&gt; You should have target database and RMAN should be implemented to backup the target database. How do we implement RMAN backup? Please see this &lt;a href="http://myorastuff.blogspot.com/2009/05/steps-to-setup-rman.html"&gt;link&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Here is the Target DB and catalog DB info in my server.&lt;br /&gt;&lt;/span&gt;Target DB = ORCL&lt;br /&gt;CatalogDB = CATDB&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Data file, redo log, control file directory location for target and catalog DB:&lt;/span&gt;&lt;br /&gt;C:\oracle\product\10.2.0\oradata\orcl&lt;br /&gt;C:\oracle\product\10.2.0\oradata\catdb&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Tnsentry file location &lt;/span&gt;&lt;br /&gt;C:\oracle\product\10.2.0\db_1\NETWORK\ADMIN&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Password file location &lt;/span&gt;&lt;br /&gt;C:\oracle\product\10.2.0\db_1\database&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;SPFILE location:&lt;/span&gt;&lt;br /&gt;C:\oracle\product\10.2.0\db_1\dbs&lt;br /&gt;&lt;br /&gt;Here are the nine easy steps to clone the database. I have followed this steps in Oracle10gR2 in windows environment. So please test the below steps in your dev/test environment before proceed to production. The steps are pretty much same for unix environment except directory names and step5&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Step1&lt;/strong&gt;.&lt;/span&gt; First create the directory structures for the CLONEDB.&lt;br /&gt;&lt;br /&gt;Create the folder &lt;span style="color:#ff0000;"&gt;clonedb &lt;/span&gt;&lt;span style="color:#000000;"&gt;in the following locations.&lt;/span&gt;&lt;br /&gt;c:\oracle\product\10.2.0\oradata&lt;br /&gt;C:\oracle\product\10.2.0\admin&lt;br /&gt;&lt;br /&gt;Create folders(adump,bdump,cdump,dpdump,udump) in the following location.&lt;br /&gt;C:\oracle\product\10.2.0\admin\clonedb&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Step2. &lt;/strong&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Create the password file for clonedb database. Orapwd is oracle utility and we can run this utility in command prompt for windows server. For unix environment, we need to run this in $ prompt.&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;orapwd file=C:\oracle\product\10.2.0\db_1\database\PWDclonedb.ora password=password entries=10&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Step3.&lt;/strong&gt;&lt;/span&gt; Add the appropriate entries into the tnsnames.ora and listener.ora files.&lt;br /&gt;&lt;br /&gt;Add this entry in listener.ora file.&lt;br /&gt;&lt;br /&gt;(SID_DESC =&lt;br /&gt;(ORACLE_HOME = C:\oracle\product\10.2.0\db_1)&lt;br /&gt;(SID_NAME = CLONEDB))&lt;br /&gt;&lt;br /&gt;After adding the above entry, reload the listener(lsnrctl reload)&lt;br /&gt;&lt;br /&gt;Add the below entry in tnsnames.ora file..&lt;br /&gt;&lt;br /&gt;CLONEDB =&lt;br /&gt;(DESCRIPTION =&lt;br /&gt;(ADDRESS = (PROTOCOL = TCP)(HOST = EW_Training)(PORT = 1521))&lt;br /&gt;(CONNECT_DATA =&lt;br /&gt;(SERVER = DEDICATED)&lt;br /&gt;(SERVICE_NAME = clonedb)&lt;br /&gt;)&lt;br /&gt;)&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Step 4.&lt;/strong&gt;&lt;/span&gt; Build init.ora file for the duplicate database. Since we are duplicating the database on the same server as the original, we must convert the file names, so there is no conflict. These entries needs to be modified in pfile for cloning database.&lt;br /&gt;&lt;br /&gt;db_name='clonedb'&lt;br /&gt;dispatchers='(PROTOCOL=TCP) (SERVICE=clonedbXDB)'&lt;br /&gt;audit_file_dest='C:\oracle\product\10.2.0\admin\clonedb\adump'&lt;br /&gt;background_dump_dest='C:\oracle\product\10.2.0\admin\clonedb\bdump'&lt;br /&gt;control_files='C:\oracle\product\10.2.0\oradata\clonedb\control01.ctl',&lt;br /&gt;'C:\oracle\product\10.2.0\oradata\clonedb\control02.ctl',&lt;br /&gt;'C:\oracle\product\10.2.0\oradata\clonedb\control03.ctl'&lt;br /&gt;core_dump_dest='C:\oracle\product\10.2.0\admin\clonedb\cdump'&lt;br /&gt;user_dump_dest='C:\oracle\product\10.2.0\admin\clonedb\udump'&lt;br /&gt;db_file_name_convert=('C:\oracle\product\10.2.0\oradata\orcl','C:\oracle\product\10.2.0\oradata\clonedb')&lt;br /&gt;log_file_name_convert=('C:\oracle\product\10.2.0\oradata\orcl','C:\oracle\product\10.2.0\oradata\clonedb')&lt;br /&gt;&lt;br /&gt;The modified PFILE is located in C:\oracle\product\10.2.0\db_1\dbs\PFILE_CLONE.ORA&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Step 5. &lt;/strong&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Create the service for CLONEDB instance. Use ORDIM utility for windows environment.&lt;/span&gt; This command should run on OS Level.&lt;br /&gt;&lt;br /&gt;ORADIM -NEW -SID clonedb&lt;br /&gt;&lt;br /&gt;Creating service is only applicable for windows environment. We do not need to create any service in unix environment. In unix, starting the database spawns a services. We must ignore this step for unix environment.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Step 6.&lt;/span&gt;&lt;/strong&gt; Create the spfile by using pfile which is build in step 4. Login as sys user in ORCL database and run this script.&lt;br /&gt;&lt;br /&gt;create spfile = 'C:\oracle\product\10.2.0\db_1\dbs\SPFILECLONEDB.ORA'&lt;br /&gt;from pfile='C:\oracle\product\10.2.0\db_1\dbs\PFILE_CLONE.ORA'&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Step 7. &lt;/strong&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Create file name called initclonedb.ORA in C:\oracle\product\10.2.0\db_1\database location. The file should have the below content.&lt;br /&gt;SPFILE='C:\oracle\product\10.2.0\db_1/dbs/spfileclonedb.ora'&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Step 8.&lt;/span&gt;&lt;/strong&gt; Login as sys user in clonedb database. Start the clonedb instance without nomount.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;C:\&gt;set oracle_sid=clonedb&lt;br /&gt;&lt;br /&gt;C:\&gt;sqlplus sys/password as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 10.2.0.1.0 - Production on Thu May 28 15:22:37 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;Connected to an idle instance.&lt;br /&gt;&lt;br /&gt;SQL&gt; startup force nomount&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area 612368384 bytes&lt;br /&gt;Fixed Size 1250428 bytes&lt;br /&gt;Variable Size 188746628 bytes&lt;br /&gt;Database Buffers 415236096 bytes&lt;br /&gt;Redo Buffers 7135232 bytes&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Step 9. &lt;/strong&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Connect as RMAN and clone the database.&lt;/span&gt; If you use any reserve word(like CLONE, TEST etc) for cloning database name, then you should use in double quotes. This case, i am using database name as clonedb. But in case, if we use name CLONE, then it should be quoted like this... (&lt;span style="color:#ff0000;"&gt;RMAN&gt; duplicate target database to "CLONE";&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;C:\&gt;rman target=sys/password@orcl catalog=rman/rman@catdb AUXILIARY /&lt;br /&gt;&lt;br /&gt;RMAN&gt; duplicate target database to clonedb;&lt;br /&gt;&lt;br /&gt;Now the ORCL database is successfully cloned and cloned database name is CLONEDB. In case if we want to clone the database to specific point of time, then we can use the below command to clone.&lt;br /&gt;&lt;br /&gt;DUPLICATE TARGET DATABASE TO CLONEDB UNTIL TIME 'SYSDATE-4';&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Questions and Answers....&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Question1&lt;/span&gt;&lt;br /&gt;I wanted to change the file names while cloning the database. How do we do that? Let us say, the file names in the target database are...&lt;br /&gt;&lt;br /&gt;C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF&lt;br /&gt;C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF&lt;br /&gt;C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF&lt;br /&gt;C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF&lt;br /&gt;C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS02.DBF&lt;br /&gt;&lt;br /&gt;While cloning the database, i wanted to change the file name as below. How can i achieve this?&lt;br /&gt;&lt;br /&gt;C:\ORACLE\PRODUCT\10.2.0\ORADATA\CLONEDB\USERSCLONE01.DBF&lt;br /&gt;C:\ORACLE\PRODUCT\10.2.0\ORADATA\CLONEDB\SYSAUXCLONE01.DBF&lt;br /&gt;C:\ORACLE\PRODUCT\10.2.0\ORADATA\CLONEDB\UNDOTBSCLONE01.DBF&lt;br /&gt;C:\ORACLE\PRODUCT\10.2.0\ORADATA\CLONEDB\SYSTEMCLONE01.DBF&lt;br /&gt;C:\ORACLE\PRODUCT\10.2.0\ORADATA\CLONEDB\USERSCLONE02.DBF&lt;br /&gt;&lt;br /&gt;The directory structures are taken care by db_file_name_convert and log_file_name_covert parameters. The file name changes are not taken care by this parameters. Here is the below sample script to take care of this....&lt;br /&gt;&lt;br /&gt;RMAN&gt;run&lt;br /&gt;{&lt;br /&gt;SET NEWNAME FOR DATAFILE 1 TO 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\CLONEDB\SYSTEMCLONE01.DBF';&lt;br /&gt;SET NEWNAME FOR DATAFILE 4 TO 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\CLONEDB\USERSCLONE01.DBF';&lt;br /&gt;duplicate target database to clonedb;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Question2&lt;/span&gt;&lt;span style="color:#000000;"&gt; One of my programmer truncated the table accidently. I wanted to clone that database and recover that table. But the database size is 2TB. I do not want to clone the entire 2 TB data. Since i wanted to clone only the tablespace which blongs to my table. How do we exclude unwanted tablespaces? Please remember, we can not skip SYSTEM, SYSAUX, UNDO, TEMP and default permanent tablespace.&lt;/span&gt; The below script ingore the specific tablespaces.&lt;br /&gt;&lt;br /&gt;Run&lt;br /&gt;{&lt;br /&gt;DUPLICATE TARGET DATABASE TO clonedb&lt;br /&gt;&lt;a name="449118"&gt;&lt;/a&gt;SKIP TABLESPACE USERS, INVENTORY;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Question3&lt;/span&gt;&lt;span style="color:#000000;"&gt; How do i skip the read only tablespace while cloning the database?&lt;/span&gt; The below script skip the read only tablespaces.&lt;br /&gt;&lt;br /&gt;Run&lt;br /&gt;{&lt;br /&gt;DUPLICATE TARGET DATABASE TO clonedb&lt;br /&gt;SKIP READONLY ;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Question4 &lt;/span&gt;&lt;span style="color:#000000;"&gt;Let us say, my target database is running in Host1. My catalog database is running in Host2. I wanted to clone the target database in different server which is called Host3. Where should i run the RMAN? &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;RMAN is client program that connects to the database. So it does not matter where you run the RMAN. We could actually run in Host4 if we want to... We should be good as long as we connect right database. Where the RMAN client runs is irrelevant.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Note : As per oracle10gR2, during the cloning, if any tablespaces are OFFLINE in target database, will not be cloned into new database. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Temp tablespace never be backed up through RMAN. Hence, it will not be cloned. At the end, cloning process add temp files for temporary tablespace automatically. This is pretty much same for restoring the database from RMAN backup. RMAN creates the temporary tablespace when we restore the database.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-4331465865481117368?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/4331465865481117368/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=4331465865481117368' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/4331465865481117368'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/4331465865481117368'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/cloning-database-through-rman.html' title='Cloning Database through RMAN'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-3456011808184891172</id><published>2009-05-26T16:04:00.000-07:00</published><updated>2009-06-25T11:19:40.995-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='trail recovery'/><category scheme='http://www.blogger.com/atom/ns#' term='PERSISTENT CONFIGURATION'/><category scheme='http://www.blogger.com/atom/ns#' term='show all'/><category scheme='http://www.blogger.com/atom/ns#' term='block media recovery'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle9i RMAN feature'/><category scheme='http://www.blogger.com/atom/ns#' term='BMR'/><category scheme='http://www.blogger.com/atom/ns#' term='backup crosscheck'/><category scheme='http://www.blogger.com/atom/ns#' term='backup database plus archivelog'/><category scheme='http://www.blogger.com/atom/ns#' term='delete obsolete'/><category scheme='http://www.blogger.com/atom/ns#' term='CONFIGURE'/><title type='text'>New features in RMAN since Oracle9i</title><content type='html'>&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Oracle9i RMAN new features:&lt;/strong&gt;&lt;/span&gt; Oracle9i introduced several new enhancements. Let us discuss some of the new enhancements in oracle9i.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. Persistent Configuration:&lt;/span&gt;&lt;br /&gt;Introduced new CONFIGURE command enable us to configure various backup, restore and recover parameters that are persistent across RMAN sessions.&lt;br /&gt;&lt;br /&gt;CONFIGURE RETENTION POLICY TO REDUNDANCY 3;&lt;br /&gt;CONFGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;&lt;br /&gt;CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT 'D:\BK\bk%d_%s_%p'&lt;br /&gt;CONFIGURE DEFAULT DEVICE TYPE TO DISK;&lt;br /&gt;CONFIGURE DEFAULT DEVICE TYPE CLEAR;&lt;br /&gt;CONFIGURE EXCLUDE FOR TABLESPACE users;&lt;br /&gt;CONFIGURE EXCLUDE FOR TABLESPACE users CLEAR;&lt;br /&gt;CONFIGURE CONTROLFILE AUTOBACKUP ON;&lt;br /&gt;CONFIGURE BACKUP OPTIMIZATION ON;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2. Backup of Archivelogs:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;We can use new PLUS ARCHIVELOG clause to specify that archive logs that have not been backed up are included with the data backup.&lt;br /&gt;&lt;br /&gt;BACKUP DATAFILE 2 PLUS ARCHIVELOG;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3. Restartable Backups:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;Oracle9i has added another new clause to the BACKUP statement, NOT BACKED UP [SINCE TIME….]. This clause specifies that oracle should only back up files that have not been backed up since a particular date and time.&lt;br /&gt;&lt;br /&gt;BACKUP DATABASE NOT BACKED UP SINCE TIME ‘sysdate-7’;&lt;br /&gt;&lt;br /&gt;We can use this clause to restart the backup process when it fails after completing a part of the backup. This clause only backs up the files that were missed by the first backup that failed. This clause enables you to reduce the time required for the backup. Otherwise, you would have to perform a full backup again. If we omit the SINCE TIME option, files that have never been backed up become candidates for backup.&lt;br /&gt;&lt;br /&gt;Oracle9i also optimize the restoration of files from backup, files whose file header match the headers of the files in the backup sets are not restored. This keeps us from restoring files that have already been restored in the case of restore operation that fails midway.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;4. Block Media Recovery – BMR:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;Data blocks can be corrupted due to various reasons during normal database operations. Oracle writes information about the data block corruption into the alert log file and the user trace files. Prior to oracle9i, we had to restore and recover the entire data file by applying the redo required from the archived log files, even through just one single block was corrupted. It would be time consuming to restore and recover the entire data file just for one corrupted block.&lt;br /&gt;&lt;br /&gt;Oracle9i introduced BMR to enable us to restore and recover just those blocks that are corrupted. We can find the corrupted block from V$BACKUP_CORRUPTION and V$COPY_CORRUPTION views. We also do not have to bring the data file offline to recover the corrupted blocks. The DB availability is greatly enhanced with BMR feature.&lt;br /&gt;&lt;br /&gt;BLOCKRECOVER DATAFILE d1 BLOCK b1,[b2,b3,b4…]&lt;br /&gt;[DATAFILE d2 BLOCK b5,[b7,b8….]]…&lt;br /&gt;&lt;br /&gt;--recover corrupt blocks in three datafiles&lt;br /&gt;RMAN&gt; BLOCKRECOVER DATAFILE 2 BLOCK 12, 13 DATAFILE 3 BLOCK 5, 98, 99 DATAFILE 4 BLOCK 19;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;5. Trail Recovery:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Trail recovery tests the backup and identifies any problem in the backup before we really use this backup for any recovery. The difference between regular recovery and trail recovery is that,  in trial recovery, the data is not written to the data files and changes are only recorded in the buffers. Trail recovery writes any errors encountered into the alert log file.&lt;br /&gt;&lt;br /&gt;Once the trail recovery is completed, all the effects of trail recovery are nullified, and it writes all the errors in alert log. The database should be mounted stage while doing regular recovery as well as trail recovery. So users can not use the database during both trail and regular recovery.&lt;br /&gt;&lt;br /&gt;Oracle9i introduced new feature to allow number of block corruptions during the recovery. If the corrupt blocks are few, you can perform a recovery that ignores the corrupt block but recovers the rest.&lt;br /&gt;&lt;br /&gt;RECOVER DATABASE ALLOW 2 CORRUPTION;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Miscellaneous Enhancements:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. &lt;/span&gt;Oracle9i has ability to report obsolete backups that are not required to keep the database unrecoverable with in a particular window of time. Here is the example.&lt;br /&gt;&lt;br /&gt;REPORT OBSOLETE RECOVERY WINDOW OF 7 DAYS&lt;br /&gt;&lt;br /&gt;We can also use DELETE OBSOLETE command to delete those obsolete backups. &lt;span style="color:#000000;"&gt;Also we can display files that must be backed up for number of days recovery window.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;REPORT NEED BACKUP RECOVERY WINDOW OF 7 DAYS&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2. &lt;/span&gt;&lt;span style="color:#000000;"&gt;We can use CROSSCHECK command to check if backup sets or file copies exists.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3.&lt;/span&gt; List command has been enhanced. Now we can specify either BY BACKUP or BY FILE.&lt;br /&gt;LIST BACKUP;&lt;br /&gt;LIST BACKUP BY FILE;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;4. &lt;/span&gt;&lt;span style="color:#000000;"&gt;Introduced SHOW command to display all persistent parameters.&lt;br /&gt;SHOW ALL&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Oracle10g RMAN new features: &lt;/strong&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Oracle10g introduced several new enhancements. Let us discuss some of the new enhancements in oracle10g&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. Incrementally updated backups: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;RMAN &lt;span style="color:#ff0000;"&gt;incremental backup&lt;/span&gt; method back up only datafile blocks that have changed since a specified previous backup. You can make incremental backups of databases, individual tablespaces or datafiles. The goal of an incremental backup is to back up only those data blocks that have changed since a previous backup.&lt;/span&gt;&lt;span style="color:#000000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Each data block in a datafile contains a system change number (SCN), which is the SCN at which the most recent change was made to the block. During an incremental backup, RMAN reads the SCN of each data block in the input file and compares it to the checkpoint SCN of the parent incremental backup. If the SCN in the input data block is greater than the checkpoint SCN of the parent, then RMAN copies the block.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;Incremental backups can be either level 0 or level 1. &lt;a id="sthref389" name="sthref389"&gt;&lt;/a&gt;&lt;a id="sthref390" name="sthref390"&gt;&lt;/a&gt;A level 0 incremental backup, which is the base for subsequent incremental backups, copies all blocks containing data, backing the datafile up into a backup set just as a full backup would. The only difference between a level 0 incremental backup and a full backup is that a full backup is never included in an incremental strategy.&lt;br /&gt;&lt;br /&gt;RMAN&gt; backup incremental level 0 tablespace system;&lt;br /&gt;RMAN&gt; backup incremental level 1 database;&lt;br /&gt;&lt;br /&gt;A level 1 incremental backup can be either of the following types:&lt;br /&gt;&lt;br /&gt;1. A differential backup, which backs up all blocks changed after the most recent incremental backup at level 1 or 0&lt;br /&gt;&lt;br /&gt;2. A cumulative backup, which backs up all blocks changed after the most recent incremental backup at level 0&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2. Fast Incremental backup&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;During the incremental backup, oracle scans the whole data file and compare the SCN between the blocks in the data file and backup set files. It will be a time consuming tasks. Oracle introduced change tracking file to track the physical location of all database changes. During an incremental backup, RMAN uses the change tracking file to quickly identify only the blocks that have changed, avoiding the time consuming task of reading the entire data file to determine which blocks have changed. This is called &lt;span style="color:#ff0000;"&gt;Fast incremental backup&lt;/span&gt;. The new background process CTWR(Change tracking writer) is also required when using fast incremental backups.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database enable block change tracking using file&lt;br /&gt;2 'C:/changetracking/chg01.dbf';&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;The dynamic performance view V$BLOCK_CHANGE_TRACKING shows where block change tacking file is stored, whether it is enabled, and how large it is.&lt;br /&gt;&lt;br /&gt;Please click the below link to read more about incremental backup in oracle10g. &lt;a href="http://download.oracle.com/docs/cd/B19306_01/backup.102/b14192/bkup004.htm"&gt;Click&lt;/a&gt; here&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3. Dropping database through RMAN&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We can drop the database through RMAN, it has additional benefits of dropping all backup copies and archived log files for the database if you include the INCLUDING BACKUPS clause.&lt;br /&gt;&lt;br /&gt;RMAN&gt; drop database including backups;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;4. Automatic Channel Failover&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;If we are using multiple channels during an RMAN backup to either tape or disk and one of the channels fails, the backup job continues on the remaining channels. Any errors including channel errors are reported in the dynamic performance view V$RMAN_OUTPUT after the backup job is completed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;5. Duration, Throttling and Partial Backup Options&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;BACKUP......DURATION &lt;/span&gt;&lt;span style="color:#000000;"&gt;is a maximum duration or time frame for a backup operation, we can minimize the impact of the backup operation in a 24/7 environment. The new &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;DURATION &lt;/span&gt;&lt;span style="color:#000000;"&gt;option, which replace &lt;span style="color:#ff0000;"&gt;RATE&lt;/span&gt; and &lt;span style="color:#ff0000;"&gt;READRATE&lt;/span&gt; in previous version of RMAN.&lt;/span&gt;&lt;span style="color:#000000;"&gt; For example, to spread out the backup of the USERS tablespace over a maximum of two hours, use the following command.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;RMAN&gt; BACKUP DURATION 2:00 TABLESPACE users;&lt;br /&gt;&lt;br /&gt;By default, the backup will complete as fast as possible within the two-hour time frame.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;BACKUP.....DURATION.....PARTIAL &lt;/span&gt;&lt;span style="color:#000000;"&gt;adding PARTIAL to the BACKUP command prevents an error message from being issued by RMAN in case the backup does not finish the operation in the specified amount of time. Any complete backup sets are available for recovery operations, and any partial or incomplete backup operations will have to be restarted.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;RMAN&gt; backup duration 2:00 partial&lt;br /&gt;2&gt; tablespace users&lt;br /&gt;3&gt; filesperset 1;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;BACKUP.....DURATION.....MINIMIZE LOAD &lt;/span&gt;&lt;span style="color:#000000;"&gt;The MINIMIZE LOAD clause, used with disk backups only, automatically adjusts the throughput of the backup operation to complete the backup in the estimated completion time specified by DUATION.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;RMAN&gt; BACKUP DURATION 4:00 PARTIAL&lt;br /&gt;2&gt; MINIMIZE LOAD&lt;br /&gt;3&gt; DATABASE FILESPERSET 1;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;BACKUP....DURATION....MINIMIZE TIME&lt;/span&gt;&lt;span style="color:#000000;"&gt; The MINIMIZE TIME clause, will complete the backup in the shortest possible time.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;RMAN&gt; backup duration 2:00 minimize time&lt;br /&gt;2&gt; tablespace users;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;6. Creating Image copies&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Oracle10g introduced new feature to create image copy of the data files. It is equivalent to conventional copy of oracle data files. Image copy is a bit-for-bit duplicate of a database file, identical to a copy made with an operating system command. When we take conventional backup, we need to put the tablespace in BEGIN BACKUP mode. But when we create image copy, it is not required. Another thing, when we take conventional backup, it will not be registered in RMAN catalog database. But RMAN image copy backup will be registered in catalog database.&lt;br /&gt;&lt;br /&gt;What is the advantage of image copies? To answer this question, it would be useful for migrating the database to ASM. We can also use them to recover the database in non RMAN environment.&lt;br /&gt;&lt;br /&gt;We have BACKUP AS COPY command in RMAN, which can copy entire database, multiple tablespaces, datafiles, archived log files.&lt;br /&gt;&lt;br /&gt;RMAN&gt; backup as copy database;&lt;br /&gt;RMAN&gt; backup as copy tablespace system, sysaux;&lt;br /&gt;RMAN&gt; backup as copy datafile 1;&lt;br /&gt;&lt;br /&gt;RMAN automatically determines which datafiles belong to each tablespace and performs the image copy for each. In addition, the image copies generated by RMAN can be used directly in a recovery operation without using RMAN to extract a data file from previous backup set.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;7. Full databaes backup &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We may want to back up a previous backup to tape, rather than create a direct backup to tape, so as not to impact a database that is up and running. In RMAN, we can use the following command to backup a previous copy of the entire database to the default tape device.&lt;br /&gt;&lt;br /&gt;RMAN&gt; backup copy of database;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;8. Compressed backup&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This feature allows RMAN to perform binary compression of backupsets. The resulting backupsets do not need to be uncompressed during recovery. It is most useful in the following circumstances.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1.&lt;/span&gt; You are performing disk-based backup with limited disk space&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2.&lt;/span&gt; You are performing backups across a network where network bandwidth is limiting&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3.&lt;/span&gt; You are performing backups to tape, CD or DVD where hardware compression is not available&lt;br /&gt;&lt;br /&gt;RMAN&gt;BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG;&lt;br /&gt;RMAN&gt;BACKUP AS COMPRESSED BACKUPSET DATAFILE 1,5;&lt;br /&gt;&lt;br /&gt;Compression requires additional CPU cycles which may affect the performance of the database. For this reason it should not be used for tape backups where hardware compression is available.&lt;br /&gt;&lt;br /&gt;I have discussed some of the other topics which are related to this thread. Please go through below links in case if you are interested....&lt;br /&gt;&lt;br /&gt;How do we enable archivelog in oracle? &lt;a href="http://myorastuff.blogspot.com/2009/05/enable-archive-log-in-oracle10g.html"&gt;Click&lt;/a&gt; here&lt;br /&gt;&lt;br /&gt;How do we set up RMAN in oracle? &lt;a href="http://myorastuff.blogspot.com/2009/05/steps-to-setup-rman.html"&gt;Click&lt;/a&gt; here&lt;br /&gt;&lt;br /&gt;What is difference between traditional backup and RMAN backup? &lt;a href="http://myorastuff.blogspot.com/2009/05/benefits-of-rman-backup-vs-scripted.html"&gt;Click&lt;/a&gt; here&lt;br /&gt;&lt;br /&gt;Different type of recovery scenario in RMAN? &lt;a href="http://myorastuff.blogspot.com/2009/05/rman-recovery-scenarios.html"&gt;Click&lt;/a&gt; here&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-3456011808184891172?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/3456011808184891172/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=3456011808184891172' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/3456011808184891172'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/3456011808184891172'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/new-features-in-rman-since-oracle9i.html' title='New features in RMAN since Oracle9i'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-1956827711965083057</id><published>2009-05-25T11:09:00.001-07:00</published><updated>2009-06-24T11:01:04.132-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='read consistency'/><category scheme='http://www.blogger.com/atom/ns#' term='Transaction recovery'/><category scheme='http://www.blogger.com/atom/ns#' term='roll forward'/><category scheme='http://www.blogger.com/atom/ns#' term='shutdown abort'/><category scheme='http://www.blogger.com/atom/ns#' term='roll backward'/><category scheme='http://www.blogger.com/atom/ns#' term='SMON'/><category scheme='http://www.blogger.com/atom/ns#' term='what is instance recovery in oracle'/><category scheme='http://www.blogger.com/atom/ns#' term='instance recovery'/><category scheme='http://www.blogger.com/atom/ns#' term='startup force'/><category scheme='http://www.blogger.com/atom/ns#' term='Cache recovery'/><category scheme='http://www.blogger.com/atom/ns#' term='DBWR'/><category scheme='http://www.blogger.com/atom/ns#' term='uncomitted data'/><title type='text'>Instance Recovery</title><content type='html'>Oracle performs instance recovery when the database is restarted due to instance failure or shutdown the database with ABORT option(shutdown abort) or startup the database with FORCE option(startup force). Instance recovery is taken care by SMON oracle background process automatically. Instance recovery consists of two steps. One is Roll forward, next is Roll backward.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Roll forward:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;br /&gt;&lt;/span&gt;Changes being made to the database are recorded in the database buffer cache and buffer cache will be written into data files. At the same time, the changes are recorded in redo log buffer and redo log buffer will be written to redo log file. Oracle writes the data from database buffer cache to data file only when there is enough data in data buffer cache. It is not necessary that, every commit, oracle writes the data buffer cache into data file. When instance fails before committed data are written into data files, Oracle uses the data recorded in the online redo log files to recover the lost data when the associated database is re-started. This process is called Roll forward or cache recovery.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Roll backward:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;br /&gt;&lt;/span&gt;When we make any changes in the database, the old image will be written into undo segment. Later undo segment will be used to rollback the data when we rollback the transaction. DBWR writes the buffer cache content into data file under different circumstances. It might be possible to write the uncommitted data from database buffer cache into data file. When instance fails and associated database is restarted, it rollback the uncommitted transaction in data file by using undo segment to maintain the read consistency. This is called roll forward or transaction recovery.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-1956827711965083057?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/1956827711965083057/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=1956827711965083057' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1956827711965083057'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1956827711965083057'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/instance-recovery.html' title='Instance Recovery'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-2265556522259517839</id><published>2009-05-21T17:24:00.000-07:00</published><updated>2009-06-25T10:53:30.202-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='recover database'/><category scheme='http://www.blogger.com/atom/ns#' term='recover tablespace'/><category scheme='http://www.blogger.com/atom/ns#' term='RMAN'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-01110'/><category scheme='http://www.blogger.com/atom/ns#' term='recover datafile'/><category scheme='http://www.blogger.com/atom/ns#' term='alter database open resetlogs'/><category scheme='http://www.blogger.com/atom/ns#' term='restore database'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-01157'/><category scheme='http://www.blogger.com/atom/ns#' term='recovery scenarios'/><category scheme='http://www.blogger.com/atom/ns#' term='restore tablespace'/><title type='text'>RMAN Recovery Scenarios</title><content type='html'>Olden days, we use traditional backup(putting tablespace in hot backup mode) to backup the database. When we recover the database, we use traditional backup as a base and apply archive log files to recover the database. We have some issues when we dealt with traditional backup. Then oracle introduced RMAN backup to resolve some of the issues which we faced in traditional backup. Now you may ask, What are the issues in traditional backup and what are the convenience in RMAN backup? I discussed this in another thread.. Please see think &lt;a href="http://myorastuff.blogspot.com/2009/05/benefits-of-rman-backup-vs-scripted.html"&gt;link&lt;/a&gt; to get the answer.&lt;br /&gt;&lt;br /&gt;In this thread, i am going to discuss about possible recovery scenario in RMAN. Before that, we need to setup the RMAN in oracle instance.. How do we set up RMAN in oracle instance? Here is the &lt;a href="http://myorastuff.blogspot.com/2009/05/steps-to-setup-rman.html"&gt;link&lt;/a&gt; to see how to setup RMAN in oracle.&lt;br /&gt;&lt;br /&gt;Now we will discuss about different type of DB recovery scenarios.... The database name is ORCL. The catalog database name CATDB.... RMAN has setup and backup is running every day. The database is running in windows environment.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario1 &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Kevin is DBA, he is working in Mission critical workshop. On Friday night, while taking RMAN backup, the machine is crashed and database is down. Kevin restarted the database and database is mounted successfully. But it is not opened. He realized that, some of the tablespaces are corrupted. Fortunately, redo log files and control files are intact. Kevin wanted to bring the DB as fast as possible.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; startup&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area 612368384 bytes&lt;br /&gt;Fixed Size 1250428 bytes&lt;br /&gt;Variable Size 188746628 bytes&lt;br /&gt;Database Buffers 415236096 bytes&lt;br /&gt;Redo Buffers 7135232 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;ORA-01157: cannot identify/lock data file 1 - see DBWR trace file&lt;br /&gt;ORA-01110: data file 1: 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF'&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Here is the solution.... Since most of the tablespace datafiles are corrupted, he decided to do complete database recovery. First he mounted the database. He can not open the database until he completely recover the database. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Kevin connected the RMAN and recoverd the whole database as below.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;C:\&gt;rman catalog=rman/rman@catdb target=sys/password@orcl&lt;br /&gt;&lt;br /&gt;Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 21 21:32:28 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to target database: ORCL (DBID=1215124933, not open)&lt;br /&gt;connected to recovery catalog database&lt;br /&gt;&lt;br /&gt;RMAN&gt; run{&lt;br /&gt;2&gt; restore database;&lt;br /&gt;3&gt; recover database;&lt;br /&gt;4&gt; alter database open;&lt;br /&gt;5&gt; }&lt;br /&gt;&lt;br /&gt;Starting restore at 21-MAY-09&lt;br /&gt;starting full resync of recovery catalog&lt;br /&gt;full resync complete&lt;br /&gt;allocated channel: ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: sid=156 devtype=DISK&lt;br /&gt;&lt;br /&gt;creating datafile fno=5 name=C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS02.DBF&lt;br /&gt;channel ORA_DISK_1: starting datafile backupset restore&lt;br /&gt;channel ORA_DISK_1: specifying datafile(s) to restore from backup set&lt;br /&gt;restoring datafile 00001 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF&lt;br /&gt;restoring datafile 00002 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF&lt;br /&gt;restoring datafile 00003 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF&lt;br /&gt;restoring datafile 00004 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF&lt;br /&gt;channel ORA_DISK_1: reading from backup piece C:\RMANBACKUP\BACKUPORCL_DB_0CKFJAS2_1_1_%S_%P&lt;br /&gt;channel ORA_DISK_1: restored backup piece 1&lt;br /&gt;piece handle=C:\RMANBACKUP\BACKUPORCL_DB_0CKFJAS2_1_1_%S_%P tag=TAG20090521T143649&lt;br /&gt;channel ORA_DISK_1: restore complete, elapsed time: 00:00:55&lt;br /&gt;Finished restore at 21-MAY-09&lt;br /&gt;&lt;br /&gt;Starting recover at 21-MAY-09&lt;br /&gt;using channel ORA_DISK_1&lt;br /&gt;&lt;br /&gt;starting media recovery&lt;br /&gt;media recovery complete, elapsed time: 00:00:14&lt;br /&gt;&lt;br /&gt;Finished recover at 21-MAY-09&lt;br /&gt;&lt;br /&gt;database opened&lt;br /&gt;&lt;br /&gt;RMAN&gt;&lt;/p&gt;&lt;span style="color:#ff0000;"&gt;Scenario2 &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Adita is DBA in banking firm. On Monday afternoon, due to media failure, one of the data file is corrupted. But all other data files are working fine. Anita restarted the database and one data file is complaining and DB is not restarted. Anita made the corrupted data file offine and opened the database. So users can use the DB while recoving the one data file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; startup&lt;br /&gt;ORACLE instance started.&lt;br /&gt;Total System Global Area 612368384 bytes&lt;br /&gt;Fixed Size 1250428 bytes&lt;br /&gt;Variable Size 188746628 bytes&lt;br /&gt;Database Buffers 415236096 bytes&lt;br /&gt;Redo Buffers 7135232 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;ORA-01157: cannot identify/lock data file 5 - see DBWR trace file&lt;br /&gt;ORA-01110: data file 5: 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS02.DBF'&lt;br /&gt;SQL&gt; alter database datafile 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS02.DBF'&lt;br /&gt;offline;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database open;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; select file_id from dba_data_files where file_name&lt;br /&gt;2 ='C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS02.DBF';&lt;br /&gt;&lt;br /&gt;FILE_ID&lt;br /&gt;----------&lt;br /&gt;5&lt;br /&gt;&lt;br /&gt;SQL&gt; exit&lt;br /&gt;Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Here is the solution to recover the database..........&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;C:\&gt;rman catalog=rman/rman@catdb target=sys/password@orcl&lt;br /&gt;&lt;br /&gt;Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 21 22:30:06 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to target database: ORCL (DBID=1215124933)&lt;br /&gt;connected to recovery catalog database&lt;br /&gt;&lt;br /&gt;RMAN&gt; run&lt;br /&gt;2&gt; {&lt;br /&gt;3&gt; restore datafile 5;&lt;br /&gt;4&gt; recover datafile 5;&lt;br /&gt;5&gt; }&lt;br /&gt;&lt;br /&gt;Starting restore at 21-MAY-09&lt;br /&gt;starting full resync of recovery catalog&lt;br /&gt;full resync complete&lt;br /&gt;allocated channel: ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: sid=135 devtype=DISK&lt;br /&gt;creating datafile fno=5 name=C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS02.DBF&lt;br /&gt;restore not done; all files readonly, offline, or already restored&lt;br /&gt;Finished restore at 21-MAY-09&lt;br /&gt;&lt;br /&gt;Starting recover at 21-MAY-09&lt;br /&gt;using channel ORA_DISK_1&lt;br /&gt;&lt;br /&gt;starting media recovery&lt;br /&gt;media recovery complete, elapsed time: 00:00:01&lt;br /&gt;&lt;br /&gt;Finished recover at 21-MAY-09&lt;br /&gt;&lt;br /&gt;RMAN&gt; exit&lt;br /&gt;&lt;br /&gt;Recovery Manager complete.&lt;br /&gt;&lt;br /&gt;C:\&gt;sqlplus sys/password as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 10.2.0.1.0 - Production on Thu May 21 22:31:10 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database datafile 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS02.DBF'&lt;br /&gt;ONLINE;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; select distinct status from dba_data_files;&lt;br /&gt;&lt;br /&gt;STATUS&lt;br /&gt;---------&lt;br /&gt;AVAILABLE&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario3 &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scott is a DBA in trading firm. During the hard disk replacement in unix box, one of the application tablespace data files are corrupted. When Scott restart the database, it complained that, data file is corrupted and tablespace is not usable. But fortunately, other tablespaces datafiles are intact. Scott decided to make this tablespace offline and open the database. So that others can use the database while recovering the tablespace.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; startup&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area 612368384 bytes&lt;br /&gt;Fixed Size 1250428 bytes&lt;br /&gt;Variable Size 188746628 bytes&lt;br /&gt;Database Buffers 415236096 bytes&lt;br /&gt;Redo Buffers 7135232 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;ORA-01157: cannot identify/lock data file 4 - see DBWR trace file&lt;br /&gt;ORA-01110: data file 4: 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF'&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database datafile 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF'&lt;br /&gt;OFFLINE;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database open;&lt;br /&gt;alter database open&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-01157: cannot identify/lock data file 5 - see DBWR trace file&lt;br /&gt;ORA-01110: data file 5: 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS02.DBF'&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database datafile 'C:\ORACLE\PRODUCT\10.2.\ORADATA\ORCL\USERS02.DBF'&lt;br /&gt;OFFLINE;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database open;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; exit&lt;br /&gt;Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Pr&lt;br /&gt;oduction&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scott made data files offline and opened the database. While others are using the database, he connected in RMAN and recovered only corrupted tablespace&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;C:\&gt;rman catalog=rman/rman@catdb target=sys/password@orcl&lt;br /&gt;&lt;br /&gt;Recovery Manager: Release 10.2.0.1.0 - Production on Fri May 22 09:36:52 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to target database: ORCL (DBID=1215124933)&lt;br /&gt;connected to recovery catalog database&lt;br /&gt;&lt;br /&gt;RMAN&gt; run{&lt;br /&gt;2&gt; restore tablespace users;&lt;br /&gt;3&gt; recover tablespace users;&lt;br /&gt;4&gt; }&lt;br /&gt;&lt;br /&gt;Starting restore at 22-MAY-09&lt;br /&gt;allocated channel: ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: sid=128 devtype=DISK&lt;br /&gt;creating datafile fno=5 name=C:\ORACLE\PRODUCT\10.2.\ORADATA\ORCL\USERS02.DBF&lt;br /&gt;channel ORA_DISK_1: starting datafile backupset restore&lt;br /&gt;channel ORA_DISK_1: specifying datafile(s) to restore from backup set&lt;br /&gt;restoring datafile 00004 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF&lt;br /&gt;channel ORA_DISK_1: reading from backup piece C:\RMANBACKUP\BACKUPORCL_DB_0CKFJA S2_1_1_%S_%P&lt;br /&gt;channel ORA_DISK_1: restored backup piece 1&lt;br /&gt;piece handle=C:\RMANBACKUP\BACKUPORCL_DB_0CKFJAS2_1_1_%S_%P tag=TAG20090521T143649&lt;br /&gt;channel ORA_DISK_1: restore complete, elapsed time: 00:00:16&lt;br /&gt;Finished restore at 22-MAY-09&lt;br /&gt;Starting recover at 22-MAY-09&lt;br /&gt;using channel ORA_DISK_1&lt;br /&gt;&lt;br /&gt;starting media recovery&lt;br /&gt;&lt;br /&gt;archive log thread 1 sequence 12 is already on disk as file C:\ORACLE\PRODUCT\10&lt;br /&gt;.2.0\DB_1\DATABASE\ARCHIVE\LOG_12_1_687344200.ARC&lt;br /&gt;archive log thread 1 sequence 17 is already on disk as file C:\ORACLE\PRODUCT\10&lt;br /&gt;.2.0\DB_1\DATABASE\ARCHIVE\LOG_17_1_687344200.ARC&lt;br /&gt;archive log thread 1 sequence 18 is already on disk as file C:\ORACLE\PRODUCT\10&lt;br /&gt;.2.0\DB_1\DATABASE\ARCHIVE\LOG_18_1_687344200.ARC&lt;br /&gt;archive log thread 1 sequence 19 is already on disk as file C:\ORACLE\PRODUCT\10&lt;br /&gt;.2.0\DB_1\DATABASE\ARCHIVE\LOG_19_1_687344200.ARC&lt;br /&gt;media recovery complete, elapsed time: 00:01:23&lt;br /&gt;Finished recover at 22-MAY-09&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;span style="color:#000000;"&gt;SQL&gt; connect sys/password as sysdba&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; alter database datafile 'c:\oracle\product\10.2.0\oradata\orcl\users01.dbf'&lt;br /&gt;2 online;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database datafile 'c:\oracle\product\10.2.0\oradata\orcl\users02.dbf'&lt;br /&gt;2 online;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; connect scott/tiger@orcl&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; select count(*) from emp;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;14&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario4 &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Jane is a DBA in telecommunication company. Unix admin had done some maintenance work on the server. Once they completed their work, Jane restarted the database. When Jane restart the DB, Jane realized that, SYSTEM tablespace is corrupted.. But others are intact. He decided to mount the database and recover this tablespace. This leads downtime for the database, since jane can not open the database without recovering the system tablespace.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;SQL&gt; startup&lt;br /&gt;ORACLE instance started.&lt;br /&gt;Total System Global Area 612368384 bytes&lt;br /&gt;Fixed Size 1250428 bytes&lt;br /&gt;Variable Size 188746628 bytes&lt;br /&gt;Database Buffers 415236096 bytes&lt;br /&gt;Redo Buffers 7135232 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;ORA-01157: cannot identify/lock data file 1 - see DBWR trace file&lt;br /&gt;ORA-01110: data file 1: 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF'&lt;br /&gt;SQL&gt; alter database datafile 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF&lt;br /&gt;' OFFLINE;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; ALTER DATABASE OPEN;&lt;br /&gt;ALTER DATABASE OPEN&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-01147: SYSTEM tablespace file 1 is offline&lt;br /&gt;ORA-01110: data file 1: 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF'&lt;br /&gt;SQL&gt; exit&lt;br /&gt;Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Pr&lt;br /&gt;oduction&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;C:\&gt;rman catalog=rman/rman@catdb target=sys/password@orcl&lt;br /&gt;&lt;br /&gt;Recovery Manager: Release 10.2.0.1.0 - Production on Fri May 22 10:21:04 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to target database: ORCL (DBID=1215124933, not open)&lt;br /&gt;connected to recovery catalog database&lt;br /&gt;&lt;br /&gt;RMAN&gt; run&lt;br /&gt;2&gt; {&lt;br /&gt;3&gt; restore tablespace system;&lt;br /&gt;4&gt; recover tablespace system;&lt;br /&gt;5&gt; }&lt;br /&gt;&lt;br /&gt;Starting restore at 22-MAY-09&lt;br /&gt;allocated channel: ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: sid=156 devtype=DISK&lt;br /&gt;&lt;br /&gt;channel ORA_DISK_1: starting datafile backupset restore&lt;br /&gt;channel ORA_DISK_1: specifying datafile(s) to restore from backup set&lt;br /&gt;restoring datafile 00001 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF&lt;br /&gt;channel ORA_DISK_1: reading from backup piece C:\RMANBACKUP\BACKUPORCL_DB_0JKFLE&lt;br /&gt;9Q_1_1_%S_%P&lt;br /&gt;channel ORA_DISK_1: restored backup piece 1&lt;br /&gt;piece handle=C:\RMANBACKUP\BACKUPORCL_DB_0JKFLE9Q_1_1_%S_%P tag=TAG20090522T094738&lt;br /&gt;channel ORA_DISK_1: restore complete, elapsed time: 00:00:35&lt;br /&gt;Finished restore at 22-MAY-09&lt;br /&gt;Starting recover at 22-MAY-09&lt;br /&gt;using channel ORA_DISK_1&lt;br /&gt;starting media recovery&lt;br /&gt;media recovery complete, elapsed time: 00:00:04&lt;br /&gt;Finished recover at 22-MAY-09&lt;br /&gt;RMAN&gt; exit&lt;br /&gt;&lt;br /&gt;Recovery Manager complete.&lt;br /&gt;&lt;br /&gt;C:\&gt;sqlplus sys/password as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 22 10:22:20 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database open;&lt;br /&gt;alter database open&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-01147: SYSTEM tablespace file 1 is offline&lt;br /&gt;ORA-01110: data file 1: 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF'&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database datafile 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF' online;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; ALTER DATABASE OPEN;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;SQL&gt; select distinct status from dba_tablespaces;&lt;br /&gt;&lt;br /&gt;STATUS&lt;br /&gt;---------&lt;br /&gt;ONLINE&lt;br /&gt;&lt;br /&gt;SQL&gt; select distinct status from dba_data_files;&lt;br /&gt;&lt;br /&gt;STATUS&lt;br /&gt;---------&lt;br /&gt;AVAILABLE&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario5 &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;David is DBA for Energy company. David ended up restarting the database due to hardware maintenance. When David restarts the database, realized that all the redo log files are corrupted... RMAN backup runs every day at 11.30PM. David found this issue on 12.20PM. Now David needs to do incomplete recovery. Here is the steps David taken... Mount the database and run the RMAN backup. Just to make sure all the archived redo log files are backed up before start the recovery. Once RMAN backup is completed, David run the incomplete recovery and recovered until the last archived redo log. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;SQL&gt; startup&lt;br /&gt;ORACLE instance started.&lt;br /&gt;Total System Global Area 612368384 bytes&lt;br /&gt;Fixed Size 1250428 bytes&lt;br /&gt;Variable Size 188746628 bytes&lt;br /&gt;Database Buffers 415236096 bytes&lt;br /&gt;Redo Buffers 7135232 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;ORA-00313: open failed for members of log group 1 of thread 1&lt;br /&gt;ORA-00312: online log 1 thread 1:&lt;br /&gt;'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO01.LOG'&lt;br /&gt;SQL&gt;exit&lt;br /&gt;C:\&gt;rman catalog=rman/rman@catdb target=sys/password@orcl&lt;br /&gt;Recovery Manager: Release 10.2.0.1.0 - Production on Sat May 23 20:36:24 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to target database: ORCL (DBID=1215124933, not open)&lt;br /&gt;connected to recovery catalog database&lt;br /&gt;&lt;br /&gt;RMAN&gt; backup archivelog all;&lt;br /&gt;&lt;br /&gt;Starting backup at 23-MAY-09&lt;br /&gt;allocated channel: ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: sid=152 devtype=DISK&lt;br /&gt;channel ORA_DISK_1: starting archive log backupset&lt;br /&gt;channel ORA_DISK_1: specifying archive log(s) in backup set&lt;br /&gt;input archive log thread=1 sequence=2 recid=31 stamp=687541158&lt;br /&gt;input archive log thread=1 sequence=3 recid=32 stamp=687542042&lt;br /&gt;input archive log thread=1 sequence=4 recid=33 stamp=687542062&lt;br /&gt;40 comment=NONE&lt;br /&gt;Starting Control File and SPFILE Autobackup at 23-MAY-09&lt;br /&gt;piece handle=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\C-1215124933-20090523-0A comment=NONE&lt;br /&gt;Finished Control File and SPFILE Autobackup at 23-MAY-09&lt;br /&gt;RMAN&gt; list backup of archivelog from time='sysdate-7';&lt;br /&gt;List of Backup Sets&lt;br /&gt;===================&lt;br /&gt;&lt;br /&gt;BS Key Size Device Type Elapsed Time Completion Time&lt;br /&gt;------- ---------- ----------- ------------ ---------------&lt;br /&gt;10609 8.10M DISK 00:00:02 23-MAY-09&lt;br /&gt;BP Key: 10611 Status: AVAILABLE Compressed: NO Tag: TAG20090523T2235&lt;br /&gt;40&lt;br /&gt;Piece Name: C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\01KFPFLS_1_1&lt;br /&gt;&lt;br /&gt;List of Archived Logs in backup set 10609&lt;br /&gt;Thrd Seq Low SCN Low Time Next SCN Next Time&lt;br /&gt;---- ------- ---------- --------- ---------- ---------&lt;br /&gt;1 2 544522 23-MAY-09 550869 23-MAY-09&lt;br /&gt;1 3 550869 23-MAY-09 550898 23-MAY-09&lt;br /&gt;&lt;br /&gt;BS Key Size Device Type Elapsed Time Completion Time&lt;br /&gt;------- ---------- ----------- ------------ ---------------&lt;br /&gt;10625 103.00K DISK 00:00:02 23-MAY-09&lt;br /&gt;BP Key: 10630 Status: AVAILABLE Compressed: NO Tag: TAG20090523T2236&lt;br /&gt;29&lt;br /&gt;Piece Name: C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\03KFPFND_1_1&lt;br /&gt;&lt;br /&gt;List of Archived Logs in backup set 10625&lt;br /&gt;Thrd Seq Low SCN Low Time Next SCN Next Time&lt;br /&gt;---- ------- ---------- --------- ---------- ---------&lt;br /&gt;1 4 550898 23-MAY-09 550988 23-MAY-09&lt;br /&gt;&lt;br /&gt;BS Key Size Device Type Elapsed Time Completion Time&lt;br /&gt;------- ---------- ----------- ------------ ---------------&lt;br /&gt;10672 8.29M DISK 00:00:02 23-MAY-09&lt;br /&gt;BP Key: 10676 Status: AVAILABLE Compressed: NO Tag: TAG20090523T2239&lt;br /&gt;52&lt;br /&gt;Piece Name: C:\RMANBACKUP\BACKUPORCL_DB_05KFPFTO_5_1&lt;br /&gt;&lt;br /&gt;List of Archived Logs in backup set 10672&lt;br /&gt;Thrd Seq Low SCN Low Time Next SCN Next Time&lt;br /&gt;---- ------- ---------- --------- ---------- ---------&lt;br /&gt;1 2 544522 23-MAY-09 550869 23-MAY-09&lt;br /&gt;1 3 550869 23-MAY-09 550898 23-MAY-09&lt;br /&gt;1 4 550898 23-MAY-09 550988 23-MAY-09&lt;br /&gt;1 5 550988 23-MAY-09 551206 23-MAY-09&lt;br /&gt;&lt;br /&gt;BS Key Size Device Type Elapsed Time Completion Time&lt;br /&gt;------- ---------- ----------- ------------ ---------------&lt;br /&gt;10692 37.00K DISK 00:00:01 23-MAY-09&lt;br /&gt;BP Key: 10697 Status: AVAILABLE Compressed: NO Tag: TAG20090523T2240&lt;br /&gt;42&lt;br /&gt;Piece Name: C:\RMANBACKUP\BACKUPORCL_DB_07KFPFVA_7_1&lt;br /&gt;&lt;br /&gt;List of Archived Logs in backup set 10692&lt;br /&gt;Thrd Seq Low SCN Low Time Next SCN Next Time&lt;br /&gt;---- ------- ---------- --------- ---------- ---------&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;1 6&lt;/strong&gt;&lt;/span&gt; 551206 23-MAY-09 551263 23-MAY-09&lt;br /&gt;&lt;br /&gt;RMAN&gt; restore database until sequence=6 thread=1 force;&lt;br /&gt;&lt;br /&gt;Starting restore at 23-MAY-09&lt;br /&gt;allocated channel: ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: sid=156 devtype=DISK&lt;br /&gt;&lt;br /&gt;channel ORA_DISK_1: starting datafile backupset restore&lt;br /&gt;channel ORA_DISK_1: specifying datafile(s) to restore from backup set&lt;br /&gt;restoring datafile 00001 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF&lt;br /&gt;restoring datafile 00002 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF&lt;br /&gt;restoring datafile 00003 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF&lt;br /&gt;restoring datafile 00004 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF&lt;br /&gt;channel ORA_DISK_1: reading from backup piece C:\ORACLE\PRODUCT\10.2.0\DB_1\DATA&lt;br /&gt;BASE\02KFPFLV_1_1&lt;br /&gt;channel ORA_DISK_1: restored backup piece 1&lt;br /&gt;piece handle=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\02KFPFLV_1_1 tag=TAG20090523&lt;br /&gt;T223542&lt;br /&gt;channel ORA_DISK_1: restore complete, elapsed time: 00:00:45&lt;br /&gt;Finished restore at 23-MAY-09&lt;br /&gt;&lt;br /&gt;RMAN&gt; recover database until sequence=6 thread=1 ;&lt;br /&gt;&lt;br /&gt;Starting recover at 23-MAY-09&lt;br /&gt;using channel ORA_DISK_1&lt;br /&gt;&lt;br /&gt;starting media recovery&lt;br /&gt;&lt;br /&gt;archive log thread 1 sequence 4 is already on disk as file C:\ORACLE\PRODUCT\10.&lt;br /&gt;2.0\DB_1\DATABASE\ARCHIVE\LOG_4_1_687649381.ARC&lt;br /&gt;archive log thread 1 sequence 5 is already on disk as file C:\ORACLE\PRODUCT\10.&lt;br /&gt;2.0\DB_1\DATABASE\ARCHIVE\LOG_5_1_687649381.ARC&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_4_1_6876&lt;br /&gt;49381.ARC thread=1 sequence=4&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_5_1_6876&lt;br /&gt;49381.ARC thread=1 sequence=5&lt;br /&gt;media recovery complete, elapsed time: 00:00:03&lt;br /&gt;Finished recover at 23-MAY-09&lt;br /&gt;&lt;br /&gt;RMAN&gt; alter database open resetlogs;&lt;br /&gt;&lt;br /&gt;database opened&lt;br /&gt;new incarnation of database registered in recovery catalog&lt;br /&gt;RMAN&gt;&lt;br /&gt;&lt;br /&gt;The database is recovered successfully. But this is incomplete recovery. Prior to oracle10g, oracle strongly recommend to take the full database backup whenever there is incomplete recovery. But in oracle10g, it is optional. But still it is good to take the full database backup for safer side. Please read this &lt;a href="http://download.oracle.com/docs/cd/B19306_01/backup.102/b14191/osrecov.htm#BRADV218"&gt;link&lt;/a&gt; to know more about this...&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario6 &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Kathy is DBA for one of the finance company. On Monday, due to hardware issue, the server was crashed. Unfortunately, Kathy lost all data files, control files, redo log files. But luckily the current archived redo log files were intact. Here is the steps Kathy has taken to handle this crash recovery.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Kathy was not able to mount the database since she lost her control file. So she first recovered the control file from RMAN backup. Once control file is recovered, she mounted the database. After the database is mounted, she ran the RMAN backup to make sure, all the current archive log files are backed up. she recovered the data base until last archived log file. Finally she opened the the DB RESETLOGS option.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;SQL&gt; startup&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area 612368384 bytes&lt;br /&gt;Fixed Size 1250428 bytes&lt;br /&gt;Variable Size 188746628 bytes&lt;br /&gt;Database Buffers 415236096 bytes&lt;br /&gt;Redo Buffers 7135232 bytes&lt;br /&gt;ORA-00205: error in identifying control file, check alert log for more info&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;C:\&gt;set oracle_sid=orcl&lt;br /&gt;&lt;br /&gt;C:\&gt;rman catalog=rman/rman@catdb target=sys/password&lt;br /&gt;&lt;br /&gt;Recovery Manager: Release 10.2.0.1.0 - Production on Sun May 24 15:26:51 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to target database: orcl (not mounted)&lt;br /&gt;connected to recovery catalog database&lt;br /&gt;&lt;br /&gt;RMAN&gt; restore controlfile;&lt;br /&gt;&lt;br /&gt;Starting restore at 24-MAY-09&lt;br /&gt;allocated channel: ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: sid=157 devtype=DISK&lt;br /&gt;&lt;br /&gt;channel ORA_DISK_1: starting datafile backupset restore&lt;br /&gt;channel ORA_DISK_1: restoring control file&lt;br /&gt;channel ORA_DISK_1: reading from backup piece C:\ORACLE\PRODUCT\10.2.0\DB_1\DATA&lt;br /&gt;BASE\C-1215492928-20090524-00&lt;br /&gt;channel ORA_DISK_1: restored backup piece 1&lt;br /&gt;piece handle=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\C-1215492928-20090524-00 tag&lt;br /&gt;=TAG20090524T152409&lt;br /&gt;channel ORA_DISK_1: restore complete, elapsed time: 00:00:04&lt;br /&gt;output filename=C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\CONTROL01.CTL&lt;br /&gt;output filename=C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\CONTROL02.CTL&lt;br /&gt;output filename=C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\CONTROL03.CTL&lt;br /&gt;Finished restore at 24-MAY-09&lt;br /&gt;&lt;br /&gt;RMAN&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Once the control file is recovered, the database is mounted.....&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database mount;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; select archivelog_change#-1 from v$database;&lt;br /&gt;&lt;br /&gt;ARCHIVELOG_CHANGE#-1&lt;br /&gt;--------------------&lt;br /&gt;547010&lt;br /&gt;&lt;br /&gt;SQL&gt; exit&lt;br /&gt;Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Pr&lt;br /&gt;oduction&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;C:\&gt;rman catalog=rman/rman@catdb target=sys/password@orcl&lt;br /&gt;&lt;br /&gt;Recovery Manager: Release 10.2.0.1.0 - Production on Sun May 24 15:29:33 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to target database: ORCL (DBID=1215492928, not open)&lt;br /&gt;connected to recovery catalog database&lt;br /&gt;&lt;br /&gt;RMAN&gt; run{&lt;br /&gt;2&gt; set until scn 547010;&lt;br /&gt;3&gt; restore database;&lt;br /&gt;4&gt; recover database;&lt;br /&gt;5&gt; alter database open resetlogs;&lt;br /&gt;6&gt; }&lt;br /&gt;&lt;br /&gt;executing command: SET until clause&lt;br /&gt;&lt;br /&gt;Starting restore at 24-MAY-09&lt;br /&gt;allocated channel: ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: sid=156 devtype=DISK&lt;br /&gt;&lt;br /&gt;channel ORA_DISK_1: starting datafile backupset restore&lt;br /&gt;channel ORA_DISK_1: specifying datafile(s) to restore from backup set&lt;br /&gt;restoring datafile 00001 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF&lt;br /&gt;restoring datafile 00002 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF&lt;br /&gt;restoring datafile 00003 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF&lt;br /&gt;restoring datafile 00004 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF&lt;br /&gt;channel ORA_DISK_1: reading from backup piece C:\RMANBACKUP\BACKUPORCL_DB_02KFRA&lt;br /&gt;N7_1_1_%S_%P&lt;br /&gt;channel ORA_DISK_1: restored backup piece 1&lt;br /&gt;piece handle=C:\RMANBACKUP\BACKUPORCL_DB_02KFRAN7_1_1_%S_%P tag=TAG20090524T1523&lt;br /&gt;19&lt;br /&gt;channel ORA_DISK_1: restore complete, elapsed time: 00:00:45&lt;br /&gt;Finished restore at 24-MAY-09&lt;br /&gt;&lt;br /&gt;Starting recover at 24-MAY-09&lt;br /&gt;using channel ORA_DISK_1&lt;br /&gt;&lt;br /&gt;starting media recovery&lt;br /&gt;&lt;br /&gt;archive log thread 1 sequence 3 is already on disk as file C:\ORACLE\PRODUCT\10.&lt;br /&gt;2.0\DB_1\DATABASE\ARCHIVE\LOG_3_1_687712197.ARC&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_3_1_6877&lt;br /&gt;12197.ARC thread=1 sequence=3&lt;br /&gt;media recovery complete, elapsed time: 00:00:04&lt;br /&gt;Finished recover at 24-MAY-09&lt;br /&gt;&lt;br /&gt;database opened&lt;br /&gt;new incarnation of database registered in recovery catalog&lt;br /&gt;starting full resync of recovery catalog&lt;br /&gt;full resync complete&lt;br /&gt;&lt;br /&gt;RMAN&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario7 &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scott is the DBA for database. One of the DB progammer truncated the critical table around 3.45PM and he called Scott and explained the situation. Scott has to recover the truncated table. Here is the steps Scott followed....&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; select count(*) from employee;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;14&lt;br /&gt;&lt;br /&gt;SQL&gt; select to_char(sysdate,'DD-MM-YYYY:HH24:MI:SS')&lt;br /&gt;2 from dual&lt;br /&gt;3 /&lt;br /&gt;&lt;br /&gt;TO_CHAR(SYSDATE,'DD&lt;br /&gt;-------------------&lt;br /&gt;24-05-2009:15:45:42&lt;br /&gt;&lt;br /&gt;SQL&gt; truncate table employee;&lt;br /&gt;&lt;br /&gt;Table truncated.&lt;br /&gt;&lt;br /&gt;SQL&gt; select count(*) from employee;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;0&lt;br /&gt;&lt;br /&gt;SQL&gt; shutdown immediate&lt;br /&gt;Database closed.&lt;br /&gt;Database dismounted.&lt;br /&gt;ORACLE instance shut down.&lt;br /&gt;SQL&gt; startup mount&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area 612368384 bytes&lt;br /&gt;Fixed Size 1250428 bytes&lt;br /&gt;Variable Size 188746628 bytes&lt;br /&gt;Database Buffers 415236096 bytes&lt;br /&gt;Redo Buffers 7135232 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;C:\&gt;rman catalog=rman/rman@catdb target=sys/password@orcl&lt;br /&gt;&lt;br /&gt;Recovery Manager: Release 10.2.0.1.0 - Production on Sun May 24 15:58:56 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to target database: ORCL (DBID=1215492928, not open)&lt;br /&gt;connected to recovery catalog database&lt;br /&gt;&lt;br /&gt;RMAN&gt; run&lt;br /&gt;2&gt; {&lt;br /&gt;3&gt; set until time "to_date('24-05-2009:15:45:42','DD-MM-YYYY HH24:MI:SS')";&lt;br /&gt;4&gt; restore database;&lt;br /&gt;5&gt; recover database;&lt;br /&gt;6&gt; }&lt;br /&gt;&lt;br /&gt;executing command: SET until clause&lt;br /&gt;&lt;br /&gt;Starting restore at 24-MAY-09&lt;br /&gt;allocated channel: ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: sid=156 devtype=DISK&lt;br /&gt;&lt;br /&gt;channel ORA_DISK_1: starting datafile backupset restore&lt;br /&gt;channel ORA_DISK_1: specifying datafile(s) to restore from backup set&lt;br /&gt;restoring datafile 00001 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF&lt;br /&gt;restoring datafile 00002 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF&lt;br /&gt;restoring datafile 00003 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF&lt;br /&gt;restoring datafile 00004 to C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF&lt;br /&gt;channel ORA_DISK_1: reading from backup piece C:\RMANBACKUP\BACKUPORCL_DB_09KFRB&lt;br /&gt;BR_1_1_%S_%P&lt;br /&gt;channel ORA_DISK_1: restored backup piece 1&lt;br /&gt;piece handle=C:\RMANBACKUP\BACKUPORCL_DB_09KFRBBR_1_1_%S_%P tag=TAG20090524T1534&lt;br /&gt;19&lt;br /&gt;channel ORA_DISK_1: restore complete, elapsed time: 00:00:45&lt;br /&gt;Finished restore at 24-MAY-09&lt;br /&gt;&lt;br /&gt;Starting recover at 24-MAY-09&lt;br /&gt;using channel ORA_DISK_1&lt;br /&gt;&lt;br /&gt;starting media recovery&lt;br /&gt;&lt;br /&gt;archive log thread 1 sequence 2 is already on disk as file C:\ORACLE\PRODUCT\10.&lt;br /&gt;2.0\DB_1\DATABASE\ARCHIVE\LOG_2_1_687713476.ARC&lt;br /&gt;archive log thread 1 sequence 3 is already on disk as file C:\ORACLE\PRODUCT\10.&lt;br /&gt;2.0\DB_1\DATABASE\ARCHIVE\LOG_3_1_687713476.ARC&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_2_1_6877&lt;br /&gt;13476.ARC thread=1 sequence=2&lt;br /&gt;media recovery complete, elapsed time: 00:00:05&lt;br /&gt;Finished recover at 24-MAY-09&lt;br /&gt;&lt;br /&gt;RMAN&gt; exit&lt;br /&gt;&lt;br /&gt;Recovery Manager complete.&lt;br /&gt;&lt;br /&gt;C:\&gt;sqlplus sys/password as sysdba&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 10.2.0.1.0 - Production on Sun May 24 16:01:31 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database open resetlogs;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; connect scott/tiger@orcl&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; select count(*) from employee;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;14&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;I have discussed some of the other topics which are related to this thread. Please go through below links in case if you are interested....&lt;br /&gt;&lt;br /&gt;How do we enable archivelog in oracle? &lt;a href="http://myorastuff.blogspot.com/2009/05/enable-archive-log-in-oracle10g.html"&gt;Click&lt;/a&gt; here&lt;br /&gt;&lt;br /&gt;What are the new features in RMAN since Oracle9i? &lt;a href="http://myorastuff.blogspot.com/2009/05/new-features-in-rman-since-oracle9i.html"&gt;Click&lt;/a&gt; here&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-2265556522259517839?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/2265556522259517839/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=2265556522259517839' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2265556522259517839'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2265556522259517839'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/rman-recovery-scenarios.html' title='RMAN Recovery Scenarios'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-4021152490047749731</id><published>2009-05-20T17:11:00.001-07:00</published><updated>2009-06-20T08:39:59.206-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='create catalog tablespace'/><category scheme='http://www.blogger.com/atom/ns#' term='register database'/><category scheme='http://www.blogger.com/atom/ns#' term='configure default device'/><category scheme='http://www.blogger.com/atom/ns#' term='steps to setup RMAN'/><category scheme='http://www.blogger.com/atom/ns#' term='backup database plus archivelog'/><category scheme='http://www.blogger.com/atom/ns#' term='delete obsolete'/><category scheme='http://www.blogger.com/atom/ns#' term='configure retention policy'/><category scheme='http://www.blogger.com/atom/ns#' term='configure controlfile'/><title type='text'>Steps to Setup RMAN</title><content type='html'>This article is tested in oracle10gR2. How do we setup the RMAN in oracle? There are couple of ways, we can setup the RMAN. We can use control file to store backup catalog info or we can have seperate database to store catalog info. Here i am using seperate database to store backup catalog information.&lt;br /&gt;&lt;br /&gt;You might ask a question yourself, why would we need RMAN backup? Why do we need to setup RMAN, since my traditional backups are already running fine.... I already discussed this in another thread.. Please see this link to answer your question. &lt;a href="http://myorastuff.blogspot.com/2009/05/benefits-of-rman-backup-vs-scripted.html"&gt;Click&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I am using windows OS. Please remember, the directories and folder might change based on the operating system and environment. But the below steps are pretty much same for any environmnet.&lt;br /&gt;&lt;br /&gt;Here i am using ORCL as primary database and CATDB as catalog database.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step1 &lt;/span&gt;&lt;span style="color:#000000;"&gt;Enable the archive log in ORCL database. I already discussed this in another thread. Please refer this &lt;a href="http://myorastuff.blogspot.com/2009/05/enable-archive-log-in-oracle10g.html"&gt;link&lt;/a&gt; to enable the database to archive log mode.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step2 &lt;/span&gt;&lt;span style="color:#000000;"&gt;Create the tablespace and user in catalog database to hold backup information.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; CONNECT sys/password@catdb AS SYSDBA&lt;br /&gt;Connected.&lt;br /&gt;&lt;br /&gt;SQL&gt; CREATE TABLESPACE RMAN&lt;br /&gt;2 DATAFILE 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\CATDB\RMAN01.DBF' SIZE 6208K REUSE&lt;br /&gt;3 AUTOEXTEND ON NEXT 64K MAXSIZE 32767M&lt;br /&gt;4 EXTENT MANAGEMENT LOCAL&lt;br /&gt;5 SEGMENT SPACE MANAGEMENT AUTO;&lt;br /&gt;&lt;br /&gt;Tablespace created.&lt;br /&gt;&lt;br /&gt;SQL&gt; CREATE USER rman IDENTIFIED BY rman&lt;br /&gt;2 TEMPORARY TABLESPACE temp&lt;br /&gt;3 DEFAULT TABLESPACE rman&lt;br /&gt;4 QUOTA UNLIMITED ON rman;&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;SQL&gt; GRANT connect, resource, recovery_catalog_owner TO rman;&lt;br /&gt;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step3&lt;/span&gt; Create the recovery catalog in catalog database.&lt;br /&gt;&lt;br /&gt;C:\&gt;rman catalog=rman/rman@catdb&lt;br /&gt;&lt;br /&gt;Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 21 09:59:26 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to recovery catalog database&lt;br /&gt;&lt;br /&gt;RMAN&gt; create catalog tablespace "RMAN";&lt;br /&gt;&lt;br /&gt;recovery catalog created&lt;br /&gt;&lt;br /&gt;RMAN&gt; exit&lt;br /&gt;&lt;br /&gt;Recovery Manager complete.&lt;br /&gt;&lt;br /&gt;C:\&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step4&lt;/span&gt; Register the database with Catalog database. Each database should be registered to catalog database to run RMAN backup.&lt;br /&gt;&lt;br /&gt;C:\&gt;rman catalog=rman/rman@catdb target=sys/password@orcl&lt;br /&gt;&lt;br /&gt;Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 21 10:02:01 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to target database: ORCL (DBID=1215124933)&lt;br /&gt;connected to recovery catalog database&lt;br /&gt;&lt;br /&gt;RMAN&gt; register database;&lt;br /&gt;&lt;br /&gt;database registered in recovery catalog&lt;br /&gt;starting full resync of recovery catalog&lt;br /&gt;full resync complete&lt;br /&gt;&lt;br /&gt;RMAN&gt; exit&lt;br /&gt;&lt;br /&gt;Recovery Manager complete.&lt;br /&gt;&lt;br /&gt;C:\&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step5 &lt;/span&gt;&lt;span style="color:#000000;"&gt;Configure the persistent parameters.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;C:\&gt;rman catalog=rman/rman@catdb target=sys/password@orcl&lt;br /&gt;&lt;br /&gt;Recovery Manager: Release 10.2.0.1.0 - Production on Tue May 19 18:46:40 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to target database: ORCL (DBID=1215054467)&lt;br /&gt;connected to recovery catalog database&lt;br /&gt;&lt;br /&gt;RMAN&gt; configure retention policy to recovery window of 2 days;&lt;br /&gt;&lt;br /&gt;new RMAN configuration parameters:&lt;br /&gt;CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;&lt;br /&gt;new RMAN configuration parameters are successfully stored&lt;br /&gt;starting full resync of recovery catalog&lt;br /&gt;full resync complete&lt;br /&gt;&lt;br /&gt;RMAN&gt; configure default device type to disk;&lt;br /&gt;&lt;br /&gt;new RMAN configuration parameters:&lt;br /&gt;CONFIGURE DEFAULT DEVICE TYPE TO DISK;&lt;br /&gt;new RMAN configuration parameters are successfully stored&lt;br /&gt;starting full resync of recovery catalog&lt;br /&gt;full resync complete&lt;br /&gt;&lt;br /&gt;RMAN&gt; configure controlfile autobackup on;&lt;br /&gt;&lt;br /&gt;new RMAN configuration parameters:&lt;br /&gt;CONFIGURE CONTROLFILE AUTOBACKUP ON;&lt;br /&gt;new RMAN configuration parameters are successfully stored&lt;br /&gt;starting full resync of recovery catalog&lt;br /&gt;full resync complete&lt;br /&gt;&lt;br /&gt;RMAN&gt; configure channel device type disk format 'C:\rmanbackup\Backup%d_DB_%U_%S&lt;br /&gt;_%P';&lt;br /&gt;&lt;br /&gt;new RMAN configuration parameters:&lt;br /&gt;CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT 'C:\rmanbackup\Backup%d_DB_%U_%S_%P'&lt;br /&gt;;&lt;br /&gt;new RMAN configuration parameters are successfully stored&lt;br /&gt;starting full resync of recovery catalog&lt;br /&gt;full resync complete&lt;br /&gt;&lt;br /&gt;RMAN&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step 6&lt;/span&gt;&lt;span style="color:#000000;"&gt; Take database full backup.&lt;/span&gt; The full database backup should be taken first time. Afterwards, archivelog backup will be taken.&lt;br /&gt;&lt;br /&gt;C:\&gt;rman catalog=rman/rman@catdb target=sys/password@orcl&lt;br /&gt;&lt;br /&gt;Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 21 10:16:09 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to target database: ORCL (DBID=1215124933)&lt;br /&gt;connected to recovery catalog database&lt;br /&gt;&lt;br /&gt;RMAN&gt; run{&lt;br /&gt;2&gt; backup database plus archivelog;&lt;br /&gt;3&gt; delete noprompt obsolete;&lt;br /&gt;4&gt; }&lt;br /&gt;&lt;br /&gt;starting full resync of recovery catalog&lt;br /&gt;full resync complete&lt;br /&gt;&lt;br /&gt;Starting backup at 21-MAY-09&lt;br /&gt;current log archived&lt;br /&gt;allocated channel: ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: sid=144 devtype=DISK&lt;br /&gt;channel ORA_DISK_1: starting archive log backupset&lt;br /&gt;channel ORA_DISK_1: specifying archive log(s) in backup set&lt;br /&gt;input archive log thread=1 sequence=2 recid=1 stamp=687435222&lt;br /&gt;input archive log thread=1 sequence=3 recid=2 stamp=687435237&lt;br /&gt;input archive log thread=1 sequence=4 recid=3 stamp=687435270&lt;br /&gt;input archive log thread=1 sequence=5 recid=4 stamp=687435279&lt;br /&gt;input archive log thread=1 sequence=6 recid=5 stamp=687435420&lt;br /&gt;channel ORA_DISK_1: starting piece 1 at 21-MAY-09&lt;br /&gt;channel ORA_DISK_1: finished piece 1 at 21-MAY-09&lt;br /&gt;piece handle=C:\RMANBACKUP\BACKUPORCL_DB_01KFIRKU_1_1_%S_%P tag=TAG20090521T1017&lt;br /&gt;01 comment=NONE&lt;br /&gt;channel ORA_DISK_1: backup set complete, elapsed time: 00:00:16&lt;br /&gt;Finished backup at 21-MAY-09&lt;br /&gt;&lt;br /&gt;Starting backup at 21-MAY-09&lt;br /&gt;using channel ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: starting full datafile backupset&lt;br /&gt;channel ORA_DISK_1: specifying datafile(s) in backupset&lt;br /&gt;input datafile fno=00001 name=C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF&lt;br /&gt;&lt;br /&gt;input datafile fno=00003 name=C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF&lt;br /&gt;&lt;br /&gt;input datafile fno=00004 name=C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF&lt;br /&gt;input datafile fno=00002 name=C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DB&lt;br /&gt;F&lt;br /&gt;channel ORA_DISK_1: starting piece 1 at 21-MAY-09&lt;br /&gt;channel ORA_DISK_1: finished piece 1 at 21-MAY-09&lt;br /&gt;piece handle=C:\RMANBACKUP\BACKUPORCL_DB_02KFIRLF_1_1_%S_%P tag=TAG20090521T1017&lt;br /&gt;19 comment=NONE&lt;br /&gt;channel ORA_DISK_1: backup set complete, elapsed time: 00:01:06&lt;br /&gt;Finished backup at 21-MAY-09&lt;br /&gt;&lt;br /&gt;Starting backup at 21-MAY-09&lt;br /&gt;current log archived&lt;br /&gt;using channel ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: starting archive log backupset&lt;br /&gt;channel ORA_DISK_1: specifying archive log(s) in backup set&lt;br /&gt;input archive log thread=1 sequence=7 recid=6 stamp=687435506&lt;br /&gt;channel ORA_DISK_1: starting piece 1 at 21-MAY-09&lt;br /&gt;channel ORA_DISK_1: finished piece 1 at 21-MAY-09&lt;br /&gt;piece handle=C:\RMANBACKUP\BACKUPORCL_DB_03KFIRNJ_1_1_%S_%P tag=TAG20090521T1018&lt;br /&gt;27 comment=NONE&lt;br /&gt;channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03&lt;br /&gt;Finished backup at 21-MAY-09&lt;br /&gt;&lt;br /&gt;Starting Control File and SPFILE Autobackup at 21-MAY-09&lt;br /&gt;piece handle=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\C-1215124933-20090521-00 com&lt;br /&gt;ment=NONE&lt;br /&gt;Finished Control File and SPFILE Autobackup at 21-MAY-09&lt;br /&gt;&lt;br /&gt;RMAN retention policy will be applied to the command&lt;br /&gt;RMAN retention policy is set to recovery window of 2 days&lt;br /&gt;using channel ORA_DISK_1&lt;br /&gt;no obsolete backups found&lt;br /&gt;&lt;br /&gt;RMAN&gt; exit&lt;br /&gt;&lt;br /&gt;Recovery Manager complete.&lt;br /&gt;&lt;br /&gt;C:\&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Now the RMAN setup is completed successfully. Here are the info about RMAN.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Primary DB = ORCL&lt;br /&gt;Catalog DB = CATDB&lt;br /&gt;RMAN Backup location = c:\rmanbackup.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Now the full backup is taken. Every day, the below script should run and backup the new archive log files.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;C:\&gt;rman catalog=rman/rman@catdb target=sys/password@orcl&lt;br /&gt;&lt;br /&gt;Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 21 10:25:40 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to target database: ORCL (DBID=1215124933)&lt;br /&gt;connected to recovery catalog database&lt;br /&gt;&lt;br /&gt;RMAN&gt; run{&lt;br /&gt;2&gt; delete noprompt obsolete;&lt;br /&gt;3&gt; backup archivelog all;&lt;br /&gt;4&gt; }&lt;br /&gt;&lt;br /&gt;RMAN retention policy will be applied to the command&lt;br /&gt;RMAN retention policy is set to recovery window of 2 days&lt;br /&gt;allocated channel: ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: sid=133 devtype=DISK&lt;br /&gt;no obsolete backups found&lt;br /&gt;&lt;br /&gt;Starting backup at 21-MAY-09&lt;br /&gt;current log archived&lt;br /&gt;using channel ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: starting archive log backupset&lt;br /&gt;channel ORA_DISK_1: specifying archive log(s) in backup set&lt;br /&gt;input archive log thread=1 sequence=2 recid=1 stamp=687435222&lt;br /&gt;input archive log thread=1 sequence=3 recid=2 stamp=687435237&lt;br /&gt;input archive log thread=1 sequence=4 recid=3 stamp=687435270&lt;br /&gt;input archive log thread=1 sequence=5 recid=4 stamp=687435279&lt;br /&gt;input archive log thread=1 sequence=6 recid=5 stamp=687435420&lt;br /&gt;input archive log thread=1 sequence=7 recid=6 stamp=687435506&lt;br /&gt;input archive log thread=1 sequence=8 recid=7 stamp=687435975&lt;br /&gt;channel ORA_DISK_1: starting piece 1 at 21-MAY-09&lt;br /&gt;channel ORA_DISK_1: finished piece 1 at 21-MAY-09&lt;br /&gt;piece handle=C:\RMANBACKUP\BACKUPORCL_DB_05KFIS68_1_1_%S_%P tag=TAG20090521T1026&lt;br /&gt;15 comment=NONE&lt;br /&gt;channel ORA_DISK_1: backup set complete, elapsed time: 00:00:16&lt;br /&gt;Finished backup at 21-MAY-09&lt;br /&gt;&lt;br /&gt;Starting Control File and SPFILE Autobackup at 21-MAY-09&lt;br /&gt;piece handle=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\C-1215124933-20090521-01 com&lt;br /&gt;ment=NONE&lt;br /&gt;Finished Control File and SPFILE Autobackup at 21-MAY-09&lt;br /&gt;&lt;br /&gt;RMAN&gt; exit&lt;br /&gt;&lt;br /&gt;Recovery Manager complete.&lt;br /&gt;&lt;br /&gt;C:\&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we schedule the daily backup in Windows OS?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;We need to write two script, &lt;/span&gt;&lt;span style="color:#000000;"&gt;one is batch file(named as daily_backup.bat) which should contain the following command.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;rman &lt;a href="mailto:catalog=rman/rman@catdb"&gt;catalog=rman/rman@catdb&lt;/a&gt; &lt;a href="mailto:target=sys/password@orcl"&gt;target=sys/password@orcl&lt;/a&gt; cmdfile daily_backup.sql&lt;br /&gt;&lt;br /&gt;Another one is text file(named as daily_backup.sql) which should contain the following code.&lt;br /&gt;&lt;br /&gt;run&lt;br /&gt;{&lt;br /&gt;backup archivelog all;&lt;br /&gt;delete noprompt obsolete;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The batch file(daily_backup.bat) can be run manually, by double-clicking on it, or scheduled using the Scheduled Tasks Wizard (Start &gt; Programs &gt; Accessories &gt; System Tools &gt; Scheduled Tasks). The above two windows scripts are tested in windows environment and works well.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we schedule the daily backup in Unix?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Here we need to write shell script and schedule the shell script in unix scheduler(crontab).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The shell script content should be like this....... Please remember, the below shell script is not tested in unix environment. Please do test yourself in unix environment.... This is sample shell script...&lt;br /&gt;&lt;br /&gt;export ORACLE_HOME=/usr/app/oracle/product/10.2.0&lt;br /&gt;export ORACLE_SID=orcl&lt;br /&gt;export ALIAS=orcl&lt;br /&gt;cd =/usr/app/oracle/product/10.2.0/bin&lt;br /&gt;rman catalog=rman/rman@catdb target=sys/password@orcl &lt;&lt;&lt;br /&gt;run&lt;br /&gt;{&lt;br /&gt;backup archivelog all;&lt;br /&gt;delete noprompt obsolete;&lt;br /&gt;}&lt;br /&gt;exit&lt;br /&gt;EOF&lt;br /&gt;&lt;br /&gt;The above shell script can be scheduled in crontab. To learn more about crontab, see this &lt;a href="http://www.adminschoice.com/docs/crontab.htm"&gt;link.&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;If you want to read more on RMAN, Please click this &lt;a href="http://download-uk.oracle.com/docs/cd/B19306_01/backup.102/b14194/toc.htm"&gt;link.... &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I have discussed some of the other topics which are related to this thread. Please go through below links in case if you are interested....&lt;br /&gt;&lt;br /&gt;What are the new features in RMAN since Oracle9i?  &lt;a href="http://myorastuff.blogspot.com/2009/05/new-features-in-rman-since-oracle9i.html"&gt;Click&lt;/a&gt; here&lt;br /&gt;&lt;br /&gt;Different type of recovery scenario in RMAN?  &lt;a href="http://myorastuff.blogspot.com/2009/05/rman-recovery-scenarios.html"&gt;Click&lt;/a&gt; here&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-4021152490047749731?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/4021152490047749731/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=4021152490047749731' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/4021152490047749731'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/4021152490047749731'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/steps-to-setup-rman.html' title='Steps to Setup RMAN'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-2124925863920632366</id><published>2009-05-20T17:11:00.000-07:00</published><updated>2009-06-25T11:48:59.079-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='incremental backup'/><category scheme='http://www.blogger.com/atom/ns#' term='block media recovery'/><category scheme='http://www.blogger.com/atom/ns#' term='automated backup'/><category scheme='http://www.blogger.com/atom/ns#' term='use of RMAN backup'/><category scheme='http://www.blogger.com/atom/ns#' term='RMAN'/><category scheme='http://www.blogger.com/atom/ns#' term='BMR'/><category scheme='http://www.blogger.com/atom/ns#' term='High water mark'/><category scheme='http://www.blogger.com/atom/ns#' term='Benefits of RMAN Backup vs. Scripted Backups'/><category scheme='http://www.blogger.com/atom/ns#' term='RMAN corrupted block'/><category scheme='http://www.blogger.com/atom/ns#' term='HWM'/><title type='text'>Benefits of RMAN Backup vs. Scripted Backups</title><content type='html'>RMAN was introduced in oracle8i. Before oracle8i, we used traditional backup or scripted backup. Why did oracle move to RMAN backup? Why do we need to use RMAN to backup our database? We may already be doing online backup with some wonderfully crafted, home-grown scripts. We may ask this question ourself. Why should we start using RMAN when my scripted backups are working fine?&lt;br /&gt;&lt;br /&gt;We are moving to RMAN backup for two reasons. One is, when backup scripts breaks, the database backup would fail. Another issue is, when script fails, some one has to fix the backup scripts.&lt;br /&gt;&lt;br /&gt;There are number of other positive reason to move to RMAN backup. Here are these....&lt;br /&gt;&lt;br /&gt;1. RMAN will detect corrupted blocks and report them to us. RMAN also can recover only corrupted blocks. This is called Block Media Recovery(BMR). In traditional recovery, we need to restore and recover the whole data file. But in RMAN, it is not required to restore and recover the entire data file for just few corrupted blocks.&lt;br /&gt;&lt;br /&gt;2. RMAN can back up your database online without having to put the tablespace in hot backup mode. Thus, the additional redo generated during a hot backup is reduced.&lt;br /&gt;&lt;br /&gt;3. RMAN will automatically track new datafiles and tablespaces for us. In scripted backup, we might need to change the backup script when new tablespace or data file is added in the database.&lt;br /&gt;&lt;br /&gt;4. RMAN will only backup up used data blocks(up to the high water mark(HWM)). So RMAN backup images typically are smaller than those of traditional online back images.&lt;br /&gt;&lt;br /&gt;5. RMAN provides easy, automated backup, restore and recovery operations. RMAN tracks all the backups needed to recover the database.&lt;br /&gt;&lt;br /&gt;6. RMAN can work fairly seamlessly with third-party media management products.&lt;br /&gt;&lt;br /&gt;7. RMAN supports incremental backup strategies.&lt;br /&gt;&lt;br /&gt;8. With RMAN, we can actually test backups without restoring them. We can validate the backup and make sure backup will work at the time of restore.&lt;br /&gt;&lt;br /&gt;9. If we use the repository, then RMAN provides a nice, centralized reporting facility.&lt;br /&gt;&lt;br /&gt;I have discussed some of the other topics which are related to this thread. Please go through below links in case if you are interested....&lt;br /&gt;&lt;br /&gt;How do we enable archivelog in oracle? &lt;a href="http://myorastuff.blogspot.com/2009/05/enable-archive-log-in-oracle10g.html"&gt;Click&lt;/a&gt; here&lt;br /&gt;&lt;br /&gt;How do we set up RMAN in oracle? &lt;a href="http://myorastuff.blogspot.com/2009/05/steps-to-setup-rman.html"&gt;Click&lt;/a&gt; here&lt;br /&gt;&lt;br /&gt;What are the new features in RMAN since Oracle9i? &lt;a href="http://myorastuff.blogspot.com/2009/05/new-features-in-rman-since-oracle9i.html"&gt;Click&lt;/a&gt; here&lt;br /&gt;&lt;br /&gt;Different type of recovery scenario in RMAN? &lt;a href="http://myorastuff.blogspot.com/2009/05/rman-recovery-scenarios.html"&gt;Click&lt;/a&gt; here&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-2124925863920632366?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/2124925863920632366/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=2124925863920632366' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2124925863920632366'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2124925863920632366'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/benefits-of-rman-backup-vs-scripted.html' title='Benefits of RMAN Backup vs. Scripted Backups'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-826478332789585490</id><published>2009-05-19T06:25:00.002-07:00</published><updated>2009-06-20T08:31:41.433-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='archive log list'/><category scheme='http://www.blogger.com/atom/ns#' term='alter database open'/><category scheme='http://www.blogger.com/atom/ns#' term='spfile'/><category scheme='http://www.blogger.com/atom/ns#' term='enable archive log'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-32004'/><category scheme='http://www.blogger.com/atom/ns#' term='archive log'/><category scheme='http://www.blogger.com/atom/ns#' term='log_archive_dest'/><category scheme='http://www.blogger.com/atom/ns#' term='db_recovery_file_dest_size'/><category scheme='http://www.blogger.com/atom/ns#' term='create pfile'/><category scheme='http://www.blogger.com/atom/ns#' term='db_recovery_file_dest'/><category scheme='http://www.blogger.com/atom/ns#' term='log_archive_format'/><title type='text'>Enable Archive log in Oracle10g</title><content type='html'>&lt;span style="color:#ff0000;"&gt;How do we enable the archive log mode in oracle10g?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The below article is tested in oracle10g R2 version. Please remember, below steps directories and folders would change based on the environment and operating systems. Here the database name is ORCL.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step 1&lt;/span&gt; &lt;span style="color:#000000;"&gt;We need to build the pfile from spfile to add new entries. If you have already recent pfile, the you do not need to do this step.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Login as sys user and execute this to create pfile.&lt;br /&gt;&lt;br /&gt;create pfile='C:\oracle\product\10.2.0\db_1\dbs\PFILE.ORA' from spfile;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step 2&lt;/span&gt; Once pfile is created, then edit the pfile and add the below two parameters.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;log_archive_format=Log_%s_%t_%r.arc&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;log_archive_dest='C:\oracle\product\10.2.0\db_1\database\archive'&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;In case, if you already have the below two entries in the pfile, then we need to remove or comment this below two entires. Since we can not have this below two entry with above new two parameters.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;db_recovery_file_dest='C:\oracle\product\10.2.0\flash_recovery_area'&lt;br /&gt;db_recovery_file_dest_size=2147483648&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Till oracle9i, we use &lt;span style="color:#ff0000;"&gt;log_archive_start=true&lt;/span&gt; in parameter file. Since from oracle10g, this parameter is deprecated. We should not add this entry in pfile from oracle10g. If we have this entry in oracle10g, we get the below error.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;ORA-32004:obsolete and/or deprecated parameter specified.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step 3&lt;/span&gt; &lt;span style="color:#000000;"&gt;Once pfile is edited, then we need to create the spfile with modified pfile.&lt;/span&gt; Login as sys user and execute the below command.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;create spfile = 'C:\oracle\product\10.2.0\db_1\dbs\XX.ORA' from pfile='C:\oracle\product\10.2.0\db_1\dbs\PFILE.ORA'&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step 4&lt;/span&gt; &lt;span style="color:#000000;"&gt;Rename the original SPFILEORCL.ORA to different name. Then rename the XX.ORA to SPFILEORCL.ORA.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step 5&lt;/span&gt; &lt;span style="color:#000000;"&gt;Login as sys user and shutdown the database and follow the steps.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Mount the database&lt;br /&gt;alter database archivelog&lt;br /&gt;alter database open;&lt;br /&gt;&lt;br /&gt;Here is the screen output....&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; shutdown immediate&lt;br /&gt;Database closed.&lt;br /&gt;Database dismounted.&lt;br /&gt;ORACLE instance shut down.&lt;br /&gt;SQL&gt; startup mount&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area 612368384 bytes&lt;br /&gt;Fixed Size 1250428 bytes&lt;br /&gt;Variable Size 188746628 bytes&lt;br /&gt;Database Buffers 415236096 bytes&lt;br /&gt;Redo Buffers 7135232 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;SQL&gt; alter database archivelog;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database open;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; archive log list;&lt;br /&gt;Database log mode Archive Mode&lt;br /&gt;Automatic archival Enabled&lt;br /&gt;Archive destination C:\oracle\product\10.2.0\db_1\database\archive&lt;br /&gt;Oldest online log sequence 2&lt;br /&gt;Next log sequence to archive 4&lt;br /&gt;Current log sequence 4&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;I have discussed some of the other topics which are related to this thread. Please go through below links in case if you are interested....&lt;br /&gt;&lt;br /&gt;How do we set up RMAN in oracle?  &lt;a href="http://myorastuff.blogspot.com/2009/05/steps-to-setup-rman.html"&gt;Click&lt;/a&gt; here&lt;br /&gt;&lt;br /&gt;What are the new features in RMAN since Oracle9i?  &lt;a href="http://myorastuff.blogspot.com/2009/05/new-features-in-rman-since-oracle9i.html"&gt;Click&lt;/a&gt; here&lt;br /&gt;&lt;br /&gt;What is difference between traditional backup and RMAN backup?  &lt;a href="http://myorastuff.blogspot.com/2009/05/benefits-of-rman-backup-vs-scripted.html"&gt;Click&lt;/a&gt; here&lt;br /&gt;&lt;br /&gt;Different type of recovery scenario in RMAN?  &lt;a href="http://myorastuff.blogspot.com/2009/05/rman-recovery-scenarios.html"&gt;Click&lt;/a&gt; here&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-826478332789585490?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/826478332789585490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=826478332789585490' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/826478332789585490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/826478332789585490'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/enable-archive-log-in-oracle10g.html' title='Enable Archive log in Oracle10g'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-8274287888217962348</id><published>2009-05-18T13:46:00.001-07:00</published><updated>2009-05-20T19:32:54.146-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='drop database'/><category scheme='http://www.blogger.com/atom/ns#' term='startup restrict mount'/><category scheme='http://www.blogger.com/atom/ns#' term='unregister database'/><category scheme='http://www.blogger.com/atom/ns#' term='drop database including backups'/><category scheme='http://www.blogger.com/atom/ns#' term='drop database in oracle10g'/><category scheme='http://www.blogger.com/atom/ns#' term='Metalink Note: 251412.1'/><category scheme='http://www.blogger.com/atom/ns#' term='DBCA'/><category scheme='http://www.blogger.com/atom/ns#' term='catalog database'/><title type='text'>Dropping database in oracle10g</title><content type='html'>There are few ways, we can drop the database in oracle. This article is tested in oracle10gR2. Let us discuss these options here.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Option 1. &lt;/span&gt;&lt;span style="color:#000000;"&gt;We can use DBCA utility to drop the database. This approach will be a clean approach for dropping database. Since DBCA tool drop all the data files, control files, redolog files, spfile, password file and background dump trace files. This approach cleans up the tnsentry in tnsnames.ora file if we have tnsnames.ora file in server. It also deletes the entire folders relevant to that database. But this approach will not delete RMAN backup files, archived redo log files. If the database is running in RMAN and it is registered with catalog database, then DBCA utility will not unregister from catalog database automatically. So before we drop the database by using DBCA utility, we need to unregister the database by using RMAN UNREGISTER DATABASE command. If the database is using only control file for RMAN metadata, then this command is not necessary.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Option 2 &lt;/span&gt;In oracle10g, we have a command to drop the database. All the data files, control files, redo log files will be deleted automatically when we use drop database command in oracle10g. But it is not deleting the folders. It is not deleting dump files, alert log files, archived redo log files, RMAN backup files and password files  relevant to the database. Also it is not cleaning the tnsentry in tnsnames.ora file if we have tnsnames.ora file in server. We need to clean these files and folders manually after we drop the database by using drop database command. If the database is running in RMAN with catalog database, we need to unregister the database manually from catalog before we drop the database. This option would not remove backup info in catalog DB.&lt;br /&gt;&lt;br /&gt;Here are the steps to drop the database in oracle10g.&lt;br /&gt;&lt;br /&gt;1. Connect as sys user&lt;br /&gt;2. shutdown the database&lt;br /&gt;3. Mount the database with restrict mode&lt;br /&gt;4. Drop the database&lt;br /&gt;5. Clean up the files manually(trace files, password file, folders, cleaning the tnsentry, archive redo log files, RMAN backup files)&lt;br /&gt;&lt;br /&gt;SQL&gt; shutdown immediate&lt;br /&gt;Database closed.&lt;br /&gt;Database dismounted.&lt;br /&gt;ORACLE instance shut down.&lt;br /&gt;SQL&gt; startup restrict mount;&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area 612368384 bytes&lt;br /&gt;Fixed Size 1250428 bytes&lt;br /&gt;Variable Size 155192196 bytes&lt;br /&gt;Database Buffers 448790528 bytes&lt;br /&gt;Redo Buffers 7135232 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;SQL&gt; drop database;&lt;br /&gt;&lt;br /&gt;Database dropped.&lt;br /&gt;&lt;br /&gt;Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Option 3&lt;/span&gt;&lt;span style="color:#000000;"&gt; When the database is running in RMAN, the database must be registered with catalog database. The above two options will not unregister the database from catalog DB. It will not remove the backup information from catalog database. If we use the above options, we need to unregister the database from catalog manually before we drop the database. Oracle10g introduced new feature that we can now use RMAN to drop a database and remove all its records from the RMAN CATALOG. Dropping database from RMAN has a additional benefit of dropping all backup copies and archived log files for the database. &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;For further information pls also see Metalink Note: 251412.1 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;But still it is not deleting the dump files, alert log files, password file. It is not removing tnsentry in tnsnames.ora file if we have tnsnames.ora file in server. But it cleans data file, control file, redo log file, archive log file, RMAN backup files and removes backup info in CATALOG Database.&lt;br /&gt;&lt;br /&gt;C:\&gt;rman target / catalog rman/rman@catdb&lt;br /&gt;&lt;br /&gt;Recovery Manager: Release 10.2.0.1.0 - Production on Wed May 20 15:11:25 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;connected to target database (not started)&lt;br /&gt;connected to recovery catalog database&lt;br /&gt;&lt;br /&gt;RMAN&gt; startup mount&lt;br /&gt;&lt;br /&gt;Oracle instance started&lt;br /&gt;database mounted&lt;br /&gt;&lt;br /&gt;Total System Global Area 612368384 bytes&lt;br /&gt;&lt;br /&gt;Fixed Size 1250428 bytes&lt;br /&gt;Variable Size 188746628 bytes&lt;br /&gt;Database Buffers 415236096 bytes&lt;br /&gt;Redo Buffers 7135232 bytes&lt;br /&gt;&lt;br /&gt;RMAN&gt; sql 'alter system enable restricted session';&lt;br /&gt;&lt;br /&gt;sql statement: alter system enable restricted session&lt;br /&gt;&lt;br /&gt;RMAN&gt; drop database including backups;&lt;br /&gt;&lt;br /&gt;database name is "ORCL" and DBID is 1215054467&lt;br /&gt;&lt;br /&gt;Do you really want to drop all backups and the database (enter YES or NO)? YES&lt;br /&gt;&lt;br /&gt;allocated channel: ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: sid=156 devtype=DISK&lt;br /&gt;&lt;br /&gt;List of Backup Pieces&lt;br /&gt;BP Key BS Key Pc# Cp# Status Device Type Piece Name&lt;br /&gt;------- ------- --- --- ----------- ----------- ----------&lt;br /&gt;36 34 1 1 AVAILABLE DISK C:\RMANBACKUP\BACKUPORCL_DB_01KF&lt;br /&gt;EGUK_1_1_%S_%P&lt;br /&gt;37 35 1 1 AVAILABLE DISK C:\RMANBACKUP\BACKUPORCL_DB_02KF&lt;br /&gt;EGUN_1_1_%S_%P&lt;br /&gt;54 49 1 1 AVAILABLE DISK C:\RMANBACKUP\BACKUPORCL_DB_03KF&lt;br /&gt;EGVS_1_1_%S_%P&lt;br /&gt;64 62 1 1 AVAILABLE DISK C:\ORACLE\PRODUCT\10.2.0\DB_1\DA&lt;br /&gt;TABASE\C-1215054467-20090519-00&lt;br /&gt;133 130 1 1 AVAILABLE DISK C:\ORACLE\PRODUCT\10.2.0\DB_1\DA&lt;br /&gt;TABASE\C-1215054467-20090519-01&lt;br /&gt;261 255 1 1 AVAILABLE DISK C:\ORACLE\PRODUCT\10.2.0\DB_1\DA&lt;br /&gt;TABASE\C-1215054467-20090519-02&lt;br /&gt;328 324 1 1 AVAILABLE DISK C:\RMANBACKUP\BACKUPORCL_DB_07KF&lt;br /&gt;EQ6L_1_1_%S_%P&lt;br /&gt;329 325 1 1 AVAILABLE DISK C:\RMANBACKUP\BACKUPORCL_DB_08KF&lt;br /&gt;EQ7P_1_1_%S_%P&lt;br /&gt;356 350 1 1 AVAILABLE DISK C:\ORACLE\PRODUCT\10.2.0\DB_1\DA&lt;br /&gt;TABASE\C-1215054467-20090519-03&lt;br /&gt;deleted backup piece&lt;br /&gt;backup piece handle=C:\RMANBACKUP\BACKUPORCL_DB_01KFEGUK_1_1_%S_%P recid=1 stamp&lt;br /&gt;=687293397&lt;br /&gt;deleted backup piece&lt;br /&gt;backup piece handle=C:\RMANBACKUP\BACKUPORCL_DB_02KFEGUN_1_1_%S_%P recid=2 stamp&lt;br /&gt;=687293400&lt;br /&gt;deleted backup piece&lt;br /&gt;backup piece handle=C:\RMANBACKUP\BACKUPORCL_DB_03KFEGVS_1_1_%S_%P recid=3 stamp&lt;br /&gt;=687293438&lt;br /&gt;deleted backup piece&lt;br /&gt;backup piece handle=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\C-1215054467-20090519&lt;br /&gt;-00 recid=4 stamp=687293441&lt;br /&gt;deleted backup piece&lt;br /&gt;backup piece handle=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\C-1215054467-20090519&lt;br /&gt;-01 recid=5 stamp=687297981&lt;br /&gt;deleted backup piece&lt;br /&gt;backup piece handle=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\C-1215054467-20090519&lt;br /&gt;-02 recid=6 stamp=687301176&lt;br /&gt;deleted backup piece&lt;br /&gt;backup piece handle=C:\RMANBACKUP\BACKUPORCL_DB_07KFEQ6L_1_1_%S_%P recid=7 stamp&lt;br /&gt;=687302870&lt;br /&gt;deleted backup piece&lt;br /&gt;backup piece handle=C:\RMANBACKUP\BACKUPORCL_DB_08KFEQ7P_1_1_%S_%P recid=8 stamp&lt;br /&gt;=687302906&lt;br /&gt;deleted backup piece&lt;br /&gt;backup piece handle=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\C-1215054467-20090519&lt;br /&gt;-03 recid=9 stamp=687302924&lt;br /&gt;Deleted 9 objects&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;released channel: ORA_DISK_1&lt;br /&gt;allocated channel: ORA_DISK_1&lt;br /&gt;channel ORA_DISK_1: sid=156 devtype=DISK&lt;br /&gt;&lt;br /&gt;List of Archived Log Copies&lt;br /&gt;Key Thrd Seq S Low Time Name&lt;br /&gt;------- ---- ------- - --------- ----&lt;br /&gt;26 1 3 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_3_1_687273734.ARC&lt;br /&gt;33 1 4 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_4_1_687273734.ARC&lt;br /&gt;103 1 5 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_5_1_687273734.ARC&lt;br /&gt;104 1 6 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_6_1_687273734.ARC&lt;br /&gt;128 1 7 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_7_1_687273734.ARC&lt;br /&gt;129 1 8 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_8_1_687273734.ARC&lt;br /&gt;164 1 9 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_9_1_687273734.ARC&lt;br /&gt;165 1 10 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_10_1_687273734.ARC&lt;br /&gt;166 1 11 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_11_1_687273734.ARC&lt;br /&gt;167 1 12 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_12_1_687273734.ARC&lt;br /&gt;249 1 13 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_13_1_687273734.ARC&lt;br /&gt;287 1 1 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_1_1_687301150.ARC&lt;br /&gt;288 1 2 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_2_1_687301150.ARC&lt;br /&gt;289 1 3 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_3_1_687301150.ARC&lt;br /&gt;290 1 4 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_4_1_687301150.ARC&lt;br /&gt;319 1 5 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_5_1_687301150.ARC&lt;br /&gt;384 1 6 A 19-MAY-09 C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\&lt;br /&gt;LOG_6_1_687301150.ARC&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_3_1_6872&lt;br /&gt;73734.ARC recid=1 stamp=687293394&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_4_1_6872&lt;br /&gt;73734.ARC recid=2 stamp=687293436&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_5_1_6872&lt;br /&gt;73734.ARC recid=3 stamp=687297267&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_6_1_6872&lt;br /&gt;73734.ARC recid=4 stamp=687297285&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_7_1_6872&lt;br /&gt;73734.ARC recid=5 stamp=687298507&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_8_1_6872&lt;br /&gt;73734.ARC recid=6 stamp=687298515&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_9_1_6872&lt;br /&gt;73734.ARC recid=7 stamp=687300567&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_10_1_687&lt;br /&gt;273734.ARC recid=8 stamp=687300576&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_11_1_687&lt;br /&gt;273734.ARC recid=9 stamp=687300608&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_12_1_687&lt;br /&gt;273734.ARC recid=10 stamp=687300618&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_13_1_687&lt;br /&gt;273734.ARC recid=11 stamp=687301152&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_1_1_6873&lt;br /&gt;01150.ARC recid=12 stamp=687301663&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_2_1_6873&lt;br /&gt;01150.ARC recid=13 stamp=687301679&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_3_1_6873&lt;br /&gt;01150.ARC recid=14 stamp=687301699&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_4_1_6873&lt;br /&gt;01150.ARC recid=15 stamp=687301706&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_5_1_6873&lt;br /&gt;01150.ARC recid=16 stamp=687302866&lt;br /&gt;deleted archive log&lt;br /&gt;archive log filename=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\ARCHIVE\LOG_6_1_6873&lt;br /&gt;01150.ARC recid=17 stamp=687340879&lt;br /&gt;Deleted 17 objects&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;database name is "ORCL" and DBID is 1215054467&lt;br /&gt;database dropped&lt;br /&gt;&lt;br /&gt;database name is "ORCL" and DBID is 1215054467&lt;br /&gt;database unregistered from the recovery catalog&lt;br /&gt;&lt;br /&gt;RMAN&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Conclusion: What is best choice to delete the database? Based on my experience, best choice would be, use DBCA to remove the Database. But before remove, unregister the database in CATALOG database if database is using RMAN with catalog. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;In case, if you don't have DBCA, then we can go for removing DB in RMAN as below.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;RMAN&gt; drop database including backups; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;After successfully dropped the database, we might need to remove dump files, password file manually. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Another option would be, using DROP DATABASE command. Again, you need to manually remove the files, backup info in CATALOG database.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-8274287888217962348?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/8274287888217962348/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=8274287888217962348' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/8274287888217962348'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/8274287888217962348'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/how-do-we-drop-database-in-oracle10g.html' title='Dropping database in oracle10g'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-5857348067610862266</id><published>2009-05-14T08:59:00.000-07:00</published><updated>2009-06-24T06:23:59.421-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ON COMMIT PRESERVE ROWS'/><category scheme='http://www.blogger.com/atom/ns#' term='Global temporary table'/><category scheme='http://www.blogger.com/atom/ns#' term='ON COMMIT DELETE ROWS'/><category scheme='http://www.blogger.com/atom/ns#' term='CREATE GLOBAL TEMPORARY TABLE'/><title type='text'>Global Temporary tables</title><content type='html'>During the application development, we use some staging table or temporary tables to store intermediate result which are complicated to complete in one pass. Normally we use regular table or PLSQL table(array) to capture the intermediate result. But oracle8i introduced global temporary table. We can use global temporary table instead of regular table.&lt;br /&gt;&lt;br /&gt;GLOBAL TEMPORARY TABLE indicates that the table is temporary and that its definition is visible to all sessions. The data in a temporary table is visible only to the session that inserts the data into the table&lt;br /&gt;&lt;br /&gt;Please remember, the below codes are tested in oracle10g R2.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What are the advantages of Global temporary table compared to regular table?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Let us call Global temporary table as GTT....&lt;br /&gt;&lt;br /&gt;1. GTT does not generate REDO info by itself. But regular table does generate redo infomation. So it will be faster when we use GTT.&lt;br /&gt;&lt;br /&gt;2. When we truncate the GTT, it truncates only session specific data. So others can still see their data. But regular table truncate will truncate the whole table.&lt;br /&gt;&lt;br /&gt;3. Data in GTT is deleted when the session ends or commit/rollback the transaction. So GTT data is session specific. But regular table is not session specific. It is visible of all the session once the data are committed.&lt;br /&gt;&lt;br /&gt;4. Index can be created on GTT. But scope of the index data is at the session level.&lt;br /&gt;&lt;br /&gt;5. Views can be created against GTT and combination GTT and regular table&lt;br /&gt;&lt;br /&gt;6. Like regular table, database triggers can be created on GTT&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Restriction on Global temporary tables :&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;1. GTT can not be partitioned. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;2. We can not create any Foreign key constraint on GTT&lt;br /&gt;&lt;br /&gt;3. Parallel DML and parallel queries are not supported for temporary tables. Parallel hints are ignored&lt;br /&gt;&lt;br /&gt;4. GTT cannot contain columns of nested table.&lt;br /&gt;&lt;br /&gt;5. Export and Import utilities can be used to transfer the table definitions, but no data rows are processed.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Creation of Global temporary tables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The session-specific rows in a global temporary table can be preserved for the whole session. The data will be deleted when we exit the session. The ON COMMIT PRESERVE ROWS clause indicates that the data should be deleted at the end of the session.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; CREATE GLOBAL TEMPORARY TABLE gtt(&lt;br /&gt;2 column1 NUMBER,&lt;br /&gt;3 column2 NUMBER&lt;br /&gt;4 ) ON COMMIT PRESERVE ROWS;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; insert into gtt values(1,1);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select * from gtt;&lt;br /&gt;&lt;br /&gt;COLUMN1 COLUMN2&lt;br /&gt;---------- ----------&lt;br /&gt;1 1&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; connect scott/tiger@orcl&lt;br /&gt;Connected.&lt;br /&gt;scott@orcl&gt; select * from gtt;&lt;br /&gt;&lt;br /&gt;no rows selected&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;The transaction-specific rows in a global temporary table can be preserved until we commit or rollback the transaction. The ON COMMIT DELETE ROWS clause indicates that the data should be deleted when we commit or rollback the transaction.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; CREATE GLOBAL TEMPORARY TABLE gtt(&lt;br /&gt;2 column1 NUMBER,&lt;br /&gt;3 column2 NUMBER&lt;br /&gt;4 ) ON COMMIT DELETE ROWS;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; INSERT INTO gtt values(1,1);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select * from gtt;&lt;br /&gt;&lt;br /&gt;no rows selected&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-5857348067610862266?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/5857348067610862266/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=5857348067610862266' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/5857348067610862266'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/5857348067610862266'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/global-temporary-tables.html' title='Global Temporary tables'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-855762794868266243</id><published>2009-05-13T18:26:00.000-07:00</published><updated>2009-06-24T06:42:27.317-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='oracle8i constraint stat'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-25128'/><category scheme='http://www.blogger.com/atom/ns#' term='No insert/update/delete'/><category scheme='http://www.blogger.com/atom/ns#' term='DISABLE VALIDATE'/><category scheme='http://www.blogger.com/atom/ns#' term='ENABLE NOVALIDATE'/><category scheme='http://www.blogger.com/atom/ns#' term='DISABLE NOVALIDATE'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-02291'/><category scheme='http://www.blogger.com/atom/ns#' term='ENABLE VALIDATE'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-02298'/><title type='text'>Constraint stats</title><content type='html'>Table constraint can be enabled or disabled by using CREATE TABLE or ALTER TABLE statement. In addition, the VALIDATE or NOVALIDATE keywords can be used to alter the action of the state. This is introduced in oracle8i.&lt;br /&gt;&lt;br /&gt;Here are the four type of constraint stats. These four constraint stats are applicable for all type of constraints(primary key, foreign key, check etc).&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;1. ENABLE VALIDATE&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;2. ENABLE NOVALIDATE&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;3. DISABLE VALIDATE&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;4. DISABLE NOVALIDATE&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;ENABLE VALIDATE&lt;/span&gt;&lt;span style="color:#000000;"&gt; is same as ENABLE. Constraint validate the data as soon as we entered in the table. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; CREATE TABLE MASTER(id NUMBER(10));&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; CREATE TABLE child(id NUMBER(10), master_id NUMBER(10));&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; ALTER TABLE master ADD PRIMARY KEY (id);&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; ALTER TABLE child ADD CONSTRAINT fk_master&lt;br /&gt;2 FOREIGN KEY (master_id)&lt;br /&gt;3 REFERENCES master&lt;br /&gt;4 ENABLE VALIDATE;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; INSERT INTO master VALUES(1);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; INSERT INTO child VALUES(12,12);&lt;br /&gt;INSERT INTO child VALUES(12,12)&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-02291: integrity constraint (SCOTT.FK_MASTER) violated - parent key not&lt;br /&gt;found&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; COMMIT;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;ENABLE NOVALIDATE&lt;/span&gt; is not same as ENABLE. Constraint validates the new data or modified data. It would not validate the existing data in table.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; insert into master values(1);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;&lt;a href="mailto:scott@ordb"&gt;scott@ordb&lt;/a&gt;&gt; alter table child disable constraint fk_master;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; INSERT INTO child VALUES(12,12);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; alter table child enable constraint fk_master;&lt;br /&gt;alter table child enable constraint fk_master&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-02298: cannot validate (SCOTT.FK_MASTER) - parent keys not found&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; ALTER TABLE CHILD MODIFY CONSTRAINTS FK_MASTER ENABLE NOVALIDATE;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; INSERT INTO child VALUES(12,12);&lt;br /&gt;INSERT INTO child VALUES(12,12)&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-02291: integrity constraint (SCOTT.FK_MASTER) violated - parent key not&lt;br /&gt;found&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; INSERT INTO child VALUES(1,1);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; select * from master;&lt;br /&gt;&lt;br /&gt;ID&lt;br /&gt;----------&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; select * from child;&lt;br /&gt;&lt;br /&gt;ID MASTER_ID&lt;br /&gt;---------- ----------&lt;br /&gt;1 1&lt;br /&gt;12 12&lt;br /&gt;&lt;br /&gt;scott@ordb&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;DISABLE NOVALIDATE&lt;/span&gt; is the same as DISABLE. The constraint is not checked so data may violate the constraint.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; ALTER TABLE CHILD MODIFY CONSTRAINTS FK_MASTER DISABLE NOVALIDATE;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; INSERT INTO CHILD VALUES(88,88);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; COMMIT;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; select * from master;&lt;br /&gt;&lt;br /&gt;ID&lt;br /&gt;----------&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; select * from child;&lt;br /&gt;&lt;br /&gt;ID MASTER_ID&lt;br /&gt;---------- ----------&lt;br /&gt;12 12&lt;br /&gt;1 1&lt;br /&gt;88 88&lt;br /&gt;&lt;br /&gt;scott@ordb&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;DISABLE VALIDATE&lt;/span&gt; means the constraint is not checked but disallows any modification of the constrained columns.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; ALTER TABLE CHILD MODIFY CONSTRAINTS FK_MASTER DISABLE VALIDATE;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; insert into master values(1);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; insert into child values(1,1);&lt;br /&gt;insert into child values(1,1)&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-25128: No insert/update/delete on table with constraint (SCOTT.FK_MASTER)&lt;br /&gt;disabled and validated&lt;br /&gt;&lt;br /&gt;scott@ordb&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Note : Couple of things needs to be noted down here. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. Converting NOVALIDATE constraint to VALIDATE would take longer time, depends on how big the data in the table. Although conversion in the other direction is not an issue&lt;br /&gt;&lt;br /&gt;2. Disabling primary key constraint will drop the index associated with primary key. Again, when we enable the primary key constraint, it will create the index on the primary key column.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What is the ideal place to use ENABLE NOVALIDATE option?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;In a busy environment, some one disabled the constraint accidently or intentionally, and we have already bad data in that table. Now business requested you to load the new set of data, but business wanted to make sure that new set of data should be validated during the load. At this circumstances, we can use ENABLE NOVALIDATE option. This option will validate the new data and old data will not be validated.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What is the ideal place to use DISABLE VALIDATE option?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;We disabled the constraint for some reason. We do not want to load any data until we fix the issue and enable the constraint. We can use DISABLE VALIDATE option here. This option would not let you load any data when the constraint is disabled.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-855762794868266243?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/855762794868266243/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=855762794868266243' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/855762794868266243'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/855762794868266243'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/constraint-stats.html' title='Constraint stats'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-1370962343103181934</id><published>2009-05-11T16:49:00.000-07:00</published><updated>2009-06-24T10:38:41.099-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='INITIALLY IMMEDIATE'/><category scheme='http://www.blogger.com/atom/ns#' term='INITIALLY DEFERRED'/><category scheme='http://www.blogger.com/atom/ns#' term='deferred constraint'/><category scheme='http://www.blogger.com/atom/ns#' term='SET CONSTRAINTS'/><category scheme='http://www.blogger.com/atom/ns#' term='DEFERRED'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-02091: transaction rolled back'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-02091'/><category scheme='http://www.blogger.com/atom/ns#' term='DEFERRABLE'/><title type='text'>Deferred Constraints</title><content type='html'>Prior to Oracle8i, no way of entering child records without parent records, inserting duplicate records on primary key/unique key columns, deleting parent record before deleting child records. When we enter this kind of orphan records or bad records, it would fail right away and rollback the current transaction. Let us say, we entered records in parent table and entering records in child table which is not existing in parent table. Prior to oracle8i, it will fail and rollback the orphan records in child table. But parent table data will not be rolledback. This would lead into incomplete or partial data load.&lt;br /&gt;&lt;br /&gt;To avoid all these issues, oracle8i introduced deferred constraints. Deferred constraint will let you load the data in reverse order(child first, parent next) and it will validate the data only at the time of commit. The data will be validated at the time of commit and rollback both parent and child at the same time if there is any orphan records. When we reload the same data again, we do not need to manually clean the partial data which we loaded previous time in the table.&lt;br /&gt;&lt;br /&gt;For instance, we have parent table called MASTER and ten different child tables. Child tables are named as CHILD1,CHILD2,CHILD3... CHILD10. First we enter data in MASTER table and entering all the child tables. We are applying commit at the end of data load. Somehow, we entered orphan records in CHILD3 and CHILD7 tables. In regular non deferred constraints, data will be successfully loaded in all the tables except CHILD3 and CHILD7 tables. If we use deferred constraint, all the 11 tables(master and all child) transaction will be rolledback. There will not be any partial data load when we use deferred constraints.&lt;br /&gt;&lt;br /&gt;Another thing, the loading time will be faster when we use deferred constraint. Because, it does not need to validate the constraint at the time of loading.&lt;br /&gt;&lt;br /&gt;By default constraints are created as NON DEFERRABLE but this can be overidden using the DEFERRABLE keyword. If a constraint is created with the DEFERRABLE keyword, then it can act in one of two ways (INITIALLY IMMEDIATE, INITIALLY DEFERRED).&lt;br /&gt;&lt;br /&gt;INITIALLY IMMEDIATE is same as non deferred regular constraint.&lt;br /&gt;INITIALLY DEFERRED is deferred constraint which will validate at the time of commit.&lt;br /&gt;&lt;br /&gt;The below cases are tested in oracle10gR2.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Case1. Let us create the deferred FK constraint and enter the orphan records. Deferred&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;constraint validate at the time of commit and rollback both parent and child. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; CREATE TABLE MASTER(id NUMBER(10));&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; CREATE TABLE child(id NUMBER(10), master_id NUMBER(10));&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; ALTER TABLE master ADD PRIMARY KEY (id);&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; ALTER TABLE child ADD CONSTRAINT fk_master&lt;br /&gt;2 FOREIGN KEY (master_id)&lt;br /&gt;3 REFERENCES master(id)&lt;br /&gt;4 DEFERRABLE&lt;br /&gt;5 INITIALLY DEFERRED;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; INSERT INTO child VALUES(1,2);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; INSERT INTO master VALUES(1);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; COMMIT;&lt;br /&gt;COMMIT&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-02091: transaction rolled back&lt;br /&gt;ORA-02291: integrity constraint (SCOTT.FK_MASTER) violated - parent key not&lt;br /&gt;found&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select * from master;&lt;br /&gt;&lt;br /&gt;no rows selected&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select * from child;&lt;br /&gt;&lt;br /&gt;no rows selected&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Case2. Let us create the deferred FK constraint and delete the parent without deleting child records. At the time of commit, it rollbacks the transaction in child table.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; CREATE TABLE MASTER(id NUMBER(10));&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; CREATE TABLE child(id NUMBER(10), master_id NUMBER(10));&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; ALTER TABLE master ADD PRIMARY KEY (id);&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; ALTER TABLE child ADD CONSTRAINT fk_master&lt;br /&gt;2 FOREIGN KEY (master_id)&lt;br /&gt;3 REFERENCES master(id)&lt;br /&gt;4 DEFERRABLE&lt;br /&gt;5 INITIALLY DEFERRED;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; INSERT INTO child VALUES(1,1);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; INSERT INTO master VALUES(1);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; COMMIT;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; delete master;&lt;br /&gt;&lt;br /&gt;1 row deleted.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; commit;&lt;br /&gt;commit&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-02091: transaction rolled back&lt;br /&gt;ORA-02292: integrity constraint (SCOTT.FK_MASTER) violated - child record found&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select * from master;&lt;br /&gt;&lt;br /&gt;ID&lt;br /&gt;----------&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select * from child;&lt;br /&gt;&lt;br /&gt;ID MASTER_ID&lt;br /&gt;---------- ----------&lt;br /&gt;1 1&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Case3. Let us create deferred primary key and enter the duplicate records.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; create table master(no number);&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; alter table master add constraint pk_master&lt;br /&gt;2 primary key(no)&lt;br /&gt;3 deferrable&lt;br /&gt;4 initially deferred;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; insert into master values(1);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; insert into master values(1);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; insert into master values(2);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; commit;&lt;br /&gt;commit&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-02091: transaction rolled back&lt;br /&gt;ORA-00001: unique constraint (SCOTT.PK_MASTER) violated&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select * from master;&lt;br /&gt;&lt;br /&gt;no rows selected&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we change the constraint from deferred to regular and vice versa?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;We can change the regular constraint to deferred and deferred constraint to regular constraint at the session level as long as the constraint is deferrable.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The below command will change the constraints to deferred/immediate for all the deferrable&lt;br /&gt;constraint at the session level.&lt;br /&gt;&lt;br /&gt;ALTER SESSION SET CONSTRAINTS = DEFERRED;&lt;br /&gt;ALTER SESSION SET CONSTRAINTS = IMMEDIATE;&lt;br /&gt;&lt;br /&gt;We can also change the specfic constraint to deferred/immediate.&lt;br /&gt;&lt;br /&gt;set constraint fk_master deferred;&lt;br /&gt;set constraint fk_master immediate;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What is ideal place to use deferred constraint?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;When we have large volume of transaction involving multiple dependencies, we have a constraint that either load all the dependent tables successfully or rollback all the dependent tables if there is any orphan records. This would be ideal place to use deferred constraints.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-1370962343103181934?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/1370962343103181934/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=1370962343103181934' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1370962343103181934'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1370962343103181934'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/deferred-constraints.html' title='Deferred Constraints'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-6702392997713707932</id><published>2009-05-10T08:03:00.000-07:00</published><updated>2009-06-24T12:01:59.250-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='reverse'/><category scheme='http://www.blogger.com/atom/ns#' term='ideal place to use reverse key index'/><category scheme='http://www.blogger.com/atom/ns#' term='noreverse'/><category scheme='http://www.blogger.com/atom/ns#' term='b-tree index versus reverse key index'/><category scheme='http://www.blogger.com/atom/ns#' term='rebuild reverse'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><category scheme='http://www.blogger.com/atom/ns#' term='Index'/><title type='text'>Reverse key Index</title><content type='html'>Oracle introduced reverse key index to reduce the block contention(buffer busy waits) in index segment. Normal index stores the index column value and rowid in index segment. But reverse key index stores the reverse index column value and rowid. Ofcourse, oracle will not reverse the rowid. So we call this as reverse key index.&lt;br /&gt;&lt;br /&gt;Let us say, the index column value is 1234. It will be converted as 4321 and stores in index segment. 1235 will be converted as 5321 and stored in index segment. In reverse key index, oracle will not store the actual column values in sequentail order. Instead, it reverse the index column value and will be spreaded across many index blocks. This would avoid index block contention.&lt;br /&gt;&lt;br /&gt;Reverse key index would be useful when index column is populating from sequence and concurrent session inserting the data on the table.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;What is ideal place to use Reverse key index?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;1. In a single instance system, multiple sessions are trying to insert/update the index column at the same time, the index column value is extracting from sequence. Also we are deleting the rows and we are not doing any range scan on reverse key index column. This would be ideal place for reverse key index. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;2. In RAC environment, if we have column populated by an increasing numbers, concurrent session inserting the rows from different RAC instance, the index block will have contention between nodes. The data are deleted time to time according to some rules which leave some old data undeleted in the table. Also there is not much range scan on this table. This would be ideal place for reverse key index.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;If we use regular index for above two scenario, during the concurrent insert, oracle stores the index values in the sequence order and it would end up storing multiple sequential index values in the same block. This would lead into block contention when multiple insert happens at the same time with in the same block. Another thing, when we delete the old rows, the block will not be moved to free list until all rows are deleted in that block. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Reverse key index will resolve the above said issues. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;When we use reverse key index, the empty space(empty space would happen when we delete old rows in the table) in the block will be refilled. Because, reverse key index stores the column value in reverse order. &lt;/span&gt;You will be able to use the empty space for different values with reverse key indexes.&lt;br /&gt;&lt;br /&gt;When we use reverse key index, index block contention will be reduced. The reverse key index will scatter the entries accross different blocks during inserting and your many concurrent sessions will not have index block contention issues.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we create reverse key index?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; create index idx_rev&lt;br /&gt;2 on employee(empno) reverse;&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we covert regular index to reverse key index?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;scott@orcl&gt; create index idx_rev on employee(empno);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; alter index idx_rev rebuild reverse;&lt;br /&gt;&lt;br /&gt;Index altered.&lt;br /&gt;&lt;br /&gt;&lt;a href="mailto:scott@orcl"&gt;scott@orcl&lt;/a&gt;&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we covert reverse key index to regular index? &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;scott@ordb&gt; alter index idx_rev rebuild noreverse;&lt;br /&gt;&lt;br /&gt;Index altered.&lt;br /&gt;&lt;br /&gt;scott@ordb&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Restriction on Reverse key index?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Reverse key index does not support range scan. Since the index column values are not stored in the sequential order.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-6702392997713707932?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/6702392997713707932/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=6702392997713707932' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/6702392997713707932'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/6702392997713707932'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/reverse-key-index.html' title='Reverse key Index'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-3695198375633848231</id><published>2009-05-08T21:35:00.000-07:00</published><updated>2009-06-24T17:04:01.158-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='space_error_info'/><category scheme='http://www.blogger.com/atom/ns#' term='after suspend trigger'/><category scheme='http://www.blogger.com/atom/ns#' term='disable resumable'/><category scheme='http://www.blogger.com/atom/ns#' term='dba_resumabe'/><category scheme='http://www.blogger.com/atom/ns#' term='user_resumable'/><category scheme='http://www.blogger.com/atom/ns#' term='space quota exceeded'/><category scheme='http://www.blogger.com/atom/ns#' term='resumable timeout'/><category scheme='http://www.blogger.com/atom/ns#' term='enable resumable'/><category scheme='http://www.blogger.com/atom/ns#' term='dbms_resumable'/><title type='text'>Resumable space allocation</title><content type='html'>Long running operations or batch process would fail due to insufficient space. When job fails, DBA has to allocate the space and restart the job manually. When DBA restarts the job, oracle has to run the job from the scratch again. Oracle9i introduced Resumable space allocation to resolve this kind of issues.&lt;br /&gt;&lt;br /&gt;With this resumable space allocation feature, whenever job fails, it will be suspended until DBA fix the issues and job will be resumed instead of restarting from scratch.&lt;br /&gt;&lt;br /&gt;In oracle9i, resumable space allocation feature must be turned on in the session level using the ALTER SESSION ENABLE RESUMABLE statement. In oracle10g, a new parameter RESUMABLE_TIMEOUT was introduced, where the resumable space allocation feature can be turned on at the database level. The default for this parameter is 0, which means the resumable timeout is not enabled.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Steps to setup Resumable space allocation:&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;&lt;p&gt;Let us assume, we are enabling resumable job allocation for scott user.&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Step1.&lt;/span&gt; &lt;/p&gt;&lt;p&gt;We need to grant RESUMABLE system privileges to schema.&lt;br /&gt;&lt;br /&gt;GRANT RESUMABLE TO SCOTT;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Step2.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;We need to setup the resumable timeout in seconds. The operation will be suspended for specified number of seconds for DBA to fix the problem. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;There are several ways we can set timeout parameter.&lt;br /&gt;&lt;br /&gt;ALTER SESSION ENABLE RESUMABLE TIMEOUT 3600;&lt;/p&gt;EXECUTE Dbms_Resumable.Set_Timeout(3600);&lt;br /&gt;&lt;br /&gt;ALTER SESSION ENABLE RESUMABLE TIMEOUT 3600 NAME 'emp data loading';&lt;br /&gt;&lt;br /&gt;&lt;p&gt;We can set RESUMABLE_TIMEOUT parameter in init parameter file. This new parameter was introduced in oracle10g. Resumable space allocation feature will be disabled automatically when RESUMABLE_TIMEOUT parameter is zero. We can set this parameter in session level as well as database level.&lt;/p&gt;&lt;p&gt;alter session set resumable_timeout=3600;&lt;br /&gt;alter system set resumable_timeout=3600;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;What kind of issues can be suspended in resumable space allocation?&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Out of space:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;We have an out of space error when we can not get any more extents for various database objects in a tablespace.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Maximum extents reached:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;Number of extents are exceeded the maximum extents which we specified for the object.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Space Quota Exceeded:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;User exceeds the space quota for the tablespace. when we create the user, we set the space quota. Operation will be suspended when user exceeds the space quota on tablespace.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;What kind of operations can fall into resumable space allocation?&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;1. Queries that run out of temporary space for sorting.&lt;br /&gt;2. DML Insert, update statement&lt;br /&gt;3. DDL Create table as select, alter table, create index, alter index,&lt;br /&gt;create materialized view, create materialized view log etc&lt;br /&gt;4. Import/export&lt;br /&gt;5. SQL Loader&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Let us test resumable space allocation on scott schema. The below PLSQL code runs without resumable space allocation. When we run this code, it is failed right away....&lt;/span&gt;&lt;/p&gt;&lt;p&gt;scott@orcl&gt; alter session set resumable_timeout=0;&lt;br /&gt;&lt;br /&gt;Session altered.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; begin&lt;br /&gt;2 for i in 1 .. 5000&lt;br /&gt;3 loop&lt;br /&gt;4 insert into employee&lt;br /&gt;5 select * from employee;&lt;br /&gt;6 commit;&lt;br /&gt;7 end loop;&lt;br /&gt;8 end;&lt;br /&gt;9 /&lt;br /&gt;begin&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-01653: unable to extend table SCOTT.EMPLOYEE by 8 in tablespace USERSPACE&lt;br /&gt;ORA-06512: at line 4&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Let us test the same code with resumable space allocation. Now i set the timeout parmeter 60 seconds. The session suspends for 60 seconds and throw error. Since we did not fix the error during the 60 seconds.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="mailto:scott@orcl"&gt;scott@orcl&lt;/a&gt;&gt; alter session set resumable_timeout=60;&lt;br /&gt;&lt;br /&gt;Session altered.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; set time on&lt;br /&gt;11:37:24 scott@orcl&gt;&lt;br /&gt;11:37:24 scott@orcl&gt; begin&lt;br /&gt;11:37:24 2 for i in 1 .. 5000&lt;br /&gt;11:37:24 3 loop&lt;br /&gt;11:37:24 4 insert into employee&lt;br /&gt;11:37:24 5 select * from employee;&lt;br /&gt;11:37:24 6 commit;&lt;br /&gt;11:37:24 7 end loop;&lt;br /&gt;11:37:24 8 end;&lt;br /&gt;11:37:24 9 /&lt;br /&gt;begin&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-30032: the suspended (resumable) statement has timed out&lt;br /&gt;ORA-01653: unable to extend table SCOTT.EMPLOYEE by 8 in tablespace USERSPACE&lt;br /&gt;ORA-06512: at line 4&lt;br /&gt;&lt;br /&gt;11:38:26 scott@orcl&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Let us test the same PLSQL code with higher timeout seconds. Let me set 1000 seconds.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="mailto:scott@orcl"&gt;scott@orcl&lt;/a&gt;&gt; ALTER SESSION ENABLE RESUMABLE TIMEOUT 1000 NAME 'emp data loading';&lt;br /&gt;&lt;br /&gt;Session altered.&lt;/p&gt;&lt;p&gt;&lt;a href="mailto:scott@orcl"&gt;scott@orcl&lt;/a&gt;&gt; begin&lt;br /&gt;2 for i in 1 .. 10&lt;br /&gt;3 loop&lt;br /&gt;4 insert into employee&lt;br /&gt;5 select * from employee;&lt;br /&gt;6 commit;&lt;br /&gt;7 end loop;&lt;br /&gt;8 end;&lt;br /&gt;9 /&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;The above PLSQL procedure is hanging... Let me connect another session and check the status.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="mailto:scott@orcl"&gt;scott@orcl&lt;/a&gt;&gt; connect scott/tiger@orcl&lt;br /&gt;Connected.&lt;br /&gt;system@orcl&gt; select name,sql_text,status,error_msg from dba_resumable;&lt;br /&gt;&lt;br /&gt;NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;SQL_TEXT&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;STATUS&lt;br /&gt;---------&lt;br /&gt;ERROR_MSG&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;emp data loading&lt;br /&gt;INSERT INTO EMPLOYEE SELECT * FROM EMPLOYEE&lt;br /&gt;SUSPENDED&lt;br /&gt;ORA-01653: unable to extend table SCOTT.EMPLOYEE by 8 in tablespace USERSPACE&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;It seems like, the session is suspended and waiting the space to load the data. Let me connect in another session and increase the space for the tablespace.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="mailto:system@orcl"&gt;system@orcl&lt;/a&gt;&gt; connect system/password@orcl&lt;br /&gt;Connected.&lt;br /&gt;system@orcl&gt; alter database datafile&lt;br /&gt;2 'C:\ORACLE\PRODUCT\10.1.0\ORADATA\ORCL\USERSPACE.DBF' resize 1000M;&lt;br /&gt;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;br /&gt;system@orcl&gt; &lt;/p&gt;&lt;p&gt;Again i will check the status of this job.&lt;/p&gt;&lt;p&gt;&lt;a href="mailto:scott@orcl"&gt;scott@orcl&lt;/a&gt;&gt; connect scott/tiger@orcl&lt;br /&gt;Connected.&lt;br /&gt;&lt;span style="color:#000000;"&gt;scott@orcl&gt; select name,sql_text,status,error_msg from dba_resumable;&lt;br /&gt;&lt;br /&gt;NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;SQL_TEXT&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;STATUS&lt;br /&gt;---------&lt;br /&gt;ERROR_MSG&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;User SCOTT(57), Session 132, Instance 1&lt;br /&gt;INSERT INTO EMPLOYEE SELECT * FROM EMPLOYEE&lt;br /&gt;NORMAL&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;As per the above query, the status is back to normal. It means, the job is resumed. The error message is disappeared.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Again i went back and checked the job. The job is also successfully completed after increasing the space.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="mailto:scott@orcl"&gt;scott@orcl&lt;/a&gt;&gt; begin&lt;br /&gt;2 for i in 1 .. 10&lt;br /&gt;3 loop&lt;br /&gt;4 insert into employee&lt;br /&gt;5 select * from employee;&lt;br /&gt;6 commit;&lt;br /&gt;7 end loop;&lt;br /&gt;8 end;&lt;br /&gt;9 /&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;&lt;a href="mailto:scott@orcl"&gt;scott@orcl&lt;/a&gt;&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Usage of AFTER SUSPEND TRIGGER:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;It is impossible to check the suspended operations manually every time. Also suspended operation will not produce any error message. &lt;/span&gt;We can write the AFTER SUSPEND trigger to capture the suspended operations as well as error message. In AFTER SUSPEND trigger, we can write a code by using DBMS_SMTP package to notify DBA about suspended operations. We can also write the error message in log table by using autonomous transactions.&lt;/p&gt;&lt;p&gt;Here is the sample AFTER SUSPEND trigger skeleton.&lt;/p&gt;&lt;p&gt;CREATE OR REPLACE TRIGGER suspended_operations&lt;br /&gt;AFTER SUSPEND&lt;br /&gt;ON DATABASE&lt;br /&gt;DECLARE&lt;br /&gt;-- Declare any variables&lt;br /&gt;BEGIN&lt;br /&gt;-- Alter default timeout period.&lt;br /&gt;Dbms_Resumable.Set_Timeout(3600);&lt;br /&gt;-- Capture the error message into log table&lt;br /&gt;-- Send email/page to DBA to make corrective action&lt;br /&gt;END;&lt;br /&gt;/ &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;How do we see which operations are suspended in the database?&lt;/span&gt;&lt;/p&gt;&lt;p&gt;a) We can check the alert log&lt;br /&gt;b) We can view USER_RESUMABLE or DBA_RESUMABLE &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Resumable space parameters in imp/exp, SQL Loader:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;We can use these below parameters to suspend the (SQL Loader, imp/exp) data load if there is space failure.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;RESUMABLE suspend when a space related error is encountered(N)&lt;br /&gt;RESUMABLE_NAME text string used to identify resumable statement&lt;br /&gt;RESUMABLE_TIMEOUT wait time for RESUMABLE &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;DBMS_RESUMABLE Package: This package is created for managing resumable space. SYS user should grant execute privileges to other schema to use this package.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;ABORT(sessionID) - Ends the specified suspended session. Caller must be the owner of the session with sessionID, have ALTER SYSTEM privilege, or have DBA privileges. &lt;/p&gt;&lt;p&gt;GET_SESSION_TIMEOUT(sessionID) - Returns the timeout period in seconds for the specified session, or -1 if the session does not exist. &lt;/p&gt;&lt;p&gt;SET_SESSION_TIMEOUT(sessionID, timeout) - Sets the timeout in seconds of the specified session with immediate effect. &lt;/p&gt;&lt;p&gt;GET_TIMEOUT() - Returns the timeout period in seconds for the current session. &lt;/p&gt;&lt;p&gt;SET_TIMEOUT(timeout) - Sets the timeout in seconds of the current session with immediate effect. &lt;/p&gt;&lt;p&gt;DBMS_RESUMABLE.SPACE_ERROR_INFO(...) - Returns information about the space error when called from within an AFTER SUSPEND trigger. &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Note : &lt;/span&gt;&lt;span style="color:#000000;"&gt;We use the below command to enable or disable resumable space allocation in oracle9i.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;alter session enable resumable&lt;br /&gt;alter session disable resumable&lt;/p&gt;&lt;p&gt;But in oracle10g, we do not need to use these command to enable or disable resumable allocation. Oracle10g introduced new parameter RESUMABLE_TIMEOUT, we use this parameter to enable or disable resumable space allocation.&lt;/p&gt;&lt;p&gt;alter session set resumable_timeout = 0 (Disable resumable space allocation)&lt;br /&gt;alter session set resumable_timeout = 60 (enable resumable space allocation)&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-3695198375633848231?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/3695198375633848231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=3695198375633848231' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/3695198375633848231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/3695198375633848231'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/resumable-space-allocation.html' title='Resumable space allocation'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-3119070930649078273</id><published>2009-05-06T06:09:00.000-07:00</published><updated>2009-06-25T08:08:43.718-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ORA-08182'/><category scheme='http://www.blogger.com/atom/ns#' term='flashback_transaction_query'/><category scheme='http://www.blogger.com/atom/ns#' term='flashback version query'/><category scheme='http://www.blogger.com/atom/ns#' term='BIN$'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-01466'/><category scheme='http://www.blogger.com/atom/ns#' term='dbms_flashback.enable_at_time'/><category scheme='http://www.blogger.com/atom/ns#' term='flashback query'/><category scheme='http://www.blogger.com/atom/ns#' term='dbms_flashback.enable_at_system_change_number'/><category scheme='http://www.blogger.com/atom/ns#' term='dbms_flashback.disable'/><title type='text'>Flash Back Query</title><content type='html'>Oracle9i introduced Flashback query feature. Oracle Flashback Query allows users to see a consistent view of the database as it was at a point in the past. We can use SCN or TIMESTAMP to read the past data. Oracle10g went one step further and introduced two new features on top of flashback query feature. Here are the use of flash back query feature......&lt;br /&gt;&lt;br /&gt;1. Recover the lost data or undoing incorrect commit.&lt;br /&gt;2. Comparing the current data with corresponding data in the past.&lt;br /&gt;&lt;br /&gt;Let us talk about below three topics on this article. The below code in this thread is successfully tested in oracle10gR2.&lt;br /&gt;&lt;br /&gt;1. Flashback query(Oracle9i feature)&lt;br /&gt;2. Flashback version query(Oracle10g feature)&lt;br /&gt;3. Flashback transaction query(Oracle10g feature)&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Prerequisite to use Flash back query freature..&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. Automatic UNDO managment should be enabled. The following init parameter should be set.&lt;br /&gt;&lt;br /&gt;UNDO_MANAGEMENT = AUTO&lt;br /&gt;UNDO_TABLESPACE = undotablespace_name&lt;br /&gt;UNDO_RETENTION = n&lt;br /&gt;&lt;br /&gt;2. We need to grant below privilege to schema where we are using this feature. Let us assume, we are using scott schema.&lt;br /&gt;&lt;br /&gt;grant execute on dbms_flashback to scott;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Flashback Query&lt;/strong&gt;(Oracle9i feature)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Flashback query can be enabled or disabled by using dbms_flashback package. We can flashback by using SCN or specific time.&lt;/span&gt; Flashback query feature will allow users to see the data on specific time or SCN in the past.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario 1 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Let us use the timestamp and display the past data...&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;scott@orcl&gt; ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'DD-MON-YYYY HH24:MI:SS';&lt;br /&gt;&lt;br /&gt;Session altered.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; create table flashback as select * from user_objects&lt;br /&gt;2 where rownum &lt;6;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;&lt;a href="mailto:scott@orcl"&gt;scott@orcl&lt;/a&gt;&gt; select object_name from flashback;&lt;br /&gt;&lt;br /&gt;OBJECT_NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;AUDITLOG&lt;br /&gt;AUDIT_SEQ&lt;br /&gt;CUSTOMERS_SEQ&lt;br /&gt;DEPT&lt;br /&gt;DEPT1&lt;br /&gt;&lt;br /&gt;10:58:59 scott@orcl&gt; update flashback set object_name=lower(object_name);&lt;br /&gt;&lt;br /&gt;5 rows updated.&lt;br /&gt;&lt;br /&gt;10:59:14 scott@orcl&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;10:59:17 scott@orcl&gt; select object_name from flashback;&lt;br /&gt;&lt;br /&gt;OBJECT_NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;auditlog&lt;br /&gt;audit_seq&lt;br /&gt;customers_seq&lt;br /&gt;dept&lt;br /&gt;dept1&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; SELECT OBJECT_NAME from flashback AS OF&lt;br /&gt;2 TIMESTAMP TO_TIMESTAMP('06-MAY-2009 10:58:26');&lt;br /&gt;&lt;br /&gt;OBJECT_NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;AUDITLOG&lt;br /&gt;AUDIT_SEQ&lt;br /&gt;CUSTOMERS_SEQ&lt;br /&gt;DEPT&lt;br /&gt;DEPT1&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Recovering data based on specific SCN in the past...&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;scott@orcl&gt; select current_scn from v$database;&lt;br /&gt;&lt;br /&gt;CURRENT_SCN&lt;br /&gt;-----------&lt;br /&gt;19215382&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; create table flashback as select * from user_objects&lt;br /&gt;2 where rownum &lt;6;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select current_scn from v$database;&lt;br /&gt;&lt;br /&gt;CURRENT_SCN&lt;br /&gt;-----------&lt;br /&gt;19215408&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select * from flashback;&lt;br /&gt;&lt;br /&gt;OBJECT_NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;AUDITLOG&lt;br /&gt;AUDIT_SEQ&lt;br /&gt;BIN$IDl5ashFQMqE8ctrWU8K8Q==$0&lt;br /&gt;BIN$dld0GhwqRlO4sMnrYyAKgQ==$0&lt;br /&gt;CUSTOMERS_SEQ&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; update flashback set object_name=lower(object_name);&lt;br /&gt;&lt;br /&gt;5 rows updated.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select * from flashback as of scn 19215382;&lt;br /&gt;select * from flashback as of scn 19215382&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-01466: unable to read data - table definition has changed&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select * from flashback as of scn 19215408;&lt;br /&gt;&lt;br /&gt;OBJECT_NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;AUDITLOG&lt;br /&gt;AUDIT_SEQ&lt;br /&gt;BIN$IDl5ashFQMqE8ctrWU8K8Q==$0&lt;br /&gt;BIN$dld0GhwqRlO4sMnrYyAKgQ==$0&lt;br /&gt;CUSTOMERS_SEQ&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select * from flashback;&lt;br /&gt;&lt;br /&gt;OBJECT_NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;auditlog&lt;br /&gt;audit_seq&lt;br /&gt;bin$idl5ashfqmqe8ctrwu8k8q==$0&lt;br /&gt;bin$dld0ghwqrlo4smnryyakgq==$0&lt;br /&gt;customers_seq&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Note : when we enable flashback query, we provide either a timestamp or SCN. Timestamp is mapped to an SCN number every five minutes, the SCN offers a much finer level of precision for flashback.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario 3&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;We can use the explicit cursor to read the past data by using flashback query feature.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;scott@orcl&gt; create table flashback as select * from user_objects&lt;br /&gt;2 where rownum &lt;11;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; SELECT current_scn, TO_CHAR(SYSTIMESTAMP, 'YYYY-MM-DD HH24:MI:SS') FROM v$database;&lt;br /&gt;&lt;br /&gt;CURRENT_SCN&lt;br /&gt;-----------&lt;br /&gt;TO_CHAR(SYSTIMESTAMP,'YYYY-MM-&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;19218732&lt;br /&gt;2009-05-06 12:15:58&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;11:36:52 scott@orcl&gt; delete flashback;&lt;br /&gt;&lt;br /&gt;10 rows deleted.&lt;br /&gt;&lt;br /&gt;11:37:10 scott@orcl&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;11:37:11 scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;I deleted the flashback table around 11.37AM. Now i wanted to revert the data through PLSQL cursor by using SCN or TIMESTAMP.&lt;br /&gt;&lt;br /&gt;The below example reading through Timestamp.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; declare&lt;br /&gt;cursor c1 is select * from flashback;&lt;br /&gt;emprec c1%rowtype;&lt;br /&gt;begin&lt;br /&gt;dbms_flashback.enable_at_time('06-MAY-2009 11:36:52');&lt;br /&gt;OPEN C1;&lt;br /&gt;DBMS_FLASHBACK.DISABLE;&lt;br /&gt;LOOP&lt;br /&gt;FETCH c1 into emprec;&lt;br /&gt;exit when c1%notfound;&lt;br /&gt;insert into flashback(OBJECT_NAME)&lt;br /&gt;values(emprec.object_name);&lt;br /&gt;end loop;&lt;br /&gt;close c1;&lt;br /&gt;commit;&lt;br /&gt;end;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; SELECT * FROM FLASHBACK;&lt;br /&gt;&lt;br /&gt;OBJECT_NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;AUDITLOG&lt;br /&gt;AUDIT_SEQ&lt;br /&gt;BIN$EkjOJm2AS66HXzkrAueJiA==$0&lt;br /&gt;BIN$IDl5ashFQMqE8ctrWU8K8Q==$0&lt;br /&gt;BIN$YUw9dPZ5SueBF5RDCMLJIQ==$0&lt;br /&gt;BIN$dld0GhwqRlO4sMnrYyAKgQ==$0&lt;br /&gt;CUSTOMERS_SEQ&lt;br /&gt;DEPT&lt;br /&gt;DEPT1&lt;br /&gt;DO_SOMETHING&lt;br /&gt;&lt;br /&gt;10 rows selected.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;The below example reading flashback data through SCN.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; declare&lt;br /&gt;cursor c1 is select * from flashback;&lt;br /&gt;emprec c1%rowtype;&lt;br /&gt;begin&lt;br /&gt;dbms_flashback.Enable_At_System_Change_Number(19218732);&lt;br /&gt;OPEN C1;&lt;br /&gt;DBMS_FLASHBACK.DISABLE;&lt;br /&gt;LOOP&lt;br /&gt;FETCH c1 into emprec;&lt;br /&gt;exit when c1%notfound;&lt;br /&gt;insert into flashback(OBJECT_NAME)&lt;br /&gt;values(emprec.object_name);&lt;br /&gt;end loop;&lt;br /&gt;close c1;&lt;br /&gt;commit;&lt;br /&gt;end;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select * from flashback;&lt;br /&gt;&lt;br /&gt;OBJECT_NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;AUDITLOG&lt;br /&gt;AUDIT_SEQ&lt;br /&gt;BIN$EkjOJm2AS66HXzkrAueJiA==$0&lt;br /&gt;BIN$IDl5ashFQMqE8ctrWU8K8Q==$0&lt;br /&gt;BIN$YUw9dPZ5SueBF5RDCMLJIQ==$0&lt;br /&gt;BIN$dld0GhwqRlO4sMnrYyAKgQ==$0&lt;br /&gt;CUSTOMERS_SEQ&lt;br /&gt;DEPT&lt;br /&gt;DEPT1&lt;br /&gt;DO_SOMETHING&lt;br /&gt;&lt;br /&gt;10 rows selected.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Note: We can not do any operation in the database when database is in Flashback mode.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; declare&lt;br /&gt;cursor c1 is select * from flashback;&lt;br /&gt;emprec c1%rowtype;&lt;br /&gt;begin&lt;br /&gt;dbms_flashback.Enable_At_System_Change_Number(19218732);&lt;br /&gt;OPEN C1;&lt;br /&gt;--DBMS_FLASHBACK.DISABLE;&lt;br /&gt;LOOP&lt;br /&gt;FETCH c1 into emprec;&lt;br /&gt;exit when c1%notfound;&lt;br /&gt;insert into flashback(OBJECT_NAME)&lt;br /&gt;values(emprec.object_name);&lt;br /&gt;end loop;&lt;br /&gt;close c1;&lt;br /&gt;commit;&lt;br /&gt;end;&lt;br /&gt;/&lt;br /&gt;declare&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-08182: operation not supported while in Flashback mode&lt;br /&gt;ORA-06512: at line 11&lt;br /&gt;&lt;br /&gt;So far, we have seen oracle9i features. Oracle9i has ability to read the past data by using SCN or timestamp. But oracle10g has gone one step further and has ability to read the past data for specific time window. This feature is called as flashback version query. Also oracle10g can get extra information about the transactions listed by flashback version queries.&lt;br /&gt;&lt;br /&gt;As a summary, oracle10g introduced two new features on top of flashback query (which is introduced in oracle9i).&lt;br /&gt;&lt;br /&gt;1. Flashback version query&lt;br /&gt;2. Flashback transaction query&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Flashback Version query&lt;/strong&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;(Oracle10g feature)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;span style="color:#000000;"&gt;Flashback version query display the past data on specific time window. This feature helps to find the detail level data changes during that window. Here i created table and apply three transaction. At the end, we are able to display all the changes made by the transaction during that time period.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;scott@orcl&gt; create table flashversion(name varchar2(20));&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;scott@orcl&gt; SELECT TO_CHAR(SYSTIMESTAMP, 'YYYY-MM-DD HH24:MI:SS') FROM v$database;&lt;br /&gt;&lt;br /&gt;TO_CHAR(SYSTIMESTAMP,'YYYY-MM-&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;2009-05-08 09:07:59&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; insert into flashversion values('SCOTT');&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; update flashversion set name='MANI';&lt;br /&gt;&lt;br /&gt;1 row updated.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; update flashversion set name='JANI';&lt;br /&gt;&lt;br /&gt;1 row updated.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; SELECT TO_CHAR(SYSTIMESTAMP, 'YYYY-MM-DD HH24:MI:SS') FROM v$database;&lt;br /&gt;&lt;br /&gt;TO_CHAR(SYSTIMESTAMP,'YYYY-MM-&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;2009-05-08 09:09:22&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; SELECT versions_starttime,&lt;br /&gt;2 name&lt;br /&gt;3 FROM flashversion&lt;br /&gt;4 VERSIONS BETWEEN TIMESTAMP TO_TIMESTAMP('2009-05-08 09:07:59', 'YYYY-MM-DD HH24:MI:SS')&lt;br /&gt;5 AND TO_TIMESTAMP('2009-05-08 09:09:22', 'YYYY-MM-DD HH24:MI:SS');&lt;br /&gt;&lt;br /&gt;VERSIONS_STARTTIME&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;NAME&lt;br /&gt;--------------------&lt;br /&gt;08-MAY-09 09.09.15 AM&lt;br /&gt;JANI&lt;br /&gt;&lt;br /&gt;08-MAY-09 09.08.41 AM&lt;br /&gt;MANI&lt;br /&gt;&lt;br /&gt;08-MAY-09 09.08.07 AM&lt;br /&gt;SCOTT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We can use the below flashback pseudo columns with above query.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;VERSIONS_STARTSCN&lt;/span&gt; =&gt; Starting SCN when row took on this value&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;VERSIONS_STARTTIME &lt;/span&gt;=&gt; Starting TIMESTAMP when row took on this value&lt;br /&gt;&lt;br /&gt;Note : The value of NULL is returned if the row was created before the lower bound SCN or TIMESTAMP.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;VERSIONS_ENDSCN&lt;/span&gt; =&gt; Ending SCN when row last contained this value&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;VERSIONS_ENDTIME &lt;/span&gt;=&gt; Ending TIMESTAMP when row last contained this value&lt;br /&gt;&lt;br /&gt;Note : The value of NULL is returned if the value of the row is still current at the upper bound SCN or TIMESTAMP.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;VERSIONS_XID&lt;/span&gt; =&gt; ID of the transaction that created the row in it's current state.&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;VERSIONS_OPERATION&lt;/span&gt; =&gt; Operation performed by the transaction ((I)nsert, (U)pdate or (D)elete)&lt;br /&gt;&lt;br /&gt;Here is the query with all the pseudo column&lt;br /&gt;&lt;br /&gt;SELECT&lt;br /&gt;versions_startscn,&lt;br /&gt;versions_starttime,&lt;br /&gt;versions_endscn,&lt;br /&gt;versions_endtime,&lt;br /&gt;versions_xid,&lt;br /&gt;versions_operation,&lt;br /&gt;name&lt;br /&gt;FROM flashversion&lt;br /&gt;VERSIONS BETWEEN&lt;br /&gt;TIMESTAMP TO_TIMESTAMP('2009-05-08 09:07:59', 'YYYY-MM-DD HH24:MI:SS')&lt;br /&gt;AND TO_TIMESTAMP('2009-05-08 09:09:22', 'YYYY-MM-DD HH24:MI:SS');&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Flashback Transaction Query&lt;/strong&gt;(Oracle10g feature)&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Flashback transaction query can be used to get extra information about the transactions listed by flashback version queries. The VERSIONS_XID column values from a flashback version query can be used to query the FLASHBACK_TRANSACTION_QUERY view like:&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; SELECT versions_xid,name&lt;br /&gt;2 name&lt;br /&gt;3 FROM flashversion&lt;br /&gt;4 VERSIONS BETWEEN&lt;br /&gt;5 TIMESTAMP TO_TIMESTAMP('2009-05-08 09:07:59', 'YYYY-MM-DD HH24:MI:SS')&lt;br /&gt;6 AND TO_TIMESTAMP('2009-05-08 09:09:22', 'YYYY-MM-DD HH24:MI:SS');&lt;br /&gt;&lt;br /&gt;VERSIONS_XID NAME&lt;br /&gt;---------------- --------------------&lt;br /&gt;010010007B0D0000 JANI&lt;br /&gt;030028003A110000 MANI&lt;br /&gt;01002E007B0D0000 SCOTT&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; connect sys/password@orcl as sysdba&lt;br /&gt;Connected.&lt;br /&gt;sys@orcl&gt; SELECT undo_sql&lt;br /&gt;2 FROM flashback_transaction_query&lt;br /&gt;3 WHERE xid = HEXTORAW('010010007B0D0000');&lt;br /&gt;&lt;br /&gt;UNDO_SQL&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;update "SCOTT"."FLASHVERSION" set "NAME" = 'MANI' where ROWID = 'AAANPLAAEAAAGOlAAA';&lt;br /&gt;&lt;br /&gt;sys@orcl&gt; SELECT undo_sql&lt;br /&gt;2 FROM flashback_transaction_query&lt;br /&gt;3 WHERE xid = HEXTORAW('030028003A110000');&lt;br /&gt;&lt;br /&gt;UNDO_SQL&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;update "SCOTT"."FLASHVERSION" set "NAME" = 'SCOTT' where ROWID = 'AAANPLAAEAAAGOlAAA';&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Flashback_transaction_query &lt;/span&gt;&lt;span style="color:#000000;"&gt;is a view which is belonging to sys schema. If you need to access from different schema, then you need to grant necessary privileges to other schema. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here is the query content for flashback_transaction_query view.&lt;br /&gt;&lt;br /&gt;CREATE OR REPLACE FORCE VIEW SYS.FLASHBACK_TRANSACTION_QUERY&lt;br /&gt;(XID,&lt;br /&gt;START_SCN,&lt;br /&gt;START_TIMESTAMP,&lt;br /&gt;COMMIT_SCN,&lt;br /&gt;COMMIT_TIMESTAMP,&lt;br /&gt;LOGON_USER,&lt;br /&gt;UNDO_CHANGE#,&lt;br /&gt;OPERATION,&lt;br /&gt;TABLE_NAME,&lt;br /&gt;TABLE_OWNER,&lt;br /&gt;ROW_ID,&lt;br /&gt;UNDO_SQL&lt;br /&gt;)&lt;br /&gt;AS&lt;br /&gt;SELECT xid,&lt;br /&gt;start_scn,&lt;br /&gt;start_timestamp,&lt;br /&gt;DECODE (commit_scn,&lt;br /&gt;0, commit_scn,&lt;br /&gt;281474976710655, NULL,&lt;br /&gt;commit_scn)&lt;br /&gt;commit_scn,&lt;br /&gt;commit_timestamp,&lt;br /&gt;logon_user,&lt;br /&gt;undo_change#,&lt;br /&gt;operation,&lt;br /&gt;table_name,&lt;br /&gt;table_owner,&lt;br /&gt;row_id,&lt;br /&gt;undo_sql&lt;br /&gt;FROM sys.x$ktuqqry;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-3119070930649078273?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/3119070930649078273/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=3119070930649078273' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/3119070930649078273'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/3119070930649078273'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/flash-back-query.html' title='Flash Back Query'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-6872877358301210492</id><published>2009-05-04T13:47:00.000-07:00</published><updated>2009-06-24T19:17:17.823-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='show recyclebin'/><category scheme='http://www.blogger.com/atom/ns#' term='purge tablespace'/><category scheme='http://www.blogger.com/atom/ns#' term='user_recyclebin'/><category scheme='http://www.blogger.com/atom/ns#' term='PURGE'/><category scheme='http://www.blogger.com/atom/ns#' term='v$version'/><category scheme='http://www.blogger.com/atom/ns#' term='purge recyclebin'/><category scheme='http://www.blogger.com/atom/ns#' term='purge dba_recyclebin'/><category scheme='http://www.blogger.com/atom/ns#' term='flashback table to before drop'/><category scheme='http://www.blogger.com/atom/ns#' term='purge index'/><category scheme='http://www.blogger.com/atom/ns#' term='Recyclebin'/><title type='text'>Recyclebin</title><content type='html'>Flashback drop table is one of the awesome feature in oracle10g. Flashback query feature was introduced in oracle9i and we were able to read the past data by using timestamp or SCN for existing table in database. Oracle9i flashback query does not have the ability to recover the dropped tables. But oracle10g introduced a flashback drop feature to recover the dropped tables.&lt;br /&gt;&lt;br /&gt;Oracle10g introduced recyclebin to keep the dropped tables for longer time subject to space.&lt;br /&gt;&lt;br /&gt;When recyclebin is enabled, any table you drop will not get dropped. Instead, it will rename the dropped tables and dependent object to system generated name that starts with BIN$.&lt;br /&gt;&lt;br /&gt;Recyclebin is a logical structure within each tablespace that holds dropped tables and dependent object to that table. Dependent objects are index, triggers, constraints, LOB segments, nested_tables etc. The space associated with the dropped table is not immediately available, but shows up the DBA_FREE_SPACE. Free space in the tablespace that is not occupied by dropped tables. When space pressure occurs in the tablespace, objects in the recyclebin are deleted in First-in first-out(FIFO) fashion.&lt;br /&gt;&lt;br /&gt;The dropped object still belongs to the owner and still counts againts the quota for the owner in the tablespace.&lt;br /&gt;&lt;br /&gt;As long as a tablespace has no space pressure, dropped objects are available indefinitely for recovery. Dropped objects are removed automatically when there is a space pressure. Also dropped objects can be removed manually by PURGE command.&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;This article is tested on Oracle10g version.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;Let us test the recyclebin features as multiple scenario.&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario 1&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Here table is created with dependent objects(index, primary key, trigger, constraints, LOB segments, nested_tables etc). Let us drop the table and recover using recyclebin. When we recover this table, the dependent objects are also recovered. But the dependent object names never changed to original names.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;  create table flashdrop as&lt;br /&gt;  2  select * from user_tables&lt;br /&gt;  3  where rownum &lt; 6;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;&lt;a href="mailto:scott@orcl"&gt;scott@orcl&lt;/a&gt;&gt; alter table flashdrop&lt;br /&gt;2 add primary key(table_name);&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; create index idxx on flashdrop(tablespace_name);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; create trigger trg_flashdrop&lt;br /&gt;2 before insert on flashdrop&lt;br /&gt;3 for each row&lt;br /&gt;4 begin&lt;br /&gt;5 null;&lt;br /&gt;6 end;&lt;br /&gt;7 /&lt;br /&gt;&lt;br /&gt;Trigger created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select count(*) from flashdrop;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;5&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; drop table flashdrop;&lt;br /&gt;&lt;br /&gt;Table dropped.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; show recyclebin&lt;br /&gt;ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME&lt;br /&gt;---------------- ------------------------------ ------------ -------------------&lt;br /&gt;FLASHDROP BIN$jmJpbe5kSqOynybZkA+yfg==$0 TABLE 2009-05-04:18:37:20&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select object_name,original_name from recyclebin;&lt;br /&gt;&lt;br /&gt;OBJECT_NAME ORIGINAL_NAME&lt;br /&gt;------------------------------ --------------------------------&lt;br /&gt;BIN$WcPD/4MlRLayVzQi3x/Vzw==$0 SYS_C005982&lt;br /&gt;BIN$gXTgHi0nQPidAxbnCx5b+w==$0 TRG_FLASHDROP&lt;br /&gt;BIN$jmJpbe5kSqOynybZkA+yfg==$0 FLASHDROP&lt;br /&gt;BIN$4sBW2ND1RYmDYs3JerZodA==$0 IDXX&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; flashback table flashdrop to before drop;&lt;br /&gt;&lt;br /&gt;Flashback complete.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select count(*) from flashdrop;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;5&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; show recyclebin&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select object_name,original_name from recyclebin;&lt;br /&gt;&lt;br /&gt;no rows selected&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select constraint_name from&lt;br /&gt;2 user_constraints where table_name='FLASHDROP';&lt;br /&gt;&lt;br /&gt;CONSTRAINT_NAME&lt;br /&gt;------------------------------&lt;br /&gt;BIN$OIrKaH31R+WaqLWxgMWBQw==$0&lt;br /&gt;BIN$lWD5jjLRQjacvAJJN6i0pQ==$0&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select trigger_name from user_triggers&lt;br /&gt;2 where table_name='FLASHDROP';&lt;br /&gt;&lt;br /&gt;TRIGGER_NAME&lt;br /&gt;------------------------------&lt;br /&gt;BIN$gXTgHi0nQPidAxbnCx5b+w==$0&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select index_name from user_indexes&lt;br /&gt;2 where table_name='FLASHDROP';&lt;br /&gt;&lt;br /&gt;INDEX_NAME&lt;br /&gt;------------------------------&lt;br /&gt;BIN$WcPD/4MlRLayVzQi3x/Vzw==$0&lt;br /&gt;BIN$4sBW2ND1RYmDYs3JerZodA==$0&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Tables can be dropped and recovered with different name. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;create table flashdrop as&lt;br /&gt;  2  select * from user_tables&lt;br /&gt;  3  where rownum &lt; 6;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;  &lt;br /&gt;scott@orcl&gt; select count(*) from flashdrop;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;5&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; drop table flashdrop;&lt;br /&gt;&lt;br /&gt;Table dropped.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; flashback table flashdrop to before drop&lt;br /&gt;2 rename to old_flashdrop;&lt;br /&gt;&lt;br /&gt;Flashback complete.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select count(*) from flashdrop;&lt;br /&gt;select count(*) from flashdrop&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-00942: table or view does not exist&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select count(*) from old_flashdrop;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;5&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario 3&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;The recyclebin may contain several versions of a dropped object. Oracle restores them in LIFO order. It restores most recent version of dropped object. We can restore older versions by repeatedly restoring until you get the version you want, or by using the correct version's BIN$... name directly.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;create table flashdrop as&lt;br /&gt;  2  select * from user_tables&lt;br /&gt;  3  where rownum &lt; 6;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; drop table flashdrop;&lt;br /&gt;&lt;br /&gt;Table dropped.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;create table flashdrop as&lt;br /&gt;  2  select * from user_tables&lt;br /&gt;  3  where rownum &lt; 6;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; drop table flashdrop;&lt;br /&gt;&lt;br /&gt;Table dropped.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;create table flashdrop as&lt;br /&gt;  2  select * from user_tables&lt;br /&gt;  3  where rownum &lt; 6;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; drop table flashdrop;&lt;br /&gt;&lt;br /&gt;Table dropped.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select object_name, original_name,droptime&lt;br /&gt;2 from recyclebin;&lt;br /&gt;&lt;br /&gt;OBJECT_NAME ORIGINAL_NAME DROPTIME&lt;br /&gt;------------------------------ -------------------------------- -------------------&lt;br /&gt;BIN$QZwwUzhJQT2GZM/PIEW3pA==$0 FLASHDROP 2009-05-05:10:06:00&lt;br /&gt;BIN$GR72mxnyQp+++qxOmVGQfg==$0 FLASHDROP 2009-05-05:10:05:25&lt;br /&gt;BIN$ePj5BAIxTuuZy4oRO3d/oA==$0 FLASHDROP 2009-05-05:10:05:36&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; flashback table flashdrop to before drop;&lt;br /&gt;&lt;br /&gt;Flashback complete.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select object_name, original_name,droptime&lt;br /&gt;2 from recyclebin;&lt;br /&gt;&lt;br /&gt;OBJECT_NAME ORIGINAL_NAME DROPTIME&lt;br /&gt;------------------------------ -------------------------------- -------------------&lt;br /&gt;BIN$GR72mxnyQp+++qxOmVGQfg==$0 FLASHDROP 2009-05-05:10:05:25&lt;br /&gt;BIN$ePj5BAIxTuuZy4oRO3d/oA==$0 FLASHDROP 2009-05-05:10:05:36&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;In this scenario, Oracle recovered the table which is dropped recently.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario 4&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Recyclebin feature is enabled by default in oracle10g. But after turning the recyclebin feature off, we can recover the tables which are already existing in recyclebin.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;scott@orcl&gt;create table flashdrop as&lt;br /&gt;  2  select * from user_tables&lt;br /&gt;  3  where rownum &lt; 6;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; drop table flashdrop;&lt;br /&gt;&lt;br /&gt;Table dropped.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;scott@orcl&gt; show recyclebin&lt;br /&gt;ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME&lt;br /&gt;---------------- ------------------------------ ------------ -------------------&lt;br /&gt;FLASHDROP BIN$WXrd4IW+SKmYh9EGU8bg5Q==$0 TABLE 2009-05-05:10:24:59&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; ALTER SESSION SET recyclebin = OFF;&lt;br /&gt;&lt;br /&gt;Session altered.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; flashback table flashdrop to before drop;&lt;br /&gt;&lt;br /&gt;Flashback complete.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; show recyclebin;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select count(*) from flashdrop;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;5&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Scenario 5&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Let us say, we start updating on flashdrop table at 12PM. We complete all the updates around 2PM. After we realized that, the updates went wrong and we want to revert the table back to 12PM... We can achieve this using FLASHBACK TABLE feature.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;scott@orcl&gt;create table flashdrop as&lt;br /&gt;  2  select * from user_tables&lt;br /&gt;  3  where rownum &lt; 6;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; SELECT current_scn from v$database;&lt;br /&gt;&lt;br /&gt;CURRENT_SCN&lt;br /&gt;-----------&lt;br /&gt;19220251&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; delete flashdrop where rownum &lt; 2;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; update flashdrop set object_name=lower(object_name);&lt;br /&gt;&lt;br /&gt;4 rows updated.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select object_name from flashdrop;&lt;br /&gt;&lt;br /&gt;OBJECT_NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;audit_seq&lt;br /&gt;bin$ekjojm2as66hxzkrauejia==$0&lt;br /&gt;bin$hfdops9utc2qdmy9pamg6w==$0&lt;br /&gt;bin$idl5ashfqmqe8ctrwu8k8q==$0&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; flashback table flashdrop to scn 19220251;&lt;br /&gt;flashback table flashdrop to scn 19220251&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-08189: cannot flashback the table because row movement is not enabled&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; alter table flashdrop enable row movement;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; flashback table flashdrop to scn 19220251;&lt;br /&gt;&lt;br /&gt;Flashback complete.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select object_name from flashdrop;&lt;br /&gt;&lt;br /&gt;OBJECT_NAME&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;AUDITLOG&lt;br /&gt;AUDIT_SEQ&lt;br /&gt;BIN$EkjOJm2AS66HXzkrAueJiA==$0&lt;br /&gt;BIN$HFDoPs9uTC2QdMY9pAMG6w==$0&lt;br /&gt;BIN$IDl5ashFQMqE8ctrWU8K8Q==$0&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;Flashback of table can also be performed using timestamps as below...&lt;br /&gt;&lt;br /&gt;FLASHBACK TABLE flashdrop TO TIMESTAMP TO_TIMESTAMP('2004-05-06 10:00:00', 'YYYY-MM-DD HH:MI:SS');&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we purge objects manully in recyclebin?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;PURGE TABLE tablename; -- Specific table.&lt;br /&gt;PURGE INDEX indexname; -- Specific index.&lt;br /&gt;PURGE TABLESPACE ts_name; -- All tables in a specific tablespace.&lt;br /&gt;PURGE TABLESPACE ts_name USER username; -- All tables in a specific tablespace for a specific user.&lt;br /&gt;PURGE RECYCLEBIN; -- The current users entire recycle bin.&lt;br /&gt;PURGE DBA_RECYCLEBIN; -- The whole recycle bin.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we bypass the recyclebin?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;We can add PURGE statement with drop table command to bypass the recyclebin. The tables will be dropped without going into recycle bin. But when we drop tablespace(DROP TABLESPACE .... INCLUDING CONTENTS), tablespace is not placed in recyclebin. It drops associated recyclebin for that tablespace.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; DROP TABLE EMPTABLE PURGE;&lt;br /&gt;&lt;br /&gt;Table dropped.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; FLASHBACK table emptable to before drop;&lt;br /&gt;FLASHBACK table emptable to before drop&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-38305: object not in RECYCLE BIN&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Naming convention for object in recyclebin:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;When we drop the object, the dropped objects are renamed and moved to recyclebin. The names are globally unique and are used to identify the objects while they are in the recycle bin. The recyclebin name of an object is always 30 characters long. Dropped Object names are formed as follows: &lt;span style="color:#ff6666;"&gt;&lt;span style="color:#ff0000;"&gt;BIN$$globalUID$vers&lt;/span&gt;ion&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;globalUID is a globally unique, 24 character long identifier generated for the object.&lt;br /&gt;version is a version number assigned by the database.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Limitations on Recyclebin:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. Only non system locally managed tablespace(LMT) can have a recycle bin. However, dependent objects in a dictionary managed tablespace are protected if the dropped object is LMT.&lt;br /&gt;&lt;br /&gt;2. All dependent objects will be placed in recyclebin except bitmap join index, FK constraints, Materialized view logs)&lt;br /&gt;&lt;br /&gt;3. Indexes are protected only if the table is dropped first. Explicitly dropping an index does not place in recyclebin.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;4. There is no fixed amount of space allocated to the recycle bin, and no guarantee as to how long dropped objects remain in the recycle bin. Depending upon system activity, a dropped object may remain in the recycle bin for seconds, or for months.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;5. Due to security concerns, tables which have Fine-Grained Auditing (FGA) and Virtual Private Database (VPD) policies defined over them are not protected by the recycle bin.&lt;br /&gt;&lt;br /&gt;6. Partitioned index-organized tables are not protected by the recycle bin.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Recyclebin Views:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;We have two views, USER_RECYCLEBIN, DBA_RECYCLEBIN. For our convenience, synonym RECYCLEBIN is created which is pointing to user_recyclebin. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;How do we disable the recyclebin?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;The recyclebin feature is enabled in oracle10g by default. &lt;/span&gt;We can change the initialization parameter RECYCLEBIN to enable or disable this feature.&lt;br /&gt;&lt;br /&gt;ALTER SESSION SET recyclebin = OFF;&lt;br /&gt;ALTER SYSTEM SET recyclebin = OFF;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-6872877358301210492?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/6872877358301210492/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=6872877358301210492' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/6872877358301210492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/6872877358301210492'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/05/recycle-bin.html' title='Recyclebin'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-2793598810092039239</id><published>2009-04-20T15:38:00.000-07:00</published><updated>2009-06-23T15:13:02.565-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='READBUFFER'/><category scheme='http://www.blogger.com/atom/ns#' term='DIRECT PATH'/><category scheme='http://www.blogger.com/atom/ns#' term='STREAMBUFFER'/><category scheme='http://www.blogger.com/atom/ns#' term='READSIZE'/><category scheme='http://www.blogger.com/atom/ns#' term='DATE_CACHE'/><category scheme='http://www.blogger.com/atom/ns#' term='COLUMNARRAY'/><category scheme='http://www.blogger.com/atom/ns#' term='STREAMSIZE'/><category scheme='http://www.blogger.com/atom/ns#' term='TUNING PARAMETERS IN SQLLOADER'/><category scheme='http://www.blogger.com/atom/ns#' term='MULTITHREADING'/><category scheme='http://www.blogger.com/atom/ns#' term='SQLLOADER'/><category scheme='http://www.blogger.com/atom/ns#' term='COLUMNARRAYROWS'/><category scheme='http://www.blogger.com/atom/ns#' term='CONVENTIONAL PATH'/><title type='text'>SQL Loader Memory Parameters</title><content type='html'>There are few command line SQLLoader parameters which are used for tuning direct data load. These parameters should be tuned only when we have any performance issue for loading the data through SQLLoader. Since these parameters are directly impacting client memory... This article is written in Oracle10g and these parameter might change in future Oracle Versions...&lt;br /&gt;&lt;br /&gt;Here are the below parameters which are used only for Direct Path Data load.....&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;READSIZE &lt;/span&gt;&lt;span style="color:#000000;"&gt;is size of the buffer used to read the data from input data file. The default size is 1MB(1048576 bytes).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;COLUMNARRAYROWS&lt;/span&gt; is number of rows in a two-dimensional array used to hold field information. This holds field information for every row. The default is 5000 rows.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;STREAMSIZE&lt;/span&gt; is size of the buffer to send the data to server for loading into target table. The default is 256000 bytes.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;MULTITHREADING&lt;/span&gt; is an option that allows concurrent execution of some SQL*Loader client operations with database server data loading. If multithreading is turned off, the SQL*Loader client will always wait until the server finishes a data load before continuing. If multithreading is turned on, some calls to the server will be executed by the client's "load thread" while the client's "main thread" continues converting data and building stream buffers.&lt;br /&gt;&lt;br /&gt;When the MULTITHREADING command-line parameter is set to TRUE (the default on multi-CPU clients), SQL*Loader will overlap stream loading with stream conversion. If the main thread has converted data from a column array into a stream and the stream is filled before all data in the column array has been processed, the load thread will load that stream while the main thread continues to convert the column array into another stream buffer.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;DATE_CACHE&lt;/span&gt; used in direct path load. This parameter will play a role when we load the date data from input file into Oracle table. When we have date value in input file, sqlloader has to convert the date string into Oracle DATE Format before load into target table. When we have large duplicate date string in input file, then sqlloader keeps the converted date value in date_cache first time and reuse every occurrence of the same date string in input file. So it would save time for date conversion when we have the same date string in the input file.&lt;br /&gt;&lt;br /&gt;If you know the number of duplicate date strings is small or the number of unique date strings is very large, then you can disable the date cache by specifying DATE_CACHE=0 on the command line. The default value for DATE_CACHE is 1000. If number of unique date values in table greater then the size of the date cache, then DATE_CACHE will be disabled. All the date columns will share the same DATE_CACHE.&lt;br /&gt;&lt;br /&gt;Please &lt;a href="http://www.oracle.com/technology/pub/notes/technote_datecache.html"&gt;click&lt;/a&gt; this link if you need more info about DATE_CACHE.&lt;br /&gt;&lt;br /&gt;Here is the process flow between these three memory parameters(READSIZE, COLUMNARRAYROWS and STREAMSIZE) for DIRECT Path data load...&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQLLoader reads data from input data file and load into memory buffer. This buffer size is controlled by READSIZE parameter.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQLLoader parse every logical record from step1, and isolate the fields in COLUMNARRAY memory buffer based on field definition which is specified in SQLLoader control file. This process is called as "Field setting". The number of rows in the column array is controlled by COLUMNARRAYROWS parameter.&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Step2 will continue untill COLUMNARRAY buffer is full.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step4&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQLLoader will parse the columnarray data into STREAMBUFFER. This buffer size is controlled by STREAMSIZE parameter. There may be a possibility that, STREAMBUFFER might be getting full before it copies all the data from COLUMNARRAY buffer.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;STREAMBUFFER data will be sent to server.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step6&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Server will parse STREAMBUFFER data and load into target table.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step7&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Once step6 is completed, then STREAMBUFFER will be set to empty.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step8&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If more data that needs to be loaded from COLUMNARRAYBUFFER, then continue from step4. If there is no data in COLUMNARRAYBUFFER, then continue step9.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step9&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If the COLUMNARRAY buffer data is completed(loaded into target table via streambuffer), then sqlloader will look for remaining data in READBUFFER. If there are more data in READBUFFER, then continue from step2. Otherwise, continue step10&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Step10&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If all the records in READBUFFER is processed, then load more records from input data file into READBUFFER which is apparently from step1.&lt;br /&gt;&lt;br /&gt;Note : If you need more info on these DIRECT Load Tuning parameters, please &lt;a href="http://www.oracle.com/technology/pub/notes/technote_loader_path.html"&gt;click&lt;/a&gt; this link.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-2793598810092039239?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/2793598810092039239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=2793598810092039239' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2793598810092039239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2793598810092039239'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/04/oracle-sql-loader-tuning-memory.html' title='SQL Loader Memory Parameters'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-6175273216289583807</id><published>2009-04-02T16:48:00.001-07:00</published><updated>2009-06-23T14:48:04.061-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='integer is slower then number'/><category scheme='http://www.blogger.com/atom/ns#' term='INTEGER'/><category scheme='http://www.blogger.com/atom/ns#' term='scale -84 to 127'/><category scheme='http://www.blogger.com/atom/ns#' term='INTEGER VERSUS NUMBER'/><category scheme='http://www.blogger.com/atom/ns#' term='CONSTRAINED'/><title type='text'>Integer Versus Number data type</title><content type='html'>What is the difference betwen INTEGER and NUMBER? When should we use NUMBER and when should we use INTEGER? I just wanted to update my comments here...&lt;br /&gt;&lt;br /&gt;NUMBER always stores as we entered. Scale is -84 to 127. But INTEGER rounds to whole number. The scale for INTEGER is 0. INTEGER is equivalent to NUMBER(38,0). It means, INTEGER is constrained number. The decimal place will be rounded. But NUMBER is not constrained.&lt;br /&gt;&lt;br /&gt;INTEGER(12,2) =&gt; 12&lt;br /&gt;INTEGER(12.5) =&gt; 13&lt;br /&gt;INTEGER(12.9) =&gt; 13&lt;br /&gt;INTEGER(12.4) =&gt; 12&lt;br /&gt;NUMBER(12,2) =&gt; 12.2&lt;br /&gt;NUMBER(12.5) =&gt; 12.5&lt;br /&gt;NUMBER(12.9) =&gt; 12.9&lt;br /&gt;NUMBER(12.4) =&gt; 12.4&lt;br /&gt;&lt;br /&gt;INTEGER is always slower then NUMBER. Since integer is a number with added constraint. It takes additional CPU cycles to enforce the constraint. I never watched any difference, but there might be a difference when we load several millions of records on the INTEGER column. If we need to ensure that the input is whole numbers, then INTEGER is best option to go. Otherwise, we can stick with NUMBER data type.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-6175273216289583807?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/6175273216289583807/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=6175273216289583807' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/6175273216289583807'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/6175273216289583807'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/04/integer-versus-number-data-type.html' title='Integer Versus Number data type'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-2746065959350729584</id><published>2009-03-29T07:11:00.000-07:00</published><updated>2009-06-23T14:07:22.925-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='global_name'/><category scheme='http://www.blogger.com/atom/ns#' term='SP2-0333'/><category scheme='http://www.blogger.com/atom/ns#' term='v$instance'/><category scheme='http://www.blogger.com/atom/ns#' term='describe'/><category scheme='http://www.blogger.com/atom/ns#' term='sysdba'/><category scheme='http://www.blogger.com/atom/ns#' term='OLAP'/><category scheme='http://www.blogger.com/atom/ns#' term='run'/><category scheme='http://www.blogger.com/atom/ns#' term='login.sql'/><category scheme='http://www.blogger.com/atom/ns#' term='$ORACLE_HOME/sqlplus/admin'/><category scheme='http://www.blogger.com/atom/ns#' term='set termout off'/><category scheme='http://www.blogger.com/atom/ns#' term='ORA-24372'/><category scheme='http://www.blogger.com/atom/ns#' term='enhancements'/><category scheme='http://www.blogger.com/atom/ns#' term='save'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL * PLUS'/><category scheme='http://www.blogger.com/atom/ns#' term='spool'/><category scheme='http://www.blogger.com/atom/ns#' term='append'/><category scheme='http://www.blogger.com/atom/ns#' term='glogin.sql'/><title type='text'>New Enhancements in SQL* PLUS</title><content type='html'>SQL* PLUS is a tool to edit the SQL command and format the SQL output. Here is the new enhancement in SQL*PLUS for oracle10g.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Enhancement 1&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Prior to oracle10g if we describe the object that is invalid, the describe command will fail with error. But in oracle10g, DESCRIBE will try to validate the object first, and if the object is still invalid after validation, it gives the error message. If the validation is successful, then DESCRIBE command will also be successful.&lt;br /&gt;Let us test this in oracle 10g &amp;amp; oracle9i and see the difference....&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; create or replace procedure testproc is&lt;br /&gt;2 v_cnt number;&lt;br /&gt;3 begin&lt;br /&gt;4 select count(*) into v_cnt&lt;br /&gt;5 from temptable;&lt;br /&gt;6 end;&lt;br /&gt;7 /&lt;br /&gt;&lt;br /&gt;Procedure created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; desc testproc;&lt;br /&gt;PROCEDURE testproc&lt;br /&gt;scott@orcl&gt; drop table temptable;&lt;br /&gt;&lt;br /&gt;Table dropped.&lt;br /&gt;scott@orcl&gt; select status from user_objects&lt;br /&gt;2 where object_name='TESTPROC';&lt;br /&gt;&lt;br /&gt;STATUS&lt;br /&gt;-------&lt;br /&gt;INVALID&lt;br /&gt;scott@orcl&gt; create table temptable(no number);&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select status from user_objects&lt;br /&gt;2 where object_name='TESTPROC';&lt;br /&gt;&lt;br /&gt;STATUS&lt;br /&gt;-------&lt;br /&gt;INVALID&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; desc testproc;&lt;br /&gt;PROCEDURE testproc&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; select status from user_objects&lt;br /&gt;2 where object_name='TESTPROC';&lt;br /&gt;&lt;br /&gt;STATUS&lt;br /&gt;-------&lt;br /&gt;VALID&lt;br /&gt;&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;The above case, the procedure is recompiled when we describe the procedure...&lt;br /&gt;&lt;br /&gt;Let us test the same scenario in oracle9i...&lt;br /&gt;Connected to:&lt;br /&gt;Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP and Oracle Data Mining options&lt;br /&gt;JServer Release 9.2.0.8.0 - Production&lt;br /&gt;&lt;br /&gt;SQL&gt; create or replace procedure testproc is&lt;br /&gt;2 v_cnt number;&lt;br /&gt;3 begin&lt;br /&gt;4 select count(*) into v_cnt&lt;br /&gt;5 from temptable;&lt;br /&gt;6 end;&lt;br /&gt;7 /&lt;br /&gt;&lt;br /&gt;Procedure created.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;SQL&gt; desc testproc;&lt;br /&gt;PROCEDURE testproc&lt;br /&gt;&lt;br /&gt;SQL&gt; drop table temptable;&lt;br /&gt;&lt;br /&gt;Table dropped.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;SQL&gt; select status from user_objects&lt;br /&gt;2 where object_name='TESTPROC';&lt;br /&gt;&lt;br /&gt;STATUS&lt;br /&gt;-------&lt;br /&gt;INVALID&lt;br /&gt;&lt;br /&gt;SQL&gt; create table temptable(no number);&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;SQL&gt; select status from user_objects&lt;br /&gt;2 where object_name='TESTPROC';&lt;br /&gt;&lt;br /&gt;STATUS&lt;br /&gt;-------&lt;br /&gt;INVALID&lt;br /&gt;&lt;br /&gt;SQL&gt; desc testproc;&lt;br /&gt;ERROR:&lt;br /&gt;ORA-24372: invalid object for describe&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; select status from user_objects&lt;br /&gt;2 where object_name='TESTPROC';&lt;br /&gt;&lt;br /&gt;STATUS&lt;br /&gt;-------&lt;br /&gt;INVALID&lt;br /&gt;&lt;br /&gt;SQL&gt; alter procedure testproc compile;&lt;br /&gt;&lt;br /&gt;Procedure altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; desc testproc&lt;br /&gt;PROCEDURE testproc&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;The above case, the procedure is not recompiled when we describe the procedure...&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Enhancement 2&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;The glogin.sql, login.sql files are profile files used to customize our SQL*Plus environment when we log in SQL*Plus. The glogin.sql file is site profile file and located in $ORACLE_HOME/sqlplus/admin directory. The login.sql file user profile and is executed after the glogin.sql file. Prior to oracle10g, this two files(glogin.sql, login.sql) are executed one after other only when we restart the SQL*Plus. But in oracle10g, these two files are executed one after other for every connect as well as every restart of SQL*Plus.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Let us test this in oracle10g... Our goal is to display username and instance name in the sql prompt. Let me add this below entry in glogin.sql file.&lt;br /&gt;&lt;br /&gt;column global_name new_value gname&lt;br /&gt;set termout off&lt;br /&gt;select lower(user) '@'&lt;br /&gt;INSTANCE_NAME global_name&lt;br /&gt;from V$INSTANCE;&lt;br /&gt;set sqlprompt '&amp;amp;gname&gt; '&lt;br /&gt;set termout on&lt;br /&gt;&lt;br /&gt;Let us restart the SQL*Plus.&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 10.1.0.2.0 - Production on Sun Mar 29 11:04:41 2009&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2004, Oracle. All rights reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;Now again we will connect to another user and see SQL prompt is changing...&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; connect training/training@orcl&lt;br /&gt;Connected.&lt;br /&gt;training@orcl&gt;&lt;br /&gt;&lt;br /&gt;so in Oracle10g, glogin.sql is executing every connect as well as every restart of SQL* Plus.&lt;br /&gt;&lt;br /&gt;Let us test the same in oracle9i.&lt;br /&gt;&lt;p&gt;Connected to:&lt;br /&gt;Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP and Oracle Data Mining options&lt;br /&gt;JServer Release 9.2.0.8.0 - Production&lt;br /&gt;&lt;br /&gt;dwadba@invent&gt; connect &lt;a href="mailto:sales@invent"&gt;sales@invent&lt;/a&gt;&lt;br /&gt;Enter password: ************&lt;br /&gt;Connected.&lt;br /&gt;dwadba@invent&gt;&lt;/p&gt;so in Oracle9i, glogin.sql is not executing for every connect. It executes only when we start the SQL*Plus.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Enhancement 3&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;oracle10g supports white space in filenames when we use commands like SPOOL, SAVE, RUN.&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; spool 'c:/test file.txt';&lt;br /&gt;scott@orcl&gt; select sysdate from dual;&lt;br /&gt;&lt;br /&gt;SYSDATE&lt;br /&gt;---------&lt;br /&gt;29-MAR-09&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; spool off&lt;br /&gt;&lt;br /&gt;In oracle9i, it does not support space for filenames...&lt;br /&gt;&lt;p&gt;Connected to:&lt;br /&gt;Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP and Oracle Data Mining options&lt;br /&gt;JServer Release 9.2.0.8.0 - Production&lt;br /&gt;&lt;br /&gt;SQL&gt; spool 'c:/test file.txt';&lt;br /&gt;SP2-0333: Illegal spool file name: "'c:/test file.txt'" (bad character: ' ') &lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#ff6666;"&gt;Enhancement 4&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The spool command stores query result in a file. In oracle10g, SPOOL command includes the APPEND extension to add the contents of the buffer to the end of the file.&lt;br /&gt;&lt;br /&gt;Let us test this in oracle10g.&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; spool c:/test.txt&lt;br /&gt;scott@orcl&gt; select sysdate from dual;&lt;br /&gt;&lt;br /&gt;SYSDATE&lt;br /&gt;---------&lt;br /&gt;29-MAR-09&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; spool off&lt;br /&gt;scott@orcl&gt; spool c:/test.txt append&lt;br /&gt;scott@orcl&gt; select sysdate from dual;&lt;br /&gt;&lt;br /&gt;SYSDATE&lt;br /&gt;---------&lt;br /&gt;29-MAR-09&lt;br /&gt;&lt;br /&gt;scott@orcl&gt; spool off&lt;br /&gt;scott@orcl&gt;&lt;br /&gt;&lt;br /&gt;Let us test the same in oracle9i.&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP and Oracle Data Mining options&lt;br /&gt;JServer Release 9.2.0.8.0 - Production&lt;br /&gt;&lt;br /&gt;SQL&gt; spool c:/test.txt&lt;br /&gt;SQL&gt; select sysdate from dual;&lt;br /&gt;&lt;br /&gt;SYSDATE&lt;br /&gt;---------&lt;br /&gt;30-MAR-09&lt;br /&gt;&lt;br /&gt;SQL&gt; spool off&lt;br /&gt;SQL&gt; spool c:/test.txt append&lt;br /&gt;SP2-0333: Illegal spool file name: "c:/test.txt append" (bad character: ' ')&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-2746065959350729584?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/2746065959350729584/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=2746065959350729584' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2746065959350729584'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2746065959350729584'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/03/new-enhancements-in-sql-plus.html' title='New Enhancements in SQL* PLUS'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-480593156629561208</id><published>2009-02-20T09:10:00.000-08:00</published><updated>2009-03-28T21:45:25.619-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SYS'/><category scheme='http://www.blogger.com/atom/ns#' term='Character and Byte Semantics'/><category scheme='http://www.blogger.com/atom/ns#' term='CHAR'/><category scheme='http://www.blogger.com/atom/ns#' term='DICTIONARY'/><category scheme='http://www.blogger.com/atom/ns#' term='SYSTEM'/><category scheme='http://www.blogger.com/atom/ns#' term='CHARACER'/><category scheme='http://www.blogger.com/atom/ns#' term='VARCHAR2'/><category scheme='http://www.blogger.com/atom/ns#' term='SINGLEBYTE'/><category scheme='http://www.blogger.com/atom/ns#' term='NLS_LENGTH_SEMANTICS'/><category scheme='http://www.blogger.com/atom/ns#' term='MULTIBYTE'/><category scheme='http://www.blogger.com/atom/ns#' term='PARAMETER'/><category scheme='http://www.blogger.com/atom/ns#' term='BYTE'/><title type='text'>Character  and Byte Semantics in Oracle</title><content type='html'>Historically Oracle character data type column have been defined by using number of bytes. This is good as long as total number of characters equal to total number of bytes. When we maintain multilingual version of application, the database needs to set as a multi byte character set. For instance, the column data type length is VARCHAR2(10). In this case, we can store 10 characters for single byte character set. When we moved to multi byte character set, we can not store 10 characters. Oracle9i has solved this problem with the introduction of character and byte length semantics. Oracle9i introduced NLS_LENGTH_SEMANTICS init parameter to solve this issue. NLS_LENGTH_SEMANTICS enables you to create CHAR and VARCHAR2 columns using either byte or character length semantics.&lt;br /&gt;&lt;br /&gt;There are three different ways, we can declare CHAR/VARCHAR2  data type.&lt;br /&gt;Let us take VARCHAR2(10)  as an example here.&lt;br /&gt;&lt;br /&gt;1. VARCHAR2(10)&lt;br /&gt;2. VARCHAR2(10 BYTE)&lt;br /&gt;3. VARCHAR2(10 CHAR)&lt;br /&gt;&lt;br /&gt;What is the difference between VARCHAR2(10), VARCHAR2(10 BYTE) &amp;amp; VARCHAR2(10 CHAR).&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;VARCHAR2(10 BYTE)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#333333;"&gt;When we declare the data type as VARCHAR2(10 BYTE), oracle stores only 10 bytes of data, regardless of how many characters this represents. This is perfect when the database has only single byte character set. Since total number of charater is equal to total number of bytes.. So this case, oracle stores 10 Characters.. But when database handles multilingual version of application, then oracle stores multi byte characters. In this case, oracle can store only 5 character.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;VARCHAR2(10 CHAR)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#333333;"&gt;&lt;/span&gt;&lt;br /&gt;This allows the specified number of characters to be stored in the column regardless of number of bytes this equates to.. Oracle can store 10 character regardless of single byte character set or multi byte character set.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;VARCHAR2(10)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#333333;"&gt;Oracle stores 10 Character or 10 Bytes depends on NLS_LENGTH_SEMANTICS parameter value. if it sets to BYTE, then we can store 10 bytes(if it is mutibyte character set, then we can store 5 characters). The default value is BYTE. When this parameter is CHAR, then we can store 10 characters regardless of single byte character set or multi byte character set.&lt;/span&gt; When we move the database to multibyte characterset, we can change NLS_LENGTH_SEMANTICS paramter to CHAR to resolve the storage issue. Existing columns will not be affected when we change the value for this parameter.&lt;br /&gt;&lt;span style="color:#333333;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#333333;"&gt;The default character semantics of the database or session can be altered using the NLS_LENGTH_SEMANTICS parameter like:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#333333;"&gt;&lt;/span&gt;&lt;br /&gt;SQL&gt; alter system set nls_length_semantics=char;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter system set nls_length_semantics=byte;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter session set nls_length_semantics=char;&lt;br /&gt;&lt;br /&gt;Session altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter session set nls_length_semantics=byte;&lt;br /&gt;&lt;br /&gt;Session altered.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Note : NLS_LENGTH_SEMANTICS does not apply to tables in SYS and SYSTEM. The data dictionary always uses byte semantics.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-480593156629561208?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/480593156629561208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=480593156629561208' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/480593156629561208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/480593156629561208'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2009/02/character-and-byte-semantics-in-oracle.html' title='Character  and Byte Semantics in Oracle'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-2889834534254653053</id><published>2008-12-18T17:24:00.000-08:00</published><updated>2009-04-06T11:08:32.570-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='forall'/><category scheme='http://www.blogger.com/atom/ns#' term='Bulk binds'/><category scheme='http://www.blogger.com/atom/ns#' term='bulk collects'/><category scheme='http://www.blogger.com/atom/ns#' term='bulk collect into'/><title type='text'>Bulk Binds</title><content type='html'>&lt;span style="color:#ff0000;"&gt;Oracle use two engine to process PLSQL block and subprogram. All SQL code is processed by SQL engine and PLSQL code is processed by PLSQL engine. When you run SQL code in the loop, oracle has to switch between SQL engine and PLSQL engine for each iteration. So there is overhead associated for each context switch. Bulk Bind is introduced in oracle8i to reduce the context switch..  This feature is enhanced in further versions...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP and Oracle Data Mining options&lt;br /&gt;JServer Release 9.2.0.8.0 - Production&lt;br /&gt;&lt;br /&gt;SQL&gt; CREATE TABLE emp(&lt;br /&gt;2 empno NUMBER(10),&lt;br /&gt;3 empname VARCHAR2(50));&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;SQL&gt; ALTER TABLE emp ADD (&lt;br /&gt;2 CONSTRAINT emppk PRIMARY KEY(empno));&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;The total time taken to insert the 50,000 records through FOR LOOP is .071 Minuts. Because, 50,000 context switch happens in the FOR LOOP. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;SQL&gt; set serveroutput on&lt;br /&gt;SQL&gt; DECLARE&lt;br /&gt;2 TYPE emp_tab IS TABLE OF EMP%ROWTYPE;&lt;br /&gt;3 t_tab emp_tab := emp_tab();&lt;br /&gt;4 l_start NUMBER DEFAULT DBMS_UTILITY.GET_TIME;&lt;br /&gt;5 BEGIN&lt;br /&gt;6 FOR i IN 1 .. 50000 LOOP&lt;br /&gt;7 t_tab.extend;&lt;br /&gt;8 t_tab(t_tab.last).empno := i;&lt;br /&gt;9 t_tab(t_tab.last).empname := 'name:' To_Char(i);&lt;br /&gt;10 END LOOP;&lt;br /&gt;12 FOR i IN t_tab.first .. t_tab.last LOOP&lt;br /&gt;13 INSERT INTO emp (empno, empname)&lt;br /&gt;14 VALUES (t_tab(i).empno, t_tab(i).empname);&lt;br /&gt;15 END LOOP;&lt;br /&gt;16 COMMIT;&lt;br /&gt;17 DBMS_OUTPUT.PUT_LINE('Total time ... 'ROUND(ROUND((DBMS_UTILITY.GET_TIME - l_start)/100, 2)/6&lt;br /&gt;0,3));&lt;br /&gt;18 END;&lt;br /&gt;19 /&lt;br /&gt;Total time ... .071&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;/p&gt;&lt;span style="color:#ff0000;"&gt;Here time taken to insert the 50,000 records through bulk binds is 0.015 Minuts. When we compared to above example, it is much faster.. since it is completed reduced the context switches between SQL engine to PLSQL engine.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;SQL&gt; TRUNCATE TABLE emp;&lt;br /&gt;&lt;br /&gt;Table truncated.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;SQL&gt; DECLARE&lt;br /&gt;2 TYPE emp_tab IS TABLE OF emp%ROWTYPE;&lt;br /&gt;3 l_start NUMBER DEFAULT DBMS_UTILITY.GET_TIME;&lt;br /&gt;4 t_tab emp_tab := emp_tab();&lt;br /&gt;5 BEGIN&lt;br /&gt;6 FOR i IN 1 .. 50000 LOOP&lt;br /&gt;7 t_tab.extend;&lt;br /&gt;9 t_tab(t_tab.last).empno := i;&lt;br /&gt;10 t_tab(t_tab.last).empname := 'name:' To_Char(i);&lt;br /&gt;11 END LOOP;&lt;br /&gt;12&lt;br /&gt;13 FORALL i IN t_tab.first .. t_tab.last&lt;br /&gt;14 INSERT INTO emp VALUES t_tab(i);&lt;br /&gt;15 COMMIT;&lt;br /&gt;16 DBMS_OUTPUT.PUT_LINE('Total time ... 'ROUND(ROUND((DBMS_UTILITY.GET_TIME - l_start)/100, 2)/6&lt;br /&gt;0,3));&lt;br /&gt;17 END;&lt;br /&gt;18 /&lt;br /&gt;Total time ... .015&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Bulk binds can also improve the performance when loading collection from queries. BULK COLLECT INTO clause can collect the data into collections. In the below example, it took 0.021 Minuts to fetch 50,000 records with out bulk binds&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; DECLARE&lt;br /&gt;2 TYPE emp_tab IS TABLE OF emp%ROWTYPE;&lt;br /&gt;3 t_tab emp_tab := emp_tab();&lt;br /&gt;4 l_start NUMBER DEFAULT DBMS_UTILITY.GET_TIME;&lt;br /&gt;5 CURSOR c_data IS&lt;br /&gt;6 SELECT *&lt;br /&gt;7 FROM emp;&lt;br /&gt;8 BEGIN&lt;br /&gt;9 FOR cur_rec IN c_data LOOP&lt;br /&gt;10 t_tab.extend;&lt;br /&gt;11 t_tab(t_tab.last).empno := cur_rec.empno;&lt;br /&gt;12 t_tab(t_tab.last).empname := cur_rec.empname;&lt;br /&gt;13 END LOOP;&lt;br /&gt;14 DBMS_OUTPUT.PUT_LINE('Total time ... 'ROUND(ROUND((DBMS_UTILITY.GET_TIME - l_start)/100, 2)/6&lt;br /&gt;0,3));&lt;br /&gt;15 END;&lt;br /&gt;16 /&lt;br /&gt;Total time ... .021&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;In the below case, it took 0.004 Minutes to fetch the data into collection. When we compared to above case, it is faster.. since it is using BULK COLLECT to reduce the context switch.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;SQL&gt; DECLARE&lt;br /&gt;2 TYPE emp_tab IS TABLE OF emp%ROWTYPE;&lt;br /&gt;3 t_tab emp_tab := emp_tab();&lt;br /&gt;4 l_start NUMBER DEFAULT DBMS_UTILITY.GET_TIME;&lt;br /&gt;5 BEGIN&lt;br /&gt;6 SELECT empno,empname&lt;br /&gt;7 BULK COLLECT INTO t_tab&lt;br /&gt;8 FROM emp;&lt;br /&gt;9 DBMS_OUTPUT.PUT_LINE('Total time ... 'ROUND(ROUND((DBMS_UTILITY.GET_TIME - l_start)/100, 2)/6&lt;br /&gt;0,3));&lt;br /&gt;10 END;&lt;br /&gt;11 /&lt;br /&gt;Total time ... .004&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Oracle 9i Release 2 allows to use ROW key word to update the record. When we update, we can not use record type definition with bulk binds. The below case, we can not use bulk bind to improve the performance, since we are using record type definition. This is one restriction on this version(oracle9i R2).&lt;/span&gt;&lt;/p&gt;SQL&gt; DECLARE&lt;br /&gt;2 TYPE emp_tab IS TABLE OF emp%ROWTYPE;&lt;br /&gt;3 l_start NUMBER DEFAULT DBMS_UTILITY.GET_TIME;&lt;br /&gt;4 t_tab emp_tab := emp_tab();&lt;br /&gt;5 BEGIN&lt;br /&gt;6 FOR i IN 1 .. 10000 LOOP&lt;br /&gt;7 t_tab.extend;&lt;br /&gt;9 t_tab(t_tab.last).empno := i;&lt;br /&gt;10 t_tab(t_tab.last).empname := 'name' To_Char(i);&lt;br /&gt;11 END LOOP;&lt;br /&gt;13 FOR i IN t_tab.first .. t_tab.last LOOP&lt;br /&gt;14 UPDATE emp&lt;br /&gt;15 SET ROW = t_tab(i)&lt;br /&gt;16 WHERE empno = t_tab(i).empno;&lt;br /&gt;17 END LOOP;&lt;br /&gt;18 COMMIT;&lt;br /&gt;19 DBMS_OUTPUT.PUT_LINE('Total time ... 'ROUND(ROUND((DBMS_UTILITY.GET_TIME - l_start)/100, 2)/6&lt;br /&gt;0,3));&lt;br /&gt;20 END;&lt;br /&gt;21 /&lt;br /&gt;Total time ... .012&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;The below case, we are using bulk bind since, we are not using record type definition. The time took to update the 50,000 records is 0.007 Minuts. When we compare with above case, the performance is improved well.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; DECLARE&lt;br /&gt;2 TYPE empno_tab IS TABLE OF emp.empno%TYPE;&lt;br /&gt;3 TYPE emp_tab IS TABLE OF emp%ROWTYPE;&lt;br /&gt;4 l_start NUMBER DEFAULT DBMS_UTILITY.GET_TIME;&lt;br /&gt;5 t_empno empno_tab := empno_tab();&lt;br /&gt;6 t_tab emp_tab := emp_tab();&lt;br /&gt;7 BEGIN&lt;br /&gt;8 FOR i IN 1 .. 10000 LOOP&lt;br /&gt;9 t_empno.extend;&lt;br /&gt;10 t_tab.extend;&lt;br /&gt;11 t_empno(t_empno.last) := i;&lt;br /&gt;12 t_tab(t_tab.last).empno := i;&lt;br /&gt;13 t_tab(t_tab.last).empname := 'name ' To_Char(i);&lt;br /&gt;14 END LOOP;&lt;br /&gt;16 FORALL i IN t_tab.first .. t_tab.last&lt;br /&gt;17 UPDATE emp&lt;br /&gt;18 SET ROW = t_tab(i)&lt;br /&gt;19 WHERE empno = t_empno(i);&lt;br /&gt;21 COMMIT;&lt;br /&gt;22 DBMS_OUTPUT.PUT_LINE('Total time ... 'ROUND(ROUND((DBMS_UTILITY.GET_TIME - l_start)/100, 2)/6&lt;br /&gt;0,3));&lt;br /&gt;23 END;&lt;br /&gt;24 /&lt;br /&gt;Total time ... .007&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;When to use Bulk Binds: &lt;/span&gt;&lt;span style="color:#000000;"&gt;There is no univeral rule exists to dictate when to use Bulk binds. If PLSQL code reads only few hundered records, then you will not see significant performance improvement for bulk binds. When you read huge number of records and have multiple insert/update, then you can think of bulk binds. If you have the luxury of time, you can test your code both with and without bulk binds and decide to go for this feature.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-2889834534254653053?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/2889834534254653053/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=2889834534254653053' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2889834534254653053'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/2889834534254653053'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2008/12/bulk-binds.html' title='Bulk Binds'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-1900856948797329247</id><published>2008-11-06T14:36:00.000-08:00</published><updated>2008-11-07T08:34:29.353-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SYNC_INTERIM_TABLE'/><category scheme='http://www.blogger.com/atom/ns#' term='COPY_TABLE_DEPENDENTS'/><category scheme='http://www.blogger.com/atom/ns#' term='Convert Non-Partitioned to Partitioned Table - using Online Re-definition feature'/><category scheme='http://www.blogger.com/atom/ns#' term='FINISH_REDEF_TABLE'/><category scheme='http://www.blogger.com/atom/ns#' term='DBMS_REDEFINITION'/><category scheme='http://www.blogger.com/atom/ns#' term='START_REDEF_TABLE'/><title type='text'>Convert Non-Partitioned to Partitioned Table</title><content type='html'>This article is written in oracle10g R2. In any database environment, if we need to covert any huge table to partition table, then first we need to think about two factor.&lt;br /&gt;&lt;br /&gt;1. Partition key&lt;br /&gt;2. What type of partition we need to use.&lt;br /&gt;&lt;br /&gt;Once we decided the above key factor, then there are couple of ways, we can convert the table to partition table.  We have two option to convert the regular table to partition table.&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Option 1&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;This option requires table down time and it might fit if business allows the application down time. Here are the steps to follow.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. Stop using the table, make sure no one is chaning the data in table.&lt;br /&gt;2. Create the partition table with the same structure of regular table.&lt;br /&gt;3. Copy the data from regular table to partition table.&lt;br /&gt;4. Create the constriant, keys, indexes on partition table.&lt;br /&gt;5. Drop the original table&lt;br /&gt;6. Analyze the partition table.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Option 2&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This is ideal option to convert the regular table to partition table. It does not require down time and every one can use the table during the conversion. This option is introduced in oracle9i and enhanced to 10g. We are using online redefinition(DBMS_REDEFINITION) to convert the table to partition table.&lt;br /&gt;&lt;br /&gt;Some restriction of using DBMS_REDEFINITION.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff6600;"&gt;1· Cannot belong to SYS or SYSTEM Schema.&lt;br /&gt;2. The table to be redefined online should not be using User-defined data types&lt;br /&gt;3· Should not be a clustered table.&lt;br /&gt;4. Should not have MV Logs or MVs defined&lt;br /&gt;5. You cannot move a table from one schema to another using Online Redefinition feature.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff6600;"&gt;&lt;span style="color:#000000;"&gt;Here are the steps to convert to partition table.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff6600;"&gt;Step 1&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Check to make sure that the table can use the online redefintion feature&lt;/span&gt;&lt;span style="color:#ff6600;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#ff6600;"&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - ProductionWith the Partitioning, OLAP and Data Mining options&lt;br /&gt;SQL&gt; EXEC DBMS_REDEFINITION.CAN_REDEF_TABLE('SCOTT','EMP');&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Step 2&lt;br /&gt;&lt;span style="color:#000000;"&gt;Create the temporary partition table as same structure of original table.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;SQL&gt; Create table EMP_part&lt;br /&gt;2 (EMPNO NUMBER(4),&lt;br /&gt;3 ENAME VARCHAR2(10),&lt;br /&gt;4 JOB VARCHAR2(9),&lt;br /&gt;5 MGR NUMBER(4),&lt;br /&gt;6 HIREDATE DATE,&lt;br /&gt;7 SAL NUMBER(7,2),&lt;br /&gt;8 COMM NUMBER(7,2),&lt;br /&gt;9 DEPTNO NUMBER(2))&lt;br /&gt;10 partition by range (SAL)&lt;br /&gt;11 (Partition p1 values less than (1000),&lt;br /&gt;12 Partition p2 values less than (2000),&lt;br /&gt;13 Partition p3 values less than (3000),&lt;br /&gt;14 Partition p4 values less than (4000),&lt;br /&gt;15 Partition max values less than (maxvalue))&lt;br /&gt;16 tablespace users;&lt;br /&gt;&lt;br /&gt;Table created. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff6600;"&gt;Step 3 &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Start the online redefinition process.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;SQL&gt; EXEC DBMS_REDEFINITION.START_REDEF_TABLE('SCOTT','EMP','EMP_PART');&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;PL/SQL procedure successfully completed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Step 4&lt;br /&gt;&lt;span style="color:#000000;"&gt;Here is where oracle10g feature come into play. We do not need to copy any dependent objects to part_emp table. Dependent objects are like grants, synonym, triggers etc.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;SQL&gt; VARIABLE NUM_ERRORS NUMBER;&lt;br /&gt;SQL&gt; EXEC DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS('SCOTT','EMP','EMP_PART', 1,TRUE,TRUE,TRUE,FALSE,&lt;br /&gt;:NUM_ERRORS,FALSE);&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; PRINT NUM_ERRORS&lt;br /&gt;&lt;br /&gt;NUM_ERRORS&lt;br /&gt;----------&lt;br /&gt;0 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;Step 5&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Resync the table&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;SQL&gt; EXEC DBMS_REDEFINITION.SYNC_INTERIM_TABLE('SCOTT','EMP','EMP_PART');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#ff6600;"&gt;Step 6&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;Complete the online redefinition&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;SQL&gt; EXEC DBMS_REDEFINITION.FINISH_REDEF_TABLE('SCOTT','EMP','EMP_PART');&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#ff6600;"&gt;Step 7&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;Make sure emp table has all partitions as we created in emp_part table&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;SQL&gt; Select partition_name, high_value from user_tab_partitions where table_name='EMP';&lt;br /&gt;&lt;br /&gt;PARTITION_NAME HIGH_VALUE&lt;br /&gt;------------------------------ ---------------------------------------------------------------------&lt;br /&gt;MAX MAXVALUE&lt;br /&gt;P1 1000&lt;br /&gt;P2 2000&lt;br /&gt;P3 3000&lt;br /&gt;P4 4000&lt;br /&gt;&lt;br /&gt;SQL&gt; select partition_name, high_value from user_tab_partitions where table_name='EMP_PART';&lt;br /&gt;&lt;br /&gt;no rows selected&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#ff6600;"&gt;Step 8&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Make sure all the dependent objects are copied .&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;SQL&gt; SELECT TRIGGER_NAME FROM USER_TRIGGERS&lt;br /&gt;2 WHERE TABLE_NAME='EMP';&lt;br /&gt;&lt;br /&gt;TRIGGER_NAME&lt;br /&gt;------------------------------&lt;br /&gt;EMPTRIG&lt;br /&gt;&lt;br /&gt;SQL&gt; select constraint_name from user_constraints&lt;br /&gt;2 where table_name='EMP';&lt;br /&gt;&lt;br /&gt;CONSTRAINT_NAME&lt;br /&gt;------------------------------&lt;br /&gt;PK_EMP&lt;br /&gt;FK_DEPTNO&lt;br /&gt;&lt;br /&gt;SQL&gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff6600;"&gt;Note : The only problem i see here is, if we have any index on the original table, it will convert to global index on partition table. If we need the index to be local index, then we have to drop and recreate the index.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt; &lt;/p&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/599273791400702751-1900856948797329247?l=myorastuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myorastuff.blogspot.com/feeds/1900856948797329247/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=599273791400702751&amp;postID=1900856948797329247' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1900856948797329247'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/599273791400702751/posts/default/1900856948797329247'/><link rel='alternate' type='text/html' href='http://myorastuff.blogspot.com/2008/11/convert-non-partitioned-to-partitioned.html' title='Convert Non-Partitioned to Partitioned Table'/><author><name>Govind</name><uri>http://www.blogger.com/profile/00856394547947096626</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://bp2.blogger.com/_b-90-vOW7is/SHjk8IHs9II/AAAAAAAAAAU/EnrBPIrz-g4/S220/DSC04278.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-599273791400702751.post-2917690237290697357</id><published>2008-11-05T13:00:00.001-08:00</published><updated>2008-12-24T21:13:58.369-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OVERFLOW'/><category scheme='http://www.blogger.com/atom/ns#' term='IOT'/><category scheme='http://www.blogger.com/atom/ns#' term='THRESHOLD'/><category scheme='http://www.blogger.com/atom/ns#' term='index organized table'/><category scheme='http://www.blogger.com/atom/ns#' term='INCLUDING'/><title type='text'>When to Use Index Organized table?</title><content type='html'>&lt;span style="color:#ff0000;"&gt;What is Index Organized table?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;In Heap tables, oracle stores the data in data segment with ROWID. When we create the index, oracle stores the index key value and ROWID in the index segment. So the index key value and rowid are stored in both index &amp;amp; data segments. Whenever we search any data record, it first scan the index segment and find the rowid and match the rowid in data segment to get the particular record. So the drawback here is, rowid &amp;amp; index key value is stored in two places. The space consumption is one issue. Another issue is, oracle has to scan both data and index segment to obtain the record.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To overcome this problem, oracle introduced IOT in version 8. In IOT, the data is stored in the primary key index itself with the rows placed in a key-sequenced order, thus eliminating the necessity of duplicate data being stored in index and table. When we search the record, it does scan only on index segment.&lt;br /&gt;&lt;br /&gt;IOT do not consider ROWID. IOT stores the data in B-tree index and sorts the data on primary key whenever we insert, update the record.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Example to create IOT&lt;/span&gt;&lt;br /&gt;&lt;p&gt;SQL&gt; CREATE TABLE iot_emp&lt;br /&
