Wednesday, September 29, 2010

Oracle Managed Files

PURPOSE
  This document explains the usage of Oracle Managed Files (OMF files) under
  different configurations.


SCOPE & APPLICATION
  Users of Oracle Managed Files.


OMF (Oracle Managed Files) Usage for Datafiles:
===============================================

You decide to manage your datafiles with OMF.

*** *************************************************
*** Homogeneous Test : tablespace with OMF files only
*** *************************************************

1. In init.ora:
  
      DB_CREATE_FILE_DEST=/oradata/V900SUP

2. Create a tablespace using the OMF syntax:

   SQL> create tablespace omf_domi datafile size 100k;
   Tablespace created.

   SQL> select name from v$datafile;

   NAME
   ------------------------------------------
   ...
   /oradata/V900SUP/ora_omf_domi_xcpsj3tv.dbf       


3. Add a datafile to the tablespace using the OMF syntax:

   SQL> select name from v$datafile;
   NAME
   ------------------------------------------
   ...
   /oradata/V900SUP/ora_omf_domi_xcpsj3tv.dbf
   /oradata/V900SUP/ora_omf_domi_xcpspo63.dbf

   SQL> alter tablespace omf_domi add datafile '/oradata/V900SUP/ora_do03.dbf'
     2  size 100k;
   alter tablespace omf_domi add datafile '/oradata/V900SUP/ora_do03.dbf'
   *
   ERROR at line 1:
   ORA-01276: Cannot add a file with an Oracle Managed Files file name.


4. Add another datafile naming it explicitly:

   SQL> alter tablespace omf_domi add datafile '/oradata/V900SUP/do03.dbf';
   Tablespace altered.


!!! Be cautious: it is strongly recommended NOT to explicitly name the OMF
!!! files. It is likely not to work in the future.


5. Drop the tablespace and check that all datafiles are removed on the
   operating system:

   SQL> drop tablespace omf_domi;
   Tablespace dropped.

   SQL> select name from v$datafile where name like 'ora_omf%';
   no rows selected.

   In alert.log file:

   Deleted Oracle managed file /oradata/V900SUP/ora_omf_domi_xcpsj3tv.dbf
   Deleted Oracle managed file /oradata/V900SUP/ora_omf_domi_xcpspo63.dbf
   Fri Mar 23 16:09:36 2001

   Completed: drop tablespace omf_domi

   $ ls -l /oradata/V900SUP/ora_omf*
   /oradata/V900SUP/ora_omf*: No such file or directory

   $ ls -l /oradata/V900SUP
   -rw-r-----   1 ora901   dba       114688 juin 15 11:30 do03.dbf


*** ***********************************************************************
*** Homogeneous test : tablespace with OMF located in different directories
*** ***********************************************************************

   SQL> create tablespace omf_domi;
   Tablespace created.

   SQL> alter system set db_create_file_dest='/oradata/V900SUP/TEST';
   System altered.

   SQL> alter tablespace omf_domi add datafile;
   Tablespace altered.

   SQL> select name from v$datafile;

   NAME
   -----------------------------------------------
   ...
   /oradata/V900SUP/ora_omf_domi_xcpvst5q.dbf
   /oradata/V900SUP/TEST/ora_omf_domi_xcpvxk0l.dbf

   SQL> drop tablespace omf_domi;
   Tablespace dropped.

   In alert log file:

   Fri Mar 23 16:46:29 2001
   Deleted Oracle managed file /oradata/V900SUP/ora_omf_domi_xcpvst5q.dbf
   Deleted Oracle managed file /oradata/V900SUP/TEST/ora_omf_domi_xcpvxk0l.dbf

   $ ls -l /oradata/V900SUP/ora_omf*
   /oradata/V900SUP/ora_omf*: No such file or directory
   $ ls -l /oradata/V900SUP/TEST/ora_omf*
   /oradata/V900SUP/TEST/ora_omf*: No such file or directory


   All OMF have been correctly removed on the OS.


*** **********************************************************************
*** Heterogeneous test: OMF and non-OMF datafiles within the same database
*** **********************************************************************

