Thursday, October 3, 2013

How Hugepages makes difference to regular Memory Management

Operating systems basically deals with two types of memory for its operations one is Physical memory ( actual Physical RAM) and the second is Virtual memory ( combination of Physical and Swap). Virtual Memory is used to store entire program that is currently running and the physical memory is to store only specific part of memory that is important at this moment. And both physical memory and virtual memory will be segmented as pages,  and the process of copying  the pages of the program from to/from the virtual memory to/from the physical memory is called paging.
Operating system manages a page table to map virtual memory pages to physical memory pages. So when ever operating system needs to access memory for some information it will look at the paging table first and then look at the corresponding physical memory, if it doesn’t find information in physical memory then go back to virtual memory to get the required information.
Terminology That we use when referring to hugepages:
TLB (Transalation Lookaside Buffer) : It is a buffer ( or cache) in a CPU that contains parts of the page table. This is a fixed size buffer being used to do virtual address translation faster.
hugetlb: This is an entry in the TLB that points to a HugePage (a large/big page larger than regular 4K and predefined in size). HugePages are implemented via hugetlb entries, i.e. we can say that a HugePage is handled by a “hugetlb page entry”.
hugetlbfs: This is a new in-memory filesystem like tmpfs and is presented by 2.6 kernel. Pages allocated on hugetlbfs type filesystem are allocated in HugePages.

How Hugepages makes difference to regular Memory Management?
HugePages is a feature integrated into the Linux kernel with release 2.6. This feature basically provides the alternative to the 4K page size (16K for IA64) providing bigger pages. There are some basic differences between Huge pages and regular pages, and they are :
a. Huge pages can be allocated on-demand but they must be reserved during the system startup.Otherwise the allocation fails because the memory by default segmented into 4K pages.
b. HuHugePages are not swappable. Therefore there is no page-in/page-out mechanism overhead.HugePages are universally regarded as pinned.
c. Decreased Page Table Overhead: Each entry in page table occupies 64bytes memory , and is we assume we have 256GB of memory which is segmented into 4K memory pages, the pagetable alone takes around 800MB in size and managing such large table is an overhead to the operating system. In other case, if the huge pages are activated then we can reserve major part ( around 90%) of the memory to be accessed as  256MB hugepages so that the  number of entries in the system page table reduces and the size of the page table also reduces to 40 to 50MB.
d. Overall memory performance will be improved : On virtual memory systems each memory operation is actually two abstract memory operations. Since there are less number of pages to work on, the possible bottleneck on page table access is clearly avoided
e. Size of the hugepages can vary from 2MB to 256MB depending on the kernel version.

How to find the current size of hugepage? 
 grep Huge /proc/meminfo

Wednesday, October 2, 2013

Sample Backup Scripts

We can perform whole database backups with the database mounted or open. To perform a whole database backup from  the RMAN prompt the BACKUP DATABASE command can be used. The simplest form of the command requires no parameters, as shown in this example:


RMAN> backup database;
In the following example no backup location was specified meaning that the backups will automatically be placed in the Flash Recovery Area (FRA). If the FRA has not been setup then all backups default to $ORACLE_HOME/dbs.

How to check if the RFA has been setup:


SQL> show parameter recovery_file_dest

NAME                                 TYPE           VALUE
------------------------------------ -----------    ------------------------------
db_recovery_file_dest                string         /arch/
db_recovery_file_dest_size           big integer    500G

If FRA is not setup (ie values are null) please refer to the following note for assistance in setting it up.

Note 305648.1 What is a Flash Recovery Area and how to configure it ?

If you wish to place your backup outside the FRA then following RMAN syntax may be used.


RMAN> backup database format '/backups/PROD/df_t%t_s%s_p%p';

• Backing Up Individual Tablespaces with RMAN

RMAN allows individual tablespaces to be backed up with the database in open or mount stage.


RMAN> backup tablespace SYSTEM, UNDOTBS, USERS;

• Backing Up Individual Datafiles and Datafile Copies with RMAN

The flexibilty of being able to backup a single datafile is also available. As seen below you are able to reference the datafile via the file# or file name. Multiple datafiles can be backed up at a time.


RMAN> backup datafile 2;

RMAN> backup datafile 2 format '/backups/PROD/df_t%t_s%s_p%p';

RMAN> backup datafile 1,2,3,6,7,8;

RMAN> backup datafile '/oradata/system01.dbf';
• Backing Up the current controlfile & Spfile

