EVENT:10061 disable SMON from cleaning temp segment

Error:  ORA 10061
Text:   disable SMON from cleaning temp segment
-------------------------------------------------------------------------------

Explanation:
        This is NOT an error but is a special EVENT code.
        It should *NOT* be used unless explicitly requested by RD support.

        It allows you to prevent SMON from cleaning up temporary segments.
        If set in:

         7.0.X:
            This will prevent SMON performing cleanup of TEMP segments
            and from coalsecing extents. The cleanup action was performed
            every 3 minutes in 7.0.X releases.

        7.1.X:
            The event behaviour is modified in that TEMP segment cleanup
            is skipped on TIMEOUTS but will be performed if SMON is
            posted. The cleanup only occurs every 12 hours or when posted
            in 7.1.X releases.
            You can POST SMON by performing a failed CREATE TABLE command.

            A new event 10269 is for coalescing extents.

Usage:  
        event="10061 trace name context forever, level 10"

Articles:

@Archived Managing SMON Activity on multiple OPS instances   <Note:45856.1>

EVENT:10212 check cluster integrity

Error:  ORA 10212
Text:   check cluster integrity
-------------------------------------------------------------------------------
Explanation:
        This is NOT an error but is a special EVENT code.
        It should *NOT* be used unless explicitly requested by RD support.

        Event 10212 enables cluster block integrity checking.
        The causes a number of checks on the contents of a block.
        If the block is found to be corrupt in some way it is marked as
        SOFTWARE CORRUPT.

        NB: Blocks are ONLY checked/corrupted when CHANGED. They are NOT checked
            when accessed for read.

        Take care with this as if there are blocks in the database which
        are being accessed happily but have a minor corruption this will
        mark the block as corrupt.

        Once a block in an cluster is marked SOFTWARE CORRUPT it is best to
        rebuild the entire cluster.

Usage:  event="10212 trace name context forever, level 10"

Articles:
        Data and Index block equivalents  <Oerr:10210> <Oerr:10211>

EVENT:10228 trace application of redo by kcocbk

Error:  ORA 10228
Text:   trace application of redo by kcocbk
-------------------------------------------------------------------------------

Explanation:
        This is NOT an error but is a special EVENT code.
        It should *NOT* be used unless explicitly requested by RD support.

        Event 10228 is potentially useful in recovery situations since it
        traces the application of redo. Therefore, if cache recovery
        appears to hang or corrupt blocks then this can help track the dba
        and operations upon it.

        This event is available in Oracle 6 and 7.

        The code just calls the same routines used to dump a redo log using
        'alter system dump logfile' so has the same output.
        The benefit is that it'll stop when it hits the corruption.

Articles:
        Interpreting DUMP LOGFILE Output <Note:29726.1>

EVENT:10210 check data block integrity

Event:10210                  See  for similar events / parameters
~~~~~~~~~~~

Version/Use:
  7.0 - 8.1.7  Check data block integrity after each modification
  9.0+         This event is no longer valid. Use <Parameter:DB_BLOCK_CHECKING>
                instead.

7.0 - 8.1.7 "Check data block integrity after each modification"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  NOTE: Events should NEVER be set by customers unless advised to do so by
        Oracle Support Services. Read  before setting any event.

Summary Syntax:
  This event should be set at instance level:
    EVENT="10210 trace name context forever, level 10"

Levels:
  This event is either ON (level 1 or higher) or OFF (not set)

  Note that in 8.1.6 onwards you should use the
  instead of this event.

Description/Steps:
  Event 10210 enables data block integrity checking.
  This causes the data layer to perform a number of checks on the
  contents of a data block. If the block is found to be corrupt
  in some way it is marked as SOFTWARE CORRUPT.

  NB: Blocks are ONLY checked/corrupted when CHANGED. They are NOT
      checked when accessed for read.

  Take care with this, as if there are blocks in the database which
  are being accessed happily but have a minor corruption such as
  an incorrect free space count, this event will mark the block as
  corrupt. Once marked SOFTWARE CORRUPT the data in the block
  is not accessible to Oracle.

  See  for more detail of various block checking features.

Example Output / Interpreting Output:
  This event will cause an ORA-600 error to be signalled if a corruption
  is detected after a data block has been modified. The exact content
  of the trace file depends on the ORA-600 and the action at the time
  of the corruption being noticed. Refer to the relevant ORA-600 article
  for the error which is signalled.

Related:
  Database block checking features
  Index and Cluster block equivalents
  See event 10231 which allows SOFTWARE CORRUPT blocks
    to be skipped on full table scans

