You are on page 1of 73

Installation of oracle database 11g (11.2.0.

1)
Using DBCA (Database Configuration Assistant)
Installation of Oracle Database using Database Configuration Assistant.

Hardware Configuration
Host Machine Configuration:
Machine name (hostname) : ora11g.home.com
IP address : 10.0.2.15
Machine Architecture : Oracle Linux 5.5 (x86)
Memory ( RAM) :1.6 GB
Environment : Virtual ( Oracle Virtual machine 4.3)
Physical Disks:
Hard Drive Partition Size (MB) Type Mount point
/dev/sda /dev/sda1 5120 Swap
/dev/sda2 40960 primary /

Oracle Configuration:
Oracle User/groups:
O/S user Primary Group Secondary Groups Home directory
Oracle oinstall dba, oper /home/oracle

Oracle Software Components:


Software Component Version
Oracle Database Oracle Database 11g Release 2 (11.2.0.1) for
Linux x86

Oracle Database:
Software Component Database name Global database name
Oracle Database ora11g ora11g.home.com

Oracle Software Paths:


Description Path
Oracle base /u01/app/oracle
Oracle home /u01/app/oracle/product/11.2.0/db_home_1

Pre Installation
Prerequisite checks:
Component Command Description
Physical Ram #grep MemTotal /proc/meminfo Oracle needs minimum of 1GB
ram so we have 1.6 GB
Swap space #grep SwapTotal /proc/meminfo As per oracle documentation
ram up to 2GB needs swap
space= 2*ram
Ram up to 8 GB needs swap
space = ram
ram > 8GB swap space =
0.75*ram
So in our case we have 5GB
Temp space #df h /temp Oracle installation needs 400
MB of temp space as we have
40 GB
Oracle installation #df h /u01 Space requirement for Oracle
space Software:
Enterprise Edition 2.5G
Standard Edition 2.3G
Custom (max) 3G
So in our case we have 40 GB

Configuring Operating System for oracle Installation


Network Configuration:
For oracle installation a static ip address is assigned and a fully qualified name is given by
editing file /etc/hosts as:
127.0.0.1 localhost.localdomain localhost
10.0.2.15 ora11g.home.com ora11g

Kernel Parameters:
Oracle Database 11g Release 2 for Linux requires the kernel parameter settings shown below as
per the oracle documentation:
kernel.shmmax = 4294967295
kernel.shmall = 2097152
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.file-max = 6815744
fs.aio-max-nr = 1048576
Above parameters are to be amended by editing file /etc/sysctl.conf. With amending of the above
parameters in file the kernel should be reloaded as by issuing command:
#sysctl p
Resource Limits:
As per to improve the performance of the oracle software and database the resource limits of the
o/s must be edited.
The shell limits for the user Oracle are set as per Oracle by editing file /etc/security/limits.conf
as:
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
Where "nproc" is the maximum number of processes available to the user and "nofiles" is the
number of open file descriptors.
The following line to the /etc/pam.d/login file need to be appended, if it does not already exist.
session required pam_limits.so
Required rpm packages:
The Oracle Universal Installer (OUI) performs checks on the machine during installation to
verify that it meets the appropriate operating system package requirements. To ensure that these
checks complete successfully, the software requirements to install before starting the Oracle
install are:
binutils-2.17.50.0.6
compat-libstdc++-33-3.2.3
elfutils-libelf-0.125
elfutils-libelf-devel-0.125
elfutils-libelf-devel-static-0.125
gcc-4.1.2
gcc-c++-4.1.2
glibc-2.5-24
glibc-common-2.5
glibc-devel-2.52
glibc-headers-2.5
kernel-headers-2.6.18
ksh-20060214
libaio-0.3.106
libaio-devel-0.3.106
libgcc-4.1.2
libgomp-4.1.2
libstdc++-4.1.2
libstdc++-devel-4.1.2
make-3.81
pdksh-5.2.14
sysstat-7.0.2
unixODBC-2.2.11
unixODBC-devel-2.2.11

Installed the rpm packages as:


# yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel glibc glibc-
common glibc-devel gcc gcc-c++ libaio libaio-devel libgcc libstdc++ libstdc++-devel make
sysstat unixODBC unixODBC-devel
User and Directories
Created the recommended OS groups and user for the Oracle Database software
/usr/sbin/groupadd oinstall
/usr/sbin/groupadd dba
/usr/sbin/groupadd oper
/usr/sbin/useradd -m -u 501 -g oinstall -G dba,oper oracle
/usr/bin/passwd oracle

Created directories and changed permissions as:


mkdir -p /u01/app/oracle/product/10.2.0/db_1
chown -R oracle:oinstall /u01
chmod -R 775 /u01

Environmental Variables:
The environmental variables for the oracle Database are set as editing the file .bash_profile as :
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR

ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE


ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_home1; export ORACLE_HOME
ORACLE_SID=ora11g; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;
export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;
export CLASSPATH

if [ $USER = "oracle" ]; then


if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
Now run the following command to make these changes effective in the current session of user
oracle.
source ~/.bash_profile
Installation of oracle Software:
The environment is ready for oracle installation. So for oracle DBMS installation the zip file is
unzipped as below:
unzip .....database_linux32.zip
When unzip is finished the directory is changed to "database" and the Oracle Universal Installer
is started.
cd ..... /database/
./runInstaller
The snapshots For installation of oracle software only is:

Welcome window:
Choose security updates window:
Select the installation type:
Select the Grid type:
Select the product languages:
Select the installation type:
Specify the oracle base and oracle home directories:
Specify the directory for Inventory:
Supply the privilege operating system groups:
Prerequisite check:

Summary of the oracle software installation:


Install Procuct:
Execute the scripts as root user:
Successfully installed the database software:
Configuration of Oracle listener:

Issue the command netca in terminal window and select the listener configuration button

Select the add button as:


Specify the name of the listener as:

Specify the protocols for the net listener:


Specify the port for the Listener

Specify the Key for the ipc:


With successful configuration close the net configuration assistant:
Installation the database software as:
Issue the command dbca in terminal window as:

