* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download oraclearch
Entity–attribute–value model wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Relational model wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Functional Database Model wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
Clusterpoint wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Database model wikipedia , lookup
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 Results SQL or Procedure Call SQL or Procedure Call Results Client HTTP: GET HTML Role of Database Server (4 tier) Results App. Server SQL or Procedure Call Proc./ Trans Call Results HTML Client HTTP: GET Web Server Logical Objects Logical Objects Database consists of Schemas own Objects Tables Indexes Sequences Views Procedures Triggers Etc Schema Types •Application Schemas Database Payroll Student records consists of Schemas own Financial Reporting Nascar Hollywood •User Schemas Joe Objects (tables, indexes, etc) 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. LAB Create a user schema And an application schema Using 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 in GRANT RESOURCE TO CALVIN; -- let him create tables and other objects Oracle Database consists of Schemas own vs. SQL Server SQL Server Software Instance defines Users own Databases contain Objects Objects (tables, indexes, etc) (tables, indexes, etc) Oracle Database consists of Schemas (users) Granted Privileges to vs. SQL Server SQL Server Software Instance defines Users own Databases contain own Objects (tables, indexes, etc) Granted Privileges to Objects (tables, indexes, etc) 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) • Profile Provides 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 on Grant resource to trainee; -- right to create objects Grant 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 Instance (memory structures) Database (disk structures) Multiple Instances for 1 Database Instance A Instance B (memory structures) (memory structures) Database 1 (disk structures) Multiple Databases for 1 Instance Instance A (memory structures) Database 1 Database 2 (disk structures) (disk structures) Instance to Instance Communication Instance A Instance B (memory structures) (memory structures) Via client Or replication process Database 1 Database 2 (disk structures) (disk structures) Key structures and Processes CLIENT CLIENT CLIENT ORACLE INSTANCE Database Buffer Cache Network Redo Log Buffer Shared Pool Library Cache LSTNR Data Dictionary Cache SERVER SERVER SERVER DBWR SMON Data Files Data (Inc. RB Files Segments) (Inc. RB Segments) PMON CKPT Control Files Control Files LGWR ARCH On-line Redo On-line Log Files Redo On-line Log Files Redo Log Files Background Processes Database Buffer Cache Database Buffer Cache Number of Buffers determined by Initialization File Parameter: DB_BLOCK_BUFFERS (8i) DB_CACHE_SIZE (9i) Block Size is a multiple of OS Block. DBWR 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. Data Files Data (Inc. RB Files Segments) (Inc. RB Segments) Free block Used block Dirty block Buffer Hit Ratio Consistent Gets + DB Block Gets - Physical Reads * 100 Consistent Gets + DB Block Gets Generally, a hit ratio below 80% indicates too many physical reads and suggests that DB_Block_Buffers should be increased. LAB 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 Shared Pool Shared Pool Library Cache Data Dictionary Cache Library Cache •Holds parsed SQL statements •Interrogate via v$sqlarea & v$librarycache •CURSOR_SHARING = FORCE Data Dictionary Cache •Holds table and column definitions and privileges LAB Shared Pool Hit Ratios Library Cache Hit Ratio Select (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 Also look at v$sqlarea Oracle Processes •Background Processes run on server -as separate processes on UNIX (ps –ef | grep -As separate threads in single service on NT <ORA_SID>) •Listener Process one or more per server listens for connection requests hands off to server process (on diff. Port) •Server Processes Run on server Typically one process to support each connected user (unless MTS) •Client (“User”) Process runs on client machine communicates 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. •LGWR Writes before and after images of changed rows into the on-line redo log files •ARCH Numbers and archives on-line redo log files LAB Start and stop the instance And listener services using Various methods LAB Who is logged in? Look at v$session Alter system kill session ‘sid, serial’; Oracle Commit Processing Database Buffer Cache Redo Log Buffer DB-7F3 FRED 30000 DB-7F4 JANE 36000 Data requested might or Might not be in the buffer. DBWR Data Files Data (Inc. RB Files Segments) (Inc. RB Segments) Update Emp Set Sal = 40000 Where name=‘FRED’ On-line Redo On-line Log File C Redo On-line Log File B Redo Log File A Oracle Commit Processing Database Buffer Cache Redo Log Buffer DB-7F3 FRED 30000 DB-7F4 JANE 36000 BEGIN SCN 412 LGWR DBWR Data Files Data (Inc. RB Files Segments) (Inc. RB Segments) Update Emp Set Sal = 40000 Where name=‘FRED’ May or may not Have written at this point. On-line Redo On-line Log File C Redo On-line Log File B Redo Log File A Oracle Commit Processing Database Buffer Cache Redo Log Buffer DB-7F3 FRED 30000 DB-7F4 JANE 36000 RB-65B BEGIN SCN 412 LGWR DBWR Data Files Data (Inc. RB Files Segments) (Inc. RB Segments) Update Emp Set Sal = 40000 Where name=‘FRED’ May or may not Have written at this point. On-line Redo On-line Log File C Redo On-line Log File B Redo Log File A Oracle Commit Processing Database Buffer Cache Redo Log Buffer DB-7F3 FRED 30000 DB-7F4 JANE 36000 OLD:7F3 FRED 30000 RB-65B NULL OLD:RB-65B BEGIN SCN 412 LGWR DBWR Data Files Data (Inc. RB Files Segments) (Inc. RB Segments) Update Emp Set Sal = 40000 Where name=‘FRED’ May or may not Have written at this point. On-line Redo On-line Log File C Redo On-line Log File B Redo Log File A Oracle Commit Processing Database Buffer Cache Redo Log Buffer DB-7F3 FRED 30000 DB-7F4 JANE 36000 NEW:RB-65B FRED 30000 OLD:DB-7F3 FRED 30000 RB-65B FRED 30000 OLD:RB-65B BEGIN SCN 412 DBWR Data Files Data (Inc. RB Files Segments) (Inc. RB Segments) May or may not Have written at this point. (rollback segs. First) Update Emp Set Sal = 40000 Where name=‘FRED’ LGWR May or may not Have written at this point. On-line Redo On-line Log File C Redo On-line Log File B Redo Log File A Oracle Commit Processing Database Buffer Cache Redo Log Buffer DB-7F3 FRED 40000 NEW:7F3 FRED 40000 DB-7F4 JANE 36000 NEW:RB-65B FRED 30000 OLD:DB-7F3 FRED 30000 RB-65B FRED 30000 OLD:RB-65B BEGIN SCN 412 DBWR Data Files Data (Inc. RB Files Segments) (Inc. RB Segments) May or may not Have written at this point. (rollback segs. First) Update Emp Set Sal = 40000 Where name=‘FRED’ LGWR May or may not Have written at this point. On-line Redo On-line Log File C Redo On-line Log File B Redo Log File A Oracle Commit Processing Database Buffer Cache Redo Log Buffer COMMIT SCN 412 DB-7F3 FRED 40000 NEW:7F3 FRED 40000 DB-7F4 JANE 36000 NEW:RB-65B FRED 30000 OLD:DB-7F3 FRED 30000 RB-65B FRED 30000 OLD:RB-65B BEGIN SCN 412 DBWR Data Files Data (Inc. RB Files Segments) (Inc. RB Segments) May or may not Have written at this point. (rollback segs. First) Update Emp Set Sal = 40000 Where name=‘FRED’ LGWR Definitive write through commit record On-line Redo On-line Log File C Redo On-line Log File B Redo Log File A LAB Simulate Server Failure after update But before commit GO BACK Go Back 2 slides And discuss “consistent gets” Logical to Physical Mapping (controlling where objects are stored) Database Oracle Tablespace is similar to SQL Server File Group. Stores objects in Tablespaces Made Persistent via DataFiles 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 RBS USERS TEMP TOOLS INDX DRSYS OEM_REPOSITORY 32464 265600 89440 10560 1280 2560 2560 3841 E:\ORACLE\ORADATA\INSY\SYSTEM01.DBF E:\ORACLE\ORADATA\INSY\RBS01.DBF E:\ORACLE\ORADATA\INSY\USERS01.DBF E:\ORACLE\ORADATA\INSY\TEMP01.DBF E:\ORACLE\ORADATA\INSY\TOOLS01.DBF E:\ORACLE\ORADATA\INSY\INDX01.DBF E:\ORACLE\ORADATA\INSY\DR01.DBF E:\ORACLE\ORADATA\INSY\OEM_REPOSITORY.ORA Typical OFA segregation 1. Oracle software 12.Control file 1 2. System tablespace 13.Control file 2 3. System indexes 14.Control file 3 4. RBS tablespace 15.Application software 5. Data tablespace 16.User Tablespace inc. indexes 6. Data Indexes TS 17.Archive log dest 7. Temp tablespace 8. Tools tablespace inc. index 9. Online redo log 1 10. Online redo log 2 11. Online redo log 3 RAID: Redundant Array of Inexpensive Disks Volume Set: C: 123 456 789 10 11 12 13 14 15 Stripe Set (Raid Level 0) 123 10 11 16 17 456 12 13 18 19 789 14 15 20 21 RAID: Redundant Array of Inexpensive Disks Mirror set (Raid level 1): 1 3 2 4 3 5 = Drive Controller 1 3 2 4 3 5 RAID: Redundant Array of Inexpensive Disks Stripe Set with Parity (Raid Level 5) 1 0 0 0 0 0 1 1 1 0 0 0 + 1 0 1 1 1 0 0 1 + 0 1 0 0 = = 0 1 1 1 parity data 0 0 0 1 1 0 0 1 = 0 1 0 0 1 0 1 1 0 1 0 1 RAID: Redundant Array of Inexpensive Disks Stripe Set with Parity (Raid Level 5) 1 0 0 0 0 0 1 1 1 0 0 0 + + = = 0 1 1 1 parity data 0 0 0 1 1 0 0 1 = 0 1 0 0 1 0 1 1 0 1 0 1 RAID: Redundant Array of Inexpensive Disks Mirrored Stripe Set (Raid Level 0 + 1) Data container 123 10 11 16 17 456 12 13 18 19 789 14 15 20 21 456 12 13 18 19 789 14 15 20 21 Mirror container 123 10 11 16 17 RAID: Redundant Array of Inexpensive Disks Stripe Set of Mirrors (Raid Level 1 + 0) Stripe Set Mirror Set Mirror Set Mirror Set 123 10 11 16 17 456 12 13 18 19 789 14 15 20 21 123 10 11 16 17 456 12 13 18 19 789 14 15 20 21 Large Scale RAID dependent Oracle Installation Cabinet 1 (9 Containers, 42 drives) Log 1 Ndx 3 c1 Log 2 Ndx 4 Intf 1 c3 c2 Data 1, Cntrl 1 Log 3 Data 2, Cntrl 2 Sys, Rbs, Temp Cabinet 2 (9 containers, 42 drives) Log 4 Ndx 1 c4 Log 5 Ndx 2 Data 4, Cntrl 4 RAID 1 (Log 1) Controller 1 (c1) Details: RAID 0 + 1 (Ndx 3) RAID 0 + 1 (Data 1, Cntrl 1) Source: Oracle Performance Tuning 101, Oracle Press Intf 2 c6 c5 Data 3, Cntrl 3 Log 6 Archived Logs Small Scale RAID dependent Oracle Installation optimized for read/write operations. Datafiles, INIT, and Control Files RAID 1 + 0 Redo Log Files Arch Log Files Raid 1 Raid 1 LAB Directly Examine: dba_tables dba_tablespaces V$datafile Or indirectly: @\\neelix\oracle\scripts\admin\datafiles @\\neelix\oracle\scripts\admin\usertabs Look at Same using DBA studio Create a new tablespace And 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;