tag:blogger.com,1999:blog-25213680121581050982024-03-13T16:26:49.566-07:00ORACLE DBA(Sharing My Experience)Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.comBlogger21125tag:blogger.com,1999:blog-2521368012158105098.post-69688428473618490572014-08-14T01:46:00.002-07:002014-08-14T01:46:17.925-07:00Non critical error ORA-48913 caught while writing to trace file "/oracle/saptrace/diag/rdbms/XXX/trace/XXX_lgwr_36503556.trc" Error message: ORA-48913: Writing into trace file failed, file size limit [10240000] reached End of report<div dir="ltr" style="text-align: left;" trbidi="on">
Oracle 11g Recommendations are below.<br />
<br />
SQL> show parameter max_dump_file<br /><br />NAME TYPE VALUE<br />------------------------------------ ----------- ------------------------------<br />max_dump_file_size string 20000<br />SQL> alter system set max_dump_file_size=UNLIMITED scope=both;<br /><br />System altered.<br /><br />SQL> show parameter max_dump_file<br /><br />NAME TYPE VALUE<br />------------------------------------ ----------- ------------------------------<br />max_dump_file_size string UNLIMITED</div>
Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com1tag:blogger.com,1999:blog-2521368012158105098.post-23556808366957402402014-08-13T00:42:00.003-07:002014-08-13T00:42:45.260-07:00Statistics In Oracle<div dir="ltr" style="text-align: left;" trbidi="on">
In this post I'll try to summarize all sorts of statistics in Oracle, I strongly recommend reading the full article, as it contains information you may find it valuable in understanding Oracle statistics.<br />
<div>
<br /></div>
<div>
################################</div>
<div>
Database | Schema | Table | Index Statistics</div>
<div>
################################</div>
<div>
<br /></div>
<div>
Gather Database Stats:</div>
<div>
===================</div>
<div>
SQL> EXEC DBMS_STATS.GATHER_DATABASE_STATS(</div>
<div>
ESTIMATE_PERCENT=>100,METHOD_OPT=>'FOR ALL COLUMNS SIZE SKEWONLY',</div>
<div>
CASCADE => TRUE,</div>
<div>
degree => 4,</div>
<div>
OPTIONS => 'GATHER STALE',</div>
<div>
GATHER_SYS => TRUE,</div>
<div>
STATTAB => PROD_STATS);</div>
<div>
<br /></div>
<div>
CASCADE => TRUE :Gather statistics on the indexes as well. If not used Oracle will determine whether to collected or not.</div>
<div>
DEGREE => 4 :Degree of parallelism.</div>
<div>
options: </div>
<div>
=>'GATHER' :Gathers statistics on all objects in the schema.</div>
<div>
=>'GATHER AUTO' :Oracle determines which objects need new statistics, and determines how to gather those statistics.</div>
<div>
=>'GATHER STALE':Gathers statistics on stale objects. will return a list of stale objects.</div>
<div>
=>'GATHER EMPTY':Gathers statistics on objects have no statistics.will return a list of no stats objects.</div>
<div>
=>'LIST AUTO' : Returns a list of objects to be processed with GATHER AUTO.</div>
<div>
=>'LIST STALE': Returns a list of stale objects as determined by looking at the *_tab_modifications views.</div>
<div>
=>'LIST EMPTY': Returns a list of objects which currently have no statistics.</div>
<div>
GATHER_SYS => TRUE :Gathers statistics on the objects owned by the 'SYS' user.</div>
<div>
STATTAB => PROD_STATS :Table will save the current statistics. see SAVE & IMPORT STATISTICS section -last third in this post-.</div>
<div>
<br /></div>
<div>
Note: All above parameters are valid for all stats kind (schema,table,..) except Gather_SYS.</div>
<div>
<br /></div>
<div>
For faster execution:</div>
<div>
------------------</div>
<div>
SQL> EXEC DBMS_STATS.GATHER_DATABASE_STATS(</div>
<div>
ESTIMATE_PERCENT=>DBMS_STATS.AUTO_SAMPLE_SIZE,degree => 8);</div>
<div>
<br /></div>
<div>
What's new?</div>
<div>
ESTIMATE_PERCENT=>DBMS_STATS.AUTO_SAMPLE_SIZE => Let Oracle estimate skewed values always gives excellent results.(DEFAULT).</div>
<div>
Removed "METHOD_OPT=>'FOR ALL COLUMNS SIZE SKEWONLY'" => As histograms is not recommended to be gathered on all columns.</div>
<div>
Removed "cascade => TRUE" To let Oracle determine whether index statistics to be collected or not.</div>
<div>
Doubled the "degree => 8" but this depends on the number of CPUs on the machine and accepted CPU overhead during gathering DB statistics.</div>
<div>
<br /></div>
<div>
This task became an automated task starting with 10g to gathers statistics on all objects in the database having stale or missing statistics, To check the status of that task:</div>
<div>
SQL> select status from dba_autotask_client where client_name = 'auto optimizer stats collection';</div>
<div>
<br /></div>
<div>
To Enable automatic optimizer statistics task:</div>
<div>
SQL> BEGIN</div>
<div>
DBMS_AUTO_TASK_ADMIN.ENABLE(</div>
<div>
client_name => 'auto optimizer stats collection', </div>
<div>
operation => NULL, </div>
<div>
window_name => NULL);</div>
<div>
END;</div>
<div>
/</div>
<div>
<br /></div>
<div>
In case you want to Disable automatic optimizer statistics task:</div>
<div>
SQL> BEGIN</div>
<div>
DBMS_AUTO_TASK_ADMIN.DISABLE(</div>
<div>
client_name => 'auto optimizer stats collection', </div>
<div>
operation => NULL, </div>
<div>
window_name => NULL);</div>
<div>
END;</div>
<div>
/</div>
<div>
<br /></div>
<div>
To check the tables that have stale statistics:</div>
<div>
<br /></div>
<div>
SQL> select OWNER,TABLE_NAME,LAST_ANALYZED,STALE_STATS from DBA_TAB_STATISTICS where STALE_STATS='YES';</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Gather SCHEMA Stats:</div>
<div>
=====================</div>
<div>
SQL> Exec DBMS_STATS.GATHER_SCHEMA_STATS (</div>
<div>
ownname =>'SCOTT',</div>
<div>
estimate_percent=>10,</div>
<div>
degree=>1,</div>
<div>
cascade=>TRUE,</div>
<div>
options=>'GATHER STALE');</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Gather TABLE Stats:</div>
<div>
===================</div>
<div>
Check table statistics date:</div>
<div>
SQL> select table_name, last_analyzed from user_tables where table_name='T1';</div>
<div>
<br /></div>
<div>
SQL> Begin DBMS_STATS.GATHER_TABLE_STATS (</div>
<div>
ownname => 'SCOTT',</div>
<div>
tabname => 'EMP',</div>
<div>
degree => 2,</div>
<div>
cascade => TRUE,</div>
<div>
METHOD_OPT => 'FOR COLUMNS SIZE AUTO',</div>
<div>
estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE);</div>
<div>
END;</div>
<div>
/</div>
<div>
<br /></div>
<div>
CASCADE => TRUE : Gather statistics on the indexes as well. If not used Oracle will determine whether to collect it or not.</div>
<div>
DEGREE => 2: Degree of parallelism.</div>
<div>
ESTIMATE_PERCENT => DBMS_STATS.AUTO_SAMPLE_SIZE : (DEFAULT) Auto set the sample size % for skew(distinct) values (accurate and faster than setting a manual sample size).</div>
<div>
METHOD_OPT=> : For gathering Histograms:</div>
<div>
FOR COLUMNS SIZE AUTO : You can specify one column between "" instead of all columns.</div>
<div>
FOR ALL COLUMNS SIZE REPEAT : Prevent deletion of histograms and collect it only for columns already have histograms.</div>
<div>
FOR ALL COLUMNS : Collect histograms on all columns.</div>
<div>
FOR ALL COLUMNS SIZE SKEWONLY : Collect histograms for columns have skewed value should test skewness first>.</div>
<div>
FOR ALL INDEXED COLUMNS : Collect histograms for columns have indexes only.</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Note: Truncating a table will not update table statistics, it will only reset the High Water Mark, you've to re-gather statistics on that table.</div>
<div>
<br /></div>
<div>
Inside "DBA BUNDLE", there is a script called "gather_stats.sh", it will help you easily & safely gather statistics on specific schema or table plus providing advanced features such as backing up/ restore new statistics in case of fallback.</div>
<div>
To learn more about "DBA BUNDLE" please visit this post:</div>
<div>
http://dba-tips.blogspot.com/2014/02/oracle-database-administration-scripts.html</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Gather Index Stats:</div>
<div>
==================</div>
<div>
SQL> exec DBMS_STATS.GATHER_INDEX_STATS(ownname => 'SCOTT',indname => 'EMP_I',</div>
<div>
estimate_percent =>DBMS_STATS.AUTO_SAMPLE_SIZE);</div>
<div>
<br /></div>
<div>
###################</div>
<div>
Fixed OBJECTS Statistics</div>
<div>
###################</div>
<div>
<br /></div>
<div>
What are Fixed objects:</div>
<div>
---------------------</div>
<div>
-Fixed objects are the x$ tables (been loaded in SGA during startup) on which V$ views are built (V$SQL etc.).</div>
<div>
-If the statistics are not gathered on fixed objects, the Optimizer will use predefined default values for the statistics. These defaults may lead to inaccurate execution plans.</div>
<div>
-Statistics on fixed objects are not being gathered automatically nor within gathering DB stats.</div>
<div>
<br /></div>
<div>
How frequent to gather stats on fixed objects?</div>
<div>
------------------------------------------</div>
<div>
Only one time for a representative workload unless you've one of these cases:</div>
<div>
<br /></div>
<div>
- After a major database or application upgrade.</div>
<div>
- After implementing a new module.</div>
<div>
- After changing the database configuration. e.g. changing the size of memory pools (sga,pga,..).</div>
<div>
- Poor performance/Hang encountered while querying dynamic views e.g. V$ views.</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Note:</div>
<div>
- It's recommended to Gather the fixed object stats during peak hours (system is busy) or after the peak hours but the sessions are still connected (even if they idle), to guarantee that the fixed object tables been populated and the statistics well represent the DB activity.</div>
<div>
- Also note that performance degradation may be experienced while the statistics are gathering.</div>
<div>
- Having no statistics is better than having a non representative statistics.</div>
<div>
<br /></div>
<div>
How to gather stats on fixed objects:</div>
<div>
----------------------------------</div>
<div>
<br /></div>
<div>
First Check the last analyzed date:</div>
<div>
---- --------------------------</div>
<div>
SQL> select OWNER, TABLE_NAME, LAST_ANALYZED</div>
<div>
from dba_tab_statistics where table_name='X$KGLDP'; </div>
<div>
Second Export the current fixed stats in a table: (in case you need to revert back)</div>
<div>
------- -----------------------------------</div>
<div>
SQL> EXEC DBMS_STATS.CREATE_STAT_TABLE</div>
<div>
('OWNER','STATS_TABLE_NAME','TABLESPACE_NAME');</div>
<div>
<br /></div>
<div>
SQL> EXEC dbms_stats.export_fixed_objects_stats</div>
<div>
(stattab=>'STATS_TABLE_NAME',statown=>'OWNER'); </div>
<div>
Third Gather the fixed objects stats:</div>
<div>
------ ------------------------</div>
<div>
SQL> exec dbms_stats.gather_fixed_objects_stats; </div>
<div>
<br /></div>
<div>
Note:</div>
<div>
In case you experienced a bad performance on fixed tables after gathering the new statistics:</div>
<div>
<br /></div>
<div>
SQL> exec dbms_stats.delete_fixed_objects_stats(); </div>
<div>
SQL> exec DBMS_STATS.import_fixed_objects_stats</div>
<div>
(stattab =>'STATS_TABLE_NAME',STATOWN =>'OWNER'); </div>
<div>
<br /></div>
<div>
<br /></div>
<div>
#################</div>
<div>
SYSTEM STATISTICS</div>
<div>
#################</div>
<div>
<br /></div>
<div>
What is system statistics:</div>
<div>
-----------------------</div>
<div>
System statistics are statistics about CPU speed and IO performance, it enables the CBO to</div>
<div>
effectively cost each operation in an execution plan. Introduced in Oracle 9i.</div>
<div>
<br /></div>
<div>
Why gathering system statistics:</div>
<div>
------------------------------</div>
<div>
Oracle highly recommends gathering system statistics during a representative workload,</div>
<div>
ideally at peak workload time, in order to provide more accurate CPU/IO cost estimates to the optimizer.</div>
<div>
You only have to gather system statistics once.</div>
<div>
<br /></div>
<div>
There are two types of system statistics (NOWORKLOAD statistics & WORKLOAD statistics):</div>
<div>
<br /></div>
<div>
NOWORKLOAD statistics:</div>
<div>
--------------------------</div>
<div>
This will simulates a workload -not the real one but a simulation- and will not collect full statistics, it's less accurate than "WORKLOAD statistics" but if you can't capture the statistics during a typical workload you can use noworkload statistics.</div>
<div>
To gather noworkload statistics:</div>
<div>
SQL> execute dbms_stats.gather_system_stats(); </div>
<div>
<br /></div>
<div>
WORKLOAD statistics:</div>
<div>
----------------------</div>
<div>
This will gather statistics during the current workload [which supposed to be representative of actual system I/O and CPU workload on the DB].</div>
<div>
To gather WORKLOAD statistics:</div>
<div>
SQL> execute dbms_stats.gather_system_stats('start'); </div>
<div>
Once the workload window ends after 1,2,3.. hours or whatever, stop the system statistics gathering:</div>
<div>
SQL> execute dbms_stats.gather_system_stats('stop'); </div>
<div>
You can use time interval (minutes) instead of issuing start/stop command manually:</div>
<div>
SQL> execute dbms_stats.gather_system_stats('interval',60); </div>
<div>
<br /></div>
<div>
Check the system values collected:</div>
<div>
-------------------------------</div>
<div>
col pname format a20</div>
<div>
col pval2 format a40</div>
<div>
select * from sys.aux_stats$; </div>
<div>
<br /></div>
<div>
cpuspeedNW: Shows the noworkload CPU speed, (average number of CPU cycles per second).</div>
<div>
ioseektim: The sum of seek time, latency time, and OS overhead time.</div>
<div>
iotfrspeed: I/O transfer speed,tells optimizer how fast the DB can read data in a single read request.</div>
<div>
cpuspeed: Stands for CPU speed during a workload statistics collection.</div>
<div>
maxthr: The maximum I/O throughput.</div>
<div>
slavethr: Average parallel slave I/O throughput.</div>
<div>
sreadtim: The Single Block Read Time statistic shows the average time for a random single block read.</div>
<div>
mreadtim: The average time (seconds) for a sequential multiblock read.</div>
<div>
mbrc: The average multiblock read count in blocks.</div>
<div>
<br /></div>
<div>
Notes:</div>
<div>
-When gathering NOWORKLOAD statistics it will gather (cpuspeedNW, ioseektim, iotfrspeed) system statistics only.</div>
<div>
-Above values can be modified manually using DBMS_STATS.SET_SYSTEM_STATS procedure.</div>
<div>
-According to Oracle, collecting workload statistics doesn't impose an additional overhead on your system.</div>
<div>
<br /></div>
<div>
Delete system statistics:</div>
<div>
---------------------</div>
<div>
SQL> execute dbms_stats.delete_system_stats(); </div>
<div>
<br /></div>
<div>
<br /></div>
<div>
####################</div>
<div>
Data Dictionary Statistics</div>
<div>
####################</div>
<div>
<br /></div>
<div>
Facts:</div>
<div>
-----</div>
<div>
> Dictionary tables are the tables owned by SYS and residing in the system tablespace.</div>
<div>
> Normally data dictionary statistics in 9i is not required unless performance issues are detected.</div>
<div>
> In 10g Statistics on the dictionary tables will be maintained via the automatic statistics gathering job run during the nightly maintenance window.</div>
<div>
<br /></div>
<div>
If you choose to switch off that job for application schema consider leaving it on for the dictionary tables. You can do this by changing the value of AUTOSTATS_TARGET from AUTO to ORACLE using the procedure:</div>
<div>
<br /></div>
<div>
SQL> Exec DBMS_STATS.SET_PARAM(AUTOSTATS_TARGET,'ORACLE'); </div>
<div>
<br /></div>
<div>
When to gather Dictionary statistics:</div>
<div>
---------------------------------</div>
<div>
-After DB upgrades.</div>
<div>
-After creation of a new big schema.</div>
<div>
-Before and after big datapump operations.</div>
<div>
<br /></div>
<div>
Check last Dictionary statistics date:</div>
<div>
----------------------------------</div>
<div>
SQL> select table_name, last_analyzed from dba_tables</div>
<div>
where owner='SYS' and table_name like '%$' order by 2; </div>
<div>
<br /></div>
<div>
Gather Dictionary Statistics: </div>
<div>
-------------------------</div>
<div>
SQL> EXEC DBMS_STATS.GATHER_DICTIONARY_STATS;</div>
<div>
->Will gather stats on 20% of SYS schema tables.</div>
<div>
or...</div>
<div>
SQL> EXEC DBMS_STATS.GATHER_SCHEMA_STATS ('SYS');</div>
<div>
->Will gather stats on 100% of SYS schema tables.</div>
<div>
or...</div>
<div>
SQL> EXEC DBMS_STATS.GATHER_DATABASE_STATS(gather_sys=>TRUE);</div>
<div>
->Will gather stats on the whole DB+SYS schema.</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
#############</div>
<div>
Extended Statistics "11g onwards"</div>
<div>
#############</div>
<div>
<br /></div>
<div>
Extended statistics can be gathered on columns based on functions or column groups.</div>
<div>
<br /></div>
<div>
Gather extended stats on column function:</div>
<div>
=====================================</div>
<div>
If you run a query having in the WHERE statement a function like upper/lower the optimizer will be off and index on that column will not be used:</div>
<div>
SQL> select count(*) from EMP where lower(ename) = 'scott'; </div>
<div>
<br /></div>
<div>
In order to make optimizer work with function based terms you need to gather extended stats:</div>
<div>
<br /></div>
<div>
1-Create extended stats:</div>
<div>
>>>>>>>>>>>>>>>>>>>>></div>
<div>
SQL> select dbms_stats.create_extended_stats('SCOTT','EMP','(lower(ENAME))') from dual;</div>
<div>
<br /></div>
<div>
2-Gather histograms:</div>
<div>
>>>>>>>>>>>>>>>>>></div>
<div>
SQL> exec dbms_stats.gather_table_stats('SCOTT','EMP', method_opt=> 'for all columns size skewonly');</div>
<div>
<br /></div>
<div>
OR</div>
<div>
--</div>
<div>
*You can do it also in one Step:</div>
<div>
>>>>>>>>>>>>>>>>>>>>>>>>></div>
<div>
<br /></div>
<div>
SQL> Begin dbms_stats.gather_table_stats</div>
<div>
(ownname => 'SCOTT',tabname => 'EMP',</div>
<div>
method_opt => 'for all columns size skewonly for</div>
<div>
columns (lower(ENAME))');</div>
<div>
end;</div>
<div>
/</div>
<div>
<br /></div>
<div>
To check the Existance of extended statistics on a table:</div>
<div>
---------------------------------------------------</div>
<div>
SQL> select extension_name,extension from dba_stat_extensions where owner='SCOTT'and table_name = 'EMP';</div>
<div>
SYS_STU2JLSDWQAFJHQST7$QK81_YB (LOWER("ENAME"))</div>
<div>
<br /></div>
<div>
Drop extended stats on column function:</div>
<div>
-------------------------------------</div>
<div>
SQL> exec dbms_stats.drop_extended_stats('SCOTT','EMP','(LOWER("ENAME"))');</div>
<div>
<br /></div>
<div>
Gather extended stats on column group: -related columns-</div>
<div>
=================================</div>
<div>
Certain columns in a table that are part of a join condition (where statement are correlated e.g.(country,state). You want to make the optimizer aware of this relationship between two columns and more instead of using separate statistics for each columns. By creating extended statistics on a group of columns, the Optimizer can determine a more accurate the relation between the columns are used together in a where clause of a SQL statement. e.g. columns like country_id and state_name the have a relationship, state like Texas can only be found in USA so the value of state_name are always influenced by country_id.</div>
<div>
If there are extra columns are referenced in the "WHERE statement with the column group the optimizer will make use of column group statistics.</div>
<div>
<br /></div>
<div>
1- create a column group:</div>
<div>
>>>>>>>>>>>>>>>>>>>>></div>
<div>
SQL> select dbms_stats.create_extended_stats('SH','CUSTOMERS', '(country_id,cust_state_province)')from dual;</div>
<div>
2- Re-gather stats|histograms for table so optimizer can use the newly generated extended statistics:</div>
<div>
>>>>>>>>>>>>>>>>>>>>>>></div>
<div>
SQL> exec dbms_stats.gather_table_stats ('SH','customers',method_opt=> 'for all columns size skewonly');</div>
<div>
<br /></div>
<div>
OR</div>
<div>
---</div>
<div>
<br /></div>
<div>
*You can do it also in one Step:</div>
<div>
>>>>>>>>>>>>>>>>>>>>>>>>></div>
<div>
<br /></div>
<div>
SQL> Begin dbms_stats.gather_table_stats</div>
<div>
(ownname => 'SH',tabname => 'CUSTOMERS',</div>
<div>
method_opt => 'for all columns size skewonly for</div>
<div>
columns (country_id,cust_state_province)');</div>
<div>
end; </div>
<div>
/</div>
<div>
<br /></div>
<div>
Drop extended stats on column group:</div>
<div>
--------------------------------------</div>
<div>
SQL> exec dbms_stats.drop_extended_stats('SH','CUSTOMERS', '(country_id,cust_state_province)');</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
########</div>
<div>
Histograms</div>
<div>
########</div>
<div>
<br /></div>
<div>
What are Histograms?</div>
<div>
-----------------------</div>
<div>
> Holds data about values within a column in a table for number of occurrences for a specific value/range.</div>
<div>
> Used by CBO to optimize a query to use whatever index Fast Full scan or table full scan.</div>
<div>
> Usually being used against columns have data being repeated frequently like country or city column.</div>
<div>
> gathering histograms on a column having distinct values (PK) is useless because values are not repeated.</div>
<div>
> Two types of Histograms can be gathered:</div>
<div>
-Frequency histograms: is when distinct values (buckets) in the column is less than 255 (e.g. the number of countries is always less than 254).</div>
<div>
-Height balanced histograms: are similar to frequency histograms in their design, but distinct values > 254</div>
<div>
See an Example: http://aseriesoftubes.com/articles/beauty-and-it/quick-guide-to-oracle-histograms</div>
<div>
> Collected by DBMS_STATS (which by default doesn't collect histograms, it deletes them if you didn't use the parameter).</div>
<div>
> Mainly being gathered on foreign key columns/columns in WHERE statement.</div>
<div>
> Help in SQL multi-table joins.</div>
<div>
> Column histograms like statistics are being stored in data dictionary.</div>
<div>
> If application exclusively uses bind variables, Oracle recommends deleting any existing histograms and disabling Oracle histograms generation.</div>
<div>
<br /></div>
<div>
Cautions:</div>
<div>
– Do not create them on Columns that are not being queried.</div>
<div>
– Do not create them on every column of every table.</div>
<div>
– Do not create them on the primary key column of a table.</div>
<div>
<br /></div>
<div>
Verify the existence of histograms:</div>
<div>
--------------------------------------</div>
<div>
SQL> select column_name,histogram from dba_tab_col_statistics</div>
<div>
where owner='SCOTT' and table_name='EMP'; </div>
<div>
<br /></div>
<div>
Creating Histograms:</div>
<div>
-----------------------</div>
<div>
e.g.</div>
<div>
SQL> Exec dbms_stats.gather_schema_stats</div>
<div>
(ownname => 'SCOTT',</div>
<div>
estimate_percent => dbms_stats.auto_sample_size,</div>
<div>
method_opt => 'for all columns size auto',</div>
<div>
degree => 7); </div>
<div>
<br /></div>
<div>
<br /></div>
<div>
method_opt:</div>
<div>
FOR COLUMNS SIZE AUTO => Fastest. you can specify one column instead of all columns.</div>
<div>
FOR ALL COLUMNS SIZE REPEAT => Prevent deletion of histograms and collect it only for columns already have histograms.</div>
<div>
FOR ALL COLUMNS => collect histograms on all columns .</div>
<div>
FOR ALL COLUMNS SIZE SKEWONLY => collect histograms for columns have skewed value .</div>
<div>
FOR ALL INDEXES COLUMNS => collect histograms for columns have indexes.</div>
<div>
<br /></div>
<div>
Note: AUTO & SKEWONLY will let Oracle decide to create the Histograms or not.</div>
<div>
<br /></div>
<div>
Check the existence of Histograms:</div>
<div>
SQL> select column_name, count(*) from dba_tab_histograms</div>
<div>
where OWNER='SCOTT' table_name='EMP' group by column_name; </div>
<div>
<br /></div>
<div>
Drop Histograms: 11g</div>
<div>
------------------</div>
<div>
e.g.</div>
<div>
SQL> Exec dbms_stats.delete_column_stats</div>
<div>
(ownname=>'SH', tabname=>'SALES',</div>
<div>
colname=>'PROD_ID', col_stat_type=> HISTOGRAM); </div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Stop gather Histograms: 11g</div>
<div>
----------------------</div>
<div>
[This will change the default table options]</div>
<div>
e.g.</div>
<div>
SQL> Exec dbms_stats.set_table_prefs</div>
<div>
('SH', 'SALES','METHOD_OPT', 'FOR ALL COLUMNS SIZE AUTO,FOR COLUMNS SIZE 1 PROD_ID');</div>
<div>
>Will continue to collect histograms as usual on all columns in the SALES table except for PROD_ID column.</div>
<div>
<br /></div>
<div>
Drop Histograms: 10g</div>
<div>
------------------</div>
<div>
e.g.</div>
<div>
SQL> exec dbms_stats.delete_column_stats(user,'T','USERNAME');</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
##################################</div>
<div>
Save/IMPORT & RESTORE STATISTICS:</div>
<div>
##################################</div>
<div>
===================</div>
<div>
Export /Import Statistics:</div>
<div>
===================</div>
<div>
In this way statistics will be exported into table then imported later from that table.</div>
<div>
<br /></div>
<div>
1-Create STATS TABLE:</div>
<div>
- -------------------------</div>
<div>
SQL> Exec dbms_stats.create_stat_table(ownname => 'SYSTEM', stattab => 'prod_stats',tblspace => 'USERS'); </div>
<div>
<br /></div>
<div>
2-Export the statistics to the STATS table:</div>
<div>
---------------------------------------------</div>
<div>
For Database stats:</div>
<div>
SQL> Exec dbms_stats.export_database_stats(statown => 'SYSTEM', stattab => 'prod_stats');</div>
<div>
For System stats:</div>
<div>
SQL> Exec dbms_stats.export_SYSTEM_stats(statown => 'SYSTEM', stattab => 'prod_stats');</div>
<div>
For Dictionary stats:</div>
<div>
SQL> Exec dbms_stats.export_Dictionary_stats(statown => 'SYSTEM', stattab => 'prod_stats');</div>
<div>
For Fixed Tables stats:</div>
<div>
SQL> Exec dbms_stats.export_FIXED_OBJECTS_stats(statown => 'SYSTEM', stattab => 'prod_stats');</div>
<div>
For Schema stas:</div>
<div>
SQL> EXEC DBMS_STATS.EXPORT_SCHEMA_STATS('ORIGINAL_SCHEMA','STATS_TABLE',NULL,'STATS_TABLE_OWNER');</div>
<div>
For Table: </div>
<div>
SQL> Conn scott/tiger</div>
<div>
SQL> Exec dbms_stats.export_TABLE_stats(ownname => 'SCOTT',tabname => 'EMP',stattab => 'prod_stats');</div>
<div>
For Index:</div>
<div>
SQL> Exec dbms_stats.export_INDEX_stats(ownname => 'SCOTT',indname => 'PK_EMP',stattab => 'prod_stats');</div>
<div>
For Column:</div>
<div>
SQL> Exec dbms_stats.export_COLUMN_stats (ownname=>'SCOTT',tabname=>'EMP',colname=>'EMPNO',stattab=>'prod_stats');</div>
<div>
<br /></div>
<div>
3-Import the statistics from PROD_STATS table to the dictionary:</div>
<div>
--------------------------------------------------------------------</div>
<div>
For Database stats:</div>
<div>
SQL> Exec DBMS_STATS.IMPORT_DATABASE_STATS</div>
<div>
(stattab => 'prod_stats',statown => 'SYSTEM'); </div>
<div>
For System stats:</div>
<div>
SQL> Exec DBMS_STATS.IMPORT_SYSTEM_STATS</div>
<div>
(stattab => 'prod_stats',statown => 'SYSTEM'); </div>
<div>
For Dictionary stats:</div>
<div>
SQL> Exec DBMS_STATS.IMPORT_Dictionary_STATS</div>
<div>
(stattab => 'prod_stats',statown => 'SYSTEM'); </div>
<div>
For Fixed Tables stats:</div>
<div>
SQL> Exec DBMS_STATS.IMPORT_FIXED_OBJECTS_STATS</div>
<div>
(stattab => 'prod_stats',statown => 'SYSTEM'); </div>
<div>
For Schema stats:</div>
<div>
SQL> Exec DBMS_STATS.IMPORT_SCHEMA_STATS</div>
<div>
(ownname => 'SCOTT',stattab => 'prod_stats', statown => 'SYSTEM');</div>
<div>
For Table stats and it's indexes: </div>
<div>
SQL> Exec dbms_stats.import_TABLE_stats</div>
<div>
( ownname => 'SCOTT', stattab => 'prod_stats',tabname => 'EMP');</div>
<div>
For Index:</div>
<div>
SQL> Exec dbms_stats.import_INDEX_stats</div>
<div>
( ownname => 'SCOTT', stattab => 'prod_stats', indname => 'PK_EMP');</div>
<div>
For COLUMN:</div>
<div>
SQL> Exec dbms_stats.import_COLUMN_stats</div>
<div>
(ownname=>'SCOTT',tabname=>'EMP',colname=>'EMPNO',stattab=>'prod_stats');</div>
<div>
<br /></div>
<div>
4-Drop Stat Table:</div>
<div>
-------------------</div>
<div>
SQL> Exec dbms_stats.DROP_STAT_TABLE (stattab => 'prod_stats',ownname => 'SYSTEM');</div>
<div>
<br /></div>
<div>
===============</div>
<div>
Restore statistics: -From Dictionary-</div>
<div>
===============</div>
<div>
Old statistics are saved automatically in SYSAUX for 31 day.</div>
<div>
<br /></div>
<div>
Restore Dictionary stats as of timestamp:</div>
<div>
-----------------------------------------</div>
<div>
SQL> Exec DBMS_STATS.RESTORE_DICTIONARY_STATS(sysdate-1); </div>
<div>
<br /></div>
<div>
Restore Database stats as of timestamp:</div>
<div>
--------------------------------------</div>
<div>
SQL> Exec DBMS_STATS.RESTORE_DATABASE_STATS(sysdate-1); </div>
<div>
<br /></div>
<div>
Restore SYSTEM stats as of timestamp:</div>
<div>
--------------------------------------</div>
<div>
SQL> Exec DBMS_STATS.RESTORE_SYSTEM_STATS(sysdate-1); </div>
<div>
<br /></div>
<div>
Restore FIXED OBJECTS stats as of timestamp:</div>
<div>
-----------------------------------------------</div>
<div>
SQL> Exec DBMS_STATS.RESTORE_FIXED_OBJECTS_STATS(sysdate-1); </div>
<div>
<br /></div>
<div>
Restore SCHEMA stats as of timestamp:</div>
<div>
---------------------------------------</div>
<div>
SQL> Exec dbms_stats.restore_SCHEMA_stats</div>
<div>
(ownname=>'SYSADM',AS_OF_TIMESTAMP=>sysdate-1); </div>
<div>
OR:</div>
<div>
SQL> Exec dbms_stats.restore_schema_stats</div>
<div>
(ownname=>'SYSADM',AS_OF_TIMESTAMP=>'20-JUL-2008 11:15:00AM');</div>
<div>
<br /></div>
<div>
Restore Table stats as of timestamp:</div>
<div>
-----------------------------------</div>
<div>
SQL> Exec DBMS_STATS.RESTORE_TABLE_STATS</div>
<div>
(ownname=>'SYSADM', tabname=>'T01POHEAD',AS_OF_TIMESTAMP=>sysdate-1);</div>
<div>
=========</div>
<div>
Advanced:</div>
<div>
=========</div>
<div>
<br /></div>
<div>
To Check current Stats history retention period (days):</div>
<div>
-------------------------------------------------</div>
<div>
SQL> select dbms_stats.get_stats_history_retention from dual;</div>
<div>
SQL> select dbms_stats.get_stats_history_availability from dual;</div>
<div>
To modify current Stats history retention period (days):</div>
<div>
-------------------------------------------------</div>
<div>
SQL> Exec dbms_stats.alter_stats_history_retention(60); </div>
<div>
<br /></div>
<div>
Purge statistics older than 10 days:</div>
<div>
------------------------------</div>
<div>
SQL> Exec DBMS_STATS.PURGE_STATS(SYSDATE-10); </div>
<div>
<br /></div>
<div>
Procedure To claim space after purging statstics:</div>
<div>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>></div>
<div>
Space will not be claimed automatically when you purge stats, you must claim it manually using this procedure:</div>
<div>
<br /></div>
<div>
Check Stats tables size:</div>
<div>
>>>>>></div>
<div>
col Mb form 9,999,999</div>
<div>
col SEGMENT_NAME form a40</div>
<div>
col SEGMENT_TYPE form a6</div>
<div>
set lines 120</div>
<div>
select sum(bytes/1024/1024) Mb,</div>
<div>
segment_name,segment_type from dba_segments</div>
<div>
where tablespace_name = 'SYSAUX'</div>
<div>
and segment_name like 'WRI$_OPTSTAT%'</div>
<div>
and segment_type='TABLE'</div>
<div>
group by segment_name,segment_type order by 1 asc</div>
<div>
/</div>
<div>
<br /></div>
<div>
Check Stats indexes size:</div>
<div>
>>>>></div>
<div>
col Mb form 9,999,999</div>
<div>
col SEGMENT_NAME form a40</div>
<div>
col SEGMENT_TYPE form a6</div>
<div>
set lines 120</div>
<div>
select sum(bytes/1024/1024) Mb, segment_name,segment_type</div>
<div>
from dba_segments</div>
<div>
where tablespace_name = 'SYSAUX'</div>
<div>
and segment_name like '%OPT%'</div>
<div>
and segment_type='INDEX'</div>
<div>
group by segment_name,segment_type order by 1 asc</div>
<div>
/ </div>
<div>
Move Stats tables in same tablespace:</div>
<div>
>>>>></div>
<div>
select 'alter table '||segment_name||' move tablespace</div>
<div>
SYSAUX;' from dba_segments</div>
<div>
where tablespace_name = 'SYSAUX'</div>
<div>
and segment_name like '%OPT%' and segment_type='TABLE'</div>
<div>
/ </div>
<div>
Rebuild stats indexes:</div>
<div>
>>>>>></div>
<div>
select 'alter index '||segment_name||' rebuild online;'</div>
<div>
from dba_segments where tablespace_name = 'SYSAUX'</div>
<div>
and segment_name like '%OPT%' and segment_type='INDEX'</div>
<div>
/</div>
<div>
<br /></div>
<div>
Check for un-usable indexes:</div>
<div>
>>>>></div>
<div>
select di.index_name,di.index_type,di.status from</div>
<div>
dba_indexes di , dba_tables dt</div>
<div>
where di.tablespace_name = 'SYSAUX'</div>
<div>
and dt.table_name = di.table_name</div>
<div>
and di.table_name like '%OPT%'</div>
<div>
order by 1 asc</div>
<div>
/ </div>
<div>
<br /></div>
<div>
Delete Statistics:</div>
<div>
===============</div>
<div>
For Database stats:</div>
<div>
SQL> Exec DBMS_STATS.DELETE_DATABASE_STATS (); </div>
<div>
For System stats:</div>
<div>
SQL> Exec DBMS_STATS.DELETE_SYSTEM_STATS (); </div>
<div>
For Dictionary stats:</div>
<div>
SQL> Exec DBMS_STATS.DELETE_DICTIONARY_STATS (); </div>
<div>
For Fixed Tables stats:</div>
<div>
SQL> Exec DBMS_STATS.DELETE_FIXED_OBJECTS_STATS (); </div>
<div>
For Schema stats:</div>
<div>
SQL> Exec DBMS_STATS.DELETE_SCHEMA_STATS ('SCOTT'); </div>
<div>
For Table stats and it's indexes:</div>
<div>
SQL> Exec dbms_stats.DELETE_TABLE_stats(ownname=>'SCOTT',tabname=>'EMP');</div>
<div>
For Index:</div>
<div>
SQL> Exec dbms_stats.DELETE_INDEX_stats(ownname => 'SCOTT',indname => 'PK_EMP');</div>
<div>
For Column:</div>
<div>
SQL> Exec dbms_stats.DELETE_COLUMN_stats(ownname =>'SCOTT',tabname=>'EMP',colname=>'EMPNO');</div>
<div>
<br /></div>
<div>
Note: This procedure can be rollback by restoring STATS using DBMS_STATS.RESTORE_ procedure.</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Pending Statistics: "11g onwards"</div>
<div>
===============</div>
<div>
What is Pending Statistics:</div>
<div>
Pending statistics is a feature let you test the new gathered statistics without letting the CBO (Cost Based Optimizer) use them "system wide" unless you publish them.</div>
<div>
<br /></div>
<div>
How to use Pending Statistics:</div>
<div>
Switch on pending statistics mode:</div>
<div>
SQL> Exec DBMS_STATS.SET_GLOBAL_PREFS('PUBLISH','FALSE');</div>
<div>
Note: Any new statistics will be gathered on the database will be marked PENDING unless you change back the previous parameter to true: </div>
<div>
SQL> Exec DBMS_STATS.SET_GLOBAL_PREFS('PUBLISH','TRUE');</div>
<div>
<br /></div>
<div>
Gather statistics: "as you used to do"</div>
<div>
SQL> Exec DBMS_STATS.GATHER_TABLE_STATS('sh','SALES'); </div>
<div>
Enable using pending statistics on your session only:</div>
<div>
SQL> Alter session set optimizer_use_pending_statistics=TRUE;</div>
<div>
Then any SQL statement you will run will use the new pending statistics...</div>
<div>
<br /></div>
<div>
When proven OK, publish the pending statistics:</div>
<div>
SQL> Exec DBMS_STATS.PUBLISH_PENDING_STATS(); </div>
<div>
<br /></div>
<div>
Once you finish don't forget to return the Global PUBLISH parameter to TRUE:</div>
<div>
SQL> Exec DBMS_STATS.SET_GLOBAL_PREFS('PUBLISH','TRUE');</div>
<div>
>If you didn't do so, all new gathered statistics on the database will be marked as PENDING, the thing may confuse you or any DBA working on this DB in case he is not aware of that parameter change.</div>
<div>
<br /></div>
<div>
Reference:</div>
<div>
http://docs.oracle.com/cd/E18283_01/appdev.112/e16760/d_stats.htm</div>
<div>
<br /></div>
<div>
This task became an automated task starting from 10g, To check the status of that task:</div>
<div>
SQL> select * from dba_autotask_client where client_name = "auto optimizer stats collection" ;</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
As per Oracle documentation, this task gathers statistics on all objects in the database which have stale or missing statistics.</div>
<div>
<br /></div>
<div>
Also you can:</div>
<div>
<br /></div>
<div>
Enable automatic optimizer statistics:</div>
<div>
SQL> BEGIN</div>
<div>
DBMS_AUTO_TASK_ADMIN.ENABLE(</div>
<div>
client_name => 'auto optimizer stats collection', </div>
<div>
operation => NULL, </div>
<div>
window_name => NULL);</div>
<div>
END;</div>
<div>
/</div>
<div>
<br /></div>
<div>
Disable automatic optimizer statistics:</div>
<div>
SQL> BEGIN</div>
<div>
DBMS_AUTO_TASK_ADMIN.DISABLE(</div>
<div>
client_name => 'auto optimizer stats collection', </div>
<div>
operation => NULL, </div>
<div>
window_name => NULL);</div>
<div>
END;</div>
<div>
/</div>
<div>
<br /></div>
<div>
To check the tables that have stale statistics:</div>
<div>
SQL> select OWNER,TABLE_NAME,LAST_ANALYZED,STALE_STATS from DBA_TAB_STATISTICS where STALE_STATS='YES';</div>
<div>
<br /></div>
<div>
I've updated the post with these information, I recommend you to check this reference:</div>
<div>
http://docs.oracle.com/cd/B28359_01/server.111/b28274/stats.htm#i41282</div>
<div>
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com0tag:blogger.com,1999:blog-2521368012158105098.post-86768291322958230552013-04-24T06:58:00.002-07:002013-04-24T06:58:53.424-07:00Handling Block Corruptions<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h3 class="post-title entry-title" itemprop="name" style="background-color: white; color: #555544; font-family: tahoma, 'Trebuchet MS', lucida, helvetica, sans-serif; font-size: 16px; margin: 5px 0px 0px; padding: 0px;">
</h3>
<h2 style="color: black; font-family: Tahoma, Verdana, Helvetica, sans-serif;">
<u>Handling Block Corruptions in Oracle7 / 8 / 8i / 9i / 10g / 11g</u></h2>
<pre style="color: black; font-weight: normal;"><h3 class="km" style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 16px; padding-top: 0.5em;">
<a href="" name="aref1"></a><a href="" name="aref1"></a><u>Contents</u></h3>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#Introduction">Introduction</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#Overview">Overview of Steps to handle a Corruption</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#NOLOG">Corruption due to NOLOGGING or UNRECOVERABLE</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#1">(1) Determine the Extent of the Corruption Problem</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#2">(2) Replace or Move Away from Suspect Hardware</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#3">(3) Which Objects are Affected ?</a>
<i>Options for various Segment Types:
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#CACHE">CACHE</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#CLUSTER">CLUSTER</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#INDEXP">INDEX PARTITION</a> <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#INDEX">INDEX</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LOBINDEX">LOBINDEX</a> <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LOB">LOBSEGMENT</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#ROLLBACK">ROLLBACK</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#TABLEP">TABLE PARTITION</a> <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#TABLE">TABLE</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#TEMPORARY">TEMPORARY</a> <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#IOT">IOT</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#UNDO">TYPE2 UNDO</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#other">Other Segment Types</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#norows">No Segment</a></i>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4">(4) Choosing a Recovery Option</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4A">(4A) Complete Recovery</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4ABL">Block Level Recovery</a> ,
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4AF">Datafile Recovery</a> ,
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4AD">Database Recovery</a> ,
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4AZ">After Complete Recovery</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4B">(4B) Recreating Indexes</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4C">(4C) Salvaging Data from Tables</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4CT">Methods of extracting data from a corrupt table AROUND a corrupt block</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4CL">Methods of extracting data from a table with a corrupt LOBSEGMENT block</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4CX">Extracting data from the corrupt block itself</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4D">(4D) Leaving the Corruption in Place</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LEAVEWARN">Warnings when Leaving a Corruption in Place</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4E">(4E) Last Options</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#HIST">Document History</a>
<i>All SQL statements here are for use in SQL*Plus (in 8.1 or higher)
or Server Manager (Oracle7 / 8.0) when connected as a SYSDBA user.
(Eg: "connect / as sysdba" or "connect internal")</i>
<a href="" name="Introduction">
</a><h3 class="km" style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 16px; padding-top: 0.5em;">
<a href="" name="Introduction"></a><a href="" name="aref2"></a><a href="" name="aref2"></a><u>Introduction</u></h3>
This article discusses how to handle one or more block corruptions
on an Oracle datafile and describes the main actions to take to deal
with them. Please read the complete article before taking any action.
This note does not cover memory corruption issues (typically
ORA-600 [17xxx] type errors).
<i><b>Note:</b> If the problem is an ORA-1578 on STARTUP then please
contact your local support center for advice referencing
Note:106638.1 - this note is not visible to customers
but the relevant steps from it can be supplied by an experienced
support analyst.
</i>
You may be referred to this article from many places for many forms of
error - it is important that you have the following information for each
corrupt block:
<br />
<ul>
<li> An absolute FILE NUMBER of the file containing the corrupt block.
Referred to as "<i>&AFN</i>" in this article.
</li>
<li> The file name of the file containing the corrupt block.
Referred to as "<i>&FILENAME</i>" in this article.
( If you know the FILE NUMBER but not its name then V$DATAFILE
can be used to get the file name:
SELECT name FROM v$datafile WHERE file#=<i>&AFN</i>;
If the file number does not appear in V$DATAFILE in Oracle8i
AND <i>&AFN</i> is greater than the DB_FILES parameter
value then it is probably a TEMPFILE. In this case the filename
can be found using:
SELECT name FROM v$tempfile
WHERE file#=(<i>&AFN</i> - <i>&DB_FILES_value</i>);
)
</li>
<li> The BLOCK NUMBER of the corrupt block in that file.
Referred to as "<i>&BL</i>" in this article.
</li>
<li> The tablespace number and name containing the affected block.
Referred to as "<i>&TSN</i>" (tablespace number) and
"<i>&TABLESPACE_NAME</i>" in this article.
If you do not know these then you can find them using:
SELECT ts# "TSN" FROM v$datafile WHERE file#=<i>&AFN</i>;
SELECT tablespace_name FROM dba_data_files WHERE file_id=<i>&AFN</i>;
</li>
<li> The block size of the tablespace where the corruption lies.
Referred to as "<i>&TS_BLOCK_SIZE</i>" in this article.
For Oracle 9i+, run the following query to determine the appropriate
block size:
SELECT block_size FROM dba_tablespaces
WHERE tablespace_name =
(SELECT tablespace_name FROM dba_data_files WHERE file_id=<i>&AFN</i>);
For Oracle 7, 8.0 and 8.1:
Every tablespace in the database has the same block size.
For these versions, issue "SHOW PARAMETER DB_BLOCK_SIZE" and
use this value as your <i>&TS_BLOCK_SIZE</i>.
</li>
</ul>
<i>Eg: For the ORA-1578 error:
ORA-01578: ORACLE data block corrupted (file # 7, block # 12698)
ORA-01110: data file 22: '/oracle1/oradata/V816/oradata/V816/users01.dbf'
then:
&AFN is "22" (from the ORA-1110 portion of the error)
&RFN is "7" (from the "file #" in the ORA-1578)
&BL is "12698" (from the "block #" in the ORA-1578)
&FILENAME is '/oracle1/oradata/V816/oradata/V816/users01.dbf'
&TSN etc.. should be determined from the above SQL
For other errors (ORA-600 , ORA-1498 etc...) the above values should
either be given to you by Oracle Support, or be given to you from the
article which covers the relevant error.
</i>
Some errors, such as ORA-1410 "invalid ROWID" , ORA-12899 "value too
large for column" etc.., do not give details of the corrupt file /
block. For such cases <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=869305.1">Note:869305.1</a> may help in locating the
corrupt row.
<a href="" name="Overview">
</a><h3 class="km" style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 16px; padding-top: 0.5em;">
<a href="" name="Overview"></a><a href="" name="aref3"></a><a href="" name="aref3"></a><u>Overview of Steps to handle a Corruption</u></h3>
There are many possible causes of a block corruption including:
- Bad IO hardware / firmware
- OS problems
- Oracle problems
- Recovering through "UNRECOVERABLE" or "NOLOGGING" database actions
<i>(in which case ORA-1578 is expected behaviour - see <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#NOLOG">below</a>)</i>
The point in time when an Oracle error is raised may be much later than
when any corruption initially occurred.
As the root cause is not usually known at the time the corruption is
encountered, and as in most cases the key requirement is to get up
and running again, then the steps used tackle corruption problems in
this article are:
1) Determine the extent of the corruption problems
and also determine if the problems are permanent or transient.
<i>If the problem is widespread or the errors move about
then focus on identifying the cause first (check hardware
etc..). This is important as there is no point recovering
a system if the underlying hardware is faulty.</i>
2) Replace or move away from any faulty or suspect hardware.
3) Determine which database objects are affected.
4) Choose the most appropriate database recovery / data salvage
option.
For all steps above it is sensible to collect evidence and
document exactly what actions are being taken. The '<i>Evidence>></i>'
tags in this article list the information which should be collected
to assist with identifying the root cause of the problem.
<a href="" name="NOLOG">
<u><b>Corruption due to NOLOGGING or UNRECOVERABLE</b></u>
If a NOLOGGING (or UNRECOVERABLE) operation is performed on an
object and the datafile containing that object is subsequently
recovered then the data blocks affected by the NOLOGGING operation
are marked as corrupt and will signal an ORA-1578 error when
accessed. In Oracle8i an ORA-26040 is also signalled
("ORA-26040: Data block was loaded using the NOLOGGING option" )
which makes the cause fairly obvious, but earlier releases have no
additional error message. If a block is corrupt due to recovery
through a NOLOGGING operation then you can use this article from
</a><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#3">Section 3 "Which Objects are Affected ?"</a> onwards but note that:
(a) Recovery cannot retrieve the NOLOGGING data
(b) No data is salvagable from inside the block
<a href="" name="1">
</a><h3 class="km" style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 16px; padding-top: 0.5em;">
<a href="" name="1"></a><a href="" name="aref4"></a><a href="" name="aref4"></a><u>(1) Determine the Extent of the Corruption Problem</u></h3>
Whenever a corruption error occurs note down the FULL error message/s
and look in the instance's alert log and trace files for any associated
errors. It is important to do this first to assess whether this is
a single block corruption, an error due to an UNRECOVERABLE operation
or a more severe issue.
It is a good idea to scan affected files (and any important files)
with DBVERIFY to check for other corruptions in order to determine
the extent of the problem.
For details of using DBVERIFY see <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=35512.1">Note:35512.1</a>
Once you have determined a list of corrupt file/block combinations
then the steps below can be used to help determine what action
can be taken.
<i><b>Evidence>></b>
- Record the original error in full, along with details of
the application which encountered the error.
- Save an extract from the alert log from a few hours before
the FIRST recorded problem up to the current point in time.
- Save any tracefiles mentioned in the alert log.
- Record any recent OS problems you have encountered.
- Note if you are using any special features - Eg: ASYNC IO,
fast write disk options etc..
- Record your current BACKUP position (Dates, Type etc...)
- Note if your database is in ARCHIVELOG mode or not
Eg: Issue "ARCHIVE LOG LIST" in SQL*Plus (or Server Manager)
</i>
<a href="" name="2">
</a><h3 class="km" style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 16px; padding-top: 0.5em;">
<a href="" name="2"></a><a href="" name="aref5"></a><a href="" name="aref5"></a><u>(2) Replace or Move Away from Suspect Hardware</u></h3>
The vast majority of corruption problems are caused by faulty hardware.
If there is a hardware fault or a suspect component then it is sensible
to either repair the problem, or make disk space available on a
separate disk sub-system prior to proceeding with a recovery option.
You can move datafiles about using the following steps:
1. Make sure the file to be relocated is either OFFLINE or
the instance is in the MOUNT state (not open)
2. Physically restore (or copy) the datafile to its new location
eg: /newlocation/myfile.dbf
3. Tell Oracle the new location of the file.
eg: ALTER DATABASE RENAME FILE '/oldlocation/myfile.dbf'
TO '/newlocation/myfile.dbf';
(Note that you cannot RENAME a TEMPFILE - TEMPFILEs should
be dropped and recreated at the new location)
4. Online the relevant file / tablespace (if database is open)
<b>IMPORTANT:</b> If there are multiple errors (which are NOT due to NOLOGGING)
OR You have OS level errors against the affected file
OR The errors are transient and keep moving about
then there is little point proceeding until the underlying problem
has been addressed or space is available on alternative disks.
Get your hardware vendor to check the system over and contact
Oracle Support with details of all errors.
<i><b>Please note:</b> Whilst a failed hardware check is a good indication
that there is a hardware issue, a successful hardware check should <b>not</b>
be taken as proof that there is no hardware related issue - it is very
common for hardware tests to report success when there really is some
underlying fault.</i>
If using any special IO options such as direct IO , async IO or
similar it may be worth disabling them in order to eliminate such options
as a potential source of problems.
<a href="" name="3">
</a><h3 class="km" style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 16px; padding-top: 0.5em;">
<a href="" name="3"></a><a href="" name="aref6"></a><a href="" name="aref6"></a><u>(3) Which Objects are Affected ?</u></h3>
It is best to determine which objects are affected BEFORE making any
decisions about how to recover - this is because the corruption/s may be
on object/s which can easily be re-created.
Eg: For a corruption on a 5 row lookup table it may be far quicker to
drop and recreate the table than to perform a recovery.
For each corruption collect the information in the following table.
The steps to do this are explained below. </pre>
<ul style="color: black; font-family: Tahoma, Verdana, Helvetica, sans-serif; font-size: small; font-weight: normal;">
<li><table border="2"><caption><b>Information to Record for each Corruption<b></b></b></caption><tbody>
<tr><td>Original<br />Error</td><td>Absolute<br />File#<br /><i>&AFN</i></td><td>Relative<br />File#<br /><i>&RFN</i></td><td>Block#<br /><br /><i>&BL</i></td><td>Tablespace</td><td>Segment<br />Type</td><td>Segment<br />Owner.Name</td><td>Related<br />Objects</td><td>Recovery<br />Options</td></tr>
<tr><td><br /></td><td><br /></td><td><br /></td><td><br /></td><td><br /></td><td><br /></td><td><br /></td><td><br /></td><td><br /></td></tr>
<tr><td><br /></td><td><br /></td><td><br /></td><td><br /></td><td><br /></td><td><br /></td><td><br /></td><td><br /></td><td><br /></td></tr>
</tbody></table>
</li>
</ul>
<pre style="color: black; font-weight: normal;"> The notes below will help you fill in this table for each corruption.
<a href="" name="OERR">
<b><u>"Original Error"</u></b>
This is the error as initially reported.
Eg: ORA-1578 / ORA-1110 , ORA-600 with all arguments etc..
</a><a href="" name="FIL">
<b><u>"Absolute File#", "Relative File#" and "Block#"</u></b>
The File# and Block# should have been given to you either by the
error, by Oracle Support, or by the steps in an error article which
directed you to this article.
In Oracle8/8i/9i/10g:
The absolute and relative file numbers are often the
same but can differ (especially if the database has
been migrated from Oracle7). It is important to get
the correct numbers for <i>&AFN</i> and <i>&RFN</i>
or you may end up salvaging the wrong object !!
An ORA-1578 reports the RELATIVE file number, with the
ABSOLUTE file number given in the accompanying ORA-1110
error. For ORA-600 errors you should be told an absolute
file number.
The following query will show the absolute and relative
file numbers for datafiles in the database:
SELECT tablespace_name, file_id "AFN", relative_fno "RFN"
FROM dba_data_files;
In Oracle8i/9i/10g:
In addition to the notes above about Oracle8, Oracle8i onwards
can have TEMPFILES. The following query will show the
absolute and relative file numbers for tempfiles in the
database:
SELECT tablespace_name, file_id+value "AFN", relative_fno "RFN"
FROM dba_temp_files, v$parameter
WHERE name='db_files';
In Oracle7: Use the same file number for both the "Absolute File#"
and the "Relative File#"
</a><a href="" name="OBJ">
<b><u>"Segment Type", "Owner", "Name" and "Tablespace"</u></b>
The following query will tell you the object TYPE , OWNER and NAME of
a segment given the absolute file number "<i>&AFN</i>" and block number "<i>&BL</i>" of the
corrupt block - the database must be open in order to use this query:
SELECT tablespace_name, segment_type, owner, segment_name
FROM dba_extents
WHERE file_id = <i>&AFN</i>
and <i>&BL</i> between block_id AND block_id + blocks - 1
;
If the block is in a TEMPFILE the above query will return no data.
For TEMPFILES the "Segment Type" will be "TEMPORARY".
If the above query does not return rows, it can also be that the corrupted block is a segment header
in a Locally Managed Tablespace (LMT). When the corrupted block is a segment
header block in a LMT, the above query produces a corruption message in the alert.log
but the query does not not fail. In that case use this query:
SELECT owner, segment_name, segment_type, partition_name
FROM dba_segments
WHERE header_file = <i>&AFN</i>
and header_block = <i>&BL</i>
;
Reference </a><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=819533.1">Note 819533.1</a>
<a href="" name="LIST">
<b><u>"Related Objects" and Possible "Recovery Options" by SEGMENT_TYPE:</u></b>
The related objects and recovery options which can be used depend on the
SEGMENT_TYPE. The additional queries and possible recovery options are
listed below for each of the most common segment types.
</a><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#CACHE">CACHE</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#CLUSTER">CLUSTER</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#INDEXP">INDEX PARTITION</a> <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#INDEX">INDEX</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LOBINDEX">LOBINDEX</a> <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LOB">LOBSEGMENT</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#ROLLBACK">ROLLBACK</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#TABLEP">TABLE PARTITION</a> <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#TABLE">TABLE</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#TEMPORARY">TEMPORARY</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#UNDO">TYPE2 UNDO</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#other">Some other Segment Type</a>
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#norows">"no rows" from the query</a>
<a href="" name="CACHE">
<b><u>CACHE</u></b>
- If the segment type is CACHE recheck you have entered the SQL
and parameters correctly.
If you get the same result contact Oracle support with all
information you have.
<b>Options:</b>
The database is likely to require recovery.
<i>{</i></a><i><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#EV">Continue</a>} {<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LIST">Back to Segment List</a>}</i>
<a href="" name="CLUSTER">
<b><u>CLUSTER</u></b>
- If the segment is a CLUSTER determine which tables it contains.
Eg:
SELECT owner, table_name
FROM dba_tables
WHERE owner='<i>&OWNER</i>'
AND cluster_name='<i>&SEGMENT_NAME</i>'
;
<b>Options:</b>
If the OWNER is "SYS" then contact Oracle support with all details.
The database is likely to require recovery.
For non dictionary clusters possible options include:
Recovery
OR Salvage data from all tables in the cluster
THEN Recreate the cluster and all its tables
As the cluster may contain a number of tables, it is best to
collect information for each table in the cluster before making a
decision.
<i>{</i></a><i><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#TABLE">Collect TABLE information</a>} {<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LIST">Back to Segment List</a>}</i>
<a href="" name="INDEXP">
<b><u>INDEX PARTITION</u></b>
- If the segment is an INDEX PARTITION note the NAME and OWNER
and then determine which partition is affected thus:
SELECT partition_name
FROM dba_extents
WHERE file_id = <i>&AFN</i>
AND <i>&BL</i> BETWEEN block_id AND block_id + blocks - 1
;
then continue below as if the segment was an INDEX segment.
<b>Options:</b>
Index partitions can be rebuilt using:
ALTER INDEX xxx REBUILD PARTITION ppp;
(take care with the REBUILD option as described in
</a><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4B">"Recreating Indexes"</a> below)
<a href="" name="INDEX">
<b><u>INDEX</u></b>
- If the segment is an INDEX then if the OWNER is "SYS" contact
Oracle support with all details.
For a non-dictionary INDEX or INDEX PARTITIONs find out which table
the INDEX is on:
Eg:
SELECT table_owner, table_name
FROM dba_indexes
WHERE owner='<i>&OWNER</i>'
AND index_name='<i>&SEGMENT_NAME</i>'
;
and determine if the index supports a CONSTRAINT:
Eg: SELECT owner, constraint_name, constraint_type, table_name
FROM dba_constraints
WHERE owner='<i>&TABLE_OWNER</i>'
AND constraint_name='<i>&INDEX_NAME</i>'
;
Possible values for CONSTRAINT_TYPE are:
P The index supports a primary key constraint.
U The index supports a unique constraint.
If the INDEX supports a PRIMARY KEY constraint (type "P") then
check if the primary key is referenced by any foreign key constraints:
Eg:
SELECT owner, constraint_name, constraint_type, table_name
FROM dba_constraints
WHERE r_owner='<i>&TABLE_OWNER</i>'
AND r_constraint_name='<i>&INDEX_NAME</i>'
;
<b>Options:</b>
If the OWNER is "SYS" then contact Oracle support with all details.
The database is likely to require recovery.
For non dictionary indexes possible options include:
Recovery
OR Recreate the index (with any associated constraint
disables/enables)
(take care with the REBUILD option as described in
</a><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4B">"Recreating Indexes"</a> below)
<i>{<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#EV">Continue</a>} {<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LIST">Back to Segment List</a>}</i>
<a href="" name="ROLLBACK">
<b><u>ROLLBACK</u></b>
- If the segment is a ROLLBACK segment contact Oracle support as
rollback segment corruptions require special handling.
<b>Options:</b>
The database is likely to require recovery.
<i>{</i></a><i><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#EV">Continue</a>} {<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LIST">Back to Segment List</a>}</i>
<a href="" name="UNDO">
<b><u>TYPE2 UNDO</u></b>
- TYPE2 UNDO is a system managed undo segment which is a special
form of rollback segment. Corruptions in these segments require
special handling.
<b>Options:</b>
The database is likely to require recovery.
<i>{</i></a><i><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#EV">Continue</a>} {<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LIST">Back to Segment List</a>}</i>
<a href="" name="TABLEP">
<b><u>TABLE PARTITION</u></b>
- If the segment is a TABLE PARTITION note the NAME and OWNER
and then determine which partition is affected thus:
SELECT partition_name
FROM dba_extents
WHERE file_id = <i>&AFN</i>
AND <i>&BL</i> BETWEEN block_id AND block_id + blocks - 1
;
then continue below as if the segment was a TABLE segment.
<b>Options:</b>
If all corruptions are in the same partition then one option
at this point is to EXCHANGE the corrupt partition with an
empty TABLE - this can allow the application to continue (without
access to the data in the corrupt partition) whilst any good
data can then be extracted from the table.
For other options see the </a><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#TABLE">TABLE</a> options below.
<a href="" name="TABLE">
<b><u>TABLE</u></b>
- If the OWNER is "SYS" then contact Oracle support with all details.
The database is likely to require recovery.
For a non-dictionary TABLE or TABLE PARTITIONs find out which
INDEXES exist on the TABLE:
Eg:
SELECT owner, index_name, index_type
FROM dba_indexes
WHERE table_owner='<i>&OWNER</i>'
AND table_name='<i>&SEGMENT_NAME</i>'
;
and determine if there is any PRIMARY key on the table:
Eg: SELECT owner, constraint_name, constraint_type, table_name
FROM dba_constraints
WHERE owner='<i>&OWNER</i>'
AND table_name='<i>&SEGMENT_NAME</i>'
AND constraint_type='P'
;
If there is a primary key then check if this is referenced by any
foreign key constraints:
Eg:
SELECT owner, constraint_name, constraint_type, table_name
FROM dba_constraints
WHERE r_owner='<i>&OWNER</i>'
AND r_constraint_name='<i>&CONSTRAINT_NAME</i>'
;
<b>Options:</b>
If the OWNER is "SYS" then contact Oracle support with all details.
The database is likely to require recovery.
For non dictionary tables possible options include:
Recovery
OR Salvage data from the table (or partition)
THEN Recreate the table (or partition)
OR Leave the corruption in place
(eg: Use DBMS_REPAIR to mark the problem blocks to be skipped)
<i>{</i></a><i><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#EV">Continue</a>} {<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LIST">Back to Segment List</a>}</i>
<a href="" name="IOT">
<b><u>IOT (Index Organized Table)</u></b>
The corruption in IOT table should be handled in the same way as in a heap or partitioned table.
The only exception is if the PK is corrupted.
PK of an IOT table is the table itself and can't be dropped and recreated.
<b>Options:</b>
If the OWNER is "SYS" then contact Oracle support with all details.
The database is likely to require recovery.
For non dictionary tables possible options include:
Recovery
OR Salvage data from the table (or partition)
THEN Recreate the table (or partition)
OR Leave the corruption in place
(DBMS_REPAIR cannot be used with IOTs)
<i>{</i></a><i><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#EV">Continue</a>} {<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LIST">Back to Segment List</a>}</i>
<a href="" name="LOBINDEX">
<b><u>LOBINDEX</u></b>
- Find out which table the LOB belongs to:
SELECT table_name, column_name
FROM dba_lobs
WHERE owner='<i>&OWNER</i>'
AND index_name='<i>&SEGMENT_NAME</i>';
- If the table is owned by "SYS" then contact Oracle support with all
details. The database is likely to require recovery.
- It is not possible to rebuild LOB indexes and so you have to
treat the problem as a corruption on the LOB column of the
affected table.
Get index and constraint information for the table which has
the corrupt LOB index using the SQL in the </a><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#TABLE">TABLE</a>
section, then return here.
<b>Options:</b>
If the OWNER is "SYS" then contact Oracle support with all details.
The database is likely to require recovery.
For non dictionary tables possible options include:
Recovery
OR Salvage data from the table (and its LOB column/s)
THEN Recreate the table
It is not generally sensible just to leave the corruption in
place unless the table is unlikely to have any further DML on
the problem column.
<i>{<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#EV">Continue</a>} {<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LIST">Back to Segment List</a>}</i>
<a href="" name="LOB">
<b><u>LOBSEGMENT</u></b>
- Find out which table the LOB belongs to:
Eg:
SELECT table_name, column_name
FROM dba_lobs
WHERE owner='<i>&OWNER</i>'
AND segment_name='<i>&SEGMENT_NAME</i>';
- If the table is owned by "SYS" then contact Oracle support with all
details. The database is likely to require recovery.
- For non-dictionary tables ...
Get index and constraint information for the table which has
the corrupt LOB data using the SQL in the </a><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#TABLE">TABLE</a>
section, then return here to find details of the exact rows
affected.
Finding the exact row which references the corrupt LOB block
can be a challenge as the errors reported do not show any
detail about which table row owns the lob entry which is corrupt.
Typically one can refer to application logs or any SQL_TRACE
or 10046 trace of a session hitting the error (if available) or
see if having event "1578 trace name errorstack level 3"
set in the session helps identify the current SQL/binds/row.
eg:
ALTER SYSTEM SET EVENTS '1578 trace name errorstack level 3';
Then wait for the error to be hit by the application
and find the trace file.
If there are no clues then you can construct a PLSQL block
to scan the problem table row by row extracting the LOB
column data which loops until it hits an error. Such a technique
may take a while but it should be possible to get a primary key
or rowid of any row which references a corrupt LOB block.
eg:
set serverout on
exec dbms_output.enable(100000);
declare
error_1578 exception;
pragma exception_init(error_1578,-1578);
n number;
cnt number:=0;
badcnt number:=0;
begin
for cursor_lob in
(select rowid r, <i>&LOB_COLUMN_NAME</i> L from <i>&OWNER</i>..<i>&TABLE_NAME</i>)
loop
begin
n:=dbms_lob.instr(cursor_lob.L,hextoraw('AA25889911'),1,999999) ;
exception
when error_1578 then
dbms_output.put_line('Got ORA-1578 reading LOB at '||cursor_lob.R);
badcnt:=badcnt+1;
end;
cnt:=cnt+1;
end loop;
dbms_output.put_line('Scanned '||cnt||' rows - saw '||badcnt||' errors');
end;
/
It is possible to have a corrupt LOB block which is only
present as an old version (for consistent read) and which has
not yet been re-used in which case all table rows will be
accessible but it may not be possible to insert / update
the LOB columns once that block is reclaimed for reuse.
<b>Options:</b>
If the OWNER is "SYS" then contact Oracle support with all details.
The database is likely to require recovery.
For non dictionary tables possible options include:
Recovery
OR Salvage data from the table (and its LOB column/s)
THEN Recreate the table
OR Leave the corruption in place
(It is not possible to use DBMS_REPAIR on LOB segments)
<i>{<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#EV">Continue</a>} {<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LIST">Back to Segment List</a>}</i>
<a href="" name="TEMPORARY">
<b><u>TEMPORARY</u></b>
- If the segment type is TEMPORARY then the corruption does not
affect a permanent object. Check if the tablespace where the
problem occurred is being used as a TEMPORARY tablespace thus:
SELECT count(*) FROM dba_users
WHERE temporary_tablespace='<i>&TABLESPACE_NAME</i>'
;
<b>Options:</b>
If this is a TEMPORARY_TABLESPACE then it may be possible
to create a NEW temporary tablespace and switch all users
to that tablespace then DROP the problem tablespace.
If this is not a temporary tablespace then the block should
not be read again and should get re-formatted next time the
block is used - the error should not repeat PROVIDED any
underlying cause has been cured.
No restore is normally required, although if the disk is
suspect and the tablespace contains useful data then a
database recovery of the affected file/s may be wise.
<i>{</i></a><i><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#EV">Continue</a>} {<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LIST">Back to Segment List</a>}</i>
<a href="" name="other">
<b><u>Some other SEGMENT_TYPE</u></b>
- If the segment type returned is not covered above then contact
Oracle support for advice with all information collected so far.
<i>{</i></a><i><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#EV">Continue</a>} {<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LIST">Back to Segment List</a>}</i>
<a href="" name="norows">
<b><u>"no rows returned"</u></b>
- If there appears to be no extent containing the corrupt block
then first double check the figures used in the query. If you
are sure the file and block are correct and do not appear as
belonging to an object in DBA_EXTENTS then:
- Double check if the file involved is a TEMPFILE.
Note that TEMPFILE file numbers depend on the init.ora
parameter DB_FILES so any changes to this parameter
change the absolute file number reported in errors.
- DBA_EXTENTS does not include blocks which are used
for local space management in locally managed tablespaces.
- If the database you are now querying is from a different
point in time to the datafile with the error then the
problem object may have been dropped and so queries against
DBA_EXTENTS may show no rows.
- If the error you are investigating was reported by DBVERIFY
then DBV checks all blocks regardless of whether they
belong to an object or not. This it is possible for a
corrupt block to exist in the datafile but in a block
not in use by any object.
<b>Options:</b>
An error on an UNUSED Oracle block can be ignored as Oracle will
create a new block image should the block need to be used so any
existing problem on the block will never get read.
If you suspect that the block may be a space management
block then you can use DBMS_SPACE_ADMIN to help check
this by running:
exec DBMS_SPACE_ADMIN.TABLESPACE_VERIFY('<i>&TABLESPACE_NAME</i>');
This should write inconsistencies to the trace file but
if it encounters a fatally corrupt block it will report an
error like:
ORA-03216: Tablespace/Segment Verification cannot proceed
An error on a bitmap space management block can often be corrected
by running:
exec DBMS_SPACE_ADMIN.TABLESPACE_REBUILD_BITMAPS('<i>&TABLESPACE_NAME</i>');
<i>{</i></a><i><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#EV">Continue</a>} {<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LIST">Back to Segment List</a>}</i>
<a href="" name="EV">
<i><b>Evidence>></b>
- For each corrupt block it is also a good idea to collect
the following physical evidence if there is a need to try
and identify the actual cause of the corruption:
i) An operating system HEX dump of the bad block and the block
either side of it.
On UNIX:
dd if=<i>&FILENAME</i> bs=<i>&TS_BLOCK_SIZE</i> skip=<i>&BL-1</i> count=3 of=BL.dd
^^^^^^^^ ^^^^^^^^^^^^^^ ^^^
Eg: For BL=1224:
dd if=ts11.dbf bs=4k skip=1223 count=3 of=1223_1225.dd
On VMS:
DUMP/BLOCKS=(start:XXXX,end:YYYY)/out=dump.out <i>&FILENAME</i>
Where XXXX=Operating system block number (in 512 byte chunks)
To calculate this multiply the block number reported by
'<i>&TS_BLOCK_SIZE</i>/512'.
ii) If you are in ARCHIVELOG mode make a safe copy of the archived
log files around the time of the error, and preferably for a few
hours before the error was reported. Also secure any backup/s
of the problem datafile from before the errors as the before
image PLUS redo can help point towards a cause.
(DBV can often be used to check if the problem exists in a
backup copy of a file). The ideal scenario is to have a
datafile backup image which does not have any corruption
and all the redo from that point in time up to and just past
the time when the corruption is first reported.
iii) Obtain an Oracle dump of the problem block/s:
ALTER SYSTEM DUMP DATAFILE '<i>&FILENAME</i>'
BLOCK <i>&BL</i>
;
(The output will go to a tracefile in the USER_DUMP_DEST).
</i>
<i>{</i></a><i><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4">Continue</a>} {<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LIST">Back to Segment List</a>}</i>
<a href="" name="4">
</a><h3 class="km" style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 16px; padding-top: 0.5em;">
<a href="" name="4"></a><a href="" name="aref7"></a><a href="" name="aref7"></a><u>(4) Choosing a Recovery Option</u></h3>
The best recovery option now depends on the objects affected. The notes
in <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#3">Section (3)</a> above should have highlighted the main options available
for each affected object. The actual recovery method chosen may include
a mix or one or more methods thus:
<u><b>Is any Recovery Required ?</b></u>
If the error is in a TEMPORARY tablespace, or is in a block
which is no longer part of any database object then no action
is required, although it may be wise to relocate the problem
tablespace to a different storage device.
See <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LEAVEWARN">Warnings</a>.
<u><b>Is Complete Recovery an option ?</b></u>
In order for complete recovery to be an option the following
must be true:
- The database is in ARCHIVELOG mode
<i>(The "ARCHIVE LOG LIST" command shows Archivelog Mode)</i>
- You have a good backup of affected files. Note that in some cases,
the corruption may have been present, but undetected, for a long
period of time. If the most recent datafile backup still contains
the corruption, you can try an earlier backup as long as you have all
the necessary ARCHIVELOGS.
<i>(You can often use the DBV START= / END= options to check
if specific block/s in a restored copy of a backup
file are corrupt)</i>
- All ARCHIVELOGS are available from the time of the backup
to the current point in time
- The current online log/s are available and intact
- The errors are NOT due to recovery through a <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#NOLOG">NOLOGGING</a> operation
When the above criteria are satisfied then complete recovery
is usually the preferred option
*BUT NOTE*
(a) If the rollback of a transaction has seen a corrupt block on an
object other than the rollback segment itself then UNDO may
have been discarded. In this case you may need to rebuild
indexes / check data integrity AFTER the recovery completes.
(b) If the files to be recovered contain data from NOLOGGING
operations performed since the last backup then those blocks
will be marked corrupt if datafile or database recovery is
used. In some cases this can put you in a worse scenario than
the current position.
If database recovery has already been performed and the corruption
is still there then either all of your backups contain the corruption,
the underlying fault is still present or the problem is replaying
through redo. In these cases you will need to choose some other
recovery option.
See "<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4A">(4A) Complete Recovery</a>" for complete recovery steps.
<u><b>Can the object be Dropped or Re-created without needing</b></u>
<b><u>to extract any data from the object itself ?</u></b>
It may be possible to lose the object, or to recreate it from
a script / recent export. Once an object is dropped then blocks
in that object are marked as "free" and will be re-formatted when
the block gets allocated to a new object. It is advisable to RENAME
rather than DROP a table unless you are absolutely sure that you
do not need any data in it.
In the case of a table partition then only the affected partition
needs to be dropped. eg: ALTER TABLE ... DROP PARTITION ...
If the corruption affects the partition segment header, or the
file containing the partition header is offline, then DROP
PARTITION may fail. In this case it may still be possible to
drop the partition by first exchanging it with a table of the
same definition.
eg: ALTER TABLE .. EXCHANGE PARTITION .. WITH TABLE ..;
The most common object which can be re-created is an index.
Always address TABLE corruptions before INDEX problems on a table.
See "<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4B">(4B) Recreating Indexes</a>" for more details.
For any segment, a quick way to extract the DDL for an object, when you
have the absolute file number and block number of the corrupt block, is:
set long 64000
select dbms_metadata.get_ddl(segment_type, segment_name, owner)
FROM dba_extents
WHERE file_id=&AFN
AND &BL BETWEEN block_id AND block_id + blocks -1;
<u><b>Is it required to salvage data before recreating the object ?</b></u>
If the problem is on a critical application table which is
regularly updated then it may be required to salvage as much
data from the table as possible, then recreate the table.
See "<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4C">(4C) Salvaging Data from Tables</a>" for more details.
<u><b>Is it acceptable to leave the corruption in place for the moment?</b></u>
In some cases the best immediate option may be to leave the
corruption in place and isolate it from application access.
See "<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4D">(4D) Leaving the Corruption In Place</a>" for more details.
<u><b>Last Options</b></u>
Are any of the following possible ?
Recovery to an old point-in-time (via point in time recovery)
of either the database or tablespace point in time recovery
OR Restore of a COLD backup from before the corruption
OR Use of an existing export file
See "<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4E">(4E) Last Options</a>" for more details.
<a href="" name="4A">
</a><h3 class="km" style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 16px; padding-top: 0.5em;">
<a href="" name="4A"></a><a href="" name="aref8"></a><a href="" name="aref8"></a><u>(4A) Complete Recovery</u></h3>
If the database is in ARCHIVELOG mode and you have a good backup
of the affected files then recovery is usually the preferred option.
This is not GUARANTEED to clear a problem, but is effective for the
majority of corruption issues. If recovery re-introduces the problem
then return to the list of options above and choose another method.
If you are using Oracle9i (or higher) then it may be possible
to perform block level recovery using the RMAN BLOCKRECOVER command.
If using an earlier Oracle release then you can either perform datafile
recovery (which can be done while the rest of the database is still up
and running), or database recovery (which requires the database to be
taken down) .
If you are using Oracle 11g (or higher) then it may be possible to use
Data Recovery Advisor (see <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=1317849.1">Note 1317849.1</a>)
<a href="" name="4ABL">
<b>Block Level Recovery</b>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
As of Oracle9i RMAN allows individual blocks to be recovered whilst the
rest of the database (including other blocks in the datafile) are available
for normal access. Note that block level recovery can only be used
to recover a block fully to the current point in time.
It is not necessary to be using RMAN for backups to be able to use this
option for recovery of individual blocks.
eg:
Consider that you have an ORA-1578 on file #6 block #30 which is likely
due to a media corruption problem and there is a good cold backup
image of that file which has been restored to '.../RESTORE/filename.dbf'.
Provided all archivelogs exist (in the default location) then you can use
RMAN to perform a block level recovery using a command sequence like:
rman nocatalog
connect target
catalog datafilecopy '.../RESTORE/filename.dbf';
run {blockrecover datafile 6 block 30;}
This will use the registered datafile backup image and any required
archivelogs to perform block recovery of just the one problem block
to current point in time.
Please see the documentation for full details of the RMAN BLOCKRECOVER
command and limitations.
See </a><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=144911.1">note 144911.1</a> for an example.
<a href="" name="4AF">
<b>Datafile Recovery</b>
~~~~~~~~~~~~~~~~~~
Datafile recovery of a file involves the following steps. If there are
several files repeat the steps for each file or see "Database Recovery"
below. These steps can be used if the database is either OPEN or MOUNTED.
OFFLINE the affected data file
eg: ALTER DATABASE DATAFILE 'name_of_file' OFFLINE;
Copy it to a safe location (in case the backup is bad)
Restore the latest backup of the file onto a GOOD disk
Check the restored file for obvious corruptions with DBVERIFY
For details of using DBVERIFY see </a><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=35512.1">Note:35512.1</a>
Assuming the restored file is OK, then RENAME the datafile to the
NEW location (if different from the old location)
eg: ALTER DATABASE RENAME FILE 'old_name' TO 'new_name';
Recover the datafile
eg: RECOVER DATAFILE 'name_of_file';
Online the file/s
eg: ALTER DATABASE DATAFILE 'name_of_file' ONLINE;
<i>{<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#EV">Continue</a>}</i>
<a href="" name="4AD">
<b>Database Recovery</b>
~~~~~~~~~~~~~~~~~
Database recovery generally involves the following steps:
Shutdown (Immediate or Abort)
Copy the current copy of all files to be recovered to a safe location
Restore the backup files to a GOOD disk location
<i>DO NOT RESTORE THE CONTROL FILES or ONLINE REDO LOG FILES</i>
Check restored files with DBVERIFY
For details of using DBVERIFY see </a><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=35512.1">Note:35512.1</a>
Startup MOUNT
Rename any relocated files
eg: ALTER DATABASE RENAME FILE 'old_name' TO 'new_name';
Ensure all required files are online
eg: ALTER DATABASE DATAFILE 'name_of_file' ONLINE;
Recover the database
eg: RECOVER DATABASE
Open the database
eg: ALTER DATABASE OPEN;
<a href="" name="4AZ">
<b>After a Complete Recovery</b>
~~~~~~~~~~~~~~~~~~~~~~~~~~
Once a complete recovery has been performed it is advisable to check the
database before allowing it to be used:
- Run "ANALYZE <i><table_name></i> VALIDATE STRUCTURE CASCADE"
against each problem object to check for table/index mis-matches.
If there has been any UNDO discarded this may show a mismatch
requiring indexes to be re-created.
- Check the logical integrity of data in the table at the application level.
</a><a href="" name="4B">
</a><h3 class="km" style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 16px; padding-top: 0.5em;">
<a href="" name="4B"></a><a href="" name="aref9"></a><a href="" name="aref9"></a><u>(4B) Recreating Indexes</u></h3>
If the corrupt object is a user INDEX you can simply drop and
re-create it PROVIDED the underlying table is not also corrupt.
If the underlying table is also corrupt it is advisable to sort out
the TABLE before recreating any indexes.
If the information collected shows that the index has dependent FOREIGN
KEY constraints then you will need to do something like this:
- ALTER TABLE <i><child_table></i> DISABLE CONSTRAINT <i><fk_constraint></i>;
for each foreign key
- Rebuild the primary key using
ALTER TABLE <i><table></i> DISABLE CONSTRAINT <i><pk_constraint></i>;
DROP INDEX <i><index_name></i>;
CREATE INDEX <i><index_name></i> .. with appropriate storage clause
ALTER TABLE <i><table></i> ENABLE CONSTRAINT <i><pk_constraint></i>;
- Enable the foreign key constraints
ALTER TABLE <i><child_table></i> ENABLE CONSTRAINT <i><fk_constraint></i>;
For an index partition you can:
ALTER INDEX ... REBUILD PARTITION ...;
<b>Notes:</b>
(1) It is important not to REBUILD a non-partitioned corrupt index
using an "ALTER INDEX .. REBUILD" command as this will usually
try to build the new index from the existing index segment,
which contains a corrupt block.
"ALTER INDEX ... REBUILD ONLINE" and "ALTER INDEX ... REBUILD
PARTITION ..." do not build the new index from the old index
segment and so can be used.
(2) Create INDEX can use the data from an existing index
if the new index is a sub-set of the columns in the
existing index. Hence if you have 2 corrupt indexes drop
them BOTH before re-creating them.
(3) Be sure to use the correct storage details when recreating indexes.
<a href="" name="4C">
</a><h3 class="km" style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 16px; padding-top: 0.5em;">
<a href="" name="4C"></a><a href="" name="aref10"></a><a href="" name="aref10"></a><u>(4C) Salvaging Data from Tables</u></h3>
If the corrupt object is a TABLE or CLUSTER or LOBSEGMENT then it
must be understood that the data within the corrupt block is lost.
Some of the data may be salvageable from a HEX dump of the block, or
from columns covered by indexes.
<b>Important:</b>
As it may be required to salvage data in the corrupt
block from the indexes it is a good idea NOT to drop
any existing index until any required data has been
extracted.
There are many ways to get data out of a table which contains a
corrupt block. Choose the most appropriate method as detailed
below. The aim of these methods is to extract as much data as
possible from the table blocks which can be accessed. It is
usually a good idea to RENAME the corrupt table so that the new
object can be created with the correct name.
Eg: RENAME <i><emp></i> TO <i><emp_corrupt></i>;
<a href="" name="4CT"><b><u>Methods of extracting data from a corrupt table AROUND a corrupt block</u></b>
(1) From Oracle 7.2 onwards, including Oracle 8.0, 8.1, and 9i, it is
possible to SKIP over corrupt blocks in a table.
This is by far the simplest option to extract table data and is
discussed in:
Extracting data using DBMS_REPAIR.SKIP_CORRUPT_BLOCKS or
Event 10231 </a><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=33405.1">Note:33405.1</a>
If the corruption is in an IOT overflow segment then the same method should
be followed, but using event 10233 together with a full index scan.
<b>Note that this method can only be used if the block "wrapper" is
marked corrupt</b>. Eg: If the block reports ORA-1578.
If the problem is an ORA-600 or other error which does not report
and ORA-1578 error then it is often possible to use DBMS_REPAIR
to mark the problem blocks in a table as "soft corrupt" such
that they will then signal ORA-1578 when accessed which then
allows you to use DBMS_REPAIR.SKIP_CORRUPT_BLOCKS.
<b>Note:</b> Any blocks which are marked corrupt by the "FIX_CORRUPT_BLOCKS"
procedure will also be marked corrupt following any restore /
recover operation through the time of the FIX_CORRUPT_BLOCKS.
Full details of using DBMS_REPAIR for this can be found in the
documentation but in summary the steps are:
- Use DBMS_REPAIR.ADMIN_TABLES to create the admin tables
- Use DBMS_REPAIR.CHECK_OBJECT to find problem blocks
- Get any good data out of problem blocks before corrupting them.
- Use DBMS_REPAIR.FIX_CORRUPT_BLOCKS to mark the found problem
blocks as corrupt so that they will then signal ORA-1578
- If required use DBMS_REPAIR.SKIP_CORRUPT_BLOCKS to skip corrupt
blocks on the table.
(2) From Oracle 7.1 onwards you can use a ROWID range scan.
The syntax for this is a little tricky but it is possible
to select around a corrupt block using a ROWID hint.
As the format of ROWIDs changed between Oracle7 and Oracle8
there are 2 articles which discuss this:
Using ROWID Range Scans to extract data in Oracle8 and higher <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=61685.1">Note:61685.1</a>
Using ROWID Range Scans to extract data in Oracle7 <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=34371.1">Note:34371.1</a>
(3) If there is a primary key you can select table data via this index.
It may also be possible to select some of data via any other index.
This can be slow and time consuming and is only normally needed
for Oracle 7.0 releases. This method is described in <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=34371.1">Note:34371.1</a>
(which also describes the ROWID range scans)
(4) There are various salvage programs / PLSQL scripts which can be
used to salvage data from a table. These can take longer to set
up and use than the above methods but can often cope with various
kinds of corruption besides an ORA-1578.
<b><i>As these methods typically require much hand-holding from
support then some of these articles may not be visible to customers.</i></b>
<i>These require Pro*C to be available and an understanding of how
to build Pro*C executables:</i>
SALVAGE.PC for Oracle7 <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=2077307.6">Note:2077307.6</a>
<i>These requires manual interaction:</i>
SALVAGE.SQL for Oracle7/8 <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=2064553.4">Note:2064553.4</a>
<a href="" name="4CL"><b><u>Methods of extracting data from a table with a corrupt LOBSEGMENT block</u></b>
It is not possible to used DBMS_REPAIR on LOB segments.
If the corrupt LOB block is NOT referenced by any row in the table
then it should be possible to CREATE TABLE as SELECT (CTAS) or
export / drop / import the table as is.
If the corrupt LOB block is referenced by a row then it should be
possible to select or export with a WHERE predicate that excludes
the problem row/s.
</a><a href="" name="LOBWARN">WARNING:
It is possible to update the LOB column value
of a problem row to NULL which will then clear
ORA-1578 on SELECT operations *BUT* the corrupt
block will then be waiting to be reclaimed and will
eventually signal an ORA-1578 on attempts to get a
new LOB for INSERT or UPDATE operations on any row
which can be a worse situation than having a corruption
on a known row.
Hence you should only really set the LOB column to NULL
if you intend to immediately recreate the table.
</a><a href="" name="4CX"><b><u>Extracting data from the corrupt block itself</u></b>
As the corrupt block itself is "corrupt" then any data extracted
from the block should be treated as suspect. The main methods
of getting the rows from the corrupt block itself are:
- For TABLE blocks Oracle Support can use a tool which attempts to
interpret the block contents.
- Use any existing indexes on the table to extract data for
columns covered by the index where the ROWID falls inside the
corrupt block. This is described towards the end of the ROWID
range scan articles mentioned above:
For Oracle8/8i see </a><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=61685.1">Note:61685.1</a>
For Oracle7 see <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=34371.1">Note:34371.1</a>
- It may be possible to use LogMiner on the redo stream
to find the original inserts/updates which loaded the
data to the problem block. The main factor here is
WHEN the data was actually put in the block.
eg; row 2 may have been inserted yesterday but row 1 may
have been inserted 5 years ago.
<a href="" name="LEAVE"> </a><a href="" name="4D">
</a><h3 class="km" style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 16px; padding-top: 0.5em;">
<a href="" name="4D"></a><a href="" name="aref11"></a><a href="" name="aref11"></a><u>(4D) Leaving A Corruption In Place</u></h3>
It is possible to leave a corruption in place and just accept the
errors reported, or prevent access to the problem rows at an application
level.
eg: If the problem block / row is in a child table then it may be possible
at application level to prevent access via the parent row/s such that
the child rows are never accessed. (Be wary of cascade type constraints
though)
This may not help with reports and other jobs which access data in
bulk so it may also be desirable to use the DBMS_REPAIR options
shown in <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#4C">4C</a> above to prevent the block/s erroring when
accessed. Marking a corruption like this and leaving it around may
give a short term solution allowing full data salvage and/or recovery
to be attempted at scheduled outage, or allowing time to check other
recovery options on a second (clone) database. Note though that
marking a block corrupt with DBMS_REPAIR.FIX_CORRUPT_BLOCKS will cause
the marked block/s to also be corrupt after recovery through the
time that FIX_CORRUPT_BLOCKS was executed.
Leaving a corruption may be sensible for data which rapidly ages and is
subsequently purged (eg: In a date partitioned table where older
partitions are dropped at some point).
<a href="" name="LEAVELOB"><b>Leaving Corruptions in LOB segments</b>
At application level it can be possible to leave a corrupt
LOB column in place until such time as the table can be rebuilt.
One way to ensure you do not hit the </a><a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?_afrLoop=358815101388126&id=28814.1&_afrWindowMode=0&_adf.ctrl-state=v7vajsj1b_464#LOBWARN">"WARNING"</a> scenario above
is to ensure that the table is only ever accessed via a view
which includes a WHERE predicate to prevent the problem row/s
from being seen.
eg: Consider table MYTAB( a number primary key, b clob ) has
one or more rows pointing at corrupt LOB data.
ALTER TABLE MYTAB ADD ( BAD VARCHAR2(1) );
CREATE VIEW MYVIEW AS SELECT a,b FROM MYTAB WHERE BAD is null;
Set BAD='Y' for any problem row/s
If you only access MYTAB via MYVIEW and the row will never be visible
and so cannot be updated keeping the corrupt entry isolated until it
can be dealt with.
Clearly this example is more of a design time solution but some
applications may already have similar mechanisms and may only access data
via a view (or via an RLS policy) giving some option/s to hide the problem
row/s.
<a href="" name="LEAVEWARN"><b>Warnings when Leaving a Corruption in Place</b>
Whilst it is possible to leave a corruption in place it should be
noted that the corrupt blocks will still show up in runs of DBVERIFY,
in RMAN backup warnings / errors etc..
It is important to make a careful record of any corruption you
expect to see from these tools, particularly any blocks you expect
to skip with RMAN (eg: having MAX_CORRUPT set) and be sure to remove
any "acceptance" of the errors once the corruptions have been cleared.
eg: Consider that a corrupt block has been handled by leaving the corruption
in place and avoiding the problem row/s at application level.
RMAN may be configured to allow the corruptions during backup.
The table is then recreated at a later date during some table
reorganisation.
If RMAN is not updated to reflect that no errors should now be
expected then RMAN may ignore some other corruption which occurs
at a later time.
It is also important to note that leaving corrupt blocks around in
table segments can lead to mismatched results from queries
eg: different results can occur for tables with SKIP_CORRUPT set
depending on whether an index scan or table access occurs.
Other reports may just error .
Note that leaving a corruption in place but marking the block with
DBMS_REPAIR.FIX_CORRUPT_BLOCKS writes redo to corrupt the block
which may limit subsequent recovery options.
</a><a href="" name="4E">
</a><h3 class="km" style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 16px; padding-top: 0.5em;">
<a href="" name="4E"></a><a href="" name="aref12"></a><a href="" name="aref12"></a><u>(4E) Last Options</u></h3>
If you have a standby setup (physical or logical) then check that first.
Whatever sort of block the problem occurred on, one possible option
is to recover the database, or problem tablespace, to a point in time
BEFORE the corruption appeared. The difficulty with this option is that
it is not always possible to know when the problem first appeared.
DBVERIFY can be often be used to check a restored file for corruptions.
For details of using DBVERIFY see <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=35512.1">Note:35512.1</a> . In particular the
START= / END= DBV options can be used to give a quick first test of whether
the problem block itself is bad on a restored backup image.
This section outlines some final options available for recovering.
If you have come here then one or more of the following have happened:
- You have lost a "vital" datafile (or have a corruption on it)
and have no good backup of the problem file/s (without the corruption)
- Are either not in ARCHIVELOG mode OR do not have all archivelogs
since the file was first created
- Complete recovery keeps reintroducing the problem
Last chance:
Please note if you have lost all copies of a datafile but DO still have
the ARCHIVE logs from when the file was first created it is still possible
to recover the file.
Eg:
ALTER DATABASE CREATE DATAFILE '....' [as '...'] ;
RECOVER DATAFILE '....'
ALTER DATABASE DATAFILE '....' ONLINE;
If you are in this scenario try to recover the datafile using these
steps before proceeding below.
If you have reached this line there are no options left to recover to
the current point in time. It is advisable to shutdown the instance and
take a BACKUP of the current database NOW in order to provide a fall-back
position if the chosen course of action fails. (Eg: if you find your backup
is bad).
Some outline options available are:
Revert to an old COLD backup
- eg: If in NOARCHIVELOG mode
Set up a clone database from a COLD backup
- and extract (export) the problem table/s
or transport the problem tablespace
Point in time recovery to an older point in time that is consistent
- requires a good backup and any necessary archive logs
- ALL files have to be restored and the whole DB rolled forward
to a suitable point in time.
- It may be possible to do the point in time recovery in a
clone database and then transport the problem tablespace
to the problem database, or export / import the problem table
from the clone to the problem database .
Tablespace point in time recovery
- It may be possible to perform a point in time recovery
of the affected tablespace only. There are many notes
describing tablespace point in time recovery such as
<a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=223543.1">Note:223543.1</a>.
Rebuild of DB from some logical export / copy
- Requires there to already be a good logical backup of the database
- NB: You have to RE-CREATE the database for this option.
- As with other options the rebuild could be in a clone database
just to get a good image of the problem table/s.
If you have a good backup then rolling forwards with DB_BLOCK_CHECKING=TRUE
can help find the first point in time where something started to go wrong.
It is not generally necessary to take the problem database down while
investigating the recovery options.
eg: You can restore the system tablespace and problem tablespace
datafiles only to a totally different location and/or machine
as a different instance to investigate how far you can roll forwards etc..
As of Oracle9i you can also use "Trial Recovery" options to save
having to keep restoring a backup while looking into your options.
</pre>
<div>
<br /></div>
<h3 class="post-title entry-title" itemprop="name" style="background-color: white; color: #555544; font-family: tahoma, 'Trebuchet MS', lucida, helvetica, sans-serif; font-size: 16px; margin: 5px 0px 0px; padding: 0px;">
<br /></h3>
<h3 class="post-title entry-title" itemprop="name" style="background-color: white; color: #555544; font-family: tahoma, 'Trebuchet MS', lucida, helvetica, sans-serif; font-size: 16px; margin: 5px 0px 0px; padding: 0px;">
<br /></h3>
<h3 class="post-title entry-title" itemprop="name" style="background-color: white; color: #555544; font-family: tahoma, 'Trebuchet MS', lucida, helvetica, sans-serif; font-size: 16px; margin: 5px 0px 0px; padding: 0px;">
Script To Run DBV On All Datafiles Of the Database</h3>
<div class="post-header" style="background-color: white; color: #555544; font-family: tahoma, 'Trebuchet MS', lucida, helvetica, sans-serif; font-size: 13px;">
<div class="post-header-line-1">
</div>
</div>
<div class="post-body entry-content" id="post-body-2719425103877496973" itemprop="description articleBody" style="color: #555544; font-family: tahoma, 'Trebuchet MS', lucida, helvetica, sans-serif; font-size: 13px; line-height: 18px; margin-bottom: 1em; margin-top: 5px;">
<span xmlns=""><div style="background-color: white;">
<table border="0" style="border-collapse: collapse;"><colgroup><col style="width: 399px;"></col></colgroup><tbody valign="top">
<tr><td valign="middle"> </td></tr>
</tbody></table>
</div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<span style="font-family: 'Times New Roman'; font-size: 12pt;">This script will simplify the task of running DBV on the all datafiles of a database.</span></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<span style="font-family: 'Times New Roman'; font-size: 12pt;">When user experiences ORA-01578 / ORA-08103 or any other kind of corrupt messages this utility can be used to scan the datafiles at OS level.</span></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<span style="font-family: 'Times New Roman'; font-size: 12pt;"><a href="" name="SWREQS">We need to have the database atleast in MOUNT stage to perform this operation.</a></span></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="SWREQS"><span style="color: #333333; font-family: Arial; font-size: 12pt;"><strong></strong></span></a><strong><a href="" name="CONFIG">Configuring the Script</a></strong></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="CONFIG"><span style="font-family: 'Times New Roman'; font-size: 12pt;"> Login to your server as the oracle user, and create a directory that is going to hold the DBV logs.</span></a></div>
<div style="background-color: #eef3f7; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="CONFIG"><span style="font-family: 'Courier New';">mkdir /tmp/dbvlogs<br />cd /tmp/dbvlogs </span><span style="font-family: 'Times New Roman'; font-size: 12pt;"><br /></span></a></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="CONFIG"> </a><strong><a href="" name="RUNSTEPS">Running the Script</a></strong></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="RUNSTEPS"><span style="font-family: 'Times New Roman'; font-size: 12pt;"> As a first step run the following script from sqlplus which will generate the script for DBV</span></a></div>
<div style="background-color: #eef3f7; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="RUNSTEPS"><span style="font-family: 'Times New Roman'; font-size: 12pt;">sqlplus /nolog <br />connect / as sysdba <br />set feedback off <br />set head off <br />set echo off <br />set linesize 200 <br />set pagesize 2500 <br />spool /tmp/dbvlogs/dbvchk.sh <br />select 'dbv file=' || name || ' blocksize='|| block_size || ' logfile=' || <br />substr(name, instr(name, '/', -1, 1) +1) ||<br />'.' || file# || '.log' from v$datafile <br />/ <br />spool off <br /> </span></a></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="RUNSTEPS"><br /></a><a href="" name="RUNSTEPS"> </a></div>
<div style="background-color: #92d050; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="RUNSTEPS"><span style="color: red; font-family: Arial; font-size: 10pt;">Incase if datafiles are in <strong>RAW devices</strong>, then we need to mention the END parameter in DBV.<br />You can use the following query incase if you are using RAW devices. </span></a></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<br /></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<br /></div>
<div style="background-color: #eef3f7; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="RUNSTEPS"><span style="font-family: 'Courier New';"><span style="font-size: 9pt;">select 'dbv file=' || name || ' blocksize='|| block_size || ' end=' ||(bytes/block_size) ||' logfile=' || <br />substr(name, instr(name, '/', -1, 1) +1) || <br />'.' || file# || '.log' from v$datafile <br />/ </span><span style="font-size: 10pt;"><br /></span></span></a></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="RUNSTEPS"><br /> </a></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="RUNSTEPS"><span style="font-family: 'Courier New'; font-size: 10pt;"> -- For Windows the following modification is required</span></a></div>
<div style="background-color: #eef3f7; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="RUNSTEPS"><span style="font-family: 'Courier New'; font-size: 10pt;"><br /><br />select 'dbv file=' || name || ' blocksize='|| block_size ||<br />' logfile=' || substr(name, instr(name, '\', -1, 1) +1) ||<br />'.' || file# || '.log' from v$datafile <br />/<br /></span></a></div>
<div style="background-color: #92d050; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="RUNSTEPS"><span style="color: red; font-family: Arial; font-size: 10pt;">If <strong>ASM storage</strong> being used, we need to specify USERID to get authenticated on ASM Instance.<br />You can use following query if you are running in ASM storage.</span></a></div>
<div style="background-color: #92d050; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="RUNSTEPS"><br /> </a></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<br /></div>
<div style="background-color: #eef3f7; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="RUNSTEPS"><span style="font-family: 'Times New Roman'; font-size: 12pt;">select 'dbv file=' || name || ' blocksize='|| block_size || ' USERID=sys/&SYS_PASSWORD logfile=' ||<br />substr(name, instr(name, '/', -1, 1) +1) ||<br />'.' || file# || '.log' from v$datafile<br />/</span></a></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="RUNSTEPS"><span style="color: #333333; font-family: Arial; font-size: 12pt;"><strong></strong></span></a><strong><a href="" name="ADDINFO">Script</a></strong></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="ADDINFO"><span style="font-family: 'Times New Roman'; font-size: 12pt;">Now you need to run the dbv commands for all the datafiles, which is spooled to dbvchk.sh. </span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Times New Roman'; font-size: 12pt;"><br /></span></a></div>
<div style="margin-bottom: 1em; margin-top: 5px;">
<a href="" name="ADDINFO"><span style="font-family: Arial; font-size: 12pt;"><strong style="background-color: white;"><span style="color: #92d050;">Please proof read this script before executing the same</span>.</strong></span></a></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="ADDINFO"><br /> </a></div>
<div style="background-color: #eef3f7; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="ADDINFO"><span style="font-family: 'Times New Roman'; font-size: 12pt;">$ cd /tmp/dbvlogs<br />$ chmod 755 dbvchk.sh <br />$ ./dbvchk.sh </span></a></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="ADDINFO"><br /> </a></div>
<div style="background-color: #fefcee; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="ADDINFO"><span style="font-family: Arial; font-size: 12pt;">In case of Windows, just run the above file. Its more appropriate to have a .bat extention for windows.</span></a></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="ADDINFO"><span style="font-family: 'Times New Roman'; font-size: 12pt;">If you have a tar logged then, compress the log files, upload the above compressed file to metalink.</span></a></div>
<div style="background-color: #eef3f7; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="ADDINFO"><span style="font-family: 'Times New Roman'; font-size: 12pt;">$ tar cvf dbvlogs.tar *.log<br />$ compress dbvlogs.tar.Z </span></a></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="ADDINFO"><br /> </a></div>
<div style="background-color: #fefcee; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="ADDINFO"><span style="font-family: Arial; font-size: 12pt;">In case of Windows operating system, simply use the winzip utility to compress the files.</span></a></div>
<div style="background-color: white; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="ADDINFO"><span style="color: #333333; font-family: Arial; font-size: 12pt;"><strong></strong></span></a><strong><a href="" name="OUTPUT">Script Output</a></strong></div>
<div style="background-color: #92d050; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="OUTPUT"><span style="font-family: 'Times New Roman'; font-size: 12pt;"> As per the above script the dbv logs will be generated under /tmp/dbvlogs directory.<br />The files will have the name as follows.</span></a></div>
<div style="background-color: #92d050; margin-bottom: 1em; margin-top: 5px;">
<a href="" name="OUTPUT"><span style="font-family: Arial; font-size: 12pt;">For system datafile with the name /tmp/system.dbf and file# 1 the logfile will have the name like.<br /><br /><strong>/tmp/dbvlogs/system.dbf.1.log</strong></span></a></div>
</span></div>
</div>
Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com1tag:blogger.com,1999:blog-2521368012158105098.post-70100324751051320262013-03-08T02:09:00.000-08:002013-03-08T02:24:53.805-08:00Restore RMAN Incremental backup to new server<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #333333; font-family: Calibri; font-size: 12pt; line-height: 18px;">Restore 10gR2 Database incremental backup to a new server using RMAN. The method I used here will not use RMAN catalog database assuming that you have only database backup.</span><br />
<div class="post-body entry-content" id="post-body-7992471584860668786" itemprop="description articleBody" style="background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 1.4; position: relative; width: 648px;">
<div dir="ltr" trbidi="on">
<span style="font-size: 12pt; line-height: 18px;"><span closure_uid_f2q5tf="119" style="font-family: Calibri;"></span></span><br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<b><u>RMAN Backup Configuration</u></b></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
Daily : Incremental Level 1 cumulative</div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
Weekly: Incremental Level 0</div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
Retention Policy: RECOVERY WINDOW OF 7 DAYS</div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
Device: Disk</div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
Control File Autobackup: on</div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
In this, assume that following directories are used to restoring DB</div>
<div class="MsoNormal" closure_uid_f2q5tf="120" style="margin: 0in 0in 10pt;">
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: medium none; margin: auto auto auto 31.1pt;"><tbody>
<tr><td style="background-color: transparent; border: 1pt solid windowtext; padding: 0in 5.4pt; width: 208.6pt;" valign="top" width="278"><div class="MsoNormal" style="margin: 0in 0in 0pt;">
<span style="font-family: 'Times New Roman', serif; font-size: 10pt;">DB Name</span><span style="font-family: Arial, sans-serif;"></span></div>
</td><td style="background-color: transparent; border-bottom-style: solid; border-bottom-width: 1pt; border-color: windowtext windowtext windowtext rgb(236, 233, 216); border-right-style: solid; border-right-width: 1pt; border-top-style: solid; border-top-width: 1pt; padding: 0in 5.4pt; width: 198.2pt;" valign="top" width="264"><div class="MsoNormal" style="margin: 0in 0in 0pt;">
<span style="font-family: 'Times New Roman', serif; font-size: 10pt;">ORCL1</span><span style="font-family: Arial, sans-serif;"></span></div>
</td></tr>
<tr><td style="background-color: transparent; border-bottom-style: solid; border-bottom-width: 1pt; border-color: rgb(236, 233, 216) windowtext windowtext; border-left-style: solid; border-left-width: 1pt; border-right-style: solid; border-right-width: 1pt; padding: 0in 5.4pt; width: 208.6pt;" valign="top" width="278"><div class="MsoNormal" style="margin: 0in 0in 0pt;">
<span style="font-family: 'Times New Roman', serif; font-size: 10pt;">u04/ORCL1/flash_recovery_area</span><span style="font-family: Arial, sans-serif;"></span></div>
</td><td style="background-color: transparent; border-bottom-style: solid; border-bottom-width: 1pt; border-color: rgb(236, 233, 216) windowtext windowtext rgb(236, 233, 216); border-right-style: solid; border-right-width: 1pt; padding: 0in 5.4pt; width: 198.2pt;" valign="top" width="264"><div class="MsoNormal" style="margin: 0in 0in 0pt;">
<span style="font-family: 'Times New Roman', serif; font-size: 10pt;">Flash Recovery Area</span><span style="font-family: Arial, sans-serif;"></span></div>
</td></tr>
<tr><td style="background-color: transparent; border-bottom-style: solid; border-bottom-width: 1pt; border-color: rgb(236, 233, 216) windowtext windowtext; border-left-style: solid; border-left-width: 1pt; border-right-style: solid; border-right-width: 1pt; padding: 0in 5.4pt; width: 208.6pt;" valign="top" width="278"><div class="MsoNormal" style="margin: 0in 0in 0pt;">
<span style="font-family: 'Times New Roman', serif; font-size: 10pt;">/u01/ ORCL1/oracle/admin</span><span style="font-family: Arial, sans-serif;"></span></div>
</td><td style="background-color: transparent; border-bottom-style: solid; border-bottom-width: 1pt; border-color: rgb(236, 233, 216) windowtext windowtext rgb(236, 233, 216); border-right-style: solid; border-right-width: 1pt; padding: 0in 5.4pt; width: 198.2pt;" valign="top" width="264"><div class="MsoNormal" style="margin: 0in 0in 0pt;">
<span style="font-family: 'Times New Roman', serif; font-size: 10pt;">ORACLE_BASE</span><span style="font-family: Arial, sans-serif;"></span></div>
</td></tr>
<tr><td style="background-color: transparent; border-bottom-style: solid; border-bottom-width: 1pt; border-color: rgb(236, 233, 216) windowtext windowtext; border-left-style: solid; border-left-width: 1pt; border-right-style: solid; border-right-width: 1pt; padding: 0in 5.4pt; width: 208.6pt;" valign="top" width="278"><div class="MsoNormal" style="margin: 0in 0in 0pt;">
<span style="font-family: 'Times New Roman', serif; font-size: 10pt;">/u04/ ORCL1/oradata</span><span style="font-family: Arial, sans-serif;"></span></div>
</td><td style="background-color: transparent; border-bottom-style: solid; border-bottom-width: 1pt; border-color: rgb(236, 233, 216) windowtext windowtext rgb(236, 233, 216); border-right-style: solid; border-right-width: 1pt; padding: 0in 5.4pt; width: 198.2pt;" valign="top" width="264"><div class="MsoNormal" style="margin: 0in 0in 0pt;">
<span style="font-family: 'Times New Roman', serif; font-size: 10pt;">To store datafile</span><span style="font-family: Arial, sans-serif;"></span></div>
</td></tr>
</tbody></table>
</div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<b><u><span style="font-family: Calibri;">Pre-requisite for restore</span></u></b></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">1.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">You must know DBID of the database to be restored.</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">2.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">A valid backup is required.</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">3.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">Sufficient Disk Space on the server to restore the backup.</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">4.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">If restoring from tape, Tape Library must be configured to the server for restoring.</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">5.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">Server OS/Architecture must be same as the backed up database server.</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">6.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">All recommended patches and tuning must be done on the server as per Oracle documentation.</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">7.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">Oracle Software of same version of backed up database must be installed.</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">8.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">Oracle Software must be patched similar to backed up database.</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<b><u><span style="font-family: Calibri;">Performing Complete Recovery</span></u></b></div>
<div class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">1.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;"><u>Restore the backup: </u>Once the server is ready with all pre-requisites, restore the backup to the specific directory/directories. Here it will be to the flash recovery area<u></u></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.25in; text-align: justify; text-indent: -0.25in;">
<span style="font-family: Calibri;">2.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;"><b>Verify the directory and file permissions:</b> Oracle user and dba group must have full permission on the restored directory and files. Owner of the files must be oracle user.</span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.25in; text-align: justify; text-indent: -0.25in;">
<span style="font-family: Calibri;">3.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;"><b>Parameter file:</b> Identify the backup piece from the Latest CONTROLFILE and SPFILE backups located in restored $Flash_Recovery_Area/autobackup/</span></div>
<div class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.25in; text-align: justify; text-indent: -0.25in;">
<span style="font-family: Calibri;">4.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;"><b>Parameter file:</b> Identify the backup piece from the Latest CONTROLFILE and SPFILE backups located in restored $Flash_Recovery_Area/autobackup/<latest date>. Filename usually starts with o1_mf_s_ if you are backing up spfile with controlfile autobackup, otherwise Filename look like o1_mf_n_</span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt 0.25in; text-align: justify;">
<span style="font-family: Calibri;">If the parameter file is not backed up as part of your backup strategy, you must create it manually.</span></div>
<div class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">5.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">Add entry for LISTENER_ORCL1 in $ORACLE_HOME/network/admin/tnsnames.ora<u></u></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">6.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">Restore SPFILE as follows. SPIFLE will be restored in $ORACLE_HOME/dbs (If you don’t have spfile in autobackup you will have to create it manually)<u></u></span></div>
<div class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.25in;">
<br /></div>
<div style="border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt 1pt 31pt;">
<div class="MsoNormal" style="border: medium none; margin: 0in 0in 10pt; padding: 0in;">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 14px;">$ export ORACLE_SID=</span><span style="font-family: Calibri;"> ORCL1<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 14px;"></span></span></div>
<div class="MsoNormal" style="border: medium none; margin: 0in 0in 10pt; padding: 0in;">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 14px;">$ rman target /</span></div>
<div class="MsoNormal" style="border: medium none; margin: 0in 0in 10pt; padding: 0in;">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 14px;">RMAN> startup nomount</span></div>
<div class="MsoNormal" style="border: medium none; margin: 0in 0in 10pt; padding: 0in;">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 14px;">RMAN> set DBID=</span><span style="font-family: 'Courier New';"><DBID of your database></span><span style="font-family: 'Courier New'; font-size: 10pt; line-height: 14px;"></span></div>
<div class="MsoNormal" style="border: medium none; margin: 0in 0in 10pt; padding: 0in;">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 14px;">RMAN> restore spfile from "<$FLASH_RECOVERY_AREA>/autobackup/<latest directory>/o1_mf_s_751194987_6wyrfc7d_.bkp ";</span></div>
</div>
<div class="MsoListParagraph" style="margin: 0in 0in 10pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">7.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">Create PFILE (initORCL1.ora) from SPFILE;</span></div>
<div style="border: 1pt solid windowtext; margin-left: 0.25in; margin-right: 0in; padding: 1pt 4pt;">
<div class="MsoNormal" style="border: medium none; margin: 0in 0in 10pt; padding: 0in;">
<span style="font-family: Calibri;"><span style="font-size: 10pt; line-height: 14px;">RMAN> sql 'create pfile from spfile';</span><span style="font-size: 10pt; line-height: 14px;"></span></span></div>
</div>
<div class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">8.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">Modify the PFILE(initORCL1.ora) and make the required changes.</span></div>
<div class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">9.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">Correct the following parameters as per new environment.</span></div>
<div style="border: 1pt solid windowtext; padding: 1pt 4pt;">
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">Control File = /new/path/controln1.dbf,/new/path/controln1.dbf</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">user_dump_dest = <ORACLE_BASE>/admin/<DBNAME>/udump</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">background_dump_dest = <ORACLE_BASE>/admin/<DBNAME>/bdump</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">core_dump_dest = <ORACLE_BASE>/admin/<DBNAME>/bdump</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">log_archive_dest_1 = 'location=/new/path'</span></div>
</div>
<div class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.25in;">
<br /></div>
<div class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.25in; text-indent: -0.25in;">
<span style="font-family: 'Courier New'; font-size: 8pt; line-height: 12px;">10.<span style="font-family: 'Times New Roman';"> </span></span><span style="font-family: Calibri;">Restore control file as follows<span style="font-family: 'Courier New'; font-size: 8pt; line-height: 12px;"></span></span></div>
<div style="border: 1pt solid windowtext; margin-left: 49.5pt; margin-right: 0in; padding: 1pt 4pt 1pt 31pt;">
<div class="MsoNormal" style="border: medium none; margin: 0in 0in 10pt; padding: 0in;">
<span style="font-family: 'Courier New'; font-size: 8pt; line-height: 12px;">restore controlfile to '<path>' from "<restored/controlfile/autobackup/path>";</span></div>
</div>
<div class="MsoListParagraph" style="margin: 0in 0in 10pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">11.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">Force Mount the Instance as follows:</span></div>
<div style="border: 1pt solid windowtext; margin-left: 45pt; margin-right: 0in; padding: 1pt 4pt 1pt 27pt;">
<div class="MsoNormal" style="border: medium none; margin: 0in 0in 10pt; padding: 0in;">
<span style="font-family: Calibri;"><span style="font-size: 10pt; line-height: 14px;">RMAN> startup force mount pfile=$ORACLE_HOME/dbs/</span>initORCL1.ora<i></i></span></div>
</div>
<div class="MsoListParagraph" style="margin: 0in 0in 10pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">12.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">Create SPFILE from PFILE.</span></div>
<div style="border: 1pt solid windowtext; margin-left: 49.5pt; margin-right: 0in; padding: 1pt 4pt 1pt 31pt;">
<div class="MsoNormal" style="border: medium none; margin: 0in 0in 10pt; padding: 0in;">
<span style="font-size: 10pt; line-height: 14px;"><span style="font-family: Calibri;">RMAN> sql 'create spfile from pfile'</span></span></div>
</div>
<div class="MsoListParagraph" style="margin: 0in 0in 10pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">13.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">Shutdown the Database and Mount the database:</span></div>
<div style="border: 1pt solid windowtext; padding: 1pt 4pt;">
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">RMAN> shutdown</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">RMAN> startup mount;</span></div>
</div>
<div class="MsoListParagraph" style="margin: 0in 0in 10pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">14.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;"><b> </b>Disable Flashback Database as follows:</span></div>
<div style="border: 1pt solid windowtext; margin-left: 1in; margin-right: 0in; padding: 1pt 4pt 1pt 22pt;">
<div class="MsoNormal" style="border: medium none; margin: 0in 0in 10pt; padding: 0in;">
<span style="font-size: 10pt; line-height: 14px;"><span style="font-family: Calibri;">SQ> alter database flashback off;</span></span></div>
</div>
<div class="MsoListParagraph" style="margin: 0in 0in 10pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">15.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">Disable Block Change Tracking as follows:</span></div>
<div style="border: 1pt solid windowtext; margin-left: 0.75in; margin-right: 0in; padding: 1pt 4pt;">
<div class="MsoNormal" style="border: medium none; margin: 0in 0in 10pt; padding: 0in; text-indent: 0.25in;">
<span style="font-size: 10pt; line-height: 14px;"><span style="font-family: Calibri;">SQ> alter database disable block change tracking;</span></span></div>
</div>
<div class="MsoListParagraph" style="margin: 0in 0in 10pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">16.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;">Restore the Database as follows. Tail the alert log file and make sure database files are getting restored. Since we are restoring datafiles to new location, files to be renamed(Yu can generate a script to do this). This needs to be executed as one command in run</span></div>
<div style="border: 1pt solid windowtext; padding: 1pt 16pt 1pt 4pt;">
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">$ export ORACLE_SID= ORCL1</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">$ rman target /</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">RMAN></span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">run{</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">set newname for datafile '<old/path/>orcl1_system01.dbf' to '/u04/ORCL1/oradata/orcl1_system01.dbf';</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">.</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">.</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">.</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;"><Rename all your DBFs></span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">.</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">.</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">restore database;</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">switch datafile all;</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">recover database;</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">}</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<br /></div>
</div>
<div class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.25in;">
<br /></div>
<div class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.25in; text-indent: -0.25in;">
<b><span style="font-family: Calibri;">17.</span><span style="font-family: 'Times New Roman';"> </span></b><b><span style="font-family: Calibri;">Rename Log File:</span></b></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-family: Calibri;">If the restored log file path is different, then rename the restored log files in the control fileUse the below SQL to generate script to rename all data files and execute the generated script.</span></div>
<div style="border: 1pt solid windowtext; margin-left: 75.1pt; margin-right: 0in; padding: 1pt 4pt 1pt 31pt;">
<div class="MsoNormal" style="border: medium none; margin: 0in 0in 10pt; padding: 0in;">
<span style="font-family: 'Courier New'; font-size: 8pt; line-height: 12px;">select 'alter database rename file '''|| member ||''' to '''|| replace(member,'<old/path/>','</new/path/>')||''';' from v$logfile</span></div>
</div>
<div class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">18.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;"><b>Open Database:</b> Open the Database by executing following command</span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.25in;">
<span style="font-family: 'Courier New'; font-size: 8pt; line-height: 12px;">SQL> Alter database open resetlogs;</span></div>
<div class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">19.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;"><b>Create Temp Tablespace</b></span></div>
<div style="border: 1pt solid windowtext; padding: 1pt 4pt;">
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">SQL> CREATE TEMPORARY TABLESPACE temp2 TEMPFILE '/new/path/<db_name>_temp02.dbf' size 500m autoextend off ;</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">SQL> ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp2;</span></div>
<div class="MsoNoSpacing" style="border: medium none; margin: 0in 0in 0pt; padding: 0in;">
<span style="font-family: Calibri;">SQL> DROP TABLESPACE temp;</span></div>
</div>
<div class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.25in;">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;">
<span style="font-family: Calibri;">20.</span><span style="font-family: 'Times New Roman';"> </span><span style="font-family: Calibri;"><b> </b>Configure & change Flash Recovery Area:</span></div>
<div class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.25in;">
<br /></div>
<div style="border: 1pt solid windowtext; padding: 1pt 4pt 1pt 31pt;">
<div class="MsoNormal" style="border: medium none; margin: 0in 0in 10pt; padding: 0in;">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 14px;">SQL> alter system set db_recovery_file_dest='</new/path> /flash_recovery_area' scope=both;</span></div>
</div>
</div>
<div style="clear: both;">
</div>
</div>
<div class="post-footer" style="background-color: white; color: #999999; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; line-height: 1.6; margin: 0.5em 0px 0px;">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com0tag:blogger.com,1999:blog-2521368012158105098.post-46828033778454543632013-01-23T04:15:00.000-08:002013-01-23T04:15:07.116-08:00New Jobs in Oracle 11g<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
1. ORA$AUTOTASK_CLEAN<br />
<br />
The job is created by the 11g script catmwin.sql – Catalog script for<br />
Maintenance Window catmwin.sql defines maintenance window and stats collection job.This job is an autotask repository data ageing job and deletes obsolete AUTOTASK repository data. The delete of this old data will be performed by the procedure ora$age_autotask_data which will be executed by the job.<br />
<br />
2. HM_CREATE_OFFLINE_DICTIONARY<br />
<br />
The job is created by the 11g script catmwin.sql which mentions that this is a job for creation of offline dictionary for Database Repair Advisor.<br />
<br />
3. DRA_REEVALUATE_OPEN_FAILURES<br />
<br />
The job is created by the 11g script catmwin.sql which mentions that this is a job for reevaluate open failures for Database Recovery Advisor. In other words it is used to get assistance in case of loss or corruption of datafiles, redo log files or controlfiles.The job executes the procedure dbms_ir.reevaluateopenfailures.<br />
<br />
4. MGMT_CONFIG_JOB<br />
<br />
Comes with the OCM(Oracle Configuration Manager) installation.<br />
This is a configuration collection job.The job is created by the script ocmjb10.sql by running procedure ‘ORACLE_OCM.MGMT_CONFIG.collect_config’.<br />
<br />
5. MGMT_STATS_CONFIG_JOB<br />
<br />
This is an OCM Statistics collection job created in ocmjb10.sql by running<br />
‘ORACLE_OCM.MGMT_CONFIG.collect_stats’.<br />
<br />
6. BSLN_MAINTAIN_STATS_JOB<br />
<br />
This job is a compute statistics job. This job runs the BSLN_MAINTAIN_STATS_PROG program on the BSLN_MAINTAIN_STATS_SCHED schedule. The program BSLN_MAINTAIN_STATS_PROG will keep the default baseline’s statistics up-to-date.<br />
<br />
7. XMLDB_NFS_CLEANUP_JOB<br />
<br />
The job is created in xdbu102.sql and runs the procedure dbms_xdbutil_int.cleanup_expired_nfsclients.<br />
<br />
8. RSE$CLEAN_RECOVERABLE_SCRIPT<br />
<br />
This job is STREAMS related. It is created in execstr.sql and is new in 11.2. The script execstr.sql executes anonymous blocks for STReam. The job is responsible with the cleaning of recoverable scripts and calls ‘ ‘sys.dbms_streams_auto_int.clean_recoverable_script;’.<br />
<br />
9. SM$CLEAN_AUTO_SPLIT_MERGE<br />
<br />
This job is STREAMS related. It is created in file execstr.sql and is new in 11.2 too. The job is responsible with the cleaning of auto split merge views.<br />
</div>
Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com0tag:blogger.com,1999:blog-2521368012158105098.post-57775949626860190482012-10-25T02:15:00.001-07:002012-10-25T02:15:27.210-07:00Bringing ONLINE a Datafile that is in RECOVER mode because it was OFFLINE<br />
<div class="post-header" style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 10px; line-height: 15px; margin: 0px 0px 1.5em;">
<div class="post-header-line-1">
</div>
</div>
<div class="post-body entry-content" id="post-body-2540207545142554687" style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 12px; line-height: 1.4; position: relative; width: 620px;">
A recent <a href="http://forums.oracle.com/forums/thread.jspa?threadID=884117&tstart=0" style="color: #888888; text-decoration: none;">forums thread</a> was about a Datafile that had been taken OFFLINE by the DBA and was in RECOVER mode.<span id="formatbar_Buttons" style="display: block;"><span class="down" id="formatbar_CreateLink" style="display: block;" title="Link"><img alt="Link" border="0" class="gl_link" src="http://www.blogger.com/img/blank.gif" style="-webkit-box-shadow: rgba(0, 0, 0, 0.0980392) 1px 1px 5px; border: 1px solid rgb(238, 238, 238); box-shadow: rgba(0, 0, 0, 0.0980392) 1px 1px 5px; padding: 5px;" /></span></span><span id="formatbar_Buttons" style="display: block;"><span class="down" id="formatbar_CreateLink" style="display: block;" title="Link"><img alt="Link" border="0" class="gl_link" src="http://www.blogger.com/img/blank.gif" style="-webkit-box-shadow: rgba(0, 0, 0, 0.0980392) 1px 1px 5px; border: 1px solid rgb(238, 238, 238); box-shadow: rgba(0, 0, 0, 0.0980392) 1px 1px 5px; padding: 5px;" /><br />When a DBA sees a datafile in 'RECOVER' mode (in DBA_DATAFILES) he shouldn't jump to the conclusion that he needs to RESTORE *and* RECOVER the datafile -- particularly if it does exist !<br />A RESTORE is required only if the file doesn't exist on disk (accessible to the database) OR is corrupted.<br /><br />In "normal" circumstances (i.e. when a RESTORE has been issued), a RECOVER needs to roll-forward through all the ArchiveLogs that have been generated since the point in time of the datafile -- i.e. the backup of that datafile.<br /><br />However, if the Datafile was taken OFFLINE, although Oracle marks it as requiring RECOVERy (as is seeen in DBA_DATA_FILES.STATUS), it doesn't really need all the ArchiveLogs. It only needs those ArchiveLogs that captured the Checkpoint of the Datafile and it's being taken OFFLINE. Subsequent ArchiveLogs (no matter how many they were) are not required. Thus, if the file was taken OFFLINE four days ago, as the DBA, I need only the ArchiveLogs that captured the last set of transactions not checkpointed into the Datafile and the ArchiveLog that captured the issuance of the ALTER DATABASE DATAFILE filename OFFLINE command. I do NOT need 4 days of ArchiveLogs.<br /><br />Here, I first present one case where I do not have the ArchiveLog that captured the DATAFILE OFFLINE command. As is evident, datafile /usr/tmp/test_offline cannot be RECOVERed and brought ONLINE :<br /><br /><pre>
SQL> select log_mode from v$database;
LOG_MODE
------------
ARCHIVELOG
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle_fs/ArchiveLogs/ORT24FS
Oldest online log sequence 1
Next log sequence to archive 2
Current log sequence 2
SQL> create tablespace test_offline datafile '/usr/tmp/test_offline' size 10M ;
Tablespace created.
SQL> alter system switch logfile;
System altered.
SQL> alter database datafile '/usr/tmp/test_offline' offline;
Database altered.
SQL> select * from dba_data_files where file_name like '/usr/tmp/test%';
FILE_NAME
--------------------------------------------------------------------------------
FILE_ID TABLESPACE_NAME BYTES BLOCKS STATUS
---------- ------------------------------ ---------- ---------- ---------
RELATIVE_FNO AUT MAXBYTES MAXBLOCKS INCREMENT_BY USER_BYTES USER_BLOCKS
------------ --- ---------- ---------- ------------ ---------- -----------
ONLINE_
-------
/usr/tmp/test_offline
6 TEST_OFFLINE AVAILABLE
6
RECOVER
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> !rm /oracle_fs/ArchiveLogs/ORT24FS/*
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle_fs/ArchiveLogs/ORT24FS
Oldest online log sequence 3
Next log sequence to archive 5
Current log sequence 5
SQL> !ls -l /oracle_fs/ArchiveLogs/ORT24FS
total 0
SQL> alter system switch logfile;
System altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle_fs/ArchiveLogs/ORT24FS
Oldest online log sequence 4
Next log sequence to archive 6
Current log sequence 6
SQL> !ls -l /oracle_fs/ArchiveLogs/ORT24FS
total 8
-rw-r----- 1 ora10204 dba 4608 Apr 22 22:33 1_5_684196024.dbf
SQL> alter database datafile '/usr/tmp/test_offline' online;
alter database datafile '/usr/tmp/test_offline' online
*
ERROR at line 1:
ORA-01113: file 6 needs media recovery
ORA-01110: data file 6: '/usr/tmp/test_offline'
SQL> recover datafile 6;
ORA-00279: change 649615 generated at 04/22/2009 22:29:06 needed for thread 1
ORA-00289: suggestion : /oracle_fs/ArchiveLogs/ORT24FS/1_2_684196024.dbf
ORA-00280: change 649615 for thread 1 is in sequence #2
Specify log: {<ret>=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.
SQL> alter database datafile '/usr/tmp/test_offline' online;
alter database datafile '/usr/tmp/test_offline' online
*
ERROR at line 1:
ORA-01113: file 6 needs media recovery
ORA-01110: data file 6: '/usr/tmp/test_offline'
SQL> drop tablespace test_offline including contents and datafiles;
Tablespace dropped.
SQL> </ret></pre>
<br />I needed ArchiveLog 2 to be able to issue the RECOVER command. However, as I had (seemingly inadvertently or because it is very old file) removed that ArchiveLog from disk, I cannot RECOVER the datafile. Note, however, that if I did have a Tape backup of ArchiveLogs 2 and 3 I would have been able to RECOVER that datfile and then bring it ONLINE (without requiring Sequences 4 and 5).<br /><br /><br />In this next scenario, I delete only the subsequent ArchiveLogs after the first one after the ALTER DATABASE DATAFILE filename OFFLINE command. (We can assume that I either preserved the required ArchiveLogs or restored them from backup).<br /><br /><pre>
SQL> create tablespace t_o_2 datafile '/usr/tmp/t_o_2.dbf' size 10M;
Tablespace created.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle_fs/ArchiveLogs/ORT24FS
Oldest online log sequence 4
Next log sequence to archive 6
Current log sequence 6
SQL> alter system switch logfile;
System altered.
SQL> alter database datafile '/usr/tmp/t_o_2.dbf' offline;
Database altered.
SQL> alter system switch logfile;
System altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle_fs/ArchiveLogs/ORT24FS
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8
SQL> !ls -l /oracle_fs/ArchiveLogs/ORT24FS
total 44
-rw-r----- 1 ora10204 dba 4608 Apr 22 22:33 1_5_684196024.dbf
-rw-r----- 1 ora10204 dba 28160 Apr 22 22:36 1_6_684196024.dbf
-rw-r----- 1 ora10204 dba 6656 Apr 22 22:36 1_7_684196024.dbf
SQL> create table t_2 (col_1 number);
Table created.
SQL> insert into t_2 select object_id from dba_objects;
50601 rows created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> !ls -l /oracle_fs/ArchiveLogs/ORT24FS
total 900
-rw-r----- 1 ora10204 dba 4608 Apr 22 22:33 1_5_684196024.dbf
-rw-r----- 1 ora10204 dba 28160 Apr 22 22:36 1_6_684196024.dbf
-rw-r----- 1 ora10204 dba 6656 Apr 22 22:36 1_7_684196024.dbf
-rw-r----- 1 ora10204 dba 866304 Apr 22 22:38 1_8_684196024.dbf
-rw-r----- 1 ora10204 dba 1536 Apr 22 22:38 1_9_684196024.dbf
SQL> !rm /oracle_fs/ArchiveLogs/ORT24FS/1_8_*.dbf
SQL> !rm /oracle_fs/ArchiveLogs/ORT24FS/1_9_*.dbf
SQL> alter database datafile '/usr/tmp/t_o_2.dbf' online;
alter database datafile '/usr/tmp/t_o_2.dbf' online
*
ERROR at line 1:
ORA-01113: file 6 needs media recovery
ORA-01110: data file 6: '/usr/tmp/t_o_2.dbf'
SQL> recover datafile 6;
ORA-00279: change 649846 generated at 04/22/2009 22:36:10 needed for thread 1
ORA-00289: suggestion : /oracle_fs/ArchiveLogs/ORT24FS/1_6_684196024.dbf
ORA-00280: change 649846 for thread 1 is in sequence #6
Specify log: {<ret>=suggested | filename | AUTO | CANCEL}
ORA-00279: change 649874 generated at 04/22/2009 22:36:28 needed for thread 1
ORA-00289: suggestion : /oracle_fs/ArchiveLogs/ORT24FS/1_7_684196024.dbf
ORA-00280: change 649874 for thread 1 is in sequence #7
ORA-00278: log file '/oracle_fs/ArchiveLogs/ORT24FS/1_6_684196024.dbf' no
longer needed for this recovery
Specify log: {<ret>=suggested | filename | AUTO | CANCEL}
Log applied.
Media recovery complete.
SQL> select * from dba_data_files where file_name like '/usr/tmp/t_o%';
FILE_NAME
--------------------------------------------------------------------------------
FILE_ID TABLESPACE_NAME BYTES BLOCKS STATUS
---------- ------------------------------ ---------- ---------- ---------
RELATIVE_FNO AUT MAXBYTES MAXBLOCKS INCREMENT_BY USER_BYTES USER_BLOCKS
------------ --- ---------- ---------- ------------ ---------- -----------
ONLINE_
-------
/usr/tmp/t_o_2.dbf
6 T_O_2 AVAILABLE
6
OFFLINE
SQL> alter database datafile '/usr/tmp/t_o_2.dbf' online;
Database altered.
SQL></ret></ret></pre>
<br /><br />Thus, the RECOVER command for /usr/tmp/t_o_2.dbf required only ArchiveLogs 6 and 7. I did NOT need ArchiveLogs 8, 9 and 10 even though they have been generated since after the particular Datafile was taken OFFLINE.<br />Therefore, although ArchiveLogs 8, 9 and 10 do capture transactions in *other* Datafiles (and, therefore, would be required if I were to RESTORE and/or RCOVER the other Datafiles), I do not need them for this particular Datafile that was "properly and normally" taken OFFLINE.<br />As further evidence, see these messages from the alert.log file :<br /><pre>
Wed Apr 22 22:36:42 2009
alter database datafile '/usr/tmp/t_o_2.dbf' offline
Wed Apr 22 22:36:42 2009
Completed: alter database datafile '/usr/tmp/t_o_2.dbf' offline
Wed Apr 22 22:36:47 2009
Thread 1 cannot allocate new log, sequence 8
Checkpoint not complete
Current log# 1 seq# 7 mem# 0: /oracle_fs/Databases/ORT24FS/redo01.dbf
Wed Apr 22 22:36:49 2009
Thread 1 advanced to log sequence 8 (LGWR switch)
Current log# 2 seq# 8 mem# 0: /oracle_fs/Databases/ORT24FS/redo02.dbf
Wed Apr 22 22:38:15 2009
Thread 1 cannot allocate new log, sequence 9
Checkpoint not complete
Current log# 2 seq# 8 mem# 0: /oracle_fs/Databases/ORT24FS/redo02.dbf
Wed Apr 22 22:38:16 2009
Thread 1 advanced to log sequence 9 (LGWR switch)
Current log# 3 seq# 9 mem# 0: /oracle_fs/Databases/ORT24FS/redo03.dbf
Thread 1 cannot allocate new log, sequence 10
Checkpoint not complete
Current log# 3 seq# 9 mem# 0: /oracle_fs/Databases/ORT24FS/redo03.dbf
Wed Apr 22 22:38:19 2009
Thread 1 advanced to log sequence 10 (LGWR switch)
Current log# 1 seq# 10 mem# 0: /oracle_fs/Databases/ORT24FS/redo01.dbf
Wed Apr 22 22:39:19 2009
alter database datafile '/usr/tmp/t_o_2.dbf' online
Wed Apr 22 22:39:19 2009
ORA-1113 signalled during: alter database datafile '/usr/tmp/t_o_2.dbf' online...
Wed Apr 22 22:39:25 2009
ALTER DATABASE RECOVER datafile 6
Media Recovery Start
parallel recovery started with 2 processes
ORA-279 signalled during: ALTER DATABASE RECOVER datafile 6 ...
Wed Apr 22 22:39:28 2009
ALTER DATABASE RECOVER CONTINUE DEFAULT
Wed Apr 22 22:39:28 2009
Media Recovery Log /oracle_fs/ArchiveLogs/ORT24FS/1_6_684196024.dbf
ORA-279 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
Wed Apr 22 22:39:31 2009
ALTER DATABASE RECOVER CONTINUE DEFAULT
Wed Apr 22 22:39:31 2009
Media Recovery Log /oracle_fs/ArchiveLogs/ORT24FS/1_7_684196024.dbf
Wed Apr 22 22:39:31 2009
Media Recovery Complete (ORT24FS)
Completed: ALTER DATABASE RECOVER CONTINUE DEFAULT
Wed Apr 22 22:40:15 2009
alter database datafile '/usr/tmp/t_o_2.dbf' online
Wed Apr 22 22:40:15 2009
Starting control autobackup
Control autobackup written to DISK device
handle '/oracle_fs/FRAs/ORT24FS/ORT24FS/autobackup/c-4163910544-20090422-03'
Completed: alter database datafile '/usr/tmp/t_o_2.dbf' online </pre>
<br /><br /><br />Thus, Oracle needed only ArchiveLogs 6 and 7 even as I had deleted 8 and 9 from disk (and have no backups of 8 and 9).</span></span></div>
Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com0tag:blogger.com,1999:blog-2521368012158105098.post-59726376446408424712012-10-12T04:51:00.001-07:002012-10-12T04:52:34.073-07:00SQL set operators<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h1 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif;">
SQL set operators</h1>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="p1" name="p1" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" title="Introduction"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h2 style="background-color: white; font-family: serif; margin-bottom: 1em; margin-top: 1em;">
1 Introduction</h2>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">SQL set operators allows combine results from two or more SELECT statements. At first sight this looks similar to SQL joins although there is big difference. SQL joins tends to combine columns i.e. with each additionally joined table it is possible to select more and more columns. SQL set operators on the other hand combine rows from different queries with strong preconditions - all involved SELECTS must:</span><br />
<ul style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">
<li style="font-size: 1em; line-height: 1.65em;">retrieve the same number of columns and</li>
<li style="font-size: 1em; line-height: 1.65em;">the data types of corresponding columns in each involved SELECT must be compatible (either the same or with possibility implicitly convert to the data types of the first SELECT statement).</li>
</ul>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Visually the difference can be explained as follows - joins tend to extend breadthways, but set operations in depth.</span><br />
<img alt="SQL join example" src="http://www.gplivna.eu/papers/sql_set_operators_files/01_sql_join.gif" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" /><br />
<img alt="SQL set operator example" src="http://www.gplivna.eu/papers/sql_set_operators_files/02_sql_set_operator.gif" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" /><br />
<b style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">NB 1!</b><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> All examples are created for Oracle database and written according to Oracle syntax. However it doesn't matter what database management system is used, many of them with (probably) very little modifications or even exactly the same can be used for every other DBMS supporting set operators. Exactly why they work or why not are described for </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p3.1" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">Oracle</a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">, </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p3.2" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">SQL Server</a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> and </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p3.3" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">MySQL</a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">. If you need to use them for other DBMSes then you should check these examples yourself although I would be very pleased if you'd send me information what examples are not working on what DBMSes. I will include this info here along with your name.</span><br />
<h2 style="background-color: white; font-family: serif; margin-bottom: 1em; margin-top: 1em;">
Contents</h2>
<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p1" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">1 Introduction</a><br />
<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p2" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">2 Set operator types and syntax</a><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p2.1" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">2.1 Common facts to remember</a><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p2.2" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">2.2 Used tables for examples</a><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p2.3" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">2.3 UNION [DISTINCT] and UNION ALL</a><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p2.4" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">2.4 EXCEPT [DISTINCT] and EXCEPT ALL</a><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p2.5" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">2.5 INTERSECT [DISTINCT] and INTERSECT ALL</a><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p2.6" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">2.6 Raising it to higher levels - are two table data equal?</a><br />
<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p3" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">3 Example usage for various DBMSes</a><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p3.1" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">3.1 Oracle</a><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p3.2" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">3.2 Microsoft SQL Server</a><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p3.3" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">3.3 MySQL</a><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p3.4" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">3.4 IBM DB2</a><br />
<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#p4" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">4 References and more information</a><br />
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="p2" name="p2" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" title="Set operator types and syntax"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h2 style="background-color: white; font-family: serif; margin-bottom: 1em; margin-top: 1em;">
2 Set operator types and syntax</h2>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">According to SQL Standard there are following Set operator types:</span><br />
<ul style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">
<li style="font-size: 1em; line-height: 1.65em;">UNION [DISTINCT];</li>
<li style="font-size: 1em; line-height: 1.65em;">UNION ALL;</li>
<li style="font-size: 1em; line-height: 1.65em;">EXCEPT [DISTINCT];</li>
<li style="font-size: 1em; line-height: 1.65em;">EXCEPT ALL;</li>
<li style="font-size: 1em; line-height: 1.65em;">INTERSECT [DISTINCT];</li>
<li style="font-size: 1em; line-height: 1.65em;">INTERSECT ALL.</li>
</ul>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">As we can see there are 3 basic types Union, Except and Intersect and all have 2 modifications either Distinct or All. SQL Standard does not enforce keyword Distinct and some DBMSes for example Oracle and SQL Server even do not allow it, therefore if you see just Union, Except or Intersect - these actually mean Union Distinct, Except Distinct and Intersect Distinct.</span><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">It is already clear from the very syntax that </span><i style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Distinct</i><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> modification removes duplicates from the result set, but </span><i style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">All</i><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> modification retains them.</span><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Query syntax is common for all of them:</span><br />
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;"><b><query1>
<SET OPERATOR>
<query1>
</b></span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Each query1 and query2 is full-fledged SELECT statements with possible joins, subqueries and other constructions. There is also possibility to combine more than 2 SELECT statements with set operators among them.</span><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Lets look in general overview what the result of each one of them is. Following chart defines 2 queries returning data and various set operator combinations among them.</span><br />
<table border="1" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif;"><tbody>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><th>QueryA</th><th>QueryB</th><th>QueryA UNION [DISTINCT] QueryB<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e1" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 1</a></th><th>QueryA UNION ALL QueryB<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e3" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 3</a></th><th>QueryA EXCEPT (MINUS) [DISTINCT] QueryB <a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e10" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 10</a></th><th>QueryB EXCEPT (MINUS) [DISTINCT] QueryA <a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e11" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 11</a></th><th>QueryA EXCEPT (MINUS) ALL QueryB<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e14" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 14</a></th><th>QueryB EXCEPT (MINUS) ALL QueryA<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e15" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 15</a></th><th>QueryA INTERSECT [DISTINCT] QueryB<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e17" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 17</a></th><th>QueryA INTERSECT ALL QueryB<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e19" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 19</a></th></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: red;">Riga</span></td><td><span style="color: red;">Riga</span></td><td><span style="color: red;">Riga</span></td><td><span style="color: red;">Riga</span></td><td><span style="color: blue;">Tallinn</span></td><td></td><td><span style="color: red;">Riga</span></td><td><span style="color: green;">Vilnius</span></td><td><span style="color: red;">Riga</span></td><td><span style="color: red;">Riga</span></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: red;">Riga</span></td><td><span style="color: red;">Riga</span></td><td><span style="color: blue;">Tallinn</span></td><td><span style="color: red;">Riga</span></td><td><span style="color: orange;">Stockholm</span></td><td></td><td><span style="color: blue;">Tallinn</span></td><td><span style="color: green;">Vilnius</span></td><td><span style="color: green;">Vilnius</span></td><td><span style="color: red;">Riga</span></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: red;">Riga</span></td><td><span style="color: green;">Vilnius</span></td><td><span style="color: green;">Vilnius</span></td><td><span style="color: red;">Riga</span></td><td></td><td></td><td><span style="color: blue;">Tallinn</span></td><td><span style="color: green;">Vilnius</span></td><td><span style="color: turquoise;">Helsinki</span></td><td><span style="color: green;">Vilnius</span></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: blue;">Tallinn</span></td><td><span style="color: green;">Vilnius</span></td><td><span style="color: turquoise;">Helsinki</span></td><td><span style="color: red;">Riga</span></td><td></td><td></td><td><span style="color: blue;">Tallinn</span></td><td></td><td></td><td><span style="color: turquoise;">Helsinki</span></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: blue;">Tallinn</span></td><td><span style="color: green;">Vilnius</span></td><td><span style="color: orange;">Stockholm</span></td><td><span style="color: red;">Riga</span></td><td></td><td></td><td><span style="color: turquoise;">Helsinki</span></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: blue;">Tallinn</span></td><td><span style="color: green;">Vilnius</span></td><td></td><td><span style="color: blue;">Tallinn</span></td><td></td><td></td><td><span style="color: orange;">Stockholm</span></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: green;">Vilnius</span></td><td><span style="color: turquoise;">Helsinki</span></td><td></td><td><span style="color: blue;">Tallinn</span></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: turquoise;">Helsinki</span></td><td></td><td></td><td><span style="color: blue;">Tallinn</span></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: turquoise;">Helsinki</span></td><td></td><td></td><td><span style="color: green;">Vilnius</span></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: orange;">Stockholm</span></td><td></td><td></td><td><span style="color: green;">Vilnius</span></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td></td><td></td><td></td><td><span style="color: green;">Vilnius</span></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td></td><td></td><td></td><td><span style="color: green;">Vilnius</span></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td></td><td></td><td></td><td><span style="color: green;">Vilnius</span></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td></td><td></td><td></td><td><span style="color: turquoise;">Helsinki</span></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td></td><td></td><td></td><td><span style="color: turquoise;">Helsinki</span></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td></td><td></td><td></td><td><span style="color: turquoise;">Helsinki</span></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td></td><td></td><td></td><td><span style="color: orange;">Stockholm</span></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
</tbody></table>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Next chart contains the same QueryA but QueryC returns 0 rows, just to feel some possible quirks.</span><br />
<table border="1" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif;"><tbody>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><th>QueryA</th><th>QueryC</th><th>QueryA UNION [DISTINCT] QueryC<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e4" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 4</a></th><th>QueryA UNION ALL QueryC<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e5" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 5</a></th><th>QueryA EXCEPT (MINUS) [DISTINCT] QueryC<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e12" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 12</a></th><th>QueryA EXCEPT (MINUS) ALL QueryC<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e16" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 16</a></th><th>QueryC EXCEPT (MINUS) [DISTINCT] QueryA</th><th>QueryC EXCEPT (MINUS) ALL QueryA</th><th>QueryA INTERSECT [DISTINCT] QueryC <a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e18" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 18</a></th><th>QueryA INTERSECT ALL QueryC</th></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: red;">Riga</span></td><td></td><td><span style="color: red;">Riga</span></td><td><span style="color: red;">Riga</span></td><td><span style="color: red;">Riga</span></td><td><span style="color: red;">Riga</span></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: red;">Riga</span></td><td></td><td><span style="color: blue;">Tallinn</span></td><td><span style="color: red;">Riga</span></td><td><span style="color: blue;">Tallinn</span></td><td><span style="color: red;">Riga</span></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: red;">Riga</span></td><td></td><td><span style="color: green;">Vilnius</span></td><td><span style="color: red;">Riga</span></td><td><span style="color: green;">Vilnius</span></td><td><span style="color: red;">Riga</span></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: blue;">Tallinn</span></td><td></td><td><span style="color: turquoise;">Helsinki</span></td><td><span style="color: blue;">Tallinn</span></td><td><span style="color: turquoise;">Helsinki</span></td><td><span style="color: blue;">Tallinn</span></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: blue;">Tallinn</span></td><td></td><td><span style="color: orange;">Stockholm</span></td><td><span style="color: blue;">Tallinn</span></td><td><span style="color: orange;">Stockholm</span></td><td><span style="color: blue;">Tallinn</span></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: blue;">Tallinn</span></td><td></td><td></td><td><span style="color: blue;">Tallinn</span></td><td></td><td><span style="color: blue;">Tallinn</span></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: green;">Vilnius</span></td><td></td><td></td><td><span style="color: green;">Vilnius</span></td><td></td><td><span style="color: green;">Vilnius</span></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: turquoise;">Helsinki</span></td><td></td><td></td><td><span style="color: turquoise;">Helsinki</span></td><td></td><td><span style="color: turquoise;">Helsinki</span></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: turquoise;">Helsinki</span></td><td></td><td></td><td><span style="color: turquoise;">Helsinki</span></td><td></td><td><span style="color: turquoise;">Helsinki</span></td><td></td><td></td><td></td><td></td></tr>
<tr style="font-size: 0.8em; margin-bottom: 0px; margin-top: 0px;"><td><span style="color: orange;">Stockholm</span></td><td></td><td></td><td><span style="color: orange;">Stockholm</span></td><td></td><td><span style="color: orange;">Stockholm</span></td><td></td><td></td><td></td><td></td></tr>
</tbody></table>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="p2.1" name="p2.1" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" title="Common facts to remember"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h3 style="background-color: white; font-family: serif; font-size: 1.3em; margin-bottom: 0.8em; margin-top: 0.8em;">
2.1 Common facts to remember</h3>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">There are some facts which probably aren't obvious and should be mentioned. Let's expand requirements for queries to be combined using one of the set operators:</span><br />
<ul style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">
<li style="font-size: 1em; line-height: 1.65em;">column count must be the same;</li>
<li style="font-size: 1em; line-height: 1.65em;">data types of retrieved columns should match or at least should be implicitly convertible by database;</li>
<li style="font-size: 1em; line-height: 1.65em;">one can use many set operators for example Query1 UNION ALL Query2 UNION ALL Query3 MINUS Query4 INTERSECT Query5. In such case one should look into used DB documentation what is the order of operators, because for example Oracle executes operators starting from left to right, but DB2 firstly executes Intersect;</li>
<li style="font-size: 1em; line-height: 1.65em;">Usually returned column names are taken from the first query;</li>
<li style="font-size: 1em; line-height: 1.65em;">Order by clauses for each individual query except the last one cannot be at all (Oracle) or are ignored (MySQL).</li>
</ul>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Some other facts:</span><br />
<ul style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">
<li style="font-size: 1em; line-height: 1.65em;">UNION and INTERSECT operators are commutative, i.e. the order of queries is not important; it doesn't change the final result. See <a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e1" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 1</a> and<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e2" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 2</a>.</li>
<li style="font-size: 1em; line-height: 1.65em;">EXCEPT operator is NOT commutative, it IS important which query is first, which second using EXCEPT operator. See <a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e10" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 10</a> and <a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e11" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 11</a>.</li>
<li style="font-size: 1em; line-height: 1.65em;">UNION, EXCEPT and INTERSECT used without anything or with DISTINCT returns only unique values. This is especially interesting when one query returning many nonunique rows is UNIONED to another query returning zero rows (<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e4" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 4</a>). The final result contains fewer rows than first query.</li>
<li style="font-size: 1em; line-height: 1.65em;">If you know that result sets returned by each query are unique then use UNION ALL, because database doesn't know that and uses more (wasted) resources to filter out duplicates in case of UNION.</li>
<li style="font-size: 1em; line-height: 1.65em;">If you need determined ordering then use Order by clause in the last query. Don't assume that rows from first query will always be returned first.</li>
<li style="font-size: 1em; line-height: 1.65em;">If you need to distinguish which query produced rows then you can add some tag or flag column indicating which query produced them.</li>
<li style="font-size: 1em; line-height: 1.65em;">NULL values using set operators are considered to be equal to each other (<a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e9" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 9</a>).</li>
</ul>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="p2.2" name="p2.2" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" title="Used tables for examples"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h3 style="background-color: white; font-family: serif; font-size: 1.3em; margin-bottom: 0.8em; margin-top: 0.8em;">
2.2 Used tables for examples</h3>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Throughout this entire article we will use following tables and table data (the same data as used in tables above):</span><br />
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">CREATE TABLE table1 (
id INTEGER NOT NULL PRIMARY KEY,
city VARCHAR(10) NOT NULL);
CREATE TABLE table2 (
id INTEGER NOT NULL PRIMARY KEY,
city VARCHAR(10) NOT NULL);
CREATE TABLE table3 (
city VARCHAR(10) NOT NULL);
INSERT INTO table1 VALUES (1, 'RIGA');
INSERT INTO table1 VALUES (2, 'RIGA');
INSERT INTO table1 VALUES (3, 'RIGA');
INSERT INTO table1 VALUES (4, 'TALLINN');
INSERT INTO table1 VALUES (5, 'TALLINN');
INSERT INTO table1 VALUES (6, 'TALLINN');
INSERT INTO table1 VALUES (7, 'VILNIUS');
INSERT INTO table1 VALUES (8, 'HELSINKI');
INSERT INTO table1 VALUES (9, 'HELSINKI');
INSERT INTO table1 VALUES (10, 'STOCKHOLM');
INSERT INTO table2 VALUES (1, 'RIGA');
INSERT INTO table2 VALUES (2, 'RIGA');
INSERT INTO table2 VALUES (3, 'VILNIUS');
INSERT INTO table2 VALUES (4, 'VILNIUS');
INSERT INTO table2 VALUES (5, 'VILNIUS');
INSERT INTO table2 VALUES (6, 'VILNIUS');
INSERT INTO table2 VALUES (7, 'HELSINKI');
COMMIT;
</span></pre>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="p2.3" name="p2.3" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" title="UNION [DISTINCT] and UNION ALL"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h3 style="background-color: white; font-family: serif; font-size: 1.3em; margin-bottom: 0.8em; margin-top: 0.8em;">
2.3 UNION [DISTINCT] and UNION ALL</h3>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">These usually are most widely used set operators. Quite many times one cannot get all the result from one Select statement. Then one of the UNIONS can help.</span><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Graphically UNION can be visualised using Venn diagrams. Assume we have two row sets.</span><br />
<img alt="Two queries" src="http://www.gplivna.eu/papers/sql_set_operators_files/03_two_queries.gif" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" /><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Then Query1 UNION Query2 would be as follows. Grey area shows resultant set.</span><br />
<img alt="SQL Union" src="http://www.gplivna.eu/papers/sql_set_operators_files/04_sql_union.gif" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" /><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Of course the previous picture is very general visualisation and fully real just for sets which contains each element no more than once.</span><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Query1 UNION ALL Query2 would be as follows:</span><br />
<img alt="SQL Union all" src="http://www.gplivna.eu/papers/sql_set_operators_files/05_sql_union_all.gif" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" /><br />
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="p2.3.1" name="p2.3.1." style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" title="Examples"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h3 style="background-color: white; font-family: serif; font-size: 1.3em; margin-bottom: 0.8em; margin-top: 0.8em;">
2.3.1 Examples</h3>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">As we can see only unique rows are retuned in next example.</span><a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e1" name="e1" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 1</u> Unions cities from table1 and table2.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM table1
UNION
SELECT city FROM table2;
CITY
----------
HELSINKI
RIGA
STOCKHOLM
TALLINN
VILNIUS
</span></pre>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e2" name="e2" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 2</u> Unions cities from table2 and table1. The query ordering is not important, result is the same, compare with <a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e1" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 1</a>.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM table2
UNION
SELECT city FROM table1;
CITY
----------
HELSINKI
RIGA
STOCKHOLM
TALLINN
VILNIUS
</span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">DO NOT ASSUME that Union always return ordered row set. It is NOT TRUE. It is just because of implementation model, i.e. sort is being done to filter out duplicates. At least from version 10 Oracle has possibility to do HASH UNIQUE operation, which doesn't sort rows and you won't get them back sorted. So ALWAYS use Order by clause if you need guaranteed order of rows.</span><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Next example just combines the rows without filtering out duplicates.</span><br />
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e3" name="e3" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 3</u> Unions ALL cities from table1 and table2.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM table1
UNION ALL
SELECT city FROM table2;
CITY
----------
RIGA
RIGA
RIGA
TALLINN
TALLINN
TALLINN
VILNIUS
HELSINKI
HELSINKI
STOCKHOLM
RIGA
RIGA
VILNIUS
VILNIUS
VILNIUS
VILNIUS
HELSINKI
17 rows selected.
</span></pre>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e4" name="e4" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 4</u> UNION [DISTINCT] even with empty set may reduce number of rows. Compare result from first two queries with third query.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM table1;
CITY
----------
RIGA
RIGA
RIGA
TALLINN
TALLINN
TALLINN
VILNIUS
HELSINKI
HELSINKI
STOCKHOLM
10 rows selected.
SELECT city FROM table3;
no rows selected
SELECT city FROM table1
UNION
SELECT city FROM table3;
CITY
----------
HELSINKI
RIGA
STOCKHOLM
TALLINN
VILNIUS
</span></pre>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e5" name="e5" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 5</u> UNION ALL with empty set gives the same result as without it.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM table1
UNION ALL
SELECT city FROM table3;
CITY
----------
RIGA
RIGA
RIGA
TALLINN
TALLINN
TALLINN
VILNIUS
HELSINKI
HELSINKI
STOCKHOLM
10 rows selected.
</span></pre>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e6" name="e6" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 6</u> Each query in Union must return the same number of columns.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT * FROM table1
UNION
SELECT city FROM table2;
SELECT * FROM table1
*
ERROR at line 1:
ORA-01789: query block has incorrect number of result columns
</span></pre>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e7" name="e7" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 7</u> Of course query can be Unioned to itself. This time all rows are returned because combination of both columns is reviewed.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT * FROM table1
UNION
SELECT * FROM table1;
ID CITY
---------- ----------
1 RIGA
2 RIGA
3 RIGA
4 TALLINN
5 TALLINN
6 TALLINN
7 VILNIUS
8 HELSINKI
9 HELSINKI
10 STOCKHOLM
10 rows selected.
</span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Along with subquery factoring clause (or common table expression clause, "with" clause) UNION ALL can be used to generate some sample data without having actual tables. It has become very popular in </span><a href="http://forums.oracle.com/forums/forum.jspa?forumID=61" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;" target="_blank">Oracle forums</a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">.</span><br />
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e8" name="e8" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 8</u> Using "with" clause to generate sample test data to test inner join functionality.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">WITH cities AS (
SELECT 1 as cty_id, 'RIGA' as city FROM dual
UNION ALL
SELECT 2, 'TALLINN' FROM dual
),
streets AS (
SELECT 1 as str_id, 1 as str_cty_id, 'BRIVIBAS' as street FROM dual
UNION ALL
SELECT 2, 2, 'NARVA MNT'FROM dual
)
SELECT city, street FROM cities
INNER JOIN streets ON (str_cty_id = cty_id);
CITY STREET
------- ---------
RIGA BRIVIBAS
TALLINN NARVA MNT
</span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">NULL values are considered equal when using with set operators. This is different than usually, for example, testing for eaquality.</span><a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e9" name="e9" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 9</u> Using "with" clause to generate two NULL values and unioning them.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">WITH null1 AS (
SELECT NULL value FROM dual
),
null2 AS (
SELECT NULL value FROM dual
)
SELECT value FROM null1
UNION
SELECT value FROM null2;
V
-
1 row selected.
</span></pre>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="p2.4" name="p2.4" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" title="EXCEPT [DISTINCT] and EXCEPT ALL"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h3 style="background-color: white; font-family: serif; font-size: 1.3em; margin-bottom: 0.8em; margin-top: 0.8em;">
2.4 EXCEPT [DISTINCT] and EXCEPT ALL</h3>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">EXCEPT returns unique rows that are returned by the first query but are NOT returned by the second query. EXCEPT ALL does the same but retains cardinality, for example, if the first query returns two values of X and second only one, then EXCEPT won't return X but EXCEPT </span><b style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">ALL</b><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> would return one instance of X.</span><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Oracle uses MINUS operator instead of EXCEPT, but the functionality is the same. None of the Oracle, SQL Server and MySQL has implemented EXCEPT ALL. It can be simulated using analytic functions as shown in </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e14" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">Example 14</a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> till </span><a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e16" style="background-color: white; border: 1px solid white; color: #da62b0; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px; text-decoration: none;">Example 16</a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">.</span><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Usually EXCEPT is used to compare date in different data sources (tables) to find differences, for example, differences in the same tables across test and production and/or actual copy and backup.</span><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Visually Query1 EXCEPT Query2 can be expressed as follows:</span><br />
<img alt="SQL except (minus) A-B" src="http://www.gplivna.eu/papers/sql_set_operators_files/06_sql_minus_12.gif" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" /><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Obviously diagram is not symmetric therefore for Query2 EXCEPT Query1 we get different picture:</span><br />
<img alt="SQL except (minus) B-A" src="http://www.gplivna.eu/papers/sql_set_operators_files/07_sql_except_21.gif" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" /><br />
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="p2.4.1" name="p2.4.1" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" title="Examples"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h3 style="background-color: white; font-family: serif; font-size: 1.3em; margin-bottom: 0.8em; margin-top: 0.8em;">
2.4.1 Examples</h3>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e10" name="e10" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 10</u> Cities in table1 except (minus) [distinct] cities in table2.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM table1
MINUS
SELECT city FROM table2;
CITY
----------
STOCKHOLM
TALLINN
</span></pre>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e11" name="e11" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 11</u> Cities in table2 except (minus) [distinct] cities in table1. Of course the result is different than in <a href="http://www.gplivna.eu/papers/sql_set_operators.htm#e10" style="border: 1px solid white; color: #da62b0; text-decoration: none;">Example 10</a>.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM table2
MINUS
SELECT city FROM table1;
no rows selected
</span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">As MINUS filters out duplicates then even subtracting empty set may reduce the initial set.</span><a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e12" name="e12" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 12</u> Cities in table1 except (minus) [distinct] empty set (cities in table3).</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM table1
MINUS
SELECT city FROM table3;
CITY
----------
HELSINKI
RIGA
STOCKHOLM
TALLINN
VILNIUS
</span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">It is not possible in Oracle and SQL Server to use EXCEPT (MINUS) ALL directly.</span><a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e13" name="e13" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 13</u> Minus all doesn't exist in Oracle.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM table1
MINUS ALL
SELECT city FROM table2;
MINUS ALL
*
ERROR at line 2:
ORA-00928: missing SELECT keyword
</span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">However using analytic functions and simple minus it is possible. The main idea for MINUS (EXCEPT) ALL is to retain cardinality, i.e. how many instances of each row exists in source sets. Here analytic function row_number() can help. It just increments counter for each row which is the same as previous and restarts if the row values change. Then we can use simple MINUS [DISTINCT], and show only business columns.</span><a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e14" name="e14" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 14</u> Faked minus all using row_number() analytic function. Cities in table1 except (minus) all cities in table2.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM (
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table1
MINUS
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table2
) q;
CITY
----------
HELSINKI
RIGA
STOCKHOLM
TALLINN
TALLINN
TALLINN
</span></pre>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e15" name="e15" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 15</u> Faked minus all using row_number() analytic function. Cities in table2 except (minus) all cities in table1.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM (
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table2
MINUS
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table1
) q;
CITY
----------
VILNIUS
VILNIUS
VILNIUS
</span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Any set Minus all empty set doesn't change. Just like with Union all.</span><a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e16" name="e16" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 16</u> Faked minus all using row_number() analytic function. Cities in table1 except (minus) all empty set (cities in table3).</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM (
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table1
MINUS
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table3
) q;
CITY
----------
HELSINKI
HELSINKI
RIGA
RIGA
RIGA
STOCKHOLM
TALLINN
TALLINN
TALLINN
VILNIUS
</span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">It is obvious that subtracting anything from empty set will always be empty set therefore I won't show you these examples. It is true for both modifications of except (minus) - distinct and all.</span><a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="p2.5" name="p2.5" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" title="INTERSECT [DISTINCT] and INTERSECT ALL"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h3 style="background-color: white; font-family: serif; font-size: 1.3em; margin-bottom: 0.8em; margin-top: 0.8em;">
2.5 INTERSECT [DISTINCT] and INTERSECT ALL</h3>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Intersect returns only these rows, which are in both tables. Intersect [distinct] returns just unique rows, but intersect all retains cardinality. Intersect is commutative, just like union - it is not important which query is the first, which second one.</span><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Picture for Query1 INTERSECT Query2 is as follows:</span><br />
<img alt="SQL intersect" src="http://www.gplivna.eu/papers/sql_set_operators_files/08_sql_intersect.gif" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" /><br />
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="p2.5.1" name="p2.5.1" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" title="Examples"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h3 style="background-color: white; font-family: serif; font-size: 1.3em; margin-bottom: 0.8em; margin-top: 0.8em;">
2.5.1 Examples</h3>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e17" name="e17" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 17</u> Cities in table1 intersect [distinct] cities in table2.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM table1
INTERSECT
SELECT city FROM table2;
CITY
----------
HELSINKI
RIGA
VILNIUS
</span></pre>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e18" name="e18" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 18</u> Cities in table2 intersect [distinct] empty set (cities in table3). Every intersection with empty set is empty set.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM table1
INTERSECT
SELECT city FROM table3;
no rows selected
</span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Intersect all is not possible in Oracle or SQL Server just like with Minus (Except) all. But we can use already known workaround.</span><a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e19" name="e19" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 19</u> Faked intersect all using row_number() analytic function. Cities in table1 intersect all cities in table2.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM (
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table1
INTERSECT
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table2
) q;
CITY
----------
HELSINKI
RIGA
RIGA
VILNIUS
</span></pre>
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="p2.6" name="p2.6" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" title="Raising it to higher levels - are two table data equal?"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h3 style="background-color: white; font-family: serif; font-size: 1.3em; margin-bottom: 0.8em; margin-top: 0.8em;">
2.6 Raising it to higher levels - are two table data equal?</h3>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">There are times when we need to find whether two table data are equal. And here I mean "really equal" i.e. both the rows are equal and in case of duplicate rows cardinality of them also are the same. So what we need is to test whether the "opposite" of Intersect i.e. rows that are returned only by the first query or the second query is empty set. Visually it would be as in following picture grey area would be empty.</span><br />
<img alt="SQL symmetric difference" src="http://www.gplivna.eu/papers/sql_set_operators_files/09_sql_symmetric_difference.gif" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" /><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">In set theory "the opposite" of intersect can be referred as </span><i style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Symmetric difference</i><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">, which is similar to XOR (exclusive OR) in Boolean logic.</span><br />
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Unfortunately there isn't such </span><i style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Symmetric difference</i><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"> operator in SQL. So we need to be more creative. Looking at previous pictures throughout this article it is quite obvious what we need:</span><br />
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">(Query 1 MINUS Query2)
UNION
(Query 2 MINUS Query1)
</span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">In case of absolutely unique rows it would be sufficient - as soon as it returns at least one row, tables' data are not equal. But. We have to remember that there might be duplicates and amount of them might be different in both result sets. So then we'd need:</span><br />
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">(Query 1 MINUS <b>ALL</b> Query2)
UNION <b>ALL</b>
(Query 2 MINUS <b>ALL</b> Query1)
</span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">Let's look at real examples.</span><a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e20" name="e20" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 20</u> Distinct Symmetric difference of table1 and table2.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">(SELECT city FROM table1
MINUS
SELECT city FROM table2)
UNION
(SELECT city FROM table1
MINUS
SELECT city FROM table2);
CITY
----------
STOCKHOLM
TALLINN
</span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">It is obvious that somehow these tables are different. But exactly how? Then we'd need smarter query.</span><a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e21" name="e21" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 21</u> Symmetric difference retaining cardinality of table1 and table2.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city FROM (
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table1
MINUS
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table2
) q
UNION ALL
SELECT city FROM (
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table2
MINUS
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table1
) q;
CITY
----------
HELSINKI
RIGA
STOCKHOLM
TALLINN
TALLINN
TALLINN
VILNIUS
VILNIUS
VILNIUS
</span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">So these are rows that are left outside in one or another table. What if we'd like to know in what table exactly? Just add a flag column.</span><a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="e22" name="e22" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h4 style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 0.9em; margin-bottom: 3px; margin-top: 3px;">
<u>Example 22</u> Symmetric difference retaining cardinality and showing what is missed of table1 and table2.</h4>
<pre style="background-color: white; font-size: 1.2em; margin-bottom: 0.5em; margin-top: 0.5em;"><span style="background-color: silver;">SELECT city, 2 flag FROM (
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table1
MINUS
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table2
) q
UNION ALL
SELECT city, 1 flag FROM (
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table2
MINUS
SELECT city,
row_number() OVER (PARTITION BY city ORDER BY city) rn
FROM table1
) q;
CITY FLAG
---------- ----------
HELSINKI 2
RIGA 2
STOCKHOLM 2
TALLINN 2
TALLINN 2
TALLINN 2
VILNIUS 1
VILNIUS 1
VILNIUS 1
</span></pre>
<span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;">So we can see that table2 misses one Helsinki, one Stockholm and 3 Tallin rows and table1 misses 3 Vilnius rows. If we'd add these rows, then they'd contain exactly the same cities with exactly the same cardinality.</span><a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" id="p3" name="p3" style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;" title="Example usage for various DBMSes"></a><span style="background-color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 13px;"></span><br />
<h2 style="background-color: white; font-family: serif; margin-bottom: 1em; margin-top: 1em;">
</h2>
</div>
Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com0tag:blogger.com,1999:blog-2521368012158105098.post-82896316138955272932012-08-01T05:01:00.001-07:002012-08-01T05:01:03.143-07:00User password expiry check<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
set linesize 999<br />
set pagesize 999<br />
col expiry_date for a20<br />
select NAME, username , expiry_date , account_status from v$database, dba_users where expiry_date < sysdate+30 and account_status IN ( 'OPEN', 'EXPIRED(GRACE)' )and username IN ('SYSTEM','SYS','DBSNMP')<br />
order by account_status, expiry_date, username<br />
/<br />
</div>Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com0tag:blogger.com,1999:blog-2521368012158105098.post-86121065025353477462012-07-10T06:14:00.000-07:002012-07-10T06:14:12.748-07:00RMAN error ORA-00230: operation disallowed: snapshot control file enqueue unavailable<div dir="ltr" style="text-align: left;" trbidi="on">
I found an error message in the alertlog about RMAN backup.<br /><br />Mod Nov 07 08:46:02 NZDT 2011<br />Starting control autobackup<br />Autobackup failed with following error<br />ORA-00230: operation disallowed: snapshot control file enqueue unavailable<br /><br />The error looks like other process is holding the controlfile hence the rman can’t do the snapshot. Most likely is the previous backup process job is still holding it, so let’s check what we have in the database<br /><br />SQL> select sid, serial#, status, logon_time from v$session where program like ‘%rman%’;<br /><br />SID SERIAL# STATUS LOGON_TIME<br />—– ——- ———— —————<br />198 67 ACTIVE 06-NOV-11<br />219 31393 INACTIVE 06-NOV-11<br />203 10571 INACTIVE 06-NOV-11<br />210 403 INACTIVE 06-NOV-11<br />199 3791 INACTIVE 06-NOV-11<br />200 2627 INACTIVE 06-NOV-11<br /><br />as we can see there are left running processes over the weekend. Now the question is why the weekend backup process is still running? I checked the filesystem and found I can’t access (hung session) the autofs mount point, this is the reason why the process is still running. The SA restarted the autofs process to resolve the issue</div>Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com0tag:blogger.com,1999:blog-2521368012158105098.post-39360720062593377392012-06-27T21:04:00.001-07:002012-06-27T21:07:59.359-07:00Log On Scripts and Prevent Users Login frm another Tools<div dir="ltr" style="text-align: left;" trbidi="on">
To limiting access of a user to a database based on time interval. We can prevent a specific user to access to a database between 08 and 22.<br />
created a logon script and see how it’s working:<br />
<br />
<pre>C:\Documents and Settings\Administrator>sqlplus <span style="color: red;">"/as sysdba"</span>
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jul 28 14:56:58 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> create user kan identified by kan;
User created.
SQL> grant connect, resource to kan;
Grant succeeded.
SQL> conn kan/kan
Connected.
SQL> disc
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Pr
oduction
With the Partitioning, OLAP and Data Mining options
SQL> conn / as sysdba
Connected.
SQL> CREATE OR REPLACE TRIGGER limit_connection
2 AFTER LOGON ON DATABASE
3 BEGIN
4 IF USER = <span style="color: navy;">'KAN'</span> THEN
5 IF to_number(TO_CHAR (SYSDATE, <span style="color: navy;">'hh24'</span>)) BETWEEN 8 AND 22
6 THEN
7 RAISE_APPLICATION_ERROR(-20998,<span style="color: navy;">' Dear user '</span>||USER||<span style="color: navy;">'! You can'</span><span style="color: navy;">'t login between 08 and 22'</span>);
8 END IF;
9 END IF;
10 END limit_connection;
11 /
Trigger created.
SQL> select to_char(sysdate,<span style="color: navy;">'hh24'</span>) from dual;
TO
--
23
SQL> conn kan/kan
Connected.
SQL> select to_char(sysdate,<span style="color: navy;">'hh24'</span>) from dual;
TO
--
18
SQL> conn kan/kan
ERROR:
ORA-00604: error occurred at recursive SQL level 1
ORA-20998: Dear user KAN! You can<span style="color: navy;">'t login between 08 and 22</span>
ORA-06512: at line 5
Warning: You are no longer connected to ORACLE.
SQL></pre>
<br />
<br />
<br />
<br />
To prevent users from using additional tools to connect to production database. This is the AFTER LOGON trigger create ON DATABASE as follows:<br />
<br />
<pre style="background: rgb(254, 254, 254); font-family: monospace;"><a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=CONNECT"><span style="color: blue;">CONNECT</span></a> <span style="color: blue;">/</span> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=AS"><span style="color: blue;">AS</span></a> SYSDBA<span style="color: blue;">;</span>
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=CREATE"><span style="color: blue;">CREATE</span></a> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=OR"><span style="color: blue;">OR</span></a> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=REPLACE"><span style="color: black;">REPLACE</span></a> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=TRIGGER"><span style="color: blue;">TRIGGER</span></a> block_tools_from_prod
AFTER LOGON <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=ON"><span style="color: blue;">ON</span></a> DATABASE
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=DECLARE"><span style="color: blue;">DECLARE</span></a>
v_prog sys<span style="color: blue;">.</span>v_$session<span style="color: blue;">.</span>program<span style="color: blue;">%</span><a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=TYPE"><span style="color: blue;">TYPE</span></a><span style="color: blue;">;</span>
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=BEGIN"><span style="color: blue;">BEGIN</span></a>
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=SELECT"><span style="color: blue;">SELECT</span></a> program <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=INTO"><span style="color: blue;">INTO</span></a> v_prog
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=FROM"><span style="color: blue;">FROM</span></a> sys<span style="color: blue;">.</span>v_$session
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=WHERE"><span style="color: blue;">WHERE</span></a> audsid <span style="color: blue;">=</span> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=USERENV"><span style="color: black;">USERENV</span></a><span style="color: blue;">(</span><span style="color: red;">'SESSIONID'</span><span style="color: blue;">)</span>
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=AND"><span style="color: blue;">AND</span></a> audsid <span style="color: blue;">!=</span> <span style="color: #880000;">0</span> <span style="color: #008800; font-style: italic;">-- Don't Check SYS Connections</span>
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=AND"><span style="color: blue;">AND</span></a> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=ROWNUM"><span style="color: blue;">ROWNUM</span></a> <span style="color: blue;">=</span> <span style="color: #880000;">1</span><span style="color: blue;">;</span> <span style="color: #008800; font-style: italic;">-- Parallel processes will have the same AUDSID's</span>
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=IF"><span style="color: blue;">IF</span></a> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=UPPER"><span style="color: black;">UPPER</span></a><span style="color: blue;">(</span>v_prog<span style="color: blue;">)</span> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=LIKE"><span style="color: blue;">LIKE</span></a> <span style="color: red;">'%TOAD%'</span> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=OR"><span style="color: blue;">OR</span></a> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=UPPER"><span style="color: black;">UPPER</span></a><span style="color: blue;">(</span>v_prog<span style="color: blue;">)</span> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=LIKE"><span style="color: blue;">LIKE</span></a> <span style="color: red;">'%T.O.A.D%'</span> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=OR"><span style="color: blue;">OR</span></a> <span style="color: #008800; font-style: italic;">-- Toad</span>
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=UPPER"><span style="color: black;">UPPER</span></a><span style="color: blue;">(</span>v_prog<span style="color: blue;">)</span> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=LIKE"><span style="color: blue;">LIKE</span></a> <span style="color: red;">'%SQLNAV%'</span> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=OR"><span style="color: blue;">OR</span></a> <span style="color: #008800; font-style: italic;">-- SQL Navigator</span>
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=UPPER"><span style="color: black;">UPPER</span></a><span style="color: blue;">(</span>v_prog<span style="color: blue;">)</span> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=LIKE"><span style="color: blue;">LIKE</span></a> <span style="color: red;">'%PLSQLDEV%'</span> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=OR"><span style="color: blue;">OR</span></a> <span style="color: #008800; font-style: italic;">-- PLSQL Developer</span>
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=UPPER"><span style="color: black;">UPPER</span></a><span style="color: blue;">(</span>v_prog<span style="color: blue;">)</span> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=LIKE"><span style="color: blue;">LIKE</span></a> <span style="color: red;">'%BUSOBJ%'</span> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=OR"><span style="color: blue;">OR</span></a> <span style="color: #008800; font-style: italic;">-- Business Objects</span>
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=UPPER"><span style="color: black;">UPPER</span></a><span style="color: blue;">(</span>v_prog<span style="color: blue;">)</span> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=LIKE"><span style="color: blue;">LIKE</span></a> <span style="color: red;">'%EXCEL%'</span> <span style="color: #008800; font-style: italic;">-- MS-Excel plug-in</span>
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=THEN"><span style="color: blue;">THEN</span></a>
RAISE_APPLICATION_ERROR<span style="color: blue;">(</span><span style="color: blue;">-</span><span style="color: #880000;">20000</span><span style="color: blue;">,</span> <span style="color: red;">'Development tools are not allowed here.'</span><span style="color: blue;">)</span><span style="color: blue;">;</span>
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=END"><span style="color: blue;">END</span></a> <a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=IF"><span style="color: blue;">IF</span></a><span style="color: blue;">;</span>
<a href="http://www.oracle.com/pls/db10g/search?remark=quick_search&word=END"><span style="color: blue;">END</span></a><span style="color: blue;">;</span>
<span style="color: blue;">/</span>
SHOW ERRORS</pre>
</div>Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com0tag:blogger.com,1999:blog-2521368012158105098.post-74187606762926246942012-06-25T03:41:00.000-07:002012-06-25T03:41:59.061-07:00DBA_SCHEDULER_JOBs<div dir="ltr" style="text-align: left;" trbidi="on">
This query will give you the names and the status of the jobs scheduled by DBMS_SCHEDULER:<br /><br />SELECT job_name,enabled FROM DBA_SCHEDULER_JOBs;<br /><br /><div>
sql> select job, what from dba_jobs where broken = 'Y' or failures > 0;</div>
<div>
<br /></div>
<div>
sql> select d.job_name,d.job_action from dba_scheduler_jobs d, sys.scheduler$_jobs where d.job_action = s.program_action and s.obj# = &myjobnum;</div>
<div>
<br /></div>
<div>
<br /></div>
Then use "exec dbms_scheduler.disable" to disable each one as below:<br /><br />I created a script "disablejobs.sql" as :<br /><br />exec dbms_scheduler.disable('SYS.XMLDB_NFS_CLEANUP_JOB');<br />exec dbms_scheduler.disable('SYS.SM$CLEAN_AUTO_SPLIT_MERGE');<br />exec dbms_scheduler.disable('SYS.RSE$CLEAN_RECOVERABLE_SCRIPT');<br />exec dbms_scheduler.disable('SYS.FGR$AUTOPURGE_JOB');<br />exec dbms_scheduler.disable('SYS.BSLN_MAINTAIN_STATS_JOB');<br />exec dbms_scheduler.disable('SYS.DRA_REEVALUATE_OPEN_FAILURES');<br />exec dbms_scheduler.disable('SYS.HM_CREATE_OFFLINE_DICTIONARY');<br />exec dbms_scheduler.disable('SYS.ORA$AUTOTASK_CLEAN');<br />exec dbms_scheduler.disable('SYS.FILE_WATCHER');<br />exec dbms_scheduler.disable('SYS.PURGE_LOG');<br />exec dbms_scheduler.disable('SYS.MGMT_STATS_CONFIG_JOB');<br />exec dbms_scheduler.disable('SYS.MGMT_CONFIG_JOB');<br />exec dbms_scheduler.disable('SYS.RLM$SCHDNEGACTION');<br />exec dbms_scheduler.disable('SYS.RLM$EVTCLEANUP');<br /><br /><br /><br />and then executed:<br /><br />SQL> @disablejobs.sql<br /><br />PL/SQL procedure successfully completed.</div>Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com1tag:blogger.com,1999:blog-2521368012158105098.post-62046406335275024282012-06-25T02:34:00.000-07:002012-06-25T02:34:39.032-07:00inbound connection timed out (ORA-3136)<div dir="ltr" style="text-align: left;" trbidi="on">
<br />WARNING: inbound connection timed out (ORA-3136)<br /><br /><br /><br />The "WARNING: inbound connection timed out (ORA-3136)" in the alert log indicates that the client was not able to complete it's authentication within the period of time specified by parameter SQLNET.INBOUND_CONNECT_TIMEOUT.<br /><br />You may also witness ORA-12170 without timeout error on the database server sqlnet.log file.<br />This entry would also have the clinet address which failed to get authenticated. Some applications or JDBC thin driver applications may not have these details.<br /><br />From 10.2 onwards the default value of this parameter is 60 seconds, hence if the client is not able authenticate within 60 secs , the warning would appear in the alert log and the client connection will be terminated.<br /><br />This timeout restriction was introduced to combat Denial of Service (DoS) attack whereby malicious clients attempt to flood database servers with connect requests that consumes resources.<br /><br />There can be three main reasons for this error<br />Server gets a connection request from a malicious client which is not supposed to connect to the database , in which case the error thrown is the correct behavior. You can get the client address for which the error was thrown via sqlnet log file.<br />The server receives a valid client connection request but the client takes a long time to authenticate more than the default 60 seconds.<br />The DB server is heavily loaded due to which it cannot finish the client logon within the timeout specified.<br /><br />The default value of 60 seconds is good enough in most conditions for the database server to authenticate a client connection. If its taking longer period, then its worth checking all the below points before going for the workadound:<br /><br />1. Check whether local connection on the database server is sucessful & quick.<br /><br />2. If local connections are quick ,then check for underlying network delay with the help of your network administrator.<br /><br />3. Check whether your Database performance has degraded by anyway.<br /><br />4. Check alert log for any critical errors for eg, ORA-600 or ORA-7445 and get them resolved first.<br />These critical errors might have triggered the slowness of the database server.<br /><br /><br /><br />As a workaround to avoid only this warning messages, you can set the parameters SQLNET.INBOUND_CONNECT_TIMEOUT and INBOUND_CONNECT_TIMEOUT_listenername<br />to the value more than 60. <br /><br />In server side sqlnet.ora file add SQLNET.INBOUND_CONNECT_TIMEOUT<br /><br /><br />SQLNET.INBOUND_CONNECT_TIMEOUT = 120In listener.ora file INBOUND_CONNECT_TIMEOUT_listenername<br /><br /><br />INBOUND_CONNECT_TIMEOUT_LISTENER = 110<br /><br /><br /><br />From Oracle version 10.2.0.3 onwards the default value of INBOUND_CONNECT_TIMEOUT_<br /> is 60 seconds. For previous releases it is zero by default.</div>Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com3tag:blogger.com,1999:blog-2521368012158105098.post-52423055976162912702012-06-15T22:12:00.002-07:002012-06-15T22:12:27.012-07:00Resizing / Recreating Online Redo Log Files<div dir="ltr" style="text-align: left;" trbidi="on">
One of the best ways I have found to resize or recreate online redo log files and keep the current sequence is to perform it online. In this example, we will resize all online redo logs from 100MB to 250MB while the database is running and use SQL*Plus to drop/recreate them in stages. <br />
Before looking at the tasks involved to perform the resize, let's look at the current online redo log groups and their sizes: <br />
<table class="codeExampleTable"><tbody>
<tr><td><pre>
SQL> <b>SELECT a.group#, a.member, b.bytes</b>
2 <b>FROM v$logfile a, v$log b WHERE a.group# = b.group#;</b>
GROUP# MEMBER BYTES
---------- ---------------------------------------- ------------
1 /u03/app/oradata/ORA920/redo_g01a.log 104,857,600
1 /u04/app/oradata/ORA920/redo_g01b.log 104,857,600
1 /u05/app/oradata/ORA920/redo_g01c.log 104,857,600
2 /u03/app/oradata/ORA920/redo_g02a.log 104,857,600
2 /u04/app/oradata/ORA920/redo_g02b.log 104,857,600
2 /u05/app/oradata/ORA920/redo_g02c.log 104,857,600
3 /u03/app/oradata/ORA920/redo_g03a.log 104,857,600
3 /u04/app/oradata/ORA920/redo_g03b.log 104,857,600
3 /u05/app/oradata/ORA920/redo_g03c.log 104,857,600
9 rows selected.</pre>
</td></tr>
</tbody></table>
Now let's take a look at the steps involved to resize / recreate all online redo log groups: <br />
<br />
<ol>
<li><b>Make the last redo log CURRENT</b> <br />
Force a log switch until the last redo log is marked "CURRENT" by issuing the following command: <br />
<table class="codeExampleTable"><tbody>
<tr><td><pre>
SQL> <b>select group#, status from v$log;</b>
GROUP# STATUS
---------- ----------------
<span style="color: green;"><b>1 CURRENT</b></span>
2 INACTIVE
3 INACTIVE
SQL> <b>alter system switch logfile;</b>
SQL> <b>alter system switch logfile;</b>
SQL> <b>select group#, status from v$log;</b>
GROUP# STATUS
---------- ----------------
1 INACTIVE
2 INACTIVE
<span style="color: green;"><b>3 CURRENT</b></span></pre>
</td></tr>
</tbody></table>
</li>
<li><b>Drop first redo log</b> <br />
After making the last online redo log file the CURRENT one, drop the first online redo log: <br />
<table class="codeExampleTable"><tbody>
<tr><td><pre>
SQL> <b>alter database drop logfile group 1;</b>
Database altered.</pre>
</td></tr>
</tbody></table>
<div class="boxLeftPadding">
<table class="messageDialogBox"><tbody>
<tr><td><table><tbody>
<tr><td nowrap="" valign="top"><img border="0" src="http://www.idevelopment.info/images/popup_dialog_information_mark.gif" /> </td><td> As a DBA, you should already be aware that if you are going to drop a logfile group, it cannot be the <i>current</i> logfile group. I have run into instances; however, where attempting to drop the logfile group resulted in the following error as a result of the logfile group having an <i>active</i> status: <br />
<pre>SQL> <b>ALTER DATABASE DROP LOGFILE GROUP 1;</b>
<span style="color: red;">ALTER DATABASE DROP LOGFILE GROUP 1
*
ERROR at line 1:
ORA-01624: log 1 needed for crash recovery of instance ORA920 (thread 1)
ORA-00312: online log 1 thread 1: '<i><file_name></i>'</span></pre>
Easy problem to resolve. Simply perform a checkpoint on the database: <br />
<pre>SQL> <b>ALTER SYSTEM CHECKPOINT GLOBAL;</b>
System altered.
SQL> <b>ALTER DATABASE DROP LOGFILE GROUP 1;</b>
Database altered.</pre>
</td></tr>
</tbody></table>
</td></tr>
</tbody></table>
</div>
</li>
<li><b>Re-create dropped online redo log group</b> <br />
Re-create the dropped redo log group with different size (if desired): <br />
<table class="codeExampleTable"><tbody>
<tr><td><pre>
SQL> <b>alter database add logfile group 1 (</b>
2 <b>'/u03/app/oradata/ORA920/redo_g01a.log',</b>
3 <b>'/u04/app/oradata/ORA920/redo_g01b.log',</b>
4 <b>'/u05/app/oradata/ORA920/redo_g01c.log') size 250m reuse;</b>
Database altered.</pre>
</td></tr>
</tbody></table>
</li>
<li><b>Force another log switch</b> <br />
After re-creating the online redo log group, force a log switch. The online redo log group just created should become the "CURRENT" one: <br />
<table class="codeExampleTable"><tbody>
<tr><td><pre>
SQL> <b>select group#, status from v$log;</b>
GROUP# STATUS
---------- ----------------
1 UNUSED
2 INACTIVE
<span style="color: green;"><b>3 CURRENT</b></span>
SQL> <b>alter system switch logfile;</b>
SQL> <b>select group#, status from v$log;</b>
GROUP# STATUS
---------- ----------------
<span style="color: green;"><b>1 CURRENT</b></span>
2 INACTIVE
3 ACTIVE</pre>
</td></tr>
</tbody></table>
</li>
<li><b>Loop back to Step 2 until all logs are rebuilt</b> <br />
After re-creating an online redo log group, continue to re-create (or resize) all online redo log groups until all of them are rebuilt. </li>
</ol>
<br />
After rebuilding (resizing) all online redo log groups, here is a snapshot of all physical files: <br />
<table class="codeExampleTable"><tbody>
<tr><td><pre>
SQL> <b>SELECT a.group#, a.member, b.bytes</b>
2 <b>FROM v$logfile a, v$log b WHERE a.group# = b.group#;</b>
GROUP# MEMBER BYTES
---------- ---------------------------------------- ------------
1 /u03/app/oradata/ORA920/redo_g01a.log 262,144,000
1 /u04/app/oradata/ORA920/redo_g01b.log 262,144,000
1 /u05/app/oradata/ORA920/redo_g01c.log 262,144,000
2 /u03/app/oradata/ORA920/redo_g02a.log 262,144,000
2 /u04/app/oradata/ORA920/redo_g02b.log 262,144,000
2 /u05/app/oradata/ORA920/redo_g02c.log 262,144,000
3 /u03/app/oradata/ORA920/redo_g03a.log 262,144,000
3 /u04/app/oradata/ORA920/redo_g03b.log 262,144,000
3 /u05/app/oradata/ORA920/redo_g03c.log 262,144,000
9 rows selected.</pre>
</td></tr>
</tbody></table>
<!--
| ******************************************************
| About the Author
| ******************************************************
+--> <a href="" name="About the Author"></a> <br />
<h1>
</h1>
</div>Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com0tag:blogger.com,1999:blog-2521368012158105098.post-76030112470903691362012-06-15T22:10:00.003-07:002012-06-15T22:10:39.375-07:00Configuring Kernel Parameters For Oracle 10g Installation<div dir="ltr" style="text-align: left;" trbidi="on">
<br />This section documents the checks and modifications to the Linux kernel that should be made by the DBA to support Oracle Database 10g. Before detailing these individual kernel parameters, it is important to fully understand the key kernel components that are used to support the Oracle Database environment.<br /> <br /><br /> <br />The kernel parameters and shell limits presented in this section are recommended values only as documented by Oracle. For production database systems, Oracle recommends that we tune these values to optimize the performance of the system. <br /><br /> <br />Verify that the kernel parameters shown in this section are set to values greater than or equal to the recommended values. <br /><br /> <br />Shared Memory : Shared memory allows processes to access common structures and data by placing them in a shared memory segment. This is the fastest form of Inter-Process Communications (IPC) available - mainly due to the fact that no kernel involvement occurs when data is being passed between the processes. Data does not need to be copied between processes . <br /><br /> <br />Oracle makes use of shared memory for its Shared Global Area (SGA) which is an area of memory that is shared by all Oracle backup and foreground processes. Adequate sizing of the SGA is critical to Oracle performance since it is responsible for holding the database buffer cache, shared SQL, access paths, and so much more. <br /><br /> <br />To determine all current shared memory limits, use the following :<br /><br /> <br /># ipcs -lm <br />------ Shared Memory Limits -------- <br />max number of segments = 4096 <br />max seg size (kbytes) = 4194303 <br />max total shared memory (kbytes) = 1073741824 <br />min seg size (bytes) = 1 <br /><br /> <br />The following list describes the kernel parameters that can be used to change the shared memory configuration for the server: <br /><br /> <br />1.) shmmax - Defines the maximum size (in bytes) for a shared memory segment. The Oracle SGA is comprised of shared memory and it is possible that incorrectly setting shmmax could limit the size of the SGA. When setting shmmax, keep in mind that the size of the SGA should fit within one shared memory segment. An inadequate shmmax setting could result in the following: <br />ORA-27123: unable to attach to shared memory segment <br /><br /> <br />We can determine the value of shmmax by performing the following :<br /><br /> <br /># cat /proc/sys/kernel/shmmax <br />4294967295 <br /><br /> <br />For most Linux systems, the default value for shmmax is 32MB. This size is often too small to configure the Oracle SGA. The default value for shmmax in CentOS 5 is 4GB which is more than enough for the Oracle configuration. Note that this value of 4GB is not the "normal" default value for shmmax in a Linux environment inserts the following two entries in the file /etc/sysctl.conf:<br /><br /> <br /># Controls the maximum shared segment size, in bytes <br />kernel.shmmax = 4294967295 <br /><br /> <br />2.) shmmni : This kernel parameter is used to set the maximum number of shared memory segments system wide. The default value for this parameter is 4096. This value is sufficient and typically does not need to be changed. We can determine the value of shmmni by performing the following:<br /><br /> <br /># cat /proc/sys/kernel/shmmni <br />4096 <br /><br /> <br />3.) shmall : This parameter controls the total amount of shared memory (in pages) that can be used at one time on the system. The value of this parameter should always be at least: We can determine the value of shmall by performing the following :<br /><br /> <br /># cat /proc/sys/kernel/shmall <br />268435456 <br /><br /> <br />For most Linux systems, the default value for shmall is 2097152 and is adequate for most configurations. The default value for shmall in CentOS 5 is 268435456 (see above) which is more than enough for the Oracle configuration described in this article. Note that this value of 268435456 is not the "normal" default value for shmall in a Linux environment , inserts the following two entries in the file /etc/sysctl.conf:<br /><br /> <br /># Controls the maximum number of shared memory segments, in pages <br />kernel.shmall = 268435456 <br /><br /> <br />4.) shmmin : This parameter controls the minimum size (in bytes) for a shared memory segment. The default value for shmmin is 1 and is adequate for the Oracle configuration described in this article.We can determine the value of shmmin by performing the following: <br /><br /> <br /># ipcs -lm | grep "min seg size" <br />min seg size (bytes) = 1 <br /><br /> <br />Semaphores : <br />After the DBA has configured the shared memory settings, it is time to take care of configuring the semaphores. The best way to describe a semaphore is as a counter that is used to provide synchronization between processes (or threads within a process) for shared resources like shared memory. Semaphore sets are supported in System V where each one is a counting semaphore. When an application requests semaphores, it does so using "sets". To determine all current semaphore limits, use the following:<br /><br /> <br /># ipcs -ls <br />------ Semaphore Limits -------- <br />max number of arrays = 128 <br />max semaphores per array = 250 <br />max semaphores system wide = 32000 <br />max ops per semop call = 32 <br />semaphore max value = 32767 <br /><br /> <br />We can also use the following command: <br /># cat /proc/sys/kernel/sem <br />250 32000 32 128 <br /><br /> <br />The following list describes the kernel parameters that can be used to change the semaphore configuration for the server:<br /><br /> <br />i.) semmsl - This kernel parameter is used to control the maximum number of semaphores per semaphore set. Oracle recommends setting semmsl to the largest PROCESS instance parameter setting in the init.ora file for all databases on the Linux system plus 10. Also, Oracle recommends setting the semmsl to a value of no less than 100. <br /><br /> <br />ii.) semmni - This kernel parameter is used to control the maximum number of semaphore sets in the entire Linux system. Oracle recommends setting semmni to a value of no less than 100. <br /><br /> <br />iii.) semmns - This kernel parameter is used to control the maximum number of semaphores (not semaphore sets) in the entire Linux system. Oracle recommends setting the semmns to the sum of the PROCESSES instance parameter setting for each database on the system, adding the largest PROCESSES twice, and then finally adding 10 for each Oracle database on the system. Use the following calculation to determine the maximum number of semaphores that can be allocated on a Linux system. It will be the lesser of: <br />SEMMNS -or- (SEMMSL * SEMMNI) <br /><br /> <br />iv.) semopm - This kernel parameter is used to control the number of semaphore operations that can be performed per semop system call. The semop system call (function) provides the ability to do operations for multiple semaphores with one semop system call. A semaphore set can have the maximum number of semmslsemaphores per semaphore set and is therefore recommended to set semopm equal to semmsl in some situations. Oracle recommends setting the semopm to a value of no less than 100. <br /><br /> <br />File Handles : <br />When configuring the Linux server, it is critical to ensure that the maximum number of file handles is large enough. The setting for file handles denotes the number of open files that you can have on the Linux system. Use the following command to determine the maximum number of file handles for the entire system: <br /><br /> <br /># cat /proc/sys/fs/file-max <br />102312<br /><br /> <br />Oracle recommends that the file handles for the entire system be set to at least 65536. We can query the current usage of file handles by using the following :<br /><br /> <br /># cat /proc/sys/fs/file-nr <br />3072 0 102312 <br /><br /> <br />The file-nr file displays three parameters: <br />• Total allocated file handles <br />• Currently used file handles <br />• Maximum file handles that can be allocated<br /><br /> <br />If we need to increase the value in /proc/sys/fs/file-max, then make sure that the ulimit is set properly. Usually for Linux 2.4 and 2.6 it is set to unlimited. Verify theulimit setting my issuing the ulimit command : <br /><br /> <br /># ulimit <br />unlimited <br /><br /> <br />IP Local Port Range : <br />Oracle strongly recommends to set the local port range ip_local_port_range for outgoing messages to "1024 65000" which is needed for systems with high-usage. This kernel parameter defines the local port range for TCP and UDP traffic to choose from. <br />The default value for ip_local_port_range is ports 32768 through 61000 which is inadequate for a successful Oracle configuration. Use the following command to determine the value of ip_local_port_range:<br /><br /> <br /># cat /proc/sys/net/ipv4/ip_local_port_range <br />32768 61000 <br /><br /> <br />Networking Settings : <br />With Oracle 9.2.0.1 and later, Oracle makes use of UDP as the default protocol on Linux for inter-process communication (IPC), such as Cache Fusion and Cluster Manager buffer transfers between instances within the RAC cluster. <br /><br /> <br />Oracle strongly suggests to adjust the default and maximum receive buffer size (SO_RCVBUF socket option) to 1MB and the default and maximum send buffer size (SO_SNDBUF socket option) to 256KB.The receive buffers are used by TCP and UDP to hold received data until it is read by the application. The receive buffer cannot overflow because the peer is not allowed to send data beyond the buffer size window.<br /><br /> <br />This means that datagrams will be discarded if they don't fit in the socket receive buffer, potentially causing the sender to overwhelm the receiver. Use the following commands to determine the current buffer size (in bytes) of each of the IPC networking parameters:<br /><br /> <br /># cat /proc/sys/net/core/rmem_default <br />109568<br /><br /> <br /># cat /proc/sys/net/core/rmem_max <br />131071<br /><br /> <br /># cat /proc/sys/net/core/wmem_default <br />109568<br /><br /> <br /># cat /proc/sys/net/core/wmem_max <br />131071 <br /><br /> <br />Setting Kernel Parameters for Oracle <br />If the value of any kernel parameter is different to the recommended value, they will need to be modified. For this article, I identified and provide the following values that will need to be added to the /etc/sysctl.conf file which is used during the boot process.<br /><br /> <br />kernel.shmmax = 2147483648 <br />kernel.shmmni = 4096 <br />kernel.shmall = 2097152 <br />kernel.sem = 250 32000 100 128 <br />fs.file-max = 65536 <br />net.ipv4.ip_local_port_range = 1024 65000 <br />net.core.rmem_default = 1048576 <br />net.core.rmem_max = 1048576 <br />net.core.wmem_default = 262144 <br />net.core.wmem_max = 262144 <br /><br /> <br />After adding the above lines to the /etc/sysctl.conf file, they persist each time the system reboots. If we would like to make these kernel parameter value changes to the current system without having to first reboot, enter the following command:<br /><br /> <br /># /sbin/sysctl –p</div>Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com0tag:blogger.com,1999:blog-2521368012158105098.post-38013765912517098872012-06-15T22:09:00.000-07:002012-06-15T22:09:30.169-07:00SHMMAX and SHMALL for Oracle in Linux<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;">SHMMAX and SHMALL are
two key shared memory parameters that directly impact’s the way by which Oracle
creates an SGA. Shared memory is nothing but part of Unix IPC System (Inter
Process Communication) maintained by kernel where multiple processes share a
single chunk of memory to communicate with each other.</span>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<div style="margin: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;"><br /></span></span></div>
<div style="margin: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">While
trying to create an SGA during a database startup, Oracle chooses from one of
the 3 memory management models a) one-segment or b) contiguous-multi segment or
c) non-contiguous multi segment. Adoption of any of these models is dependent on
the size of SGA and values defined for the shared memory parameters in the linux
kernel, most importantly SHMMAX.<o:p></o:p></span></span></div>
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><u1:p></u1:p></span><br />
<div style="margin: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;"><b><u><br /></u></b></span><br /><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;"><b><u>So what are
these parameters - SHMMAX and SHMALL?</u></b></span><br /><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;"><b><u><br /></u></b></span><br /><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;">SHMMAX is
the <b>maximum size</b> of a <b>single shared memory segment</b> set in
“<b>bytes”.</b></span></div>
<div style="margin: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New"; font-size: 12px;"><br /></span><br /><span class="Apple-style-span" style="font-family: "Courier New"; font-size: 12px;">silicon:~ # cat
/proc/sys/kernel/shmmax</span></div>
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">536870912</span><span style="color: black; font-family: "Times New Roman", serif; font-size: 9pt;"><o:p></o:p></span></span></div>
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;"><br /></span><br /><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;">SHMALL is the <b>total
size of Shared Memory Segments System wide</b> set in “<b style="mso-bidi-font-weight: normal;">pages”.</b></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New"; font-size: 12px;"><br /></span><br /><span class="Apple-style-span" style="font-family: "Courier New"; font-size: 12px;">silicon:~ # cat
/proc/sys/kernel/shmall</span><br /><span class="Apple-style-span" style="font-family: "Courier New";"></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">1415577</span><span style="color: black; font-family: "Times New Roman", serif; font-size: 9pt;"><o:p></o:p></span></span></div>
</div>
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;"><br /></span><br /><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;">The key thing to note
here is the value of SHMMAX is set in "<b>bytes</b>" but the value of SHMMALL is
set in "<b>pages</b>".</span><br /><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;"><br /></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;"><b><u>What’s the
optimal value for SHMALL?</u></b></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;"><br /></span><br /><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;">As SHMALL is the total
size of Shard Memory Segments System wide, it should always be less than the
Physical Memory on the System and should also be less than sum of SGA’s of all
the oracle databases on the server. Once this value (sum of SGA’s) hit the
limit, i.e. the value of shmall, then any attempt to start a new database (or
even an existing database with a resized SGA) will result in an “out of memory”
error (below). This is because there won’t be any more shared memory segments
that Linux can allocate for SGA.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New"; font-size: 12px;"><br /></span><br /><span class="Apple-style-span" style="font-family: "Courier New"; font-size: 12px;">ORA-27102: out of
memory</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">Linux-x86_64
Error: 28: No space left on device.<o:p></o:p></span></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;"><br /></span><br /><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;">So above can happen
for two reasons. Either the value of shmall is not set to an optimal value or
you have reached the threshold on this server.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">Setting
the value for SHMALL to optimal is straight forward. All you want to know is how
much “Physical Memory” (excluding Cache/Swap) you have on the system and how
much of it should be set aside for Linux Kernel and to be dedicated to Oracle
Databases.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">For e.g.
Let say the Physical Memory of a system is 6GB, out of which you want to set
aside 1GB for Linux Kernel for OS Operations and dedicate the rest of 5GB to
Oracle Databases. Then here’s how you will get the value for
SHMALL.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">Convert
this 5GB to bytes and divide by page size. Remember SHMALL should be set in
“pages” not “bytes”.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">So here
goes the calculation.<o:p></o:p></span></span></div>
<span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;"><br /></span><br /><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;">Determine Page Size
first, can be done in two ways. In my case it’s 4096 and that’s the recommended
and default in most cases which you can keep the same. </span><br /><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">silicon:~ #
getconf PAGE_SIZE</span><span style="color: black; font-family: "Times New Roman", serif; font-size: 9pt;"><o:p></o:p></span></span></div>
<span class="Apple-style-span" style="font-family: "Courier New";"></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">4096</span><span style="color: black; font-family: "Times New Roman", serif; font-size: 9pt;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><br /></span><br /><span class="Apple-style-span" style="font-family: "Courier New";">or</span><br /><span class="Apple-style-span" style="font-family: "Courier New";"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">silicon:~ # cat
/proc/sys/kernel/shmmni<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">4096<o:p></o:p></span></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">Convert
5GB into bytes and divide by page size, I used the linux calc to do the
math.</span><span style="color: black; font-family: "Courier New"; font-size: 9pt;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">silicon:~ #
echo "( 5 * 1024 * 1024 * 1024 ) / 4096 " | bc
-l<o:p></o:p></span></span></div>
<span class="Apple-style-span" style="font-family: "Courier New";"></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">1310720.00000000000000000000<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;"><br /></span></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span class="Apple-style-span" style="font-size: 12px;"></span></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">Reset
shmall and load it dynamically into kernel<o:p></o:p></span></span></div>
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">silicon:~ #
echo "1310720" > /proc/sys/kernel/shmall<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New"; font-size: 12px;">silicon:~ # sysctl
–p</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">Verify if
the value has been taken into effect.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">silicon:~ #
sysctl -a | grep shmall<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">kernel.shmall =
1310720<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">Another
way to look this up is<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">silicon:~ #
ipcs -lm<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">------ Shared
Memory Limits --------<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">max number of
segments = 4096 /* SHMMNI
*/<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">max seg size
(kbytes) = 524288 /* SHMMAX */<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">max total
shared memory (kbytes) = 5242880 /* SHMALL
*/<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">min seg size
(bytes) = 1<o:p></o:p></span></span></div>
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span class="Apple-style-span" style="font-size: 12px;"></span></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">To keep
the value effective after every reboot, add the following line to
/etc/sysctl.conf<o:p></o:p></span></span></div>
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">echo
“kernel.shmall = 1310720” >>
/etc/sysctl.conf<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;">Also verify if
sysctl.conf is enabled or will be read during boot.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">silicon:~ #
chkconfig boot.sysctl<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">boot.sysctl
on<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">If
returns “off”, means it’s disabled. Turn it on by
running<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">silicon:~ #
chkconfig boot.sysctl on<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">boot.sysctl
on<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span class="Apple-style-span" style="font-size: 12px;"><b><u><span class="Apple-style-span" style="-webkit-text-decorations-in-effect: none; font-weight: normal;"><b><u>What’s
the optimal value for SHMMAX?</u></b></span></u></b></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;"><br /></span></span></div>
</div>
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<div class="MsoNormal" style="font-family: Verdana, sans-serif; line-height: normal; margin-bottom: 0pt; text-align: justify;">
<span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">Oracle
makes use of one of the 3 memory management models to create the SGA during
database startup and it does this in following sequence. First Oracle attempts
to use the one-segment model and if this fails, it proceeds with the next one
which's the contiguous multi-segment model and if that fails too, it goes with
the last option which is the non-contiguous multi-segment
model.<o:p></o:p></span></div>
<div class="MsoNormal" style="font-family: Verdana, sans-serif; line-height: normal; margin-bottom: 0pt; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="font-family: Verdana, sans-serif; line-height: normal; margin-bottom: 0pt; text-align: justify;">
<span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">So during
startup it looks for <b style="mso-bidi-font-weight: normal;">shmmax</b>
parameter and compares it with the initialization parameter *.sga_target. If
shmmax > *.sga_target, then oracle goes with <b style="mso-bidi-font-weight: normal;">one-segment</b> model approach where the
entire SGA is created within a single shared memory
segment.<o:p></o:p></span></div>
<div class="MsoNormal" style="font-family: Verdana, sans-serif; line-height: normal; margin-bottom: 0pt; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="font-family: Verdana, sans-serif; line-height: normal; margin-bottom: 0pt; text-align: justify;">
<span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">But the
above attempt (one-segment) fails if SGA size otherwise *.sga_target >
shmmax, then Oracle proceeds with the 2<sup>nd</sup> option – contiguous
multi-segment model. Contiguous allocations, as the name indicates are a set of
shared memory segments which are contiguous within the memory and if it can find
such a set of segments then entire SGA is created to fit in within this
set. </span><br /><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;"><br /></span><br /><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">But if
cannot find a set of contiguous allocations then last of the 3 option’s is
chosen – non-contiguous multi-segment allocation and in this Oracle has to grab
the free memory segments fragmented between used spaces.<o:p></o:p></span></div>
<div class="MsoNormal" style="font-family: Verdana, sans-serif; line-height: normal; margin-bottom: 0pt; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="font-family: Verdana, sans-serif; line-height: normal; margin-bottom: 0pt; text-align: justify;">
<span class="Apple-style-span" style="font-size: 12px;">So let’s say if you know the max
size of SGA of any database on the server stays below 1GB, you can set shmmax to
1 GB. But say if you have SGA sizes for different databases spread between 512MB
to 2GB, then set shmmax to 2Gigs and so on.</span></div>
<div class="MsoNormal" style="font-family: Verdana, sans-serif; line-height: normal; margin-bottom: 0pt; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="font-family: Verdana, sans-serif; line-height: normal; margin-bottom: 0pt; text-align: justify;">
<span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">Like
SHMALL, SHMMAX can be defined by one of these methods..<o:p></o:p></span></div>
<div class="MsoNormal" style="font-family: Verdana, sans-serif; line-height: normal; margin-bottom: 0pt; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="font-family: Verdana, sans-serif; line-height: normal; margin-bottom: 0pt; text-align: justify;">
<span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">Dynamically
reset and reload it to the kernel..</span><span style="color: black; font-family: Verdana, sans-serif; font-size: 12pt;"><o:p></o:p></span><br /><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0pt; text-align: justify;">
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0pt; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">silicon:~
# </span><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;"> echo
"536870912" > </span><span style="color: black; font-family: "Courier New"; font-size: 9pt;">/proc/sys/kernel/shmmax<o:p></o:p></span></span></div>
<span class="Apple-style-span" style="font-family: "Courier New";"></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">silicon:~
# </span><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;"> sysctl
–p -- Dynamically reload the
parameters.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">Or use
sysctl to reload and reset ..<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">silicon:~
# </span><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">sysctl -w
kernel.shmmax=536870912</span><span style="color: black; font-family: "Courier New"; font-size: 9pt;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">To
permanently set so it’s effective in reboots…<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;">silicon:~
# </span><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">echo
"kernel.shmmax=536870912" >> </span><span style="color: black; font-family: "Courier New"; font-size: 9pt;">/etc/systctl.conf<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;"><br /></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: justify;">
<span class="Apple-style-span" style="font-family: "Courier New";"><span style="color: black; font-family: "Courier New"; font-size: 9pt;"><span class="Apple-style-span" style="font-family: "Times New Roman"; font-size: x-small;"></span></span></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0pt; text-align: justify;">
<div style="margin: 0px;">
<span class="Apple-style-span"><span style="color: black; font-size: 9pt;"><span style="color: black; font-family: Verdana, sans-serif; font-size: 9pt;">Install
doc for 11g recommends the value of shmmax to be set to "4GB – 1byte" or half
the size of physical memory whichever is lower. I believe “4GB – 1byte” is
related to the limitation on the 32 bit (x86) systems where the virtual address
space for a user process can only be little less than 4GB. As there’s no such
limitation for 64bit (x86_64) bit systems, you can define SGA’s larger than 4
Gig’s. But i</span><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 12px;">dea here is to let
Oracle use the efficient one-segment model and for this shmmax should stay
higher than SGA size of any individual database on the
system.</span></span></span></div>
</div>
</div>
</div>
</div>
</div>Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com3tag:blogger.com,1999:blog-2521368012158105098.post-29732698254177351002012-06-15T09:10:00.006-07:002012-06-15T09:10:55.694-07:00mknod operation<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="post-body entry-content" id="post-body-989042521611143762" itemprop="articleBody" style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 1.4; position: relative; text-align: -webkit-auto; width: 520px;">
<div dir="ltr" style="text-align: left;" trbidi="on">
<strong><span style="color: #38761d;">Implement the mknod operation using the following example :</span></strong></div>
</div>
<br />
<span style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">File Name: exppipe.sh</span><br style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;" /><span style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">#!/bin/sh</span><br style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;" /><span style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">. $HOME/.bash_profile</span><br style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;" /><span style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">cd /home/oracle/mknode/</span><br style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;" /><span style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">mknod exp_pipe p</span><br style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;" /><span style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">gzip -cNf exp_data.dmp.gz &</span><br style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;" /><span style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">exp demo/demo file=exp_pipe log=exp_data.log owner=demo statistics=none</span><br style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;" /><span style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">rm -f exp_pipe p</span><br style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;" /><span style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">fi</span>
</div>Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com0tag:blogger.com,1999:blog-2521368012158105098.post-52765103396102799302012-06-15T09:10:00.001-07:002012-06-15T09:10:04.703-07:00_kgl_large_heap_warning_threshold -- oracle 10.2 hidden parameter<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="post-body entry-content" id="post-body-1210280086442190899" itemprop="articleBody" style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 1.4; position: relative; text-align: -webkit-auto; width: 520px;">
<div dir="ltr" style="text-align: left;" trbidi="on">
Today in my environment i faced the below error message<br /><br />Memory Notification: Library Cache Object loaded into SGA<br />Heap size 9940K<br />exceeds notification threshold (8192K)<br /><br />for that i found the solution<br /><br />In 10.2.0.2, the threshold was increased to 50MB after regression tests, so this should be a reasonable and recommended value.<br /><br />So, you may try to increase the parameter _kgl_large_heap_warning_threshold= 52428800<br /><br />SQL> alter system set "_kgl_large_heap_warning_threshold"=52428800 scope=spfile ;<br />SQL> shutdown immediate<br />SQL> startup<br /><br />Strongly recommend you to upgrade the database to the latest patchset which is <strong>10.2.0.5</strong>,<br />where you can avoid such problems.</div>
</div>
</div>Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com0tag:blogger.com,1999:blog-2521368012158105098.post-15437961998356939072012-06-15T09:09:00.002-07:002012-06-15T09:09:08.100-07:00CONTROLFILE AUTOBACKUP should be TURNED ON??<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="post-body entry-content" id="post-body-1136527374521736271" itemprop="articleBody" style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 1.4; position: relative; text-align: -webkit-auto; width: 520px;">
<div dir="ltr" style="text-align: left;" trbidi="on">
RMAN is one of the very useful utility provided by Oracle for backup and recovery Purpose. Oracle online backups were introduced with Version 6, where tablespace must be kept in backup mode in order to take online backups.<br /><br />RMAN was first introduced with Version 8 through which database server database can be backup. Since then, Oracle has enhanced RMAN features drastically by every release/version. I am not going to discuss neither the RMAN history nor the backup.<br /><br />I would like to mention here, how enabling few default parameters of RMAN can save the life of dba significantly.<br /><br />RMAN has following default parameters and its default values:<br /><br />RMAN> show all;<br /><br />using target database controlfile instead of recovery catalog<br />RMAN configuration parameters are:<br />CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default<br />CONFIGURE BACKUP OPTIMIZATION OFF; # default<br />CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default<br /><strong><span style="color: red;">CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default<br />CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default</span></strong><br />CONFIGURE DEVICE TYPE DISK PARALLELISM 1; # default<br />CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default<br />CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default<br />CONFIGURE MAXSETSIZE TO UNLIMITED; # default<br />CONFIGURE SNAPSHOT CONTROLFILE NAME TO /app/oracle/dbs/snapcf_EHEALTH.f'; # default<br />I would be talking the benefits of CONTROLFILE AUTOBACKUP.<br /><br />By default CONTROLFILE AUTOBACKUP is OFF. I would strongly recommend enabling CONTROLFILE AUTOBACKUP ON.<br /><br />I remember in my early days of DBA job, a lot of notes/articles and many people use to suggest backup the controlfile immediately after any maintenance on the tablespaces, which was a good suggestion.<br /><br />RMAN just takes away this head ache of backing controlfile after any maintenance on tablespace, when you turn ON CONTROLFILE AUTOBACKUP feature.<br /><strong><br />Benefits:</strong><br /><br />With a control file autobackup, RMAN can recover the database even if the current control file, recovery catalog, and server parameter file are inaccessible.<br /><br />A control file autobackup lets you restore the RMAN repository contained in the control file when the control file is lost and you have no recovery catalog. You do not need a recovery catalog or target database control file to restore the control file autobackup.<br /><br />Whenever you add a datafile/s, resize, increase/decrease the size of datafile/s or etc, controlfile is automatically backed up.<br /><br />If CONFIGURE CONTROLFILE AUTOBACKUP is ON, then RMAN automatically backs up the control file and the current server parameter file (if used to start up the database) in one of two circumstances: when a successful backup must be recorded in the RMAN repository, and when a structural change to the database affects the contents of the control file which therefore must be backed up.<br /><br /><br /><strong>Conclusion:</strong><br />You can turn the autobackup feature on or off by running the following commands through RMAN utility:CONFIGURE CONTROLFILE AUTOBACKUP ON;CONFIGURE CONTROLFILE AUTOBACKUP OFF;</div>
</div>
</div>Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com0tag:blogger.com,1999:blog-2521368012158105098.post-2037504440018746342012-06-15T09:04:00.003-07:002012-06-15T09:04:54.410-07:00How to show user profile and change its limit ?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<span style="font-family: 'Courier New', Courier, monospace;"><br />1. First see the profile
which are using my user ;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">SELECT *<br />FROM dba_users<br />WHERE USERNAME=’ISLBAS’;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">2. For showing the specific profiles property</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">select * from dba_profiles<br />where profile=’DEFAULT’</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">–profile attribute<br />select * from profile$</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">—profile names<br />select * from profname$</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">SELECT name, lcount<br />FROM user$<br />WHERE lcount <> 0;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">3.In order to track password related profile limits, Oracle stores the
history<br />of passwords for a user in user_history$.</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">select * from user_history$</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">4. To change profile limit use</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">ALTER PROFILE default limit<br />failed_login_attempts UNLIMITED;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<br />
<pre class="oac_no_warn" xml:space="preserve"><span style="font-family: 'Courier New', Courier, monospace;">CREATE USER dcranney
IDENTIFIED BY bedrock
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp_ts
QUOTA unlimited ON users;
</span><div class="sect1">
<div class="sect2">
<span style="font-family: 'Courier New', Courier, monospace;"><a href="" id="sthref1575" name="sthref1575"></a>
</span><h3 class="sect2">
<span style="font-family: 'Courier New', Courier, monospace;">Listing All System Privilege Grants</span></h3>
<span style="font-family: 'Courier New', Courier, monospace;">
</span><span style="font-family: 'Courier New', Courier, monospace;"><a href="" id="sthref1576" name="sthref1576"></a><a href="" id="sthref1577" name="sthref1577"></a>The
following query returns all system privilege grants made to roles and users:</span><br />
<pre class="oac_no_warn" xml:space="preserve"><span style="font-family: 'Courier New', Courier, monospace;">SELECT * FROM DBA_SYS_PRIVS;
GRANTEE PRIVILEGE ADM
-------------- --------------------------------- ---
SECURITY_ADMIN ALTER PROFILE YES
SECURITY_ADMIN ALTER USER YES
SECURITY_ADMIN AUDIT ANY YES
SECURITY_ADMIN AUDIT SYSTEM YES
SECURITY_ADMIN BECOME USER YES
SECURITY_ADMIN CREATE PROFILE YES
SECURITY_ADMIN CREATE ROLE YES
SECURITY_ADMIN CREATE USER YES
SECURITY_ADMIN DROP ANY ROLE YES
SECURITY_ADMIN DROP PROFILE YES
SECURITY_ADMIN DROP USER YES
SECURITY_ADMIN GRANT ANY ROLE YES
SWILLIAMS CREATE SESSION NO
JWARD CREATE SESSION NO
</span></pre>
</div>
<!-- class="sect2" --><span style="font-family: 'Courier New', Courier, monospace;">
</span><div class="sect2">
<span style="font-family: 'Courier New', Courier, monospace;"><a href="" id="sthref1578" name="sthref1578"></a>
</span><h3 class="sect2">
<span style="font-family: 'Courier New', Courier, monospace;">Listing All Role Grants</span></h3>
<span style="font-family: 'Courier New', Courier, monospace;">
</span><span style="font-family: 'Courier New', Courier, monospace;"><a href="" id="sthref1579" name="sthref1579"></a><a href="" id="sthref1580" name="sthref1580"></a>The
following query returns all the roles granted to users and other roles:</span><br />
<pre class="oac_no_warn" xml:space="preserve"><span style="font-family: 'Courier New', Courier, monospace;">SELECT * FROM DBA_ROLE_PRIVS;
GRANTEE GRANTED_ROLE ADM
------------------ ------------------------------------ ---
SWILLIAMS SECURITY_ADMIN NO
</span></pre>
</div>
<!-- class="sect2" --><span style="font-family: 'Courier New', Courier, monospace;">
</span><div class="sect2">
<span style="font-family: 'Courier New', Courier, monospace;"><a href="" id="sthref1581" name="sthref1581"></a>
</span><h3 class="sect2">
<span style="font-family: 'Courier New', Courier, monospace;">Listing Object Privileges Granted to a User</span></h3>
<span style="font-family: 'Courier New', Courier, monospace;">
</span><span style="font-family: 'Courier New', Courier, monospace;">The following query returns all object privileges (not including
column-specific privileges) granted to the specified user:</span><br />
<pre class="oac_no_warn" xml:space="preserve"><span style="font-family: 'Courier New', Courier, monospace;">SELECT TABLE_NAME, PRIVILEGE, GRANTABLE FROM DBA_TAB_PRIVS
WHERE GRANTEE = 'JWARD';
TABLE_NAME PRIVILEGE GRANTABLE
----------- ------------ ----------
EMP SELECT NO
EMP DELETE NO
</span></pre>
<span style="font-family: 'Courier New', Courier, monospace;">
</span><span style="font-family: 'Courier New', Courier, monospace;">To list all the column-specific privileges that have been granted, use the
following query<a href="" id="sthref1582" name="sthref1582"></a>:</span><br />
<pre class="oac_no_warn" xml:space="preserve"><span style="font-family: 'Courier New', Courier, monospace;">SELECT GRANTEE, TABLE_NAME, COLUMN_NAME, PRIVILEGE
FROM DBA_COL_PRIVS;
GRANTEE TABLE_NAME COLUMN_NAME PRIVILEGE
----------- ------------ ------------- --------------
SWILLIAMS EMP ENAME INSERT
SWILLIAMS EMP JOB INSERT
JWARD EMP NAME INSERT
JWARD EMP JOB INSERT
</span></pre>
</div>
<!-- class="sect2" --><span style="font-family: 'Courier New', Courier, monospace;">
</span><div class="sect2">
<span style="font-family: 'Courier New', Courier, monospace;"><a href="" id="sthref1583" name="sthref1583"></a>
</span><h3 class="sect2">
<span style="font-family: 'Courier New', Courier, monospace;">Listing the Current Privilege Domain of Your Session</span></h3>
<span style="font-family: 'Courier New', Courier, monospace;">
</span><span style="font-family: 'Courier New', Courier, monospace;"><a href="" id="sthref1584" name="sthref1584"></a>The following query lists all roles
currently enabled for the issuer:</span><br />
<pre class="oac_no_warn" xml:space="preserve"><span style="font-family: 'Courier New', Courier, monospace;">SELECT * FROM SESSION_ROLES;
</span></pre>
<span style="font-family: 'Courier New', Courier, monospace;">
</span><span style="font-family: 'Courier New', Courier, monospace;">If <code>swilliams</code> has enabled the <code>security_admin</code> role
and issues this query, then Oracle Database returns the following
information:</span><br />
<pre class="oac_no_warn" xml:space="preserve"><span style="font-family: 'Courier New', Courier, monospace;">ROLE
------------------------------
SECURITY_ADMIN
</span></pre>
<span style="font-family: 'Courier New', Courier, monospace;">
</span><span style="font-family: 'Courier New', Courier, monospace;">The following query lists all system privileges currently available in the
security domain of the issuer, both from explicit privilege grants and from
enabled roles:</span><br />
<pre class="oac_no_warn" xml:space="preserve"><span style="font-family: 'Courier New', Courier, monospace;">SELECT * FROM SESSION_PRIVS;
</span></pre>
<span style="font-family: 'Courier New', Courier, monospace;">
</span><span style="font-family: 'Courier New', Courier, monospace;">If <code>swilliams</code> has the <code>security_admin</code> role enabled
and issues this query, then Oracle returns the following results:</span><br />
<pre class="oac_no_warn" xml:space="preserve"><span style="font-family: 'Courier New', Courier, monospace;">PRIVILEGE
----------------------------------------
AUDIT SYSTEM
CREATE SESSION
CREATE USER
BECOME USER
ALTER USER
DROP USER
CREATE ROLE
DROP ANY ROLE
GRANT ANY ROLE
AUDIT ANY
CREATE PROFILE
ALTER PROFILE
DROP PROFILE
</span></pre>
<span style="font-family: 'Courier New', Courier, monospace;">
</span><span style="font-family: 'Courier New', Courier, monospace;">If the <code>security_admin</code> role is disabled for
<code>swilliams</code>, then the first query would return no rows, while the
second query would only return a row for the <code>CREATE SESSION</code>
privilege grant.</span></div>
<!-- class="sect2" --><span style="font-family: 'Courier New', Courier, monospace;">
</span><div class="sect2">
<span style="font-family: 'Courier New', Courier, monospace;"><a href="" id="sthref1585" name="sthref1585"></a>
</span><h3 class="sect2">
<span style="font-family: 'Courier New', Courier, monospace;">Listing Roles of the Database</span></h3>
<span style="font-family: 'Courier New', Courier, monospace;">
</span><span style="font-family: 'Courier New', Courier, monospace;"><a href="" id="sthref1586" name="sthref1586"></a>The <code>DBA_ROLES</code> data
dictionary view can be used to list all roles of a database and the
authentication used for each role. For example, the following query lists all
the roles in the database:</span><br />
<pre class="oac_no_warn" xml:space="preserve"><span style="font-family: 'Courier New', Courier, monospace;">SELECT * FROM DBA_ROLES;
ROLE PASSWORD
---------------- --------
CONNECT NO
RESOURCE NO
DBA NO
SECURITY_ADMIN YES
</span></pre>
</div>
<!-- class="sect2" --><span style="font-family: 'Courier New', Courier, monospace;">
</span><div class="sect2">
<span style="font-family: 'Courier New', Courier, monospace;"><a href="" id="sthref1587" name="sthref1587"></a>
</span><h3 class="sect2">
<span style="font-family: 'Courier New', Courier, monospace;">Listing Information About the Privilege Domains of Roles</span></h3>
<span style="font-family: 'Courier New', Courier, monospace;">
</span><span style="font-family: 'Courier New', Courier, monospace;"><a href="" id="sthref1588" name="sthref1588"></a>The <code>ROLE_ROLE_PRIVS</code>,
<code>ROLE_SYS_PRIVS</code>, and <code>ROLE_TAB_PRIVS</code> data dictionary
views contain information on the privilege domains of roles. For example, the
following query lists all the roles granted to the <code>system_admin</code>
role:</span><br />
<pre class="oac_no_warn" xml:space="preserve"><span style="font-family: 'Courier New', Courier, monospace;">SELECT GRANTED_ROLE, ADMIN_OPTION
FROM ROLE_ROLE_PRIVS
WHERE ROLE = 'SYSTEM_ADMIN';
GRANTED_ROLE ADM
---------------- ----
SECURITY_ADMIN NO
</span></pre>
<span style="font-family: 'Courier New', Courier, monospace;">
</span><span style="font-family: 'Courier New', Courier, monospace;">The following query lists all the system privileges granted to the
<code>security_admin</code> role:</span><br />
<pre class="oac_no_warn" xml:space="preserve"><span style="font-family: 'Courier New', Courier, monospace;">SELECT * FROM ROLE_SYS_PRIVS WHERE ROLE = 'SECURITY_ADMIN';
ROLE PRIVILEGE ADM
----------------------- ----------------------------- ---
SECURITY_ADMIN ALTER PROFILE YES
SECURITY_ADMIN ALTER USER YES
SECURITY_ADMIN AUDIT ANY YES
SECURITY_ADMIN AUDIT SYSTEM YES
SECURITY_ADMIN BECOME USER YES
SECURITY_ADMIN CREATE PROFILE YES
SECURITY_ADMIN CREATE ROLE YES
SECURITY_ADMIN CREATE USER YES
SECURITY_ADMIN DROP ANY ROLE YES
SECURITY_ADMIN DROP PROFILE YES
SECURITY_ADMIN DROP USER YES
SECURITY_ADMIN GRANT ANY ROLE YES
</span></pre>
<span style="font-family: 'Courier New', Courier, monospace;">
</span><span style="font-family: 'Courier New', Courier, monospace;">The following query lists all the object privileges granted to the
<code>security_admin</code> role:</span><br />
<pre class="oac_no_warn" xml:space="preserve"><span style="font-family: 'Courier New', Courier, monospace;">SELECT TABLE_NAME, PRIVILEGE FROM ROLE_TAB_PRIVS
WHERE ROLE = 'SECURITY_ADMIN';
TABLE_NAME PRIVILEGE
--------------------------- ----------------
AUD$ DELETE
AUD$ SELECT</span>
</pre>
</div>
<!-- class="sect2" --></div>
<!-- class="sect1" --></pre>
<br />
<div class="geo geo-post" id="geo-post-282" style="display: none;">
<span class="latitude">23.717000</span> <span class="longitude">90.367000</span></div>
</div>Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com7tag:blogger.com,1999:blog-2521368012158105098.post-49768052450063503032012-06-14T08:16:00.000-07:002012-06-14T08:33:05.452-07:00change archivelog all crosscheck in rman<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: -webkit-auto;">
<span style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 16px; line-height: 22px;">This command is very useful, where your RMAN does not take the sequence number into consider</span></div>
<div class="post-body entry-content" id="post-body-7700177311826651519" itemprop="articleBody" style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 16px; line-height: 22px; position: relative; text-align: -webkit-auto; width: 700px;">
<br />
Here is a simple example script to see whether all of the registered archived redo logs still exist; if not, RMAN changes their status in the metadata to <strong class="Bold">expired</strong>:<br />
crosscheck archivelog all;<br />
<pre class="CEM">allocate channel for maintenance type disk;
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" name="18994"></a>change archivelog all crosscheck;
<a href="http://www.blogger.com/blogger.g?blogID=2521368012158105098" name="36774"></a>release channel;</pre>
</div>
</div>Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com0tag:blogger.com,1999:blog-2521368012158105098.post-36865389499387345602012-06-07T02:46:00.002-07:002012-06-07T03:53:05.965-07:00ORA-01555 Error - Why we are receiving ?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
<span style="font-family: inherit;">Undo data is stored in the undo tablespace, the tablespace nominated by the
UNDO_TABLESPACE instance parameter. This tablespace should be sized according to
the rate at which undo data is being generated and the length of the queries
running in the database.</span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: inherit;">But even if the undo tablespace is inadequately sized and therefore comes
under space pressure, automatic undo retention tuning will tend to minimize
problems.</span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: inherit;">Undo data generated by a transaction must always be kept until the
transaction commits. This is an absolute; under no circumstances will Oracle
ever overwrite undo data that might be needed to rollback a transaction. This
data is known as “active” undo data.</span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: inherit;">Once a transaction has committed, its undo data is no longer active, but it
could still be needed to support long running queires that began before the
transaction. Data that may be needed for this purpose is known as “unexpired”
undo data.</span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"> ”Expired” undo is data that is no longer needed either to rollback a
transaction or to be read by queries.. Active undo will never be overwritten,
and ideally expired undo can be safely overwritten at any time.</span></div>
<div style="text-align: left;">
<span style="font-family: inherit;">Unexpired undo can be overwritten, but at the risk of causing queries to fail
with the <strong>“ORA-01555 : Snapshot too old”</strong> error.</span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: inherit;">The point at which data transitions from “unexpired” to “expired” is
controlled by the instance parameter UNDO_RETENTION.</span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: inherit;">With release 9i of the Oracle database,Oracle would overwrite any expired
undo. This meant that if the UNDO_RETENTION parameter were not set appropriately
or (not set at all, in which case it defaults to 9oo seconds), there would be
great danger of ORA-1555 errors.</span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: inherit;">Oracle 10g relaeas of the database effectively ignores the UNDO_RETENTION
parameter. It will always overwrite the oldest bit of undo data.This means that
is a sense there is no longer any difference between expired and unexpired undo
and that the UNDO_RETENTION instance parameter is redundant, because undo
retention is automatically tuned for the longest possible query.</span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: inherit;">To monitor the automatic undo retention tuning ,query V$UNDOSTAT this query
will show,</span></div>
<div style="text-align: left;">
<span style="font-family: inherit;">SQL> SELECT BEGIN_TIME,END_TIME,TUNED_UNDORETENTION,ACTIVEBLKS,UNEXPIREDBLKS,EXP IREDBLKS
FROM V$UNDOSTAT;</span></div>
<div style="text-align: left;">
<strong><span style="font-family: inherit;"><br /></span></strong></div>
<div style="text-align: left;">
<span style="font-family: inherit;">Iin fivteen minutes intervals, how old(in seconds) the oldest block of
inactive undo data was. provided that no query started earlier than that, you
will never receive a snapshot too old error. The larger the undo tablespace is
and the less the transaction workload is, the further back the
TUNED_UNDORETENTION will be.</span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"><br /></span></div>
<div style="text-align: left;">
</div>
<b><span style="font-family: inherit;"><u>Optimize Oracle UNDO Parameters</u> </span></b><br />
<span style="font-family: inherit;">--------------------------------------------------------------------------------</span><br />
<span style="font-family: inherit;">Starting in Oracle9i, rollback segments are re-named undo logs. Traditionally transaction undo information was stored in Rollback Segments until a commit or rollback statement was issued, at which point it was made available for overlaying. </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">Best of all, automatic undo management allows the DBA to specify how long undo information should be retained after commit, preventing "snapshot too old" errors on long running queries. </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">This is done by setting the UNDO_RETENTION parameter. The default is 900 seconds (5 minutes), and you can set this parameter to guarantee that Oracle keeps undo logs for extended periods of time. </span><br />
<span style="font-family: inherit;">Rather than having to define and manage rollback segments, you can simply define an Undo tablespace and let Oracle take care of the rest. Turning on automatic undo management is easy. All you need to do is create an undo tablespace and set UNDO_MANAGEMENT = AUTO. </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">However it is worth to tune the following important parameters </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">The size of the UNDO tablespace </span><br />
<span style="font-family: inherit;">The UNDO_RETENTION parameter </span><br />
<span style="font-family: inherit;">Calculate UNDO_RETENTION for given UNDO Tabespace </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">You can choose to allocate a specific size for the UNDO tablespace and then set the UNDO_RETENTION parameter to an optimal value according to the UNDO size and the </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">database activity. If your disk space is limited and you do not want to allocate more space than necessary to the UNDO tablespace, this is the way to proceed. The </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">following query will help you to optimize the UNDO_RETENTION parameter: </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;"> <b>OPTIMAL UNDO RETENTION</b> = ACTUAL undo size / db_block_size * undo_block_per_sec.</span><br />
<br />
<span style="font-family: inherit;">Because these following queries use the V$UNDOSTAT statistics, run the queries only after the database has been running with UNDO for a significant and representative time! </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;"><br /></span><br />
<b><span style="font-family: inherit;">Actual Undo Size </span></b><br />
<b><span style="font-family: inherit;"><br /></span></b><br />
<span style="font-family: inherit;">SELECT SUM(a.bytes) "UNDO_SIZE"</span><br />
<span style="font-family: inherit;"> FROM v$datafile a,</span><br />
<span style="font-family: inherit;"> v$tablespace b,</span><br />
<span style="font-family: inherit;"> dba_tablespaces c</span><br />
<span style="font-family: inherit;"> WHERE c.contents = 'UNDO'</span><br />
<span style="font-family: inherit;"> AND c.status = 'ONLINE'</span><br />
<span style="font-family: inherit;"> AND b.name = c.tablespace_name</span><br />
<span style="font-family: inherit;"> AND a.ts# = b.ts#; </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;"> UNDO_SIZE</span><br />
<span style="font-family: inherit;">----------</span><br />
<span style="font-family: inherit;"> 209715200 </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;"><br /></span><br />
<b><span style="font-family: inherit;"><u>Undo Blocks per Second </u></span></b><br />
<b><span style="font-family: inherit;"><br /></span></b><br />
<span style="font-family: inherit;">SELECT MAX(undoblks/((end_time-begin_time)*3600*24))</span><br />
<span style="font-family: inherit;"> "UNDO_BLOCK_PER_SEC"</span><br />
<span style="font-family: inherit;"> FROM v$undostat; </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">UNDO_BLOCK_PER_SEC</span><br />
<span style="font-family: inherit;">------------------</span><br />
<span style="font-family: inherit;"> 3.12166667 </span><br />
<span style="font-family: inherit;"><br /></span><br />
<b><span style="font-family: inherit;"><u>DB Block Size</u> </span></b><br />
<b><span style="font-family: inherit;"><br /></span></b><br />
<span style="font-family: inherit;">SELECT TO_NUMBER(value) "DB_BLOCK_SIZE [KByte]"</span><br />
<span style="font-family: inherit;"> FROM v$parameter</span><br />
<span style="font-family: inherit;">WHERE name = 'db_block_size'; </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">DB_BLOCK_SIZE [Byte]</span><br />
<span style="font-family: inherit;">--------------------</span><br />
<span style="font-family: inherit;"> 4096 </span><br />
<span style="font-family: inherit;"><br /></span><br />
<b><span style="font-family: inherit;"><u>Optimal Undo Retention</u> </span></b><br />
<b><span style="font-family: inherit;"><br /></span></b><br />
<span style="font-family: inherit;">209'715'200 / (3.12166667 * 4'096) = 16'401 [Sec] </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;"><br /></span></div>Anonymoushttp://www.blogger.com/profile/13162704794548394498noreply@blogger.com1