Saturday, July 18, 2020

Steps to Create Oracle Database Manually

The steps involved how to create a database manually. These steps should be followed in the order presented. Before you create the database make sure you have done the planning about the size of the database, number of tablespaces and redo log files you want in the database.

Regarding the size of the database you have to first find out how many tables are going to be created in the database and how much space they will be occupying for the next 1 year or 2. The best thing is to start with some specific size and later on adjust the size depending upon the requirement

Plan the layout of the underlying operating system files your database will comprise. Proper distribution of files can improve database performance dramatically by distributing the I/O during file access. You can distribute I/O in several ways when you install Oracle software and create your database. For example, you can place redo log files on separate disks or use striping. You can situate datafiles to reduce contention. And you can control data density (number of rows to a data block).

Select the standard database block size. This is specified at database creation by the DB_BLOCK_SIZE initialization parameter and cannot be changed after the database is created. For databases, block size of 4K or 8K is widely used

Before you start creating the Database it is best to write down the specification and then proceed

The examples shown in these steps create an example database testdb

Let us create a database testdb with the following specification

Database name and System Identifier

SID=testdb
DB_NAME=testdb

TABLESPACES
-------------------
(we will have 6 tablespaces in this database. With 1 datafile in each tablespace)

Tablespace Name Datafile Location Size
---------------------------------------------------------

SYSTEM /u01/oracle/oradata/test/sys.dbf  500M
USERS /u01/oracle/oradata/test/user.dbf 100M
UNDOTBS /u01/oracle/oradata/test/undo.dbf 100M
TEMP /u01/oracle/oradata/test/temp.dbf 100M
INDEX_DATA /u01/oracle/oradata/test/indx.dbf 100M
SYSAUX /u01/oracle/oradata/test/sysaux.dbf 100M

LOGFILES
--------------

(we will have 2 log groups in the database)
------------------------------------------------

Logfile Group Member Location Size
-------------------------------------------------

GROUP 1 /u01/oracle/oradata/test/log1.ora  10M
GROUP 2 /u01/oracle/oradata/test/log2.ora 10M


CONTROL FILE
---------------------

(We will have 1 Control File in the following location)
--------------------------------------------------------------

/u01/oracle/oradata/test/control.ora

PARAMETER FILE 
------------------------

( use normal parameter file for now, later on we can switch to SPFile)

/u01/oracle/dbs/inittestdb.ora

(remember the parameter file name should of the format init<sid>.ora and it should be in ORACLE_HOME/dbs directory in Unix o/s and ORACLE_HOME/database directory in windows o/s)


Now let us start creating the database.
-------------------------------------------

Step 1: Login to oracle account and make directories for  your database.
--------------------------------------------------------------------

$ mkdir /u01/oracle/oradata/test
$ mkdir /u01/oracle/oradata/test/bdump
$ mkdir /u01/oracle/oradata/test/udump
$ mkdir /u01/oracle/oradata/test/recovery

Step 2: Create the parameter file by copying the default template (init.ora) and set the required parameters
--------------------------------------------------------------------

$ cd /u01/oracle/dbs
$ cp init.ora  inittestdb.ora

        Now open the parameter file and set the following parameters

$ vi inittestdb.ora

DB_NAME=testdb
DB_BLOCK_SIZE=8192
CONTROL_FILES=/u01/oracle/oradata/test/control.ora
UNDO_TABLESPACE=undotbs
UNDO_MANAGEMENT=AUTO
SGA_TARGET=500M
PGA_AGGREGATE_TARGET=100M
LOG_BUFFER=5242880
DB_RECOVERY_FILE_DEST=/u01/oracle/oradata/test/recovery
DB_RECOVERY_FILE_DEST_SIZE=2G

         # The following parameters are required only in 10g or earlier versions

BACKGROUND_DUMP_DEST=/u01/oracle/oradata/test/bdump
USER_DUMP_DEST=/u01/oracle/oradata/test/udump

         After entering the above parameters save the file by pressing    "Esc :wq"

Step 3: Now set ORACLE_SID environment variable and start the instance.
--------------------------------------------------------------------

