Wednesday, September 16, 2015

DBMS_REPAIR - for fixing corrupt blocks in DB

Corruption was CheckSum and was not fixed by this process...

----------- How to find the tables with the problem -----

Where corrupt block is in File_ID=10 and Block # 270456

SELECT
  owner
, segment_name
, tablespace_name
FROM
  dba_extents
WHERE
  FILE_ID=10
AND 270456 BETWEEN BLOCK_ID AND BLOCK_ID+BLOCKS;

-------------------------------------

Setup a Table Space for DBMS_REPAIR tables:

CREATE SMALLFILE TABLESPACE "DBMS_REPAIR_TBL"
 DATAFILE
 'Repair1.dbf' SIZE 200M AUTOEXTEND ON NEXT 200M MAXSIZE 5G,
 'Repair2.dbf' SIZE 200M AUTOEXTEND ON NEXT 200M MAXSIZE 5G,
 'Repair3.dbf' SIZE 200M AUTOEXTEND ON NEXT 200M MAXSIZE 5G,
 'Repair4.dbf' SIZE 200M AUTOEXTEND ON NEXT 200M MAXSIZE 5G
 NOLOGGING
 DEFAULT NOCOMPRESS
 ONLINE
 EXTENT MANAGEMENT LOCAL AUTOALLOCATE
 SEGMENT SPACE MANAGEMENT AUTO;

Source for the below is:
http://www.dba-oracle.com/concepts/dbms_repair.htm

---------- Create Two Tables
begin
  dbms_repair.admin_tables(
       table_name => 'REPAIR_TABLE',
       table_type => dbms_repair.repair_table,
       action     => dbms_repair.create_action,
      tablespace => 'DBMS_REPAIR_TBL' );
end;
/

begin
  dbms_repair.admin_tables(
     table_name => 'ORPHAN_TABLE',
     table_type => dbms_repair.orphan_table,
     action     => dbms_repair.create_action,
     tablespace => 'DBMS_REPAIR_TBL'
   );
end;

---------------- Run Check Table

set serveroutput on
declare corr_count binary_integer;
begin
corr_count := 0;
dbms_repair.CHECK_OBJECT (
   schema_name       => 'HYP_CCC',
   object_name       => 'ENTITY_DAY_FACT',
   partition_name    => null,
   object_type       => dbms_repair.table_object,
   repair_table_name => 'REPAIR_TABLE',
   flags             => null,
   relative_fno      => null,
   block_start       => null,
   block_end         => null,
   corrupt_count     => corr_count
   );
dbms_output.put_line(to_char(corr_count));
end;
/

--- IF ERRORS found run Fix Table OR Fix Index

SET SERVEROUTPUT ON
DECLARE fix_count INT;
BEGIN
Fix_count := 0;
DBMS_REPAIR.FIX_CORRUPT_BLOCKS (
SCHEMA_NAME => 'HYP_CCC',
OBJECT_NAME=> 'ENTITY_DAY_FACT',
OBJECT_TYPE => dbms_repair.table_object,
REPAIR_TABLE_NAME => 'REPAIR_TABLE',
FIX_COUNT=> fix_count);
DBMS_OUTPUT.PUT_LINE('Fix count = ' || TO_CHAR(fix_count));
END;
/

---
SET SERVEROUTPUT ON
DECLARE key_count INT;
BEGIN
key_count := 0;
DBMS_REPAIR.DUMP_ORPHAN_KEYS (
SCHEMA_NAME => 'HYP_CCC',
OBJECT_NAME => 'INDEX_NAME_HERE',
OBJECT_TYPE => dbms_repair.index_object,
REPAIR_TABLE_NAME => 'REPAIR_TABLE',
ORPHAN_TABLE_NAME=> 'ORPHAN_KEY_TABLE',
KEY_COUNT => key_count);
DBMS_OUTPUT.PUT_LINE('Orphan key count: ' || TO_CHAR(key_count));
END;
/

----------

Tuesday, September 15, 2015

ArchiveLog turned on, but nobody is backing it up...

Archive logs fill up the disk quickly and cause an outage.

Here is how I deleted all archive logs.

Deleting old archive logs by date

The other day when logging into one of my test systems I was greeted with the following error:

ORA-00257 archiver error. connect internal only until freed

The cause?  Out of disk space.  Since it was non-production we weren't backing it up, so the archive logs were just hanging out there forever.

I logged into RMAN from the console and launched the following:

allocate channel for delete type disk;
change archivelog until time 'SYSDATE-7' delete;
release channel;


Don't do this on a production system and definitely re-think your decision to have Oracle databases in archivelog mode that aren't being frequently backed up.  I know I will.

Cheers

Oracle DB Shutdown taking forever....

One way out is to open another SQLPLUS '/ as sysdba'

then

Shutdown abort;

This will kill the long running shutdown in the other session.

Not recommended, but it works.