Known Oracle Internal Stack Call Meaning

 ksedmp             # KSE: dump the process state
 ksfdmp             # Call relevant dump routine
 kgeasi             # Raise an error on an ASSERTION failure (IGNORE)
 ktcrab             KTC: Kernel Transaction Control Real ABort - Abort a
transaction.
 ktcsod             KTC: Transaction Control: STATE OBJECT PROCEDURE VECTOR
DEFINITION
 kssdch_stage       
 kssdch             KSS: delete children of state obj.
 ksures             
 ktmres             ktmres - KTM Resource cleanup routine.
 ktmmon             KTM: TX Monitor: background timeout action
 ksbrdp             KSB: run a detached (background) process
 opirip             # Oracle Program Interface Run Independent Process
(IGNORE)
 opidrv             # opidrv - ORACLE Program Interface DRiVer (IGNORE)
 sou2o              # Main Oracle executable entry point
 main               # Standard executable entry point

Function Based Indexes and Global Temporary Tables

A nonunique index can be used to enforce a primary key or unique constraint.

In Oracle8i indexes can be rebuilt without locking the table.

The DROP COLUMN option of the ALTER TABLE command is restartable.

The MOVE option of the ALTER TABLE command retains the constraints of the table.

Data rows in the global temporary table are always deleted when A user session is terminated

1.    As user Scott, create a table with three columns.  Create an index on all three columns in the order they appear in the table.  Then add a primary key constraint using the first two columns with the second column of the table appearing first.  Verify that only one index, the index being used to enforce the constraint, has been defined for the table.

Hint: if the columns in the table were labeled A, B, and C, the index would be on (A, B, C) while the constraint would be on columns (B, A).

Solution:

 

connect scott/tiger

 

 

CREATE TABLE acct

( acct_no       NUMBER(10),

customer_id           NUMBER(10),

acct_comment VARCHAR2(200),

CONSTRAINT pk_cid_aid  PRIMARY KEY(customer_id, acct_no) DISABLE

)

/

CREATE INDEX I_ANO_CNO_ACOMM

ON acct(acct_no, customer_id, acct_comment)

ONLINE

/

ALTER TABLE acct

ENABLE CONSTRAINT pk_cid_aid

/

 

select index_name, table_name from user_indexes

where table_name = ‘ACCT’

/

2. As user Scott create a table containing three columns.  Remove the third column using one of the new methods introduced in Oracle8i.  Verify that the column is no longer part of the table.

Solution:

connect scott/tiger

 

 

CREATE TABLE acct_col

( acct_col_no         NUMBER(10),

customer_id           NUMBER(10),

acct_col_comment    VARCHAR2(200)

)

/

ALTER TABLE acct_col

SET UNUSED COLUMN acct_col_comment

/

 

desc acct_col

 

SELECT * FROM user_unused_col_tabs

/

ALTER TABLE acct_col

DROP UNUSED COLUMNS

/

SELECT * FROM user_unused_col_tabs

/

 

3. As user SYS create a global temporary table containing three columns.  The inserted rows should remain available until explicitly deleted or the session ends.  Make the table available to anyone who wishes to use it.  The users should not have to know the table owner in order to make use of it.

Solution:

connect / as sysdba

 

CREATE GLOBAL TEMPORARY TABLE emp_temp_X

(eno NUMBER,

ename VARCHAR2(20),

sal NUMBER)

ON COMMIT PRESERVE ROWS;

 

connect / AS SYSDBA

 

CREATE PUBLIC SYNONYM emp_temp for emp_temp_x

/

GRANT ALL ON emp_temp TO PUBLIC

/

col object_name format a20

SELECT owner, object_name, object_type FROM dba_objects

WHERE object_name LIKE ‘%EMP_TEMP%’

/

connect scott/tiger

 

desc emp_temp

 

select * from emp_temp

/

 

 

Materialized Views and Dimensions

Materialized Views and Refresh Types

This practice will familiarize you with the various features and privileges to ensure successful creation of a materialized view from a base table.

1) Grant the necessary privileges for user Scott to create materialized views and allow query rewrite on the materialized views owned by schema Scott.

As user SYSTEM, execute the following command:> grant CREATE MATERIALIZED VIEW, QUERY REWRITE to scott;

2) As user Scott, create a materialized view name STAFF_MV_SIMPLE from the Employees table. You want the materialized view to only store data  for the job of a STAFF, and you want a complete refresh.  You need to first create the EMPLOYEES table by importing employees.dmp.

As user Scott, execute the following command:> CREATE MATERIALIZED VIEW staff_mv_simple
REFRESH COMPLETE
AS SELECT * FROM EMPLOYEES  WHERE JOB = ‘STAFF’;