The controlfile and spfile are backed up in similar ways. Whenever a full database backup if performed, the controlfile and spfile are backed up. In fact whenever file#1 is backed up these two files are backed up also.

It is also good practise to backup the controlfile especially after tablespaces and datafiles have been added or deleted.

If you are not using an RMAN catalog it is more impotant that you frequently backup of your controlfile. You can also configure another method of controlfile backup which is referred to as 'autobackup of controlfile'.

 Refer to the manual for more information regarding this feature.


RMAN> backup current controlfile;

RMAN> backup current controlfile format '/backups/PROD/df_t%t_s%s_p%p';

RMAN> backup spfile;

• Backing Up Archivelogs

It is important that archivelogs are backed up in a timely manner and correctly removed to ensure the file system does not fill up. Below are a few different examples. Option one backs up all archive logs to the FRA or default location. Option two backs up all archivelogs generate between 7 and 30 days and option three backs up archive logs from log sequence number XXX until logseq YYY then deletes the archivelogs. It also backups the archive logs to a specified location.


RMAN> backup archivelog all;

RMAN> backup archivelog from time 'sysdate-30' until time 'sysdate-7';

RMAN> backup archivelog from logseq=XXX until logseq=YYY delete input format '/backups/PROD/%d_archive_%T_%u_s%s_p%p';
• Backing up the Whole database including archivelogs

Below is an example of how the whole database can be backed up and at the same time backup the archive logs and purge them following a successful backup.  The first example backups up to the FRA, however it you wish to redirect the output the second command shows how this is achieved.


RMAN> backup database plus archivelog delete input;

RMAN> backup database plus archivelog delete input format '/backups/PROD/df_t%t_s%s_p%p';

Monday, September 30, 2013

ORA-2194 Starting up the Database

Weekend after applying PSU while trying to start a database was receiving an ORA-2194 error.

ORA-2194, 00000, "event specification syntax error %s (minor error %s) near '%s'"
// *Cause: There is a syntax error in an event specification.
// *Action: Fix the error.

SQL>shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL>startup
SQL>ORA-2194: event specification syntax error 231 (minor error 286) near 'CONETXT'

after searching all log file i found-
Someone have added a one new event. and my db was using spfile.

SQL>alter system set event='10046 trace name conetxt forever, level 12' scope=spfile;
System altered 



These are the steps to resolve the problem.

1. Create a PFILE from the current SPFILE.  You only need to be connected as
   Sysdba, the database does not need to be started.

   SQL>create pfile from spfile;
   File created.

2. Edit the generated PFILE and fix the problem.

   Change...  *.event='10046 trace name conetxt forever, level 12'
   -to-       *.event='10046 trace name context forever, level 12'

3. Startup the database with the newly generated PFILE.

   SQL>startup pfile=/.....

4. Recreate the SPFILE.

   SQL>create spfile from pfile;
   File created.

DataPump Trace file details.

How are Data Pump trace files named, and where to find them ?

Data Pump trace files are written to the directories specified by the init.ora/spfile initialization parameters BACKGROUND_DUMP_DEST and USER_DUMP_DEST.

Data Pump Master Control Process (MCP).
Format : <SID>_dm<number>_<process_id>.trc
Example: ORCL_dm00_2896.trc   or:   ORCL_dm01_3422.trc (for second active Master Control Process)
Location: BACKGROUND_DUMP_DEST   or   <ADR_HOME>/trace

Data Pump Worker Process trace file.
Format : <SID>_dw<number>_<process_id>.trc
Example: ORCL_dw01_2936.trc   or:   ORCL_dw01_2844.trc  and  ORCL_dw02_2986.trc (if PARALLEL=2)
Location: BACKGROUND_DUMP_DEST   or   <ADR_HOME>/trace

Data Pump Shadow Process trace file.
Format : <SID>_ora_<process_id>.trc
Example: ORCL_ora_3020.trc
Location: USER_DUMP_DEST   or   <ADR_HOME>/trace

Note that in Oracle10g the default location for the trace files is: $ORACLE_HOME/rdbms/log
This location will be used if the initialization parameters BACKGROUND_DUMP_DEST and/or USER_DUMP_DEST are not set.

For Oracle11g, the trace files are written to the <ADR_HOME>/trace
where <ADR_HOME> is: <ADR_BASE>/diag/<product_type>/<prod_id>/<instance_id>
where <ADR_BASE> is specified by DIAGNOSTIC_DEST (defaults to: $ORACLE_HOME/log).
E.g.: /oracle/diag/rdbms/ORCL/ORCL/trace

