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".

Thursday, September 26, 2013

No need to bring down EBS services for patching any more

Wow - 12.2 comes with the dual file system. One for PROD purpose and one for patching purpose.So there is not need to bring down EBS services for patching. :).



Monday, September 23, 2013

Could not create connection; - nested throwable: java.sql.SQLException: Listener refused the connection with the

Last week after applying april PSU  our application was getting below error,

  2013-09-19 00:05:14"ERROR [STDERR] org.jboss.util.NestedSQLException: Could not create connection; - nested throwable: java.sql.SQLException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor"
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:419)
            at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536)
            at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228)
            at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
            at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
            at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory
===================================

at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1275)
  at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3576)
  at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3677)
 - locked <0xde1c0518> (a oracle.jdbc.driver.T4CConnection)
  at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1086) 
Below is finding -
After SCAN VIP and SCAN listener failover, instance does not register with the SCAN listener. It might happen for only 1 of the scan listener. Client connection gets intermittent ORA-12514 TNS:listener does not currently know of service requested in connect descriptor.
Solution:

1) For both above bugs, the workaround is to unregister and register remote listener on the database instance which does not register to a SCAN listener with following steps.
show parameter remote_listener
alter system set remote_listener='';
alter system register;
alter system set remote_listener='<scan>:<port>';
alter system register;
 
2 - As a workaround  relocate scan  listener from one node to another node this also  resolve my issue .

3) Other points to check if service is not registered with SCAN listener:
a. remote_listener and local_listener is defined correctly
b. EZCONNECT is defined in sqlnet.ora, eg: NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
c. SCAN name is defined in /etc/hosts or DNS and whether there is any mismatch if it is defined in both places
d. nslookup <scan> should display SCAN VIP in round-robin fashion
e. do not set SECURE_REGITER_<listener> in listener.ora if the class of secure transports (COST) is not configured.

Monday, September 16, 2013

improve sqL using advisory

Today One of Apps team ping me for  A sql run everyday 15 minuts in Procedure, but last 3 day's its take 40 to 50 minutes. 


I know that which query is problematic,i have  SQL ID for that query and use the SQL tuning advisory to get the recommendation. Below is an example that I used. 

SQL> DECLARE 
l_sql_tune_task_id VARCHAR2(100); 
BEGIN 
l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task ( 
sql_id => 'gq7k9ry2pazbh', 
scope => DBMS_SQLTUNE.scope_comprehensive, 
time_limit => 60, 
task_name => 'gq7k9ry2pazbh_tuning_task', 
description =>  2    3    4    5    6    7    8    9   'Tuning task for statement gq7k9ry2pazbh'); 
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id); 
END; 
/  10   11   12  

PL/SQL procedure successfully completed.