3) Create a materialized view name STAFF_MV_REFRESH, still only storing data  for the job of a STAFF,  but you want a refresh feature that will only apply the changes made to the base table since the last time you refresh the materialized view.  You will be creating a materialized view with a fast refresh.

As user Scott, execute the following command: > CREATE MATERIALIZED VIEW staff_mv_refresh
REFRESH FAST
AS SELECT * FROM EMPLOYEES  WHERE JOB = ‘STAFF’;

4) Create a materialized view name STAFF_MV_QR, still only storing data  for the job of a STAFF, using 2 parallel processes, allowing query rewrite, and you
want a complete refresh.

As user Scott, execute the following command: > CREATE MATERIALIZED VIEW staff_mv_qr
PARALLEL (DEGREE 2)
REFRESH COMPLETE
ENABLE QUERY REWRITE
AS SELECT * FROM EMPLOYEES WHERE JOB = ‘STAFF’;

Query Rewrites

This practice will familiarize you with the various features of creating a materialized view with query rewrite capabilty.

1) Alter your session to allow query rewrite.

As user Scott, execute the following command: > alter session set QUERY_REWRITE_ENABLED = true;

2) Use EXPLAIN PLAN to verify that rewrite has taken place. Confirm you have a Plan_Table.  If you do not, please create it by running the utlxplan.sql file.
It should be located in the subdirectory where you installed Oracle.

For example, if Oracle 8.1.6 is install on c:oracle, then the file will be in the c:oracleora81rdbmsadmin

Create the Plan_table for schema Scott if it does not exist already.

As user Scott, execute the following command: > @c:oracleora81rdbmsadminutlxplan.sql

Confirm the plan_table exists.

As user Scott, execute the following command: > describe plan_table

3) Confirm materialized view STAFF_MV_QR will be use in a query rewrite request.

As user Scott, execute the following command: >delete from plan_table;

This is to ensure there are no row the the plan_table before populaing it with the explain plan results.

>explain plan for
> SELECT * FROM EMPLOYEES WHERE JOB = ‘STAFF’

>col Operation format a30
col Options   format a20
col Object    format a20

>select lpad(‘ ‘, 2*LEVEL) || OPERATION ||
decode( ID, 0, ‘ Cost = ‘||POSITION) “Operation”,
OPTIONS “Options”, OBJECT_NAME “Object”
from PLAN_TABLE
connect by prior ID = PARENT_ID  start with ID = 0
order by ID
/

Dimensions

This practice will familiarize you with the various features of creating a dimension, storing the hierachy definition in the database, and being familiar with the the data dictionary views that can be used to gather information regarding dimensions.

1) Confirm user Scott has the privilege to create a dimension.  If not,  grant that privilege to Scott.

As user System, execute the following command: > select grantee, privilege
from dba_sys_privs
where grantee = ‘SCOTT’; 

If you don’t see user Scott has the CREATE DIMENSION privilege, grant it to user Scott.

> grant create dimension to scott;

2) As user Scott, create a dimension name mv_time_dim from the time table with a hierarchy name scott_calendar.  Frist create the time table by exporting from
the file time.dmp.

As user Scott execute the following command: >CREATE DIMENSION mv_time_dim
LEVEL sdate IS time.sdate
LEVEL month IS time.month
LEVEL qtr   IS time.quarter
LEVEL yr    IS time.year
HIERARCHY scott_calendar
(sdate CHILD OF month CHILD OF qtr CHILD OF  yr)
ATTRIBUTE month DETERMINES month_name;

3) Determine the levels of the dimersion you have created.  To see that information, query the user_dim_levels view.
As user Scott execute the following command:

>select dimension_name, level_name, detailobj_name
from user_dim_levels;

Summary Management

1) After you have set up Oracle Trace Manager to monitor the utilization of your materialized views. you can determine if you should keep the materialized views you have created by querying the mview$_recommendations view.
As user Scott execute the following command:

>SELECT recommended_action, mview_name, group_by_columns, measures_list
FROM mview$_recommendations;

EVENT: 10231 "skip corrupted blocks on _table_scans_"

Event: 10231
Text:  skip corrupted blocks on _table_scans_
-------------------------------------------------------------------------------
Cause:
Action: Corrupt blocks are skipped in table scans, and listed in trace files.