1. You leave in the init.ora the DB_CREATE_FILE_DEST parameter.
   You create a new tablespace with datafiles located in another directory than
   the OMF directory:

   SQL> create tablespace omf_domi datafile
     2  '/ora/ora9i/admin/V900SUP/bdump/omf_domi01.dbf' size 100k;

   Tablespace created.

2. Drop the tablespace and check that the datafile is still remaining on the
   operating system.

   SQL> drop tablespace omf_domi;
   Tablespace dropped.

   $ ls  /ora/ora9i/admin/V900SUP/bdump
   omf_domi01.dbf


*** *************************************************************
*** Heterogeneous test: tablespace with OMF and non-OMF datafiles
*** *************************************************************

   SQL> create tablespace omf_domi datafile size 100k;
   Tablespace created.

   SQL> alter tablespace omf_domi
     2  add datafile '/ora/ora9i/admin/V900SUP/bdump/omf_domi02.dbf'
     3  size 100k;

   Tablespace altered.

   SQL> drop tablespace omf_domi;
   Tablespace dropped.

   $ ls /oradata/V900SUP
   => no more files

   $ ls /ora/ora9i/admin/V900SUP/bdump/omf*
   /ora/ora9i/admin/V900SUP/bdump/omf_domi02.dbf


   It is preferrable in this case to use the following command that drops the
   tablespace and related datafiles (OMF and non-OMF):

   SQL> drop tablespace omf_domi including contents and datafiles;
   Tablespace dropped.

   In the alert.log you will see:

   drop tablespace omf_domi including contents and datafiles
   Thu Mar 29 17:09:22 2001
   Deleted Oracle managed file /ora/ora9i/admin/V900SUP/bdump/omf_domi01.dbf
   Deleted file /ora/ora9i/admin/V900SUP/bdump/omf_domi02.dbf
   Completed: drop tablespace omf_domi including contents and datafiles


Explanation:
============

In RDBMS version 9.0.1, we identify OMF files when they are located in the
DB_CREATE_FILE_DEST directory and if the name respects the 'ora_' prefix
and the '.dbf' extension.

Only datafiles created in the DB_CREATE_FILE_DEST directory are automatically
removed from the operating system when dropping a tablespace without the
INCLUDING CONTENTS AND DATAFILES clause. Even if the value of
DB_CREATE_FILE_DEST has changed, the different locations of OMF files are taken
into account.


!!! Please Note:
!!! Be cautious: it is strongly recommended not to explicitly name the OMF
!!! files. It will probably not work successfully in the future.


IMPORTANT NOTE:
===============

Beginning in 9.0.1.2, the naming conventions for OMF files have changed. Please
reference Note: 159888.1 for details of the changes.

Search Words:
=============

ORA-1276


Show Related Information Related
Products

    * Oracle Database Products > Oracle Database > Oracle Database > Oracle Server - Enterprise Edition

Keywords
DB_CREATE_FILE_DEST; OMF
Errors
ORA-1276

Back to topBack to top

Wednesday, September 22, 2010

Useful LINKS

LINUX Commands

Views - Create and manage

Materialised views (creating) in Oracle

Master Index 10g

Master Index 11g 

http://blogs.oracle.com/stevenChan/

TKPROF

Explain Plan and TKprof

DBA Interview Questions

Few Solns for probs and Ans for ques :-)

Cold backup - roll forward archive logs - TESTCASE

this is a test case (ora 9.2.0.6 on solaris 8-64bit), hope it helps
----------------------------------------------------------------------------------
Enter user-name: / as sysdba

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.7.0 - Production

SQL> select name from v$controlfile union
2 select name from v$datafile;

NAME
/opt/oracle/product/ora92/dbatest/control01.ctl
/opt/oracle/product/ora92/dbatest/control02.ctl
/opt/oracle/product/ora92/dbatest/control03.ctl
/opt/oracle/product/ora92/dbatest/cwmlite01.dbf
/opt/oracle/product/ora92/dbatest/drsys01.dbf
/opt/oracle/product/ora92/dbatest/example01.dbf
/opt/oracle/product/ora92/dbatest/indx01.dbf
/opt/oracle/product/ora92/dbatest/odm01.dbf
/opt/oracle/product/ora92/dbatest/system01.dbf
/opt/oracle/product/ora92/dbatest/tools01.dbf
/opt/oracle/product/ora92/dbatest/undotbs01.dbf
/opt/oracle/product/ora92/dbatest/users01.dbf
/opt/oracle/product/ora92/dbatest/xdb01.dbf