Select the create database radio button as:

Select the type of database to install:


Specify the oracle sid and oracle global database name:
Specify if you
want to install
the OEM as
part of database
installation as:

Specify the passwords for the oracle system years:


Specify the storage type:

Specify the recovery area and flash recovery area:


Specify if install the sample schemas as part of database installation:

Specify the memory parameters, character sets, block size for oracle database:
Overview the files that are created by dbca as part of oracle database installation:

Check the radio button for creating a template for database creation and other scripts:
Overview the summary of oracle database installation:

Install the database and overview of progress window:


Problems That I faced:

S.N Problems What I did Error messages Solution


1 Unable Check the status of Error: Environment variable I set the Environmental variable by editing
to run dbconsole as: ORACLE_UNQNAME not .bash_profile as:
OEM $ emctl status defined. Please set Oracle_uniquename=ora11g
dbconsole ORACLE_UNQNAME to
database unique name
Again checked the OC4J Configuration issue. This implies that the OEM is not
status of dbconsole /u01/app/oracle/product/11.2.0/ configured in the database as part of
db_home_1/oc4j/j2ee/ database installation
OC4J_DBConsole_ora11g.home.
com_ora11g
not found
Configure and install Em configuration failed for more So I dropped sysman and its realated
dbcontrol using emca look objects as:
as: /u01/app/oracle/cfgtoollogs/ DROP USER sysman CASCADE;
emca -config emca/ora11g/ DROP PUBLIC SYNONYM
dbcontrol db -repos emca_2013_12_26_12_24_28.lo setemviewusercontext;
create g DROP ROLE mgmt_user;
By looking log file it report that DROP PUBLIC SYNONYM
em related accounts already mgmt_target_blackouts;
exited so I need to drop the DROP USER mgmt_view;
accouts
Ie Sysman already exists spool ./synonyms.SQL
SELECT 'drop public synonym
'||object_name||';' FROM dba_objects
WHERE object_type='SYNONYM' AND
(object_name LIKE 'MGMT_%' OR
object_name LIKE 'SMP_%' OR
object_name LIKE 'EMD_%' OR
object_name LIKE 'ECM_%') AND
STATUS='INVALID';
spool off

@./synonyms.SQL

Again issued the SEVERE: Failed to unlock all This is due to the change of profile
same command to EM-related accounts parameters used by oem accounts sysman
configure and inatall and dbsnmp so I set to defaults the profile :
oem default and monitoring_profile
Again try to recreate Listener is not up or database This due to not proper configuration of
the oem service is not registered with it. listner

Tried to configure the The port is currently used by As I was not able to select any port so
lister another component this is due to network problem and is due
not proper entry in /etc/hosts file so I
provide the fully qualified name as
10.0.2.15 ora11g.home.con ora11g
Again tried to install Object already exists This is due to the oem was configured
oem successfully but not installed so first need
to delete the configuration
So I drop the oem Successfully deleted
configuration as:
emca -deconfig
dbcontrol db -repos
drop
Finally I again No error messages Successfully installed
installed the oem
using oem as:
emca -config
dbcontrol db -repos
create
Checked the status of No error messages The instance of oracle oem is currently
oem dbconsole as: running
emctl status
dbconsole
Stopped dbconsole
and restarted as:
emctl stop dbconsole
emctl start dbconsole
Installation of oracle database manually with
create statement
Installation of oracle database manually with create database statement.
As per installation I configured the oracle binaries and all required perquisites, users and
directories and started the installation of oracle database manually with following steps as:
Created the initial parameter file as:
db_name='ora11g'
db_domain=home.com
db_block_size=8192
memory_target=700m
processes=100
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
compatible ='11.2.0'
audit_trail ='db'
db_recovery_file_dest_size=5g
db_recovery_file_dest=/u01/app/oracle/ora11g/flash_recovery_area'
audit_file_dest='/u01/app/oracle/ora11g/admin/adump'
diagnostic_dest=/u01/app/oracle/ora11g/diag'
control_files = (/u01/app/oracle/ora11g/oradata/control1.ctl')

Logged into SQL*plus and creates the spfile as:


Copied the newly created pfile in directory /u01/app/oracle/product/11.2.0/dbhome1/dbs
$ sqlplus /as sysdba
$create spfile from pfile;

Create the normal text file for creation of database as:


CREATE DATABASE ora11g
USER sys IDENTIFIED BY oracle
USER system IDENTIFIED BY oracle
MAXLOGFILES 5
MAXLOGMEMBERS 3
MAXDATAFILES 200
MAXINSTANCES 1
MAXLOGHISTORY 500
LOGFILE
GROUP 1 (
'/u01/app/oracle/ora11g/oradata/redo01a.rdo',
'/u01/app/oracle/ora11g/oradata/redo01b.rdo'
) SIZE 50M,
GROUP 2 (
'/u01/app/oracle/ora11g/oradata/redo02a.rdo',
'/u01/app/oracle/ora11g/oradata/redo02b.rdo'
) SIZE 50M,
GROUP 3 (
'/u01/app/oracle/ora11g/oradata/redo03a.rdo',
'/u01/app/oracle/ora11g/oradata/redo03b.rdo'
) SIZE 50M
DATAFILE '/u01/app/oracle/ora11g/oradata/system01.dbf' SIZE 300M EXTENT
MANAGEMENT LOCAL
SYSAUX DATAFILE '/u01/app/oracle/ora11g/oradata/sysaux01.dbf' SIZE 200M
UNDO TABLESPACE UNDOTBS1 DATAFILE
'/u01/app/oracle/ora11g/oradata/undotbs01.dbf' SIZE 300M AUTOEXTEND OFF
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE
'/u01/app/oracle/ora11g/oradata/temp01.dbf' SIZE 200M REUSE AUTOEXTEND OFF
CHARACTER SET WE8ISO8859P1
NATIONAL CHARACTER SET UTF8;

And logging in sqlplus as sys user and started the database instance and issued the above
statement.

Created data dictionary objects as:


the catalog.sql and catproc.sql scripts were used to create the dictionary objects included as part
of oracle binaries installation in directory
/u01/app/oracle/produce/11.2.0/db_home_1/rdbms/admin by loging in sqlplus.
@$ORACLE_HOME/rdbms/admin/catalog.sql
@$ORACLE_HOME/rdbms/admin/catproc.sql

After successfully installation of two scripts on another script is runned as a system user as:
@$ORACLE_HOME/sqlplus/admin/pupbld.sql

Finally started the database instance and database as from sqlplus:


$ startup

Selected if any invalid object exists during installation as:


>select owner,object_name,object_type from all_objects where status<>'VALID';
No rows were selected if any rows were founded they were recompiled with the sql script:
>$ORACLE_HOME/rdbms/admin/utlrp.sql
Installation of Listener and tnsnames.ora file
The listener is configured as of using net configuration assistant and tnsnames.ora is configured
manually as :
## tnsnames.ora file for manual creation of database
ORA11G=(
DESCRIPTION=(
ADDRESS_LIST=
((PROTOCOL=TCP) (HOSTNAME=ora11g.home.com) (PORT=1521))
)
(CONNECT_DATA =
( SERVICE_NAME=ora11g.home.com)
)
)

LISTNER_ORA11G =
( ADDRESS = ( PROTOCOL=IPC)(KEY=ipc))

Configuration and installation of oracle OEM:


Specified the following command on terminal and configured and installed the database control
as:
$ emca -config db dbcontrol -repos create
With issue of above command the window asked the password for oracle database system users
as:
Problems Faced:

S.N Problems What I did Error messages Solution


1 Oem Install and reconfigure Serve cannot unlock em This is due because there was no
configuration oem with following related accounts password file to use for remote
command: account so it is necessary to created
emca config password file as:
dbcontrol db repos >orapwd
create file=/u01/app/oracle/product/11.2.0/d
b_home/dbs/orapwora11g
password=sys entries=5
Upgrade of oracle database using database
upgrade assistant
Upgrade of oracle database using database configuration assistant:
Upgrade database Details:
S.N Current version of database Version to upgrade
1 Oracle database ( 11.2.0.1) Oracle database (11.2.0.3)

Install the database software binaries of the version to upgrade:


The new location and the directories are set for the new oracle database installation by editing
the file .bash_profile and compiling it.
ORACLE_HOME=/u01/app/oracle/product/11.2.0.3/dbhome1

Compile the binary file after backup and editing as:


source ~/.bash_profile

With the new oracle home the database versions binaries of release 11.2.0.3 is installed using
OUI .

Started the upgrade of the oracle database using the database configuration assistant by issuing
following command as:
$dbua

With the issue of above command the upgrade of database started and snapshots of the upgrades
are as:

Welcome window of database upgrade assistant:


Select the database for upgrade:

The warnings given by the upgrade assistants:


Upgrade options include the degree of parallelism, recompile invalid objects etc.

The upgrade of oracle enterprise manager using dbca requires oracle listener to be running:
Specify if move datafiles as part of upgrade:

Specify the location for flash recovery and its size as:
Overview the upgrade summary as:
Perform Upgrade as:
View of the upgrade results:
With the successful upgrade of database check the status of the database instance and select
version of currently running database:

Check the status of the database control and log in into the oem if it is successfully installed or
not:
Manually upgrade of Oracle database
Manually upgrade of oracle database.
Upgrade database Details:
S.N Current version of database Version to upgrade
1 Oracle database ( 11.2.0.1) Oracle database (11.2.0.3)

Install the database software binaries of the version to upgrade:


The new location and the directories are set for the new oracle database installation by editing
the file .bash_profile and compiling it.
ORACLE_HOME=/u01/app/oracle/product/11.2.0.3/dbhome1

Compile the binary file after backup and editing as:


source ~/.bash_profile

With the new oracle home the database versions binaries of release 11.2.0.3 is installed using
OUI .

Compatibility Matrix:
Minimum version of the oracle database software that can be directly upgraded to oracle 11g
release 2. So before starting the database version must be the following:
S.N Source Database Target Database
1 9.2.0.8 or higher 11.2.x
2 10.1.0.5 or higher 11.2.x
3 10.2.0.2 or higher 11.2.x
4 11.1.0.6 or higher 11.2.x

Furthermore the following database software version will require an indirect upgrade paths. In
case DBA needs to do double effort, because two upgrades are needed.
S.N Source Database Upgrade Path Target Database
1 7.3.3 or lower 7.3.4 => 9.2.0.8 11.2.x
2 8.0.5 or lower 8.0.6 => 9.2.0.8 11.2.x
3 8.1.7 or lower 8.1.7.4 => 10.2.0.4 11.2.x
4 9.0.1.3 or lower 9.0.1.4 => 10.2.0.4 11.2.x
5 9.2.0.7 or lower 9.2.0.8 => 11.2.X

Starting Upgrade:
The manually upgrade of the oracle database consists of three parts of which are:
Pre-upgrade checks
Upgrade
Post upgrade
Pre upgrade checks:
1. Gather information:
The pre upgrade checks for upgrade of the database is done by running the script provided by the
oracle in $ORACLE_HOME/rdbms/admin/utl112i.sql of newly installed oracle software i.e.
11.2.0.3 as.
> spool upgrade_11.2.0.2.log
>@utlu112i.sql
>spool off
With the generated pre upgrade log file, it had no error messages and the all tablespaces are fine
for upgrades , components like Oracle catalog views, Oracle packages and types EM repository
will be upgraded was reported by log file.
There were warning in the log file that your recycle bin must be empty so I empty the recycle bin
of oracle using following command.
>purge DBA_RECYCLEBIN;
In addition the log reported that the memory_max_target value must be raised to 600M.

2. Database integrity check:


The integrity of the source database must be done prior to upgrade. So the integrity of the oracle
database can be done using the package provided by the oracle if you have an oracle support
account ie: dbupgdiag.sql. If still no oracle support account we can recompile and validate the
invalid objects in the database using script utlrp.sql which is in directory
$ORACLE_HOME/rdbms/admin. So I ran the script as:
>@utlrp.sql
Furthermore checked if any files in the current database needs media recovery by running the sql
statement:
>select * from v$recover_file;
As no rows were selected it stated that there no files needs media recovery.

3. Generation of pfile:
The pfile is generated for listing all the initialization parameters that is used by the current
database. So for generating pfile from spfile of currnet database first the oracle database listener
is stopped as:
>lsnrctl stop
With stopping of listener the pfile is generated either form memory or from spfile so I generated
from spfile as:
>create pfile from spfile;

4. Perform backup:
The backup is optional but it is good practice to backup your database before performing any
changes and upgrades to your database. So that if anything goes wrong during any process I can
restore and recover my database. So I performed cold back up using rman as:
>rman target /
>run {
>shutdown immediate;
>startup mount;
>backup database;
>}

5. Backup and Edit Pfile:


The necessary intilization parameters that are to be changed are changed by first keeping the
back copy of the pfile and editing. So as per reported by the oracle pre upgrade log the
memory_max_target was changed to 700M and the pfile copied to the newly installed oracle
database software in location $ORACLE_HOME/dba.

Upgrade Database.
With the necessary pre upgrade checks now the database is ready for upgrade so logged into the
sqlplus of the database software (11.2.0.3) as sys user and started database with upgrade mode
and ran the script provide by the oracle in directory $ORACLE_HOME/rdbms/catupgrd.sql. The
log of script is spooled. The commands are:
>cd $ORACLE_HOME/rdbms/
>sqlplus /as sysdba
>startup upgrade
>set echo on
>spool upgrade.log
>@catupgrd.sql
>spool.off
As the script runned successfully now errors ware reported during the upgrade.

Post Upgrade.
1.Post upgrade status:
The database is started and the post-upgrade status tool provide by the oracle in
$ORACLE_HOME/rdbms/admin/utlu112s.sql is ran which provides a summary of the upgrade
at the end of the spool tag. It displays the status of the database components in the upgraded
database and the time required to complete each component upgrade. Any errors that occur
during the upgrade are listed with each component and must be addressed. The script is run as:
>sqlplus /as sysdba
>startup force
>@utlu112s.sql
The execution of the script completed successfully and no error report was listed.
2. Rcompile the invalid objects:
The invalid objects were recompiled by running the scrip utlrp.sql as
>@utrp.sql

3. Network file configuration


The listener.ora file is copied from the previous database and edited the oracle home directory
and the listener was started as:
>lsnrctl start

4. Create spfile
The spfile is generated from the previously generated and edited pfile as form sqlplus:
>create spfile from pfile;

5. Oem configuration
The oracle enterprise manager is configured for the newly upgrade database. So before
configuring the status of oem is checked as:
>emctl status dbconsole
If it reports any error then it is necessary to first remove the components and reconfigure and
install it as:
>emca dconfig dbcontrol db repos drop
>emca config dbcontrol db repos create

So as frist I dropped the em repository and again reconfigured the database control.

Problems I Faced During Manual Upgrade:


S.N Problems What I did Error messages Solution
1 Oem Tried to configure oem the em key cannot be The repository must be first be
configura without dropping as: configured dropped before reconfiguration.
tion emca config dbcontrol the em key was not found
db repos create
Understanding Startup and Shutdown of oracle
database:
The overview, issues and the usages of the oracle shutdown and startup commands are listed in
the below table:
S.N Command Description and usages
1 >startup Start database and instance in normal way
2 >startup nomount Instance is started and typically the database is started in
no mount mode for creating database and recreating
controlfile.
3 >startup mount An instance is stared and database is not opened for normal
use in mount mode. A database is opened in mount mode
for specific maintenance operation like:
Renaming datafiles
Adding, dropping or renaming log files
Enabling or disabling log archiving
Performing database backup and recovery
4 >startup restrict A instance is started, mounted and opened a database
allows the database for only administrative personnel. Only
the users with system privilege restricted_session can
connect to database in this mode. This mode is typically
used for :
Performing logical export and imports of
database data
Perform data load with sql*loader
Temporary prevent users for accessing data
During migration and upgrade of database
5 >startup force This command is typically used when cannot start database
or shutdown database with normal, immediate or
transactional commands. With startup force if the instance
is running it first shutdown with abort and restarts the
database in normal mode.
5 >alter database mount; Change the database to mount mode from nomount mode
6 >alter database open; Open database for normal user
7 >alter database open read Enables user to query the database but disallows any
only; modification of database datafiles and log files. It does not
restrict the restore and recovery options.
8 >alter database open read Alter the database for normal use allowing both read and
write; write operations on database.
9 >shutdown normal Shutting database in normal mode causes:
No new connections are allowed after the statement
issued
Before database is shutdown , oracle waits for all
currently connected users to disconnect from the
database
Next startup requires no instance recovery
10 >shutdown immediate The shutdown immediate is used in following situations
To initiated an automated and unattended backup
When a power shutdown is going to occur soom
When the database or one of its components is
functioning irregularly and you cannot contact
users back them to log off or they are unable to log
off
Shutting down database in immediate mode causes:
No new connections are allowed nor new
transactions are allowed to be started agter the
statement is used.
Any uncommitted transactions are rolled back
Oracle does not wait for users connected to
disconnect
Next step requires no instance recovery
11 >shutdown transactional Shutting down database in transactional mode causes:
Allow to complete all ongoing transaction
No new connections or transactions are allowed
After all transactions are completed the user are
disconnected by database.
Next time of startup no instance recovery is
required.
12 >shutdown abort Shutting down database in abort causes:
No new connections and transactions are allowed
Current processing sql statements are immediately
terminated
Uncommitted transactions are not rolled back
Next step requires instance recovery
Shutdown abort is used in following conditions:
The database or one of its applications is
functioning irregularly and none of the other types
of shutdown works
Needed to shutdown database instantly
Experience problems with starting a database
instance.
Database Storage Structures (Tablespaces,
Datafiles, and oracle managed files)
Oracle database storage structures:
Tablespaces:
Tablespaces are the logical structures in oracle database storage structures. Tablespaces are
repositories for schema data, including the data dictionary. All databases must have a SYSTEM
tablespace and a SYSAUX tablespace, and (for practical purposes) a temporary tablespace and
an undo tablespace. These four will usually have been created when the database was created.
Tablespace components and options:
Locally managed tablespace:
Locally managed tablespace keep the information about space allocation information within the
tablespace datafile headers not in data dictionary, thus offering better performance .By default
oracle database sets all newly created tablespaces to be locally managed with automatic segment
management. The tablespace can be specified to be locally managed as using keyword EXTENT
MANAGEMENT LOCAL. Along with local management it can be all the extents to be of
variable sixe by specifying AUTOALLOCATE or the extents of fixed size as issuing UNIFORM
SIZE 128k;
S.N Command Description
1 create tablespace example datafile Creates a tablespace with name example and
/u01/app/oracle/oradata/ORA11G the extent management is local
example01.dbf size 100m extent
management local;
2 create tablespace example datafile Creates tablespace with name example and
/u01/app/oracle/oradata/ORA11G the extent management is local and sizes
example01.dbf size 100m extent extent according to data.
management local autoallocate;
3 create tablespace example datafile Creates a tablespace with uniform 128K
/u01/app/oracle/oradata/ORA11G extents
example01.dbf size 100m extent
management local uniform size 128k;

Autoextend tablespace:
Offline and online:
A tablespace can be brought to offline or online. If the status of the tablespace is offline, then no
users can access it. Generally a tablespace is brought to offline before performing maintenance
or recovery on the datafiles associated with that tablespace.
S.N Command Description
1 alter tablespace demo offline; Changes the tablespace demo to offline and
no operations are allowed.
2 alter tablespace demo online; Changes the tablespace demo to online for
normal operation.

Smallfile and bigfile:


Normally a tablespace created is of smallfile. The tablespace of small file can contain more than
one datafiles and the size of datafiles are typically few hundred of megabytes. By default the
creation of tablespace is of smallfile. With the tablespace created with bigfile allows the
tablespace to contain onlyone datafile of big size upto 4GB.
S.N Command Description
1 create tablespace bigfile example Creates tablespace example of size 50G, a
datafile big file supports up to 4G blocks of size.
'/u02/oracle/data/bigtbs01.dbf' size 50G;
2 create tablespace smallfile example Creates tablespace of smallfile with 2
datafile datafiles
'/u02/oracle/data/demo1.dbf' size 300M
/u02/oracle/data/demo2.dbf' size
300M;

Read and write:


Tablespaces with status read and write allows the users for read and write operation on the
datafiles associated with the tablespace and a tablespace created by default is read write. If the
status of the table space is changed to the readonly then the tablespace is allowed to readonly and
no write operation is allowed for the datafiles associated with it until its status is changed to read
write.
S.N Command Description
1 alter tablespace demo read only; Alters tablespaces demo to read only any
modification of contents on demo tablespace
are not allowed.
2 alter tablespace demo read write; Alters tablespaces demo to read and wirte

Segment space management:


Oracle Database can use to manage segment space: automatic and manual. Manual segment
space management uses linked lists called "freelists" to manage free space in the segment, while
automatic segment space management uses bitmaps. Automatic segment space management is
the more efficient method, and is the default for all new permanent, locally managed tablespaces.
The statement SEGEMENT MANAGEMENT AUTO or SEGEMTN MANAGEMENT
MANUAL is used for segment either auto or manual respectively.
S.N Command Description
1 create tablespace example datafile Create tablespace example with segment
'/u02/oracle/data/example01.dbf' size space management auto;
5m
extent management local segment space
management auto;
2 create tablespace example datafile Create tablespace example with segment
'/u02/oracle/data/example01.dbf' size space management manual;
5m
extent management local segment space
management manual;
Tablespace management ( rename, drop, add datafile):
Table space can be created using oracle enterprise manager and from sqlplus and can be
managed.
S.N Command Description
1 alter tablespace demo add datafile Adds a new datafile to the demo
'/u01/app/oracle/oradata/ORA11G/demo111.dbf' tablespace and the tablespace must me
size 1m; online.
2 alter tablespace demo rename to demotest; Renames the tablespace demo to
demotes;
3 drop tablespace demo; Drops the tablespace demo
4 drop tablespace demo including contents; Drops tablespace demo with all its
schema objects
5 drop tablespace demo including contents and Drops the tablespace demo including
datafiles; datafiles;

Temporary tablespaces:
A temporary tablespace contains transient data that persists only for the duration of the session.
Temporary tablespaces can improve the concurrency of multiple sort operations that do not fit in
memory and can improve the efficiency of space management operations during sorts.
S.N Command Description
1 create temporary tablespace tempo tempfile Creates temporary tablespace name
'/u02/oracle/data/lmtemp01.dbf' tempo with datafile of size 2om with
size 20m uniform size
extent management local uniform size 16m;
2 alter database temporary tablespace tempo Makes the tempo as the default
default; tablespace.

Oracle Managed Files:


Use of OMF is intended to remove the necessity for the DBA to have any knowledge of the file
systems. The creation of database files can be fully automated. To enable OMF, set some or all
of these instance parameters:

DB_CREATE_FILE_DEST
DB_CREATE_ONLINE_LOG_DEST_1
DB_CREATE_ONLINE_LOG_DEST_2
DB_RECOVERY_FILE_DEST

The DB_CREATE_FILE_DEST parameter specifies a default location for all datafiles. The
DB_CREATE_ONLINE_LOG_DEST_n parameters specify a default location for online redo
log files. DB_RECOVERY_FILE_DEST sets up a default location for archive redo log files and
backup files. As well as setting default file locations, OMF will generate filenames and (by
default) set the file sizes. Setting these parameters can greatly simplify file-related operations.
Having enabled OMF, it can always be overridden by specifying a datafile name on the
CREATE TABLESPACE command.

Managing users, roles, privileges, profiles and


Database auditing and security
Managing Users, Roles, Privileges
Create and Manage Database User:
To establish a session against an instance and a database, a user must connect to a user account.
The account must be specified by name and authenticated by some means. The way the account
was created will set up a range of attributes for the session, some of which can be changed later
while the session is in progress.
S.N Command Description
1 create user dralmostright identified by Creates a user dralmostright.
pa$$word default tablespace users dramostright => name of user and
temporary tablespace temp quota must be unique
unlimited on users profile clerk; identified by pa$$word => a
password must be stated in create
statement
default tablespace users =>
specifies that all the objects created
by the user will reside in users
tablespace and its optional and if
not specified default the system
tablespace will be used if no other
tablespace is specified default.
temporary tablespace temp =>
specifies the temporary tablespace
for the user to hold the current
result and statements issued by the
user if not specified system
tablespace will be used by default.
Its optional.
quota unlimited on users =>this
gives permission to user to create
objects in the tablespace. The quota
clause applies a quota space for
user to store and creates schema
objects. The unlimited clause
specifies that it has no bounds on
space on tablespace alternatively it
can be used as quota 10m on users.
profile clerk => specifies the profile
for the user. A profile is set of
limits on database resource and
password to access and its optional
and if not specified default profile
is used.
2 Create user dralmostright identified by Creates user dralmostright with password
pa$$word. pa$$word and default tablespace is system,
temporary tablespace is temp and profile is
clerk.

Account Status:
Every user account has a certain status, as listed in the ACCOUNT_STATUS column of
DBA_USERS. There are nine possibilities:
S.N Status Description
open the account is available for use.
2 locked this indicates that the dba deliberately locked the
account. no user can connect to a locked account.
3 expired this indicates that the lifetime has expired. passwords
can have a limited lifetime. no user can connect to an
expired account until the password is reset.
4 expired & locked not only has the account been locked, but its password
has also expired.
5 expired (grace) this indicates that the grace periods in effect. a
password need not expire immediately when its
lifetime ends; it may be configured with a grace period
during which users connecting to the account have the
opportunity to change the password.
6 locked (timed) this indicates that the account is locked because of
failed login attempts. an account can be configured to
lock automatically for a period after an incorrect
password is presented a certain number of times.
7 expired & locked (timed) this indicates that the account is locked of failed login
attempts and lifetime has expired.
8 expired (grace) & locked the account is locked due to attempts to log in more
than grace limit with incorrect password
9 expired (grace) & locked
(timed)

Some commands to alter the status and passwords of the user:


S.N Commands Description
1 alter user scott account Unlocks the account status of the user scott
unlock;
2 alter user scott identified by Setup the new password for the user scott.
password;
3 alter user scott account lock Locks the account of user scott
4 alter user dralmostright Alters the account of user dralmostright as:
identified externally default Authentication is changed to use the operating
tablespace demo temporary system account of the user dralmostright.
tablespace temp quota The default and temporary tablespaces are
unlimited on demo profile explicitly set for user dralmostright.
clerk; The user dralmostright given a 100M quota for
the demo tablespace.
The user dralmostright assigned the clerk
profile.
4 passwd Change the password of the currently logged user.
5 drop user dralmostright Drops the user dralmostright along with its associated
cascade; all schema objects.
6 alter system kill session The 111 is the session id and 2344 is the serial of the
111 ,2344; user which can be viewed in v$session data dictionary
view. This command kills the session with sid 111
explicitly.

Roles and Privileges:


When a user is created he/she must be granted some sort of privileges to enable to connect to
database, run queries and make updates and make schema objects. Four basic types of database
operations can be limited by privileges in an Oracle database:
SELECT
INSERT
UPDATE
DELETE
In addition to these data-specific privileges, several other privileges apply to the objects within a
database schema:
CREATE
DROP
ALTER
There are two types of user privileges which are:
S.N Privilege type Description
1 system privilege A system privilege is the right to perform a particular
action or to perform action on any schema objects of a
particular type. e.g. privilege to delete the rows of any
table in database is system privileges.
2 object privilege An object privilege is the right to perform a particular
action on a specific schema object. E.g. privilege to
create a table in specific user schema.

All of these privileges can be handled with two simple SQL commands. The GRANT command
gives a particular privilege to a user or role, while the REVOKE command takes away a specific
privilege.
S.N Command Description
1 grant insert, update, delete grant INSERT, UPDATE, and DELETE privileges on
on test to dralmostright. a table called test to a user name dralmostright. So the
user can now insert , update and delete rows in table
test but not select until user is granted select privileges.
2 grant all on suppliers to Grant all privileges ( insert, update, delete, references,
smith; index , alter, select ) on schema object suppliers to user
smith.
3 revoke delete on suppliers revoke DELETE privileges on a table called suppliers
from soni; from a user named soni.
4 revoke all on suppliers revoke all privileges on a table called suppliers from a
from soni; user named soni.

Managing and controlling privileges is made easier by using roles, which are named groups of
related privileges. A role can be created and can be granted with object and system privileges
and assign the role to different users.
S.N Command Description
1 create role master Creates a role named master.
2 grant select, insert, delete Grants the role master privileges to select insert and
on emp to master delete rows on emp table.
3 create role smart identified The command specifies that the enabling of the role
by smart requires authentication by password.
4 revoke master from Withdraw the role granted to the user dralmostright
dralmostright

Scenario:
Assume that the HR schema is being used as a repository for data to be used by three groups of
staff. Managerial staff have full access, senior clerical staff have limited access, and junior
clerical staff have very restricted access. So this can be implemented as:

Grant privileges to junior clerks


S.N Command Description
1 create role jounior_clerk; Creates role jounior_clerk for junior clerks
2 Grant select on hr.employee Grant minimal privileges i.e select on hr schema.
t o jounior_clerk;
grant select on
hr.department to
jounior_clerk;

Grant privileges to senior clerks


S.N Command Description
1 create role senior_clerk Creates role senior_clerk for senior clerks
2 grant jounior_clerk to Grant the privileges to senior_clerk that jounior clerks
senior_clerk with admin has by which senior clerk can grant to jounior_clerk
option; privileges to other jounior clerks.
3 Grant insert , update , delete Grant insert, update , delete privileges to senior clerks.
on hr.employee to
senior_clerk;
grant insert, update, delete
on hr.department to
senior_clerk;

Grant privileges to managers


S.N Command Description
1 create role manager Create role manager for manager staffs
2 grant senior_clerk to Grant privileges to manager that senior clerks has by
manager with admin option; which manager can grant to other senior clerks.
3 grant all on hr.employee to Grant all privileges to managers.
manager;
grant all on hr.departments
to manager;

Create and manage profiles:


A profile has a dual function: to enforce a password policy and to restrict the resources a session
can consume. Password controls are always enforced; resource limits are only enforced if the
instance parameter RESOURCE_LIMIT is on TRUEby default, it is FALSE. Profiles are used
automatically, but the default profile (applied by default to all users, including SYS and
SYSTEM) does very little.
Password Management:
The limits that can be applied to passwords are listed as below:
S.N Component Description
1 failed_login_attempts Specifies the number of consecutive errors on a
password before the account is locked. If the correct
password is given before this limit is reached, the
counter is reset to zero.
2 password_lock_time the number of days to lock an account after
failed_login_attempts is reached.
3 password_life_time The number of days before a password expires. It
may still be usable for a while after this time,
depending on password_grace_time.
4 password_grace_time The number of days following the first successful
login after the password has expired that prompts to
change the password will be generated. the old
password is still usable during this time
5 password_reuse_time The number of days before a password can be reused.
6 password_reuse_max The number of times a password can be reused.
7 password_verify_function The name of a function to run whenever a password
is changed. The purpose of the function is assumed to
be checking the new password for a required degree
of complexity, but it can do pretty much anything
you want.

Resource Limits:
The limits that can be applied to resource usage (also known as kernel limits) are listed as below:
S.N Component Description
1 sessions_per_user The number of concurrent logins that can be made to
the same user account. Sessions attempting to log in
with the same user name when this limit is reached
will be blocked.
2 cpu_per_session The cpu time (in centiseconds) that a sessions server
process is allowed to use before the session is
forcibly terminated.
3 cpu_per_call The cpu time (in centiseconds) that a sessions server
process is allowed to use to execute one sql statement
before the statement is forcibly terminated
4 logical_reads_per_session The number of blocks that can be read by a session
(irrespective of whether they were in the database
buffer cache or read from disk) before the session is
forcibly terminated
5 logical_reads_per_call The number of blocks that can be read by a single
statement (irrespective of whether they were in the
database buffer cache or read from disk) before the
statement is forcibly terminated.
6 private_sga For sessions connected through the shared server
architecture, the number of kilobytes that the session
is allowed to take in the sga for session data
7 connect_time In minutes, the maximum duration of a session before
the session is forcibly terminated.
8 idle_time In minutes, the maximum time a session can be idle
before the session is forcibly terminated.
9 composite_limit A weighted sum of cpu_per_session, connect_time,
logical_reads_per_session, and private_sga

Create and assign profiles:


S.N Command Description
1 create profile dba_profile Creates profile dba_profile. Users with dba_profile
limit sessions_per_user can have unlimited sessions and life time that a
unlimited password is valid is 7 days and grace limit is one
password_life_time 7 times.
password_grace_time 1;
2 Alter user dralmostright Changes the profile of the user dralmostright to
profile dba_profile; dba_profile;
3 drop profile dba_profile; Drop profile dba_profile;
Auditing:
Auditing is the monitoring and recording of selected user database actions. It can be based on
individual actions, such as the type of SQL statement executed, or on combinations of factors
that can include user name, application, time, and so on. Security policies can trigger auditing
when specified elements in an Oracle database are accessed or altered, including the contents
within a specified object.
Oracle provides three auditing techniques:
Database auditing can track the use of certain privileges, the execution of certain
commands, access to certain tables, or logon attempts.
Value-based auditing uses database triggers. Whenever a row is inserted, updated, or
deleted, a block of PL/SQL code will run that can (among other things) record complete
details of the event.
Fine-grained auditing allows tracking access to tables according to which rows (or which
columns of the rows) were accessed. It is much more precise than either database
auditing or value-based auditing, and it can limit the number of audit records generated to
only those of interest.

Database Auditing:
Before setting up database auditing, the AUDIT_TRAIL instance parameter must be set. This
has six possible values:
S.N Value Description
1 none (or false) Database auditing is disabled, no matter what auditing you
attempt to configure.
2 os audit records will be written to the operating systems audit trail
the application log on windows, or the audit_file_dest directory
on unix
3 db The audit records are written to a data dictionary table,
sys.aud$. there are views that let you see the contents of this
table
4 db_extended As db, but including the sql statements with bind variables that
generated the audit records.
5 xml as os, but formatted with xml tags
6 xml_extended As xml, but with the sql statements and bind variables.

Database auditing is configured using the AUDIT command.Use of privileges can be audited
with, for example.
S.N Command Description
1 audit create any trigger; will generate one audit record for every session that
violates an audit condition, irrespective of the
number of times it violates the condition, i.e every
time a user issue a create trigger statement it is
tracked by database as type set by parameter
audit_trail
2 audit insert on hr.employees Generate a audit record whenever the insert is
whenever successful; successful to table hr.employees.
3 audit session whenever not Generate audit record whenever user tries to login
successful; with incorrect password or login attempt fail.

Value based auditing


Database Backup, Restore and recovery (Manual
+ server Managed)
Backup Terminologies:
A backup, or the process of backing up, refers to the copying and archiving of computer data so
it may be used to restore the original after a data loss event. A backup carried out with operating
system commands is known as a user-managed backup. A backup carried out by RMAN is
known as a server-managed backup. There are three decisions to make before carrying out a
server-managed backup. So they are:
S.N Type Description
1 Closed A closed backup is carried out when the database
is shut down; alternative terms for closed are cold,
consistent, and offline
2 Open An open backup is carried out while the database
is in use; alternative terms are hot, inconsistent,
and online. An open backup can only be made if
the database is in archivelog mode
3 Whole A whole backup is a backup of all the datafiles and
the control files.
4 Partial A partial backup is a backup of a subset of whole
backup. In most circumstances, partial backups
can only be made if the database is in archivelog
mode.
5 Full A fullbackup includes all used blocks of the files
backed up.
6 Incremental An incremental backup includes only those blocks
that have been changed since the last backup. An
incremental backup can be cumulative (including
all blocks changed since the last full backup) or
differential (including all blocks changed since the
last incremental backup).

User Managed backup:


User-managed backup is accomplished with whatever operating system facilities happen to be
available and SQL*Plus commands. These may be as simple as the copy command on Windows,
or cp on UNIX. The significance of archivelog mode for the backup techniques available is the
same for user-managed backup as for server-managed backup: in noarchivelog mode, backup
must be closed and whole; in archivelog mode, it can be open and partial. In neither case is an
incremental backup possible: operating system facilities are not Oracle aware and will not be
capable of identifying blocks that have changed since the last backup, in the way that RMAN
can. The granularity of any user-managed backup or restore operation is the datafile, not the
individual blocks.

Backup in Noarchivelog Mode:


To perform full backup of a database in NOARCHIVELOG mode, the database must be shut
down:
The locations of datafiles, control files and logfiles are retrieved and spooled as issuing
following sql commands:
>spool backup.txt
>select cp ||name|| /u01/app/backup from v$datafile;
>select cp||name|| /u01/app/backup from v$controlfile;
>select cp||name|| /u01/app/backup from v$logfile;
>spool off

Opening the backup.txt file and issuing the commands in it, performs the complete user managed
backup. Including the online redo log file members in the backup is strictly optional if the
database is shutdown cleanly because with clean shutdown the database is properly check
pointed and all files are in consistent state.

Backup in Archivelog mode:


To perform inconsistent backup the database must be in archivelog. So to check the database is
in archivelog or not issued the following command (+ other related commands) as:
S.N Command Description
1 Select log_mode from v$database; Displays if the database is in archive log mode
or no archive log mode.
2 archive log list displays archiving information for the
connected instance
3 alter database archivelog; If the database is not in archive log the
database msut be shutdown cleanly and open
in mount mode and the database can be
changed to archivelog mode.
4 alter system archive log all; Force archiving of all log files
5 alter system archive log current; Force archiving of the current log file
6 alter system archive log start; Start Archive Logging
7 alter system archive log stop; Stop Archive Logging
8 Alter system noarchivelog; Changes the current archivelog mode to no
archivelog mode.

The user managed inconsistent backup consists of the following steps:


Steps Command Description
1 alter database backup controlfile to The first command back up the control file to a
/u01/app/oracle/backup/bc_crtl.ctl; binary file (duplicate of existing controlfile).
OR
alter database backup controlfile to The second command produce SQL statements
trace as /u01/app/oracle/backup/ that can later be used to re-create control file.
bc_crtl.ctl;
2 alter tablespace users begin backup; The tablespace is brought to backup mode
while the operations related to the tablespace
are allowed, and this cause excessive
generation of redo logs. So the datafiles can
now be backup with copy command as the
datafiles are partially checkpointed.
3 alter tablespace users end backup; Brought the tablespace for normal use;
4 alter system archivelog all; Archive the all online redo log files.
Server managed backup, restore and recovery
RMAN utility is used for server managed backup, restore and recovery. RMAN (Recovery
Manager) is a backup and recovery manager supplied for Oracle databases (from version 8)
created by the Oracle Corporation. It provides database backup, restore, and recovery capabilities
addressing high availability and disaster recovery concerns. Oracle Corporation recommends
RMAN as its preferred method for backup and recovery and has written command-line and
graphical (via Oracle Enterprise Manager) interfaces for the product.
The file types that can be backed up by RMAN are:
Datafiles
Controlfile
Archive redo log files
SPFILE
Backup set pieces

Files that cannot be backed up by RMAN include:


Tempfiles
Online redo log files
Password file
Static PFILE
Oracle Net configuration files

RMAN can generate three types of backup which are:


S.N Backup type Description
1 backup set A backup set is a proprietary format that can
contain several files and will not include blocks
of a datafile that are not currently part of a
segment.
2 compressed backup set A compressed backup set has the same content as
a backup set, but RMAN will apply a
compression algorithm as it writes out the backup
set.
3 image copy An image copy is a backup file that is identical to
the input file. An image copy is immediately
interchangeable with its source, whereas to
extract a file from a backup set requires an
RMAN restore operation.

RMAN backup and restore operations are carried out by server processes known as channels. A
channel is either of type disk (meaning that it can read and write backups on disk) or of type
SBT_TAPE (meaning that it is capable of reading and writing backups stored on a tape device).

Server Managed consistent backup:


The server managed consistent backup is taken when the database is shutdown with consistency
in control files, datafiles and log files i.e. if the database is shutdown in either normal or
transactional or immediate mode. An RMAN-consistent backup can be accomplished only when
the database is in mount mode. This is because RMAN needs to read the controlfile in order to
find the datafiles. If a user-managed operating system backup were attempted in mount mode, it
would be invalid because even in mount mode the controlfile might be written to while being
copied. So during the time of recovery the recovery fails. The scripts to take the consistent
backup is as follows:
S.N Command Description
1 rman target / Connect to the target database using operating
system credentials.
2 run { Script to back up the database in consistent mode
shutdown immediate; from ramn. So the script in rman is grouped in run
starup mount; block. The frist command shutdowns the database
backup database; cleanly.
alter database open; Second start the database in mount mode as rman
} needs to read the information about datafiles, log
files from control file.
The third command uses the channels to back up the
complete database with the default configuration of
rman.
The final command opens the database for normal
use if the backup of the database was successful.

Server managed open backups:


An absolutely reliable open backup can be made using RMAN with a two-word command issued
at the RMAN prompt: BACKUP DATABASE. This command relies on configured defaults for
the destination of the backup (disk or tape library), the names of the backup files generated, the
number of server channels to launch to carry out the backup, and the type of backup (image
copies of the files, backup sets, or compressed backup sets).
S.N Command Description
1

You might also like