SQL> EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'gq7k9ry2pazbh_tuning_task'); 
^[[6~^H^H

PL/SQL procedure successfully completed.

SQL> SP2-0042: unknown command" - rest of line ignored.
SQL> 
SQL> SELECT task_name, status FROM dba_advisor_log WHERE owner = 'SYS' and task_name = 'gq7k9ry2pazbh_tuning_task'; 

TASK_NAME       STATUS
------------------------------ -----------
gq7k9ry2pazbh_tuning_task      COMPLETED

SQL> SET LONG 10000; 
SET PAGESIZE 1000 
SET LINESIZE 200 
SELECT DBMS_SQLTUNE.report_tuning_task('gq7k9ry2pazbh_tuning_task') AS recommendations FROM dual; 
SET PAGESIZE 24 SQL> SQL> SQL> 
RECOMMENDATIONS
--------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name   : gq7k9ry2pazbh_tuning_task
Tuning Task Owner  : SYS
Scope   : COMPREHENSIVE
Time Limit(seconds): 60
Completion Status  : COMPLETED
Started at   : 09/16/2013 12:42:38
Completed at   : 09/16/2013 12:43:11

-------------------------------------------------------------------------------
Schema Name: CRM
SQL ID   : gq7k9ry2pazbh
SQL Text   : sele...............................................

-------------------------------------------------------------------------------
There are no recommendations to improve the statement.

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

- Consider accepting the recommended SQL profile. 

SQL> execute dbms_sqltune.accept_sql_profile(task_name =>'gq7k9ry2pazbh_tuning_task', task_owner => 'SYS', replace => TRUE); 



Thursday, September 12, 2013

Power of oracle System user

Today i understand system db user  can change passwd of sys (supper user also ).

sqlplus system/One_1_Two_2T

SQL*Plus: Release 11.2.0.2.0 Production on Wed Sep 11 22:55:12 2013

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

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL>
SQL> show user
USER is "SYSTEM"
SQL>
SQL> alter user sys identified by One_1_Two_2T;

User altered.

SQL>

Standby datafile missing or datafile created with wrong name

Today I got a new problem in one of our 8 node cluster critical database. After verifying the error.
alert.log & Trace file I got the actual problem that on production database one datafile is created which is not created on desired location on standby side .

Note: If your STANDBY_FILE_MANAGEMENT parameter is not configured Auto in Data Guard environment and file is created then file will created
 on standby server with unnamed file name in dbs directory.

STANDBY_FILE_MANAGEMENT enables or disables automatic standby file management. When automatic standby file management is enabled, operating system file additions and deletions on the primary database are replicated on the standby database.

For example if we add a data file on the Primary when parameter STANDBY_FILE_MANAGEMENT on standby set to MANUAL , While recovery process(MRP) is trying to apply archives, Due to that parameter setting it will create an Unnamed file in $ORACLE_HOME/dbs and it will cause to kill MRP process and Errors will be as below.

Errors Received at the time of Recovery:-

SQL> RECOVER STANDBY DATABASE;

ORA-00283: recovery session canceled due to errors

ORA-01111: name for data file 992 is unknown – rename to correct file

ORA-01110: data file 992: '/$ORACLE_HOME/dba/UNNAMED00033'

ORA-01157: cannot identify/lock data file 992 – see DBWR trace file

ORA-01111: name for data file 992 is unknown – rename to correct file

ORA-01110: data file 992: '/$ORACLE_HOME/dba/UNNAMED00033'



Trace File:-

MRP0: Background Media Recovery terminated with error 1111

ORA-01111: name for data file 992 is unknown – rename to correct file

ORA-01110: data file 992: '/$ORACLE_HOME/dba/UNNAMED00033’

ORA-01157: cannot identify/lock data file 992 – see DBWR trace file

ORA-01111: name for data file 992 is unknown – rename to correct file
,,
,,

ARCH: Connecting to console port…

Check for the files needs to be recovered.

SQL> select * from v$recover_file where error like ‘%FILE%’;



FILE#  ONLINE  ONLINE_ ERROR                   CHANGE# TIME

—— ——- ——- ——————– ———- ——————–

    992 ONLINE  ONLINE  FILE MISSING                  0



SQL>

Identify on primary of data file 992(Primary Database)

SQL>  select file#,name from v$datafile where file#=992;



FILE#   NAME

—— ———————————————————————-

   992  +DATA01\DB_NAME/datafile/UNDOTBS02.DBF



SQL>

Identify dummy file name created in (Standby)

SQL> select file#,name from v$datafile where file#=992;



FILE#  NAME

—— ———————————————————————-

    992 /$ORACLE_HOME/dba/UNNAMED00033



SQL>

Crosscheck that no MRP is running and STANDBY_FILE_MANAGEMENT can be enabled once after creating file on standby



SQL> alter database create datafile ‘/$ORACLE_HOME/dba/UNNAMED00033' as ‘+DATA01\UNDO\UNDOTBS02.DBF

 *

 ERROR at line 1:

 ORA-01276: Cannot add file

 +DATA1\UNDO\UNDOTBS02. File has an Oracle Managed Files file name.

Since i am using  ASM with OMF, It's not allowed to create data file, because it will file system names and format maintained by ASM.  If you try to create datafile as above with ASM File, You will pass with below error.

Then Run above command as shown below

SQL> alter database create datafile /$ORACLE_HOME/dba/UNNAMED00033’ as new;

Database altered.

SQL>

Enable STANDBY_FILE_MANAGEMENT to AUTO & Start MRP.

SQL> show parameter standby_file_management

NAME                                 TYPE        VALUE

———————————— ———– ————————-

standby_file_management              string      MANUAL



SQL> alter system set standby_file_management=AUTO scope=both;

System altered.



SQL> show parameter standby_file_management

NAME                                 TYPE        VALUE

———————————— ———– ————————–

standby_file_management              string      AUTO



SQL> alter database recover managed standby database disconnect from session;

Database altered.

SQL>

After creating the file, MRP will start applying archives on standby database.

Note:-

Setting STANDBY_FILE_MANAGEMENT to AUTO causes Oracle to automatically create files on the standby database and, in some cases, overwrite existing files. Care must be taken when setting STANDBY_FILE_MANAGEMENT and DB_FILE_NAME_CONVERT so that existing standby files will not be accidentally overwritten.


There are many reasons for a file being created as UNNAMED or MISSING in the standby database,
including insufficient disk space on standby site (or) improper parameter settings related to file management.

Wednesday, September 11, 2013

"ORA-00245: control file backup failed; target is likely on a local file system" Backup fails on oracle 11.3 RAC database

We have 8 node Rac cluster. nothing is shared .
On a 8 node RAC database we were occasionally facing issue with RMAN backup.
released channel: CH3
released channel: CH4
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of resync command on default channel at 09/10/2013 22:03:09
ORA-00245: control file backup failed; target is likely on a local file system

Recovery Manager complete.
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of resync command on default channel at 09/10/2013 22:03:09
ORA-00245: control file backup failed; target is likely on a local file system

 rman target/

Recovery Manager: Release 11.2.0.3.0 - Production on Tue Sep 10 23:01:50 2013

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

connected to target database: RAC (DBID=XXXXXXXX)

Before ---

RMAN> show snapshot controlfile name;

using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name RAC are:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '<oracle_home_dbs>/snapcf_RAC01.f';

RMAN>

Thus in different instances I found the value is different as snapcf_rac02.f/snapcf_rac02.f ...rac08, also noticed "#default" at the end.

The issue is intermittent and does not appear every time, and so we are not sure if this is actually some issue with configuration.

Reason:-
Oracle [Support Note ID 1472171.1] says that snapshot control file should be on shared location.


After Taking action -
RMAN> show snapshot controlfile name;

using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name RAC are:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '+DATA/RAC/datafile/snapcf_RAC.f';

RMAN>

So at the place of making it on shared location we just gave it a common name, by just giving following command from any one node.

RMAN> CONFIGURE SNAPSHOT CONTROLFILE NAME TO '+DATA/RAC/datafile/snapcf_RAC.f';

After setting snapshot controlfile to Shared location (diskgroup) all the backups are successful.

Sunday, September 8, 2013

ORA-22859: invalid modification of columns

Today while Doing SqlServer Migration to Oracle db. i came to know below issue ,

As part of  requirement  apps team want to change joshiv_TEXT columan data type from   NOT N ULL CLOB to VARCHAR2(1000).

ALTER joshiv MODIFY  joshiv_TEXT varchar2(1000);

ALTER TABLE joshiv MODIFY  joshiv_TEXT varchar2(1000)
                                                         *
ERROR at line 1:
ORA-22859: invalid modification of columns

eugetp12 >desc joshiv
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 joshiv_STMT                             NOT NULL VARCHAR2(10 CHAR)
 joshiv_KEY                              NOT NULL VARCHAR2(9 CHAR)
 joshiv_TYPE                                      VARCHAR2(10 CHAR)
 joshiv_TEXT                             NOT NULL CLOB


ALTER TABLE joshiv ADD joshiv_TEXT_TEMP VARCHAR2(1000);

Table altered.

UPDATE joshiv  SET FOOTNOTE_TEXT_temp = DBMS_LOB.SUBSTR (joshiv_TEXT, 1000)
37 rows updated.

ALTER TABLE joshiv DROP COLUMN joshiv_TEXT;
Table altered.
ALTER TABLE joshiv RENAME COLUMN FOOTNOTE_TEXT_TEMP TO joshiv_TEXT;
Table altered.

desc joshiv
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 joshiv_STMT                             NOT NULL VARCHAR2(10 CHAR)
 joshiv_KEY                              NOT NULL VARCHAR2(9 CHAR)
 joshiv_TYPE                                      VARCHAR2(10 CHAR)
 joshiv_TEXT                                      VARCHAR2(1000)