Data pump Timing details

One of my export  job running more than 8 hours but did not seen any progress on log file and dumpfile .  after  googling i found below help full  undocumented parameter METRICS .
With the undocumented parameter METRICS additional information can be obtained about the number of objects that were processed and the time it took for processing them. Objects in this context are for example the exported system GRANT privileges, the imported tablespace quota GRANT statements, the exported CREATE TABLE statements. Note that the METRICS parameter does not create any additional trace files. Instead, the extra details are logged in the logfile of the Export Data Pump or Import Data Pump job.
Example output:

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
FLASHBACK automatically enabled to preserve database integrity.
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_04":  system/******** directory=test_dir dumpfile=ac_20130830.dmp logfile=exp_0830.log schemas=xxx EXCLUDE=GRANT METRICS=y
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 6.370 GB
Processing object type SCHEMA_EXPORT/USER
     Completed 1 USER objects in 0 seconds
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
     Completed 8 SYSTEM_GRANT objects in 1 seconds
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
     Completed 1 DEFAULT_ROLE objects in 0 seconds
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
     Completed 2 TABLESPACE_QUOTA objects in 0 seconds
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
     Completed 1 PROCACT_SCHEMA objects in 3 seconds
Processing object type SCHEMA_EXPORT/TYPE/TYPE_SPEC
     Completed 239 TYPE objects in 1 seconds
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
     Completed 354 SEQUENCE objects in 3 seconds
Processing object type SCHEMA_EXPORT/TABLE/TABLE
     Completed 457 TABLE objects in 8 seconds
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
     Completed 850 INDEX objects in 2 seconds
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
     Completed 2350 CONSTRAINT objects in 5 seconds
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
     Completed 851 INDEX_STATISTICS objects in 1 seconds
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
     Completed 2423 COMMENT objects in 4 seconds
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_SPEC
     Completed 77 PACKAGE objects in 1 seconds
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
     Completed 51 PROCEDURE objects in 0 seconds
Processing object type SCHEMA_EXPORT/PACKAGE/COMPILE_PACKAGE/PACKAGE_SPEC/ALTER_PACKAGE_SPEC
     Completed 77 ALTER_PACKAGE_SPEC objects in 0 seconds


Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE

Recover readonly tablespace

How to recover a READONLY tablespace backups made before a RESETLOGS in a new
incarnation:

* Backups of a  tablespace made after it was made read-only
 (only if it was not made read/write again before the RESETLOGS)


This is  a inhouse tested scenario

Here are the steps :

STEPS
-----

SQL> select name,status,checkpoint_change# from v$datafile;
NAME                                     STATUS          CHECKPOINT_CHANGE#
---------------------------------------- -------         ------------------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF      SYSTEM             766796
D:\ORACLE\ORADATA\AMAR\RBS01.DBF         ONLINE             766796
D:\ORACLE\ORADATA\AMAR\USERS01.DBF       ONLINE             766796
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF        ONLINE             766796
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF       ONLINE             766796
D:\ORACLE\ORADATA\AMAR\INDX01.DBF        ONLINE             766796
D:\ORACLE\ORADATA\AMAR\DR01.DBF          ONLINE             766796
D:\ORACLE\ORADATA\AMAR\TEST01.DBF        ONLINE             423736  --> THIS IS THE READ ONLY TABLESPACE
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF        ONLINE             766864

9 rows selected.

SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME                       STATUS
------------------------------        ---------
SYSTEM                                 ONLINE
RBS                                    ONLINE
USERS                                  ONLINE
TEMP                                   ONLINE
TOOLS                                  ONLINE
INDX                                   ONLINE
DRSYS                                  ONLINE
TEST                                   READ ONLY
JAGU                                   ONLINE

9 rows selected.

SQL> shutdown abort
ORACLE instance shut down.

----------ASSUME THERE WAS  A  DATABASE CRASH --------------------

A few assumptions in this case
------------------------

++ Having Restored  all the datafile except the read only
++ NOT  RESTORED THE  readonly tablespace datafile yet
++ Trying to do the incomplete recovery

SQL> startup mount
ORACLE instance started.
Total System Global Area  187987996 bytes
Fixed Size                    75804 bytes
Variable Size              67436544 bytes
Database Buffers          120397824 bytes
Redo Buffers                  77824 bytes
Database mounted.



