Database Administrator 3

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 52

Database

By Muhammad Ashar Javed


Week # 3
Objectives
 After completing this lesson, you should be able to do
the following:
 Outline the Oracle architecture and its main components
 List the structures involved in connecting a user to an
Oracle instance
Objectives
 Oracle server architecture by examining the physical,
memory, process, and logical structures involved in
establishing a database connection, creating a session, and
executing SQL commands
Overview of Primary Components
Overview of Primary Components

 Oracle server:
 There are several files, processes, and memory structures
in an Oracle server
 Not all of them are used when processing a SQL
statement
 Some are used to improve the performance of the
database, ensure that the database can be recovered in
the event of a software or hardware error, or perform other
tasks necessary to maintain the database.
 The Oracle server consists of an Oracle instance and an
Oracle database
Oracle Server
 An Oracle server:
 Is a database management system that provides an open,
comprehensive, integrated approach to information
management
 Consists of an Oracle instance and an Oracle database
 The Oracle server can run on a number of different
computers in one of the following ways
 Client-Application Server-Server
Server-to-Server (S2S) is a method of sharing data about app or
web activity from one server to another
 Client-Server
dividing tasks between servers and clients
 Host-Based
A system controlled by a central or main computer. A host-based
system may refer to a hierarchical communications system
controlled by a central computer
Overview of Primary Components

 Oracle instance:
 An Oracle instance is the combination of the background
processes and memory structures.
 The instance must be started to access the data in the
database.
 Every time an instance is started, a System Global Area
(SGA) is allocated and Oracle background processes are
started.
 Background processes perform functions on behalf of the
invoking process.
Oracle instance
1.Every Running Oracle Database must be associated with at
least one database instance.
2.Now, one more important point is that an instance exists in
memory and a database exists on disk, so an instance can
exist without a database and a database can exist without an
instance.
3.Losing an instance is no issue, but losing data files for
example losing the database. That means if you lose some
data file, it means you are losing the database. If you lose
the instance, no issue, you can create the instance again.
Microsoft word example
 We can understand the database and instance using a very
simple example. Actually, the difference between Database
and Database Instance like Microsoft word and Microsoft
document. For example, Microsoft Word imagines as the
Database Instance and so it is the program. And imagine
Microsoft Document is the Database. So, we use Microsoft
Word to read the data inside the document.
Oracle Instance
 An Oracle instance:
 Is a means to access an Oracle database
 Always opens one and only one database
 Consists of memory and process structures
Physical Structure
 The physical structure of an
Oracle database is
determined by the operating
system files that provide the
actual physical storage for
database information
 Control files
 Data files
 Redo log files
Memory Structure
 Oracle’s memory structure consists of two memory
areas known as
 System Global Area (SGA): Allocated at instance startup,
and is a fundamental component of an Oracle Instance
 Program Global Area (PGA): Allocated when the server
process is started
Memory Structure
 Oracle’s memory structure consists of two memory
areas known as
 System Global Area (SGA): Allocated at instance startup,
and is a fundamental component of an Oracle Instance
 Program Global Area (PGA): Allocated when the server
process is started
Process Structure
 An Oracle process is a program that depending on its
type can request information, execute a series of steps,
or perform a specific task.
 Oracle takes advantage of various types of processes:
 User process
 Server process
 Background process
User Process
 A user process is a program that requests interaction
with the Oracle server.
 It must first establish a connection.
 It does not interact directly with the Oracle server
Server Process
 whenever the user connects to the database and tries
to run any SQL statements, oracle creates the server
process. This is the main purpose of the server process.
 It means reading database data from the database storage
and loading that data into the Oracle instance buffer
cache
 A server process is a program that directly interacts with the
Oracle server.
 It fulfills calls generated and returns results.
 Can be dedicated or shared server
 Server process communicates with the Oracle server
using the Oracle Program Interface
Program Global Area (PGA)
 Each server process has its own cache dedicated for each
connecting client. This cache is also known as the PGA.

 User process check query is correct and required data is


present?

 So, in order to execute any SQL Statement, Oracle will


create one Server Process and we need a Memory to handle
that server process we call this memory PGA. If more users
are connected to the database there will be a more no. of
PGA’s i.e. more dedicated server processes.

 PGA contains data and control information that is used by


