Oracle Database Essentials
Oracle Database Essentials
Oracle Database Essentials
www.bmutebi.com
Who am I …
Hi,IamMutebiBashir.
✓ Databaseadministrationreferstomanagingandmaintainingdatabasesystems.
✓ Databaseadministrationissoimportantforanumberofreasonse.g.reducingcosts,
ensuredatabaseavailability,reputationoftheorganization,etc.
✓ Databaseadministrationiscomprisedofbackingupofdata,databaserecovery,database
auditing,databaseavailability,etc.
✓ ThepeoplechargedwithdatabaseadministrationarereferredtoasDatabase
Administrators(DBA)
What you will learn
www.bmutebi.com
Oracle Architecture
✓ For the first part, Oracle database software is divided into two parts i.e. instance and the
database.
✓ The instance is made up of memory and background processes that keep the software
running.
✓ Database is made up of files on a disk e.g. redo log files, data files, etc.
Oracle Architecture – How users connect to database
✓ Whenever a person uses an application that runs on Oracle database software, they
undergo a process before connecting to the database.
✓ Assuming you start an Oracle based app on your device, it has to connect to the
database.
✓ What happens, your device sends a connection request to the database in form of a user
process (initiates connection to the database)
✓ To the other side of the connection, the user is connected to the instance.
Oracle Architecture – How users connect to database
✓ In the instance, a user session is started and the server process is started. Server process
interacts with the database on behalf of the user.
✓ When the server process is started, memory is allocated (Program Global Area - PGA).
Thisworkswithserverprocesstoensureclient’srequestsaresatisfied.
✓ After this (in addition to other things), the user can now access the records in the
database.
Oracle Architecture - Illustration
Connection
1. Instance
2. Database
Data
User Process
Oracle Architecture - Instance
✓ Remember instance is different from the database. The instance is the gateway to the
database. Without it, forget about the database.
✓ Under memory, we have PGA (Program Global Area) and the System Global Area (SGA)
✓ The PGA is a private memory structure charged with storing user session details as well
as working with the server process.
✓ The SGA is a public memory structure with mandatory and option components.
Oracle Architecture – Instance (System Global Area)
Mandatory Components
✓ Redo log buffer – stores SQL statements that cause a change to data temporarily..
Optional Components
✓ We can set the memory target from which memory will be allocated.
Oracle Architecture – Instance - Illustration
Database buffer
1. Instance Redobuffer
Shared Pool
✓ Database Writer (DBWn) – writes recently modified data blocks to data files (checkpoint
event).
✓ Checkpoint (CKPT) – updates the control files and data file headers about a checkpoint event.
✓ Log Writer (LGWR) – writes SQL statements that cause a change to data to redo log files.
Oracle Architecture – Instance - Illustration
Database buffer
✓ Archiverprocess(ARCn). Chargedwithcopyingtransactionalrecoveryinformationfromthe
redologfiletothearchivelocation.
✓ MemoryManager(MMAN). ManagesthesizeofeachindividualSGAcomponentwhen
Oracle’sAutomaticSharedMemoryManagementfeatureisused.
✓ RecoveryWriter(RVWR).WritesrecoveryinformationtodiskwhenOracle’sFlashback
Databasefeatureisused.
✓ Weusethev$process viewtolookatallrunningprocesses.
Oracle Architecture – Database
✓ Whentheinstancecomponentsareallright,wecannowaccessthedatabase.
✓ Thedatabaseisconcernedwithstorage.
✓ Itismadeupofphysicalfilesi.e.datafiles(storesdataintables),redologfiles(stores
SQLstatementsthatcauseachangetodata),parameterfiles(storesdatabase
parameters),controlfiles(storesinformationaboutthedatabase),etc.
✓ Inaddition,thedatabasealsohaslogicalstoragei.e.tablespace,segments,extentsand
blocks.(Weshalllookatalltheselater.)
Oracle Architecture – Summary
✓ Userprocessinitiatesandmaintainsuserconnectiontotheinstance.
✓ Serverprocessinteractwiththedatabaseonbehalfoftheuser.
✓ Instanceismadeofmemorystructuresandbackgroundprocesses.
✓ Memorystructuresare:SGA(databasebuffer,redologbufferandsharedpool),PGA.
✓ Backgroundprocessesincludemandatory(SMON,PMON,DBWn,CKPT,LGWR)and
optional.
✓ Databasephysicalstoragestructuresincluderedologfile,datafile,controlfile,etc.
✓ Databaselogicalstoragestructuresincludetablespace,segments,extentsandblocks.
Preparing Oracle Environment
ORACLE DATABASE ESSENTIALS – MUTEBI BASHIR
www.bmutebi.com
Installing Oracle Database
✓ Reviewdocumentation
✓ Harddiskspace– 200MB
✓ RAMspace- 1GB
✓ Editioni.e.Expressedition,Enterpriseedition,Standardedition.
✓ Softwareversioni.e.11g,12c,18c,21c.
✓ OUI(OracleUniversalInstaller)
Creating Oracle Database
✓ WeusetheDatabaseConfigurationAssistant(DBCA)tool
✓ Letsgetstarted
Managing Storage Structures
ORACLE DATABASE ESSENTIALS – MUTEBI BASHIR
www.bmutebi.com
Physical Files – Control File
✓ Such information includes database name, location of the database, location and name
of database files, checkpoint information, etc.
✓ This information is so crucial and used during database startup process and during
recovery process.
✓ Redologfile– storesSQLstatementsthatcauseachangetodatapermanently.
✓ Theyarestoredinredologgroupsandeachgroupmusthaveatleastoneredologfile.
✓ Aminimumoftworedologgroupsandworkwith
✓ TheLGWRwritesonthisfileinacircularfashion.
✓ Wheneverdataismovedfromthisfile,wegetanotherfilecalledthearchivedredolog
file.
Physical Files – Data File.
✓ Datafiles– storesdataintablespermanently.
✓ Theyarestoredinalogicalstoragespacecalledthetablespace.Eachdatafilemust
belongtoonlyonetablespace.
✓ ItworkswiththeDBWnandCKPTprocess
✓ Letsseehowwecancreatetablespaceswithdatafiles.
✓ Otherfilesinclude:Parameterfiles(SPandPfiles)– storedatabaseparameterse.g.
memorytarget,controlfileparameters,etc.,archivedredologfiles,alertlogfiles,etc.
Logical Storage - Tablespace
✓ Tablespace– storedatafileslogically.
✓ Eachdatafilebelongstoonlyandonlyonetablespace.
✓ Tablespacesareusedtoorganizedataandmakebackupprocesseasier.
✓ Wecanalsocreateourowntablespaces.
Logical Storage - Tablespace
www.bmutebi.com
Instance Startup Process
✓ WeusetheSTARTUPcommandtostarttheinstance
✓ YouhavetobeaDBAtostartuporshutdowntheinstance.
✓ ThefirststageofstartupprocessistheNomount stage.Hereinitializationparameters
areloaded.
✓ Differentwaysofstartinguptheinstance.
✓ StartupOpen– thisisthedefaultmode.Itisthenormalstartupprocess.
✓ StartupRestrict– thedatabaseisopenedtoonlythosewithrestrictedsessionprivilege.
✓ StartupReadOnly– thedatabaseisopenedbutnoeditscanbemade.
✓ StartupForce– thedatabaseisforcedtostartup.
Instance Shutdown Process
✓ The first stage of shutdown process is the Close stage. The database is shutdown and no
longer available to anyone.
✓ The second stage is the Unmount stage – the instance is de-associated with database.
✓ The final stage is the Shutdown stage – the instance is shutdown – background
processes and memory are stopped and de-allocated.
Instance Shutdown Modes
✓ Differentwaysofshuttingdowntheinstance.
✓ ShutdownNormal– thisisthedefaultmode.Itisthenormalshutdownprocess.
✓ ShutdownTransactional– Waitsforuserswithtransactions.
✓ ShutdownImmediate– Databaseisshutdownimmediately.Uncommittedtransactions
arerolledback.Noneedforrecovery.
✓ ShutdownAbort– databaseisshutdowninstantly.Uncommittedtransactionsarenot
rolledback.Itneedsrecovery.
Oracle Meta Data
ORACLE DATABASE ESSENTIALS – MUTEBI BASHIR
www.bmutebi.com
Meta Data
✓ Metadataisdataaboutthedatabase
✓ Wemayneedtoknowthedifferentthingsaboutadatabaselikedatabaseuser
properties,therunningprocesses,thelocationofvariousfiles,alltablesinthedatabase,
etc.
✓ Oracleprovidesthisinformationtousinformofviewsi.e.virtualtables.
✓ Theseviewsaredatadictionaryviewsanddynamicperformanceviews.
✓ TheyarereallysomuchimportantinyourworkasaDBA.
Meta Data – Data Dictionary Views
✓ These provide information about the database and its objects e.g. users, tables, etc.
✓ DBA_ returns all specified objects in the database e.g. DBA_TABLES returns all tables
✓ ALL_ returns all objects belonging to a particular user plus those they have access to e.g.
ALL_TABLES will return all tables belonging to a user and those they have access to.
✓ Theseprovideinformationaboutdatabasestatusandperformance.
✓ Theystartwithv$andarealwaysinsingular.
✓ Examplesincludev$process,v$logfile,v$datafile,v$sgainfo,etc.
User Security - Authentication
ORACLE DATABASE ESSENTIALS – MUTEBI BASHIR
www.bmutebi.com
User Security – Authentication
✓ Weneedtoauthenticateuserstouseourdatabase
✓ Userauthenticationlooksatensuringtherightusersconnecttoourdatabase.
✓ Wecreateuseraccountsforintendedusersandassignresourcestothem.
✓ WehavedefaultadministrativeuseraccountsinOraclei.e.SYS,SYSTEM,SYSMAN
✓ Wealsohaveotherdefaultaccountse.g.PUBLIC,hr,etc.
✓ Tocreateauseraccount,wemustpayattentiontosomethings.
User Security – Components of User Account.
✓ A username – itshouldn’texceed30charactersandshouldn’tincludespecialcharacters.
✓ Temporarytablespace– usedtostoretemporarysegmentsfromsortingoperations
✓ Quota– spaceallocatedtoauseronadefaulttablespace
✓ Profile– limitsresourceusagelikememoryusage,sessiontimeout,passwordcomplexity,
etc.
✓ Accountstatus– accountcanbeopen,locked,orexpired.
User Security - Authorization
ORACLE DATABASE ESSENTIALS – MUTEBI BASHIR
www.bmutebi.com
User Security – Authorization
✓ Thislooksatgivingrightsorprivilegestoauseraccounttoaccessdatabaseresources.
✓ TheyareassignedusingGRANTandremovedusingREVOKE
✓ WehavedifferenttypesofprivilegesinOraclei.e.objectprivileges,systemprivileges,and
role.
✓ Objectprivileges– allowaccessandtootherusers’objectsliketablese.g.UPDATE,DELETE,INSERT,etc.
WecangivearighttothegranteetoextendthesameprivilegesgiventoanotheruserusingWITH
GRANTOPTION.Incaseofarevoke,alluserslosetherights.
✓ Systemprivileges– allowperformingofdatabaseleveloperationse.g.CREATEUSER,CREATETABLE,
ALTERTABLE,etc..Wecangivearighttothegranteetoextendthesameprivilegesgiventoanother
userusingWITHADMINOPTION.Incaseofarevoke,otherusersdonotlosetherights.
User Security – Authorization
✓ Role privileges – role is a set of privileges that can be granted to any user account in the database.
Roles can be inherited.
✓ Oracle comes with default roles for example, SYSDBA, CONNECT, RESOURCE.
✓ We can grant privileges which wish all users to have to user PUBLIC
✓ We have the principle of least privileges that encourages granting of minimum privileges
to users as much as possible.
www.bmutebi.com
User Security – Auditing
✓ Wefocusonkeepingtrackofalluseractionsastheyareusingthedatabase.
✓ WeenableauditingbyuseofAUDITkeywordanddisableitbyuseofNOAUDIT.
✓ Therearetypesofauditingwecanusei.e.objectauditing,privilegeauditingand
statementauditing.
✓ Wecanauditalluseractionsspecified,auditonlysuccessfulactionsusingWHENEVER
SUCCESSFULorauditonlyunsuccessfulactionsusingWHENEVERNOTSUCCESSFUL.
✓ ObjectauditingfocusesontrackingSQLstatementsthatuseobjectprivilegese.g.
UPDATE,INSERT,etc.Thisauditingcanbeenabledordisabledforallusers.
User Security – Auditing
✓ PrivilegeauditingfocusesontrackingSQLstatementsthatusesystemprivilegese.g.CREATE
TABLE,CREATEUSERetc.
✓ Privilegeauditingcanbedoneonspecificindividualsratherthanallusers.
✓ StatementauditingfocusesonmonitoringuseofspecificSQLstatements.
✓ OraclegroupsdifferentSQLstatementsintoonee.g.TABLEforCREATETABLE,ALTERTABLE,
TRUNCATETABLE,USERforCREATEUSER,ALTERUSER,DROPUSER,etc.
✓ Weusethewordgroupingtofosterauditing.Forexample,AUDITTABLE.
✓ Audittrailsarealwayskeptinoperatingsystemordatabase.Youneedtofirstconfigurethe
audittrailparameterbeforestartingtheauditing.
Database Backup
ORACLE DATABASE ESSENTIALS – MUTEBI BASHIR
www.bmutebi.com
Database Backup
✓ Backupsimplylooksatmakingcopiesofthedatabasefilessuchthatincaseofany
failure,weeasilygetbacktonormal.
✓ Thereareseveralreasonsastowhyweshouldalwaysperformdatabasebackup.
✓ Wehavebackupstrategiesi.e.whole(alldatafilesand1controlfilearebackedup)and
partialbackup(somedatafilesarebackedupandcontrolfilebackupisoptional).
✓ Wealsohavebackuptypesi.e.full(alldataondatafilesisbackedup)andincremental
backup(onlychangeddatablocksarebackedup).
✓ Youcanbackupthedatabasewhenitisavailabletousers(hotbackup)orwhenitisnot
available(coldbackup).Thisisreferredtoasbackupmodes.
Database Backup – Recovery Components
✓ Thesehelpusinthebackupandrecoveryoperations.Theyincludethefollowing.
✓ Controlfile
✓ Redologfiles
✓ Archivedredologfiles
✓ Checkpoint
✓ FlashRecoveryArea
✓ WecanusetheRMANtoolstohelpindatabasebackup.
✓ Wefirstputthedatabaseinarchivelog modei.e.enablearchivingprocess.
Database Recovery
ORACLE DATABASE ESSENTIALS – MUTEBI BASHIR
www.bmutebi.com
Database Recovery – Database Failures
✓ Instance failure – happens when the SCN in the data file headers is not matching the one
in the control file.
✓ User process failure – happens when there is an abrupt disconnection of the user process
from the instance.
✓ User error – happens when there is deliberate or unintentional actions on data e.g.
Delete data, modifying data, etc.
Database Recovery – Database Failures
✓ Usererror– happenswhenthereisdeliberateorunintentionalactionsondatae.g.
Deletedata,modifyingdata,etc.Flashbackqueriesandflashbacktablescanhelp.
✓ Mediafailure– happenswhenthereisalossofoneofthedatabasefilesi.e.datafile,
controlfileandredologfile.TheRMANcanhelpusinrecoveringdatahere.
Thank You!
ORACLE DATABASE ESSENTIALS – MUTEBI BASHIR
www.bmutebi.com