Explanation:
        This is NOT an error but is a special EVENT code.
        It should *NOT* be used unless explicitly requested by ST support.

   8.1 onwards:
   ~~~~~~~~~~~~
        The "7.2 onwards" notes below still apply but in Oracle8i
        there is a PL/SQL <Package:DBMS_REPAIR> which can be used
        to check corrupt blocks.  See <DocIndex:DBMS_REPAIR>.

        It is possible to simulate 10231 on a table using
        DBMS_REPAIR.SKIP_CORRUPT_BLOCKS('schema','table').
        The SKIP_CORRUPT column of DBA_TABLES shows tables which
        have been marked to allow skipping of corrupt blocks.

   7.2 onwards:
   ~~~~~~~~~~~~
	Event 10231 causes SOFTWARE CORRUPT or MEDIA corrupt blocks
	to be skipped on FULL TABLE SCANS only.  (E.g: on export)
	Software corrupt blocks are defined below.  Media corrupt
        blocks are Oracle blocks where the header field information
        is not what was expected.  These can now be skipped with
	the 10231 event.

   Before 7.2:
   ~~~~~~~~~~~
        Event 10231 causes SOFTWARE CORRUPT blocks to be skipped on
        FULL TABLE SCANS only.  (E.g: on export).

        A 'software corrupt' block is a block that has a SEQ number of ZERO.
        This raises an ORA-1578 error.

	NB: Blocks may be internally corrupt and still cause problems or
	    raise ORA-1578.  If a block is physically corrupt and the SEQ
	    is not set to ZERO, you cannot use 10231 to skip it.  You have
	    to try to scan around the block instead.

	    To manually corrupt a block and cause it to be skipped you
	    must: Set SEQ to ZERO.
		  Set the INCSEQ at the end of the block to match.


	You can set event numbers 10210, 10211, and 10212 to check blocks
        at the data level and mark them software corrupt if they are found
        to be corrupt.  You CANNOT use these events to mark a physically
        corrupt block as software corrupt because the block never reaches
        the data layer.

        When a block is skipped, any data in the block is totally ignored.


Usage:  Event="10231 trace name context forever, level 10".
	This should be removed from the instance parameters immediately after
	it has been used.

        Alternatively it can be set at session level:
        alter session set events '10231 trace name context forever, level 10'

@Articles:
@       Customer FAX Explaining How to Use Event 10231	 Note 33405.1
@       Data, Index & Cluster Block  <Event:10210><Event:10211><Event:10212>
@	Skip Blocks on Index Range Scan			 <Event:10233>
@	Physical Oracle Data Block Layout		 Note 33242.1

DBMS_REPAIR example



PURPOSE

 This document provides an example of DBMS_REPAIR as introduced in Oracle 8i.
 Oracle provides different methods for detecting and correcting data block
 corruption - DBMS_REPAIR is one option.

 WARNING: Any corruption that involves the loss of data requires analysis to
 understand how that data fits into the overall database system. Depending on
 the nature of the repair, you may lose data and logical inconsistencies can
 be introduced; therefore you need to carefully weigh the gains and losses
 associated with using DBMS_REPAIR.

SCOPE & APPLICATION

 This article is intended to assist an experienced DBA working with an Oracle
 Worldwide Support analyst only.  This article does not contain general
 information regarding the DBMS_REPAIR package, rather it is designed to provide
 sample code that can be customized by the user (with the assistance of
 an Oracle support analyst) to address database corruption.  The
 "Detecting and Repairing Data Block Corruption" Chapter of the Oracle8i
 Administrator's  Guide should be read and risk assessment analyzed prior to
 proceeding.

RELATED DOCUMENTS

  Oracle 8i Administrator's Guide,  DBMS_REPAIR Chapter

Introduction
=============

Note: The DBMS_REPAIR package is used to work with corruption in the
transaction layer and the data layer only (software corrupt blocks).
Blocks with physical corruption (ex. fractured block) are marked as
the block is read into the buffer cache and DBMS_REPAIR ignores all
blocks marked corrupt.

The only block repair in the initial release of DBMS_REPAIR is to
*** mark the block software corrupt ***.

DB_BLOCK_CHECKING and DB_BLOCK_CHECKSUM must both be set to FALSE.

A backup of the file(s) with corruption should be made before using package.

Database Summary
===============

A corrupt block exists in table T1.

SQL> desc t1
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 COL1                                      NOT NULL NUMBER(38)
 COL2                                               CHAR(512)

SQL> analyze table t1 validate structure;
analyze table t1 validate structure
*
ERROR at line 1:
ORA-01498: block check failure - see trace file

---> Note: In the trace file produced from the ANALYZE, it can be determined
---        that the corrupt block contains 3 rows of data (nrows = 3).
---        The leading lines of the trace file follows:

