vrijdag 25 mei 2012

Create the database manually using OMF (Oracle Managed Files).

Oracle Managed Files simplify the creation of tablespaces. You don’t need to name the datafiles, Oracle does that for you.
You only specify the directories which will contain the tablespaces by configuring the following parameters:

  • DB_CREATE_FILE_DEST: specifies the default location for datafiles and tempfiles
  • DB_CREATE_ONLINE_LOG_DEST_n: specifies the default location for controlfiles and redo log files
  • DB_RECOVERY_FILE_DEST: defines the location for the Fast Recovery Area (used to be called the Flashback Recovery Area in 10g).
    Default location for RMAN backups, flashback logs,archived logs (when no other local destination is configured),
    Also used as the default location for redo logs and control files  or multiplexed copies of redo logs and control files if DB_CREATE_ONLINE_LOG_DEST_n are not specified.

For more information about OMF, check the Administrator’s Guide:  What Are Oracle Managed Files?

Example of parameters to be added to the parameter file:

DB_CREATE_FILE_DEST = '/u02/oradata/ocmdb1'
DB_CREATE_ONLINE_LOG_DEST_1 = '/u02/oradata/ocmdb1'
DB_CREATE_ONLINE_LOG_DEST_2 = '/u03/oradata/ocmdb1'
DB_RECOVERY_FILE_DEST='/u03/oradata/ocmdb1/fast_recovery_area'

Specifying Control Files at Database Creation


If the CONTROL_FILES parameter is not set than the control files are created in the following locations:


In  DB_CREATE_ONLINE_LOG_DEST_n if these parameters are set.
Otherwise in  DB_CREATE_FILE_DEST and/or  DB_RECOVERY_FILE_DEST if they are set.


Specifying Redo Log Files at Database Creation


The LOGFILE clause is not required in the CREATE DATABASE statement, and omitting it provides a simple means of creating Oracle managed redo log files.
The default size for the redo log files is 100 MB.

The redo log file are created In  DB_CREATE_ONLINE_LOG_DEST_n if these parameters are set.
Otherwise in DB_CREATE_FILE_DEST and/or DB_RECOVERY_FILE_DEST if they are set.


Specifying the SYSTEM and SYSAUX Tablespace Datafiles at Database Creation


The DATAFILE or SYSAUX DATAFILE clause is not required in the CREATE DATABASE statement, and omitting it provides a simple means of creating Oracle managed datafiles for the SYSTEM and SYSAUX tablespaces.
If the DATAFILE clause is omitted, then one of the following actions occurs:



  • If DB_CREATE_FILE_DEST is set, then one Oracle managed datafile for the SYSTEM tablespace and another for the SYSAUX tablespace are created in the DB_CREATE_FILE_DEST directory.

  • If DB_CREATE_FILE_DEST is not set, then the database creates one SYSTEM and one SYSAUX tablespace datafile whose names and sizes are operating system dependent.
    Any SYSTEM or SYSAUX tablespace datafile created in this manner is not an Oracle managed file.

The datafiles are created with a size of 100MB and are autoextensible.
You can create OMF files and specify a size instead as well by including the DATAFILE clause, omitting a filename, but specifying overriding attributes.


Specifying the Undo Tablespace Datafile at Database Creation


The DATAFILE subclause of the UNDO TABLESPACE clause is optional and a filename is not required in the file specification.
If a filename is not supplied and the DB_CREATE_FILE_DEST parameter is set, then an Oracle managed datafile is created in the DB_CREATE_FILE_DEST directory.

The UNDO TABLESPACE clause itself is optional in the CREATE DATABASE statement. If it is not supplied, and automatic undo management mode is enabled (the default), then a default undo tablespace named SYS_UNDOTS is created and a 20 MB datafile that is autoextensible is allocated.


Example of creating the database manually using OMF:


Create the password file:


export ORACLE_SID=ocmdb1
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH

orapwd file=$ORACLE_HOME/orapwocmdb1.ora entries=30


Create the parameter file:


cp $ORACLE_HOME/dbs/init.ora $ORACLE_HOME/dbs/initocmdb1.ora


Alter the parameters in this file.


Example:

db_name='OCMDB1'
memory_target=400M
processes = 150
audit_trail ='db'
db_block_size=8192
db_domain='local'
db_recovery_file_dest='/u03/oradata/ocmdb1/flash_recovery_area'
db_recovery_file_dest_size=2G
diagnostic_dest='/u01/app/oracle'
dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDO_TS'
# You may want to ensure that control files are created on separate physical
# devices
# The control_files parameter is not set, thus the control files will be created as Oracle Managed Files
#control_files = (/u01/oradata/ocmdb1/control01.ctl, /u02/oradata/ocmdb1/control02.ctl, /u03/oradata/ocmdb1/control03.ctl)
compatible ='11.2.0'
DB_CREATE_FILE_DEST='/u02/oradata/ocmdb1'
DB_CREATE_ONLINE_LOG_DEST_1='/u01/oradata/ocmdb1'
DB_CREATE_ONLINE_LOG_DEST_2='/u02/oradata/ocmdb1'
DB_CREATE_ONLINE_LOG_DEST_3='/u03/oradata/ocmdb1'


Create the spfile:


[oracle@ORAVM1 dbs]$ sqlplus / as sysdba
SQL> create spfile from pfile;
SQL> exit


Create the database:


[oracle@ORAVM1 dbs]$ sqlplus / as sysdba

SQL> startup mount exclusive restrict   
ORACLE instance started.

Total System Global Area  417546240 bytes
Fixed Size                  2228944 bytes
Variable Size             268438832 bytes
Database Buffers          142606336 bytes
Redo Buffers                4272128 bytes
ORA-00205: error in identifying control file, check alert log for more info

SQL> CREATE DATABASE ocmdb1
EXTENT MANAGEMENT LOCAL
DATAFILE SIZE 400M
SYSAUX DATAFILE SIZE 200M
DEFAULT TEMPORARY TABLESPACE dflt_ts TEMPFILE SIZE 10M
UNDO TABLESPACE undo_ts DATAFILE SIZE 100M;



EXTENT MANAGEMENT LOCAL” is specified to make sure that the SYSTEM tablespace is created locally managed.
If you omit this clause, the system tablespace will be dictionary managed (the default). Oracle advises to create the SYSTEM tablespace as locally managed.


DATAFILE SIZE 400M: if you omit this clause, the SYSTEM datafile wil be created with a size of 100MB and will be autoextensible.

SYSAUX DATAFILE SIZE 200M: you can omit this clause as well. This was specified in order to have a size of 200M (non autoextensible in this example).

DEFAULT TEMPORARY TABLESPACE dflt_ts TEMPFILE SIZE 10M: you can omit this clause to have a default temporary TS created with a size of 20 MB (auto extensible).

UNDO TABLESPACE undo_ts DATAFILE SIZE 100M;   You can omit this clause as well.