SQL> recover database until cancel ;
ORA-00283: recovery session canceled due to errors
ORA-01157: cannot identify/lock data file 8 - see DBWR trace file
ORA-01110: data file 8: 'D:\ORACLE\ORADATA\AMAR\TEST01.DBF'

Reason for this error
-----------------------
++  As this file is missing .
++  SO EITHER we HAVE to  RESTORE FROM BACKUP or OFFLINE DROP THIS FILE


++  Now have dropped the datafile 8

SQL> alter database datafile 8 offline drop;

Database altered.

SQL> select name,status from v$datafile_header;
NAME                                      STATUS
---------------------------------------- -------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF      ONLINE
D:\ORACLE\ORADATA\AMAR\RBS01.DBF         ONLINE
D:\ORACLE\ORADATA\AMAR\USERS01.DBF       ONLINE
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF        ONLINE
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF       ONLINE
D:\ORACLE\ORADATA\AMAR\INDX01.DBF        ONLINE
D:\ORACLE\ORADATA\AMAR\DR01.DBF          ONLINE
                                         OFFLINE - in datafile header entry is there
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF        ONLINE

9 rows selected.

SQL> select FILE# from v$recover_file;
 FILE#
----------
         8  FILE NEEDS ReCOVERY

+++ DONE a INCOMPLETE Recovery

SQL> recover database until cancel
cancel

SQL> alter database open resetlogs;

Database altered.

SQL> select name,to_char(RESETLOGS_TIME,'DD-MON-YYYY HH:MI::SS') from v$database

  2  ;
