Upload
mariah-floyd
View
235
Download
3
Tags:
Embed Size (px)
Citation preview
Goals for This Week
• Brief SQL refresh
• New SQL in Oracle 9i
• Overview of Oracle Architecture
• Basic Oracle Administration
• Performance Tuning
• Schema Design
• Back-end Tools
Switch to SQL Intro
Role of Database Server
SQL orProcedureCall
Results
Client
SQL orProcedure Call
HTMLHTTP:GET
Results
Role of Database Server (4 tier)
Client
SQL orProcedure Call
Results
Web Server
App.Server
HTML
HTTP: GET
Proc./TransCall
Results
Logical Objects
Logical Objects
Database
Schemas
Objects
own
consists of
TablesIndexesSequencesViewsProceduresTriggersEtc
Schema Types
Database
Schemas
Objects(tables, indexes, etc)
own
consists of
•Application Schemas
Payroll
Student records
Financial Reporting
Nascar
Hollywood
•User Schemas
Joe
Fred
Dave
Schema Attributes
•Application Schemas
Usually referred to as a “schema object”
Contains a set of closely related tables and associated objects
Typical Object Reference: Hollywood.Movies
•User Schemas
Often referred to as a “User” or “Account” object.
May or may not contain personal tables (Joe.Contacts).
May or may not have the right to even create objects.
Are generally granted privileges to objects in application schemas.
LABCreate a user schemaAnd an application schemaUsing dba studio
Note security weakness:
System (pw: manager)Sys (pw: change_on_install)Scott (pw: tiger)Sysman (pw: oem_start)
Caution Creating a user schema from SQL:
CREATE USER CALVIN IDENTIFIED by HOBBES
LAB Creating a user schema from SQL:
CREATE USER CALVIN IDENTIFIED by HOBBES
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP
QUOTA 100M on users
QUOTA 100M on temp
QUOTA 100M on rbs; -- quota on RBS not necessary on 9i
GRANT CONNECT TO CALVIN; -- let him log inGRANT RESOURCE TO CALVIN; -- let him create tables and other objects
Oracle vs. SQL Server
Database
Schemas
Objects(tables, indexes, etc)
own
consists of
SQL Server Software Instance
Databases
Objects(tables, indexes, etc)
contain
Usersown
defines
Oracle vs. SQL Server
Database
Schemas (users)
Objects(tables, indexes, etc)
own
consists of
SQL Server Software Instance
Databases
Objects(tables, indexes, etc)
contain
Usersown
defines
GrantedPrivileges to
GrantedPrivileges to
Controlling Application Access•Each User is given an Oracle Account and control is maintained by granting privileges to tables, procedures and other objects. (e.g. DESIGN)
•All users connect ominously to a web site. The Web or Application server connects to Oracle in the context of a particular user.
•Although the Web or Application server connects to Oracle in the context of a particular user, individuals connecting to the web site must still authenticate for the interface to determine what they should be allowed to do:
-Oracle Authentication-Local “user” table in application-Network authentication
Roles and Profiles
• Role– Functions similar to NT Groups
– Specific Object and System Privileges are granted to the Role
– That Collection of Privs can be quickly granted to a USER by granting them the Role (Example: GRANT DBA to HOMER)
• ProfileProvides default values for USER attributes such as– Number of Concurrent Sessions
– Password complexity
LAB Creating a role
Create ROLE trainee;
Grant connect to trainee; -- right to log onGrant resource to trainee; -- right to create objectsGrant select_catalog_role to trainee; -- dictionary privs
LAB Creating user schemas from PL/SQL:
DECLARE v_sqlstatement varchar2(200); v_newclass newclass%rowtype; CURSOR newclass_cursor IS SELECT * from newclass;BEGIN DBMS_OUTPUT.PUT_LINE ('****************** begin account creation'); OPEN newclass_cursor; FETCH newclass_cursor into v_newclass; WHILE newclass_cursor%found LOOP DBMS_OUTPUT.PUT_LINE (v_newclass.userid); v_sqlstatement := 'create user ' || UPPER(v_newclass.userid) || ' identified by oracle '; v_sqlstatement := v_sqlstatement || 'DEFAULT TABLESPACE USERS '; v_sqlstatement := v_sqlstatement || 'TEMPORARY TABLESPACE TEMP '; v_sqlstatement := v_sqlstatement || 'QUOTA 100M on users '; v_sqlstatement := v_sqlstatement || 'QUOTA 100M on temp '; v_sqlstatement := v_sqlstatement || 'QUOTA 100M on rbs '; -- rbs quota not needed in 9i execute immediate v_sqlstatement; -- this is dynamic SQL needed because of early binding v_sqlstatement := 'GRANT trainee TO ' || v_newclass.userid; execute immediate v_sqlstatement; FETCH newclass_cursor into v_newclass; END LOOP; DBMS_OUTPUT.PUT_LINE ('****************** end account creation'); CLOSE newclass_cursor;END;/
Oracle’s Architecture
Instance vs. Database
Database(disk structures)
Instance(memory structures)
Multiple Instances for 1 Database
Database 1(disk structures)
Instance A(memory structures)
Instance B(memory structures)
Multiple Databases for 1 Instance
Database 1(disk structures)
Instance A(memory structures)
Database 2(disk structures)
Instance to Instance Communication
Database 1(disk structures)
Instance A(memory structures)
Database 2(disk structures)
Instance B(memory structures)
Via clientOr replication
process
DataFiles
(Inc. RBSegments)
On-lineRedo
Log Files
Key structures and Processes
On-lineRedo
Log FilesOn-line
RedoLog Files
DataFiles
(Inc. RBSegments)
Redo Log BufferDatabase Buffer Cache
DBWR
LibraryCache
Data DictionaryCache
Shared Pool
ORACLE INSTANCE
LGWRSMON PMON CKPTBackgroundProcesses
SERVER
ARCH
ControlFiles
ControlFiles
CLIENT
Network
SERVERSERVER
CLIENTCLIENT
LSTNR
DataFiles
(Inc. RBSegments)
Database Buffer Cache
DataFiles
(Inc. RBSegments)
Database Buffer Cache
DBWR
Number of Buffers determined byInitialization File Parameter: DB_BLOCK_BUFFERS (8i) DB_CACHE_SIZE (9i)
Block Size is a multiple of OS Block.
Block Size if fixed in Oracle 8i.Block Size is not fixed in 9i except for the system, rollback, and temp tablespaces.
LRU algorithm used to determine buffered data.
Free block
Used block
Dirty block
Buffer Hit Ratio
Consistent Gets + DB Block Gets - Physical Reads
Consistent Gets + DB Block Gets* 100
Generally, a hit ratio below 80% indicates too manyphysical reads and suggests that DB_Block_Buffersshould be increased.
Hit Ratio Since Instance Startup
Select sum(decode(NAME, 'consistent gets',VALUE, 0)) "Consistent Gets",
sum(decode(NAME, 'db block gets',VALUE, 0)) "DB Block Gets", sum(decode(NAME, 'physical reads',VALUE, 0)) "Physical Reads", round((sum(decode(name, 'consistent gets',value, 0)) +
sum(decode(name, 'db block gets',value, 0)) - sum(decode(name, 'physical reads',value, 0))) /
(sum(decode(name, 'consistent gets',value, 0)) + sum(decode(name, 'db block gets',value, 0))) * 100,2) "Hit Ratio"
from v$sysstat
Next: change number of buffers, bounce service, large query, check hits
LAB
Shared Pool
LibraryCache
Data DictionaryCache
Shared PoolLibrary Cache
•Holds parsed SQL statements•Interrogate via v$sqlarea & v$librarycache•CURSOR_SHARING = FORCE
Data Dictionary Cache•Holds table and column definitions and privileges
Shared Pool Hit Ratios
Library Cache Hit RatioSelect (sum(pins) / (sum(pins) + sum(reloads))) * 100 “Lib. Hit Ratio”
from v$librarycache
Dictionary Hit Ratio Select (sum(gets) / (sum(getmisses) + sum(gets))) * 100 “Dict.
Hit Ratio” from v$rowcache
LAB
Also look at v$sqlarea
Oracle Processes•Background Processes
run on server-as separate processes on UNIX (ps –ef | grep <ORA_SID>)-As separate threads in single service on NT
•Listener Processone or more per serverlistens for connection requestshands off to server process (on diff. Port)
•Server ProcessesRun on serverTypically one process to support each connected user (unless MTS)
•Client (“User”) Processruns on client machinecommunicates with a server process on server
Oracle Background Processes•DBWR
Writes dirty blocks from the buffer pool back to disk.•SMON
Checks for consistency, initiates recovery•PMON
Cleans up resources if process fails•CKPT
Updates database status after commits and other key events.
•LGWRWrites before and after images of changed rows into the on-line redo log files
•ARCHNumbers and archives on-line redo log files
LABStart and stop the instanceAnd listener services usingVarious methods
LAB
Who is logged in?
Look at v$session
Alter system kill session ‘sid, serial’;
DataFiles
(Inc. RBSegments)
On-lineRedo
Log File C
Oracle Commit Processing
DB-7F3 FRED 30000
On-lineRedo
Log File BOn-line
RedoLog File A
DataFiles
(Inc. RBSegments)
Redo Log BufferDatabase Buffer Cache
DB-7F4 JANE 36000
Update EmpSet Sal = 40000Where name=‘FRED’
Data requested might or Might not be in the buffer.
DBWR
DataFiles
(Inc. RBSegments)
On-lineRedo
Log File C
Oracle Commit Processing
DB-7F3 FRED 30000
BEGIN SCN 412
On-lineRedo
Log File BOn-line
RedoLog File A
DataFiles
(Inc. RBSegments)
Redo Log BufferDatabase Buffer Cache
DB-7F4 JANE 36000
May or may notHave written at this point.
Update EmpSet Sal = 40000Where name=‘FRED’
DBWRLGWR
DataFiles
(Inc. RBSegments)
On-lineRedo
Log File C
Oracle Commit Processing
DB-7F3 FRED 30000
BEGIN SCN 412
On-lineRedo
Log File BOn-line
RedoLog File A
DataFiles
(Inc. RBSegments)
Redo Log BufferDatabase Buffer Cache
DB-7F4 JANE 36000
May or may notHave written at this point.
Update EmpSet Sal = 40000Where name=‘FRED’
RB-65B
DBWRLGWR
DataFiles
(Inc. RBSegments)
On-lineRedo
Log File C
Oracle Commit Processing
DB-7F3 FRED 30000
OLD:7F3 FRED 30000
OLD:RB-65B
BEGIN SCN 412
On-lineRedo
Log File BOn-line
RedoLog File A
DataFiles
(Inc. RBSegments)
Redo Log BufferDatabase Buffer Cache
DB-7F4 JANE 36000
May or may notHave written at this point.
Update EmpSet Sal = 40000Where name=‘FRED’
RB-65B NULL
DBWRLGWR
DataFiles
(Inc. RBSegments)
On-lineRedo
Log File C
Oracle Commit Processing
DB-7F3 FRED 30000
RB-65B FRED 30000
BEGIN SCN 412
On-lineRedo
Log File BOn-line
RedoLog File A
DataFiles
(Inc. RBSegments)
Redo Log BufferDatabase Buffer Cache
DB-7F4 JANE 36000
May or may notHave written at this point.(rollback segs. First)
May or may notHave written at this point.
Update EmpSet Sal = 40000Where name=‘FRED’
OLD:DB-7F3 FRED 30000
OLD:RB-65B
NEW:RB-65B FRED 30000
DBWRLGWR
DataFiles
(Inc. RBSegments)
On-lineRedo
Log File C
Oracle Commit Processing
DB-7F3 FRED 40000
RB-65B FRED 30000
NEW:7F3 FRED 40000
BEGIN SCN 412
On-lineRedo
Log File BOn-line
RedoLog File A
DataFiles
(Inc. RBSegments)
Redo Log BufferDatabase Buffer Cache
DB-7F4 JANE 36000
May or may notHave written at this point.(rollback segs. First)
May or may notHave written at this point.
Update EmpSet Sal = 40000Where name=‘FRED’
OLD:DB-7F3 FRED 30000
OLD:RB-65B
NEW:RB-65B FRED 30000
DBWRLGWR
DataFiles
(Inc. RBSegments)
On-lineRedo
Log File C
Oracle Commit Processing
DB-7F3 FRED 40000
RB-65B FRED 30000
NEW:7F3 FRED 40000
BEGIN SCN 412
On-lineRedo
Log File BOn-line
RedoLog File A
DataFiles
(Inc. RBSegments)
Redo Log BufferDatabase Buffer Cache
DB-7F4 JANE 36000
May or may notHave written at this point.(rollback segs. First)
Update EmpSet Sal = 40000Where name=‘FRED’
OLD:DB-7F3 FRED 30000
OLD:RB-65B
NEW:RB-65B FRED 30000
COMMIT SCN 412
Definitive writethrough commitrecordDBWR
LGWR
LABSimulate ServerFailure after updateBut before commit
GOBACK
Go Back 2 slidesAnd discuss “consistent gets”
Logical to Physical Mapping(controlling where objects are stored)
Database
Tablespaces
DataFiles
Stores objects in
Made Persistent via
OracleTablespace issimilar toSQL ServerFile Group.
Why multiple Tablespaces?• Reduce Disk Contention by spreading disk I/O
over multiple spindles.– We control which TS objects are stored on
– We control physical location of TS datafiles
– Even if all disks are in use currently, the best practice is to keep major apps on different tablespaces to more easily allow for future movement.
• Reduce performance degradation during on-line physical backups.
• Allows different applications to have different physical parameters – block size
– Fragmentation level
– etc
Typical Tablespaces:
• SYSTEM 32464 E:\ORACLE\ORADATA\INSY\SYSTEM01.DBF• RBS 265600 E:\ORACLE\ORADATA\INSY\RBS01.DBF• USERS 89440 E:\ORACLE\ORADATA\INSY\USERS01.DBF• TEMP 10560 E:\ORACLE\ORADATA\INSY\TEMP01.DBF• TOOLS 1280 E:\ORACLE\ORADATA\INSY\TOOLS01.DBF• INDX 2560 E:\ORACLE\ORADATA\INSY\INDX01.DBF• DRSYS 2560 E:\ORACLE\ORADATA\INSY\DR01.DBF• OEM_REPOSITORY 3841 E:\ORACLE\ORADATA\INSY\OEM_REPOSITORY.ORA
Typical OFA segregation1. Oracle software2. System tablespace3. System indexes4. RBS tablespace5. Data tablespace6. Data Indexes TS7. Temp tablespace8. Tools tablespace inc. index9. Online redo log 110. Online redo log 211. Online redo log 3
12.Control file 113.Control file 214.Control file 315.Application software16.User Tablespace inc.
indexes17.Archive log dest
RAID: Redundant Array of Inexpensive Disks
1 2 34 5 6
Volume Set:
7 8 910 11
Stripe Set (Raid Level 0)
12 1314 15
C:
1 2 3 4 5 6 7 8 910 11 12 13 14 1516 17 18 19 20 21
RAID: Redundant Array of Inexpensive Disks
1 3 24 3 5
Mirror set (Raid level 1):
1 3 24 3 5
=
DriveController
RAID: Redundant Array of Inexpensive Disks
Stripe Set with Parity (Raid Level 5)
=+
0 1 00 1 00 0 01 0 1
1 1 01 0 00 0 11 1 0
1 1 11 0 01 0 00 0 1
0 1 10 1 01 0 10 1 0+
==
parity
data
RAID: Redundant Array of Inexpensive Disks
Stripe Set with Parity (Raid Level 5)
=+
0 1 00 1 00 0 01 0 1
1 1 11 0 01 0 00 0 1
0 1 10 1 01 0 10 1 0+
==
parity
data
RAID: Redundant Array of Inexpensive Disks
Mirrored Stripe Set (Raid Level 0 + 1)
1 2 3 4 5 6 7 8 910 11 12 13 14 1516 17 18 19 20 21
Data container
1 2 3 4 5 6 7 8 910 11 12 13 14 1516 17 18 19 20 21
Mirror container
RAID: Redundant Array of Inexpensive DisksStripe Set of Mirrors (Raid Level 1 + 0)
1 2 3 4 5 6 7 8 910 11 12 13 14 1516 17 18 19 20 21
1 2 3 4 5 6 7 8 910 11 12 13 14 1516 17 18 19 20 21
Mirror Set Mirror Set Mirror Set
Stripe Set
Large Scale RAID dependent Oracle InstallationCabinet 1 (9 Containers, 42 drives)
Log 1 Ndx 3
Data 1, Cntrl 1
Log 2 Ndx 4
Data 2, Cntrl 2
Log 3 Intf 1
Sys, Rbs, Temp
Cabinet 2 (9 containers, 42 drives)
Log 4 Ndx 1
Data 3, Cntrl 3
Log 5 Ndx 2
Data 4, Cntrl 4
Log 6 Intf 2
Archived Logs
Source: Oracle Performance Tuning 101, Oracle Press
Controller 1 (c1) Details:
c3c2c1
c6c5c4
RAID 1 (Log 1) RAID 0 + 1 (Ndx 3)
RAID 0 + 1 (Data 1, Cntrl 1)
Small Scale RAID dependent Oracle Installation optimized for read/write operations.
RAID 1 + 0
RedoLog FilesDatafiles, INIT, and Control Files
Raid 1 Raid 1
ArchLog Files
LABDirectly Examine: dba_tables
dba_tablespacesV$datafile
Or indirectly:@\\neelix\oracle\scripts\admin\datafiles@\\neelix\oracle\scripts\admin\usertabs
Look at Same using DBA studio
Create a new tablespaceAnd related datafile(s).
Creating Indexes and Tables in specific tablespaces.
• Each user is assigned a default tablespace.
•Don’t create tables when logged in as system or sys unless instructed to do so when installing Oracle tools.
•Override defaults when necessary through extended DDL syntax.
CREATE TABLE GLACCOUNTS ( AccountNum char(6) Name varchar2(30), Balance number(12,2)) TABLESPACE FINANCIALS;