Search notes:

Oracle: create a database within a shell

There are basically three ways to create an Oracle database:
This article focuses on the second option. It can be completed on the command line only, that is, without any GUI tool.

Setting ORACLE_HOME

Setting the ORACLE_HOME environment variable to the Oracle home directory.
export ORACLE_BASE=/u01/app/oracle
       ORACLE_COPY=/u02/app/oracle # Used for redundancy of important files

export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/dbhome_1

Setting the Instance's SID

There can be more than one Oracle instance on a single machine.
In order to be able to distinguish these instances, Oracle uses a SID (System Identifier) which is a string.
The SID can be set through the ORACLE_SID environment variables.
export ORACLE_SID=ORA12

Adjusting the PATH variable

Making sure that $PATH contains $ORACLE_HOME/bin:
export PATH=$ORACLE_HOME/bin:$PATH

Creating a password file

orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=1_amRoot

Creating a minimal initialization parameter file

oradatadir_1=$ORACLE_BASE/oradata/$ORACLE_SID
oradatadir_2=$ORACLE_COPY/oradata/$ORACLE_SID

echo "
db_name                    =  $ORACLE_SID         # required
db_block_size              =  8192
db_recovery_file_dest      = '$ORACLE_BASE/fast_recovery_area'
db_recovery_file_dest_size =  2G                  # required if db_recovery_file_dest is specified
memory_target              =  1G
audit_trail                =  db
control_files              = (
     '$oradatadir_1/control.ctl'
   , '$oradatadir_2/control.ctl'
)
" > $ORACLE_HOME/dbs/init$ORACLE_SID.ora
Apparently, the fast_recovery_area directory needs to be created manually:
mkdir $ORACLE_BASE/fast_recovery_area

The create database script

echo "
create database $ORACLE_SID
-- user sys    identified by sys_password
-- user system identified by system_password
   logfile group 1 ('$oradatadir_1/redo01.log'
                 ,  '$oradatadir_2/redo01.log'
                   )                            size 100m blocksize 512,
           group 2 ('$oradatadir_1/redo02.log'
                 ,  '$oradatadir_2/redo02.log'
                   )                            size 100m blocksize 512,
           group 3 ('$oradatadir_1/redo03.log'
                 ,  '$oradatadir_2/redo03.log'
                   )                            size 100m blocksize 512
-- maxloghistory                  1
-- maxlogfiles                   16
-- maxlogmembers                  3
-- maxdatafiles                1024
   character set           al32utf8
   national character set al16utf16
   extent management local               datafile '$oradatadir_1/system_01.dbf'  size 700m reuse autoextend on next    10m maxsize unlimited
   sysaux                                datafile '$oradatadir_1/sysaux_01.dbf'  size 550m reuse autoextend on next    10m maxsize unlimited
   default           tablespace users    datafile '$oradatadir_1/users_01.dbf'   size 500m reuse autoextend on             maxsize unlimited
   user_data         tablespace data     datafile '$oradatadir_1/data_01.dbf'    size 200m reuse autoextend on             maxsize unlimited
   undo              tablespace undo     datafile '$oradatadir_1/undo.dbf'       size 200m reuse autoextend on next    10m maxsize unlimited
   default temporary tablespace temp     tempfile '$oradatadir_1/temp.dbf'       size  20m reuse autoextend on next     1m maxsize unlimited
   ;
" > /tmp/create-db.sql
Apparently, the oradata directory must be created manually:
mkdir -p $oradatadir_1
mkdir -p $oradatadir_2

Starting and connecting to the Oracle instance

sqlplus sys/1_amRoot as sysdba

Hmm??

sqlplus /nolog
SQL>  connect sys/1_amRoot as sysdba
SQL*Plus should confirm with
Connected to an idle instance.
SQL> startup nomount

Executing the create database script

SQL> @/tmp/create-db

Create the data dictionary and dynamic performance views

Still connected as SYSDBA, $ORACLE_HOME/rdbms/admin/catalog.sql will create the data dictionary and dynamic performance views:
SQL> @?/rdbms/admin/catalog.sql

Further scripts

Still connected as SYSDBA:
SQL> @?/rdbms/admin/catproc.sql
SQL> @?/rdbms/admin/utlrp.sql
The next script must be run as SYSTEM:
SQL> connect system/manager
SQL> @?/sqlplus/admin/pupbld.sql

Index