Oracle Server processes when sorting data, joining large
tables together as part of a SQL statement, and so on.
PGA
Types of Server Processes in
Oracle:
 Dedicated Server Process: In this case, if two users are
connected to the database, there will be two server
processes, which means each user has its own dedicated
server process. There i.
 This is more likely called as one to one relation. If there are
100 users the oracle allocates 100 users which is not much
efficient.
Types of Server Processes in Oracle:
 Shared Server Process:
 In this case, the client user processes connect to a
dispatcher. The dispatcher can support multiple client
connections concurrently. So, the shared server architecture
eliminates the need for a dedicated server process for each
connection. The dispatcher can support multiple user
connections parallelly which is more efficient.

 Note: Usually the database is set into the Dedicated Server


Process but if we need the Shared Server Process, we need
to change the initialization parameters in the parameter file.
This change is done by an Oracle DBA.
System Global Area (SGA)
System Global Area (SGA)
 memory structures that contain data and control information for
one database instance. So, it contains sub-component and each
sub-component performs a specific task.
 Main Tasks of SGA:
1. Maintaining internal data structures that many processes access
concurrently
2. Caching data blocks read from disk
3. Buffering redo data before writing it to the online redo log files
4. Storing SQL execution plans
System Global Area (SGA)
 The SGA consists of several memory structures:
 Shared pool
 Database buffer cache
 Redo log buffer
 There are two optional memory structures that can be
configured within the SGA:
 Large pool
 Java pool
Shared Pool
 The main purpose of Shared Pool is to cache non-user data
like data dictionaries (metadata: data about data. for
example, DBA_Tables).
 So, when the user executes a select statement, the oracle
has a lot of jobs to do. He needs to know, is this table exists
or not? From where he will know? He will know from the
Data Dictionary. So, it will cache the data dictionary into a
path in the System Global Area called Shared Pool. So, the
data will be faster.
 The Shared Pool has its sub-components as follows:
1.Data dictionary cache
2.Library cache

 Sized by the parameter SHARED_POOL_SIZE


 ALTER SYSTEM SET SHARED_POOL_SIZE = 64M;
 Fixed and Variable
Data Dictionary Cache
 The data dictionary cache is a collection of the most
recently used definitions in the database.
 It includes information about database files, tables,
indexes, columns, users, privileges, and other database
objects.
 During the parse phase, the server process looks at the
data dictionary for information to resolve object names
and validate access.
 Caching the data dictionary information into memory
improves response time on queries.
 • Size is determined by the shared pool sizing
What is a Library cache?
 Library cache stores the SQL statement that is executed
named execution plan.

 The execution plan is the procedure of how to execute the


statement step-wise
 i.e it describes how fast a SQL statement can be executed.

 Whenever a user executes any SQL statement for example a


select statement, it undergoes parsing which means
checking for any mistakes in the statement. If there are any
mistakes then it will issue an error to the output. If there are
no errors then it will save in the library cache. Here we got a
new word called parsing.
What is Parsing?

 Parsing is an action breaking the statement and


performing a Syntax check and Semantic Check.
1.Syntax Check: Checking whether the statement
is valid or not and following the rules of SQL syntax
2.Semantic Check: It checks whether the tables
are valid or not, do the users have access to those
tables, and check if the data types are correct or
not.
Library Cache
 The library cache stores information about the most
recently used SQL and PL/SQL statements. The library
cache
 Enables the sharing of commonly used statements Is
managed by a least recently used (LRU) algorithm
 Consists of two structures:
 Shared SQL area
 Shared PL/SQL area
 • Has its size determined by the shared pool sizing
Library Cache
 Shared SQL
 The Shared SQL stores and shares the execution plan and parse
tree for SQL statements run against the database
 an identical SQL statement is run
 Shared PL/SQL
 The shared PL/SQL area stores and shares the most recently
executed PL/SQL statements.
 Parsed and compiled program units and procedures (functions,
packages, and triggers) are stored in this area
Database Buffer Cache
 The database buffer cache is responsible for
caching the database user data.
 The buffer cache frequently accesses the
database data into the buffer memory which
improves performance.
 The data is stored in the buffer cache in the form