$ export ORACLE_SID=testdb

$ sqlplus
Enter User: / as sysdba
SQL>startup nomount


Step 4: Give the create database command      
--------------------------------------------------

 I am not specifying optional setting such as language, characterset etc. For these settings oracle will use  
the default values. I am giving the bare minimum command to create the database to keep it simple.

The command to create the database is  

SQL> create database testdb
    datafile ‘/u01/oracle/oradata/test/sys.dbf’ size 500M
    sysaux datafile ‘/u01/oracle/oradata/test/sysaux.dbf’ size 100m
    undo tablespace undotbs
    datafile ‘/u01/oracle/oradata/test/undo.dbf’ size 100m
    default temporary tablespace temp
    tempfile ‘/u01/oracle/oradata/test/tmp.dbf’ size 100m
    logfile
            group 1 ‘/u01/oracle/oradata/test/log1.ora’ size 50m,
            group 2 ‘/u01/oracle/oradata/test/log2.ora’ size 50m;

             After the command finishes you will get the following message

   Database created.

If you are getting any errors then see accompanying messages. If no accompanying messages are shown then
you have to see the alert_testdb.log file located in BACKGROUND_DUMP_DEST directory, which will show the
exact reason why the command has failed. After you have rectified the error please delete all created files in
u01/oracle/oradata/test directory and again give the above command.



Step 5:  above command finishes, the database will get mounted and opened. Now create additional  tablespace
--------------------------------------------------------------------
              

         To create USERS tablespace

SQL> create tablespace users
datafile ‘/u01/oracle/oradata/test/user.dbf’ size 100M;

        To create INDEX_DATA tablespace

SQL>create tablespace index_data
 datafile ‘/u01/oracle/oradata/test/indx.dbf’ size 100M

Step 6:  Populate the database with data dictionaries and to install  procedural options execute the following scripts
--------------------------------------------------------------------
           

        First execute the CATALOG.SQL script to install data dictionaries

 SQL>@/u01/oracle/rdbms/admin/catalog.sql

        The above script will take several minutes. After the above script is finished run the CATPROC.SQL script to install procedural option.

SQL>@/u01/oracle/rdbms/admin/catproc.sql

         This script will also take several minutes to complete.


Step 7: Change the passwords for SYS and SYSTEM account, since the default passwords change on install  known by everybody.
--------------------------------------------------------------------

SQL>alter user sys identified by test123;
SQL>alter user system identified by test123;


Step 8: Create Additional user accounts. 
----------------------------------------------

SQL>create user scott default tablespace users identified by tiger quota 10M on users;
SQL>grant connect to scott;
SQL>create user chaitanya default tablespace users identified by chaitu123 quota 10M on users;
SQL>grant connect to chaitanya;

Step 9: Add this database SID in listener.ora file and restart the listener process.
--------------------------------------------------------------------

$ cd /u01/oracle/network/admin     

$ vi listener.ora

           (This file will already contain sample entries. Copy and paste one sample entry and edit the SID setting)

       LISTENER =
          (DESCRIPTION_LIST =
            (DESCRIPTION =
             (ADDRESS =(PROTOCOL = TCP)(HOST=192.168.100.1)(PORT = 1521))
            )
          )
        SID_LIST_LISTENER =
          (SID_LIST =
            (SID_DESC =
              (SID_NAME = PLSExtProc)
              (ORACLE_HOME =/u01/oracle)
              (PROGRAM = extproc)
            )
                        (SID_DESC =
              (SID_NAME=orcl)
             (ORACLE_HOME=/u01/oracle)
            )
           )



                #Add these lines in SID_LIST_LISTENER at the bottom of file

                         (SID_DESC =
              (SID_NAME=testdb)
             (ORACLE_HOME=/u01/oracle)
            )

                 Save the file by pressing Esc :wq

                 Now restart the listener process.

     $ lsnrctl stop
    $ lsnrctl start

Step 10:  Take a full database backup after you just created the database.
--------------------------------------------------------------------


x

ITIL Process

ITIL Process Introduction In this Blog i am going to explain  ITIL Process, ITIL stands for Information Technology Infrastructure Library ...