Storage: Cookbook Oracle using raw partitions

This document describes the steps to create an Oracle database using raw file systems for the Oracle files. The following cookbook was created using VM-Ware.

Create a partition to hold Raw Devices

The first thing need to be done is to create a partition on the SCSI-harddisk. In this cookbook, the Raw Devices will be created on the third SCSI disk (sdc)

 

fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/sdc: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Command (m for help):

 

With the p-command, the existing partitions will be showed. At this point we don’t have any partitions on /sdc. Press n to create a partition in fdisk

 

Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 1
First cylinder (1-522, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522):
Using default value 522

Command (m for help): p

Disk /dev/sdc: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot    Start       End       Blocks      Id   System
/dev/sdc1          1       522     4192933+       5   Extended

 

Create partition to house Redo Log Group 1

The Oracle database will use 2 groups of Redo Log files both 100Mb. To be sure the Redo Log files will fit, the partition is created a little bigger as necessary (105Mb).

 

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1-522, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522): +105M

Command (m for help): p

Disk /dev/sdc: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot    Start       End       Blocks      Id   System
/dev/sdc1          1       522     4192933+       5   Extended
/dev/sdc5          1        14      112392       83   Linux


 

Create partition to house Redo Log Group 2

This will look exact the same as the partition created in the previous step:

 

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (15-522, default 15):
Using default value 15
Last cylinder or +size or +sizeM or +sizeK (15-522, default 522): +105m

Command (m for help): p

Disk /dev/sdc: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot    Start       End       Blocks      Id   System
/dev/sdc1          1       522     4192933+       5   Extended
/dev/sdc5          1        14      112392       83   Linux
/dev/sdc6         15        28      112423+      83   Linux

 

Create partition to house SYSTEM data file

The system data file will be 750Mb. The size of the partition will be 760Mb to be sure it will fit.

 

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (29-522, default 29):
Using default value 29
Last cylinder or +size or +sizeM or +sizeK (29-522, default 522): +760M

Command (m for help): p

Disk /dev/sdc: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot    Start       End       Blocks      Id   System
/dev/sdc1          1       522     4192933+       5   Extended
/dev/sdc5          1        14      112392       83   Linux
/dev/sdc6         15        28      112423+      83   Linux
/dev/sdc7         29       121      746991       83   Linux

 

Create partition to house SYSAUX data file

The sysaux data file will be 300Mb. The size of the partition will be 310Mb to be sure it will fit.

 

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (122-522, default 122):
Using default value 122
Last cylinder or +size or +sizeM or +sizeK (122-522, default 522): +310M

Command (m for help): p

Disk /dev/sdc: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot    Start       End       Blocks      Id   System
/dev/sdc1          1       522     4192933+       5   Extended
/dev/sdc5          1        14      112392       83   Linux
/dev/sdc6         15        28      112423+      83   Linux
/dev/sdc7         29       121      746991       83   Linux
/dev/sdc8        122       160      313236       83   Linux

 

Create partition to house USERS data file

The users data file will be 100Mb. The size of the partition will be 105Mb.

 

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (161-522, default 161):
Using default value 161
Last cylinder or +size or +sizeM or +sizeK (161-522, default 522): +105M

Command (m for help): p

Disk /dev/sdc: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot    Start       End       Blocks      Id   System
/dev/sdc1          1       522     4192933+       5   Extended
/dev/sdc5          1        14      112392       83   Linux
/dev/sdc6         15        28      112423+      83   Linux
/dev/sdc7         29       121      746991       83   Linux
/dev/sdc8        122       160      313236       83   Linux
/dev/sdc9        161       174      112423+      83   Linux

 

Create partition to house the TOOLS data file

The tools data file will be 100Mb. The size of the partition will be 105Mb.

 
 

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (175-522, default 175):
Using default value 175
Last cylinder or +size or +sizeM or +sizeK (175-522, default 522): +105M

Command (m for help): p

Disk /dev/sdc: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot    Start       End       Blocks      Id   System
/dev/sdc1          1       522     4192933+       5   Extended
/dev/sdc5          1        14      112392       83   Linux
/dev/sdc6         15        28      112423+      83   Linux
/dev/sdc7         29       121      746991       83   Linux
/dev/sdc8        122       160      313236       83   Linux
/dev/sdc9        161       174      112423+      83   Linux
/dev/sdc10       175       188      112423+      83   Linux

 

Create partition to house the TEMP temp file

The temp file will be 100Mb. The size of the partition will be 105Mb.

 

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (189-522, default 189):
Using default value 189
Last cylinder or +size or +sizeM or +sizeK (189-522, default 522): +105M