of blocks instead of individual rows (1 block =
8kb by default).
 We can change the value of each block. This is
the smallest unit in the oracle database.
 DB_BLOCK_SIZE determines the primary block size
Database Buffer Cache
 For example, in order not to confuse we will example . User
Ali executed a statement (select from students) after finishing
all the parsing the server process copies the table students
from the database-to-database buffer cache and stores it in
it. After storing it displays the output. Due to this, the
statement output will be much faster than the first time
Database Buffer Cache
 Consists of independent sub-caches:
 DB_CACHE_SIZE
 DB_KEEP_CACHE_SIZE
 DB_RECYCLE_CACHE_SIZE
 Database buffer cache can be dynamically resized to
grow or shrink using ALTER SYSTEM
 ALTER SYSTEM SET DB_CACHE_SIZE = 96M;
 DB_CACHE_ADVICE can be set to gather statistics for
predicting different cache size behavior
Redo Log Buffer Cache
 This is a circular buffer that holds information about
changes made to the database
 Its primary purpose is recovery.
 Changes recorded within are called redo entries.
 Redo entries contain information to reconstruct or redo
changes.
 Size is defined by LOG_BUFFER.
Redo Log Buffer Cache example

 For example, from the previous example itself, User Jay


executed a select statement (select * from students) and
then he changed his mind and he needs to add a new row in
the table. So, now he executed an update statement to add a
new row in the table. The table is already present in the
database buffer cache and a new row is added to the table in
the buffer cache. So now there is a change in the database.
Now the information of changes is stored in the redo log
buffer which is again stored in the database.
Question?
 Now there should be a question why can’t the data be stored
from the database buffer cache to the database. Because the
redo log buffer is only for the changes made to the database.

 Storing the data is faster from the redo log buffer to the
database compared to the database buffer cache database a

 it is more secure to take the information from the redo log


buffer rather than the database buffer cache.
Large Pool
 A large pool is a memory present in the SGA which allocates
memory for special oracle features like
 the shared server process and
 the parallel queries.
 The Large pool contains memory to store database backup and
recovery operations.
 It also contains the memory I/O server process for large
transactions.

 It relieves the burden placed on the shared pool.


 This configured memory area is used for session memory
(UGA), I/O slaves, and backup and restore operations.
 Unlike the shared pool, the large pool does not use an LRU list.
 Sized by LARGE_POOL_SIZE
 ALTER SYSTEM SET LARGE_POOL_SIZE = 64M;
Java Pool
 The memory is used to parse java code and scripts. When
you execute a java code in the Large Pool database it is
parsed and stored in the java pool just like a database buffer
cache. JAVA_POOL_SIZE is the parameter that is used to
assign memory or make any modifications to the memory.
Background Processes
 The relationship between the physical and memory
structures is maintained and enforced by Oracle’s
background processes

 Bunch of dedicated server-side processes running in the


background to manage the database.

 It helps in transferring the data from the database instance


to the files in the database. In these background processes,
we have both required and optional background processes.

 Tasks Performed by Background Processes in Oracle:


1.Writing database blocks to disk
2.Writing redo entries to disk
3.Make sure all of the database files on disk are synchronized
4.Perform maintenance task
Types of Background Process in Oracle Database Instance
Architecture:

1.Database Writer Process


2.Log writer process
3.Checkpoint
4.System Monitor
5.Process Monitor
6.Recovery Process
7.Archiver Process
 Database Writer Processes (DBWn):
 Database Writer is responsible for writing the contents of the
database buffers to data files on disk. We see in DBWn ‘n’ it
indicates we can have many database writers. It writes the
modified data i.e updated, inserted, and deleted data from
the database buffer cache to datafiles.

 Log Writer (LGWR):


 Log Writer is responsible for writing redo records from the
redo log buffering memory into a physical disk.
 Checkpoint Process (CKPT):
 This process handles database checkpoints. An Oracle
checkpoint is a database event that synchronizes modified data
blocks. In memory from the buffer cache with the data files on
disk.
 It makes LGWR (log writer) and DBWR (database writer) writes
to the database.

 Process Monitor (PMON):


 It performs process recovery when a user process or a
session fails.
 It is also responsible for cleaning up any changes made to blocks
in the database buffer cache
 releasing resources that were previously used by a failed user
