Monday, October 11, 2010

ORA-04043 on DBA_* Views if they are described while database is mount stage

Problem Description
Whenever you issue describe command or do any query on a DBA_* views it fails with ORA-04043. Amazing but it is true and another terrible scenario of oracle. For example,
SQL> desc dba_data_files
ERROR:
ORA-04043: object dba_data_files does not exist


SQL> desc dba_tablespaces;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------

 TABLESPACE_NAME                           NOT NULL VARCHAR2(30)
 BLOCK_SIZE                                NOT NULL NUMBER
 INITIAL_EXTENT                                     NUMBER
 NEXT_EXTENT                                        NUMBER
 MIN_EXTENTS                               NOT NULL NUMBER
 MAX_EXTENTS                                        NUMBER
 PCT_INCREASE                                       NUMBER
 MIN_EXTLEN                                         NUMBER
 STATUS                                             VARCHAR2(9)
 CONTENTS                                           VARCHAR2(9)
 LOGGING                                            VARCHAR2(9)
 FORCE_LOGGING                                      VARCHAR2(3)
 EXTENT_MANAGEMENT                                  VARCHAR2(10)
 ALLOCATION_TYPE                                    VARCHAR2(9)
 PLUGGED_IN                                         VARCHAR2(3)
 SEGMENT_SPACE_MANAGEMENT                           VARCHAR2(6)
 DEF_TAB_COMPRESSION                                VARCHAR2(8)
 RETENTION                                          VARCHAR2(11)
 BIGFILE                                            VARCHAR2(3)

SQL> desc dba_temp_files
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------

 FILE_NAME                                          VARCHAR2(513)
 FILE_ID                                            NUMBER
 TABLESPACE_NAME                           NOT NULL VARCHAR2(30)
 BYTES                                              NUMBER
 BLOCKS                                             NUMBER
 STATUS                                             CHAR(9)
 RELATIVE_FNO                                       NUMBER
 AUTOEXTENSIBLE                                     VARCHAR2(3)
 MAXBYTES                                           NUMBER
 MAXBLOCKS                                          NUMBER
 INCREMENT_BY                                       NUMBER
 USER_BYTES                                         NUMBER
 USER_BLOCKS                                        NUMBER


Though database is open but still it does not show dba_data_files view.
SQL> select open_mode from v$database;

OPEN_MODE
----------
READ WRITE

SQL> desc dba_data_files;
ERROR:
ORA-04043: object dba_data_files does not exist
Moreover whenever you try to compile the dba_data_files view it fails with error ORA-00001: unique constraint (SYS.I_OBJ2) violated like below.
SQL> alter view dba_data_files compile;
alter view dba_data_files compile
                                *
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-00001: unique constraint (SYS.I_OBJ2) violated
Cause and Investigation of the Problem
The problem is happened due to Oracle bug. ORA-4043 raised on DBA_* tables if those views are described in mount stage. This is same if you issue "desc dba_*" while database is being opened.

You can easily reproduce the problem.
Step 01: Shut down the database.
SQL> shut immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
Step 02: Start the database in mount stage.
SQL> startup mount
ORACLE instance started.

Total System Global Area  314572800 bytes
Fixed Size                  1290328 bytes
Variable Size             205524904 bytes
Database Buffers          100663296 bytes
Redo Buffers                7094272 bytes
Database mounted.
Step 03: Describe one or any DBA_* views.
SQL> desc dba_data_files
ERROR:
ORA-04043: object dba_data_files does not exist
Step 04: Open the database.
SQL> alter database open;

Database altered.
Step 05: Describe the same DBA_* view.
SQL> desc dba_data_files
ERROR:
ORA-04043: object dba_data_files does not exist

Compile the view also raise ORA-00001.
SQL> alter view dba_data_files compile;
alter view dba_data_files compile
                                *
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-00001: unique constraint (SYS.I_OBJ2) violated
Solution of the Problem
Solution 01: Flush the shared pool and reissue the same statement.
SQL> alter system flush shared_pool;

System altered.

SQL> desc dba_data_files
 Name                                      Null?    Type
 ----------------------------------------- -------- -------------------------

 FILE_NAME                                          VARCHAR2(513)
 FILE_ID                                            NUMBER
 TABLESPACE_NAME                                    VARCHAR2(30)
 BYTES                                              NUMBER
 BLOCKS                                             NUMBER
 STATUS                                             VARCHAR2(9)
 RELATIVE_FNO                                       NUMBER
 AUTOEXTENSIBLE                                     VARCHAR2(3)
 MAXBYTES                                           NUMBER
 MAXBLOCKS                                          NUMBER
 INCREMENT_BY                                       NUMBER
 USER_BYTES                                         NUMBER
 USER_BLOCKS                                        NUMBER
 ONLINE_STATUS                                      VARCHAR2(7)
Solution 02: Don't describe the dba_* views at mount stage.

Solution 03: Shutdown and restart instance and don't desc any dba_* views while database is being mounted or opened.

No comments: