Database Notes

Oracle DB

  1. Relational Model & RDBMS
  2. Oracle DB Architecture : DBA Roles, Schema, Data Dictionary, Indexing, SysAdmin Roles, Data Modeling, Logical vs. Physical
  3. Normalization: Denormalization, Keys, Normal Forms
  4. DB Objects: Tables, Views, etc.
  5. Stored Procedures & Transactions: Cursors, Stored Procedures, Transactions, Triggers.
  6. Performance: Bottlenecks, Problems/Causes, Locks, Blocks + Deadlocks, Dimensions
  7. Backup & Recovery: Replication, Mirroring
  8. Toad
Most Commonly Used
    Restoring Backup
  1. sqlplus "sys as sysdba" ...
  2. shutdown immediate
  3. startup
  4. exp (logical backup)
  5. cp c:/oracle/oradata/lvso9 { .ctl, .dbf files to be }
  6. if nec → recreate passwd file
  7. startup

    1. Relational Model, RDBMS

    • database = orgzd collecn of info/data
    • primary key = col containg unique vals for a tbl
    • dbms (db mgt sys) = software allowg storage, creatn, retrieval + manipuln of data in a db.
    • rdbms (relatnal db managemt sys) - coll of relns or 2d tbls / dbms in context of relatnal db theory + "Codd's Twelve Rules" defd for relatnal db + later expanded to 300 rules,
    • relatn- special type of tbl havg properties: describe 1 entity + have no duplicate rows (hence always has a primary key) + cols unordered + rows unordered
    • primary key PK - uniq val identifyg a tbl row, duplicate values not allowed, usu not changed
    • foreign key FK = tbl col referencg a PK/uniq key col in another/same tbl.; logical not physical pointers, must match existg PK value/unique key val, or be null.
    • field: intersn of row + col; maybe null.
    • Normalizn - process of simplifyg db design for optimum struct
    emp_id	name	salary	dept_id
    01	smith	20	01
    ... { emp_id (01) - uniq PK; dept_id - FK referrg to 
    t_dept }
    

    redo log: record all changes made to data

    x. DB Architecture of Oracle

    Physical Structure

    		________________________________________
    User Process	|		Instance		|
        \|/		|					|
    Server Process->| > SGA					|
    		|  - Shared Pool			|
    	PGA     |    o Library Cache			|
    		|    o Data Dictionary Cache		|
    		|  - Db Buffer Cache			|
    		|  - Redo Log Buffer			|
    		|  - Java Pool 				|
    		|  - Large Pool				|
    		| > PMON		> SMON		|
    		| > DBWR		> LGWR 		|
    		| > CKPT		> Others	|			
    		_________________________________________
    
    			_________________________
    	Parameter File	|	Database	|
    			| > Datafiles		|   Archived
    	Password File	| > Control Files	|   Log Files
    			| > Redo Log Files	|
    			_________________________
    
      Process Structure
    1. User proc: started at t a db user request conn to ora server
    2. Server proc: connects to ora instance, startd when user est sessn; direct intern with server usg OPI (Ora Program Interface); Shared Server env: server proc handles request of many user procs
    3. Bg proc: started when ora instance started
        Mandatory Bg Proc
      1. PMON : Process Monitor cleans up after failed procs by rollg back transn, releasg locks, freeg other resrcs, restartg dead dispatchers.
      2. SMON : System Monitor for Instance Recovery, Coalesces free space, Dealloc temp segments
      3. LGWR : Log Writer mks sequential writes from Redo Log Buffer to the redo log file when transactn commits, when Redo Log Buffer 1/3 full, when > 1M changes recorded in Redo Log Buffer, before DBWn writes, or every 3 secs.
      4. CKPT : Checkpoint defs checkpoint positns in th redo log file where db recovery to begin incase of instance failure; fired every 3 secs
      5. DBWn : Db Writer records changes to undo + data blocks in db buffer cache, writes dirty buffers from db buffer cache to datafiles ;
        writes when checkpt occurs, dirty buffers reach threshold, no more free buffers, timeout occurs, rac ping request made, tablespace put OFFLINE, tablespace made READ ONLY, table dropped or truncated, tablespace BEGIN BACKUP occurs
        Optnal Bg Proc
      • ARCn - Archiver, auto archive online redo logs when ARCHIVELOG mode set (NOARCHIVELOG - ARCn off, usu. not used for prod db)
      • RECO - recoverer
      • QMNn - advanced queug
      • Dnnn - dispatcher
      • Snnn - shared server
      • Pnnn - parallel query slaves
      • CJQ0 - coordinator job queue bg proc
      • LMDn - rac dlm monitor - remote locks
      • LMON - rac dlm monitor - global locks
      • LCKn - rac lock mgr - instance locks

    Logical Structure

    
    DB Storage Hierarchy
    
    ______________________
    Database                  
      ____________________ 
      Tablespace             
        __________________   
        Segment             
          ________________
          Extent          
           _______________
           Oracle Block
    

    x. DBA Tools

    SQL*Plus

    (Ora cmd line tool to run stdd sql cmds)

    OEM (Ora Enterprise Mgr)

    3-tier or 2-tier
      Startg Up a Db
    1. Shutdown
    2. NOMOUNT: instance started; only durg db creatn or recreatn of ctrl files
      1. read init files from $ORACLE_HOME/dbs/spfileSID.ora, if fail, spfile.ora, if fail initSID.ora (STARTUP .. PFILE... overrides this deflt behaviour)
      2. alloc sga
      3. start bg procs
      4. open alertSID.log file + trace files
      5. db mustbe named in DB_NAME param in init param file or in STARTUP cmd
    3. MOUNT : ctrl file opened for this instance
        Db mounted but not open durg
      • renamg datafiles
      • en/disablg redo log archivg optns
      • performg full db recovery
      • alter database mydb MOUNT | OPEN;
    4. OPEN: all files opened as descd by ctrl files: online datafiles opened, online redo log files opened
      • alter database mydb OPEN READ ONLY | OPEN READ WRITE;
      • verificn all datafiles + redo log files openable
      • db consistency checked, SMON perfs instance recovery if requd
      • STARTUP
      • STARTUP PFILE = $ORACLE_HOME/dbs/initdb01.ora
      • unix: cf. /var/opt/oracle/oratab for auto-startup/shutdown
      • startup + shutdown are sql*plus cmds not sql cmds
    5. restricted mode: startup restrict ; alter system enable|disable restricted session (place instance in restricted mode; only users with RESTRICTED SESSION priv can access)
    6. alter system kill session (term sessn)
      How to Create Db
    1. Ora Univ Installer
    2. Ora Db Cfg Assistt (java based gui)
      1. set env vars ( = create db )
      2. Programs > Oracle - OraHome90 > Cfg + Mig Tools > Database Cfg Assist > Create a Database > Data warehouse | Gen purpose | New Db | Transn Processg
    3. create database
      1. set env vars:
        • ORACLE_BASE = /u01/app/oracle (dir at top of ora sw)
        • ORACLE_HOME = $ORACLE_BASE/product/release (where ora sw installed, ofa reco)
        • ORACLE_SID = instance name, mustbe unique for ora instances runng on same machine
        • ORA_NLS33 = $ORACLE_HOME/ocommon/nls/admin/data (for non-ascii charsets)
        • PATH = ... $ORACLE_HOME/bin
        • LD_LIBRARY_PATH = $ORACLE_HOME/lib
      2. mk init param file: cp init.ora initSID.ora
      3. start instance in nomount
      4. run script containg CREATE DATABASE ...
      5. open the db
      6. run scripts catalog.sql (SYS:SYSDBA; mk views on base tbls + on dyn perf views, mk basic plsql env) , catproc.sql (SYS:SYSDBA; mk pkgs, procedures requd to use plsql), pupbld.sql (as SYSTEM; mk product user profile tbl + prevt warng messg each time user connects to sql*plus)

      create database mydatabase  { DB_NAME used if no name given }
       logfile
        GROUP 1 ('/$HOME/ORADATA/u01/redo01.log') SIZE 100M, 
        GROUP 2 ('/$HOME/ORADATA/u01/redo02.log') SIZE 100M, 
        GROUP 3 ('/$HOME/ORADATA/u01/redo03.log') SIZE 100M, 
       MAXLOGFILES 5  { max nu of redo log file grps ever creatable }
       MAXLOGMEMBERS 5 { max nu of log file members for a log file grp }
       MAXLOGHISTORY 1
       MAXDATAFILES 100
       MAXINSTANCES 1
       DATAFILE '/$HOME/ORADATA/u01/system01.dbf' size 325M
       UNDO TABLESPACE undotbs
       DATAFILE '/$HOME/ORADATA/u02/undotbs01.dbf' size 200M
           AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED { enable auto extensn of data files }
       DEFAULT TEMPORARY TABLESPACE temp
       CHARACTER SET US7ASCII
       NATIONAL CHARACTER SET AL16UTF16
       SET TIME_ZONE = 'America/New_York'
      
    4. OMF (Oracle Managed Files: ora_*.dbf): estd by setting DB_CREATE_FILE_DEST = /$HOME/ORADATA/u05 or DB_CREATE_ONLINE_LOG_DEST_1 = /$HOME/ORADATA/u01 in init param file → use only create database mydb;
        omf namg conventn:
      • ora_%u.ctl (ctrl files; %u - unique 8-char strg)
      • ora_%g_%u.log (redo log files; %g - redo log file grp nu)
      • ora_%t_%u.dbf (datafiles; %t - tablespace name)
      • ora_%t_%u.tmp (temp datafiles)

    OFA (Optimal Flexible Arch)

    (Ora reco stdd db arch layout)
    product/
    	9i/
    		/bin
    		/dbs
    		/rdbms
    		/sqlplus
    admin/
    	myinstance/
    	pfile/
    oradata/
    	db01/
    	system01.dbf
    	control01.ctl
    	redo0101.log ... 
    	db02/
    	system01.dbf
    	control01.ctl
    	redo0101.log ...
    

    x. Normalization


    x. DB Objects


    OCP misc

    Indexes

    Views


    Error Messages


    Business Intelligence

    Business Objects - 14.7% BI market leader, 
    
    BI Market (IDC):
    1) OLAP (Online Analytical Processing)
    2) EIS (Executive Information Systems)
    3) End-user Query and Reporting: BO no.1 in West Europe
    (26.3%)
    4) Packaged Data Marts/Warehouses
    5) Data Mining Tools
    
    
    "Leading Analyst Research finds BO Number One BI Tools Vendor 
    in Western Europe", PRWeb, 3/10/2002, 
    http://www.prweb.com/releases/2002/10/prweb47367.htm
    

    Ora vs sql server


    References

    version 0.05: added ora9i db admin fundas I, vol.1+2 Student Guide by ora educn essence included
    version 0.04: added all of oracle_9i_intro_sql_studguide_1_oracle
    version 0.03: added 2 of deshabandhu bar's practicals
    version 0.02: 18/4/2004 - added 137 deviq ocp q