Command (m for help): p

Disk /dev/sdc: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot    Start       End       Blocks      Id   System
/dev/sdc1          1       522     4192933+       5   Extended
/dev/sdc5          1        14      112392       83   Linux
/dev/sdc6         15        28      112423+      83   Linux
/dev/sdc7         29       121      746991       83   Linux
/dev/sdc8        122       160      313236       83   Linux
/dev/sdc9        161       174      112423+      83   Linux
/dev/sdc10       175       188      112423+      83   Linux
/dev/sdc11       189       202      112423+      83   Linux

 

Create partition to house UNDO data file

The undo data file will be 100Mb. The size of the partition will be 105Mb.

 

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (203-522, default 203):
Using default value 203
Last cylinder or +size or +sizeM or +sizeK (203-522, default 522): +105M

Command (m for help): p

Disk /dev/sdc: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot    Start       End       Blocks      Id   System
/dev/sdc1          1       522     4192933+       5   Extended
/dev/sdc5          1        14      112392       83   Linux
/dev/sdc6         15        28      112423+      83   Linux
/dev/sdc7         29       121      746991       83   Linux
/dev/sdc8        122       160      313236       83   Linux
/dev/sdc9        161       174      112423+      83   Linux
/dev/sdc10       175       188      112423+      83   Linux
/dev/sdc11       189       202      112423+      83   Linux
/dev/sdc12       203       216      112423+      83   Linux

 

Create partition to house Controlfile

For this test database, only one Controlfile is used. A partition of 50M is created for the Controlfile.

 

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (203-522, default 203):
Using default value 203
Last cylinder or +size or +sizeM or +sizeK (203-522, default 522): +105M

Command (m for help): p

Disk /dev/sdc: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot    Start       End       Blocks      Id   System
/dev/sdc1          1       522     4192933+       5   Extended
/dev/sdc5          1        14      112392       83   Linux
/dev/sdc6         15        28      112423+      83   Linux
/dev/sdc7         29       121      746991       83   Linux
/dev/sdc8        122       160      313236       83   Linux
/dev/sdc9        161       174      112423+      83   Linux
/dev/sdc10       175       188      112423+      83   Linux
/dev/sdc11       189       202      112423+      83   Linux
/dev/sdc12       203       216      112423+      83   Linux

 

Write partition information to disk

Although the Partition are created, the information is not written to disk yet. To apply the changes, press w to write the changes to disk

 

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

 

Binding the newly created Raw devices

In this step the Raw devices are binded. Binding Raw devices can be done with the raw-command:

 

raw /dev/raw/raw1 /dev/sdc5
/dev/raw/raw1: bound to major 8, minor 37

raw /dev/raw/raw2 /dev/sdc6
/dev/raw/raw2: bound to major 8, minor 38

raw /dev/raw/raw3 /dev/sdc7
/dev/raw/raw3: bound to major 8, minor 39

raw /dev/raw/raw4 /dev/sdc8
/dev/raw/raw4: bound to major 8, minor 40

raw /dev/raw/raw5 /dev/sdc9
/dev/raw/raw5: bound to major 8, minor 41

raw /dev/raw/raw6 /dev/sdc10
/dev/raw/raw6: bound to major 8, minor 42

raw /dev/raw/raw7 /dev/sdc11
/dev/raw/raw7: bound to major 8, minor 43

raw /dev/raw/raw8 /dev/sdc12
/dev/raw/raw8: bound to major 8, minor 44

raw /dev/raw/raw8 /dev/sdc13
/dev/raw/raw8: bound to major 8, minor 45

 

Add Binding information to /etc/sysconfig/rawdevices

To automatically bind the Raw devices at system boot, the binding information must be added to the file /etc/sysconfig/rawdevices

 

# This file and interface are deprecated.
# Applications needing raw device access should open regular
# block devices with O_DIRECT.
# raw device bindings
# format : <rawdev> <major> <minor>
#          <rawdev> <blockdev>
# example: /dev/raw/raw1 /dev/sda1
#          /dev/raw/raw2 8 5

/dev/raw/raw1 /dev/sdc5
/dev/raw/raw2 /dev/sdc6
/dev/raw/raw3 /dev/sdc7
/dev/raw/raw4 /dev/sdc8
/dev/raw/raw5 /dev/sdc9
/dev/raw/raw6 /dev/sdc10
/dev/raw/raw7 /dev/sdc11
/dev/raw/raw8 /dev/sdc12
/dev/raw/raw9 /dev/sdc13

 

The binding can be reviewed by looking at the /dev/raw directory:

 

