Beruflich Dokumente
Kultur Dokumente
Advantages of DBMS
-Control of data redundancy
- Data consistency
- Sharing of data
- Improved data integrity
- Increased productivity
- Improved security
- Improved maintenance through data independence
- Enforcement of standards
- Increased concurrency
- Improved backup and recovery services
Types of Databases
1) OLTP (Operational/Online transaction processing) - Stores
dynamic information which changes constantly and reflects
up-to-the minute information. For Ex-Inventory, Order
maintenance and hotel booking.
2) Analytical or Data Warehousing Used to store historical
and time dependent data to track trends, view statistical
data over a long period of time or make long-term
projections.
3) Operational Data Stores Data in the Operational Data
Store are constantly refreshed so that the resulting image
reflects the latest state of operations. It stores collective
integrated operational data.
Unlike the OLTP has Subject-Oriented and enterprise-wide
data.
Unlike Data warehousing DB stores are volatile, current and
DB terms
Relation: table, Attribute: Column, Tuple: Record or Row
Functional dependencies : The attribute X is functionally dependent on Y if
t1[X]= t2[ X] and t1[Y]=t2[Y]. If t1 and t2 are tuples of a record.
Multi-valued dependencies: If two tuples t1 and t2 exist in r such that t1[X] =
t2[X] then t3 and t4 should also exist in r with the following properties
t3[x] = t4[X] = t1[X] = t2[X]
t3[Y] = t1[Y] and t4[Y] = t2[Y]
t3[Z] = t2[Z] and t4[Z] = t1[Z]
where [Z = (R-(X U Y)) ]
Fully Functionally dependent: A functional dependency X Y is full functional
dependency if removal of any attribute A from X means that the dependency
does not hold any more.
Transitive rule: If {X Y, Y Z} then X Z
Super key : Uniquely identify a database record.
Candidate key: Special subset of super keys that do not have any extraneous
information in them
Primary key : Unique and not null
Foreign key : A column in the child table is a actually a primary key other
parent table.
Normalization
What is normalization
It is a process of analyzing and breaking down the given
relation schemas based on their Functional Dependencies
(FDs) and primary key to achieve the properties such as:
Minimizing redundancy
Minimizing insertion, deletion and update anomalies.
There are often good reasons NOT to normalize, too: If your
database is largely a reporting platform, you may want to
persist duplicated data to avoid unnecessary joins. OLAP (online analytical processing) is just a big excuse not to
normalize.
Normalization Forms
Form
Defined by
Third normal
form (3NF)
Boyce-Codd
normal form
(BCNF)
Fourth normal
form (4NF)
Brief definition
Table faithfully represents a relation and has no
repeating groups. It is a relation in which the intersection
of each row and column contains one and only one value
No non-prime attribute in the table is functionally
dependent on a proper subset of a candidate key. It is a
relation that is in 1NF and every non-primary-key
attribute is fully functionally dependent on primary key.
Every non-prime attribute is non-transitively dependent
on every candidate key in the table. It is a relation that is
in 1NF, 2NF in which no non-primary-key attribute is
transitively dependent on the primary key.
Every non-trivial functional dependency in the table is a
dependency on a super key. It is a relation in which
every determinant is a candidate key
Every non-trivial multivalued dependency in the table is
a dependency on a superkey.
Every non-trivial join dependency in the table is implied
by the superkeys of the table. Its a relation that contains
no join dependency
Fifth normal
form (5NF)
Domain/key
normal form
(DKNF)
Sixth normal
form (6NF)
Oracle Security
Systems analysts, database designers, database administrators,
application developers and users.
Default User ids
SYS, SYSTEM (password assigned during installation)
SCOTT/TIGER (sample user with DBA role)
Admin User ids
SYSDBA (SYS schema)
SYSOPER (PUBLIC schema)
DBA role
Data Dictionary
User
(_tables,_constraints, _tab_columns, _cons_columns)
System (_tables, _columns, _Indexes)
Oracle Architecture
Oracle Database
Oracle Database = Oracle Instance + data files
Oracle Instance = Memory Architecture + Process Architecture
Memory Architecture
The memory used for the DB operations. Broadly divided into SGA
(System Global Area) and PGA (Program Global Area)
SGA Contains following data structure
Database buffer cache
Redo log buffer
Shared pool
Java pool
Large pool (optional)
Data dictionary cache
Other miscellaneous information
We can also categorized SGA into fixed SGA and variable SGA.
This value is in terms of blocks. we can find the size of a block using
DB_BLOCK_SIZE parameter
SQL> show parameters db_block_size
NAME TYPE VALUE
db_block_size integer 8192
Database Buffers = db_block_buffers X db_block_size=20000 X 8192 =
163840000 bytes
Variable size = Shared Pool Size + Large Pool Size + Java Pool
size
SQL> SELECT pool, sum(bytes) from v$sgastat group by pool;
POOL SUM(BYTES)
java pool 50331648
shared pool 352321536
11069860
Variable size = 352321536 + 50331648 = 402653184 bytes
Program Global Area
PGA contains information about bind variables, sort areas, and other
The reason being that even though the parse information for SQL or
PLSQL may be available in library cache of shared pool, the value
upon which the user want to execute the select or update statement
cannot be shared. These values are stored in PGA. This is also called
Private Global Area.
Database buffer cache is again divided into 3 different types of
cache.
Default Cache
Keep Cache
Recycle Cache
default cache
Define the cache size using DB_CACHE_SIZE (or DB_BLOCK_BUFFER and
specify the block size).
The cache has a limited size, so not all the data on disk can fit in the cache.
When the cache is full, subsequent cache misses cause Oracle to write dirty
data already in the cache to disk to make room for the new data.
You can configure the database buffer cache with separate buffer pools that
either keep data in the buffer cache or make the buffers available for new
data immediately after using the data blocks.
The KEEP buffer pool retains the schema objects data blocks in memory. This
is defined using the INIT.ORA parameter DB_KEEP_CACHE_SIZE
Process Architecture
Oracle has several process running in the background for proper functioning of
database.
Following are the main categories of process.
Server Process
Background Process
Server Process - to handle the requests of user processes connected to the instance.
Server processes (or the server portion of combined user/server processes)
created on behalf of each users application can perform one or more of the
following:
Read necessary data blocks from datafiles on disk into the shared database buffers
of the SGA, if the blocks are not already present in the SGA
Return results in such a way that the application can process the information
Background Process - An Oracle instance can have many background processes; not
all are always present. The background processes in an Oracle instance include the
following:
Checkpoint (CKPT)
Archiver (ARCn)
Recoverer (RECO)
Dispatcher (Dnnn)
Contd
Database writer (DBWn) - The database writer process (DBWn) writes the contents of
buffers to datafiles. The DBWn processes are responsible for writing modified (dirty)
buffers in the database buffer cache to disk. Although one database writer process
(DBW0) is adequate for most systems, you can configure additional processes (DBW1
through DBW9) to improve write performance if your system modifies data heavily. These
additional DBWn processes are not useful on uniprocessor systems.
Log Writer (LGWR) - The log writer process (LGWR) is responsible for redo log buffer
managementwriting the redo log buffer to a redo log file on disk. LGWR writes all redo
entries that have been copied into the buffer since the last time it wrote.
Checkpoint (CKPT) - When a checkpoint occurs, Oracle must update the headers of all
datafiles to record the details of the checkpoint. This is done by the CKPT process. The
CKPT process does not write blocks to disk; DBWn always performs that work.
System Monitor (SMON) - The system monitor process (SMON) performs crash
recovery, if necessary, at instance startup. SMON is also responsible for cleaning up
temporary segments that are no longer in use and for coalescing contiguous free extents
within dictionary-managed tablespaces. If any dead transactions were skipped during
crash and instance recovery because of file-read or offline errors, SMON recovers them
when the tablespace or file is brought back online. SMON wakes up regularly to check
whether it is needed.
Process Monitor (PMON) The process monitor (PMON) performs process recovery when a user process fails.
PMON is responsible for cleaning up the database buffer cache and freeing resources that
the user process was using. For example, it resets the status of the active transaction
table, releases locks, and removes the process ID from the list of active processes.
PMON periodically checks the status of dispatcher and server processes, and restarts any
that have died (but not any that Oracle has terminated intentionally). PMON also registers
information about the instance and dispatcher processes with the network listener.
Contd
Archiver Process (ARCn) The archiver process (ARCn) copies online redo log files to a designated storage
device after a log switch has occurred. ARCn processes are present only when the
database is in ARCHIVELOG mode, and automatic archiving is enabled.
An Oracle instance can have up to 10 ARCn processes (ARC0 to ARC9). The LGWR
process starts a new ARCn process whenever the current number of ARCn processes
is insufficient to handle the workload. The ALERT file keeps a record of when LGWR
starts a new ARCn process.
Recoverer (RECO) - The recoverer process (RECO) is a background process used
with the distributed database configuration that automatically resolves failures
involving distributed transactions. The RECO process of a node automatically
connects to other databases involved in an in-doubt distributed transaction. When
the RECO process reestablishes a connection between involved database servers, it
automatically resolves all in-doubt transactions, removing from each databases
pending transaction table any rows that correspond to the resolved in-doubt
transactions.
The RECO process is present only if the instance permits distributed transactions
and if the DISTRIBUTED_TRANSACTIONS parameter is greater than zero. If this
initialization parameter is zero, RECO is not created during instance startup.
Lock Manager Server (LMS) - In Oracle9i Real Application Clusters, a Lock Manager
Server process (LMS) provides inter-instance resource management.
Queue Monitor (QMNn) - The queue monitor process is an optional background
process for Oracle Advanced Queuing, which monitors the message queues. You can
configure up to 10 queue monitor processes. These processes, like the Jnnn
processes, are different from other Oracle background processes in that process
failure does not cause the instance to fail.
Oracle Files
Datafile
Storage Architecture
Data files
Segments
Extents
Blocks
Logical storage structures
Tablespaces
Tables / Clusters / Indexes
Rows
Columns
Physical Storage
Architecture
Relationship among Segments, Extents, and Blocks
Segment
96K
Extent
Extent
24K
72K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
2K
Database Blocks
Segment
a set of one or more extents that contains all the data for a specific type of
logical storage structure within a tablespace
Data Segment
- A collection of extents that holds all of the data for a table or a cluster
Index Segment
- A collection of extents that holds all of the index data for search
optimization on large tables and clusters
Rollback Segment
- A collection of extents that holds rollback data for rollback, readconsistency, or recovery
Temporary segment
- A collection of extents that holds data belonging to temporary tables
created during a sort operation
Bootstrap segment
- An extent that contains dictionary definitions for dictionary tables to be
loaded when the database is opened.
Extent
A set of contiguous database blocks within a
datafile.
Extent are allocated when.
- The segment is created (INITIAL EXTENT)
- The segments grows (NEXT EXTENT)
- The table is altered to allocate extents.
Block
General Block Information
(Block add, Segment type)
85 ~ 100 bytes
Table info in Cluster
Header
Table Dictionary
Row Dictionary
Free Space
Row Data
DATA1.ORA
DATA2.ORA
USER Tablespace
DATA3.ORA
Contd
Objects stored in tablespaces
Tablespace (one or more datafiles)
Table
INDEX
INDEX
Database Files
Table
INDEX
INDEX
INDEX
INDEX
INDEX
INDEX
INDEX
Objects
INDEX
Table
Oracle Client/Server
Architecture
NETWORK
Server b
Client
Application
Server/Server
Client/Server
Server A
Benefit of Client/Server Component
- Database S/W work on Server
- Only Server upgrade to increase size
- Minimize network resource
- Minimize Client H/W spec
- concurrency, consistency, transparency
- concurrency, consistency, transparency
SQL*Net
What is SQL*Net?
- Oracles Client/Server middleware product
- transparent connection from client tool to DB ( from on DB to another )
- works across multiple network protocol and operation system
What is TNS?
- Transparent Network Substrate
- Oracles Network applications to access the underlying network protocols
transparently
- TNS-based application, Oracle Protocol Adapters, Network software like TCP/IP
Configuration File
-
TNSNAME.ORA ( Client )
TNSNAV.ORA ( Client )
SQLNET.ORA ( Client, Server )
LISTENER.ORA ( Server )
3. Fetch
SGA
Shared Pool Database Buffer
SGA
Shared Pool Database Buffer
Datafiles
User
Process
Datafiles
Server
Process
User
Process
SGA
Shared Pool Database Buffer
Smith
Griego
Begay
Chen
2. Execute
Datafiles
User
Process
Server
Process
Server
Process
SQL
SQL is the basic language used to manipulate and
retrieve data from database
Strutured English Querylanguage (pronounced
"sequel")
SQL is used by all DBMS like DB2, Oracle, Microsoft's
SQL Server and Access, Sybase, Informix, MySQL,
mSQL etc.
The early versions of SQL like SQL86, SQL89, and
SQL92 (SQL2) etc were combined in to SQL99 with
implementing more features.
Later on SQL2003 and SQL2008 were also standardize
SQL History
Dat Events
e
1970
1974
1978
1979
1981
1982
1983
1986
1987
1988
1989
1990
SQL History-cont.,
Date Events
1991
1992
1993
1994
1996
1997
1998
SELECT
INSERT
UPDATE
DELETE),
conditional update or insert
operation
MERGE
EXPLAIN PLAN
LOCK TABLE
CREATE
ALTER
DROP
RENAME
TRUNCATE
GRANT,
REVOKE
AUDIT/ NOAUDIT
COMMENT
Transaction
Control
COMMIT
ROLLBACK
SAVEPOINT
SET TRANSACTION
Session Control
SET ROLE
ALTER SESSION
System Control
ALTER SYSTEM
Static SQL
Dynamic SQL
Dual
SQL> desc dual
Name
Null? Type
----------------------------------------- -------- ---------------------------DUMMY
VARCHAR2(1)
SQL> select * from dual;
D
X
SQL> select 'SQL Training' as Heading from dual;
HEADING
-----------SQL Training
SQL*PLUS
It is the default oracle client to connect to any server.
In windows the connection is done as:
Next Day
SQL commands
String and Date Functions
Advanced SQL commands