0% found this document useful (0 votes)
7 views39 pages

01 Oracle Architecture

Uploaded by

selezeno4ka1337
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views39 pages

01 Oracle Architecture

Uploaded by

selezeno4ka1337
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

Oracle architecture

Codd’s 12 rules
• Rule 1: Information Rule
– The data stored in a database, may it be user data or metadata, must be a value of some table
cell. Everything in a database must be stored in a table format.

• Rule 2: Guaranteed Access Rule


– Every single data element (value) is guaranteed to be accessible logically with a combination of
table-name, primary-key (row value), and attribute-name (column value). No other means,
such as pointers, can be used to access data.

• Rule 3: Systematic Treatment of NULL Values


– The NULL values in a database must be given a systematic and uniform treatment. This is a
very important rule because a NULL can be interpreted as one of the following − data is
missing, data is not known, or data is not applicable.

• Rule 4: Active Online Catalog


– The structure description of the entire database must be stored in an online catalog, known
as data dictionary, which can be accessed by authorized users. Users can use the same
query language to access the catalog which they use to access the database itself.
Codd’s 12 rules
• Rule 5: Comprehensive Data Sub-Language Rule
•There must be at least one language whose statements are expressible, per
some well-defined syntax, as character strings and that is comprehensive in
supporting all of the following items:
 Data definition. (create table, alter table, drop table)
 View definition. (create view)
 Data manipulation (insert, delete, update).
 Integrity constraints. (primary key, foreign key, check)
 Authorization. (grant, revoke)
• Transaction boundaries (commit, rollback, savepoint).
Codd’s 12 rules
• Rule 6: View Updating Rule
– All the views of a database, which can theoretically be updated, must also be updatable by the
system.

• Rule 7: High-Level Insert, Update, and Delete Rule


– A database must support high-level insertion, update, and deletion. This must not be limited to a
single row, that is, it must also support union, intersection, and minus operations to yield sets of
data records.

• Rule 8: Physical Data Independence


– The data stored in a database must be independent of the applications that access the
database. Any change in the physical structure of a database must not have any impact
on how the data is being accessed by external applications.
Codd’s 12 rules
• Rule 9: Logical Data Independence
– The logical data in a database must be independent of its user’s view (application). Any
change in logical data must not affect the applications using it. For example, if two tables are
merged or one is split into two different tables, there should be no impact or change on the
user application.

• Rule 10: Integrity Independence


– Integrity constraints specific to a particular relational data base must be definable in the
relational data sublanguage and storable in the catalog, not in the application programs.

• Rule 11: Distribution Independence


– The end-user must not be able to see that the data is distributed over various locations. Users
should always get the impression that the data is located at one site only. This rule has been
regarded as the foundation of distributed database systems.

• Rule 12: Non-Subversion Rule


– If a system has an interface that provides access to low-level records, then the interface
must not be able to subvert the system and bypass security and integrity constraints.
Oracle Database Architecture
•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
Database Structures
Memory structures Instance
System Global Area (SGA)

Process structures
Background processes

Storage structures Database files


Physical Database Structure .

Control files • Data files • Online redo log files

• Parameter file • Archive log files


• Backup
files
• Password file • Alert and trace log
files
Files of a database
A data file is a physical file on disk that was created by Oracle
Database and contains data structures such as tables and
indexes.
A control file contains information such as the following: the
database name, information about data files, online redo log files,
tablespace information, etc.
The online redo log is a set of files containing records of changes made
to data files. Online redo log is the most crucial structure for
recovery.
Alert log is a file that provides a chronological log of database
messages and errors.
Data Dictionary Views
Who Contents Subset Notes
Can of
Query
DBA_ DBA Everything N/A May have additional
columns meant for
DBA use only
ALL_ Everyone Everything DBA_ Includes user’s own
that the user
has privileges views objects
to see

USER_ Everyone Everything ALL_ Is usually the same as


ALL_ except for the
that the views missing OWNER column.
user owns Some views have
abbreviated names as
PUBLIC synonyms.
Data Dictionary: Usage
Examples
a SELECT table_name, tablespace_name FROM
user_tables;

SELECT sequence_name, min_value, max_value,


b increment_by FROM all_sequences WHERE
sequence_owner IN ('MDSYS','XDB');

c SELECT USERNAME, ACCOUNT_STATUS FROM


dba_users WHERE ACCOUNT_STATUS = 'OPEN';

d DESCRIBE dba_indexes;
What Is a Schema?

owns

HR schema
HR user
Schema Objects
• In Oracle Database, a database schema
is a collection of logical data structures, or
schema objects. A database schema is
owned by a database user and has the
same name as the username.
Tables
CREATE TABLE dept
(deptno NUMBER(2), dname VARCHAR2(42), loc VARCHAR2(39));

SELECT owner, table_name, num_rows


FROM DBA_TABLES
WHERE owner='NIKOVITS' AND table_name='DEPT';

(!) ANALYZE TABLE DEPT COMPUTE STATISTICS;


(!) ANALYZE TABLE DEPT DELETE STATISTICS;
Tables
CREATE TABLE dept
(deptno NUMBER(2), dname VARCHAR2(42), loc VARCHAR2(39));

SELECT column_id, column_name, data_type, data_length,


data_precision, data_scale
FROM DBA_TAB_COLUMNS
WHERE owner='NIKOVITS' AND table_name='DEPT';
Views
CREATE VIEW v1 AS
SELECT deptno, AVG(sal) AvgSal FROM emp GROUP BY deptno;

SELECT view_name, text


FROM DBA_VIEWS
WHERE owner='NIKOVITS' AND view_name='V1';
Synonyms
CREATE SYNONYM syn1 FOR v1;