NAME                                         TO_CHAR(RESETLOGS_TIM
---------------------------------------- ---------------------
AMAR                                     01-MAR-2004 01:07::18

SQL> select name,to_char(RESETLOGS_TIME,'DD-MON-YYYY HH:MI::SS')
  2  from v$datafile_header;
NAME                                         TO_CHAR(RESETLOGS_TIM
---------------------------------------- ---------------------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF      01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\RBS01.DBF         01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\USERS01.DBF       01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF        01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF       01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\INDX01.DBF        01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\DR01.DBF          01-MAR-2004 01:07::18
                                                                 MISSING FOR DATAFILE 8
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF        01-MAR-2004 01:07::18

9 rows selected.

SQL> select file# from v$recover_file;
FILE#
----------
         8  - Still showing needs recovery after RESETLOGS

++ If this file was lost in the crash we will need to restore the same from the backup taken after it was made READ ONLY

SQL> recover datafile 8;
ORA-00283: recovery session canceled due to errors
ORA-00264: no recovery required


Reasons for the errors seen
---------------------------

++ As this is a READ ONLY TS it does not need media recovery
++ We cant take the datafile online directly

SQL> alter database datafile 8 online;
alter database datafile 8 online
*
ERROR at line 1:
ORA-01190: controlfile or data file 8 is from before the last RESETLOGS
ORA-01110: data file 8: 'D:\ORACLE\ORADATA\AMAR\TEST01.DBF'

SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
RBS                            ONLINE
USERS                          ONLINE
TEMP                           ONLINE
TOOLS                          ONLINE
INDX                           ONLINE
DRSYS                          ONLINE
TEST                           READ ONLY -READONLY After RESETLOGS
JAGU                           ONLINE

9 rows selected.

SQL> select name,status from v$datafile;
 clsNAME                                 STATUS
---------------------------------------- -------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF      SYSTEM
D:\ORACLE\ORADATA\AMAR\RBS01.DBF         ONLINE
D:\ORACLE\ORADATA\AMAR\USERS01.DBF       ONLINE
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF        ONLINE
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF       ONLINE
D:\ORACLE\ORADATA\AMAR\INDX01.DBF        ONLINE
D:\ORACLE\ORADATA\AMAR\DR01.DBF          ONLINE
D:\ORACLE\ORADATA\AMAR\TEST01.DBF        OFFLINE -- as we have offline drop this file
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF        ONLINE

9 rows selected.

SQL> select name,status from v$datafile_header;
 clsNAME                                  STATUS
---------------------------------------- -------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF      ONLINE
D:\ORACLE\ORADATA\AMAR\RBS01.DBF         ONLINE
D:\ORACLE\ORADATA\AMAR\USERS01.DBF       ONLINE
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF        ONLINE
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF       ONLINE
D:\ORACLE\ORADATA\AMAR\INDX01.DBF        ONLINE
D:\ORACLE\ORADATA\AMAR\DR01.DBF          ONLINE
                                         OFFLINE -- as we have offline drop this file
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF        ONLINE

9 rows selected.


+++ TRYing to take the READ ONLY tablespace ONLINE
SQL> alter tablespace test online;

Tablespace altered.

SQL> select name,status from v$datafile;
NAME                                     STATUS
---------------------------------------- -------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF      SYSTEM
D:\ORACLE\ORADATA\AMAR\RBS01.DBF         ONLINE
D:\ORACLE\ORADATA\AMAR\USERS01.DBF       ONLINE
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF        ONLINE
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF       ONLINE
D:\ORACLE\ORADATA\AMAR\INDX01.DBF        ONLINE
D:\ORACLE\ORADATA\AMAR\DR01.DBF          ONLINE
D:\ORACLE\ORADATA\AMAR\TEST01.DBF        ONLINE -File is online
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF        ONLINE

9 rows selected.

SQL> select name,status from v$datafile_header;
NAME                                     STATUS
---------------------------------------- -------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF      ONLINE
D:\ORACLE\ORADATA\AMAR\RBS01.DBF         ONLINE
D:\ORACLE\ORADATA\AMAR\USERS01.DBF       ONLINE
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF        ONLINE
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF       ONLINE
D:\ORACLE\ORADATA\AMAR\INDX01.DBF        ONLINE
D:\ORACLE\ORADATA\AMAR\DR01.DBF          ONLINE
D:\ORACLE\ORADATA\AMAR\TEST01.DBF        ONLINE - FIle is online
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF        ONLINE

9 rows selected.

SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
RBS                            ONLINE
USERS                          ONLINE
TEMP                           ONLINE
TOOLS                          ONLINE
INDX                           ONLINE
DRSYS                          ONLINE
TEST                           READ ONLY -- Still in Read only after resetlogs and is accessible in the database.
JAGU                           ONLINE

9 rows selected.

SQL> select name,checkpoint_change# from v$datafile_header;
NAME                                       CHECKPOINT_CHANGE#
---------------------------------------- ------------------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF                  766872
D:\ORACLE\ORADATA\AMAR\RBS01.DBF                     766872
D:\ORACLE\ORADATA\AMAR\USERS01.DBF                   766872
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF                    766872
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF                   766872
D:\ORACLE\ORADATA\AMAR\INDX01.DBF                    766872
D:\ORACLE\ORADATA\AMAR\DR01.DBF                      766872
D:\ORACLE\ORADATA\AMAR\TEST01.DBF                    423736 -- its  the same SCN as we started with
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF                    766872

9 rows selected.

SQL> select name,to_char(RESETLOGS_TIME,'DD-MON-YYYY HH:MI::SS')
  2  from v$datafile_header;
NAME                                      TO_CHAR(RESETLOGS_TIM
---------------------------------------- ---------------------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF      01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\RBS01.DBF         01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\USERS01.DBF       01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF        01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF       01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\INDX01.DBF        01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\DR01.DBF          01-MAR-2004 01:07::18
D:\ORACLE\ORADATA\AMAR\TEST01.DBF        10-NOV-2003 01:12::26 -- Showing the LAST RESETLOGS date
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF        01-MAR-2004 01:07::18

9 rows selected.

SQL> alter tablespace test read write;

Tablespace altered.

SQL> select name,checkpoint_change# from v$datafile_header;
NAME                                      CHECKPOINT_CHANGE#
---------------------------------------- ------------------
D:\ORACLE\ORADATA\AMAR\SYSTEM01.DBF                  766872
D:\ORACLE\ORADATA\AMAR\RBS01.DBF                     766872
D:\ORACLE\ORADATA\AMAR\USERS01.DBF                   766872
D:\ORACLE\ORADATA\AMAR\TEMP01.DBF                    766872
D:\ORACLE\ORADATA\AMAR\TOOLS01.DBF                   766872
D:\ORACLE\ORADATA\AMAR\INDX01.DBF                    766872
D:\ORACLE\ORADATA\AMAR\DR01.DBF                      766872
D:\ORACLE\ORADATA\AMAR\TEST01.DBF                    766928 -Sync with the other files
D:\ORACLE\ORADATA\AMAR\JAGU01.DBF                    766872

9 rows selected.

Now the Readonly tablespace before the incarnation is a part of the database.

After performing a RESTORE / RECOVER, desire to perform quick validation checks to ensure database is consistent and ready for OPEN RESETLOGS.

This proactive check helps to prevent several issues which may appear during or after OPEN RESETLOGS.

At first, It's helpful to enable the session to display the timestamp for DATE type columns :


SQL> alter session set nls_date_format='DD-MON-YYYY HH24:MI:SS' ;
Check 1:

Objective: Verify that the datafiles are recovered to the intended point in time (PIT) and they are consistent (FUZZY=NO)

Query the current status and PIT (P-oint I-n T-ime upto which the datafiles have been recovered) of datafiles by reading datafile headers directly from the physical datafiles:


SQL> select fuzzy, status, error, recover, checkpoint_change#, checkpoint_time, count(*) from v$datafile_header group by fuzzy, status, error, recover, checkpoint_change#, checkpoint_time ;

FUZ STATUS  ERROR           REC CHECKPOINT_CHANGE# CHECKPOINT_TIME        COUNT(*)
--- ------- --------------- --- ------------------ -------------------- ----------
NO  ONLINE                                 5311260 31-AUG-2011 23:10:14          6
YES ONLINE                                 5311260 31-AUG-2011 23:10:14          1



+ Verify that the checkpoint_time / checkpoint_change# is in line with your intended UNTIL TIME/SCN. If not, recover the database further if you have more archived logs available.

+ If FUZZY=YES for some datafiles, it means more recovery is required. If no more archived logs are available, identify such datafiles and determine if we can take them offline because we will loose the data in those datafiles. If the datafiles belong to SYSTEM or UNDO tablespace, we can / MUST not bring such datafile offline without proper analysis. Please consult Oracle Support for further actions.

SQL> select file#, substr(name, 1, 50), substr(tablespace_name, 1, 15), undo_opt_current_change# from v$datafile_header where fuzzy='YES' ;

     FILE# SUBSTR(NAME,1,50)                                  SUBSTR(TABLESPA UNDO_OPT_CURRENT_CHANGE#
---------- -------------------------------------------------- --------------- ------------------------
         3 /u01/app/oracle/oradata/prod111/undotbs01.dbf      UNDOTBS1                         5117431

Occasionally, if the tablespace name doesn't indicate it to be UNDO tablespace, if we see non-zero value in column UNDO_OPT_CURRENT_CHANGE#, it indicates that the datafile contains undo segments.


To bring a datafile offline :


SQL> alter database datafile <file#> offline ;

Check 1 can be considered Passed when :

+ Verified that all the datafiles have been recovered upto the intended Point in time.

+ Fuzzy=NO for SYSTEM, UNDO and all intended datafiles. For datafiles with Fuzzy=YES, either recover them further or bring them OFFLINE if no further archived logs available.


Check 2:

Objective: Verify that the files with status=RECOVER are not OFFLINE unintentionally

SQL> select status, enabled, count(*) from v$datafile group by status, enabled ;

STATUS  ENABLED      COUNT(*)
------- ---------- ----------
SYSTEM  DISABLED            1
ONLINE  READ WRITE          4
RECOVER DISABLED            2



If the files are in RECOVER status, verify if they are OFFLINE :


SQL> select file#, substr(name, 1, 50), status, error, recover from v$datafile_header ;



If you want the data for these files to be accessible, then bring them ONLINE :


SQL> alter database datafile <file#> ONLINE ;



If a file remains offline at the time of OPEN RESETLOGS, the datafile may not be brought back online again in the same OPENED database.

Check 2 can be considered Passed when:

a) All the intended datafiles are not OFFLINE 

 

Check 3:

Objective: Additional Fuzzy check (Absolute Fuzzy check) 


Occasionally, it is possible to see Fuzzy=NO and same checkpoint_change# for all the intended datafiles ; still some of the datafiles might be fuzzy and OPEN RESETLOGS will return error, e.g.

SQL> select fuzzy, status, error, recover, checkpoint_change#, checkpoint_time, count(*) from v$datafile_header group by fuzzy, status, error, recover, checkpoint_change#, checkpoint_time ;

FUZ STATUS  ERROR           REC CHECKPOINT_CHANGE#      CHECKPOINT_TIME   COUNT(*)
--- ------- --------------- --- ------------------ -------------------- ----------
NO  ONLINE                                 5311260 31-AUG-2011 23:10:14          7


SQL> ALTER DATABASE OPEN RESETLOGS ;

ORA-01194: file 4 needs more recovery to be consistent
ORA-01110: data file 3: '/u01/app/oracle/oradata/prod111/undotbs02.dbf'



Hence, we should perform additional fuzzy check known as Absolute Fuzzy Check:


SQL> select hxfil file#, substr(hxfnm, 1, 50) name, fhscn checkpoint_change#, fhafs Absolute_Fuzzy_SCN, max(fhafs) over () Min_PIT_SCN from x$kcvfh where fhafs!=0 ;

FILE#      NAME                                               CHECKPOINT_CHANG ABSOLUTE_FUZZY_S     MIN_PIT_SCN
---------- -------------------------------------------------- ---------------- ---------------- ----------------
         4 /u01/app/oracle/oradata/prod111/undotbs01.dbf               5311260          5311524          5311524
         6 /u01/app/oracle/oradata/prod111/system01.dbf                5311260          5311379          5311524
 

Note: Column Min_PIT_SCN will return same value even for multiple rows as we have applied ANALYTICAL "MAX() OVER ()" function on it.

Above query indicates that the recovery must be performed at least UNTIL SCN 5311524 to make datafiles consistent and ready to OPEN. Since the checkpoint_change# is smaller than Min_PIT_SCN, the datafiles will ask for more recovery.


Check 3 can be considered Passed when,

a) No rows selected from above query (i.e. Min_PIT_SCN is 0 (Zero) for all the datafiles)

b) Min_PIT_SCN is returned less than Checkpoint_Change#