13 rows selected.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
-----------------------------------------------------------------------------------------
now lets take a cold backup
$ cp *.dbf ./coldbackup/.
$ cp *.ctl ./coldbackup/.
$ cd coldbakcup
$ ls -ltr
total 1954528
-rw-r--r-- 1 oracle9 dba 20979712 Jun 1 12:26 drsys01.dbf
-rw-r--r-- 1 oracle9 dba 20979712 Jun 1 12:26 cwmlite01.dbf
-rw-r--r-- 1 oracle9 dba 155983872 Jun 1 12:26 example01.dbf
-rw-r--r-- 1 oracle9 dba 20979712 Jun 1 12:26 odm01.dbf
-rw-r--r-- 1 oracle9 dba 26222592 Jun 1 12:26 indx01.dbf
-rw-r--r-- 1 oracle9 dba 419438592 Jun 1 12:26 system01.dbf
-rw-r--r-- 1 oracle9 dba 42999808 Jun 1 12:26 temp01.dbf
-rw-r--r-- 1 oracle9 dba 10493952 Jun 1 12:26 tools01.dbf
-rw-r--r-- 1 oracle9 dba 209723392 Jun 1 12:26 undotbs01.dbf
-rw-r--r-- 1 oracle9 dba 26222592 Jun 1 12:26 users01.dbf
-rw-r--r-- 1 oracle9 dba 39985152 Jun 1 12:26 xdb01.dbf
-rw-r----- 1 oracle9 dba 2023424 Jun 1 12:27 control01.ctl
-rw-r----- 1 oracle9 dba 2023424 Jun 1 12:27 control03.ctl
-rw-r----- 1 oracle9 dba
---------------------------------------------------------------------------------
now lets create a table and insert some rows

SQL> startup
ORACLE instance started.

SQL> create table test (counter number(10));

Table created.

SQL> insert into test
2 select rownum from all_objects where rownum between &1 and &2
3 /
Enter value for 1: 1
Enter value for 2: 100
old 2: select rownum from all_objects where rownum between &1 and &2
new 2: select rownum from all_objects where rownum between 1 and 100

100 rows created.

SQL> commit;

Commit complete.
------------------------------------------------------------------------------------------------
SQL> alter system switch logfile;

System altered.
------------------------------------------------------------------------------------------------
SQL> insert into test select rownum from all_objects where rownum between &1 and &2
2 /
Enter value for 1: 1
Enter value for 2: 10
old 1: insert into test select rownum from all_objects where rownum between &1 and &2
new 1: insert into test select rownum from all_objects where rownum between 1 and 10

10 rows created.

SQL> commit;

Commit complete.

SQL> select count(*) from test;

COUNT(*)
110
--------------------------------------------------------------------------------------------
SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> /

System altered.
-------------------------------------------------------------------------------------------------------------
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down. 2023424 Jun 1 12:27 control02.ctl
$
-----------------------------------------------------------------------------------------------------------

Now lets delete all data/controlfile/logfiles from current location and restore from cold backup

$ rm *.dbf *.log *.ctl