SELECT * FROM DBA_SYNONYMS


WHERE owner='NIKOVITS' AND synonym_name='SYN1';

SELECT * FROM syn1 WHERE deptno > 10;


Sequences
•A sequence is a mechanism for
automatically generating integers that follow
a pattern. 1
2
– A sequence has a name, which is 3
4
how it is referenced when the next 5
value is requested.
– A sequence is not associated with
any particular table or column.
– The progression can be ascending or
descending.
– The interval between numbers can be of any size.
– A sequence can cycle when a limit is reached.
Sequences
CREATE SEQUENCE seq1
MINVALUE 1 MAXVALUE 100 INCREMENT BY 5
START WITH 50 CYCLE;

SELECT * FROM DBA_SEQUENCES


WHERE sequence_name='SEQ1';
Using a Sequence
Next value from sequence:
INSERT INTO dept VALUES(seq1.NEXTVAL, 'IT', 'Budapest');

Current value from sequence:


INSERT INTO emp(deptno, empno, ename, job, sal)
VALUES(seq1.CURRVAL, 1, 'Tailor', 'SALESMAN', 100);

Current value from sequence:


INSERT INTO emp(deptno, empno, ename, job, sal)
VALUES(seq1.CURRVAL, 2, 'Sailor', 'SALESMAN', 200);
ANY Object
SELECT owner, object_name, object_id, object_type
FROM DBA_OBJECTS
WHERE owner='NIKOVITS‚ and created > sysdate - 1;
How Table Data Is Stored
A datafile with records

KING … 5000 … 10  EMP record

MILLER … 1300 … 10  EMP record

10 ACCOUNTING NEW YORK  DEPT record

SELECT SUM(sal) FROM EMP NATURAL JOIN DEPT


WHERE dname=’ACCOUNTING’;
Tablespaces and Data Files
– Tablespaces consist of one or more data files.
– Data files belong to only one tablespace.

Data file 1 Data file 2

USERS tablespace
SYSTEM and SYSAUX Tablespaces

– The SYSTEM and SYSAUX tablespaces are


mandatory tablespaces.
– They are created at the time of database
creation.
– They must be online.
– The SYSTEM tablespace is used for core
functionality (for example, data dictionary
tables).
– The auxiliary SYSAUX tablespace is used for
additional database components (such as the
Enterprise Manager Repository).
Viewing Tablespace Information
Segments, Extents, and Blocks
– Segments exist within a tablespace.
– Segments are made up of a collection of extents.
– Extents are a collection of data blocks.
– Data blocks are mapped to disk blocks.

Segment Extents Data Disk


blocks blocks
Logical and Physical Database
Structures
Logical Physical

Database

Schema Tablespace Data file

Segment

Extent

Oracle data
OS block
block
How Table Data Is Stored
Columns Blocks

Table A Table B

Rows

Segment Segment

Table
Tablespace

Row piece Extent


Anatomy of a Database Block

Block header
Growth
Free space

Row data
Tablespaces and Data Files

•The Oracle database stores data


logically in tablespaces and physically
in data files.
– Tablespaces:
• Can belong to only one database
• Consist of one or more data files
• Are further divided into logical units ofDatabase
storage
– Data files: Tablespace
• Can belong to only one
tablespace and one database
• Are a repository for schema Data files
object data
Space Management in
Tablespaces
– Locally managed tablespace:
• Free extents are managed in the tablespace.
• A bitmap is used to record free extents.
• Each bit corresponds to a block or group of blocks.
• The bit value indicates free or used extents.
• The use of locally managed tablespaces is
recommended.
– Dictionary-managed tablespace:
• Free extents are managed by the data dictionary.
• Appropriate tables are updated when extents are
allocated or unallocated.
• These tablespaces are supported only for backward
compatibility.
Enlarging the Database

– You can enlarge the database in the following ways:


• Creating a new tablespace
• Adding a data file to an existing tablespace
• Increasing the size of a data file
• Providing for the dynamic growth of a data file

Database

SYSTEM INVENTORY
tablespace tablespace
Execution of a SELECT statement

SELECT datum FROM nikovits.szallit


WHERE ckod=2 AND pkod=5;

How does the DBMS find the pieces of Data on disk?


Data blocks
Records
Fields
Where Table Data is Stored?

SELECT segment_name, segment_type, tablespace_name,


header_file, header_block, blocks, extents
FROM dba_segments where owner='NIKOVITS'
AND segment_name='SZALLIT' AND
segment_type='TABLE';
Where Table Data is Stored?

SELECT segment_name, segment_type,


file_id, block_id, blocks
FROM dba_extents where owner='NIKOVITS'
AND segment_name='SZALLIT' AND
segment_type='TABLE';
Where Table Data is Stored?

SELECT file_id, file_name, blocks


FROM dba_data_files;
Which part of the Datafile?
(What is the block size?)

SELECT tablespace_name, block_size


FROM dba_tablespaces;
Variable-length records
(finding records within blocks)
• When do we have a file with variable-length records?
– file contains records of multiple tables
– create table t (field1 int, field2 varchar2(n))
• Problems:
– Holes created upon deletion have variable size
– Find large enough free space for new record
• Could use previous approaches: maximum record size
– a lot of space wasted
• Use slotted page structure
– Slot directory
– Each slot storing offset, size of record ...
– Record IDs: page number, slot number

32 ... 16 38 N
N 2 1
Record Organization
(finding fields within records)
• Fixed-length record formats
– Fields stored consecutively
• Variable-length record formats
– Array of offsets
– NULL values when start offset = end offset

f1 f2 f3 f4
Base address (B)
L1 L2 L3 L4

f3 Address = B+L1+L2

f1 f2 f3 f4
Base address (B)

You might also like