Académique Documents
Professionnel Documents
Culture Documents
Oracle Architecture
ORACLE Architecture
• Database Components
• Memory Structures
• Processes
• Oracle Instance
• Shared Server ( Multi –threaded Server)
1
12/1/2010
Database overview
An oracle database consists of
Physical Components
• Data file
• Control Files
• Redo log files
Logical components
• Tablespace , segments , extent , block.
• Schema Objects
Database file
A database consists of a set of operating
system files.
Types of information is stored in an oracle
database
• User Data
Actual Application Data
• System Data
Data that the database needs to manage itself
• Overhead Data
Indexes , Integrity etc.
2
12/1/2010
Database file
An ORACLE database consists of one or more physical
operating system files, called database files.
Control file
A database’s overall physical architecture is
maintained by its control files.
3
12/1/2010
Control File
A control file is associated with a single database.
4
12/1/2010
5
12/1/2010
ARCHIVELOG Mode
-- All transaction redo logs are kept
-- A copy of current log is made before a log switch
occurs. This
ensures the database protection against all types of
failure.
6
12/1/2010
Tablespace
A database is divided into logical divisions
called tablespaces.
A database may have one or more tablespaces
Tablespace
The typical tablespace present in an ORACLE
database are :
SYSTEM
SYSAUX
TEMPORARY
UNDO
USER
BIGFILE
INDEX
7
12/1/2010
Tablespace
SYSTEM
-- where ORACLE stores all the information it needs to manage itself.
-- the system tablespace always contain the data dictionary for the
entire database objects.
SYSAUX
-- An auxiliary tablespace to the SYSTEM tablespace
Tablespace
TEMPORARY :
-- where ORACLE stores all its temporary tables.
UNDO :
-- Used for rolling back transactions.
USER :
-- Where all the information about the user is stored.
BIGFILE :
-- Consists of only one datafile
-- Single data file can be upto 8EB.
8
12/1/2010
Data segments
Index segments
Undo segments
Temporary segments
Bootstrap segments
9
12/1/2010
UNDO :
where all undo information is stored.
TEMPORARY :
Used to store intermediate results of various operations
BOOTSTRAP :
Helps to initialize data dictionary cache when the database is opened by
an instance
Schema Objects
-- Tables
-- Indexes
-- Views
etc.
10
12/1/2010
11
12/1/2010
Java Pool
Streams pool
12
12/1/2010
13
12/1/2010
It consists of
-- Library Cache
-- Data Dictionary Cache
Shared pool
Library Cache
– stores information about the most recently used
SQL and PL/SQL statements.
– Use Least Recently used (LRU) algorithm
– Consist of two areas
shared SQL are
Shared PL/SQL area.
14
12/1/2010
Shared Pool
The Data Dictionary Cache
– Contains reference information about the
database , its structure and its users
– Contents of the data dictionary
Names of all tables and views
Names and data types of the columns in database
tables.
Privileges of all Oracle users.
PGA contains
-- Private SQL area
-- Session memory
-- SQL work area.
15
12/1/2010
Oracle Processes
An ORACLE Instance
-- The combination of SGA and the ORACLE processes is called an
Oracle Database instance
-- An Oracle instance may have number of background processes; not
all are always present.
Oracle Processes
System Processes
-- Mandatory Processes
-- Optional Processes
User Processes
16
12/1/2010
Database Writer
17
12/1/2010
Database writer
-- Checkpoints occur
-- Dirty buffers reach threshold
-- There are no free buffers
-- Time out occurs
Log Writers
18
12/1/2010
System Monitor
The system Monitor Process performance instance
recovery at instance start up.
Process Monitor
Performs process recovery when a user process
fails.
PMON
19
12/1/2010
Checkpoint (CKPT)
Signals DBWR at checkpoints
20
12/1/2010
Parameter File
Static parameter file (PFILE)
-- Default name in the format of initSID.ora
-- Text File
-- Default Location ORACLE_Home\Database
E.g.
- ALTER SYSTEM SET undo_tablespace=undo3 SCOPE=BOTH;
21
12/1/2010
Parameters in Initialization
Some common Parameters
-- BACKGROUND_DUMP_DEST
-- COMPATIBLE
-- CONTROL_FILES
-- DB_CACHE_SIZE
-- DB_NAME
-- SHARED_POOL_SIZE
-- USER_DUMP_DEST
Starting Up a Database
SYNTAX
E.g.
-- STARTUP
-- STARTUP PFILE =
ORACLE_HOME\database\init<sid>.ora
22
12/1/2010
Starting Up a Database
-- NOMOUNT
-- MOUNT
-- OPEN
SYNTAX:
23
12/1/2010
SYNTAX
Diagnostic Files
The files contains information about significant events.
-- alert_SID.log
Location decided by BACKGROUND_DUMP_DEST
24
12/1/2010
Terminating Session
Syntax
25
12/1/2010
Data Dictionary
26
12/1/2010
-- DBA
-- ALL
--USER
Data Dictionary
To get overview of the data dictionary views , query the
DICTIONARY view or
its synonym DICT
General Overview
-- DICTIONARY , DICT_COLUMNS
Schema objects
-- DBA_TABLES
-- DBA_INDEXES
-- DBA_TAB_COLUMNS
-- DBA_TAB_CONSTRAINTS
27
12/1/2010
Data Dictionary
Space allocation
-- DBA_SEGMENTS
-- DBA_EXTENTS
Database structure
-- DBA_TABLESPACES
-- DBA_DATA_FILES
These virtual table exists in memory only when the database is running
Listed in V$FIXED_TABLE
28
12/1/2010
V$DATABASE
-- Database information from the control file
V$DATAFILE
-- Data file information from the control file
V$INSTANCE
-- State of the current instance
V$PARAMETER
-- List parameters and values currently in effect
V$SESSION
-- Session information
V$SGA
-- Summary information of the SGA
V$SPPARAMETER
-- Contents of the SPFILE
V$TABLESPACE
-- Tablespace information from the control file
V$VERSION
-- Version numbers of core library components
29
12/1/2010
Managing tablespace
Tablespace
30
12/1/2010
Tablespace
-- SYSTEM
SYSTEM
SYSAUX
-- Non- SYSTEM
USER
TEMP
TOOLS
Tablespace
SYSTEM tablespace
31
12/1/2010
Tablespace
Tablespace
Syntax
32
12/1/2010
Tablespace
NOLOGGING
Space management
Locally Managed
33
12/1/2010
Space management
Space management
Syntax of extent_management_clause
[ EXTENT MANAGEMENT
[ DITIONARY | LOCAL
[ AUTOALLOCATE | UNIFORM
[ SIZE integer [ K | M] ] ] ]
Example
CREATE TABLESPACE mydata
DATAFILE `c:\oradata\mydata01.dbf`
SIZE 400M
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K
34
12/1/2010
Space management
extent_management_clause
-- LOCAL
Default clause specifies that the tablespace is locally managed using
bitmaps
With this clause DEFAULT storage_clause , MINIMUM EXTENT or
TEMPORARY clauses can not be specified
-- AUTOALLOCATE
Specified that the tablespace is SYSTEM managed
Users can not specify an extent size
Space management
Dictionary managed
-- Coalescing is required
35
12/1/2010
Space management
Undo Tablespace
Used to store undo segments
Syntax :
E . G.
-- CREATE UNDO TABLESPACE undo1 DATAFILE
‘c:\oradata\undo.dbf’ SIZE 20M
36
12/1/2010
Temporary Tablespace
Temporary tablespace
Temporary Tablespace
The extents once allocated can be only freed when the instance is
shut down
e.g
37
12/1/2010
Temporary Tablespace
Points to remember about temporary data
files in locally managed temporary tablespace
• Non standard block sizes cannot be specified
• Temporary files are always set to NOLOGGING mode
• It cannot be made read only
• Temporary files are required for read only databases
• Media recovery does not recover tempfiles.
38
12/1/2010
39
12/1/2010
40
12/1/2010
41
12/1/2010
DROPPING TABLESPACES
SYNTAX
- DROP TABLESPACE ts_name [INCLUDING
CONTENTS[AND DATAFILES][CASCADE
CONSTRAINTS]];
Example
- DROP TABLESPACE user1 INCLUDING
CONTENTS AND DATAFILES;
DROPPING TABLESPACES
Guidelines
- Tablespace can not be dropped if it
Is a system tablespace
Contain active segments
- Tablespace that still contains data can be only
dropped by specifying INCLUDING CONTENTS
option.
- To drop files of tablespace use AND DATAFILES
clause
42
12/1/2010
TABLESPACE INFORMATION
Tablespace Information
- DBA_TABLESPACES
- V$TABLESPACE
Data file information
-DBA_DATA_FILES
- V$DATAFILE
Temp file information
- DBA_TEMP_FILES
- V$TEMPFILE
UNDO SEGMENT
• Purpose of Undo segments
- Transaction rollback
Used to record old values of data that were changed by a
transaction
Restores these values if transaction is rolled back
- Transaction recovery
Possible because changes made to the undo segment are
also protected by the online redo log files.
- Read consistency
Does not allow other transactions to see any uncommitted
changes
43
12/1/2010
44
12/1/2010
45
12/1/2010
46
12/1/2010
DATABASE SCHEMA
A schema is a named collection of database
objects that are associated with particular
user
When a database user is created , a schema
with the same name is created for that user.
CREATING USER
Consider following when creating User
- Identify table space
- Decide quota on each tablespaces
- Assign a default and temporary tablespaces
-Decide privileges and roles
47
12/1/2010
CREATING USER
DATA DICTIONARY AUTHENTICATION
Syntax
CREATE USER username IDENTIFIED BY
<password>[DEFAULT TABLESPACE
ts_name][TEMPORARY TABLESPACE
ts_name][QUOTA<integer[K|M]| UNLIMITED
> ON ts_name][PASSWORD
EXPIRE][ACCOUNT<LOCK|UNLOCK>][PROFILE<
profile_name|DEFAULT>];
CREATING USER
DATA DICTIONARY AUTHENTICATION
Example
CREATE USER Anil IDENTIFIED BY xxyyzz
DEFAULT TABLESPACE user1
TEMPORARY TABLESPACE temp
QUOTA 10M ON user1
QUOTA 10M ON data
PASSWORD EXPIRE
ACCOUNT UNLOCK
48
12/1/2010
CREATING USER
Points to remember
- If default tablespace is not assigned then
system tablespace is assigned as the default
- If PASSWORD EXPIRE is specified then, user
will be prompted to change his password at
the first log in
49
12/1/2010
CHANGING PASSWORD
Syntax:
- ALTER USER user_name IDENTIFIED BY
new_password;
- e.g.
- ALTER USER Anil IDENTIFIED BY anil87;
DROPPING A USER
Syntax:
- DROP USER user_name [CASCADE];
E.g
- DROP USER Anil CASCADE;
The CASCADE option drops all objects in the
schema before dropping the user.
50
12/1/2010
USER INFORMATION
Information about users can be obtained
from the following views
- DBA_USERS
- DBA_TS_QUOTAS
PRIVILEGES
Privileges
- are rights to execute particular SQL statement
Need to grant privileges
- Data confidentiality
Only relevant personnel have access to
confidential data
- Efficient system management
Users are allowed to perform limited operations
that they need.
51
12/1/2010
PRIVILEGES
Categories of privileges
- System privileges
- Object privileges
SYSTEM PRIVILEGES
System privileges allows users to perform
particular actions in the database
e.g
- Creating public synonyms, new users etc.
- Removing users , tables etc.
- Database backup
These privileges are normally granted only to
DBAs
52
12/1/2010
SYSTEM PRIVILEGES
Category Privileges
Index CREATE ANY INDEX
ALTER ANY INDEX
DROP ANY INDEX
Table CREATE TABLE
CREATE ANY TABLE
ALTER ANY TABLE
DROP ANY TABLE
SELECT ANY TABLE
UPDATE ANY TABLE
DELETE ANY TABLE
Session CREATE ANY SESSION
ALTER SESSION
RESTRICTED SESSION
Tablespace CREATE TABLESPACE
ALTER TABLESPACE
DROP TABLESPACE
SYSTEM PRIVILEGES
Points to remember
- CREATE privilege include dropping these
objects
- To connect database CREATE SESSION privilege
is required
- To truncate table of another schema DROP ANY
TABLE privilege is required.
53
12/1/2010
GRANT-SYSTEM PRIVILEGES
Syntax :
GRANT privilege1[, privilege2,….]
TO USER <[user_name1,user_name2,….] |role|
PUBLIC> [WITH ADMIN OPTION];
E.g.
GRANT create session , create table TO Anil;
WITH ADMIN OPTION
-Enables the grantee to further grant the privilege or
role to other users or roles.
54
12/1/2010
OBJECT PRIVILEGES
Enables users to access and manipulate a
specific object
Each object has a particular set of grantable
privileges
- Table SELECT,INSERT,UPDATE,DELETE,INDEX
REFERENCES ,ALTER
- View SELECT,INSERT,UPDATE,DELETE,REFERENCE
- Sequence SELECT , ALTER
- Sub-program EXECUTE
OBJECT PRIVILEGES
Owner has all privilege on objects available in
his schema
Owner can give privileges on objects owned
by him to other users or roles
Syntax:
GRANT <obj_priv1[(col_names)][,obj_priv2,….]
| ALL > ON object_name
TO <user_name|role|PUBLIC>[WITH GRANT
OPTION];
55
12/1/2010
OBJECT PRIVILEGES
WITH GRANT OPTION
- Allows grantee to grant objects privileges to
other users or roles
- Not valid when granting an object privilege to
a role
Example :
- Grant select ON emp TO Amit WITH GRANT
OPTION;
- GRANT update (job,deptno) ON emp TO
miller.
56
12/1/2010
PRIVILEGES INFORMATION
DBA_SYS_PRIVS
- Lists system privileges granted to users and roles
DBA_TAB_PRIVS
- Lists all grants on all objects in the database
DBA_COL_PRIVS
- Lists column privileges
SESSION_PRIVS
- Lists the privileges that are currently available to the user
ALL_TAB_PRIVS_MADE
- Lists the grants made on the objects owned by the current user
ROLE
Role is a named group of related privileges
that can be granted to users
Role provides easy and controlled privilege
management
Role can consists of both system and object
privileges
It can granted to any database user or role
57
12/1/2010
CREATE ROLE
Syntax:
- CREATE ROLE role_name;
e.g
- CREATE ROLE engineer;
- GRANT create session , create table, create
view, TO engineer;
- GRANT engineer TO Amol, Anamika WITH
ADMIN OPTION;
PREDEFINED ROLE
CONNECT
- Privileges to connect to the database and create various
objects as cluster , database
link,sequence,synonym,table,view
RESUORCE
- Privileges to create programmatic objects such as procedure,
functions,packages,triggers,types.
DBA
- All system privileges with ADMIN option
SELECT_CATALOG_ROLE-
-Select privilege on data dictionary tables
58
12/1/2010
ASSIGNING ROLES
Syntax:
GRANT role1,role2,……
TO <user|role|PUBLIC>[WITH ADMIN OPTION]
E.g.
- GRANT engineer TO scott WITH ADMIN
OPTION;
REVOKING ROLES
Syntax:
REVOKE role1,[,role2]
FROM <user|role|PUBLIC>;
Example:
- REVOKE engineer FROM scott;
Any user with ADMIN option for a role can
revoke the role from any other database user
or role.
59
12/1/2010
REMOVING ROLE
DROP ROLE command
- Removes it from all users and roles it was
granted
- Removes it from database
ADMIN OPTION or DROP ANY ROLE
privileges are required
Syntax:
- DROP ROLE role;
ROLE INFORMATION
DBA_ROLES
- Lists the roles defined in the database
DBA_ROLE_PRIVS
- Lists all the roles granted to users and roles
ROLE_ROLE_PRIVS
- Lists roles granted to the roles
DBA_SYS_PRIVS
- Lists system privileges granted to users and
roles
60