Dump file /export/home/oracle/product/8.1.5/admin/V815/udump/v815_ora_2835.trc
Oracle8 Enterprise Edition Release 8.1.5.0.0 - Beta
With the Partitioning option

*** 1998.12.16.15.53.02.000
*** SESSION ID:(7.6) 1998.12.16.15.53.02.000
kdbchk: row locked by non-existent transaction
        table=0   slot=0
        lockid=32   ktbbhitc=1
Block header dump:  0x01800003
 Object id on Block? Y
 seg/obj: 0xb6d  csc: 0x00.1cf5f  itc: 1  flg: -  typ: 1 - DATA
     fsl: 0  fnx: 0x0 ver: 0x01

 Itl           Xid                  Uba         Flag  Lck        Scn/Fsc
0x01   xid:  0x0002.011.00000121    uba: 0x008018fb.0345.0d  --U-    3  fsc
0x0000.0001cf60

data_block_dump
===============
tsiz: 0x7b8
hsiz: 0x18
pbl: 0x28088044
bdba: 0x01800003
flag=-----------
ntab=1
nrow=3
frre=-1
fsbo=0x18
fseo=0x19d
avsp=0x185
tosp=0x185
0xe:pti[0]      nrow=3  offs=0
0x12:pri[0]     offs=0x5ff
0x14:pri[1]     offs=0x3a6
0x16:pri[2]     offs=0x19d
block_row_dump:

[... remainder of file not included]

end_of_block_dump