Check 4 (After successful OPEN RESETLOGS) :

Monitor the alert.log for the time of OPEN RESETLOGS activities. You might see some messages like below during dictionary check: 

Dictionary check beginning
Tablespace 'TEMP' #3 found in data dictionary, <(============================== (1)
but not in the controlfile. Adding to controlfile.
Tablespace 'USERS' #4 found in data dictionary, 
but not in the controlfile. Adding to controlfile.
File #4 found in data dictionary but not in controlfile.
Creating OFFLINE file 'MISSING00004' in the controlfile. <(==================== (2)
File #5 is online, but is part of an offline tablespace. <(==================== (3)
data file 5: '/u01/app/oracle/oradata/prod111/example01.dbf'
File #7 found in data dictionary but not in controlfile. <(==================== (2)
Creating OFFLINE file 'MISSING00007' in the controlfile.
File #8 is offline, but is part of an online tablespace. <(==================== (4)
data file 8: '/u01/app/oracle/oradata/prod111/mydata02.dbf'
File #9 is online, but is part of an offline tablespace. <(==================== (3)
data file 9: '/u01/app/oracle/oradata/prod111/example02.dbf'
Dictionary check complete


We discuss below the points highlighted :


(1) Check if the temp files exist. If not, add them as per your preference: 

SQL> select file#, name from v$tempfile ;

no rows selected

SQL> select file#, name from dba_temp_files ;

no rows selected


SQL> select tablespace_name, status, contents from dba_tablespaces where contents='TEMPORARY' ;

TABLESPACE_NAME                STATUS    CONTENTS
------------------------------ --------- ---------
TEMP                           ONLINE    TEMPORARY


SQL> alter tablespace temp add tempfile '/u01/app/oracle/oradata/temp01.dbf' size 10m ;

Tablespace altered.

SQL> select file#, substr(name, 1, 50), status, enabled from v$tempfile

FILE#    SUBSTR(NAME,1,50)                                  STATUS  ENABLED
-------- -------------------------------------------------- ------- ----------
       1 /u01/app/oracle/oradata/temp01.dbf                 ONLINE  READ WRITE

(2) It appears that the tablespace was brought offline using "ALTER TABLESPACE USERS OFFLINE" command. So, verify if the missing files really exist with original name. You may need to consult your pear DBAs, or refer alert.log / RMAN backup log or any such information which may provide clue about the actual file name. 

If you find the file, try to rename them. If not, we can offline the datafile or drop associated tablespace:

SQL> select file#, status, enabled, substr(name, 1, 50) from v$datafile where name like '%MISSING%' ;

FILE#    STATUS  ENABLED    SUBSTR(NAME,1,50)
-------- ------- ---------- --------------------------------------------------
       4 OFFLINE DISABLED   /u01/app/oracle/product/11.1.0/db_1/dbs/MISSING000
       7 OFFLINE DISABLED   /u01/app/oracle/product/11.1.0/db_1/dbs/MISSING000


SQL> alter database datafile 4 online ;
alter database datafile 4 online
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01111: name for data file 4 is unknown - rename to correct file
ORA-01110: data file 4: '/u01/app/oracle/product/11.1.0/db_1/dbs/MISSING00004'


SQL> alter database rename file 'MISSING00004' to '/u01/app/oracle/oradata/prod111/users01.dbf' ;

Database altered.

SQL> alter database rename file 'MISSING00007' to '/u01/app/oracle/oradata/prod111/users02.dbf' ;

Database altered.

SQL> select tablespace_name, status from dba_tablespaces where tablespace_name in (select tablespace_name from dba_data_files where file_id in (4, 7)) ;

TABLESPACE_NAME                STATUS
------------------------------ ---------
USERS                          OFFLINE

SQL> ALTER TABLESPACE USERS ONLINE ;

Tablespace altered.



Before proceedig further, let's query the status for these files in alert.log:

SQL> select a.file#, substr(a.name, 1, 50) file_name, a.status file_status, a.error, substr(a.tablespace_name, 1, 10) tablespace_name, b.status tablespace_status from v$datafile_header a, dba_tablespaces b
where a.tablespace_name=b.tablespace_name /* and a.file# in (4, 5, 7, 8, 9) */ ;

FILE# FILE_NAME                                     FILE_STATUS ERROR           TABLESPA TABLESPACE_STATUS
----- --------------------------------------------- ----------- --------------- -------- ------------------
    1 /u01/app/oracle/oradata/prod111/system01.dbf  ONLINE                      SYSTEM   ONLINE
    2 /u01/app/oracle/oradata/prod111/sysaux01.dbf  ONLINE                      SYSAUX   ONLINE
    3 /u01/app/oracle/oradata/prod111/undotbs01.dbf ONLINE                      UNDOTBS1 ONLINE
    4 /u01/app/oracle/oradata/prod111/users01.dbf   OFFLINE     OFFLINE NORMAL  USERS    OFFLINE <(== related to (2) in alert.log excerpt above
    5 /u01/app/oracle/oradata/prod111/example01.dbf ONLINE                      EXAMPLE  OFFLINE <(== related to (3) in alert.log excerpt above 
    6 /u01/app/oracle/oradata/prod111/mydata01.dbf  ONLINE                      MYDATA   ONLINE 
    7 /u01/app/oracle/oradata/prod111/users02.dbf   OFFLINE     OFFLINE NORMAL  USERS    OFFLINE <(== related to (2) in alert.log excerpt above 
    8 /u01/app/oracle/oradata/prod111/mydata02.dbf  OFFLINE     WRONG RESETLOGS MYDATA   ONLINE <(=== related to (4) in alert.log excerpt above 
    9 /u01/app/oracle/oradata/prod111/example02.dbf ONLINE                      EXAMPLE  OFFLINE <(== related to (3) in alert.log excerpt above

9 rows selected.


So, we can attempt to correct the "ERROR" as displayed in above query depending on the availability of file / archived logs and other possible factors. 

Let's continue,

(3) It seems that tablespace was brought offline inconsistently ( ALTER TABLESPACE EXAMPLE OFFLINE IMMEDIATE ). If the archived log generated at that time has got applied, the file may be back online : 
 

SQL> alter tablespace example ONLINE ;

Tablespace altered.
 

(4) This tablespace MYDATA has 2 datafiles File# 6 & 8. It appears that File# 8 was brought offline ( using ALTER DATABASE DATAFILE 8 OFFLINE ) and it was OFFLINE before OPEN RESETLOGS. If the archived log generated at that time has got applied during recovery or all the archived logs are available for recovery since that time, the file may be back online :

SQL> alter database datafile 8 online ;
alter database datafile 8 online
*
ERROR at line 1:
ORA-01190: control file or data file 8 is from before the last RESETLOGS
ORA-01110: data file 8: '/u01/app/oracle/oradata/prod111/mydata02.dbf'


SQL> alter tablespace mydata online ;
alter tablespace mydata online
*
ERROR at line 1:
ORA-01190: control file or data file 8 is from before the last RESETLOGS
ORA-01110: data file 8: '/u01/app/oracle/oradata/prod111/mydata02.dbf'


SQL> recover datafile 8 ;
Media recovery complete.
SQL> alter database datafile 8 online ;

Database altered.

SQL> alter tablespace mydata online ;

Tablespace altered.


Please note that it is not always possible to recover and bring the file online which is failing with error " ORA-01190: control file or data file x is from before the last RESETLOGS".