[root@lx01 dev]# cd /dev/raw
[root@lx01 raw]# ls -ltr
total 0
crw-rw---- 1 root disk 162, 1 May 11 09:23 raw1
crw-rw---- 1 root disk 162, 2 May 11 09:23 raw2
crw-rw---- 1 root disk 162, 3 May 11 09:23 raw3
crw-rw---- 1 root disk 162, 4 May 11 09:23 raw4
crw-rw---- 1 root disk 162, 5 May 11 09:24 raw5
crw-rw---- 1 root disk 162, 6 May 11 09:24 raw6
crw-rw---- 1 root disk 162, 7 May 11 09:24 raw7
crw-rw---- 1 root disk 162, 8 May 11 09:24 raw8
crw-rw---- 1 root disk 162, 8 May 11 09:24 raw9

 

Changing the permissions on the Raw devices

As shown in the previous step, the Raw devices are owned by root. With the chown-command, the ownership and group must be changed to oracle:dba

 

[root@lx01 raw]# chown oracle:dba raw*
[root@lx01 raw]# ls -ltr
total 0
crw-rw---- 1 oracle dba 162, 1 May 11 09:23 raw1
crw-rw---- 1 oracle dba 162, 2 May 11 09:23 raw2
crw-rw---- 1 oracle dba 162, 3 May 11 09:23 raw3
crw-rw---- 1 oracle dba 162, 4 May 11 09:23 raw4
crw-rw---- 1 oracle dba 162, 5 May 11 09:24 raw5
crw-rw---- 1 oracle dba 162, 6 May 11 09:24 raw6
crw-rw---- 1 oracle dba 162, 7 May 11 09:24 raw7
crw-rw---- 1 oracle dba 162, 8 May 11 09:24 raw8
crw-rw---- 1 oracle dba 162, 8 May 11 09:24 raw9

 

Change ownership Raw devices after system-boot

Every time the system is booted, the owner and group of the Raw devices (raw1 through raw9) are changed back to root. To automatically change these permissions after a system-boot, the chown-command should be added to the /etc/rc.local file:

 

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

# Change the Ownership of the Raw devices every time the system is booted
chown oracle:dba /dev/raw/raw*

 

Adding Environment variabled to .bash_profile of the oracle user

Before creating the database, some environment variables must be added to the profile:

• ORACLE_BASE
• ORACLE_HOME
• ORACLE_SID

 

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME

export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=/u01/oracle/product/10.2.0/rdbms
export ORACLE_SID=TST

export PATH=$ORACLE_HOME/bin:$PATH

 

To effect the changes, log out and log in again as oracle

 

Create the admin-tree for administration of the database

In this step the directory in which Oracle stores administrative files, are created

 

[root@lx01 raw]# su - oracle
[oracle@lx01 ~]$ vi .bash_profile
[oracle@lx01 ~]$ id
uid=80(oracle) gid=80(dba) groups=80(dba),100(users)
[oracle@lx01 ~]$
[oracle@lx01 ~]$
[oracle@lx01 ~]$ su - oracle
Password:
[oracle@lx01 ~]$ cd $ORACLE_BASE
[oracle@lx01 oracle]$ pwd
/u01/oracle
[oracle@lx01 oracle]$ mkdir admin
[oracle@lx01 oracle]$ cd admin
[oracle@lx01 admin]$ mkdir $ORACLE_SID
[oracle@lx01 admin]$ ls
TST
[oracle@lx01 admin]$ cd TST
[oracle@lx01 TST]$ mkdir bdump
[oracle@lx01 TST]$ mkdir cdump
[oracle@lx01 TST]$ mkdir udump
[oracle@lx01 TST]$

 

Create the PFILE for the database in $ORACLE_HOME/dbs

In the $ORACLE_HOME/dbs directory, the PFILE must be created for the database. Later this pfile can be used to create the SPFILE.

 

[oracle@lx01 dbs]$ cat initTST.ora
db_name=TST
control_files = (/dev/raw/raw9)
background_dump_dest=/u01/oracle/admin/TST/bdump
core_dump_dest=/u01/oracle/admin/TST/cdump
user_dump_dest=/u01/oracle/admin/TST/udump
undo_management=AUTO
undo_tablespace=UNDOTBS

#optional parameters
open_cursors=300
processes=150
sga_target=262144000
pga_aggregate_target=131072000

 

Create the password file for the database

A password file must be created in the $ORACLE_HOME/dbs directory:

 