DBMS_REPAIR.ADMIN_TABLES (repair and orphan key
================================================

ADMIN_TABLES provides administrative functions for repair and orphan key tables.

SQL> @adminCreate
SQL> connect sys/change_on_install
Connected.
SQL>
SQL> -- Repair Table
SQL>
SQL> declare
  2  begin
  3  -- Create repair table
  4  dbms_repair.admin_tables (
  5  --    table_name => 'REPAIR_TABLE',
  6      table_type => dbms_repair.repair_table,
  7      action => dbms_repair.create_action,
  8      tablespace => 'USERS');          -- default TS of SYS if not specified
  9  end;
 10  /

PL/SQL procedure successfully completed.

SQL> select owner, object_name, object_type
  2  from dba_objects
  3  where object_name like '%REPAIR_TABLE';

OWNER                 OBJECT_NAME                      OBJECT_TYPE
------------------------------------------------------------------
SYS                   DBA_REPAIR_TABLE                 VIEW
SYS                   REPAIR_TABLE                     TABLE

SQL>
SQL> -- Orphan Key Table
SQL>
SQL> declare
  2  begin
  3  -- Create orphan key table
  4  dbms_repair.admin_tables (
  5      table_type => dbms_repair.orphan_table,
  6      action => dbms_repair.create_action,
  7      tablespace => 'USERS');          -- default TS of SYS if not specified
  8  end;
  9  /

PL/SQL procedure successfully completed.

SQL> select owner, object_name, object_type
  2  from dba_objects
  3  where object_name like '%ORPHAN_KEY_TABLE';

OWNER                 OBJECT_NAME                      OBJECT_TYPE
------------------------------------------------------------------
SYS                   DBA_ORPHAN_KEY_TABLE             VIEW
SYS                   ORPHAN_KEY_TABLE                 TABLE

DBMS_REPAIR.CHECK_OBJECT
=========================

CHECK_OBJECT procedure checks the specified object and populates the repair
table with information about corruption and repair directive(s).  Validation
consists of block checking all blocks in the object.  All blocks previously
marked corrupt will be skipped.

Note: In the initial release of DBMS_REPAIR the only repair is to mark the
      block as software corrupt.

SQL> @checkObject
SQL> set serveroutput on
SQL>
SQL> declare
  2     rpr_count int;
  3  begin
  4     rpr_count := 0;
  5  dbms_repair.check_object (
  6     schema_name => 'SYSTEM',
  7     object_name => 'T1',
  8     repair_table_name => 'REPAIR_TABLE',
  9     corrupt_count => rpr_count);
 10     dbms_output.put_line('repair count: ' || to_char(rpr_count));
 11  end;
 12  /
repair count: 1

PL/SQL procedure successfully completed.

SQL> desc repair_table
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 OBJECT_ID                                 NOT NULL NUMBER
 TABLESPACE_ID                             NOT NULL NUMBER
 RELATIVE_FILE_ID                          NOT NULL NUMBER
 BLOCK_ID                                  NOT NULL NUMBER
 CORRUPT_TYPE                              NOT NULL NUMBER
 SCHEMA_NAME                               NOT NULL VARCHAR2(30)
 OBJECT_NAME                               NOT NULL VARCHAR2(30)
 BASEOBJECT_NAME                                    VARCHAR2(30)
 PARTITION_NAME                                     VARCHAR2(30)
 CORRUPT_DESCRIPTION                                VARCHAR2(2000)
 REPAIR_DESCRIPTION                                 VARCHAR2(200)
 MARKED_CORRUPT                            NOT NULL VARCHAR2(10)
 CHECK_TIMESTAMP                           NOT NULL DATE
 FIX_TIMESTAMP                                      DATE
 REFORMAT_TIMESTAMP                                 DATE

SQL> select object_name, block_id, corrupt_type, marked_corrupt,
  2  corrupt_description, repair_description
  3  from repair_table;

OBJECT_NAME                      BLOCK_ID CORRUPT_TYPE MARKED_COR
------------------------------ ---------- ------------ ----------
CORRUPT_DESCRIPTION
--------------------------------------------------------------------------------
REPAIR_DESCRIPTION
--------------------------------------------------------------------------------
T1                                      3            1 FALSE
kdbchk: row locked by non-existent transaction
        table=0   slot=0
        lockid=32   ktbbhitc=1
mark block software corrupt

Data Extraction
===============

The repair table indicates that block 3 of file 6 is corrupt - but remember
that this block has not yet been marked as corrupt, therefore now is the
time to extract any meaningful data.  After the block is marked corrupt,
the entire block must be skipped.

1. Determine the number of rows in the block from ALTER SYSTEM DUMP (nrows = 3).
2. Query the corrupt object and extract as much information as possible.

SQL> -- The following query can be used to salvage data from a corrupt block.
SQL> -- Creating a temporary table facilitates data insertion.

SQL> create table temp_t1 as
  2  select * from system.t1
  3  where dbms_rowid.rowid_block_number(rowid) = 3
  4  and dbms_rowid.rowid_to_absolute_fno (rowid, 'SYSTEM','T1') = 6;

Table created.

SQL> select col1 from temp_t1;

      COL1
----------
         2
         3

DBMS_REPAIR.FIX_CORRUPT_BLOCKS  (ORA-1578)
============================================

FIX_CORRUPT_BLOCKS procedure fixes the corrupt blocks in the specified objects
based on information in the repair table.  After the block has been marked as
corrupt,  an ORA-1578 results when a full table scan is performed.

SQL> declare
  2     fix_count int;
  3  begin
  4     fix_count := 0;
  5  dbms_repair.fix_corrupt_blocks (
  6     schema_name => 'SYSTEM',
  7     object_name => 'T1',
  8     object_type => dbms_repair.table_object,
  9     repair_table_name => 'REPAIR_TABLE',
 10     fix_count => fix_count);
 11     dbms_output.put_line('fix count: ' || to_char(fix_count));
 12  end;
 13  /
fix count: 1

PL/SQL procedure successfully completed.

SQL> select object_name, block_id, marked_corrupt
  2  from repair_table;

OBJECT_NAME                      BLOCK_ID MARKED_COR
------------------------------ ---------- ----------
T1                                      3 TRUE

SQL> select * from system.t1;
select * from system.t1
                     *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 6, block # 3)
ORA-01110: data file 6: '/tmp/ts_corrupt.dbf'

DBMS_REPAIR.DUMP_ORPHAN_KEYS
==============================

DUMP_ORPHAN_KEYS reports on index entries that point to rows in corrupt data
blocks.

SQL> select index_name from dba_indexes
  2  where table_name in (select distinct object_name from repair_table);

INDEX_NAME
------------------------------
T1_PK

SQL> @dumpOrphanKeys
SQL> set serveroutput on
SQL>
SQL> declare
  2     key_count int;
  3  begin
  4     key_count := 0;
  5  dbms_repair.dump_orphan_keys (
  6     schema_name => 'SYSTEM',
  7     object_name => 'T1_PK',
  8     object_type => dbms_repair.index_object,
  9     repair_table_name => 'REPAIR_TABLE',
 10     orphan_table_name => 'ORPHAN_KEY_TABLE',
 11     key_count => key_count);
 12     dbms_output.put_line('orphan key count: ' || to_char(key_count));
 13  end;
 14  /
orphan key count: 3
PL/SQL procedure successfully completed.

SQL> desc orphan_key_table
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 SCHEMA_NAME                               NOT NULL VARCHAR2(30)
 INDEX_NAME                                NOT NULL VARCHAR2(30)
 IPART_NAME                                         VARCHAR2(30)
 INDEX_ID                                  NOT NULL NUMBER
 TABLE_NAME                                NOT NULL VARCHAR2(30)
 PART_NAME                                          VARCHAR2(30)
 TABLE_ID                                  NOT NULL NUMBER
 KEYROWID                                  NOT NULL ROWID
 KEY                                       NOT NULL ROWID
 DUMP_TIMESTAMP                            NOT NULL DATE

SQL> select index_name, count(*) from orphan_key_table
  2  group by index_name;

INDEX_NAME                       COUNT(*)
------------------------------ ----------
T1_PK                                   3

Note: Index entry in the orphan key table implies that the index should be
rebuilt to guarantee the a table probe and an index probe return the same
result set.

DBMS_REPAIR.SKIP_CORRUPT_BLOCKS
===============================

SKIP_CORRUPT_BLOCKS enables/disables the skipping of corrupt blocks during
index and table scans of a specified object.

Note: If an index and table are out of sync, then a SET TRANSACTION READ ONLY
transaction may be inconsistent in situations where one query probes only
the index and then a subsequent query probes both the index and the table.
If the table block is marked corrupt, then the two queries will return
different results.

Suggestion: If SKIP_CORRUPT_BLOCKS is enabled, then rebuild any indexes
identified in the orphan key table (or all index associated with object
if DUMP_ORPHAN_KEYS was omitted).

SQL> @skipCorruptBlocks
SQL> declare
  2  begin
  3  dbms_repair.skip_corrupt_blocks (
  4     schema_name => 'SYSTEM',
  5     object_name => 'T1',
  6     object_type => dbms_repair.table_object,
  7     flags => dbms_repair.skip_flag);
  8  end;
  9  /

PL/SQL procedure successfully completed.

SQL> select table_name, skip_corrupt from dba_tables
  2  where table_name = 'T1';

TABLE_NAME                     SKIP_COR
------------------------------ --------
T1                             ENABLED

SQL> -- rows in corrupt block skipped, no errors on full table scan
SQL> select * from system.t1;

COL1              COL2
--------------------------------------------------------------------------------
4                 dddd
5                 eeee

--> Notice the pk index has not yet been corrected.

SQL> insert into system.t1 values (1,'aaaa');
insert into system.t1 values (1,'aaaa')
                   *
SQL> select * from system.t1 where col1 = 1;

no rows selected

DBMS_REPAIR.REBUILD_FREELISTS
===============================

REBUILD_FREELISTS rebuilds freelists for the specified object.

SQL> declare
  2  begin
  3  dbms_repair.rebuild_freelists (
  4     schema_name => 'SYSTEM',
  5     object_name => 'T1',
  6     object_type => dbms_repair.table_object);
  7  end;
  8  /

PL/SQL procedure successfully completed.

Rebuild Index
=============

Note:  Every index identified in the orphan key table should be rebuilt to
ensure consistent results.

SQL> alter index system.t1_pk rebuild online;

Index altered.

SQL> insert into system.t1 values (1, 'aaaa');

1 row created.

SQL> select * from system.t1;

COL1              COL2
--------------------------------------------------------------------------------
4                 dddd
5                 eeee
1                 aaaa

Note - The above insert statement was used to provide a simple example.
This is the perfect world - we know the data that was lost.  The temporary
table (temp_t1) should also be used to include all rows extracted from
the corrupt block.

Conclusion
==========

At this point the table T1 is available but data loss was incurred.  In general,
data loss must be seriously considered before using the DBMS_REPAIR package for
mining the index segment and/or table block dumps is very complicated and
logical inconsistencies may be introduced.  In the initial release, the only
repair affected by DBMS_REPAIR is to mark the block as software corrupt.

<<End of Article>

Setting an Oracle event:The structure of the trace syntax

PURPOSE
-------

The purpose of this article is to explain briefly the structure of the syntax to
event-based trace generation.

Setting an event: The structure of the trace syntax
---------------------------------------------------

@ A comprehensive/full overview of the event syntax can be found in:
@ Note:9331.1 - Full Event Syntax (from ksdp.c)
@ Note:45217.1 - Summary Event Syntax for WWCS

0. "Setting an Event" - Abstract definition:
============================================

   "Setting an event" means to tell oracle to generate information in form of a
   so called trace file in the context of the event.

1. Event Classes to be traced:
==============================

   There are 4 Classes of traceable events:

   Class 1 "Dump something": Traces are generated upon so called unconditioned,
                             immediate, events. This is the case when oracle data has
			     to be dumped like, e.g., the headers of all redolog files
			     or the contents of the controlfile. These events can not
			     be set in the init<SID>.ora.

   Class 2 "Trap on Error" : Setting this class of (error-) events cause oracle to
                             generate a so called errorstack everytime the event happens.

   Class 3 "Change execution path" : Setting such an event will cause oracle to
                             change the execution path for some specific code segment.
			     For example, setting event "10269" prevents SMON from doing
			     free space coalescing.

   Class 4 "Trace something": Events from this class are set to obtain traces that are
                             used for, e.g., sql tuning. A common event is "10046" which
			     will cause oracle to trace  the sql access path on each
			     sql-statement.

II. Event based trace generation syntax - Overview and examples:
================================================================

   1. Session:         alter session set events '10181 trace name context forever, level 1000';
   2. init<sid>.ora:   event="10181 trace name context forever, level 1000";

   -------------------------------------------------------------------------------------------
  | TRACE      |                        TRACE SYNTAX                                          |
  | CLASS      |                                                                              |
  |-------------------------------------------------------------------------------------------|
  |            | <event name> |                     <action>                                  |
  |-------------------------------------------------------------------------------------------|
  |            |              | <action key word> | "name" | <trace name> | <trace qualifier> |
   -------------------------------------------------------------------------------------------|
  |            |              |                   |        |              |                   |
  |            |  immediate   |   trace           | "name" | blockdump    |    level 67110390 |
  |            |  immediate   |   trace           | "name" | redohdr      |    level 10       |
  |            |  immediate   |   trace           | "name" | file_hdrs    |    level 10       |
  | "Dump      |  immediate   |   trace           | "name" | controlf     |    level 10       |
  | Something" |  immediate   |   trace           | "name" | systemstate  |    level 10       |
  |            |              |                   |        |              |                   |
  |-------------------------------------------------------------------------------------------
  |            |              |                   |        |              |                   |
  |            |        942   |   trace           | "name" | errorstack   |    forever        |
  |            |        942   |   trace           | "name" | errorstack   |    off            |
  | "Trap      |         60   |   trace           | "name" | errorstack   |    level 1        |
  | on         |       6501   |   trace           | "name" | processstate |    level 10       |
  | Error"     |       4030   |   trace           | "name" | heapdump     |    level 2        |
  |            |              |                   |        |              |                   |
  |-------------------------------------------------------------------------------------------
  |            |              |                   |        |              |                   |
  | "Change    |      10269   |   trace           | "name" | context      | forever, level 10 |
  | Execution  |              |                   |        |              |                   |
  | path"      |              |                   |        |              |                   |
  |            |              |                   |        |              |                   |
  |-------------------------------------------------------------------------------------------
  |            |              |                   |        |              |                   |
  |            |      10046   |   trace           | "name" | context      | forever, level 12 |
  | "Trace     |      10046   |   trace           | "name" | context      | off               |
  | something" |              |                   |        |              |                   |
  |            |              |                   |        |              |                   |
   -------------------------------------------------------------------------------------------

III: Trace syntax: Annotations
===============================

   0. There are tools like oradebug that allow for setting an event in another
      session; this is useful, e.g., for tracing the export utility.
      @Setting Events from Oracle Tools <Note:45219.1">
      @For a list of common ACTIONS see <Event:List>
      @For COMMON numeric events see    <event:Numeric>
   1. The general syntax of setting an event is:  <event name>  <action>
      <action> consists of three parts:           <action key word> <trace name> <trace qualifier>
      @<action key word> can be either "trace", "crash", or "debug".
      @ See <Note:9331.1">
      <event name> is either "immediate", by this indicating an unconditioned event
      or an event name given as a symbolic number from the system event name table.
      An unconditioned event (keyword "immediate") cannot be set in the parameter file.
      <trace qualifier> "forever" means: Activate a trace whenever this event occurs.
      <trace name> "context" is a special trace name and pertains only to events set up
      to either trace a diagnostic event or to change the behaviour of the oracle
      code execution path. It cannot be used in conjunction with errorstack- ("errorstack")
      or dump-generating ("immediate") events.
   2. There are exactly 2 types of events, session-events and process-events.
      Process-events are initialized in the parameter file, session-events
      are initialized with the "alter session..." or "alter system ..."command.
      When checking for posted events, the oracle server first checks for session events
      then for process-events.

RELATED DOCUMENTS
-----------------
@     Event Syntax for most common forms of event setting <Note:45217.1>
@     The FULL Event syntax <Note:9331.1>
@     Setting Events from Oracle Tools <Note:45219.1>
@     List of common ACTIONS <Event:List>
@     COMMON numeric events <Event:Numeric>

沪ICP备14014813号-2

沪公网安备 31010802001379号