session.
 Archiver Process (ARCn):
 It is responsible to copy the Oracle redo log files to a remote
storage device after a redo log switch has occurred. We call
this FRA (Flash Recovery Area) which is used for backup and
restore methodology. Here ‘n’ in ARCn indicates multiple
archiver processes

 Recover Process (RECO):


 RECO is used as part of distributed database transactions.
 What are Distributed Transactions?
 Distributed transactions are transactions that involve multiple
databases, and should either commit a rollback on both
databases at once. For example, we have two databases. If
we need to save any changes to both databases at the same
time, we need to give commit to both databases at once. If we
need to revert any changes, we need to do rollback at once.
 SMON performs recovery during the start-up sequence of
the Oracle Instance if required. It is also responsible for
cleaning up any unused temporary segments. It also
maintains System Change Number which will be explained
further
Overview of Primary Components

 Oracle database
 An Oracle database consists of operating system
files
 Also known as database files, that provide the
actual physical storage for database information.
 The database files are used to ensure that the
data is kept consistent and can be recovered in
the event of a failure of the instance
Oracle Database
 An Oracle database:
 Is a collection of data that is treated as a unit
 Consists of three file types
Oracle Database
 The general purpose of a database is to store and retrieve
related information.
 An Oracle database has a logical and a physical structure.
 The physical structure of the database is the set of operating
system files in the database.
Oracle Database
 Data files
 Data Files contain the actual user data, application data, and
metadata. i.e Tables, Rows, indexes procedures, views, etc.
The combination of datafiles is represented as tablespaces.
The data is stored using Database writer
 If you lose Datafiles, you lose your database. The extension
for datafiles is .dbf

 Redo logs
 Redo Log Files stores changes to the database as they
occur and are used for data recovery. The redo log files store
the changes made to the database like DML and DCL
operations. Log writer is used to writing the changes to redo
log files.
 Note: If you lose Redo log files, you lose your database. The
extension for the redo log file is .log
Other Key File Structures
 Control files
Control files stores metadata about the data files and online redo log files
like names, locations, timestamp, and status. This information is required
by the database instance to start and open the database. The extension for
Control files is .ctl

 The parameter file


 Defines the characteristics of an Oracle instance. For example, it contains
parameters that size some of the memory structures in the SGA

 There are two parameter files.


1. Pfile
2. Spfile
 This file defines how the database instance is configured when it starts
up. All the configurations of the database are present in the parameter
file.
 Example: SGA size SGA_TARGET, SGA_MAX_SIZE.
 Note: The spfile is a binary file, you cannot edit it directly, it should be
done by using oracle commands. Pfile is a parameter file. You can edit
again. If you lose the spfile no issue, you can recreate it again. But it is
better to take a backup of the spfile in order to restore all the
configurations of the database.
 The password file
 It stores passwords for users with administrative privileges
(sys user) in order to connect remotely. Sys user has all the
privileges to the database.
 Note: DBA password cannot be stored in the database,
because Oracle cannot access the database before the
instance is started, Therefore, the authentication of the DBA
must happen outside of the database. The password file will
be present in the below location:

 Archived redo log files

 This is explained as a group of redo log files. All the redo log files
are archived and stored in some other location for backup and
recovery purposes. Contains ongoing history of the data
changes. Using the backup file and archived redo log files you
can recover your Oracle databaserecover from media failures
 Alert Log File:

 The alert log file is a chronological log of messages and


errors written out by an Oracle Database in sequential order.
So, this is your go-to file in case you’re trying to troubleshoot
a problem with your database. This log file has all the
records what are all the changes to files and other errors
also. For example, you can see when the database was
started and stopped.

 Database Backups Files:


 Any backups of your database that you have taken to be
stored in any location to recover the database when the
database is crashed.
 Note: The backup must include the data files, control files,
and redo log files to recover because these are the important
database files.
Establishing a Connection
and Creating a Session
 Connecting to an Oracle instance consists of establishing a user
connection and creating a session
 Connect to an Oracle server in one of three ways
Sessions
 A session is a specific connection of a user to an Oracle
server. The session starts when the user is validated by the
Oracle server, and it ends when the user logs out or when
there is an abnormal termination

You might also like