[oracle@lx01 dbs]$ orapwd file=orapwTST password=manager
[oracle@lx01 dbs]$ ls -ltr
total 36
-rw-r----- 1 oracle dba 8385 Sep 11 1998 init.ora
-rw-r----- 1 oracle dba 12920 May 3 2001 initdw.ora
-rw-r--r-- 1 oracle dba 225 May 11 09:42 initTST.ora
-rw-r----- 1 oracle dba 1536 May 11 09:42 orapwTST

 

Start the Oracle instance

Make sure the ORACLE_HOME and ORACLE_SID environment variables are set. Log in as the oracle unix user, start SQL*Plus en start the instance in nomount:

 

[oracle@lx01 dbs]$ echo $ORACLE_HOME
/u01/oracle/product/10.2.0/rdbms
[oracle@lx01 dbs]$ echo $ORACLE_SID
TST
[oracle@lx01 create]$ sqlplus

SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 11 09:47:59 2007

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

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

SQL> startup nomount
ORACLE instance started.

Total System Global Area     113246208 bytes
Fixed Size                     1218004 bytes
Variable Size                 58722860 bytes
Database Buffers              50331648 bytes
Redo Buffers                   2973696 bytes

 

Create the Oracle Database

In this step, the Oracle database will be created. Instead of using a cooked file system for the data files, the Raw devices are used.

 

SQL> CREATE DATABASE TST
        MAXLOGFILES 255
        MAXINSTANCES 1
        MAXDATAFILES 256
        MAXLOGHISTORY 256
        DATAFILE '/dev/raw/raw3' SIZE 500M REUSE
        UNDO TABLESPACE "UNDOTBS" DATAFILE '/dev/raw/raw8'
        SIZE 50M REUSE
        DEFAULT TABLESPACE USER_DEFAULT DATAFILE '/dev/raw/raw5' size 75m REUSE
        SYSAUX DATAFILE '/dev/raw/raw4' size 250M
        CHARACTER SET US7ASCII
        LOGFILE GROUP 1 ('/dev/raw/raw1') SIZE 75M REUSE,
                GROUP 2 ('/dev/raw/raw2') SIZE 75M REUSE;

Database created.

 

Create the temporary tablespace

In Oracle10g the temporary tablespace consists of temp files in stead of the ordinary data files. The temporary tablespace can be created with the following command:

 

SQL> create temporary tablespace "TEMP" tempfile '/dev/raw/raw7' size 100m
reuse extent management local ;

Tablespace created.

SQL> alter database default temporary tablespace "TEMP";

Database altered.

 

Running necessary data dictionary scripts to create views, synonyms etc

After the database has been created, catalog.sql and catproc.sql must be executed. These files are located in $ORACLE_HOME/rdbms/admin

 

SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 11 10:31:17 2007

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

Enter user-name: /as sysdba

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> @catalog

...

SQL> @catproc

 

Create SPFILE from current PFILE

Oracle advises to use a SPFILE in stead of an ordinary PFILE. With the following command the SPFILE can be created:

 

[oracle@lx01 admin]$ cd $ORACLE_HOME/dbs
[oracle@lx01 dbs]$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 11 10:50:42 2007

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


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> shutdown immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> create spfile from pfile='initTST.ora' ;

File created.

SQL> startup
ORACLE instance started.

Total System Global Area 264241152 bytes
Fixed Size 1218868 bytes
Variable Size 88082124 bytes
Database Buffers 171966464 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL> show parameter spfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- -------------------------------------------------
spfile                               string      /u01/oracle/product/10.2.0/rdbms/dbs/spfileTST.ora

 

Execute the ‘show parameter spfile’-command in SQL*Plus to check whether the SPFILE is used.

 

Adding tablespace TOOLS

 

SQL> create tablespace "TOOLS" datafile '/dev/raw/raw6' size 100m
reuse extent management local ;

Tablespace created.

 

Querying DBA_DATA_FILES, V$CONTROLFILE and V$LOGFILE

 

SQL> select file_name, bytes/1024/1024 Mb from dba_data_files ;

FILE_NAME MB
-------------------- ----------
/dev/raw/raw3 500
/dev/raw/raw8 50
/dev/raw/raw4 250
/dev/raw/raw5 75
/dev/raw/raw6 100

SQL> select name from v$controlfile;

NAME
--------------------
/dev/raw/raw9

SQL> select member from v$logfile ;

MEMBER
--------------------
/dev/raw/raw1
/dev/raw/raw2

 

References:

1. Raw devices on Linux; Oracle Metalink Note 224302.1
2. 10g Manual Database Creation in Oracle; Oracle Metalink Note 240052.1

 

Auteur: Edwin Kessels (edwin.kessels@keed.nl) Copyright © 2007 Keed