Monday, March 25, 2013

How to fix ORA-26040: Data block was loaded using the NOLOGGING option

Today I faced with new ORA error. After solving I want to share this experience with yours.

So, today 5`th datafile of my database was corrupted (/u01/app/oracle/oradata/ulfet_db/example01.dbf).
After recover via RMAN I saw strange error.


RMAN> recover datafile 5 block 443;
Starting recover at 24-MAR-13
using channel ORA_DISK_1
channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00005
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ULFET_DB/backupset/2013_03_24/o1_mf_nnndf_TAG20130324T223233_8nykp220_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/ULFET_DB/backupset/2013_03_24/o1_mf_nnndf_TAG20130324T223233_8nykp220_.bkp tag=TAG20130324T223233
channel ORA_DISK_1: restored block(s) from backup piece 1
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:03

starting media recovery
media recovery complete, elapsed time: 00:00:04
Finished recover at 24-MAR-13
RMAN>



SQL> select count(1) from block_corrupt_test;
select count(1) from block_corrupt_test
                     *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 5, block # 443)
ORA-01110: data file 5: '/u01/app/oracle/oradata/ulfet_db/example01.dbf'
ORA-26040: Data block was loaded using the NOLOGGING option


col segment_name format a20
col tablespace_name format a15

SQL> select owner, segment_name, tablespace_name from dba_extents where FILE_ID=5 and 443 between BLOCK_ID and BLOCK_ID+BLOCKS;

OWNER                       SEGMENT_NAME               TABLESPACE_NAME
------------------------ --------------------                  ---------------
SYS                              BLOCK_CORRUPT_TEST   EXAMPLE

Using dbv utility to clarify datafile corruption  

[oracle@localhost ~]$ dbv file=/u01/app/oracle/oradata/ulfet_db/example01.dbf

DBVERIFY: Release 11.2.0.1.0 - Production on Sun Mar 24 22:57:06 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

DBVERIFY - Verification starting : FILE = /u01/app/oracle/oradata/ulfet_db/example01.dbf

DBV-00201: Block, DBA 20971963, marked corrupt for invalid redo application


DBVERIFY - Verification complete

Total Pages Examined         : 12800
Total Pages Processed (Data) : 6586
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 1261
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 3251
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 1702
Total Pages Marked Corrupt   : 1
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 1377097 (0.1377097)
[oracle@localhost ~]$ 

Use below query to get block error and file_name:

SQL> select dbms_utility.data_block_address_block('20971963') block_no,
dbms_utility.data_block_address_file('20971963') file_no
from dual;

  BLOCK_NO    FILE_NO
---------- ----------
       443          5

SQL> 

Now follow up below statements:

Create the repair table (in tablespace where corrupted table resides)

SQL> BEGIN
DBMS_REPAIR.ADMIN_TABLES (
TABLE_NAME => 'REPAIR_TABLE',
TABLE_TYPE => dbms_repair.repair_table,
ACTION => dbms_repair.create_action,
TABLESPACE => 'example');
END;
/  2    3    4    5    6    7    8  

PL/SQL procedure successfully completed.

SQL> 

Identify corrupted blocks:

SQL> set serveroutput on
DECLARE num_corrupt INT;
BEGIN
num_corrupt := 0;
DBMS_REPAIR.CHECK_OBJECT (
SCHEMA_NAME => 'SYS',
OBJECT_NAME => 'BLOCK_CORRUPT_TEST',
REPAIR_TABLE_NAME => 'REPAIR_TABLE',
corrupt_count => num_corrupt);
DBMS_OUTPUT.PUT_LINE('number corrupt: ' || TO_CHAR (num_corrupt));
END;
/SQL>   2    3    4    5    6    7    8    9   10   11  
number corrupt: 1

PL/SQL procedure successfully completed.

SQL> 


Show corrupted blocks:

SQL> select BLOCK_ID, CORRUPT_TYPE from REPAIR_TABLE;

BLOCK_ID CORRUPT_TYPE
---------- ------------
       443         6148

SQL> 


Mark the identified blocks as corrupted:

SQL> DECLARE num_fix INT;
BEGIN
num_fix := 0;
DBMS_REPAIR.FIX_CORRUPT_BLOCKS (
SCHEMA_NAME => 'SYS',
OBJECT_NAME=> 'BLOCK_CORRUPT_TEST',
OBJECT_TYPE => dbms_repair.table_object,
REPAIR_TABLE_NAME => 'REPAIR_TABLE',
FIX_COUNT=> num_fix);
DBMS_OUTPUT.PUT_LINE('num fix: ' || to_char(num_fix));
END;
/  2    3    4    5    6    7    8    9   10   11   12  

PL/SQL procedure successfully completed.

SQL> 

Allow in the future DML statements to skip the corrupted blocks:

SQL> BEGIN
DBMS_REPAIR.SKIP_CORRUPT_BLOCKS (
SCHEMA_NAME => 'SYS',
OBJECT_NAME => 'BLOCK_CORRUPT_TEST',
OBJECT_TYPE => dbms_repair.table_object,
FLAGS => dbms_repair.SKIP_FLAG);
END;
/  2    3    4    5    6    7    8  

PL/SQL procedure successfully completed.

SQL> 


Now, check table again:

SQL> select count(1) from block_corrupt_test;
COUNT(1)
------------
10


Wednesday, March 13, 2013

Change production database name

Today I will show you how to rename existing database name. Before it take backup of your database and also please note that this step will change only database name not dbid.

My database name is prod2 and oracle version is 11g R2. I will change it to prod name.

SQL> select name from v$database;

NAME
---------
PROD2

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

SQL>

[oracle@localhost ~]$ uname -n
localhost.localdomain

[oracle@localhost ~]$ more /etc/redhat-release 
Red Hat Enterprise Linux Server release 5.5 (Tikanga)

Firstly shutdown database and open it on mount mode.

[oracle@localhost ~]$ sql

SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 13 19:29:16 2013

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  318046208 bytes
Fixed Size                  1336260 bytes
Variable Size             109055036 bytes
Database Buffers          201326592 bytes
Redo Buffers                6328320 bytes
Database mounted.
SQL> 

Now execute nid utility (dbnewid) and specify new database name.

[oracle@localhost ~]$ nid target =/ dbname=prod setname=YES

DBNEWID: Release 11.2.0.1.0 - Production on Wed Mar 13 19:33:07 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Connected to database PROD2 (DBID=1461820883)

Connected to server version 11.2.0

Control Files in database:
    /u01/app/oracle/oradata/prod2/control01.ctl
    /u01/app/oracle/flash_recovery_area/prod2/control02.ctl

Change database name of database PROD2 to PROD? (Y/[N]) => Y

Proceeding with operation
Changing database name from PROD2 to PROD
    Control File /u01/app/oracle/oradata/prod2/control01.ctl - modified
    Control File /u01/app/oracle/flash_recovery_area/prod2/control02.ctl - modified
    Datafile /u01/app/oracle/oradata/prod2/system01.db - wrote new name
    Datafile /u01/app/oracle/oradata/prod2/sysaux01.db - wrote new name
    Datafile /u01/app/oracle/oradata/prod2/undotbs01.db - wrote new name
    Datafile /u01/app/oracle/oradata/prod2/users01.db - wrote new name
    Datafile /u01/app/oracle/oradata/prod2/temp01.db - wrote new name
    Control File /u01/app/oracle/oradata/prod2/control01.ctl - wrote new name
    Control File /u01/app/oracle/flash_recovery_area/prod2/control02.ctl - wrote new name
    Instance shut down

Database name changed to PROD.
Modify parameter file and generate a new password file before restarting.
Succesfully changed database name.
DBNEWID - Completed succesfully.

[oracle@localhost ~]$ 


Create new name directories in admin folder

[oracle@localhost admin]$ mkdir prod
[oracle@localhost admin]$ cd prod
[oracle@localhost prod]$ mkdir adump dpdump pfile


Last action is change pfile and password file and open database with resetlogs option.

[oracle@localhost pfile]$ pwd
/u01/app/oracle/admin/prod2/pfile

[oracle@localhost pfile]$ ls
init.ora.2132013192312

[oracle@localhost pfile]$ cat init.ora.2132013192312 | grep db_name
db_name=prod2

#change db_name to new db_name
#change audit_file_dest to new path : /u01/app/oracle/admin/prod/adump
[oracle@localhost pfile]$ vi init.ora.2132013192312

[oracle@localhost pfile]$ cat init.ora.2132013192312 | grep db_name
db_name=prod


[oracle@localhost pfile]$ cat init.ora.2132013192312 | grep audit_file
audit_file_dest=/u01/app/oracle/admin/prod/adump

[oracle@localhost dbs]$ pwd
/u01/oracle/product/11.2.0/db_1/dbs

[oracle@localhost dbs]$ orapwd file=orapwprod entries=5 ignorecase=y password=oracle

[oracle@localhost dbs]$ export | grep ORACLE_SID
declare -x ORACLE_SID="prod"
[oracle@localhost dbs]$ 


mv init file from ../prod2/pfile/ to ../prod/pfile/
and recreate spfile

[oracle@localhost dbs]$ export | grep ORACLE_SID
declare -x ORACLE_SID="prod"
[oracle@localhost dbs]$ sql

SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 13 19:52:23 2013

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> shut immediate
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux Error: 2: No such file or directory
SQL> shut abort;
ORACLE instance shut down.

SQL> create spfile from pfile='/u01/app/oracle/admin/prod/pfile/init.ora.2132013192312';

File created.

SQL> 

SQL> startup mount
ORACLE instance started.

Total System Global Area  318046208 bytes
Fixed Size                  1336260 bytes
Variable Size             109055036 bytes
Database Buffers          201326592 bytes
Redo Buffers                6328320 bytes
Database mounted.

SQL> alter database open;

Database altered.

SQL> select name from v$database;

NAME
---------
PROD

SQL>