$ cd coldbackup
$ cp * ../.
$ ls -ltr
total 1954528
-rw-r--r-- 1 oracle9 dba 20979712 Jun 1 12:26 drsys01.dbf
-rw-r--r-- 1 oracle9 dba 20979712 Jun 1 12:26 cwmlite01.dbf
-rw-r--r-- 1 oracle9 dba 155983872 Jun 1 12:26 example01.dbf
-rw-r--r-- 1 oracle9 dba 20979712 Jun 1 12:26 odm01.dbf
-rw-r--r-- 1 oracle9 dba 26222592 Jun 1 12:26 indx01.dbf
-rw-r--r-- 1 oracle9 dba 419438592 Jun 1 12:26 system01.dbf
-rw-r--r-- 1 oracle9 dba 42999808 Jun 1 12:26 temp01.dbf
-rw-r--r-- 1 oracle9 dba 10493952 Jun 1 12:26 tools01.dbf
-rw-r--r-- 1 oracle9 dba 209723392 Jun 1 12:26 undotbs01.dbf
-rw-r--r-- 1 oracle9 dba 26222592 Jun 1 12:26 users01.dbf
-rw-r--r-- 1 oracle9 dba 39985152 Jun 1 12:26 xdb01.dbf
-rw-r----- 1 oracle9 dba 2023424 Jun 1 12:27 control01.ctl
-rw-r----- 1 oracle9 dba 2023424 Jun 1 12:27 control03.ctl
-rw-r----- 1 oracle9 dba 2023424 Jun 1 12:27 control02.ctl

-----------------------------------------------------------------------------------------------
$ sqlplus

SQL*Plus: Release 9.2.0.7.0 - Production on Fri Jun 1 12:32:47 2007

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Enter user-name: / as sysdba
Connected to an idle instance.

SQL> startup mount;
ORACLE instance started.

Total System Global Area 320308936 bytes
Fixed Size 730824 bytes
Variable Size 285212672 bytes
Database Buffers 33554432 bytes
Redo Buffers 811008 bytes
Database mounted.

SQL> RESTORE DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL;

SP2-0734: unknown command beginning "RESTORE DA..." - rest of line ignored.
SQL>
SQL> restore database using backup controlfile until cancel;
SP2-0734: unknown command beginning "restore da..." - rest of line ignored.
SQL>
SQL>
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 166115 generated at 06/01/2007 12:25:37 needed for thread 1
ORA-00289: suggestion :
/opt/oracle/product/ora92/oradata/dbatest/archive/1_7.dbf
ORA-00280: change 166115 for thread 1 is in sequence #7

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

ORA-00279: change 166232 generated at 06/01/2007 12:28:32 needed for thread 1
ORA-00289: suggestion :
/opt/oracle/product/ora92/oradata/dbatest/archive/1_8.dbf
ORA-00280: change 166232 for thread 1 is in sequence #8
ORA-00278: log file '/opt/oracle/product/ora92/oradata/dbatest/archive/1_7.dbf'
no longer needed for this recovery

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

ORA-00279: change 166342 generated at 06/01/2007 12:29:35 needed for thread 1
ORA-00289: suggestion :
/opt/oracle/product/ora92/oradata/dbatest/archive/1_9.dbf
ORA-00280: change 166342 for thread 1 is in sequence #9
ORA-00278: log file '/opt/oracle/product/ora92/oradata/dbatest/archive/1_8.dbf'
no longer needed for this recovery

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

ORA-00279: change 166408 generated at 06/01/2007 12:29:38 needed for thread 1
ORA-00289: suggestion :
/opt/oracle/product/ora92/oradata/dbatest/archive/1_10.dbf
ORA-00280: change 166408 for thread 1 is in sequence #10
ORA-00278: log file '/opt/oracle/product/ora92/oradata/dbatest/archive/1_9.dbf'
no longer needed for this recovery

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

ORA-00279: change 166410 generated at 06/01/2007 12:29:39 needed for thread 1
ORA-00289: suggestion :
/opt/oracle/product/ora92/oradata/dbatest/archive/1_11.dbf
ORA-00280: change 166410 for thread 1 is in sequence #11
ORA-00278: log file
'/opt/oracle/product/ora92/oradata/dbatest/archive/1_10.dbf' no longer needed
for this recovery

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

ORA-00308: cannot open archived log
'/opt/oracle/product/ora92/oradata/dbatest/archive/1_11.dbf'
ORA-27037: unable to obtain file status
SVR4 Error: 2: No such file or directory
Additional information: 3

SQL> ALTER DATABASE OPEN RESETLOGS;

Database altered.

SQL> SELECT COUNT(*) FROM TEST;

COUNT(*)
110

so i get backup my 110 rows